Commit 08c7d729 authored by Pascal Engélibert's avatar Pascal Engélibert

Auto fetch public IP

parent b90010d7
......@@ -35,6 +35,7 @@ Now, start the server:
python3 server.py -s
# Use -d if using a different dir than default
# Use -P for automatic fetch of public IP address
### Proxy
......
......@@ -8,7 +8,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
viewBox="0 0 500 500"
viewBox="100 50 300 400"
version="1.1"
id="svg1151"
sodipodi:docname="logo.svg"
......
......@@ -39,6 +39,10 @@ out_ = something I'm sending to a node
DIR = "~/.gmixer"
BIND_HOST = socket.gethostname()
try:
BIND_HOST = socket.gethostbyname(BIND_HOST)
except socket.gaierror:
pass
BIND_PORT = 10951
PUBLIC_HOST = BIND_HOST
PUBLIC_PORT = BIND_PORT
......@@ -156,7 +160,7 @@ def save_txs(db_txs, pool):
tx.export_ubjson(db_txs)
# Read ini config file
def readConfig(cdir):
def readConfig(cdir, conf_overwrite={}):
if not os.path.isfile(cdir+"/config.json"):
configfile = open(cdir+"/config.json", "w")
configfile.write("{}")
......@@ -186,6 +190,13 @@ def readConfig(cdir):
conf["mix"].setdefault("mix_min_txs", MIX_MIN_TXS)
conf["mix"].setdefault("mix_req_age_max", MIX_REQ_AGE_MAX)
for key in conf_overwrite:
c = conf
k = key.split(".")
for i in k[:len(k)-1]:
c = conf[i]
c[k[len(k)-1]] = conf_overwrite[key]
with open(cdir+"/config.json", "w") as configfile:
json.dump(conf, configfile, indent=1)
......@@ -760,6 +771,15 @@ if __name__ == "__main__":
DIR = DIR[:len(DIR)-1] # Remove last slash
os.makedirs(DIR, exist_ok=True)
conf_overwrite = {}
if "-P" in sys.argv:
import subprocess
print("Fetching public address...")
PUBLIC_HOST = subprocess.run(['curl', '-4', 'https://zettascript.org/tux/ip/'], stdout=subprocess.PIPE).stdout.decode("utf-8")
print("Public host: " + PUBLIC_HOST)
conf_overwrite["server.public_host"] = PUBLIC_HOST
readConfig(DIR, conf_overwrite)
if "-s" in sys.argv:
main()
......@@ -791,6 +811,7 @@ Options:\n\
-s Start server\n\
-i Init config\n\
-I Init config (generate random keys)\n\
-P Auto set public address (overwrites config)\n\
-k Display public key\n\
-v Display version\n\
")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment