mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-19 03:43:29 +00:00
replace kuainiao with xlnetacc from sensel
This commit is contained in:
parent
16c2522ec2
commit
8e2184a58d
@ -1,17 +0,0 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Kuainiao
|
||||
LUCI_DEPENDS:=+kmod-ppp +openssl-util +wget +kmod-mppe
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=3
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
@ -1,34 +0,0 @@
|
||||
module("luci.controller.kuainiao", package.seeall)
|
||||
|
||||
function index()
|
||||
local fs = luci.fs or nixio.fs
|
||||
if not fs.access("/etc/config/kuainiao") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "services", "kuainiao"}, cbi("kuainiao"), _("Kuai Niao"),201)
|
||||
page.dependent = true
|
||||
entry({"admin","services","kuainiao","status"},call("kuainiao_status")).leaf=true
|
||||
entry({"admin","services","kuainiao","dwonstatus"},call("down_status")).leaf=true
|
||||
entry({"admin","services","kuainiao","upstatus"},call("up_status")).leaf=true
|
||||
end
|
||||
|
||||
function kuainiao_status()
|
||||
local e={}
|
||||
e.running=luci.sys.exec("ps |grep -v grep |grep -w '/usr/bin/kuainiao' ")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function up_status()
|
||||
local e={}
|
||||
e.upstatus=luci.sys.exec("cat /usr/share/kuainiao/kuainiao_up_state")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
function down_status()
|
||||
local e={}
|
||||
e.dwonstatus=luci.sys.exec("cat /usr/share/kuainiao/kuainiao_down_state")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
@ -1,59 +0,0 @@
|
||||
#fork from https://github.com/zz090923610/thunder-fastNiao,thanks to zz090923610
|
||||
require("luci.sys")
|
||||
require("luci.sys.zoneinfo")
|
||||
require("luci.config")
|
||||
local fs = require "nixio.fs"
|
||||
local ut = require "luci.util"
|
||||
local o=require"luci.model.network".init()
|
||||
local sys = require "luci.sys"
|
||||
local m,t,e
|
||||
m = Map("kuainiao", translate("迅雷快鸟"),translate("迅雷快鸟是迅雷联合宽带运营商推出的一款致力于帮助用户解决宽带低、网速慢、上网体验差的专业级宽带加速软件。"))
|
||||
m:section(SimpleSection).template = "kuainiao/kuainiao_status"
|
||||
s = m:section(NamedSection, "base", "kuainiao", translate("首次使用请填写完帐号密码保存提交一次,之后再启用。"))
|
||||
s.addremove = false
|
||||
s:tab("base",translate("Basic Settings"))
|
||||
s:tab("log",translate("快鸟日志"))
|
||||
enabled = s:taboption("base",Flag, "enabled", translate("Enable"))
|
||||
enabled.default=0
|
||||
enabled.rmempty = false
|
||||
enable_down = s:taboption("base",Flag, "enable_down", translate("开启下行加速"))
|
||||
enable_down.default=1
|
||||
enabled.rmempty = false
|
||||
enable_down:depends("enabled",1)
|
||||
|
||||
enable_up = s:taboption("base",Flag, "enable_up", translate("开启上行加速"))
|
||||
enable_up.default=0
|
||||
enabled.rmempty = false
|
||||
enable_up:depends("enabled",1)
|
||||
local a
|
||||
speed_wan=s:taboption("base",ListValue,"speed_wan",translate("指定加速的接口"))
|
||||
for a,s in ipairs(o:get_networks())do
|
||||
if s:name()~="loopback" and s:name()~="lan" then speed_wan:value(s:name())end
|
||||
end
|
||||
username = s:taboption("base",Value, "kuainiao_name", translate("迅雷快鸟帐号"))
|
||||
username.datatype = "minlength(1)"
|
||||
username.rmempty = false
|
||||
password = s:taboption("base",Value, "kuainiao_passwd", translate("迅雷快鸟密码"))
|
||||
password.password = true
|
||||
password.datatype = "minlength(1)"
|
||||
password.rmempty = false
|
||||
kuainiao_config_pwd = s:taboption("base",Value, "kuainiao_config_pwd", translate("加密后密码(自动生成,勿修改)"))
|
||||
kuainiao_config_pwd.password = true
|
||||
kuainiao_config_pwd.datatype = "minlength(1)"
|
||||
kuainiao_config_pwd.rmempty = true
|
||||
--kuainiao_config_pwd.readonly=true
|
||||
log=s:taboption("log",TextValue,"log")
|
||||
log.rows=26
|
||||
log.wrap="off"
|
||||
log.readonly=true
|
||||
log.cfgvalue=function(t,t)
|
||||
return nixio.fs.readfile("/var/log/kuainiao.log")or""
|
||||
end
|
||||
log.write=function(log,log,log)
|
||||
end
|
||||
m:section(SimpleSection).template = "kuainiao/kuainiao_rsa"
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
io.popen("luci_kuainiao_apply")
|
||||
end
|
||||
return m
|
@ -1,25 +0,0 @@
|
||||
<%#
|
||||
Copyright (C) 2017 Jian Chang <aa65535@live.com>
|
||||
Licensed to the public under the GNU General Public License v3.
|
||||
-%>
|
||||
<script type="text/javascript" src="<%=resource%>/md5.js"></script>
|
||||
<script type="text/javascript" src="<%=resource%>/sha1.js"></script>
|
||||
<script type="text/javascript" src="<%=resource%>/rsa.js"></script>
|
||||
<script type="text/javascript">
|
||||
var kn = 'AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B021E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78AF146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F5DBCEBE22F89D640F5336E42F587DC4AFEDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E36FD';
|
||||
var ke = '010001';
|
||||
var rsa = new RSAKey();
|
||||
rsa.setPublic(kn, ke);
|
||||
</script>
|
||||
<% include("cbi/map") %>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!-- var mac = document.getElementById('cbid.kuainiao.base.wanmac').value;-->
|
||||
<!--var fake_device_id = md5(mac);-->
|
||||
<!--var device_sign = "div100."+fake_device_id+md5(hex_sha1(fake_device_id+"com.xunlei.vip.swjsq68700d1872b772946a6940e4b51827e8af")); -->
|
||||
var password = document.getElementById('cbid.kuainiao.base.kuainiao_passwd').value;
|
||||
var encrypted_pwd = rsa.encrypt(md5(password));
|
||||
var kuainiao_conf_pwd=encrypted_pwd.toUpperCase();
|
||||
document.getElementById('cbid.kuainiao.base.kuainiao_config_pwd').value = kuainiao_conf_pwd;
|
||||
<!-- document.getElementById('cbid.kuainiao.base.device_sign').value = device_sign; -->
|
||||
</script>
|
@ -1,38 +0,0 @@
|
||||
<%#
|
||||
Copyright 2017 Lede by stones
|
||||
-%>
|
||||
|
||||
<% include("cbi/map") %>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "kuainiao", "status")%>', null,
|
||||
function(x, result)
|
||||
{
|
||||
var status = document.getElementById('kuainiao_status');
|
||||
status.innerHTML = result.running?'<font color=green><%=translate("RUNNING")%></font>':'<font color=red><%=translate("NOT RUNNING")%></font>';
|
||||
}
|
||||
);
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "kuainiao", "dwonstatus")%>', null,
|
||||
function(x, result)
|
||||
{
|
||||
var dwonstatus = document.getElementById('dwon_status');
|
||||
dwonstatus.innerHTML = (result.dwonstatus?result.dwonstatus:"--");
|
||||
}
|
||||
);
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "kuainiao", "upstatus")%>', null,
|
||||
function(x, result)
|
||||
{
|
||||
var upstatus = document.getElementById('up_status');
|
||||
upstatus.innerHTML = (result.upstatus?result.upstatus:"--");
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<%:快鸟运行状态:%><em id="kuainiao_status"><%:Collecting data...%></em>
|
||||
<legend></legend>
|
||||
<legend></legend>
|
||||
<%:下行提速状态:%><em id="dwon_status"><%:Collecting data...%></em>
|
||||
<legend></legend>
|
||||
<%:上行提速状态:%><em id="up_status"><%:Collecting data...%></em>
|
||||
</fieldset>
|
@ -1,4 +0,0 @@
|
||||
msgid "Kuai Niao"
|
||||
msgstr "迅雷快鸟"
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
|
||||
config kuainiao 'base'
|
||||
option kuainiao_name ''
|
||||
option kuainiao_passwd ''
|
||||
option speed_wan 'wan'
|
||||
option enabled '0'
|
||||
option enable_down '1'
|
||||
option enable_up '0'
|
@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
. /lib/functions.sh
|
||||
|
||||
enabled=`uci -q get kuainiao.base.enabled`
|
||||
[ "enabled" -eq 1 ] || exit 0
|
||||
[ "$ACTION" = ifup ] && {
|
||||
logger -t Thunder kuainiao has reloaded due to Device: $DEVICE Action: $ACTION ;
|
||||
/etc/init.d/kuainiao stop && sleep 2;
|
||||
/etc/init.d/kuainiao start;
|
||||
}
|
||||
|
||||
[ "$ACTION" = ifdown ] && {
|
||||
logger -t Thunder KuaiNiao has stoped due to Device: $DEVICE Action: $ACTION ;
|
||||
/etc/init.d/kuainiao stop;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
STOP=15
|
||||
SERVICE_WRITE_PID=1
|
||||
SERVICE_DAEMONIZE=1
|
||||
LOGFILE=/var/log/kuainiao.log
|
||||
|
||||
start_service()
|
||||
{
|
||||
procd_open_instance
|
||||
procd_set_param command /usr/bin/kuainiao
|
||||
procd_set_param respawn ${respawn_threshold:-5} ${respawn_timeout:-300} ${respawn_retry:-10}
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service(){
|
||||
clean_log
|
||||
pid_kuainiao=`ps | grep -v grep | grep -w "/usr/bin/kuainiao" |awk '{print $1}' 2>/dev/null`
|
||||
[ -n "$pid_kuainiao" ] && {
|
||||
for pid in $pid_kuainiao
|
||||
do
|
||||
echo "Stop service kuainiao PID: $pid"
|
||||
kill $pid 2>/dev/null
|
||||
for spid in `pgrep sleep`
|
||||
do
|
||||
ppid=`cat /proc/$spid/status | grep -w "PPid" | awk '{print $2}'`
|
||||
[ "$ppid" -eq "$pid" ] && kill $spid 2>/dev/null && echo "Stop service kuainiao SPID: $spid"
|
||||
done
|
||||
done
|
||||
}
|
||||
echo "<font color=red>暂无加速信息</font>" > /usr/share/kuainiao/kuainiao_down_state
|
||||
echo "<font color=red>暂无加速信息</font>" > /usr/share/kuainiao/kuainiao_up_state
|
||||
}
|
||||
|
||||
clean_log() {
|
||||
[ -f "$LOGFILE" ] && {
|
||||
logsnum=$(cat $LOGFILE | grep -c .)
|
||||
if [ $logsnum -gt 300 ];then
|
||||
rm -f $LOGFILE >/dev/null 2>&1 &
|
||||
echo "$(date): 日志文件过长,清空处理!" >> $LOGFILE
|
||||
fi
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@kuainiao[-1]
|
||||
add ucitrack kuainiao
|
||||
set ucitrack.@kuainiao[-1].init=kuainiao
|
||||
commit ucitrack
|
||||
EOF
|
||||
exit 0
|
@ -1,606 +0,0 @@
|
||||
#!/bin/sh
|
||||
#2017/05/01 by kenney
|
||||
#2017/07/19 update for lede by stones
|
||||
. /lib/functions.sh
|
||||
|
||||
LOGFILE=/var/log/kuainiao.log
|
||||
down_state_file=/usr/share/kuainiao/kuainiao_down_state
|
||||
up_state_file=/usr/share/kuainiao/kuainiao_up_state
|
||||
version="0.4"
|
||||
app_version="2.0.3.4"
|
||||
protocolVersion=108
|
||||
sdkVersion=17550
|
||||
logmore=0 #打印更详细日志排查
|
||||
|
||||
|
||||
logmore(){
|
||||
data=$1
|
||||
[ "$logmore" -eq 1 ] && {
|
||||
echo $(date): $data >> $LOGFILE
|
||||
}
|
||||
}
|
||||
|
||||
log_down(){
|
||||
kuainiao_down_state=$1
|
||||
status=$2
|
||||
if [ "$status" -eq 1 ]; then
|
||||
echo "<font color=green>$kuainiao_down_state</font>" > $down_state_file
|
||||
else
|
||||
echo "<font color=red>$kuainiao_down_state</font>" > $down_state_file
|
||||
fi
|
||||
}
|
||||
|
||||
log_up(){
|
||||
kuainiao_up_state=$1
|
||||
status=$2
|
||||
if [ "$status" -eq 1 ]; then
|
||||
echo "<font color=green>$kuainiao_up_state</font>" > $up_state_file
|
||||
else
|
||||
echo "<font color=red>$kuainiao_up_state</font>" > $up_state_file
|
||||
fi
|
||||
}
|
||||
|
||||
#WAN接口IP判断
|
||||
get_bind_address(){
|
||||
ifname=$(uci -P /var/state get network.$kuainiao_config_wan.ifname 2>/dev/null)
|
||||
[ $? -eq 1 ] && echo $(date): "获取网络 $kuainiao_config_wan 信息出错" >>$LOGFILE && echo >>$LOGFILE && return
|
||||
logmore "ifname is $ifname"
|
||||
##wan_selected 所选接口IP
|
||||
wan_selected=$(ifconfig $ifname 2>/dev/null | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null)
|
||||
[ -z "$wan_selected" ] && echo $(date): "获取网络 $kuainiao_config_wan 接口 $ifname 信息出错" >>$LOGFILE && echo >>$LOGFILE && return
|
||||
if [ "$wan_selected" != "0.0.0.0" ]; then
|
||||
bind_address=$wan_selected
|
||||
else
|
||||
bind_address=""
|
||||
fi
|
||||
}
|
||||
|
||||
#定义请求函数
|
||||
#bind_address='113.248.3.11'
|
||||
get_http_req(){
|
||||
if [ -n "$bind_address" ]; then
|
||||
HTTP_REQ="wget --bind-address=$bind_address --no-check-certificate -O - "
|
||||
POST_ARG="--post-data="
|
||||
else
|
||||
HTTP_REQ="wget --no-check-certificate -O - "
|
||||
POST_ARG="--post-data="
|
||||
fi
|
||||
kuainiao_HTTP_REQ=$HTTP_REQ
|
||||
kuainiao_POST_ARG=$POST_ARG
|
||||
}
|
||||
|
||||
#数据mock
|
||||
|
||||
generate_pwd_rsa_hex()
|
||||
{
|
||||
# calculate passwd_md5
|
||||
logmore "Generating passwd md5"
|
||||
passwd_md5=`echo -n "$kuainiao_config_pwd" | md5sum | tr -d " -"`
|
||||
|
||||
if [ `echo -n "$passwd_md5" | wc -c` -ne 32 ]; then
|
||||
logmore "md5sum should be 32 chars, exit."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
logmore "Generating PWD RSA HEX"
|
||||
#first, encoding passwd using rsa
|
||||
a=`echo "$passwd_md5" | openssl rsautl -raw -pubin -inkey /etc/thunder.key -hexdump | tr [a-z] [A-Z]`
|
||||
a=`echo $a | grep -o '00[0-9]0 \- \([A-Z0-9]\{2\}[- ]\)\{16\}' | sed 's/00[0-9]0 - //g' | tr -d " \-\n"`
|
||||
echo -n "$a"
|
||||
|
||||
}
|
||||
|
||||
#pwd='702CFAF5824E4306516F488DEAFC2D24F76C82FA53BA3396F5615FDD32E4430E45B254E136056ED5F3C5B404A08E2178B51330999A4EC3C2D2989D554D7863BDE8F058F44808E6B65F4D071B5D5C7210210DA9ED8D729312CECA39E0F4516143E33C089F616ABE93E14D3224BEB311D3D6EF65A6CE265D3E4ABA285523F14320'
|
||||
|
||||
get_device_sign(){
|
||||
ifname=$(uci get network.$kuainiao_config_wan.ifname 2>/dev/null)
|
||||
wan_mac=$(ifconfig $ifname | grep 'HWaddr' | awk '{print $5}')
|
||||
fake_device_id=$(echo -n "$wan_mac" | md5sum | cut -d ' ' -f1)
|
||||
fake_device_id_tmp1=$(echo -n "$fake_device_id"com.xunlei.vip.swjsq68700d1872b772946a6940e4b51827e8af"" | openssl sha1 -hmac | awk '{print $2}')
|
||||
devicesign="div100."${fake_device_id}$(echo -n "$fake_device_id_tmp1" | md5sum | cut -d ' ' -f1)
|
||||
}
|
||||
|
||||
|
||||
#verifyCode=$kuainiao_config_verifyCode
|
||||
#verifyKey=$kuainiao_verifyKey
|
||||
|
||||
#获取用户真实MAC地址
|
||||
get_mac_addr(){
|
||||
if [ -n "$bind_address" ]; then
|
||||
ifname=$(uci get network.$kuainiao_config_wan.ifname 2>/dev/null)
|
||||
peerid=$(ifconfig $ifname | grep 'HWaddr' | awk '{print $5}' | awk 'gsub(/:/, "")')004V
|
||||
fi
|
||||
#peerid='000C29212478004V'
|
||||
}
|
||||
|
||||
|
||||
#获取迅雷用户uid
|
||||
get_xunlei_uid(){
|
||||
get_http_req
|
||||
logmore "HTTP_REQ is $HTTP_REQ"
|
||||
logmore "POST_ARG is $POST_ARG"
|
||||
uname=$kuainiao_config_uname
|
||||
#get_mac_addr
|
||||
logmore "peerid is $peerid"
|
||||
[ -z "$peerid" ] && exit 0
|
||||
#pwd=$generate_pwd_rsa_hex
|
||||
pwd=$kuainiao_config_pwd
|
||||
get_device_sign
|
||||
logmore "devicesign is $devicesign"
|
||||
ret=`$HTTP_REQ --header "User-Agent:android-async-http/xl-acc-sdk/version-1.6.1.177600" https://login.mobile.reg2t.sandai.net:443/ $POST_ARG"{\"userName\":\""$uname"\",\"businessType\":68,\"clientVersion\":\"$app_version\",\"appName\":\"ANDROID-com.xunlei.vip.swjsq\",\"isCompressed\":0,\"sequenceNo\":1000001,\"sessionID\":\"\",\"loginType\":0,\"rsaKey\":{\"e\":\"010001\",\"n\":\"AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B021E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78AF146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F5DBCEBE22F89D640F5336E42F587DC4AFEDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E36FD\"},\"cmdID\":1,\"verifyCode\":\"$verifyCode\",\"peerID\":\""$peerid"\",\"protocolVersion\":$protocolVersion,\"platformVersion\":1,\"passWord\":\""$pwd"\",\"extensionList\":\"\",\"verifyKey\":\"$verifyKey\",\"sdkVersion\":$sdkVersion,\"devicesign\":\""$devicesign"\"}"`
|
||||
#判断是否登陆成功
|
||||
#echo $ret >>test.txt
|
||||
logmore "........................"
|
||||
logmore "ret is $ret"
|
||||
logmore "........................"
|
||||
session=`echo $ret|awk -F '"sessionID":' '{print $2}'|awk -F '[,}]' '{print $1}'|grep -oE "[A-F,0-9]{32}"`
|
||||
logmore "session is $session"
|
||||
#vcode=`echo $ret|awk -F '"errorDescUrl":' '{print $2}'|awk -F '}' '{print $1}'`
|
||||
#vcode=`echo $vcode|sed 's/\\//g'`
|
||||
errcode=`echo $ret|awk -F '"errorCode":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
logmore "errcode is $errcode"
|
||||
if [ -z "$session" ]; then
|
||||
if [ $errcode == 6 ];then
|
||||
#kuainiao_vcodeimg_url="$vcode"
|
||||
#kuainiao_verifyKey='F9F6FBE928911784D809EBF046ABE0A6A467583F3944507099EA54BC9B5DA7BD'
|
||||
kuainiao_last_act="您的账号不安全,需要输入验证码! $(date "+%Y-%m-%d %H:%M:%S")"
|
||||
|
||||
elif [ $errcode == 12 ];then
|
||||
#kuainiao_vcodeimg_url=""
|
||||
#kuainiao_verifyKey=''
|
||||
kuainiao_last_act="登陆协议无效,请更新!$(date "+%Y-%m-%d %H:%M:%S")"
|
||||
|
||||
elif [ $errcode == 3 ];then
|
||||
#kuainiao_vcodeimg_url=""
|
||||
#kuainiao_verifyKey=''
|
||||
kuainiao_last_act="用户名密码错误,请检查!$(date "+%Y-%m-%d %H:%M:%S")"
|
||||
|
||||
else
|
||||
#kuainiao_vcodeimg_url=""
|
||||
#kuainiao_verifyKey=''
|
||||
kuainiao_last_act="迅雷账号登陆失败,请检查输入的用户名密码! $(date "+%Y-%m-%d %H:%M:%S")"
|
||||
|
||||
fi
|
||||
#echo "迅雷账号登陆失败,请检查输入的用户名密码!"
|
||||
log_down "$kuainiao_last_act" 0
|
||||
|
||||
else
|
||||
uid=`echo $ret|awk -F '"userID":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
kuainiao_config_uid=$uid
|
||||
kuainiao_config_session=$session
|
||||
kuainiao_last_act="迅雷快鸟已登陆成功!"
|
||||
log_down "$kuainiao_last_act" 1
|
||||
fi
|
||||
echo $(date): "$kuainiao_last_act" >> $LOGFILE
|
||||
}
|
||||
|
||||
#获取加速API
|
||||
get_kuainiao_api(){
|
||||
portal=`$HTTP_REQ http://api.portal.swjsq.vip.xunlei.com:81/v2/queryportal`
|
||||
portal_ip=`echo $portal|grep -oE '([0-9]{1,3}[\.]){3}[0-9]{1,3}'`
|
||||
portal_port_temp=`echo $portal|grep -oE "port...[0-9]{1,5}"`
|
||||
portal_port=`echo $portal_port_temp|grep -oE '[0-9]{1,5}'`
|
||||
|
||||
logmore "portal is $portal" >> $LOGFILE
|
||||
logmore "portal_ip is $portal_ip" >> $LOGFILE
|
||||
logmore "portal_port_temp is $portal_port_temp" >> $LOGFILE
|
||||
logmore "portal_port is $portal_port" >> $LOGFILE
|
||||
|
||||
if [ -z "$portal_ip" ]; then
|
||||
kuainiao_down_state="迅雷快鸟下行API获取失败,请检查网络环境,或稍后再试!"
|
||||
echo $(date): "$kuainiao_down_state" >> $LOGFILE
|
||||
log_down "$kuainiao_down_state" 0
|
||||
else
|
||||
api_url="http://$portal_ip:$portal_port/v2"
|
||||
kuainiao_config_api=$api_url
|
||||
fi
|
||||
}
|
||||
|
||||
#获取上行加速API
|
||||
get_kuainiao_upapi(){
|
||||
upportal=`$HTTP_REQ http://api.upportal.swjsq.vip.xunlei.com/v2/queryportal`
|
||||
upportal_ip=`echo $upportal|grep -oE '([0-9]{1,3}[\.]){3}[0-9]{1,3}'`
|
||||
upportal_port_temp=`echo $upportal|grep -oE "port...[0-9]{1,5}"`
|
||||
upportal_port=`echo $upportal_port_temp|grep -oE '[0-9]{1,5}'`
|
||||
|
||||
logmore "upportal is $upportal"
|
||||
logmore "upportal_ip is $upportal_ip"
|
||||
logmore "upportal_port_temp is $upportal_port_temp"
|
||||
logmore "upportal_port is $upportal_port"
|
||||
|
||||
if [ -z "$upportal_ip" ]; then
|
||||
kuainiao_up_state="迅雷快鸟上行API获取失败,请检查网络环境,或稍后再试!"
|
||||
#echo "迅雷快鸟服务API获取失败,请检查网络环境,或稍后再试!"
|
||||
echo $(date): "$kuainiao_up_state" >> $LOGFILE
|
||||
log_up "$kuainiao_up_state" 0
|
||||
else
|
||||
upapi_url="http://$upportal_ip:$upportal_port/v2"
|
||||
kuainiao_config_upapi=$upapi_url
|
||||
fi
|
||||
logmore "$(date): upapi_url is $upapi_url"
|
||||
}
|
||||
|
||||
|
||||
#检测快鸟加速信息
|
||||
get_bandwidth(){
|
||||
|
||||
logmore "api_url is $api_url"
|
||||
logmore "peerid is $peerid"
|
||||
if [ -n "$api_url" ]; then
|
||||
[ -n "$portal_port_temp" ] && [ -n "$portal_port" ] && bandwidth
|
||||
band=$width
|
||||
logmore "band is $band"
|
||||
can_upgrade=`echo $band|awk -F '"can_upgrade":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
logmore "can_upgrade is $can_upgrade"
|
||||
kuainiao_can_upgrade=$can_upgrade
|
||||
logmore "kuainiao_can_upgrade is $kuainiao_can_upgrade"
|
||||
dial_account=`echo $band|awk -F '"dial_account":"' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
kuainiao_dial_account=$dial_account
|
||||
logmore "kuainiao_dial_account is $kuainiao_dial_account"
|
||||
#判断是否满足加速条件
|
||||
if [ "$can_upgrade" -eq 1 ]; then
|
||||
#echo "迅雷快鸟可以加速~~~愉快的开始加速吧~~"
|
||||
#获取加速详细信息
|
||||
old_downstream=`echo $band|awk -F '"bandwidth":' '{print $2}'|awk -F '"downstream":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
max_downstream=`echo $band|awk -F '"max_bandwidth":' '{print $2}'|awk -F '"downstream":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
down_state="下行可以加速"
|
||||
kuainiao_old_downstream=$(expr $old_downstream / 1024)
|
||||
kuainiao_max_downstream=$(expr $max_downstream / 1024)
|
||||
logmore "kuainiao_old_downstream is $kuainiao_old_downstream"
|
||||
logmore "kuainiao_max_downstream is $kuainiao_max_downstream"
|
||||
else
|
||||
down_state="下行不满足加速条件"
|
||||
#echo "T_T 不能加速啊,不满足加速条件哦~~"
|
||||
log_down "$down_state" 0
|
||||
fi
|
||||
echo $(date): "$down_state" >> $LOGFILE
|
||||
# kuainiao_down_state=$down_state
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
#检测快鸟上行加速信息
|
||||
get_upbandwidth(){
|
||||
logmore "upapi_url is $upapi_url"
|
||||
if [ -n "$upapi_url" ]; then
|
||||
[ -n "$upportal_port_temp" ] && [ -n "$upportal_port" ] && upbandwidth
|
||||
band=$upwidth
|
||||
logmore "upwidth is $upwidth"
|
||||
can_upgrade=`echo $band|awk -F '"can_upgrade":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
kuainiao_can_upupgrade=$can_upgrade
|
||||
updial_account=`echo $band|awk -F '"dial_account":"' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
kuainiao_dial_upaccount=$updial_account
|
||||
logmore "can_upgrade is $can_upgrade"
|
||||
logmore "kuainiao_can_upupgrade is $kuainiao_can_upupgrade"
|
||||
logmore "updial_account is $updial_account"
|
||||
logmore "kuainiao_dial_upaccount is $kuainiao_dial_upaccount"
|
||||
#判断是否满足加速条件
|
||||
if [ "$can_upgrade" -eq 1 ]; then
|
||||
#echo "迅雷快鸟可以加速~~~愉快的开始加速吧~~"
|
||||
#获取加速详细信息
|
||||
old_upstream=`echo $band|awk -F '"bandwidth":' '{print $2}'|awk -F '"upstream":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
max_upstream=`echo $band|awk -F '"max_bandwidth":' '{print $2}'|awk -F '"upstream":' '{print $2}'|awk -F '[,}]' '{print $1}'`
|
||||
up_state="上行可以加速"
|
||||
kuainiao_old_upstream=$(expr $old_upstream / 1024)
|
||||
kuainiao_max_upstream=$(expr $max_upstream / 1024)
|
||||
logmore "kuainiao_old_upstream is $kuainiao_old_upstream"
|
||||
logmore "kuainiao_max_upstream is $kuainiao_max_upstream"
|
||||
else
|
||||
up_state="上行不满足加速条件"
|
||||
log_up "$up_state" 0
|
||||
fi
|
||||
echo "$(date): $up_state" >> $LOGFILE
|
||||
kuainiao_up_state=$up_state
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#检测试用加速信息
|
||||
query_try_info(){
|
||||
info=`$HTTP_REQ "$api_url/query_try_info?peerid=$peerid&userid=$uid&user_type=1&sessionid=$session"`
|
||||
echo $info
|
||||
}
|
||||
##{"errno":0,"message":"","number_of_try":0,"richmessage":"","sequence":0,"timestamp":1455936922,"try_duration":10}
|
||||
|
||||
query_try_upinfo(){
|
||||
info=`$HTTP_REQ "$upapi_url/query_try_info?peerid=$peerid&userid=$uid&client_type=android-uplink-2.3.3.9&client_version=andrioduplink-2.3.3.9&os=android-7.0.24DUK-AL20&sessionid=$session"`
|
||||
echo $info
|
||||
}
|
||||
##{"errno":0,"exp_day_len":0,"is_exp_day":0,"message":"","number_of_try":1,"richmessage":"","sequence":268435461,"timestamp":1493469390,"try_duration":10}
|
||||
|
||||
get_upgrade_down(){
|
||||
_ts=`date +%s`000
|
||||
ret=`$HTTP_REQ "$api_url/upgrade?peerid=$peerid&userid=$uid&user_type=1&sessionid=$kuainiao_config_session&dial_account=$dial_account&client_type=android-swjsq-$app_version&client_version=androidswjsq-$app_version&os=android-5.0.1.24SmallRice&time_and=$_ts"`
|
||||
errcode=`echo $ret|awk -F '"errno":' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
if [ "$errcode" == "0" ]; then
|
||||
down_state="$down_state (您的下行带宽已从$kuainiao_old_downstream M提升到$kuainiao_max_downstream M)"
|
||||
log_down "$down_state" 1
|
||||
else
|
||||
down_state="$down_state 下行带宽提升失败,请检查宽带账号是否绑定正确"
|
||||
log_down "$down_state" 0
|
||||
fi
|
||||
echo $(date): "$down_state" >> $LOGFILE
|
||||
# kuainiao_down_state=$down_state
|
||||
}
|
||||
|
||||
get_upgrade_up(){
|
||||
_ts=`date +%s`000
|
||||
up_ret=`$HTTP_REQ --header "User-Agent:android-async-http/xl-acc-sdk/version-1.0.0.1" "$upapi_url/upgrade?peerid=$peerid&userid=$uid&client_type=android-uplink-2.3.3.9&client_version=andrioduplink-2.3.3.9&os=android-7.0.24DUK-AL20&sessionid=$session&user_type=1&dial_account=$updial_account"`
|
||||
errcode=`echo $up_ret|awk -F '"errno":' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
if [ "$errcode" == "0" ] || [ "$errcode" == "812" ];then
|
||||
up_state="$up_state (您的上行带宽已从$kuainiao_old_upstream M提升到$kuainiao_max_upstream M)"
|
||||
log_up "$up_state" 1
|
||||
else
|
||||
up_state="$up_state 上行带宽提升失败,请检查宽带账号是否绑定正确"
|
||||
log_up "$up_state" 0
|
||||
fi
|
||||
echo $(date): "$up_state" >> $LOGFILE
|
||||
# kuainiao_up_state=$up_state
|
||||
# echo "$kuainiao_up_state" > $up_state_file
|
||||
}
|
||||
|
||||
#迅雷快鸟上行加速心跳包
|
||||
keepalive_up(){
|
||||
_ts=`date +%s`000
|
||||
up_ret=`$HTTP_REQ --header "User-Agent:android-async-http/xl-acc-sdk/version-1.0.0.1" "$upapi_url/keepalive?peerid=$peerid&userid=$uid&client_type=android-uplink-2.3.3.9&client_version=andrioduplink-2.3.3.9&os=android-7.0.24DUK-AL20&sessionid=$session&user_type=1&dial_account=$kuainiao_dial_upaccount"`
|
||||
errcode=`echo $up_ret|awk -F '"errno":' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
if [ "$errcode" != "0" ];then
|
||||
#kuainiao_run_upid=0
|
||||
kuainiao_up_state="迅雷上行提速失效!$(date '+%Y-%m-%d %H:%M:%S')"
|
||||
kuainiao_run_upstatus=0
|
||||
log_up "$kuainiao_up_state" 0
|
||||
else
|
||||
#kuainiao_run_upid=$(expr $kuainiao_run_upid + 1)
|
||||
kuainiao_up_state="您的上行带宽已从${kuainiao_old_upstream}M提升到${kuainiao_max_upstream}M $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
kuainiao_run_upstatus=1
|
||||
log_up "$kuainiao_up_state" 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#检测提速带宽
|
||||
bandwidth(){
|
||||
[ "$logmore" -eq 1 ] && {
|
||||
echo $(date): "bandwidth start" >> $LOGFILE
|
||||
echo $(date): "peerid is $peerid" >> $LOGFILE
|
||||
echo $(date): "uid is $uid" >> $LOGFILE
|
||||
echo $(date): "session is $session" >> $LOGFILE
|
||||
}
|
||||
_ts=`date +%s`000
|
||||
width=`$HTTP_REQ "$api_url/bandwidth?peerid=$peerid&userid=$uid&user_type=1&sessionid=$session&dial_account=$dial_account&client_type=android-swjsq-$app_version&client_version=androidswjsq-$app_version&os=android-5.0.1.24SmallRice&time_and=$_ts"`
|
||||
#echo $width
|
||||
}
|
||||
##{"bandwidth":{"downstream":51200,"upstream":0},"can_upgrade":1,"dial_account":"100001318645","errno":0,"max_bandwidth":{"downstream":102400,"upstream":0},"message":"","province":"bei_jing","province_name":"北京","richmessage":"","sequence":0,"sp":"cnc","sp_name":"联通","timestamp":1455936922}
|
||||
|
||||
upbandwidth(){
|
||||
_ts=`date +%s`000
|
||||
upwidth=`$HTTP_REQ "$upapi_url/bandwidth?peerid=$peerid&userid=$uid&user_type=1&sessionid=$session&dial_account=$dial_account&client_type=android-swjsq-$app_version&client_version=androidswjsq-$app_version&os=android-5.0.1.24SmallRice&time_and=$_ts"`
|
||||
#echo $upwidth
|
||||
}
|
||||
|
||||
|
||||
#迅雷快鸟下行加速心跳包
|
||||
keepalive_down(){
|
||||
_ts=`date +%s`000
|
||||
ret=`$HTTP_REQ "$api_url/keepalive?peerid=$peerid&userid=$uid&user_type=1&sessionid=$session&dial_account=$dial_account&client_type=android-swjsq-$app_version&client_version=androidswjsq-$app_version&os=android-5.0.1.24SmallRice&time_and=$_ts"`
|
||||
errcode=`echo $ret|awk -F '"errno":' '{print $2}'|awk -F '[,}"]' '{print $1}'`
|
||||
if [ "$errcode" != "0" ];then
|
||||
#kuainiao_run_upid=0
|
||||
kuainiao_down_state="迅雷下行提速失效!"$(date "+%Y-%m-%d %H:%M:%S")
|
||||
log_down "$kuainiao_down_state" 0
|
||||
kuainiao_run_status=0
|
||||
else
|
||||
#kuainiao_run_upid=$(expr $kuainiao_run_upid + 1)
|
||||
kuainiao_down_state="您的下行带宽已从${kuainiao_old_downstream}M提升到${kuainiao_max_downstream}M $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
log_down "$kuainiao_down_state" 1
|
||||
kuainiao_run_status=1
|
||||
|
||||
fi
|
||||
echo $(date): "$kuainiao_down_state" >> $LOGFILE
|
||||
}
|
||||
|
||||
sigterm(){
|
||||
|
||||
[ "$kuainiao_can_upgrade" -eq 1 ] && kuainiao_recover
|
||||
[ "$kuainiao_can_upupgrade" -eq 1 ] && kuainiao_uprecover
|
||||
logmore "trap sigterm exit"
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
#快鸟加速注销
|
||||
kuainiao_recover(){
|
||||
_ts=`date +%s`000
|
||||
recover=`$HTTP_REQ "$api_url/recover?peerid=$peerid&userid=$uid&user_type=1&sessionid=$session&dial_account=$dial_account&client_type=android-swjsq-$app_version&client_version=androidswjsq-$app_version&os=android-5.0.1.24SmallRice&time_and=$_ts"`
|
||||
#echo $recover
|
||||
echo $(date): "快鸟下行带宽加速已注销" >> $LOGFILE
|
||||
}
|
||||
|
||||
kuainiao_uprecover(){
|
||||
_ts=`date +%s`000
|
||||
recover=`$HTTP_REQ "$upapi_url/recover?peerid=$peerid&userid=$uid&client_type=android-uplink-2.3.3.9&client_version=andrioduplink-2.3.3.9&os=android-7.0.24DUK-AL20&sessionid=$session&user_type=1&dial_account=$updial_account"`
|
||||
#echo $recover
|
||||
echo $(date): "快鸟上行带宽加速已注销" >> $LOGFILE
|
||||
}
|
||||
|
||||
#执行初始化
|
||||
kuainiao_init(){
|
||||
local kuainiao_last_act=""
|
||||
local kuainiao_can_upgrade=0
|
||||
local kuainiao_can_upupgrade=0
|
||||
local kuainiao_down_state=""
|
||||
local kuainiao_up_state=""
|
||||
}
|
||||
|
||||
##主逻辑
|
||||
trap 'sigterm' TERM
|
||||
trap 'sigterm' INT
|
||||
|
||||
kuainiao_init
|
||||
config_load kuainiao
|
||||
config_get_bool enabled base enabled 0
|
||||
config_get_bool kuainiao_downenable base enable_down 0
|
||||
config_get_bool kuainiao_upenable base enable_up 0
|
||||
config_get kuainiao_config_wan base speed_wan
|
||||
config_get kuainiao_config_uname base kuainiao_name
|
||||
config_get kuainiao_config_pwd base kuainiao_config_pwd
|
||||
|
||||
[ "$enabled" -eq 0 ] || [ -z "$kuainiao_config_pwd" ] && exit 0
|
||||
[ "$kuainiao_downenable" -eq 0 ] && [ "$kuainiao_upenable" -eq 0 ] && exit 0
|
||||
[ -z "$kuainiao_config_uname" ] && exit 0
|
||||
|
||||
logmore "enabled is $enabled"
|
||||
logmore "kuainiao_downenable is $kuainiao_downenable"
|
||||
logmore "kuainiao_upenable is $kuainiao_upenable"
|
||||
logmore "kuainiao_config_wan is $kuainiao_config_wan"
|
||||
logmore "kuainiao_config_uname is $kuainiao_config_uname"
|
||||
logmore "kuainiao_config_pwd is $kuainiao_config_pwd"
|
||||
|
||||
if [ "$kuainiao_downenable" -eq 1 ] || [ "$kuainiao_upenable" -eq 1 ]; then
|
||||
|
||||
logmore "启动延时 7s"
|
||||
sleep 7s
|
||||
|
||||
#登陆迅雷获取uid
|
||||
logmore "get_bind_address start"
|
||||
get_bind_address
|
||||
logmore "bind_address is $bind_address"
|
||||
logmore "get_mac_addr start"
|
||||
get_mac_addr
|
||||
logmore "peerid is $peerid"
|
||||
logmore "get_xunlei_uid start"
|
||||
get_xunlei_uid
|
||||
logmore "get_xunlei_uid is done"
|
||||
logmore "id is $uid"
|
||||
#判断是否登陆成功
|
||||
if [ -n "$uid" ]; then
|
||||
if [ "$kuainiao_downenable" -eq 1 ]; then
|
||||
logmore "get_kuainiao_api is started......."
|
||||
get_kuainiao_api
|
||||
logmore "get_bandwidth is started......."
|
||||
get_bandwidth
|
||||
kuainiao_config_downstream=$(expr $old_downstream / 1024)
|
||||
kuainiao_config_max_downstream=$(expr $max_downstream / 1024)
|
||||
logmore "kuainiao_config_downstream is $kuainiao_config_downstream"
|
||||
logmore "kuainiao_config_max_downstream is $kuainiao_config_max_downstream"
|
||||
logmore "kuainiao_can_upgrade is $kuainiao_can_upgrade"
|
||||
|
||||
if [ "$kuainiao_can_upgrade" -eq 1 ]; then
|
||||
logmore "get_upgrade_down is started......."
|
||||
get_upgrade_down
|
||||
logmore "get_upgrade_down is done......."
|
||||
sleep 1s
|
||||
#keepalive_down
|
||||
fi
|
||||
fi
|
||||
if [ "$kuainiao_upenable" -eq 1 ]; then
|
||||
logmore "get_kuainiao_upapi start"
|
||||
get_kuainiao_upapi
|
||||
logmore "get_upbandwidth start"
|
||||
get_upbandwidth
|
||||
kuainiao_config_upstream=$(expr $old_upstream / 1024)
|
||||
kuainiao_config_max_upstream=$(expr $max_upstream / 1024)
|
||||
logmore "kuainiao_config_upstream is $kuainiao_config_upstream"
|
||||
logmore "kuainiao_config_max_upstream is $kuainiao_config_max_upstream"
|
||||
logmore "kuainiao_can_upupgrade is $kuainiao_can_upupgrade"
|
||||
|
||||
if [ "$kuainiao_can_upupgrade" -eq 1 ]; then
|
||||
logmore "get_upgrade_up start"
|
||||
get_upgrade_up
|
||||
sleep 1s
|
||||
#keepalive_up
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# [ -z "$kuainiao_can_upgrade" ] && [ -z "$kuainiao_can_upupgrade" ] && {
|
||||
# logmore "exit kuainiao...."
|
||||
# sleep 7s
|
||||
# echo "<font color=red>暂无加速信息</font>" > $down_state_file
|
||||
# echo "<font color=red>暂无加速信息</font>" > $up_state_file
|
||||
# exit 0
|
||||
|
||||
# }
|
||||
while true;
|
||||
do
|
||||
sleep 295s
|
||||
if [ "$kuainiao_downenable" -eq 1 ] && [ "$kuainiao_can_upgrade" -eq 1 ];then
|
||||
keepalive_down
|
||||
[ "$kuainiao_run_status" -eq 0 ] && restart_kuainiao
|
||||
fi
|
||||
if [ "$kuainiao_upenable" -eq 1 ] && [ "$kuainiao_can_upupgrade" -eq 1 ];then
|
||||
keepalive_up
|
||||
[ "$kuainiao_run_upstatus" -eq 0 ] && restart_kuainiao
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
restart_kuainiao(){
|
||||
kuainiao_init
|
||||
config_load kuainiao
|
||||
config_get_bool enabled base enabled 0
|
||||
config_get_bool kuainiao_downenable base enable_down 0
|
||||
config_get_bool kuainiao_upenable base enable_up 0
|
||||
config_get kuainiao_config_wan base speed_wan
|
||||
config_get kuainiao_config_uname base kuainiao_name
|
||||
config_get kuainiao_config_pwd base kuainiao_config_pwd
|
||||
|
||||
if [ "$kuainiao_downenable" -eq 1 ] || [ "$kuainiao_upenable" -eq 1 ]; then
|
||||
logmore "启动延时 7s"
|
||||
sleep 7s
|
||||
|
||||
#登陆迅雷获取uid
|
||||
logmore "get_bind_address start"
|
||||
get_bind_address
|
||||
logmore "bind_address is $bind_address"
|
||||
logmore "get_mac_addr start"
|
||||
get_mac_addr
|
||||
logmore "peerid is $peerid"
|
||||
logmore "get_xunlei_uid start"
|
||||
get_xunlei_uid
|
||||
logmore "get_xunlei_uid is done"
|
||||
logmore "id is $uid"
|
||||
#判断是否登陆成功
|
||||
if [ -n "$uid" ]; then
|
||||
if [ "$kuainiao_downenable" -eq 1 ]; then
|
||||
logmore "get_kuainiao_api is started......."
|
||||
get_kuainiao_api
|
||||
logmore "get_bandwidth is started......."
|
||||
get_bandwidth
|
||||
kuainiao_config_downstream=$(expr $old_downstream / 1024)
|
||||
kuainiao_config_max_downstream=$(expr $max_downstream / 1024)
|
||||
if [ "$kuainiao_can_upgrade" -eq 1 ]; then
|
||||
[ "$logmore" -eq 1 ] && logmore "get_upgrade_down is started......."
|
||||
get_upgrade_down
|
||||
logmore "get_upgrade_down is done......."
|
||||
sleep 1s
|
||||
#keepalive_down
|
||||
fi
|
||||
fi
|
||||
if [ "$kuainiao_upenable" -eq 1 ]; then
|
||||
logmore "get_kuainiao_upapi start"
|
||||
get_kuainiao_upapi
|
||||
logmore "get_upbandwidth start"
|
||||
get_upbandwidth
|
||||
kuainiao_config_upstream=$(expr $old_upstream / 1024)
|
||||
kuainiao_config_max_upstream=$(expr $max_upstream / 1024)
|
||||
if [ "$kuainiao_can_upupgrade" -eq 1 ]; then
|
||||
logmore "get_upgrade_up start"
|
||||
get_upgrade_up
|
||||
sleep 1s
|
||||
#keepalive_up
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
#add_kuainiao_cru
|
||||
fi
|
||||
[ -z "$kuainiao_can_upgrade" ] && [ -z "$kuainiao_can_upupgrade" ] && {
|
||||
logmore "exit kuainiao...."
|
||||
sleep 7s
|
||||
echo "<font color=red>暂无加速信息</font>" > $down_state_file
|
||||
echo "<font color=red>暂无加速信息</font>" > $up_state_file
|
||||
exit 0
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
enabled=`uci get kuainiao.base.enabled`
|
||||
|
||||
if [ "$enabled" -eq 0 ]; then
|
||||
/etc/init.d/kuainiao stop
|
||||
/etc/init.d/kuainiao disable
|
||||
else
|
||||
/etc/init.d/kuainiao stop
|
||||
/etc/init.d/kuainiao start
|
||||
/etc/init.d/kuainiao enable
|
||||
fi
|
@ -1 +0,0 @@
|
||||
暂无加速信息
|
@ -1 +0,0 @@
|
||||
暂无加速信息
|
@ -1 +0,0 @@
|
||||
var md5; md5 || (md5 = function(){function i(a,b){a[b>>5]|=128<<b%32,a[(b+64>>>9<<4)+14]=b;for(var c=1732584193,d=-271733879,e=-1732584194,f=271733878,g=0;a.length>g;g+=16){var h=c,i=d,j=e,o=f;c=k(c,d,e,f,a[g+0],7,-680876936),f=k(f,c,d,e,a[g+1],12,-389564586),e=k(e,f,c,d,a[g+2],17,606105819),d=k(d,e,f,c,a[g+3],22,-1044525330),c=k(c,d,e,f,a[g+4],7,-176418897),f=k(f,c,d,e,a[g+5],12,1200080426),e=k(e,f,c,d,a[g+6],17,-1473231341),d=k(d,e,f,c,a[g+7],22,-45705983),c=k(c,d,e,f,a[g+8],7,1770035416),f=k(f,c,d,e,a[g+9],12,-1958414417),e=k(e,f,c,d,a[g+10],17,-42063),d=k(d,e,f,c,a[g+11],22,-1990404162),c=k(c,d,e,f,a[g+12],7,1804603682),f=k(f,c,d,e,a[g+13],12,-40341101),e=k(e,f,c,d,a[g+14],17,-1502002290),d=k(d,e,f,c,a[g+15],22,1236535329),c=l(c,d,e,f,a[g+1],5,-165796510),f=l(f,c,d,e,a[g+6],9,-1069501632),e=l(e,f,c,d,a[g+11],14,643717713),d=l(d,e,f,c,a[g+0],20,-373897302),c=l(c,d,e,f,a[g+5],5,-701558691),f=l(f,c,d,e,a[g+10],9,38016083),e=l(e,f,c,d,a[g+15],14,-660478335),d=l(d,e,f,c,a[g+4],20,-405537848),c=l(c,d,e,f,a[g+9],5,568446438),f=l(f,c,d,e,a[g+14],9,-1019803690),e=l(e,f,c,d,a[g+3],14,-187363961),d=l(d,e,f,c,a[g+8],20,1163531501),c=l(c,d,e,f,a[g+13],5,-1444681467),f=l(f,c,d,e,a[g+2],9,-51403784),e=l(e,f,c,d,a[g+7],14,1735328473),d=l(d,e,f,c,a[g+12],20,-1926607734),c=m(c,d,e,f,a[g+5],4,-378558),f=m(f,c,d,e,a[g+8],11,-2022574463),e=m(e,f,c,d,a[g+11],16,1839030562),d=m(d,e,f,c,a[g+14],23,-35309556),c=m(c,d,e,f,a[g+1],4,-1530992060),f=m(f,c,d,e,a[g+4],11,1272893353),e=m(e,f,c,d,a[g+7],16,-155497632),d=m(d,e,f,c,a[g+10],23,-1094730640),c=m(c,d,e,f,a[g+13],4,681279174),f=m(f,c,d,e,a[g+0],11,-358537222),e=m(e,f,c,d,a[g+3],16,-722521979),d=m(d,e,f,c,a[g+6],23,76029189),c=m(c,d,e,f,a[g+9],4,-640364487),f=m(f,c,d,e,a[g+12],11,-421815835),e=m(e,f,c,d,a[g+15],16,530742520),d=m(d,e,f,c,a[g+2],23,-995338651),c=n(c,d,e,f,a[g+0],6,-198630844),f=n(f,c,d,e,a[g+7],10,1126891415),e=n(e,f,c,d,a[g+14],15,-1416354905),d=n(d,e,f,c,a[g+5],21,-57434055),c=n(c,d,e,f,a[g+12],6,1700485571),f=n(f,c,d,e,a[g+3],10,-1894986606),e=n(e,f,c,d,a[g+10],15,-1051523),d=n(d,e,f,c,a[g+1],21,-2054922799),c=n(c,d,e,f,a[g+8],6,1873313359),f=n(f,c,d,e,a[g+15],10,-30611744),e=n(e,f,c,d,a[g+6],15,-1560198380),d=n(d,e,f,c,a[g+13],21,1309151649),c=n(c,d,e,f,a[g+4],6,-145523070),f=n(f,c,d,e,a[g+11],10,-1120210379),e=n(e,f,c,d,a[g+2],15,718787259),d=n(d,e,f,c,a[g+9],21,-343485551),c=p(c,h),d=p(d,i),e=p(e,j),f=p(f,o)}return[c,d,e,f]}function j(a,b,c,d,e,f){return p(q(p(p(b,a),p(d,f)),e),c)}function k(a,b,c,d,e,f,g){return j(b&c|~b&d,a,b,e,f,g)}function l(a,b,c,d,e,f,g){return j(b&d|c&~d,a,b,e,f,g)}function m(a,b,c,d,e,f,g){return j(b^c^d,a,b,e,f,g)}function n(a,b,c,d,e,f,g){return j(c^(b|~d),a,b,e,f,g)}function p(a,b){var c=(a&65535)+(b&65535),d=(a>>16)+(b>>16)+(c>>16);return d<<16|c&65535}function q(a,b){return a<<b|a>>>32-b}function r(a){for(var b=[],d=(1<<c)-1,e=0;a.length*c>e;e+=c)b[e>>5]|=(a.charCodeAt(e/c)&d)<<e%32;return b}function t(b){for(var c=a?"0123456789ABCDEF":"0123456789abcdef",d="",e=0;b.length*4>e;e++)d+=c.charAt(b[e>>2]>>e%4*8+4&15)+c.charAt(b[e>>2]>>e%4*8&15);return d}var a=0,c=8;return function(a){return t(i(r(a),a.length*c))}}());
|
@ -1,202 +0,0 @@
|
||||
/*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||
* in FIPS PUB 180-1
|
||||
* Version 2.1a Copyright Paul Johnston 2000 - 2002.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
|
||||
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
|
||||
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
|
||||
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
|
||||
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
|
||||
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function sha1_vm_test()
|
||||
{
|
||||
return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
||||
*/
|
||||
function core_sha1(x, len)
|
||||
{
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << (24 - len % 32);
|
||||
x[((len + 64 >> 9) << 4) + 15] = len;
|
||||
|
||||
var w = Array(80);
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
var e = -1009589776;
|
||||
|
||||
for(var i = 0; i < x.length; i += 16)
|
||||
{
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
var olde = e;
|
||||
|
||||
for(var j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16) w[j] = x[i + j];
|
||||
else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||
var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
|
||||
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||
e = d;
|
||||
d = c;
|
||||
c = rol(b, 30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
e = safe_add(e, olde);
|
||||
}
|
||||
return Array(a, b, c, d, e);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the appropriate triplet combination function for the current
|
||||
* iteration
|
||||
*/
|
||||
function sha1_ft(t, b, c, d)
|
||||
{
|
||||
if(t < 20) return (b & c) | ((~b) & d);
|
||||
if(t < 40) return b ^ c ^ d;
|
||||
if(t < 60) return (b & c) | (b & d) | (c & d);
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the appropriate additive constant for the current iteration
|
||||
*/
|
||||
function sha1_kt(t)
|
||||
{
|
||||
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
||||
(t < 60) ? -1894007588 : -899497514;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-SHA1 of a key and some data
|
||||
*/
|
||||
function core_hmac_sha1(key, data)
|
||||
{
|
||||
var bkey = str2binb(key);
|
||||
if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
|
||||
return core_sha1(opad.concat(hash), 512 + 160);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function rol(num, cnt)
|
||||
{
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an 8-bit or 16-bit string to an array of big-endian words
|
||||
* In 8-bit function, characters >255 have their hi-byte silently ignored.
|
||||
*/
|
||||
function str2binb(str)
|
||||
{
|
||||
var bin = Array();
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < str.length * chrsz; i += chrsz)
|
||||
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a string
|
||||
*/
|
||||
function binb2str(bin)
|
||||
{
|
||||
var str = "";
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < bin.length * 32; i += chrsz)
|
||||
str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a hex string.
|
||||
*/
|
||||
function binb2hex(binarray)
|
||||
{
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i++)
|
||||
{
|
||||
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
|
||||
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a base-64 string
|
||||
*/
|
||||
function binb2b64(binarray)
|
||||
{
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i += 3)
|
||||
{
|
||||
var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
|
||||
| (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
|
||||
| ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
|
||||
for(var j = 0; j < 4; j++)
|
||||
{
|
||||
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
|
||||
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
71
package/lean/luci-app-xlnetacc/Makefile
Normal file
71
package/lean/luci-app-xlnetacc/Makefile
Normal file
@ -0,0 +1,71 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-xlnetacc
|
||||
PKG_VERSION:=1.0.0
|
||||
PKG_RELEASE:=3
|
||||
|
||||
PKG_LICENSE:=GPLv2
|
||||
PKG_MAINTAINER:=Sense <sensec@gmail.com>
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=luci
|
||||
CATEGORY:=LuCI
|
||||
SUBMENU:=3. Applications
|
||||
TITLE:=LuCI Support for XLNetAcc
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+wget +openssl-util
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
LuCI Support for XLNetAcc.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \
|
||||
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
( . /etc/uci-defaults/luci-xlnetacc ) && rm -f /etc/uci-defaults/luci-xlnetacc
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/xlnetacc
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/xlnetacc.*.lmo $(1)/usr/lib/lua/luci/i18n/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
|
||||
$(INSTALL_DATA) ./files/luci/controller/*.lua $(1)/usr/lib/lua/luci/controller/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
|
||||
$(INSTALL_DATA) ./files/luci/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/xlnetacc
|
||||
$(INSTALL_DATA) ./files/luci/view/xlnetacc/*.htm $(1)/usr/lib/lua/luci/view/xlnetacc/
|
||||
$(INSTALL_DIR) $(1)/www/luci-static/resources/xlnetacc
|
||||
$(INSTALL_DATA) ./files/luci/luci-static/resources/xlnetacc/*.js $(1)/www/luci-static/resources/xlnetacc/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/root/etc/config/xlnetacc $(1)/etc/config/xlnetacc
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/root/etc/init.d/xlnetacc $(1)/etc/init.d/xlnetacc
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/root/etc/uci-defaults/luci-xlnetacc $(1)/etc/uci-defaults/luci-xlnetacc
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) ./files/root/usr/bin/xlnetacc.sh $(1)/usr/bin/xlnetacc.sh
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
@ -0,0 +1,47 @@
|
||||
module("luci.controller.xlnetacc", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/xlnetacc") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "services", "xlnetacc"},
|
||||
firstchild(), _("XLNetAcc")).dependent = false
|
||||
|
||||
entry({"admin", "services", "xlnetacc", "general"},
|
||||
cbi("xlnetacc"), _("Settings"), 1)
|
||||
|
||||
entry({"admin", "services", "xlnetacc", "log"},
|
||||
template("xlnetacc/logview"), _("Log"), 2)
|
||||
|
||||
entry({"admin", "services", "xlnetacc", "status"}, call("action_status"))
|
||||
entry({"admin", "services", "xlnetacc", "logdata"}, call("action_log"))
|
||||
end
|
||||
|
||||
local function is_running(name)
|
||||
return luci.sys.call("pidof %s >/dev/null" %{name}) == 0
|
||||
end
|
||||
|
||||
function action_status()
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({
|
||||
run_state = is_running("xlnetacc.sh"),
|
||||
down_state = nixio.fs.readfile("/var/state/xlnetacc_down_state") or "",
|
||||
up_state = nixio.fs.readfile("/var/state/xlnetacc_up_state") or ""
|
||||
})
|
||||
end
|
||||
|
||||
function action_log()
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local util = require "luci.util"
|
||||
local log_data = { }
|
||||
|
||||
log_data.syslog = util.trim(util.exec("logread | grep xlnetacc"))
|
||||
if uci:get("xlnetacc", "general", "logging") ~= "0" then
|
||||
log_data.client = nixio.fs.readfile("/var/log/xlnetacc.log") or ""
|
||||
end
|
||||
uci:unload("xlnetacc")
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(log_data)
|
||||
end
|
Binary file not shown.
@ -0,0 +1,92 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "XLNetAcc"
|
||||
msgstr "迅雷快鸟"
|
||||
|
||||
msgid "XLNetAcc is a Thunder joint broadband operators launched a commitment to help users solve the low broadband, slow Internet access, poor Internet experience of professional-grade broadband upgrade software."
|
||||
msgstr "迅雷快鸟是迅雷联合宽带运营商推出的一款致力于帮助用户解决宽带低、网速慢、上网体验差的专业级宽带提速软件。"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
|
||||
msgid "Log"
|
||||
msgstr "日志"
|
||||
|
||||
msgid "Running Status"
|
||||
msgstr "运行状态"
|
||||
|
||||
msgid "XLNetAcc Running Status"
|
||||
msgstr "快鸟运行状态"
|
||||
|
||||
msgid "DownLink Upgrade Status"
|
||||
msgstr "下行提速状态"
|
||||
|
||||
msgid "UpLink Upgrade Status"
|
||||
msgstr "上行提速状态"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "No upgrade information"
|
||||
msgstr "暂无提速信息"
|
||||
|
||||
msgid "General Settings"
|
||||
msgstr "基本设置"
|
||||
|
||||
msgid "Enabled"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Enable DownLink Upgrade"
|
||||
msgstr "开启下行提速"
|
||||
|
||||
msgid "Enable UpLink Upgrade"
|
||||
msgstr "开启上行提速"
|
||||
|
||||
msgid "Enable Logging"
|
||||
msgstr "启用日志记录"
|
||||
|
||||
msgid "Enable verbose logging"
|
||||
msgstr "启用详细日志"
|
||||
|
||||
msgid "Upgrade interface"
|
||||
msgstr "指定提速接口"
|
||||
|
||||
msgid "XLNetAcc account"
|
||||
msgstr "迅雷快鸟帐号"
|
||||
|
||||
msgid "XLNetAcc password"
|
||||
msgstr "迅雷快鸟密码"
|
||||
|
||||
msgid "Does not store the plaintext password, automatically emptied after start."
|
||||
msgstr "不存储明文密码,启动后自动清空。"
|
||||
|
||||
msgid "Encrypted password"
|
||||
msgstr "加密后的密码"
|
||||
|
||||
msgid "Auto-generate in accordance with the plaintext password, do not modify it!"
|
||||
msgstr "根据明文密码自动生成,请勿修改!"
|
||||
|
||||
msgid "Log Data"
|
||||
msgstr "日志数据"
|
||||
|
||||
msgid "Loading..."
|
||||
msgstr "正在加载..."
|
||||
|
||||
msgid "Refresh every 5 seconds."
|
||||
msgstr "每 5 秒刷新。"
|
||||
|
||||
msgid "syslog:"
|
||||
msgstr "系统日志:"
|
||||
|
||||
msgid "log file:"
|
||||
msgstr "日志文件:"
|
||||
|
||||
msgid "No log data."
|
||||
msgstr "无日志数据。"
|
||||
|
||||
msgid "Error get log data."
|
||||
msgstr "获取日志数据失败。"
|
9
package/lean/luci-app-xlnetacc/files/luci/luci-static/resources/xlnetacc/md5-min.js
vendored
Normal file
9
package/lean/luci-app-xlnetacc/files/luci/luci-static/resources/xlnetacc/md5-min.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for more info.
|
||||
*/
|
||||
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}return a}function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}return a}function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}return Array(o,n,m,l)}function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
|
9
package/lean/luci-app-xlnetacc/files/luci/luci-static/resources/xlnetacc/sha1-min.js
vendored
Normal file
9
package/lean/luci-app-xlnetacc/files/luci/luci-static/resources/xlnetacc/sha1-min.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||
* in FIPS 180-1
|
||||
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*/
|
||||
var hexcase=0;var b64pad="";function hex_sha1(a){return rstr2hex(rstr_sha1(str2rstr_utf8(a)))}function hex_hmac_sha1(a,b){return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function sha1_vm_test(){return hex_sha1("abc").toLowerCase()=="a9993e364706816aba3e25717850c26c9cd0d89d"}function rstr_sha1(a){return binb2rstr(binb_sha1(rstr2binb(a),a.length*8))}function rstr_hmac_sha1(c,f){var e=rstr2binb(c);if(e.length>16){e=binb_sha1(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binb_sha1(a.concat(rstr2binb(f)),512+f.length*8);return binb2rstr(binb_sha1(d.concat(g),512+160))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binb(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(24-c%32)}return a}function binb2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(24-c%32))&255)}return a}function binb_sha1(v,o){v[o>>5]|=128<<(24-o%32);v[((o+64>>9)<<4)+15]=o;var y=Array(80);var u=1732584193;var s=-271733879;var r=-1732584194;var q=271733878;var p=-1009589776;for(var l=0;l<v.length;l+=16){var n=u;var m=s;var k=r;var h=q;var f=p;for(var g=0;g<80;g++){if(g<16){y[g]=v[l+g]}else{y[g]=bit_rol(y[g-3]^y[g-8]^y[g-14]^y[g-16],1)}var z=safe_add(safe_add(bit_rol(u,5),sha1_ft(g,s,r,q)),safe_add(safe_add(p,y[g]),sha1_kt(g)));p=q;q=r;r=bit_rol(s,30);s=u;u=z}u=safe_add(u,n);s=safe_add(s,m);r=safe_add(r,k);q=safe_add(q,h);p=safe_add(p,f)}return Array(u,s,r,q,p)}function sha1_ft(e,a,g,f){if(e<20){return(a&g)|((~a)&f)}if(e<40){return a^g^f}if(e<60){return(a&g)|(a&f)|(g&f)}return a^g^f}function sha1_kt(a){return(a<20)?1518500249:(a<40)?1859775393:(a<60)?-1894007588:-899497514}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
|
@ -0,0 +1,40 @@
|
||||
local m, s, o
|
||||
local uci = luci.model.uci.cursor()
|
||||
|
||||
m = Map("xlnetacc", "%s - %s" %{translate("XLNetAcc"), translate("Settings")}, translate("XLNetAcc is a Thunder joint broadband operators launched a commitment to help users solve the low broadband, slow Internet access, poor Internet experience of professional-grade broadband upgrade software."))
|
||||
m:append(Template("xlnetacc/status"))
|
||||
|
||||
s = m:section(NamedSection, "general", "general", translate("General Settings"))
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(Flag, "enabled", translate("Enabled"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Flag, "down_acc", translate("Enable DownLink Upgrade"))
|
||||
|
||||
o = s:option(Flag, "up_acc", translate("Enable UpLink Upgrade"))
|
||||
|
||||
o = s:option(Flag, "logging", translate("Enable Logging"))
|
||||
o.default = "1"
|
||||
|
||||
o = s:option(Flag, "verbose", translate("Enable verbose logging"))
|
||||
o:depends("logging", "1")
|
||||
|
||||
o = s:option(ListValue, "network", translate("Upgrade interface"))
|
||||
uci:foreach("network", "interface", function(section)
|
||||
if section[".name"] ~= "loopback" and section[".name"] ~= "lan" then
|
||||
o:value(section[".name"])
|
||||
end
|
||||
end)
|
||||
|
||||
o = s:option(Value, "account", translate("XLNetAcc account"))
|
||||
|
||||
o = s:option(Value, "password", translate("XLNetAcc password"), translate("Does not store the plaintext password, automatically emptied after start."))
|
||||
o.password = true
|
||||
o.template = "xlnetacc/rsa"
|
||||
|
||||
o = s:option(Value, "encrypt", translate("Encrypted password"), translate("Auto-generate in accordance with the plaintext password, do not modify it!"))
|
||||
--o.readonly = true
|
||||
|
||||
return m
|
@ -0,0 +1,49 @@
|
||||
<% css = [[
|
||||
#log_text {
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
height: 500px;
|
||||
overflow: auto;
|
||||
}
|
||||
#log_text pre {
|
||||
word-break: break-all;
|
||||
margin: 0;
|
||||
}
|
||||
.description {
|
||||
color: #ffffff;
|
||||
background-color: #0099ff;
|
||||
}
|
||||
]]
|
||||
%>
|
||||
|
||||
<%+header%>
|
||||
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:XLNetAcc%> - <%:Log Data%></h2>
|
||||
<fieldset class="cbi-section">
|
||||
<fieldset class="cbi-section-node">
|
||||
<div id="log_text"><img src="<%=resource%>/icons/loading.gif" alt="<%:Loading...%>" style="vertical-align:middle" /><%:Collecting data...%></div>
|
||||
<div style="text-align:right"><small><%:Refresh every 5 seconds.%></small></div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var log_id = document.getElementById('log_text');
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "xlnetacc", "logdata")%>', null, function(x, data) {
|
||||
if ( log_id && data ) {
|
||||
log_id.innerHTML = String.format(
|
||||
'<pre>%s%s%s%s</pre>',
|
||||
'<span class="description"><strong><%:syslog:%></strong></span><br/>',
|
||||
data.syslog || '<%:No log data.%>',
|
||||
'<br/><br/><span class="description"><strong><%:log file:%></strong></span><br/>',
|
||||
data.client || '<%:No log data.%>'
|
||||
);
|
||||
} else if ( log_id ) {
|
||||
log_id.innerHTML = '<strong><%:Error get log data.%></strong>';
|
||||
}
|
||||
});
|
||||
//]]></script>
|
||||
|
||||
<%+footer%>
|
@ -0,0 +1,41 @@
|
||||
<script type="text/javascript" src="<%=resource%>/xlnetacc/md5-min.js"></script>
|
||||
<!-- <script type="text/javascript" src="<%=resource%>/xlnetacc/sha1-min.js"></script> -->
|
||||
<script type="text/javascript" src="<%=resource%>/xlnetacc/rsa.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function onchange_rsa(id) {
|
||||
cbi_d_update(id);
|
||||
|
||||
var password = document.getElementById('cbid.xlnetacc.general.password').value;
|
||||
if ( password == "" ) {
|
||||
document.getElementById('cbid.xlnetacc.general.encrypt').value = "";
|
||||
} else {
|
||||
var kn = 'AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B021E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78AF146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F5DBCEBE22F89D640F5336E42F587DC4AFEDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E36FD';
|
||||
var ke = '010001';
|
||||
var rsa = new RSAKey();
|
||||
rsa.setPublic(kn, ke);
|
||||
|
||||
var cryptpwd = rsa.encrypt(hex_md5(password));
|
||||
document.getElementById('cbid.xlnetacc.general.encrypt').value = cryptpwd.toUpperCase();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<%+cbi/valueheader%>
|
||||
<input data-update="change"<%=
|
||||
attr("id", cbid) ..
|
||||
attr("name", cbid) ..
|
||||
attr("type", self.password and "password" or "text") ..
|
||||
attr("class", self.password and "cbi-input-password" or "cbi-input-text") ..
|
||||
attr("value", self:cfgvalue(section) or self.default) ..
|
||||
ifattr(self.size, "size") ..
|
||||
ifattr(self.placeholder, "placeholder") ..
|
||||
ifattr(self.readonly, "readonly") ..
|
||||
ifattr(self.maxlength, "maxlength") ..
|
||||
ifattr(self.datatype, "data-type", self.datatype) ..
|
||||
ifattr(self.datatype, "data-optional", self.optional or self.rmempty) ..
|
||||
ifattr(self.combobox_manual, "data-manual", self.combobox_manual) ..
|
||||
ifattr(#self.keylist > 0, "data-choices", { self.keylist, self.vallist })
|
||||
%> onchange="onchange_rsa(this.id)" />
|
||||
<% if self.password then %><img src="<%=resource%>/cbi/reload.gif" style="vertical-align:middle" title="<%:Reveal/hide password%>" onclick="var e = document.getElementById('<%=cbid%>'); e.type = (e.type=='password') ? 'text' : 'password';" /><% end %>
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,21 @@
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:Running Status%></legend>
|
||||
<table width="100%" cellspacing="10" id="_xlnetacc_status_table">
|
||||
<tr><td width="33%"><%:XLNetAcc Running Status%></td><td id="_run_state"><em><%:Collecting data...%></em></td></tr>
|
||||
<tr><td width="33%"><%:DownLink Upgrade Status%></td><td id="_down_state"><em><%:Collecting data...%></em></td></tr>
|
||||
<tr><td width="33%"><%:UpLink Upgrade Status%></td><td id="_up_state"><em><%:Collecting data...%></em></td></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var run_state = document.getElementById('_run_state');
|
||||
var down_state = document.getElementById('_down_state');
|
||||
var up_state = document.getElementById('_up_state');
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "xlnetacc", "status")%>', null, function(x, status) {
|
||||
if ( x && x.status == 200 ) {
|
||||
run_state.innerHTML = status.run_state ? '<%:RUNNING%>' : '<%:NOT RUNNING%>';
|
||||
down_state.innerHTML = status.down_state ? status.down_state : '<%:No upgrade information%>';
|
||||
up_state.innerHTML = status.up_state ? status.up_state : '<%:No upgrade information%>';
|
||||
}
|
||||
});
|
||||
//]]></script>
|
@ -0,0 +1,5 @@
|
||||
|
||||
config general 'general'
|
||||
option enabled '0'
|
||||
option network 'wan'
|
||||
|
44
package/lean/luci-app-xlnetacc/files/root/etc/init.d/xlnetacc
Executable file
44
package/lean/luci-app-xlnetacc/files/root/etc/init.d/xlnetacc
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=95
|
||||
STOP=10
|
||||
SERVICE_DAEMONIZE=1
|
||||
|
||||
NAME=xlnetacc
|
||||
|
||||
start() {
|
||||
pidof "${NAME}.sh" >/dev/null 2>&1 && return
|
||||
|
||||
config_load "$NAME"
|
||||
config_get_bool enabled "general" "enabled" 0
|
||||
config_get_bool down_acc "general" "down_acc" 0
|
||||
config_get_bool up_acc "general" "up_acc" 0
|
||||
config_get network "general" "network"
|
||||
config_get account "general" "account"
|
||||
config_get encrypt "general" "encrypt"
|
||||
( [ $enabled -eq 0 ] || [ $down_acc -eq 0 -a $up_acc -eq 0 ] || [ -z "$account" -o -z "$encrypt" -o -z "$network" ] ) && return
|
||||
|
||||
logger -p "daemon.notice" -t "$NAME" "XLNetAcc is starting ..."
|
||||
service_start /usr/bin/${NAME}.sh --start
|
||||
}
|
||||
|
||||
stop() {
|
||||
pidof "${NAME}.sh" >/dev/null 2>&1 || return
|
||||
|
||||
local pid spid
|
||||
for pid in $(pidof "${NAME}.sh"); do
|
||||
kill $pid >/dev/null 2>&1
|
||||
echo "Stop XLNetAcc process PID: $pid"
|
||||
for spid in $(pgrep -P $pid "sleep"); do
|
||||
kill $spid >/dev/null 2>&1
|
||||
echo "Stop XLNetAcc process SPID: $spid"
|
||||
done
|
||||
done
|
||||
logger -p "daemon.notice" -t "$NAME" "XLNetAcc has stoped."
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
22
package/lean/luci-app-xlnetacc/files/root/etc/uci-defaults/luci-xlnetacc
Executable file
22
package/lean/luci-app-xlnetacc/files/root/etc/uci-defaults/luci-xlnetacc
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@xlnetacc[-1]
|
||||
add ucitrack xlnetacc
|
||||
set ucitrack.@xlnetacc[-1].init=xlnetacc
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
general=$(uci -q get xlnetacc.@general[-1])
|
||||
if [ -z "$general" ]; then
|
||||
uci -q add xlnetacc general
|
||||
fi
|
||||
if [ "$general"x != "general"x ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
rename xlnetacc.@general[-1]="general"
|
||||
commit xlnetacc
|
||||
EOF
|
||||
fi
|
||||
|
||||
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
|
||||
exit 0
|
512
package/lean/luci-app-xlnetacc/files/root/usr/bin/xlnetacc.sh
Normal file
512
package/lean/luci-app-xlnetacc/files/root/usr/bin/xlnetacc.sh
Normal file
@ -0,0 +1,512 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 声明常量
|
||||
readonly appName='com.xunlei.vip.swjsq'
|
||||
readonly protocolVersion=108
|
||||
readonly sdkVersion=17550
|
||||
readonly agentVersion='1.6.1.177600'
|
||||
readonly client_type_down='android-swjsq'
|
||||
readonly client_version_down='2.0.3.4'
|
||||
readonly client_type_up='android-uplink'
|
||||
readonly client_version_up='2.3.3.9'
|
||||
readonly client_os='android-7.0.24DUK-AL20'
|
||||
|
||||
# 声明全局变量
|
||||
_http_cmd=
|
||||
_http_args=
|
||||
_devicesign=
|
||||
_peerid=
|
||||
_userid=
|
||||
_sessionid=
|
||||
_api_url_down=
|
||||
_api_url_up=
|
||||
_dial_account_down=
|
||||
_dial_account_up=
|
||||
_cur_down=
|
||||
_max_down=
|
||||
_cur_up=
|
||||
_max_up=
|
||||
access_url=
|
||||
msg_to_en=
|
||||
msg_to_cn=
|
||||
|
||||
# 包含用于解析 JSON 格式返回值的函数
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
# 读取 UCI 设置相关函数
|
||||
uci_get_by_name() {
|
||||
local ret=$(uci get $NAME.$1.$2 2> /dev/null)
|
||||
echo -n ${ret:=$3}
|
||||
}
|
||||
uci_get_by_type() {
|
||||
local ret=$(uci get $NAME.@$1[-1].$2 2> /dev/null)
|
||||
echo -n ${ret:=$3}
|
||||
}
|
||||
uci_get_by_bool() {
|
||||
case $(uci_get_by_name "$1" "$2" "$3") in
|
||||
1|on|true|yes|enabled) echo -n 1;;
|
||||
*) echo -n 0;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 日志和状态栏输出。1 日志文件, 2 系统日志, 4 详细模式, 8 下行状态栏, 16 上行状态栏, 32 失败状态
|
||||
_log() {
|
||||
local msg=$1
|
||||
local flag=$2
|
||||
[ -z "$msg" ] && return
|
||||
[ -z "$flag" ] && flag=1
|
||||
local timestamp=$(date +'%Y/%m/%d %H:%M:%S')
|
||||
|
||||
[ $logging -eq 0 -a $(( $flag & 1 )) -ne 0 ] && flag=$(( $flag ^ 1 ))
|
||||
if [ $verbose -eq 0 -a $(( $flag & 4 )) -ne 0 ]; then
|
||||
[ $(( $flag & 1 )) -ne 0 ] && flag=$(( $flag ^ 1 ))
|
||||
[ $(( $flag & 2 )) -ne 0 ] && flag=$(( $flag ^ 2 ))
|
||||
fi
|
||||
if [ $down_acc -eq 0 -a $(( $flag & 8 )) -ne 0 ]; then
|
||||
flag=$(( $flag ^ 8 ))
|
||||
[ $up_acc -ne 0 ] && flag=$(( $flag | 16 ))
|
||||
fi
|
||||
if [ $up_acc -eq 0 -a $(( $flag & 16 )) -ne 0 ]; then
|
||||
flag=$(( $flag ^ 16 ))
|
||||
[ $down_acc -ne 0 ] && flag=$(( $flag | 8 ))
|
||||
fi
|
||||
|
||||
[ $(( $flag & 1 )) -ne 0 ] && echo "$timestamp $msg" >> $LOGFILE 2> /dev/null
|
||||
[ $(( $flag & 2 )) -ne 0 ] && logger -p "daemon.info" -t "$NAME" "$msg"
|
||||
|
||||
[ $(( $flag & 32 )) -eq 0 ] && local color="green" || local color="red"
|
||||
[ $(( $flag & 8 )) -ne 0 ] && echo -n "<font color=$color>$timestamp $msg</font>" > $down_state_file 2> /dev/null
|
||||
[ $(( $flag & 16 )) -ne 0 ] && echo -n "<font color=$color>$timestamp $msg</font>" > $up_state_file 2> /dev/null
|
||||
}
|
||||
|
||||
# 清理日志
|
||||
clean_log() {
|
||||
[ $logging -eq 1 -a -f "$LOGFILE" ] || return
|
||||
if [ $(wc -l "$LOGFILE" | awk '{print $1}') -gt 500 ]; then
|
||||
_log "清理日志文件"
|
||||
local logdata=$(tail -n 300 "$LOGFILE")
|
||||
echo "$logdata" > $LOGFILE 2> /dev/null
|
||||
unset logdata
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取接口IP地址
|
||||
get_acc_ip() {
|
||||
local acc_ipaddr
|
||||
json_cleanup; json_load "$(ubus call network.interface.$network status 2> /dev/null)" >/dev/null 2>&1
|
||||
json_select "ipv4-address" >/dev/null 2>&1; json_select 1 >/dev/null 2>&1
|
||||
json_get_var acc_ipaddr "address"
|
||||
[ -z "$acc_ipaddr" ] && { _log "获取网络 $network IP地址出错"; return; }
|
||||
_log "acc_ipaddr is $acc_ipaddr" $(( 1 | 4 ))
|
||||
|
||||
if [ "$acc_ipaddr" != "0.0.0.0" ]; then
|
||||
_log "绑定IP地址: $acc_ipaddr"
|
||||
echo -n "$acc_ipaddr"
|
||||
fi
|
||||
}
|
||||
|
||||
# 定义基本 HTTP 命令和参数
|
||||
gen_http_cmd() {
|
||||
_http_cmd="wget-ssl -nv -t 1 -O - --no-check-certificate"
|
||||
_http_cmd="$_http_cmd --bind-address=$1"
|
||||
_http_cmd="$_http_cmd --user-agent=android-async-http/xl-acc-sdk/version-$agentVersion"
|
||||
_log "_http_cmd is $_http_cmd" $(( 1 | 4 ))
|
||||
}
|
||||
|
||||
# 生成设备签名
|
||||
gen_device_sign() {
|
||||
local ifname macaddr
|
||||
while : ; do
|
||||
ifname=$(uci get "network.$network.ifname" 2> /dev/null)
|
||||
[ "${ifname:0:1}" == "@" ] && network="${ifname:1}" || break
|
||||
done
|
||||
[ -z "$ifname" ] && { _log "获取网络 $network 信息出错"; return; }
|
||||
json_cleanup; json_load "$(ubus call network.device status {\"name\":\"$ifname\"} 2> /dev/null)" >/dev/null 2>&1
|
||||
json_get_var macaddr "macaddr"
|
||||
[ -z "$macaddr" ] && { _log "获取网络 $network MAC地址出错"; return; }
|
||||
macaddr=$(echo -n "$macaddr" | awk '{print toupper($0)}')
|
||||
|
||||
# 根据MAC地址生成peerid
|
||||
readonly _peerid="${macaddr//:/}004V"
|
||||
_log "_peerid is $_peerid" $(( 1 | 4 ))
|
||||
|
||||
# 根据MAC地址生成devicesign
|
||||
local xlnetacc_vip="${appName}68700d1872b772946a6940e4b51827e8af"
|
||||
local fake_device_id_md5=$(echo -n "$macaddr" | md5sum | awk '{print $1}')
|
||||
local fake_device_id_sha1=$(echo -n "$fake_device_id_md5$xlnetacc_vip" | openssl sha1 -hmac | awk '{print $2}')
|
||||
readonly _devicesign="div100.$fake_device_id_md5"$(echo -n "$fake_device_id_sha1" | md5sum | awk '{print $1}')
|
||||
_log "_devicesign is $_devicesign" $(( 1 | 4 ))
|
||||
}
|
||||
|
||||
# 帐号登录
|
||||
xlnetacc_login() {
|
||||
# 生成POST数据
|
||||
json_init
|
||||
json_add_string userName "$account"
|
||||
json_add_int businessType 68
|
||||
json_add_string clientVersion "$client_version_down"
|
||||
json_add_string appName "ANDROID-$appName"
|
||||
json_add_int isCompressed 0
|
||||
json_add_int sequenceNo 1000001
|
||||
json_add_string sessionID
|
||||
json_add_int loginType 0
|
||||
json_add_object rsaKey
|
||||
json_add_string e '010001'
|
||||
json_add_string n 'AC69F5CCC8BDE47CD3D371603748378C9CFAD2938A6B021E0E191013975AD683F5CBF9ADE8BD7D46B4D2EC2D78AF146F1DD2D50DC51446BB8880B8CE88D476694DFC60594393BEEFAA16F5DBCEBE22F89D640F5336E42F587DC4AFEDEFEAC36CF007009CCCE5C1ACB4FF06FBA69802A8085C2C54BADD0597FC83E6870F1E36FD'
|
||||
json_close_object
|
||||
json_add_int cmdID 1
|
||||
json_add_string verifyCode
|
||||
json_add_string peerID "$_peerid"
|
||||
json_add_int protocolVersion $protocolVersion
|
||||
json_add_int platformVersion 1
|
||||
json_add_string passWord "$encrypt"
|
||||
json_add_string extensionList
|
||||
json_add_string verifyKey
|
||||
json_add_int sdkVersion $sdkVersion
|
||||
json_add_string devicesign "$_devicesign"
|
||||
json_close_object
|
||||
|
||||
local ret=$($_http_cmd 'https://login.mobile.reg2t.sandai.net:443/' --post-data="$(json_dump)")
|
||||
_log "ret is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno
|
||||
json_get_var errno "errorCode"
|
||||
json_get_var _userid "userID"
|
||||
_log "_userid is $_userid" $(( 1 | 4 ))
|
||||
json_get_var _sessionid "sessionID"
|
||||
_log "_sessionid is $_sessionid" $(( 1 | 4 ))
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ] || [ -z "$_userid" -o -z "$_sessionid" ]; then
|
||||
local errorDesc
|
||||
json_get_var errorDesc "errorDesc"
|
||||
local outmsg="帐号登录失败。错误代码: ${errno}"; \
|
||||
[ -n "$errorDesc" ] && outmsg="${outmsg},原因: $errorDesc"; _log "$outmsg" $(( 1 | 8 | 16 | 32 ))
|
||||
else
|
||||
local outmsg="帐号登录成功"; _log "$outmsg" $(( 1 | 8 | 16 ))
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 获取提速API
|
||||
xlnetacc_portal() {
|
||||
xlnetacc_var $1
|
||||
|
||||
[ $1 -eq 1 ] && access_url='http://api.portal.swjsq.vip.xunlei.com:81/v2/queryportal' || \
|
||||
access_url='http://api.upportal.swjsq.vip.xunlei.com/v2/queryportal'
|
||||
local ret=$($_http_cmd "$access_url")
|
||||
_log "$msg_to_en portal is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno portal_ip portal_port
|
||||
json_get_var errno "errno"
|
||||
json_get_var portal_ip "interface_ip"
|
||||
json_get_var portal_port "interface_port"
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ] || [ -z "$portal_ip" -o -z "$portal_port" ]; then
|
||||
local message
|
||||
json_get_var message "message"
|
||||
local outmsg="获取${msg_to_cn}API失败。错误代码: ${errno}"; \
|
||||
[ -n "$message" ] && outmsg="${outmsg},原因: $message"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
else
|
||||
local outmsg="获取${msg_to_cn}API成功"; _log "$outmsg" $(( 1 | $1 * 8 ))
|
||||
if [ $1 -eq 1 ]; then
|
||||
_api_url_down="http://$portal_ip:$portal_port/v2"
|
||||
_log "_api_url_down is $_api_url_down" $(( 1 | 4 ))
|
||||
else
|
||||
_api_url_up="http://$portal_ip:$portal_port/v2"
|
||||
_log "_api_url_up is $_api_url_up" $(( 1 | 4 ))
|
||||
fi
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 获取网络带宽信息
|
||||
xlnetacc_bandwidth() {
|
||||
xlnetacc_var $1
|
||||
|
||||
local ret=$($_http_cmd "$access_url/bandwidth?${_http_args}&time_and=$(date +%s)000")
|
||||
_log "$msg_to_en bandwidth is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno can_upgrade dial_account richmessage
|
||||
json_get_var errno "errno"
|
||||
json_get_var can_upgrade "can_upgrade"
|
||||
json_get_var dial_account "dial_account"
|
||||
json_get_var richmessage "richmessage"
|
||||
|
||||
# 获取带宽数据
|
||||
local cur_bandwidth max_bandwidth flag
|
||||
[ $1 -eq 1 ] && flag="downstream" || flag="upstream"
|
||||
json_select "bandwidth" >/dev/null 2>&1
|
||||
json_get_var cur_bandwidth "$flag"
|
||||
json_select; json_select "max_bandwidth" >/dev/null 2>&1
|
||||
json_get_var max_bandwidth "$flag"
|
||||
cur_bandwidth=$(expr $cur_bandwidth / 1024 2> /dev/null)
|
||||
max_bandwidth=$(expr $max_bandwidth / 1024 2> /dev/null)
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ]; then
|
||||
local outmsg="获取${msg_to_cn}带宽信息失败。错误代码: ${errno}"; \
|
||||
[ -n "$richmessage" ] && outmsg="${outmsg},原因: $richmessage"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
elif [ "$can_upgrade" -eq 0 ]; then
|
||||
local outmsg="${msg_to_cn}无法提速"; \
|
||||
[ -n "$richmessage" ] && outmsg="${outmsg},原因: $richmessage"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
[ $1 -eq 1 ] && down_acc=0 || up_acc=0
|
||||
errno=-2
|
||||
elif [ "$cur_bandwidth" -ge "$max_bandwidth" ]; then
|
||||
local outmsg="${msg_to_cn}无需提速。当前带宽 ${cur_bandwidth}M,超过最大可提升带宽 ${max_bandwidth}M"; \
|
||||
_log "$outmsg" $(( 1 | $1 * 8 ))
|
||||
[ $1 -eq 1 ] && down_acc=0 || up_acc=0
|
||||
errno=-3
|
||||
else
|
||||
local outmsg="${msg_to_cn}可以提速。当前带宽 ${cur_bandwidth}M,可提升至 ${max_bandwidth}M"; _log "$outmsg" $(( 1 | $1 * 8 ))
|
||||
if [ $1 -eq 1 ]; then
|
||||
_dial_account_down=$dial_account
|
||||
_log "_dial_account_down is $_dial_account_down" $(( 1 | 4 ))
|
||||
_cur_down=$cur_bandwidth
|
||||
_log "_cur_down is $_cur_down" $(( 1 | 4 ))
|
||||
_max_down=$max_bandwidth
|
||||
_log "_max_down is $_max_down" $(( 1 | 4 ))
|
||||
else
|
||||
_dial_account_up=$dial_account
|
||||
_log "_dial_account_up is $_dial_account_up" $(( 1 | 4 ))
|
||||
_cur_up=$cur_bandwidth
|
||||
_log "_cur_up is $_cur_up" $(( 1 | 4 ))
|
||||
_max_up=$max_bandwidth
|
||||
_log "_max_up is $_max_up" $(( 1 | 4 ))
|
||||
fi
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 发送带宽提速信号
|
||||
xlnetacc_upgrade() {
|
||||
xlnetacc_var $1
|
||||
|
||||
local ret=$($_http_cmd "$access_url/upgrade?${_http_args}&time_and=$(date +%s)000")
|
||||
_log "$msg_to_en upgrade is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno
|
||||
json_get_var errno "errno"
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ]; then
|
||||
local richmessage
|
||||
json_get_var richmessage "richmessage"
|
||||
local outmsg="${msg_to_cn}提速失败。错误代码: ${errno}"; \
|
||||
[ -n "$richmessage" ] && outmsg="${outmsg},原因: $richmessage"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
[ $errno -ne -1 ] && { [ $1 -eq 1 ] && down_acc=0 || up_acc=0; }
|
||||
else
|
||||
[ $1 -eq 1 ] && local cur_bandwidth=$_cur_down || local cur_bandwidth=$_cur_up
|
||||
[ $1 -eq 1 ] && local max_bandwidth=$_max_down || local max_bandwidth=$_max_up
|
||||
local outmsg="${msg_to_cn}提速成功,带宽已从 ${cur_bandwidth}M 提升到 ${max_bandwidth}M"; _log "$outmsg" $(( 1 | $1 * 8 ))
|
||||
[ $1 -eq 1 ] && down_acc=2 || up_acc=2
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 发送提速心跳信号
|
||||
xlnetacc_keepalive() {
|
||||
xlnetacc_var $1
|
||||
|
||||
local ret=$($_http_cmd "$access_url/keepalive?${_http_args}&time_and=$(date +%s)000")
|
||||
_log "$msg_to_en keepalive is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno
|
||||
json_get_var errno "errno"
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ]; then
|
||||
local richmessage
|
||||
json_get_var richmessage "richmessage"
|
||||
local outmsg="${msg_to_cn}提速失效。错误代码: ${errno}"; \
|
||||
[ -n "$richmessage" ] && outmsg="${outmsg},原因: $richmessage"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
[ $1 -eq 1 ] && down_acc=1 || up_acc=1
|
||||
else
|
||||
_log "${msg_to_cn}心跳信号返回正常"
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 发送带宽恢复信号
|
||||
xlnetacc_recover() {
|
||||
xlnetacc_var $1
|
||||
|
||||
local ret=$($_http_cmd "$access_url/recover?${_http_args}&time_and=$(date +%s)000")
|
||||
_log "$msg_to_en recover is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno
|
||||
json_get_var errno "errno"
|
||||
|
||||
if [ ${errno:=-1} -ne 0 ]; then
|
||||
local richmessage
|
||||
json_get_var richmessage "richmessage"
|
||||
local outmsg="${msg_to_cn}带宽恢复失败。错误代码: ${errno}"; \
|
||||
[ -n "$richmessage" ] && outmsg="${outmsg},原因: $richmessage"; _log "$outmsg" $(( 1 | $1 * 8 | 32 ))
|
||||
else
|
||||
_log "${msg_to_cn}带宽已恢复"
|
||||
[ $1 -eq 1 ] && down_acc=1 || up_acc=1
|
||||
fi
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 查询提速信息,未使用
|
||||
xlnetacc_query() {
|
||||
xlnetacc_var $1
|
||||
|
||||
local ret=$($_http_cmd "$access_url/query_try_info?${_http_args}&time_and=$(date +%s)000")
|
||||
_log "$msg_to_en query_try_info is $ret" $(( 1 | 4 ))
|
||||
json_cleanup; json_load "$ret" >/dev/null 2>&1
|
||||
local errno
|
||||
json_get_var errno "errno"
|
||||
|
||||
return $errno
|
||||
}
|
||||
|
||||
# 带宽提速处理
|
||||
xlnetacc_acc() {
|
||||
_api_url_down=; _api_url_up=
|
||||
_dial_account_down=; _dial_account_up=
|
||||
_cur_down=0; _max_down=0; _cur_up=0; _max_up=0
|
||||
|
||||
xlnetacc_portal $1 || return
|
||||
xlnetacc_bandwidth $1 || return
|
||||
xlnetacc_upgrade $1
|
||||
}
|
||||
|
||||
# 设置参数变量
|
||||
xlnetacc_var() {
|
||||
if [ $1 -eq 1 ]; then
|
||||
access_url=$_api_url_down
|
||||
_http_args="peerid=${_peerid}&userid=${_userid}&user_type=1&sessionid=${_sessionid}&dial_account=${_dial_account_down}&client_type=${client_type_down}-${client_version_down}&client_version=${client_type_down//-/}-${client_version_down}&os=${client_os}"
|
||||
msg_to_en="DownLink"
|
||||
msg_to_cn="下行"
|
||||
else
|
||||
access_url=$_api_url_up
|
||||
_http_args="peerid=${_peerid}&userid=${_userid}&user_type=1&sessionid=${_sessionid}&dial_account=${_dial_account_up}&client_type=${client_type_up}-${client_version_up}&client_version=${client_type_up//-/}-${client_version_up}&os=${client_os}"
|
||||
msg_to_en="UpLink"
|
||||
msg_to_cn="上行"
|
||||
fi
|
||||
}
|
||||
|
||||
# 中止信号处理
|
||||
sigterm() {
|
||||
_log "trap sigterm, exit" $(( 1 | 4 ))
|
||||
[ $down_acc -eq 2 ] && xlnetacc_recover 1
|
||||
[ $up_acc -eq 2 ] && xlnetacc_recover 2
|
||||
rm -f "$down_state_file" "$up_state_file"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 初始化
|
||||
xlnetacc_init() {
|
||||
[ "$1" != "--start" ] && return 1
|
||||
|
||||
# 防止重复启动
|
||||
local pid
|
||||
for pid in $(pidof "${0##*/}"); do
|
||||
[ $pid -ne $$ ] && return 1
|
||||
done
|
||||
|
||||
# 读取设置
|
||||
readonly NAME=xlnetacc
|
||||
readonly LOGFILE=/var/log/${NAME}.log
|
||||
readonly down_state_file=/var/state/${NAME}_down_state
|
||||
readonly up_state_file=/var/state/${NAME}_up_state
|
||||
down_acc=$(uci_get_by_bool "general" "down_acc" 0)
|
||||
up_acc=$(uci_get_by_bool "general" "up_acc" 0)
|
||||
readonly logging=$(uci_get_by_bool "general" "logging" 1)
|
||||
readonly verbose=$(uci_get_by_bool "general" "verbose" 0)
|
||||
readonly network=$(uci_get_by_name "general" "network" "wan")
|
||||
readonly account=$(uci_get_by_name "general" "account")
|
||||
readonly encrypt=$(uci_get_by_name "general" "encrypt")
|
||||
local enabled=$(uci_get_by_bool "general" "enabled" 0)
|
||||
local password=$(uci_get_by_name "general" "password")
|
||||
( [ $enabled -eq 0 ] || [ $down_acc -eq 0 -a $up_acc -eq 0 ] || [ -z "$account" -o -z "$encrypt" -o -z "$network" ] ) && return 2
|
||||
|
||||
[ $logging -eq 1 ] && [ ! -d /var/log ] && mkdir -p /var/log
|
||||
_log "------------------------------"
|
||||
_log "迅雷快鸟正在启动..."
|
||||
_log "down_acc is $down_acc" $(( 1 | 4 ))
|
||||
_log "up_acc is $up_acc" $(( 1 | 4 ))
|
||||
_log "network is $network" $(( 1 | 4 ))
|
||||
_log "account is $account" $(( 1 | 4 ))
|
||||
_log "encrypt is $encrypt" $(( 1 | 4 ))
|
||||
|
||||
# 检查外部调用工具
|
||||
command -v wget-ssl >/dev/null || { _log "GNU Wget 工具不存在"; return 3; }
|
||||
command -v md5sum >/dev/null || { _log "md5sum 工具不存在"; return 3; }
|
||||
command -v openssl >/dev/null || { _log "openssl 工具不存在"; return 3; }
|
||||
|
||||
# 检查明文密码
|
||||
if [ -n "$password" ]; then
|
||||
_log "移除已保存的明文密码"
|
||||
uci delete "${NAME}.general.password"
|
||||
uci commit "$NAME"
|
||||
fi
|
||||
|
||||
# 捕获中止信号
|
||||
trap "sigterm" INT
|
||||
trap "sigterm" TERM
|
||||
|
||||
# 生成设备签名
|
||||
gen_device_sign
|
||||
[ -z "$_peerid" -o -z "$_devicesign" ] && return 4
|
||||
|
||||
clean_log
|
||||
[ -d /var/state ] || mkdir -p /var/state
|
||||
return 0
|
||||
}
|
||||
|
||||
# 程序主体
|
||||
xlnetacc_main() {
|
||||
while : ; do
|
||||
# 获取外网IP地址
|
||||
while : ; do
|
||||
local bind_ip=$(get_acc_ip)
|
||||
if [ -z "$bind_ip" ]; then
|
||||
sleep 5s # 获取失败
|
||||
else
|
||||
gen_http_cmd "$bind_ip"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 帐号登录
|
||||
while : ; do
|
||||
xlnetacc_login
|
||||
case $? in
|
||||
0) break;; # 登录成功
|
||||
6) sleep 30m;; # 需要输入验证码,等待30分钟后重试
|
||||
-1) sleep 3m;; # 未返回有效数据,等待3分钟后重试
|
||||
*) return 5;; # 登录失败
|
||||
esac
|
||||
done
|
||||
|
||||
# 10秒检查提速状态,300秒发送心跳包
|
||||
local timer_begin=$(date +%s); local timer_count=
|
||||
while : ; do
|
||||
[ $down_acc -eq 0 -a $up_acc -eq 0 ] && break 2
|
||||
[ $down_acc -eq 1 ] && xlnetacc_acc 1
|
||||
[ $up_acc -eq 1 ] && xlnetacc_acc 2
|
||||
|
||||
sleep 10s
|
||||
timer_count=$(( $(date +%s) - $timer_begin ))
|
||||
[ $timer_count -lt 300 ] && continue
|
||||
timer_begin=$(date +%s)
|
||||
clean_log # 清理日志
|
||||
|
||||
[ $down_acc -eq 2 ] && { xlnetacc_keepalive 1; [ $? -eq -1 ] && break; }
|
||||
[ $up_acc -eq 2 ] && { xlnetacc_keepalive 2; [ $? -eq -1 ] && break; }
|
||||
done
|
||||
[ $down_acc -eq 2 ] && { xlnetacc_recover 1; down_acc=1; }
|
||||
[ $up_acc -eq 2 ] && { xlnetacc_recover 2; up_acc=1; }
|
||||
done
|
||||
_log "程序异常,迅雷快鸟已停止。"
|
||||
}
|
||||
|
||||
# 程序入口
|
||||
xlnetacc_init $*
|
||||
[ $? -eq 0 ] && xlnetacc_main
|
||||
exit $?
|
12
package/lean/luci-app-xlnetacc/tools/po2lmo/Makefile
Normal file
12
package/lean/luci-app-xlnetacc/tools/po2lmo/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
INSTALL = install
|
||||
PREFIX = /usr/bin
|
||||
|
||||
po2lmo: src/po2lmo.o src/template_lmo.o
|
||||
$(CC) $(LDFLAGS) -o src/po2lmo src/po2lmo.o src/template_lmo.o
|
||||
|
||||
install:
|
||||
$(INSTALL) -m 755 src/po2lmo $(PREFIX)
|
||||
|
||||
clean:
|
||||
$(RM) src/po2lmo src/*.o
|
247
package/lean/luci-app-xlnetacc/tools/po2lmo/src/po2lmo.c
Normal file
247
package/lean/luci-app-xlnetacc/tools/po2lmo/src/po2lmo.c
Normal file
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* lmo - Lua Machine Objects - PO to LMO conversion tool
|
||||
*
|
||||
* Copyright (C) 2009-2012 Jo-Philipp Wich <xm@subsignal.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "template_lmo.h"
|
||||
|
||||
static void die(const char *msg)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void print(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
if( fwrite(ptr, size, nmemb, stream) == 0 )
|
||||
die("Failed to write stdout");
|
||||
}
|
||||
|
||||
static int extract_string(const char *src, char *dest, int len)
|
||||
{
|
||||
int pos = 0;
|
||||
int esc = 0;
|
||||
int off = -1;
|
||||
|
||||
for( pos = 0; (pos < strlen(src)) && (pos < len); pos++ )
|
||||
{
|
||||
if( (off == -1) && (src[pos] == '"') )
|
||||
{
|
||||
off = pos + 1;
|
||||
}
|
||||
else if( off >= 0 )
|
||||
{
|
||||
if( esc == 1 )
|
||||
{
|
||||
switch (src[pos])
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
off++;
|
||||
break;
|
||||
}
|
||||
dest[pos-off] = src[pos];
|
||||
esc = 0;
|
||||
}
|
||||
else if( src[pos] == '\\' )
|
||||
{
|
||||
dest[pos-off] = src[pos];
|
||||
esc = 1;
|
||||
}
|
||||
else if( src[pos] != '"' )
|
||||
{
|
||||
dest[pos-off] = src[pos];
|
||||
}
|
||||
else
|
||||
{
|
||||
dest[pos-off] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (off > -1) ? strlen(dest) : -1;
|
||||
}
|
||||
|
||||
static int cmp_index(const void *a, const void *b)
|
||||
{
|
||||
uint32_t x = ((const lmo_entry_t *)a)->key_id;
|
||||
uint32_t y = ((const lmo_entry_t *)b)->key_id;
|
||||
|
||||
if (x < y)
|
||||
return -1;
|
||||
else if (x > y)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_uint32(uint32_t x, FILE *out)
|
||||
{
|
||||
uint32_t y = htonl(x);
|
||||
print(&y, sizeof(uint32_t), 1, out);
|
||||
}
|
||||
|
||||
static void print_index(void *array, int n, FILE *out)
|
||||
{
|
||||
lmo_entry_t *e;
|
||||
|
||||
qsort(array, n, sizeof(*e), cmp_index);
|
||||
|
||||
for (e = array; n > 0; n--, e++)
|
||||
{
|
||||
print_uint32(e->key_id, out);
|
||||
print_uint32(e->val_id, out);
|
||||
print_uint32(e->offset, out);
|
||||
print_uint32(e->length, out);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char line[4096];
|
||||
char key[4096];
|
||||
char val[4096];
|
||||
char tmp[4096];
|
||||
int state = 0;
|
||||
int offset = 0;
|
||||
int length = 0;
|
||||
int n_entries = 0;
|
||||
void *array = NULL;
|
||||
lmo_entry_t *entry = NULL;
|
||||
uint32_t key_id, val_id;
|
||||
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if( (argc != 3) || ((in = fopen(argv[1], "r")) == NULL) || ((out = fopen(argv[2], "w")) == NULL) )
|
||||
usage(argv[0]);
|
||||
|
||||
memset(line, 0, sizeof(key));
|
||||
memset(key, 0, sizeof(val));
|
||||
memset(val, 0, sizeof(val));
|
||||
|
||||
while( (NULL != fgets(line, sizeof(line), in)) || (state >= 2 && feof(in)) )
|
||||
{
|
||||
if( state == 0 && strstr(line, "msgid \"") == line )
|
||||
{
|
||||
switch(extract_string(line, key, sizeof(key)))
|
||||
{
|
||||
case -1:
|
||||
die("Syntax error in msgid");
|
||||
case 0:
|
||||
state = 1;
|
||||
break;
|
||||
default:
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
else if( state == 1 || state == 2 )
|
||||
{
|
||||
if( strstr(line, "msgstr \"") == line || state == 2 )
|
||||
{
|
||||
switch(extract_string(line, val, sizeof(val)))
|
||||
{
|
||||
case -1:
|
||||
state = 4;
|
||||
break;
|
||||
default:
|
||||
state = 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(extract_string(line, tmp, sizeof(tmp)))
|
||||
{
|
||||
case -1:
|
||||
state = 2;
|
||||
break;
|
||||
default:
|
||||
strcat(key, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( state == 3 )
|
||||
{
|
||||
switch(extract_string(line, tmp, sizeof(tmp)))
|
||||
{
|
||||
case -1:
|
||||
state = 4;
|
||||
break;
|
||||
default:
|
||||
strcat(val, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if( state == 4 )
|
||||
{
|
||||
if( strlen(key) > 0 && strlen(val) > 0 )
|
||||
{
|
||||
key_id = sfh_hash(key, strlen(key));
|
||||
val_id = sfh_hash(val, strlen(val));
|
||||
|
||||
if( key_id != val_id )
|
||||
{
|
||||
n_entries++;
|
||||
array = realloc(array, n_entries * sizeof(lmo_entry_t));
|
||||
entry = (lmo_entry_t *)array + n_entries - 1;
|
||||
|
||||
if (!array)
|
||||
die("Out of memory");
|
||||
|
||||
entry->key_id = key_id;
|
||||
entry->val_id = val_id;
|
||||
entry->offset = offset;
|
||||
entry->length = strlen(val);
|
||||
|
||||
length = strlen(val) + ((4 - (strlen(val) % 4)) % 4);
|
||||
|
||||
print(val, length, 1, out);
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
|
||||
state = 0;
|
||||
memset(key, 0, sizeof(key));
|
||||
memset(val, 0, sizeof(val));
|
||||
}
|
||||
|
||||
memset(line, 0, sizeof(line));
|
||||
}
|
||||
|
||||
print_index(array, n_entries, out);
|
||||
|
||||
if( offset > 0 )
|
||||
{
|
||||
print_uint32(offset, out);
|
||||
fsync(fileno(out));
|
||||
fclose(out);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(out);
|
||||
unlink(argv[2]);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
return(0);
|
||||
}
|
328
package/lean/luci-app-xlnetacc/tools/po2lmo/src/template_lmo.c
Normal file
328
package/lean/luci-app-xlnetacc/tools/po2lmo/src/template_lmo.c
Normal file
@ -0,0 +1,328 @@
|
||||
/*
|
||||
* lmo - Lua Machine Objects - Base functions
|
||||
*
|
||||
* Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "template_lmo.h"
|
||||
|
||||
/*
|
||||
* Hash function from http://www.azillionmonkeys.com/qed/hash.html
|
||||
* Copyright (C) 2004-2008 by Paul Hsieh
|
||||
*/
|
||||
|
||||
uint32_t sfh_hash(const char *data, int len)
|
||||
{
|
||||
uint32_t hash = len, tmp;
|
||||
int rem;
|
||||
|
||||
if (len <= 0 || data == NULL) return 0;
|
||||
|
||||
rem = len & 3;
|
||||
len >>= 2;
|
||||
|
||||
/* Main loop */
|
||||
for (;len > 0; len--) {
|
||||
hash += sfh_get16(data);
|
||||
tmp = (sfh_get16(data+2) << 11) ^ hash;
|
||||
hash = (hash << 16) ^ tmp;
|
||||
data += 2*sizeof(uint16_t);
|
||||
hash += hash >> 11;
|
||||
}
|
||||
|
||||
/* Handle end cases */
|
||||
switch (rem) {
|
||||
case 3: hash += sfh_get16(data);
|
||||
hash ^= hash << 16;
|
||||
hash ^= data[sizeof(uint16_t)] << 18;
|
||||
hash += hash >> 11;
|
||||
break;
|
||||
case 2: hash += sfh_get16(data);
|
||||
hash ^= hash << 11;
|
||||
hash += hash >> 17;
|
||||
break;
|
||||
case 1: hash += *data;
|
||||
hash ^= hash << 10;
|
||||
hash += hash >> 1;
|
||||
}
|
||||
|
||||
/* Force "avalanching" of final 127 bits */
|
||||
hash ^= hash << 3;
|
||||
hash += hash >> 5;
|
||||
hash ^= hash << 4;
|
||||
hash += hash >> 17;
|
||||
hash ^= hash << 25;
|
||||
hash += hash >> 6;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t lmo_canon_hash(const char *str, int len)
|
||||
{
|
||||
char res[4096];
|
||||
char *ptr, prev;
|
||||
int off;
|
||||
|
||||
if (!str || len >= sizeof(res))
|
||||
return 0;
|
||||
|
||||
for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++)
|
||||
{
|
||||
if (isspace(*str))
|
||||
{
|
||||
if (!isspace(prev))
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = *str;
|
||||
}
|
||||
}
|
||||
|
||||
if ((ptr > res) && isspace(*(ptr-1)))
|
||||
ptr--;
|
||||
|
||||
return sfh_hash(res, ptr - res);
|
||||
}
|
||||
|
||||
lmo_archive_t * lmo_open(const char *file)
|
||||
{
|
||||
int in = -1;
|
||||
uint32_t idx_offset = 0;
|
||||
struct stat s;
|
||||
|
||||
lmo_archive_t *ar = NULL;
|
||||
|
||||
if (stat(file, &s) == -1)
|
||||
goto err;
|
||||
|
||||
if ((in = open(file, O_RDONLY)) == -1)
|
||||
goto err;
|
||||
|
||||
if ((ar = (lmo_archive_t *)malloc(sizeof(*ar))) != NULL)
|
||||
{
|
||||
memset(ar, 0, sizeof(*ar));
|
||||
|
||||
ar->fd = in;
|
||||
ar->size = s.st_size;
|
||||
|
||||
fcntl(ar->fd, F_SETFD, fcntl(ar->fd, F_GETFD) | FD_CLOEXEC);
|
||||
|
||||
if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED)
|
||||
goto err;
|
||||
|
||||
idx_offset = ntohl(*((const uint32_t *)
|
||||
(ar->mmap + ar->size - sizeof(uint32_t))));
|
||||
|
||||
if (idx_offset >= ar->size)
|
||||
goto err;
|
||||
|
||||
ar->index = (lmo_entry_t *)(ar->mmap + idx_offset);
|
||||
ar->length = (ar->size - idx_offset - sizeof(uint32_t)) / sizeof(lmo_entry_t);
|
||||
ar->end = ar->mmap + ar->size;
|
||||
|
||||
return ar;
|
||||
}
|
||||
|
||||
err:
|
||||
if (in > -1)
|
||||
close(in);
|
||||
|
||||
if (ar != NULL)
|
||||
{
|
||||
if ((ar->mmap != NULL) && (ar->mmap != MAP_FAILED))
|
||||
munmap(ar->mmap, ar->size);
|
||||
|
||||
free(ar);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void lmo_close(lmo_archive_t *ar)
|
||||
{
|
||||
if (ar != NULL)
|
||||
{
|
||||
if ((ar->mmap != NULL) && (ar->mmap != MAP_FAILED))
|
||||
munmap(ar->mmap, ar->size);
|
||||
|
||||
close(ar->fd);
|
||||
free(ar);
|
||||
|
||||
ar = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lmo_catalog_t *_lmo_catalogs = NULL;
|
||||
lmo_catalog_t *_lmo_active_catalog = NULL;
|
||||
|
||||
int lmo_load_catalog(const char *lang, const char *dir)
|
||||
{
|
||||
DIR *dh = NULL;
|
||||
char pattern[16];
|
||||
char path[PATH_MAX];
|
||||
struct dirent *de = NULL;
|
||||
|
||||
lmo_archive_t *ar = NULL;
|
||||
lmo_catalog_t *cat = NULL;
|
||||
|
||||
if (!lmo_change_catalog(lang))
|
||||
return 0;
|
||||
|
||||
if (!dir || !(dh = opendir(dir)))
|
||||
goto err;
|
||||
|
||||
if (!(cat = malloc(sizeof(*cat))))
|
||||
goto err;
|
||||
|
||||
memset(cat, 0, sizeof(*cat));
|
||||
|
||||
snprintf(cat->lang, sizeof(cat->lang), "%s", lang);
|
||||
snprintf(pattern, sizeof(pattern), "*.%s.lmo", lang);
|
||||
|
||||
while ((de = readdir(dh)) != NULL)
|
||||
{
|
||||
if (!fnmatch(pattern, de->d_name, 0))
|
||||
{
|
||||
snprintf(path, sizeof(path), "%s/%s", dir, de->d_name);
|
||||
ar = lmo_open(path);
|
||||
|
||||
if (ar)
|
||||
{
|
||||
ar->next = cat->archives;
|
||||
cat->archives = ar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dh);
|
||||
|
||||
cat->next = _lmo_catalogs;
|
||||
_lmo_catalogs = cat;
|
||||
|
||||
if (!_lmo_active_catalog)
|
||||
_lmo_active_catalog = cat;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
if (dh) closedir(dh);
|
||||
if (cat) free(cat);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lmo_change_catalog(const char *lang)
|
||||
{
|
||||
lmo_catalog_t *cat;
|
||||
|
||||
for (cat = _lmo_catalogs; cat; cat = cat->next)
|
||||
{
|
||||
if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
|
||||
{
|
||||
_lmo_active_catalog = cat;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash)
|
||||
{
|
||||
unsigned int m, l, r;
|
||||
uint32_t k;
|
||||
|
||||
l = 0;
|
||||
r = ar->length - 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
m = l + ((r - l) / 2);
|
||||
|
||||
if (r < l)
|
||||
break;
|
||||
|
||||
k = ntohl(ar->index[m].key_id);
|
||||
|
||||
if (k == hash)
|
||||
return &ar->index[m];
|
||||
|
||||
if (k > hash)
|
||||
{
|
||||
if (!m)
|
||||
break;
|
||||
|
||||
r = m - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lmo_translate(const char *key, int keylen, char **out, int *outlen)
|
||||
{
|
||||
uint32_t hash;
|
||||
lmo_entry_t *e;
|
||||
lmo_archive_t *ar;
|
||||
|
||||
if (!key || !_lmo_active_catalog)
|
||||
return -2;
|
||||
|
||||
hash = lmo_canon_hash(key, keylen);
|
||||
|
||||
for (ar = _lmo_active_catalog->archives; ar; ar = ar->next)
|
||||
{
|
||||
if ((e = lmo_find_entry(ar, hash)) != NULL)
|
||||
{
|
||||
*out = ar->mmap + ntohl(e->offset);
|
||||
*outlen = ntohl(e->length);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void lmo_close_catalog(const char *lang)
|
||||
{
|
||||
lmo_archive_t *ar, *next;
|
||||
lmo_catalog_t *cat, *prev;
|
||||
|
||||
for (prev = NULL, cat = _lmo_catalogs; cat; prev = cat, cat = cat->next)
|
||||
{
|
||||
if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
|
||||
{
|
||||
if (prev)
|
||||
prev->next = cat->next;
|
||||
else
|
||||
_lmo_catalogs = cat->next;
|
||||
|
||||
for (ar = cat->archives; ar; ar = next)
|
||||
{
|
||||
next = ar->next;
|
||||
lmo_close(ar);
|
||||
}
|
||||
|
||||
free(cat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* lmo - Lua Machine Objects - General header
|
||||
*
|
||||
* Copyright (C) 2009-2012 Jo-Philipp Wich <xm@subsignal.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _TEMPLATE_LMO_H_
|
||||
#define _TEMPLATE_LMO_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if (defined(__GNUC__) && defined(__i386__))
|
||||
#define sfh_get16(d) (*((const uint16_t *) (d)))
|
||||
#else
|
||||
#define sfh_get16(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
|
||||
+(uint32_t)(((const uint8_t *)(d))[0]) )
|
||||
#endif
|
||||
|
||||
|
||||
struct lmo_entry {
|
||||
uint32_t key_id;
|
||||
uint32_t val_id;
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct lmo_entry lmo_entry_t;
|
||||
|
||||
|
||||
struct lmo_archive {
|
||||
int fd;
|
||||
int length;
|
||||
uint32_t size;
|
||||
lmo_entry_t *index;
|
||||
char *mmap;
|
||||
char *end;
|
||||
struct lmo_archive *next;
|
||||
};
|
||||
|
||||
typedef struct lmo_archive lmo_archive_t;
|
||||
|
||||
|
||||
struct lmo_catalog {
|
||||
char lang[6];
|
||||
struct lmo_archive *archives;
|
||||
struct lmo_catalog *next;
|
||||
};
|
||||
|
||||
typedef struct lmo_catalog lmo_catalog_t;
|
||||
|
||||
|
||||
uint32_t sfh_hash(const char *data, int len);
|
||||
uint32_t lmo_canon_hash(const char *data, int len);
|
||||
|
||||
lmo_archive_t * lmo_open(const char *file);
|
||||
void lmo_close(lmo_archive_t *ar);
|
||||
|
||||
|
||||
extern lmo_catalog_t *_lmo_catalogs;
|
||||
extern lmo_catalog_t *_lmo_active_catalog;
|
||||
|
||||
int lmo_load_catalog(const char *lang, const char *dir);
|
||||
int lmo_change_catalog(const char *lang);
|
||||
int lmo_translate(const char *key, int keylen, char **out, int *outlen);
|
||||
void lmo_close_catalog(const char *lang);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user