def start(demo=False): if demo: # load demo options. it will escape config file. cookie_secret = common.hmacstr(common.randomstr(), common.randomstr()) args = [sys.argv[0], "--debug", "--host=0.0.0.0", "--port=8080", "--base_url=/ssweb", "--service_name=shadowsocks", "--cookie_secret=" + cookie_secret, "--logging=debug"] options.parse_command_line(args) else: # pre-parse the command line options. it will be over write by 'load # options from config file'. by then, it yet loaded. options.parse_command_line() if options.config is not None: # load options from specified config file if not os.path.isfile(options.config): err_("Can't find config file '%s'." % options.config) exit(1) else: config = common.load_config(options.config) if config is not None: info_("Load config from file '%s'." % options.config) args = [sys.argv[0]] for item in config: args += ["--%s=%s" % (item, config[item])] try: options.parse_command_line(args) except tornado.options.Error: err_("Error on config file option.") sys.exit(1) else: # load options from config file, if the file exists. config_file = common.find_config_file() if config_file is not None: config = common.load_config(config_file) if config is not None: info_("Load config from file '%s'." % config_file) args = [sys.argv[0]] for item in config: args += ["--%s=%s" % (item, config[item])] try: options.parse_command_line(args) except tornado.options.Error: err_("Error on config file option.") sys.exit(1) # load options from command line try: options.parse_command_line() except tornado.options.Error: err_("Error on command line option.") sys.exit(1) debug_("options: %s" % json.dumps(options.as_dict(), sort_keys=True)) logging.debug("options: %s" % json.dumps(options.as_dict(), sort_keys=True)) # load shadowsocks configuration ss_config_filename = common.find_shadowsocks_config_file() if ss_config_filename is None: err_("Can't find any shadowsocks config file. Are you sure there " "installed shadowsocks already?") exit(1) config = common.load_shadowsocks_config(ss_config_filename) info_("Loading shadowsocks config from file '%s'." % ss_config_filename) start_tornado(config, ss_config_filename)
def start(demo=False): if demo: # load demo options. it will escape config file. cookie_secret = common.hmacstr(common.randomstr(), common.randomstr()) args = [ sys.argv[0], "--debug", "--host=0.0.0.0", "--port=8080", "--base_url=/ssweb", "--service_name=shadowsocks", "--cookie_secret=" + cookie_secret, "--logging=debug" ] options.parse_command_line(args) else: # pre-parse the command line options. it will be over write by 'load # options from config file'. by then, it yet loaded. options.parse_command_line() if options.config is not None: # load options from specified config file if not os.path.isfile(options.config): err_("Can't find config file '%s'." % options.config) exit(1) else: config = common.load_config(options.config) if config is not None: info_("Load config from file '%s'." % options.config) args = [sys.argv[0]] for item in config: args += ["--%s=%s" % (item, config[item])] try: options.parse_command_line(args) except tornado.options.Error: err_("Error on config file option.") sys.exit(1) else: # load options from config file, if the file exists. config_file = common.find_config_file() if config_file is not None: config = common.load_config(config_file) if config is not None: info_("Load config from file '%s'." % config_file) args = [sys.argv[0]] for item in config: args += ["--%s=%s" % (item, config[item])] try: options.parse_command_line(args) except tornado.options.Error: err_("Error on config file option.") sys.exit(1) # load options from command line try: options.parse_command_line() except tornado.options.Error: err_("Error on command line option.") sys.exit(1) debug_("options: %s" % json.dumps(options.as_dict(), sort_keys=True)) logging.debug("options: %s" % json.dumps(options.as_dict(), sort_keys=True)) # load shadowsocks configuration ss_config_filename = common.find_shadowsocks_config_file() if ss_config_filename is None: err_("Can't find any shadowsocks config file. Are you sure there " "installed shadowsocks already?") exit(1) config = common.load_shadowsocks_config(ss_config_filename) info_("Loading shadowsocks config from file '%s'." % ss_config_filename) start_tornado(config, ss_config_filename)
def post(self): config = dict() config["server"] = self.get_argument("server") config["method"] = self.get_argument("method") config["timeout"] = int(self.get_argument("timeout")) config["workers"] = int(self.get_argument("workers", 1)) config["port"] = self.get_arguments("port") config["password"] = self.get_arguments("password") # because of security reason, the `user` option must edit in cli. # so, we just keep the original value of `user` from config file. if self.config["user"] is not None: config["user"] = self.config["user"] # keep the original value of 'web' from config file if self.config["web"] is not None: config["web"] = self.config["web"] # check if the values in `config` are valid. # validating config["server"] if not common.is_ipaddress(config["server"]): raise ValueError # validating config["method"] if not common.is_valid_method(config["method"]): raise ValueError # validating config["timeout"] if config["timeout"] < 300: raise ValueError # validating config["workers"] if config["workers"] < 1: raise ValueError # validating config["port"] for i in range(len(config["port"])): if int(config["port"][i]) < 1 or int(config["port"][i]) > 65535: raise ValueError # validating config["password"] for i in range(len(config["password"])): if config["password"][i] is None: raise ValueError if len(config["port"]) > 1: _ = dict() for i in range(len(config["port"])): _[config["port"][i]] = config["password"][i] config["port_password"] = _ del config["port"] del config["password"] else: config["server_port"] = int(config["port"][0]) config["password"] = config["password"][0] del config["port"] try: with open(self.config_filename, "wt") as f: json.dump(config, f, indent=4, sort_keys=True) except PermissionError: msg = ("Don't have the permission to write config file '%s'." % self.config_filename) logging.error(msg) self.render("error.html", message=msg) return _ = common.load_shadowsocks_config(self.config_filename) self.application.config = _ self.redirect("/config")
def post(self): config = dict() config["server"] = self.get_argument("server") config["method"] = self.get_argument("method") config["timeout"] = int(self.get_argument("timeout")) config["workers"] = int(self.get_argument("workers", 1)) config["port"] = self.get_arguments("port") config["password"] = self.get_arguments("password") # because of security reason, the `user` option must edit in cli. # so, we just keep the original value of `user` from config file. if self.config["user"] is not None: config["user"] = self.config["user"] # keep the original value of 'web' from config file if self.config["web"] is not None: config["web"] = self.config["web"] # check if the values in `config` are valid. # validating config["server"] if not common.is_ipaddress(config["server"]): raise ValueError # validating config["method"] if not common.is_valid_method(config["method"]): raise ValueError # validating config["timeout"] if config["timeout"] < 300: raise ValueError # validating config["workers"] if config["workers"] < 1: raise ValueError # validating config["port"] for i in range(len(config["port"])): if int(config["port"][i]) < 1 or int(config["port"][i]) > 65535: raise ValueError # validating config["password"] for i in range(len(config["password"])): if config["password"][i] is None: raise ValueError if len(config["port"]) > 1: _ = dict() for i in range(len(config["port"])): _[config["port"][i]] = config["password"][i] config["port_password"] = _ del config["port"] del config["password"] else: config["server_port"] = int(config["port"][0]) config["password"] = config["password"][0] del config["port"] try: with open(self.config_filename, "wt") as f: json.dump(config, f, indent=4, sort_keys=True) except PermissionError: msg = ("Don't have the permission to write config file '%s'." % self.config_filename) logging.error(msg) self.render("error.html", message=msg) return _ = common.load_shadowsocks_config(self.config_filename) self.application.config = _ self.redirect("/config")