2020-09-13 03:26:02 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
from threading import Thread
|
|
|
|
from time import sleep
|
2020-09-14 11:54:14 +00:00
|
|
|
from subprocess import DEVNULL
|
2020-09-13 03:26:02 +00:00
|
|
|
|
|
|
|
import ujson
|
|
|
|
from psutil import Popen
|
|
|
|
from psutil import Process
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
sys.path.append(script_dir + '/src/')
|
|
|
|
|
|
|
|
from etc import onionrvalues
|
|
|
|
|
|
|
|
|
|
|
|
sub_script = script_dir + '/' + onionrvalues.SCRIPT_NAME
|
|
|
|
|
2020-09-14 11:54:14 +00:00
|
|
|
|
2020-09-13 03:26:02 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
2020-12-16 03:59:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--bind-address", help="Address to bind to. Be very careful with non-loopback",
|
|
|
|
type=str, default="")
|
|
|
|
parser.add_argument(
|
|
|
|
"--port", help="Port to bind to, must be available and possible",
|
|
|
|
type=int, default=0)
|
2020-10-21 05:34:43 +00:00
|
|
|
parser.add_argument(
|
2020-10-22 12:45:19 +00:00
|
|
|
"--use-bootstrap-file", help="Use bootstrap node list file",
|
2020-10-21 05:34:43 +00:00
|
|
|
type=int, default=1)
|
2020-09-14 11:54:14 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--show-stats", help="Display curses output of Onionr stats",
|
|
|
|
type=int, default=0)
|
2020-09-13 03:26:02 +00:00
|
|
|
parser.add_argument(
|
2020-09-14 23:28:01 +00:00
|
|
|
"--onboarding", help="Use Onionr onboarding (if first load)",
|
|
|
|
type=int, default=1)
|
2020-09-14 11:54:14 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--security-level", help="Set Onionr security level",
|
|
|
|
type=int, default=0)
|
|
|
|
parser.add_argument(
|
|
|
|
'--open-ui', help='Open onionr web ui after started',
|
|
|
|
type=int, default=1)
|
2020-09-13 03:26:02 +00:00
|
|
|
parser.add_argument(
|
2020-09-14 11:54:14 +00:00
|
|
|
'--random-localhost-ip', help='bind to random localhost IP for extra security',
|
|
|
|
type=int, default=1)
|
|
|
|
parser.add_argument(
|
|
|
|
'--use-tor', help='Use Tor transport',
|
|
|
|
type=int, default=1)
|
|
|
|
parser.add_argument(
|
|
|
|
'--private-key', help='Use existing private key',
|
2020-09-19 08:25:10 +00:00
|
|
|
type=str, default=0)
|
2020-09-14 23:28:01 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--animated-background', help='Animated background on webui index. Just for looks.',
|
|
|
|
type=int, default=0)
|
2020-09-15 18:10:39 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--keep-log-on-exit', help='Onionr can keep or delete its log file on exit',
|
|
|
|
type=int, default=0)
|
2020-09-25 08:08:58 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--use-upload-mixing', help='Re-upload blocks uploaded to us. Slow but more secure',
|
|
|
|
type=int, default=0)
|
2020-10-16 06:30:59 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--dev-mode',
|
|
|
|
help='Developer mode makes restarting and testing Onionr less tedious during development',
|
|
|
|
type=int, default=0)
|
|
|
|
parser.add_argument(
|
|
|
|
'--disable-plugin-list',
|
|
|
|
help='plugins to disable by name, separate with commas',
|
|
|
|
type=str, default='chat'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--store-plaintext',
|
|
|
|
help='store plaintext blocks or not. note that encrypted blocks may not really be encrypted, but we cannot detect that',
|
|
|
|
type=int, default=1
|
|
|
|
)
|
|
|
|
|
2020-09-13 03:26:02 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-01-22 22:58:12 +00:00
|
|
|
p = Popen([sub_script, 'version'])
|
2020-09-13 03:26:02 +00:00
|
|
|
p.wait()
|
2020-09-19 08:25:10 +00:00
|
|
|
from filepaths import config_file, keys_file
|
2020-09-14 11:54:14 +00:00
|
|
|
from coredb import blockmetadb
|
2020-09-19 08:25:10 +00:00
|
|
|
import onionrcrypto
|
2020-09-13 03:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
with open(config_file, 'r') as cf:
|
|
|
|
config = ujson.loads(cf.read())
|
|
|
|
|
2020-09-19 08:25:10 +00:00
|
|
|
|
|
|
|
if args.private_key:
|
|
|
|
priv = args.private_key
|
|
|
|
pub = onionrcrypto.cryptoutils.get_pub_key_from_priv(priv)
|
|
|
|
with open(keys_file, "a") as f:
|
|
|
|
f.write(',' + pub.decode() + ',' + priv)
|
|
|
|
config['general']['public_key'] = pub
|
|
|
|
|
2020-10-16 06:30:59 +00:00
|
|
|
config['plugins']['disabled'] = args.disable_plugin_list.split(',')
|
|
|
|
config['general']['dev_mode'] = False
|
|
|
|
|
|
|
|
config['general']['store_plaintext_blocks'] = True
|
2020-10-21 05:34:43 +00:00
|
|
|
config['general']['use_bootstrap_list'] = True
|
2020-10-22 12:45:19 +00:00
|
|
|
config['transports']['tor'] = True
|
2020-12-16 03:59:36 +00:00
|
|
|
config['general']['bind_port'] = 0 # client api server port
|
|
|
|
config['general']['bind_address'] = '' # client api server address
|
|
|
|
|
|
|
|
if args.bind_address:
|
|
|
|
config['general']['bind_address'] = args.bind_address
|
|
|
|
if args.port:
|
|
|
|
config['client']['client']['port'] = args.port
|
2020-10-16 06:30:59 +00:00
|
|
|
|
2020-10-21 05:34:43 +00:00
|
|
|
if not args.use_bootstrap_file:
|
|
|
|
config['general']['use_bootstrap_list'] = False
|
2020-10-16 06:30:59 +00:00
|
|
|
if not args.store_plaintext:
|
|
|
|
config['general']['store_plaintext_blocks'] = False
|
|
|
|
if args.dev_mode:
|
|
|
|
config['general']['dev_mode'] = True
|
2020-09-14 23:28:01 +00:00
|
|
|
if not args.onboarding:
|
2020-09-13 03:26:02 +00:00
|
|
|
config['onboarding']['done'] = True
|
2020-09-14 11:54:14 +00:00
|
|
|
if not args.random_localhost_ip:
|
|
|
|
config['general']['random_bind_ip'] = False
|
|
|
|
if not args.use_tor:
|
|
|
|
config['transports']['tor'] = False
|
2020-09-14 23:28:01 +00:00
|
|
|
if not args.animated_background:
|
|
|
|
config['ui']['animated_background'] = False
|
2020-09-15 18:10:39 +00:00
|
|
|
if args.keep_log_on_exit:
|
|
|
|
config['log']['file']['remove_on_exit'] = True
|
|
|
|
else:
|
|
|
|
config['log']['file']['remove_on_exit'] = False
|
2020-09-25 08:08:58 +00:00
|
|
|
|
|
|
|
config['general']['upload_mixing'] = False
|
|
|
|
if args.use_upload_mixing:
|
|
|
|
config['general']['upload_mixing'] = True
|
2020-09-14 11:54:14 +00:00
|
|
|
config['general']['display_header'] = False
|
|
|
|
config['general']['security_level'] = args.security_level
|
2020-09-13 03:26:02 +00:00
|
|
|
|
|
|
|
with open(config_file, 'w') as cf:
|
2020-09-19 08:25:10 +00:00
|
|
|
cf.write(ujson.dumps(config, reject_bytes=False))
|
2020-09-13 03:26:02 +00:00
|
|
|
|
|
|
|
if args.open_ui:
|
2020-12-15 06:20:27 +00:00
|
|
|
p = Popen([sub_script, 'start'])
|
2020-09-13 03:26:02 +00:00
|
|
|
sleep(2)
|
2020-12-15 06:20:27 +00:00
|
|
|
Popen([sub_script, 'openhome'])
|
2020-09-13 03:26:02 +00:00
|
|
|
else:
|
2020-12-15 06:20:27 +00:00
|
|
|
p = Popen([sub_script, 'start'])
|
2020-09-13 03:26:02 +00:00
|
|
|
|
|
|
|
p.wait()
|