mirror of
https://github.com/iv-org/instances-api.git
synced 2025-03-13 09:46:34 -04:00
Allow inst stats to be fetched from onion insts.
This commit is contained in:
parent
cc4ffcf190
commit
99193718fb
9
config.yml
Normal file
9
config.yml
Normal file
@ -0,0 +1,9 @@
|
||||
# Uses the system's CURL binary to do so.
|
||||
fetch_onion_instance_stats: true
|
||||
|
||||
# TOR's Sock proxy address that CURL uses to connect to hidden services
|
||||
tor_sock_proxy_address: "127.0.0.1"
|
||||
tor_sock_proxy_port: 9050
|
||||
|
||||
# Minutes before refreshing the instance stats
|
||||
minutes_between_refresh: 30
|
7
src/helpers/helpers.cr
Normal file
7
src/helpers/helpers.cr
Normal file
@ -0,0 +1,7 @@
|
||||
require "yaml"
|
||||
|
||||
def load_config()
|
||||
config = YAML.parse(File.read("config.yml"))
|
||||
return config
|
||||
end
|
||||
|
@ -18,6 +18,10 @@ require "http/client"
|
||||
require "kemal"
|
||||
require "uri"
|
||||
|
||||
require "./helpers/*"
|
||||
|
||||
CONFIG = load_config()
|
||||
|
||||
Kemal::CLI.new ARGV
|
||||
|
||||
macro rendered(filename)
|
||||
@ -68,6 +72,23 @@ spawn do
|
||||
|
||||
case type = host.split(".")[-1]
|
||||
when "onion"
|
||||
type = "onion"
|
||||
|
||||
if CONFIG["fetch_onion_instance_stats"]?
|
||||
begin
|
||||
args = Process.parse_arguments("--socks5-hostname '#{CONFIG["tor_sock_proxy_address"]}:#{CONFIG["tor_sock_proxy_port"]}' 'http://#{uri.host}/api/v1/stats'")
|
||||
response = nil
|
||||
Process.run("curl", args: args) do |result|
|
||||
data = result.output.read_line
|
||||
response = JSON.parse(data)
|
||||
end
|
||||
|
||||
stats = response
|
||||
|
||||
rescue ex
|
||||
stats = nil
|
||||
end
|
||||
end
|
||||
when "i2p"
|
||||
else
|
||||
type = uri.scheme.not_nil!
|
||||
@ -88,7 +109,7 @@ spawn do
|
||||
INSTANCES.clear
|
||||
INSTANCES.merge! instances
|
||||
|
||||
sleep 5.minutes
|
||||
sleep CONFIG["minutes_between_refresh"].as_i.minutes
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user