diff options
Diffstat (limited to 'applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/shadowsocks-libev.js')
-rw-r--r-- | applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/shadowsocks-libev.js | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/shadowsocks-libev.js b/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/shadowsocks-libev.js new file mode 100644 index 0000000000..3aaaa50121 --- /dev/null +++ b/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/shadowsocks-libev.js @@ -0,0 +1,242 @@ +'use strict'; +'require uci'; +'require form'; +'require network'; + +var names_options_server = [ + 'server', + 'server_port', + 'method', + 'key', + 'password', + 'plugin', + 'plugin_opts', +]; + +var names_options_client = [ + 'server', + 'local_address', + 'local_port', +]; + +var names_options_common = [ + 'verbose', + 'ipv6_first', + 'fast_open', + 'no_delay', + 'reuse_port', + 'mode', + 'mtu', + 'timeout', + 'user', +]; + +var modes = [ + 'tcp_only', + 'tcp_and_udp', + 'udp_only', +]; + +var methods = [ + // aead + 'aes-128-gcm', + 'aes-192-gcm', + 'aes-256-gcm', + 'chacha20-ietf-poly1305', + 'xchacha20-ietf-poly1305', + // stream + 'table', + 'rc4', + 'rc4-md5', + 'aes-128-cfb', + 'aes-192-cfb', + 'aes-256-cfb', + 'aes-128-ctr', + 'aes-192-ctr', + 'aes-256-ctr', + 'bf-cfb', + 'camellia-128-cfb', + 'camellia-192-cfb', + 'camellia-256-cfb', + 'salsa20', + 'chacha20', + 'chacha20-ietf', +]; + +function ucival_to_bool(val) { + return val === 'true' || val === '1' || val === 'yes' || val === 'on'; +} + +return L.Class.extend({ + values_actions: function(o) { + o.value('bypass'); + o.value('forward'); + if (o.option !== 'dst_default') { + o.value('checkdst'); + } + }, + values_redir: function(o, xmode) { + uci.sections('shadowsocks-libev', 'ss_redir', function(sdata) { + var disabled = ucival_to_bool(sdata['disabled']), + sname = sdata['.name'], + mode = sdata['mode'] || 'tcp_only'; + if (!disabled && mode.indexOf(xmode) !== -1) { + o.value(sname, sname + ' - ' + mode); + } + }); + o.value('', '<unset>'); + o.default = ''; + }, + values_serverlist: function(o) { + uci.sections('shadowsocks-libev', 'server', function(sdata) { + var sname = sdata['.name'], + server = sdata['server'], + server_port = sdata['server_port']; + if (server && server_port) { + var disabled = ucival_to_bool(sdata['.disabled']) ? ' - disabled' : '', + desc = '%s - %s:%s%s'.format(sname, server, server_port, disabled); + o.value(sname, desc); + } + }); + }, + values_ipaddr: function(o, netDevs) { + netDevs.forEach(function(v) { + v.getIPAddrs().forEach(function(a) { + var host = a.split('/')[0]; + o.value(host, '%s (%s)'.format(host, v.getShortName())); + }); + }); + }, + options_client: function(s, tab, netDevs) { + var o = s.taboption(tab, form.ListValue, 'server', _('Remote server')); + this.values_serverlist(o); + o = s.taboption(tab, form.Value, 'local_address', _('Local address')); + o.datatype = 'ipaddr'; + o.placeholder = '0.0.0.0'; + this.values_ipaddr(o, netDevs); + o = s.taboption(tab, form.Value, 'local_port', _('Local port')); + o.datatype = 'port'; + }, + options_server: function(s, opts) { + var o, optfunc, + tab = opts && opts.tab || null; + + if (!tab) { + optfunc = function(/* ... */) { + var o = s.option.apply(s, arguments); + o.editable = true; + return o; + }; + } else { + optfunc = function(/* ... */) { + var o = s.taboption.apply(s, L.varargs(arguments, 0, tab)); + o.editable = true; + return o; + }; + } + + o = optfunc(form.Value, 'server', _('Server')); + o.datatype = 'host'; + o.size = 16; + + o = optfunc(form.Value, 'server_port', _('Server port')); + o.datatype = 'port'; + o.size = 5; + + o = optfunc(form.ListValue, 'method', _('Method')); + methods.forEach(function(m) { + o.value(m); + }); + + o = optfunc(form.Value, 'password', _('Password')); + o.password = true; + o.size = 12; + + o = optfunc(form.Value, 'key', _('Key (base64)')); + o.datatype = 'base64'; + o.password = true; + o.size = 12; + o.modalonly = true;; + + optfunc(form.Value, 'plugin', _('Plugin')).modalonly = true; + + optfunc(form.Value, 'plugin_opts', _('Plugin Options')).modalonly = true; + }, + options_common: function(s, tab) { + var o = s.taboption(tab, form.ListValue, 'mode', _('Mode of operation')); + modes.forEach(function(m) { + o.value(m); + }); + o.default = 'tcp_and_udp'; + o = s.taboption(tab, form.Value, 'mtu', _('MTU')); + o.datatype = 'uinteger'; + o = s.taboption(tab, form.Value, 'timeout', _('Timeout (sec)')); + o.datatype = 'uinteger'; + s.taboption(tab, form.Value, 'user', _('Run as')); + + s.taboption(tab, form.Flag, 'verbose', _('Verbose')); + s.taboption(tab, form.Flag, 'ipv6_first', _('IPv6 First'), _('Prefer IPv6 addresses when resolving names')); + s.taboption(tab, form.Flag, 'fast_open', _('Enable TCP Fast Open')); + s.taboption(tab, form.Flag, 'no_delay', _('Enable TCP_NODELAY')); + s.taboption(tab, form.Flag, 'reuse_port', _('Enable SO_REUSEPORT')); + }, + ucival_to_bool: function(val) { + return ucival_to_bool(val); + }, + cfgvalue_overview: function(sdata) { + var stype = sdata['.type'], + lines = []; + + if (stype === 'ss_server') { + this.cfgvalue_overview_(sdata, lines, names_options_server); + this.cfgvalue_overview_(sdata, lines, names_options_common); + this.cfgvalue_overview_(sdata, lines, ['bind_address']); + } else if (stype === 'ss_local' || stype === 'ss_redir' || stype === 'ss_tunnel') { + this.cfgvalue_overview_(sdata, lines, names_options_client); + if (stype === 'ss_tunnel') { + this.cfgvalue_overview_(sdata, lines, ['tunnel_address']); + } + this.cfgvalue_overview_(sdata, lines, names_options_common); + } else { + return []; + } + + return lines; + }, + cfgvalue_overview_: function(sdata, lines, names) { + names.forEach(function(n) { + var v = sdata[n]; + if (v) { + if (n === 'key' || n === 'password') { + v = _('<hidden>'); + } + var fv = E('var', [v]); + if (sdata['.type'] !== 'ss_server' && n === 'server') { + fv = E('a', { + class: 'label', + href: L.url('admin/services/shadowsocks-libev/servers') + '#edit=' + v, + target: '_blank', + rel: 'noopener' + }, fv); + } + lines.push(n + ': ', fv, E('br')); + } + }); + }, + option_install_package: function(s, tab) { + var bin = s.sectiontype.replace('_', '-'), + opkg_package = 'shadowsocks-libev-' + bin, o; + if (tab) { + o = s.taboption(tab, form.Button, '_install'); + } else { + o = s.option(form.Button, '_install'); + } + o.title = _('Package is not installed'); + o.inputtitle = _('Install package ' + opkg_package); + o.inputstyle = 'apply'; + o.onclick = function() { + window.open(L.url('admin/system/opkg') + + '?query=' + opkg_package, '_blank', 'noopener'); + }; + } +}); |