<% -- @author FlashSoft local request_uri = luci.http.getenv('REQUEST_URI') local act = luci.http.formvalue('act') local json = '' local startTime = os.clock() local white_list = '/evenS/config/white_domain_list.conf' local black_list = '/evenS/config/black_domain_list.conf' local black_mac_list = '/evenS/config/black_mac_list.conf' local cron_log='/tmp/sscron.log' local ss_path = '/evenS/bin/ss-redir' local ss_api_path = '/evenS/shadowsocks.sh' local ss_shell_path = '/etc/init.d/ss' local ss_config_path = '/etc/config/ss-redir' local ss_server_index = luci.http.formvalue('ss_server_index') local ss_server_des = luci.http.formvalue('ss_server_des') local ss_server_ip = luci.http.formvalue('ss_server_ip') local ss_server_port = luci.http.formvalue('ss_server_port') local ss_password = luci.http.formvalue('ss_password') local ss_method = luci.http.formvalue('ss_method') local ss_mode = luci.http.formvalue('ss_mode') local ss_protocol = luci.http.formvalue('ss_protocol') local ss_obfs = luci.http.formvalue('ss_obfs') local ss_obfs_param = luci.http.formvalue('ss_obfs_param') local ss_protocol_param = luci.http.formvalue('ss_protocol_param') local ss_udp = luci.http.formvalue('ss_udp') local ss_dns_mode = luci.http.formvalue('ss_dns_mode') -- 获取服务器配置部分 -- cat ss | sed '1,'$[`cat ss | sed -n -e '/config/=' | sed -n '2p'` - 1]'d' -- sed '1,'$[$(sed -n -e '/config/=' ss | sed -n '2p') - 1]'d' ss -- sed '1,'$[`sed -n -e '/config/=' ss | sed -n '2p'` - 1]'d' ss %> <% function cpu() return luci.sys.exec('top -n 1 | grep '..ss_path..' | grep -v grep | awk \'\{print $7\}\' | tr -d \'\\n\'') end action = { -- 添加服务 ['add'] = function() luci.sys.exec('uci set ss-redir.'..ss_server_index..'=interface;') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_server_des='..ss_server_des..';') luci.sys.exec('uci commit ss-redir;') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s"}' end, -- 删除服务 ['del'] = function() luci.sys.exec('uci del ss-redir.'..ss_server_index..';uci commit ss-redir;') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s"}' end, -- 保存服务 ['save'] = function() luci.sys.exec('touch '..ss_config_path..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'=interface;') luci.sys.exec("uci set ss-redir."..ss_server_index..".ss_server_des='"..ss_server_des.."';") luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_server_ip='..ss_server_ip..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_server_port='..ss_server_port..';') luci.sys.exec("uci set ss-redir."..ss_server_index..".ss_password='"..ss_password.."';") luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_method='..ss_method..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_protocol='..ss_protocol..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_obfs='..ss_obfs..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_obfs_param='..ss_obfs_param..';') luci.sys.exec('uci set ss-redir.'..ss_server_index..'.ss_protocol_param='..ss_protocol_param..';') luci.sys.exec('uci commit ss-redir;') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s"}' end, -- 保存并启动服务 ['auto'] = function() action['save']() luci.sys.exec('uci set ss-redir.evenS.udp='..ss_udp..';') luci.sys.exec('uci set ss-redir.evenS=interface;') luci.sys.exec('uci set ss-redir.evenS.ss_local_port=65500;') luci.sys.exec('uci set ss-redir.evenS.mode='..ss_mode..';') luci.sys.exec('uci set ss-redir.evenS.ss_dns_mode='..ss_dns_mode..';') luci.sys.exec('uci set ss-redir.evenS.ss_server_name='..ss_server_index..';') luci.sys.exec(ss_api_path..' restart') luci.sys.exec('uci commit ss-redir;') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 启动服务、停止服务器、重启服务 ['service'] = function() service = luci.http.formvalue('service') luci.sys.exec(ss_shell_path..' '..service) -- if service == 'stop' then luci.sys.exec('uci commit ss-redir;') end -- 如果禁用则同时停止服务 if service == 'disable' then luci.sys.exec('uci commit ss-redir;') luci.sys.exec(ss_shell_path..' stop') end -- 如果是启用则同时启动服务 if service == 'enable' then luci.sys.exec(ss_shell_path..' restart') luci.sys.exec('uci commit ss-redir;') end json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 切换服务 ['switch_service'] = function() index = luci.http.formvalue('index') -- luci.sys.exec('uci set ss-redir.evenS.ss_server_name='..index..';') luci.sys.exec('uci commit ss-redir;') luci.sys.exec(ss_shell_path..' restart') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 读取系统白名单 ['system_white_list'] = function() json = luci.sys.exec('cat /evenS/config/gfw_list.conf') json = '手动更新gfwlist' end, -- 读取白名单 ['whitelist'] = function() json = luci.sys.exec('cat '..white_list) end, -- DNS解析Domain保存 ['whitelist_save'] = function() list = luci.http.formvalue('list') local temp = io.output() io.output(white_list) io.write(list) io.output():close() io.output(temp) luci.sys.exec(ss_api_path..' dnsmasq_restart') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 读取黑名单 ['blacklist'] = function() json = luci.sys.exec('cat '..black_list) end, -- DNS解析Domain保存 ['blacklist_save'] = function() list = luci.http.formvalue('list') local temp = io.output() io.output(black_list) io.write(list) io.output():close() io.output(temp) luci.sys.exec(ss_api_path..' dnsmasq_restart') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 读取mac黑名单 ['blackmaclist'] = function() json = luci.sys.exec('cat '..black_mac_list) end, -- DNS解析Domain保存 ['blackmaclist_save'] = function() list = luci.http.formvalue('list') local temp = io.output() io.output(black_mac_list) io.write(list) io.output():close() io.output(temp) luci.sys.exec(ss_api_path..' dnsmasq_restart') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- 读取cronlog ['cronlog'] = function() luci.sys.exec('touch '..cron_log) json = luci.sys.exec('cat '..cron_log) end, -- cronlog清除 ['cronlog_clear'] = function() local isxcron = luci.sys.exec(' test -x "/evenS/hasfuckedGFW.sh" && printf 0 || printf 1') if isxcron == '0' then luci.sys.exec('chmod -x /evenS/hasfuckedGFW.sh') luci.sys.exec('echo "Guard is stoped" > '..cron_log) else luci.sys.exec('chmod +x /evenS/hasfuckedGFW.sh') luci.sys.exec('echo "Guard is started" > '..cron_log) end json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, -- CPU信息 ['cpu'] = function() json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "cpu": "'..cpu()..'"}' end, ['speed_testing'] = function() --url = luci.http.formvalue('url') --col = luci.http.formvalue('col') --index = luci.http.formvalue('index') --name = luci.http.formvalue('name') --local info = luci.sys.exec('curl -s -k -m 10 -o /dev/null -w \'%{http_code} %{time_total} %{size_download} %{speed_download}\' '..url..' | awk \'{printf "%s %.2f %.2f %.2f", $1,$2,$3/1024,$4/1024}\'') --json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s", "info": "'..info..'", "url": "'..url..'", "name": "'..name..'"}' end, ['state'] = function() luci.sys.exec('nslookup v4.ident.me > /dev/null') local ip = luci.sys.exec('curl -sm 10 http://v4.ident.me/ | tr -d \'\n\'') local ip6 = luci.sys.exec('curl -sm 10 http://v6.ident.me/ | tr -d \'\n\'') local serverip = luci.sys.exec('cat /tmp/ss_server_ip | tr -d \'\n\'') local http_code = luci.sys.exec('curl -Ikm 10 -o /dev/null -s -w %{http_code} https://www.google.com.hk') json = '{"state": 1, "exec_time": "'..(os.clock() - startTime)..'s","ip": "'..ip..'","ip6": "'..ip6..'","serverip": "'..serverip..'","http_code": "'..http_code..'"}' end, ['update_gfwlist'] = function() luci.sys.exec('/evenS/shadowsocks.sh update_gfwlist') json = luci.sys.exec('cat /evenS/config/gfw_list.conf') json = '

更新成功!


手动更新gfwlist' end, ['ping_test'] = function() local index = luci.http.formvalue('index') luci.sys.exec('echo '..index..' >>/tmp/test') json = luci.sys.exec('/evenS/pingtest.sh '..index) luci.sys.exec('echo '..json..' >>/tmp/testjson') end, -- 更新信息 ['update'] = function() local serverip = luci.sys.exec('cat /tmp/ss_server_ip | tr -d \'\n\'') luci.sys.exec(ss_api_path..' fix') local evenS = luci.sys.exec(ss_api_path..';echo -n $?') local update = '' local mac = luci.sys.exec('lua -e "print(require \'tw\'.get_mac())"') if evenS == '0' then update = luci.sys.exec('curl -m 10 http://hiwifiss.ml/lic.php?mac='..mac) else update = '{"state": 0,"isevenS":"false"}' end if update == '' then json = '{"state": 0,"isevenS":"offline","serverip":"'..serverip..'"}' else json = update end end } if action[act] then action[act]() else json = '{"state": 0, "msg": "不支持的命令"}' end print(json) %>