Fix reset file server port with config web interface
This commit is contained in:
parent
635c3b27cd
commit
ddbd5c7b19
5 changed files with 33 additions and 12 deletions
|
@ -32,6 +32,13 @@ class ConfigStorage extends Class
|
||||||
return value.split("\n")
|
return value.split("\n")
|
||||||
if type == "boolean" and not value
|
if type == "boolean" and not value
|
||||||
return false
|
return false
|
||||||
|
else if type == "number"
|
||||||
|
if typeof(value) == "number"
|
||||||
|
return value.toString()
|
||||||
|
else if not value
|
||||||
|
return "0"
|
||||||
|
else
|
||||||
|
return value
|
||||||
else
|
else
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -68,7 +75,7 @@ class ConfigStorage extends Class
|
||||||
title: "File server port"
|
title: "File server port"
|
||||||
type: "text"
|
type: "text"
|
||||||
valid_pattern: /[0-9]*/
|
valid_pattern: /[0-9]*/
|
||||||
description: "Other peers will use this port to reach your served sites. (default: 15441)"
|
description: "Other peers will use this port to reach your served sites. (default: randomize)"
|
||||||
|
|
||||||
section.items.push
|
section.items.push
|
||||||
key: "ip_external"
|
key: "ip_external"
|
||||||
|
|
|
@ -57,9 +57,8 @@ class UiConfig extends ZeroFrame
|
||||||
for item, i in changed_values
|
for item, i in changed_values
|
||||||
last = i == changed_values.length - 1
|
last = i == changed_values.length - 1
|
||||||
value = @config_storage.deformatValue(item.value, typeof(@config[item.key].default))
|
value = @config_storage.deformatValue(item.value, typeof(@config[item.key].default))
|
||||||
value_same_as_default = JSON.stringify(@config[item.key].default) == JSON.stringify(value)
|
default_value = @config_storage.deformatValue(@config[item.key].default, typeof(@config[item.key].default))
|
||||||
if value_same_as_default
|
value_same_as_default = JSON.stringify(default_value) == JSON.stringify(value)
|
||||||
value = null
|
|
||||||
|
|
||||||
if @config[item.key].item.valid_pattern and not @config[item.key].item.isHidden?()
|
if @config[item.key].item.valid_pattern and not @config[item.key].item.isHidden?()
|
||||||
match = value.match(@config[item.key].item.valid_pattern)
|
match = value.match(@config[item.key].item.valid_pattern)
|
||||||
|
@ -69,6 +68,9 @@ class UiConfig extends ZeroFrame
|
||||||
cb(false)
|
cb(false)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if value_same_as_default
|
||||||
|
value = null
|
||||||
|
|
||||||
@saveValue(item.key, value, if last then cb else null)
|
@saveValue(item.key, value, if last then cb else null)
|
||||||
|
|
||||||
saveValue: (key, value, cb) =>
|
saveValue: (key, value, cb) =>
|
||||||
|
|
|
@ -1336,6 +1336,14 @@
|
||||||
}
|
}
|
||||||
if (type === "boolean" && !value) {
|
if (type === "boolean" && !value) {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (type === "number") {
|
||||||
|
if (typeof value === "number") {
|
||||||
|
return value.toString();
|
||||||
|
} else if (!value) {
|
||||||
|
return "0";
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -1379,7 +1387,7 @@
|
||||||
title: "File server port",
|
title: "File server port",
|
||||||
type: "text",
|
type: "text",
|
||||||
valid_pattern: /[0-9]*/,
|
valid_pattern: /[0-9]*/,
|
||||||
description: "Other peers will use this port to reach your served sites. (default: 15441)"
|
description: "Other peers will use this port to reach your served sites. (default: randomize)"
|
||||||
});
|
});
|
||||||
section.items.push({
|
section.items.push({
|
||||||
key: "ip_external",
|
key: "ip_external",
|
||||||
|
@ -1616,7 +1624,6 @@
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- ConfigView.coffee ---- */
|
/* ---- ConfigView.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1934,17 +1941,16 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
UiConfig.prototype.saveValues = function(cb) {
|
UiConfig.prototype.saveValues = function(cb) {
|
||||||
var base, changed_values, i, item, j, last, len, match, message, results, value, value_same_as_default;
|
var base, changed_values, default_value, i, item, j, last, len, match, message, results, value, value_same_as_default;
|
||||||
changed_values = this.getValuesChanged();
|
changed_values = this.getValuesChanged();
|
||||||
results = [];
|
results = [];
|
||||||
for (i = j = 0, len = changed_values.length; j < len; i = ++j) {
|
for (i = j = 0, len = changed_values.length; j < len; i = ++j) {
|
||||||
item = changed_values[i];
|
item = changed_values[i];
|
||||||
last = i === changed_values.length - 1;
|
last = i === changed_values.length - 1;
|
||||||
value = this.config_storage.deformatValue(item.value, typeof this.config[item.key]["default"]);
|
value = this.config_storage.deformatValue(item.value, typeof this.config[item.key]["default"]);
|
||||||
value_same_as_default = JSON.stringify(this.config[item.key]["default"]) === JSON.stringify(value);
|
default_value = this.config_storage.deformatValue(this.config[item.key]["default"], typeof this.config[item.key]["default"]);
|
||||||
if (value_same_as_default) {
|
this.log("default check:", JSON.stringify(default_value), "==", JSON.stringify(value));
|
||||||
value = null;
|
value_same_as_default = JSON.stringify(default_value) === JSON.stringify(value);
|
||||||
}
|
|
||||||
if (this.config[item.key].item.valid_pattern && !(typeof (base = this.config[item.key].item).isHidden === "function" ? base.isHidden() : void 0)) {
|
if (this.config[item.key].item.valid_pattern && !(typeof (base = this.config[item.key].item).isHidden === "function" ? base.isHidden() : void 0)) {
|
||||||
match = value.match(this.config[item.key].item.valid_pattern);
|
match = value.match(this.config[item.key].item.valid_pattern);
|
||||||
if (!match || match[0] !== value) {
|
if (!match || match[0] !== value) {
|
||||||
|
@ -1954,6 +1960,9 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (value_same_as_default) {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
results.push(this.saveValue(item.key, value, last ? cb : null));
|
results.push(this.saveValue(item.key, value, last ? cb : null));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
@ -2054,4 +2063,4 @@
|
||||||
|
|
||||||
window.Page.createProjector();
|
window.Page.createProjector();
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -49,6 +49,7 @@ class FileServer(ConnectionServer):
|
||||||
raise Exception("Can't find bindable port")
|
raise Exception("Can't find bindable port")
|
||||||
if not config.tor == "always":
|
if not config.tor == "always":
|
||||||
config.saveValue("fileserver_port", port) # Save random port value for next restart
|
config.saveValue("fileserver_port", port) # Save random port value for next restart
|
||||||
|
config.arguments.fileserver_port = port
|
||||||
|
|
||||||
ConnectionServer.__init__(self, ip, port, self.handleRequest)
|
ConnectionServer.__init__(self, ip, port, self.handleRequest)
|
||||||
self.log.debug("Supported IP types: %s" % self.supported_ip_types)
|
self.log.debug("Supported IP types: %s" % self.supported_ip_types)
|
||||||
|
|
|
@ -1194,6 +1194,8 @@ class UiWebsocket(object):
|
||||||
@flag.no_multiuser
|
@flag.no_multiuser
|
||||||
def actionConfigSet(self, to, key, value):
|
def actionConfigSet(self, to, key, value):
|
||||||
import main
|
import main
|
||||||
|
|
||||||
|
self.log.debug("Changing config %s value to %r" % (key, value))
|
||||||
if key not in config.keys_api_change_allowed:
|
if key not in config.keys_api_change_allowed:
|
||||||
self.response(to, {"error": "Forbidden: You cannot set this config key"})
|
self.response(to, {"error": "Forbidden: You cannot set this config key"})
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue