optimize the fill method for advertiseRoutes
This commit is contained in:
@@ -18,34 +18,30 @@ var callServiceList = rpc.declare({
|
||||
expect: { '': {} }
|
||||
});
|
||||
|
||||
function enquoteBigNumber(str) {
|
||||
return str.replace(/("\w+"):\s*(\d+)/g, '$1:"$2"');
|
||||
}
|
||||
|
||||
function getStatus() {
|
||||
var status = {};
|
||||
return Promise.resolve(callServiceList('tailscale')).then(function (res) {
|
||||
var status = {
|
||||
isRunning: false,
|
||||
backendState: undefined,
|
||||
authURL: undefined,
|
||||
displayName: undefined
|
||||
};
|
||||
return Promise.resolve(callServiceList('tailscale')).then(res => {
|
||||
try {
|
||||
status.isRunning = res['tailscale']['instances']['instance1']['running'];
|
||||
} catch (e) {
|
||||
status.isRunning = false;
|
||||
return status;
|
||||
}
|
||||
return fs.exec("/usr/sbin/tailscale", ["status", "--json"]);
|
||||
}).then(function(res) {
|
||||
var tailscaleStatus = JSON.parse(enquoteBigNumber(res.stdout));
|
||||
if (!tailscaleStatus.AuthURL && tailscaleStatus.BackendState == "NeedsLogin") {
|
||||
return fs.exec("/usr/sbin/tailscale", ["status", "--json"]).then(res => {
|
||||
const tailscaleStatus = JSON.parse(res.stdout.replace(/("\w+"):\s*(\d+)/g, '$1:"$2"'));
|
||||
if (!tailscaleStatus.AuthURL && tailscaleStatus.BackendState === "NeedsLogin") {
|
||||
fs.exec("/usr/sbin/tailscale", ["login"]);
|
||||
}
|
||||
status.backendState = tailscaleStatus.BackendState;
|
||||
status.authURL = tailscaleStatus.AuthURL;
|
||||
status.displayName = status.backendState == "Running" ? tailscaleStatus.User[tailscaleStatus.Self.UserID].DisplayName : undefined;
|
||||
return status;
|
||||
}).catch(function(error) {
|
||||
status.backendState = undefined;
|
||||
status.authURL = undefined;
|
||||
status.displayName = undefined;
|
||||
status.displayName = (status.backendState === "Running") ? tailscaleStatus.User[tailscaleStatus.Self.UserID].DisplayName : undefined;
|
||||
return status;
|
||||
});
|
||||
}).catch(() => status);
|
||||
}
|
||||
|
||||
function renderStatus(isRunning) {
|
||||
@@ -167,7 +163,7 @@ return view.extend({
|
||||
o.default = o.disabled;
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.taboption('advance',form.Value, 'advertiseRoutes', _('Expose Subnets'), _('Expose physical network routes into Tailscale, e.g. <code>10.0.0.0/24</code>.'));
|
||||
o = s.taboption('advance', form.DynamicList, 'advertiseRoutes', _('Expose Subnets'), _('Expose physical network routes into Tailscale, e.g. <code>10.0.0.0/24</code>.'));
|
||||
o.default = '';
|
||||
o.rmempty = true;
|
||||
|
||||
@@ -182,11 +178,13 @@ return view.extend({
|
||||
o.value('lanfwts', _('LAN access Tailscale'));
|
||||
o.value('wanfwts', _('WAN access Tailscale'));
|
||||
o.default = "tsfwlan tsfwwan lanfwts";
|
||||
o.rmempty = false;
|
||||
o.rmempty = true;
|
||||
|
||||
s.tab('extra', _('Extra Settings'));
|
||||
|
||||
o = s.taboption('extra', form.DynamicList, 'flags', _('Additional Flags'), String.format(_('List of extra flags. Format: --flags=value, e.g. <code>--exit-node=10.0.0.1</code>. <br> %s for enabling settings upon the initiation of Tailscale.'), '<a href="https://tailscale.com/kb/1241/tailscale-up" target="_blank">' + _('Available flags') + '</a>'));
|
||||
o.default = '';
|
||||
o.rmempty = true;
|
||||
|
||||
s = m.section(form.NamedSection, 'settings', 'config');
|
||||
s.title = _('Custom Server Settings');
|
||||
|
||||
@@ -44,7 +44,7 @@ custom_instance() {
|
||||
[ -n "$hostname" ] && ARGS="$ARGS --hostname=$hostname"
|
||||
[ "$acceptDNS" = "0" ] && ARGS="$ARGS --accept-dns=false"
|
||||
[ "$advertiseExitNode" = "1" ] && ARGS="$ARGS --advertise-exit-node"
|
||||
[ -n "$advertiseRoutes" ] && ARGS="$ARGS --advertise-routes=$advertiseRoutes"
|
||||
[ -n "$advertiseRoutes" ] && ARGS="$ARGS --advertise-routes=$(echo $advertiseRoutes | tr ' ' ',')"
|
||||
[ "$s2s" = "1" ] && ARGS="$ARGS --snat-subnet-routes=false"
|
||||
[ -n "$flags" ] && ARGS="$ARGS $flags"
|
||||
[ -n "$loginServer" ] && ARGS="$ARGS --login-server=$loginServer"
|
||||
@@ -100,7 +100,6 @@ custom_instance() {
|
||||
else
|
||||
uci -q delete firewall.tszone
|
||||
fi
|
||||
|
||||
if [ "${access//tsfwlan/}" != "$access" ]; then
|
||||
uci set firewall.tsfwlan=forwarding
|
||||
uci set firewall.tsfwlan.dest='lan'
|
||||
|
||||
Reference in New Issue
Block a user