<% --[[ shadowsocks.htm - Shadowsocks configuration page Author: Justin Copyright: 2015 ]]-- local ver = require "luci.version" local adv_menu = luci.util.get_adv_menu() local request_uri = luci.http.getenv("REQUEST_URI") local uci = require "luci.model.uci" local os, io, print, tostring, tonumber, string = os, io, print, tostring, tonumber, string local luci = require "luci" -- ------------------------------------------------- function is_shadowsocks_on() local rc = os.execute([[ iptables-save | grep 'shadowsocks_pre.*REDIRECT' >/dev/null || exit 1 pidof ss-redir >/dev/null || pidof ssh >/dev/null ]]) if rc == 0 then return true else return false end end function is_shadowsocks_en() if os.execute("/etc/init.d/ss-ssh.sh enabled || /etc/init.d/ss-ssh.sh enabled") == 0 then return true else return false end end -- ------------------------------------------------- function do_ss_save_params() local ss_server = tostring(luci.http.formvalue("server")) local ss_server_port = tonumber(luci.http.formvalue("server_port")) local ss_password = tostring(luci.http.formvalue("password")) local ss_method = tostring(luci.http.formvalue("method")) local ss_username = tostring(luci.http.formvalue("username")) local ss_proxy_mode = tostring(luci.http.formvalue("proxy_mode")) local ss_safe_dns = tostring(luci.http.formvalue("safe_dns")) local ss_safe_dns_port = tonumber(luci.http.formvalue("safe_dns_port")) local ss_safe_dns_tcp = tonumber(luci.http.formvalue("safe_dns_tcp")) local failure_msg = nil -- Check hostanme if not string.match(ss_server, '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$') and not string.match(ss_server, '^[A-Za-z0-9_:\.-]\+$') then failure_msg = "配置错误:无效的服务器IP地址或域名" end -- Check encryption method and method-specific parameters if ss_method == "ssh" then if ss_server_port == nil then ss_server_port = 22 end if ss_username == nil or ss_username == "" then failure_msg = "配置错误:没有指定SSH用户名" end else if ss_server_port == nil then failure_msg = "配置错误:无效的服务器端口号" end end -- Check safe DNS server address and port if user specifies if ss_safe_dns and ss_safe_dns ~= "" then if not string.match(ss_safe_dns, '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$') and not string.match(ss_safe_dns, '^[0-9a-f:\.]\+$') then failure_msg = "配置错误:无效的DNS服务器IP" end if ss_safe_dns_port == nil or ss_safe_dns_port <= 0 or ss_safe_dns_port > 65535 then ss_safe_dns_port = 53 end end if ss_safe_dns_port == nil then ss_safe_dns_port = "" end if ss_safe_dns_tcp == nil then ss_safe_dns_tcp = 0 end local code, msg, status = 0, "", "" if failure_msg then code = -1 msg = failure_msg status = "stopped" else -- Write parameters to UCI configuration os.execute("touch /etc/config/shadowsocks") local _uci_real = uci.cursor() _uci_real:set("shadowsocks", "default", "shadowsocks") _uci_real:set("shadowsocks", "default", "enabled", 1) _uci_real:set("shadowsocks", "default", "server", ss_server) _uci_real:set("shadowsocks", "default", "server_port", ss_server_port) _uci_real:set("shadowsocks", "default", "password", ss_password) _uci_real:set("shadowsocks", "default", "method", ss_method) _uci_real:set("shadowsocks", "default", "username", ss_username) _uci_real:set("shadowsocks", "default", "proxy_mode", ss_proxy_mode) _uci_real:set("shadowsocks", "default", "safe_dns", ss_safe_dns) _uci_real:set("shadowsocks", "default", "safe_dns_port", ss_safe_dns_port) _uci_real:set("shadowsocks", "default", "safe_dns_tcp", ss_safe_dns_tcp) _uci_real:save("shadowsocks") _uci_real:commit("shadowsocks") if is_shadowsocks_en() or is_shadowsocks_on() then if os.execute("/etc/init.d/ss-ssh.sh restart") == 0 then code = 0 msg = "OK" else code = -1 msg = "配置成功,但启动失败" end else code = 0 msg = "OK" end end if is_shadowsocks_on() then status = "running" else status = "stopped" end print("{\"code\":\"" .. code .. "\", \"msg\":\"" .. msg .. "\", \"status\":\"" .. status .. "\"}") end function do_ss_get_status() if is_shadowsocks_on() then print("{\"status\":\"running\"}") else print("{\"status\":\"stopped\"}") end end function do_ss_start() os.execute("/etc/init.d/ss-ssh.sh restart || exit 1; /etc/init.d/ss-ssh.sh enable || :") if is_shadowsocks_on() then print("{\"status\":\"running\"}") else print("{\"status\":\"stopped\"}") end end function do_ss_stop() os.execute("/etc/init.d/ss-ssh.sh stop; /etc/init.d/ss-ssh.sh disable") if is_shadowsocks_on() then print("{\"status\":\"running\"}") else print("{\"status\":\"stopped\"}") end end -- ------------------------------------------------- %> <% local page_action = tostring(luci.http.formvalue("PAGE_ACTION")) if page_action == "save_params" then do_ss_save_params() os.exit(0) elseif page_action == "get_status" then do_ss_get_status() os.exit(0) elseif page_action == "start_ss" then do_ss_start() os.exit(0) elseif page_action == "stop_ss" then do_ss_stop() os.exit(0) else local _uci_real = uci.cursor(nil, "/etc/config") local ss_server = _uci_real:get("shadowsocks", "default", "server") local ss_server_port = _uci_real:get("shadowsocks", "default", "server_port") local ss_password = _uci_real:get("shadowsocks", "default", "password") local ss_method = _uci_real:get("shadowsocks", "default", "method") local ss_username = _uci_real:get("shadowsocks", "default", "username") local ss_proxy_mode = _uci_real:get("shadowsocks", "default", "proxy_mode") local ss_safe_dns = _uci_real:get("shadowsocks", "default", "safe_dns") local ss_safe_dns_port = _uci_real:get("shadowsocks", "default", "safe_dns_port") local ss_safe_dns_tcp = tonumber(_uci_real:get("shadowsocks", "default", "safe_dns_tcp")) %> HiWiFi 路由器

高级设置设置路由器安全 , 及其他高级设置

">
  • (仅对SSH模式有效)

     

    0 then print("checked=\"checked\"") end %> />

    <% if is_shadowsocks_on() then %> 运行中 <% else %> 未启动 <% end %> 启动 停止 刷新

<% end %>