Skip to content

Commit ddbd5c7

Browse files
committed
Fix reset file server port with config web interface
1 parent 635c3b2 commit ddbd5c7

5 files changed

Lines changed: 33 additions & 12 deletions

File tree

plugins/UiConfig/media/js/ConfigStorage.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class ConfigStorage extends Class
3232
return value.split("\n")
3333
if type == "boolean" and not value
3434
return false
35+
else if type == "number"
36+
if typeof(value) == "number"
37+
return value.toString()
38+
else if not value
39+
return "0"
40+
else
41+
return value
3542
else
3643
return value
3744

@@ -68,7 +75,7 @@ class ConfigStorage extends Class
6875
title: "File server port"
6976
type: "text"
7077
valid_pattern: /[0-9]*/
71-
description: "Other peers will use this port to reach your served sites. (default: 15441)"
78+
description: "Other peers will use this port to reach your served sites. (default: randomize)"
7279

7380
section.items.push
7481
key: "ip_external"

plugins/UiConfig/media/js/UiConfig.coffee

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ class UiConfig extends ZeroFrame
5757
for item, i in changed_values
5858
last = i == changed_values.length - 1
5959
value = @config_storage.deformatValue(item.value, typeof(@config[item.key].default))
60-
value_same_as_default = JSON.stringify(@config[item.key].default) == JSON.stringify(value)
61-
if value_same_as_default
62-
value = null
60+
default_value = @config_storage.deformatValue(@config[item.key].default, typeof(@config[item.key].default))
61+
value_same_as_default = JSON.stringify(default_value) == JSON.stringify(value)
6362

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

71+
if value_same_as_default
72+
value = null
73+
7274
@saveValue(item.key, value, if last then cb else null)
7375

7476
saveValue: (key, value, cb) =>

plugins/UiConfig/media/js/all.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,14 @@
13361336
}
13371337
if (type === "boolean" && !value) {
13381338
return false;
1339+
} else if (type === "number") {
1340+
if (typeof value === "number") {
1341+
return value.toString();
1342+
} else if (!value) {
1343+
return "0";
1344+
} else {
1345+
return value;
1346+
}
13391347
} else {
13401348
return value;
13411349
}
@@ -1379,7 +1387,7 @@
13791387
title: "File server port",
13801388
type: "text",
13811389
valid_pattern: /[0-9]*/,
1382-
description: "Other peers will use this port to reach your served sites. (default: 15441)"
1390+
description: "Other peers will use this port to reach your served sites. (default: randomize)"
13831391
});
13841392
section.items.push({
13851393
key: "ip_external",
@@ -1616,7 +1624,6 @@
16161624

16171625
}).call(this);
16181626

1619-
16201627
/* ---- ConfigView.coffee ---- */
16211628

16221629

@@ -1934,17 +1941,16 @@
19341941
};
19351942

19361943
UiConfig.prototype.saveValues = function(cb) {
1937-
var base, changed_values, i, item, j, last, len, match, message, results, value, value_same_as_default;
1944+
var base, changed_values, default_value, i, item, j, last, len, match, message, results, value, value_same_as_default;
19381945
changed_values = this.getValuesChanged();
19391946
results = [];
19401947
for (i = j = 0, len = changed_values.length; j < len; i = ++j) {
19411948
item = changed_values[i];
19421949
last = i === changed_values.length - 1;
19431950
value = this.config_storage.deformatValue(item.value, typeof this.config[item.key]["default"]);
1944-
value_same_as_default = JSON.stringify(this.config[item.key]["default"]) === JSON.stringify(value);
1945-
if (value_same_as_default) {
1946-
value = null;
1947-
}
1951+
default_value = this.config_storage.deformatValue(this.config[item.key]["default"], typeof this.config[item.key]["default"]);
1952+
this.log("default check:", JSON.stringify(default_value), "==", JSON.stringify(value));
1953+
value_same_as_default = JSON.stringify(default_value) === JSON.stringify(value);
19481954
if (this.config[item.key].item.valid_pattern && !(typeof (base = this.config[item.key].item).isHidden === "function" ? base.isHidden() : void 0)) {
19491955
match = value.match(this.config[item.key].item.valid_pattern);
19501956
if (!match || match[0] !== value) {
@@ -1954,6 +1960,9 @@
19541960
break;
19551961
}
19561962
}
1963+
if (value_same_as_default) {
1964+
value = null;
1965+
}
19571966
results.push(this.saveValue(item.key, value, last ? cb : null));
19581967
}
19591968
return results;
@@ -2054,4 +2063,4 @@
20542063

20552064
window.Page.createProjector();
20562065

2057-
}).call(this);
2066+
}).call(this);

src/File/FileServer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, ip=config.fileserver_ip, port=config.fileserver_port, ip_type
4949
raise Exception("Can't find bindable port")
5050
if not config.tor == "always":
5151
config.saveValue("fileserver_port", port) # Save random port value for next restart
52+
config.arguments.fileserver_port = port
5253

5354
ConnectionServer.__init__(self, ip, port, self.handleRequest)
5455
self.log.debug("Supported IP types: %s" % self.supported_ip_types)

src/Ui/UiWebsocket.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,8 @@ def actionServerShowdirectory(self, to, directory="backup", inner_path=""):
11941194
@flag.no_multiuser
11951195
def actionConfigSet(self, to, key, value):
11961196
import main
1197+
1198+
self.log.debug("Changing config %s value to %r" % (key, value))
11971199
if key not in config.keys_api_change_allowed:
11981200
self.response(to, {"error": "Forbidden: You cannot set this config key"})
11991201
return

0 commit comments

Comments
 (0)