Skip to content

Commit

Permalink
Fix reset file server port with config web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jun 30, 2020
1 parent 635c3b2 commit ddbd5c7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
9 changes: 8 additions & 1 deletion plugins/UiConfig/media/js/ConfigStorage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ConfigStorage extends Class
return value.split("\n")
if type == "boolean" and not value
return false
else if type == "number"
if typeof(value) == "number"
return value.toString()
else if not value
return "0"
else
return value
else
return value

Expand Down Expand Up @@ -68,7 +75,7 @@ class ConfigStorage extends Class
title: "File server port"
type: "text"
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
key: "ip_external"
Expand Down
8 changes: 5 additions & 3 deletions plugins/UiConfig/media/js/UiConfig.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ class UiConfig extends ZeroFrame
for item, i in changed_values
last = i == changed_values.length - 1
value = @config_storage.deformatValue(item.value, typeof(@config[item.key].default))
value_same_as_default = JSON.stringify(@config[item.key].default) == JSON.stringify(value)
if value_same_as_default
value = null
default_value = @config_storage.deformatValue(@config[item.key].default, typeof(@config[item.key].default))
value_same_as_default = JSON.stringify(default_value) == JSON.stringify(value)

if @config[item.key].item.valid_pattern and not @config[item.key].item.isHidden?()
match = value.match(@config[item.key].item.valid_pattern)
Expand All @@ -69,6 +68,9 @@ class UiConfig extends ZeroFrame
cb(false)
break

if value_same_as_default
value = null

@saveValue(item.key, value, if last then cb else null)

saveValue: (key, value, cb) =>
Expand Down
25 changes: 17 additions & 8 deletions plugins/UiConfig/media/js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,14 @@
}
if (type === "boolean" && !value) {
return false;
} else if (type === "number") {
if (typeof value === "number") {
return value.toString();
} else if (!value) {
return "0";
} else {
return value;
}
} else {
return value;
}
Expand Down Expand Up @@ -1379,7 +1387,7 @@
title: "File server port",
type: "text",
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({
key: "ip_external",
Expand Down Expand Up @@ -1616,7 +1624,6 @@

}).call(this);


/* ---- ConfigView.coffee ---- */


Expand Down Expand Up @@ -1934,17 +1941,16 @@
};

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();
results = [];
for (i = j = 0, len = changed_values.length; j < len; i = ++j) {
item = changed_values[i];
last = i === changed_values.length - 1;
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);
if (value_same_as_default) {
value = null;
}
default_value = this.config_storage.deformatValue(this.config[item.key]["default"], typeof this.config[item.key]["default"]);
this.log("default check:", JSON.stringify(default_value), "==", JSON.stringify(value));
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)) {
match = value.match(this.config[item.key].item.valid_pattern);
if (!match || match[0] !== value) {
Expand All @@ -1954,6 +1960,9 @@
break;
}
}
if (value_same_as_default) {
value = null;
}
results.push(this.saveValue(item.key, value, last ? cb : null));
}
return results;
Expand Down Expand Up @@ -2054,4 +2063,4 @@

window.Page.createProjector();

}).call(this);
}).call(this);
1 change: 1 addition & 0 deletions src/File/FileServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, ip=config.fileserver_ip, port=config.fileserver_port, ip_type
raise Exception("Can't find bindable port")
if not config.tor == "always":
config.saveValue("fileserver_port", port) # Save random port value for next restart
config.arguments.fileserver_port = port

ConnectionServer.__init__(self, ip, port, self.handleRequest)
self.log.debug("Supported IP types: %s" % self.supported_ip_types)
Expand Down
2 changes: 2 additions & 0 deletions src/Ui/UiWebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ def actionServerShowdirectory(self, to, directory="backup", inner_path=""):
@flag.no_multiuser
def actionConfigSet(self, to, key, value):
import main

self.log.debug("Changing config %s value to %r" % (key, value))
if key not in config.keys_api_change_allowed:
self.response(to, {"error": "Forbidden: You cannot set this config key"})
return
Expand Down

0 comments on commit ddbd5c7

Please sign in to comment.