def tor_restart(options): check_options(options, 0) logging.debug( utility.run_shell_command("systemctl restart tor").decode("utf-8")) logging.debug( utility.run_shell_command("systemctl restart privoxy").decode("utf-8")) logging.info("TOR Restart called, Privoxy restarted")
def toSystemd(name, parameters, autostart=False): systemd_folder = "/lib/systemd/system" filein = open("{0}/setup/templates/{1}".format(project_dir, name)) src = Template(filein.read()) src.substitute(parameters) with open("{0}/{1}".format(systemd_folder, name), "w") as text_file: text_file.write(src.substitute(parameters)) logging.info("File {0}/{1} created".format(systemd_folder, name)) logging.debug( utility.run_shell_command("systemctl daemon-reload").decode("utf-8")) if autostart: logging.debug( utility.run_shell_command( "systemctl enable {0}".format(name)).decode("utf-8"))
def check_interface(interface_name): command = "nmcli dev show {0}|grep unmanaged||true".format(interface_name) if "unmanaged" not in utility.run_shell_command(command).decode("utf-8"): raise Exception( """Interface {0} appears to be managed or not configured. Configure it via /etc/network/interfaces to have static ip and restart Network Manager or reboot your device.""" .format(interface_name)) return ni.ifaddresses(interface_name)[2][0]['addr']
def probe_obfs_binary(mode): retval = "" if mode == "obfs3": try: retval = utility.run_shell_command("which obfsproxy").decode( "utf-8").strip() except subprocess.CalledProcessError as e: logging.debug(e.output) elif mode == "obfs4": try: retval = utility.run_shell_command("which obfs4proxy").decode( "utf-8").strip() except subprocess.CalledProcessError as e: logging.debug(e.output) else: raise Exception("Unsupported bridge mode") return retval
def set_default_interface(options): check_options(options, 1) wan = [] for i in configuration['wan_interface']: wan.append(i['name']) if options[0] not in wan: raise Exception("Interface not configured WAN interfaces list.") command = "" for i in wan: device_managed = is_managed(i) if device_managed: command += "nmcli dev disconnect {0}\n".format(i) else: command += "ifdown {0}\n".format(i) if is_managed(options[0]): command += "nmcli dev connect {0}\n".format(options[0]) else: command += "ifup {0}\n".format(options[0]) logging.debug(command) logging.debug(utility.run_shell_command(command).decode("utf-8")) logging.info("Set default interface {0} called".format(options[0]))
def is_managed(interface): command = "nmcli dev show {0}|grep unmanaged||true".format(interface) return "unmanaged" not in utility.run_shell_command(command).decode( "utf-8")
def dnsmasq_restart(options): check_options(options, 0) logging.debug( utility.run_shell_command("systemctl restart dnsmasq").decode("utf-8")) logging.info("DNSMasq restart called")
def patch_nmcli(options): check_options(options, 0) logging.debug( utility.run_shell_command("chmod u+s,a-w `which nmcli`").decode( "utf-8")) logging.info("nmcli patch called")
def i2p_stop(options): check_options(options, 0) logging.debug( utility.run_shell_command("systemctl stop i2p-tbng").decode("utf-8")) logging.info("I2P Stop called")
def i2p_restart(options): check_options(options, 0) logging.debug( utility.run_shell_command("systemctl restart i2p-tbng").decode( "utf-8")) logging.info("I2P Restart called")
def tor_stop(options): check_options(options, 0) mode(["direct"]) logging.debug( utility.run_shell_command("systemctl stop tor").decode("utf-8")) logging.info("TOR Stop called")
def halt(options): check_options(options, 0) logging.info("Halt called") logging.debug(utility.run_shell_command("shutdown -H now").decode("utf-8"))
def reboot(options): check_options(options, 0) logging.info("Reboot called") logging.debug(utility.run_shell_command("reboot").decode("utf-8"))