mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 17:33:31 +00:00
luci-ssr-plus: add ss/v2ray URI import support
This commit is contained in:
parent
667a56888f
commit
a99a8179b4
@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-ssr-plus
|
||||
PKG_VERSION:=1
|
||||
PKG_RELEASE:=101
|
||||
PKG_RELEASE:=102
|
||||
|
||||
PKG_CONFIG_DEPENDS:= CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Shadowsocks \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_V2ray \
|
||||
|
@ -115,11 +115,10 @@ s = m:section(NamedSection, sid, "servers")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(DummyValue,"ssr_url","SSR URL")
|
||||
o = s:option(DummyValue,"ssr_url","SS/SSR/V2RAY URL")
|
||||
o.rawhtml = true
|
||||
o.template = "shadowsocksr/ssrurl"
|
||||
o.value =sid
|
||||
o:depends("type", "ssr")
|
||||
|
||||
o = s:option(ListValue, "type", translate("Server Node Type"))
|
||||
o:value("ssr", translate("ShadowsocksR"))
|
||||
|
@ -1,139 +1,202 @@
|
||||
<%+cbi/valueheader%>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function padright(str, cnt, pad){
|
||||
return str + Array(cnt+1).join(pad);
|
||||
}
|
||||
function b64EncodeUnicode(str) {
|
||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
|
||||
return String.fromCharCode('0x' + p1);
|
||||
}));
|
||||
}
|
||||
function b64encutf8safe(str) {
|
||||
return b64EncodeUnicode(str).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,'');
|
||||
}
|
||||
function b64DecodeUnicode(str) {
|
||||
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
|
||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||
}).join(''));
|
||||
}
|
||||
function b64decutf8safe(str) {
|
||||
var l;
|
||||
str = str.replace(/-/g,"+").replace(/_/g,"/");
|
||||
l = str.length;
|
||||
l = (4 - l % 4)%4;
|
||||
if( l )
|
||||
str = padright(str,l,"=");
|
||||
return b64DecodeUnicode(str);
|
||||
}
|
||||
function b64encsafe(str){
|
||||
return btoa(str).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,'')
|
||||
}
|
||||
function b64decsafe(str){
|
||||
var l;
|
||||
str = str.replace(/-/g,"+").replace(/_/g,"/");
|
||||
l = str.length;
|
||||
l = (4 - l % 4)%4;
|
||||
if( l )
|
||||
str = padright(str,l,"=");
|
||||
return atob(str);
|
||||
}
|
||||
function dictvalue(d,key) {
|
||||
var v = d[key];
|
||||
if( typeof(v)=='undefined' || v=='' )
|
||||
return '';
|
||||
return b64decsafe(v);
|
||||
}
|
||||
function export_ssr_url(btn,urlname,sid) {
|
||||
var s = document.getElementById(urlname+'-status');
|
||||
if(!s)
|
||||
return false;
|
||||
var v_server = document.getElementById('cbid.shadowsocksr.'+sid+'.server');
|
||||
var v_port = document.getElementById('cbid.shadowsocksr.'+sid+'.server_port');
|
||||
var v_protocol = document.getElementById('cbid.shadowsocksr.'+sid+'.protocol');
|
||||
var v_method = document.getElementById('cbid.shadowsocksr.'+sid+'.encrypt_method');
|
||||
var v_obfs = document.getElementById('cbid.shadowsocksr.'+sid+'.obfs');
|
||||
var v_password = document.getElementById('cbid.shadowsocksr.'+sid+'.password');
|
||||
var v_obfs_param = document.getElementById('cbid.shadowsocksr.'+sid+'.obfs_param');
|
||||
var v_protocol_param = document.getElementById('cbid.shadowsocksr.'+sid+'.protocol_param');
|
||||
var v_alias = document.getElementById('cbid.shadowsocksr.'+sid+'.alias');
|
||||
|
||||
var ssr_str = v_server.value+":"+
|
||||
v_port.value+":"+
|
||||
v_protocol.value+":"+
|
||||
v_method.value+":"+
|
||||
v_obfs.value+":"+
|
||||
b64encsafe(v_password.value)+
|
||||
"/?obfsparam="+b64encsafe(v_obfs_param.value)+
|
||||
"&protoparam="+b64encsafe(v_protocol_param.value)+
|
||||
"&remarks="+b64encutf8safe(v_alias.value);
|
||||
var textarea = document.createElement("textarea");
|
||||
textarea.textContent = "ssr://"+b64encsafe(ssr_str);
|
||||
textarea.style.position = "fixed";
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
||||
s.innerHTML = "<font color='green'><%:Copy SSR to clipboard successfully.%></font>";
|
||||
} catch (ex) {
|
||||
s.innerHTML = "<font color='red'><%:Unable to copy SSR to clipboard.%></font>";
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function import_ssr_url(btn,urlname,sid) {
|
||||
var s = document.getElementById(urlname+'-status');
|
||||
if(!s)
|
||||
return false;
|
||||
var ssrurl = prompt("<%:Paste ssr url here%>", "ssr://");
|
||||
if (ssrurl == null || ssrurl == "") {
|
||||
s.innerHTML = "<font color='red'><%:User cancelled.%></font>";
|
||||
return false;
|
||||
}
|
||||
s.innerHTML = "<font color='red'><%:Invalid SSR format.%></font>";
|
||||
var ssu = ssrurl.match(/ssr:\/\/([A-Za-z0-9_-]+)/i);
|
||||
if( !ssu || ssu.length<2 )
|
||||
return false;
|
||||
var sstr = b64decsafe(ssu[1]);
|
||||
var ploc = sstr.indexOf("/?");
|
||||
var url0, param="";
|
||||
if( ploc>0 ) {
|
||||
url0 = sstr.substr(0,ploc);
|
||||
param = sstr.substr(ploc+2);
|
||||
}
|
||||
var ssm = url0.match(/^(.+):([^:]+):([^:]*):([^:]+):([^:]*):([^:]+)/);
|
||||
if( !ssm || ssm.length<7 )
|
||||
return false;
|
||||
var pdict = {};
|
||||
if( param.length>2 )
|
||||
{
|
||||
var a = param.split('&');
|
||||
for( var i=0;i<a.length; i++ ) {
|
||||
var b = a[i].split('=');
|
||||
pdict[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
|
||||
}
|
||||
}
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.server').value = ssm[1];
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.server_port').value = ssm[2];
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.protocol').value = ssm[3];
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.encrypt_method').value = ssm[4];
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.obfs').value = ssm[5];
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.password').value = b64decsafe(ssm[6]);
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.obfs_param').value = dictvalue(pdict,'obfsparam');
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.protocol_param').value = dictvalue(pdict,'protoparam');
|
||||
|
||||
var rem = pdict['remarks'];
|
||||
if( typeof(rem)!='undefined' && rem!='' && rem.length>0 )
|
||||
document.getElementById('cbid.shadowsocksr.'+sid+'.alias').value = b64decutf8safe(rem);
|
||||
|
||||
s.innerHTML = "<font color='green'><%:Import SSR successfully.%></font>";
|
||||
return false;
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<input type="button" class="cbi-button cbi-button-apply" value="<%:Import SSR%>" onclick="return import_ssr_url(this,'<%=self.option%>','<%=self.value%>')" />
|
||||
<input type="button" class="cbi-button cbi-button-apply" value="<%:Export SSR%>" onclick="return export_ssr_url(this,'<%=self.option%>','<%=self.value%>')" />
|
||||
<span id="<%=self.option%>-status"><%:ssr://%></span>
|
||||
|
||||
<%+cbi/valuefooter%>
|
||||
<%+cbi/valueheader%>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function padright(str, cnt, pad) {
|
||||
return str + Array(cnt + 1).join(pad);
|
||||
}
|
||||
function b64EncodeUnicode(str) {
|
||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
|
||||
return String.fromCharCode('0x' + p1);
|
||||
}));
|
||||
}
|
||||
function b64encutf8safe(str) {
|
||||
return b64EncodeUnicode(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '');
|
||||
}
|
||||
function b64DecodeUnicode(str) {
|
||||
return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
|
||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||
}).join(''));
|
||||
}
|
||||
function b64decutf8safe(str) {
|
||||
var l;
|
||||
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
||||
l = str.length;
|
||||
l = (4 - l % 4) % 4;
|
||||
if (l)
|
||||
str = padright(str, l, "=");
|
||||
return b64DecodeUnicode(str);
|
||||
}
|
||||
function b64encsafe(str) {
|
||||
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, '')
|
||||
}
|
||||
function b64decsafe(str) {
|
||||
var l;
|
||||
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
||||
l = str.length;
|
||||
l = (4 - l % 4) % 4;
|
||||
if (l)
|
||||
str = padright(str, l, "=");
|
||||
return atob(str);
|
||||
}
|
||||
function dictvalue(d, key) {
|
||||
var v = d[key];
|
||||
if (typeof (v) == 'undefined' || v == '')
|
||||
return '';
|
||||
return b64decsafe(v);
|
||||
}
|
||||
function export_ssr_url(btn, urlname, sid) {
|
||||
var s = document.getElementById(urlname + '-status');
|
||||
if (!s)
|
||||
return false;
|
||||
var v_server = document.getElementById('cbid.shadowsocksr.' + sid + '.server');
|
||||
var v_port = document.getElementById('cbid.shadowsocksr.' + sid + '.server_port');
|
||||
var v_protocol = document.getElementById('cbid.shadowsocksr.' + sid + '.protocol');
|
||||
var v_method = document.getElementById('cbid.shadowsocksr.' + sid + '.encrypt_method');
|
||||
var v_obfs = document.getElementById('cbid.shadowsocksr.' + sid + '.obfs');
|
||||
var v_password = document.getElementById('cbid.shadowsocksr.' + sid + '.password');
|
||||
var v_obfs_param = document.getElementById('cbid.shadowsocksr.' + sid + '.obfs_param');
|
||||
var v_protocol_param = document.getElementById('cbid.shadowsocksr.' + sid + '.protocol_param');
|
||||
var v_alias = document.getElementById('cbid.shadowsocksr.' + sid + '.alias');
|
||||
|
||||
var ssr_str = v_server.value + ":" +
|
||||
v_port.value + ":" +
|
||||
v_protocol.value + ":" +
|
||||
v_method.value + ":" +
|
||||
v_obfs.value + ":" +
|
||||
b64encsafe(v_password.value) +
|
||||
"/?obfsparam=" + b64encsafe(v_obfs_param.value) +
|
||||
"&protoparam=" + b64encsafe(v_protocol_param.value) +
|
||||
"&remarks=" + b64encutf8safe(v_alias.value);
|
||||
var textarea = document.createElement("textarea");
|
||||
textarea.textContent = "ssr://" + b64encsafe(ssr_str);
|
||||
textarea.style.position = "fixed";
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
||||
s.innerHTML = "<font color='green'><%:Copy SSR to clipboard successfully.%></font>";
|
||||
} catch (ex) {
|
||||
s.innerHTML = "<font color='red'><%:Unable to copy SSR to clipboard.%></font>";
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function import_ssr_url(btn, urlname, sid) {
|
||||
var s = document.getElementById(urlname + '-status');
|
||||
if (!s)
|
||||
return false;
|
||||
var ssrurl = prompt("在这里黏贴配置链接 ssr:// | ss:// | vmess://", "");
|
||||
if (ssrurl == null || ssrurl == "") {
|
||||
s.innerHTML = "<font color='red'>用户取消</font>";
|
||||
return false;
|
||||
}
|
||||
s.innerHTML = "";
|
||||
//var ssu = ssrurl.match(/ssr:\/\/([A-Za-z0-9_-]+)/i);
|
||||
var ssu = ssrurl.split('://');
|
||||
console.log(ssu.length);
|
||||
if ((ssu[0] != "ssr" && ssu[0] != "ss" && ssu[0] != "vmess") || ssu[1] == "") {
|
||||
s.innerHTML = "<font color='red'>无效的格式</font>";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var event = document.createEvent("HTMLEvents");
|
||||
event.initEvent("change", true, true);
|
||||
if (ssu[0] == "ssr") {
|
||||
var sstr = b64decsafe(ssu[1]);
|
||||
var ploc = sstr.indexOf("/?");
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').value = "ssr";
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').dispatchEvent(event);
|
||||
var url0, param = "";
|
||||
if (ploc > 0) {
|
||||
url0 = sstr.substr(0, ploc);
|
||||
param = sstr.substr(ploc + 2);
|
||||
}
|
||||
var ssm = url0.match(/^(.+):([^:]+):([^:]*):([^:]+):([^:]*):([^:]+)/);
|
||||
if (!ssm || ssm.length < 7)
|
||||
return false;
|
||||
var pdict = {};
|
||||
if (param.length > 2)
|
||||
{
|
||||
var a = param.split('&');
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
var b = a[i].split('=');
|
||||
pdict[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
|
||||
}
|
||||
}
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server').value = ssm[1];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server_port').value = ssm[2];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.protocol').value = ssm[3];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.encrypt_method').value = ssm[4];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.obfs').value = ssm[5];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.password').value = b64decsafe(ssm[6]);
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.obfs_param').value = dictvalue(pdict, 'obfsparam');
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.protocol_param').value = dictvalue(pdict, 'protoparam');
|
||||
|
||||
var rem = pdict['remarks'];
|
||||
if (typeof (rem) != 'undefined' && rem != '' && rem.length > 0)
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.alias').value = b64decutf8safe(rem);
|
||||
|
||||
s.innerHTML = "<font color='green'>导入ShadowsocksR配置信息成功</font>";
|
||||
return false;
|
||||
} else if (ssu[0] == "ss") {
|
||||
var ploc = ssu[1].indexOf("#");
|
||||
if (ploc > 0) {
|
||||
url0 = ssu[1].substr(0, ploc);
|
||||
param = ssu[1].substr(ploc + 1);
|
||||
} else {
|
||||
url0 = ssu[1]
|
||||
}
|
||||
var sstr = b64decsafe(url0);
|
||||
|
||||
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').value = "ss";
|
||||
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').dispatchEvent(event);
|
||||
var team = sstr.split('@');
|
||||
console.log(param);
|
||||
var part1 = team[0].split(':');
|
||||
var part2 = team[1].split(':');
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server').value = part2[0];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server_port').value = part2[1];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.password').value = part1[1];
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.encrypt_method_ss').value = part1[0];
|
||||
if (param != undefined) {
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.alias').value = decodeURI(param);
|
||||
}
|
||||
|
||||
s.innerHTML = "<font color='green'>导入Shadowsocks配置信息成功</font>";
|
||||
return false;
|
||||
} else if (ssu[0] == "vmess") {
|
||||
var sstr = b64DecodeUnicode(ssu[1]);
|
||||
var ploc = sstr.indexOf("/?");
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').value = "v2ray";
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.type').dispatchEvent(event);
|
||||
var url0, param = "";
|
||||
if (ploc > 0) {
|
||||
url0 = sstr.substr(0, ploc);
|
||||
param = sstr.substr(ploc + 2);
|
||||
}
|
||||
var ssm = JSON.parse(sstr);
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.alias').value = ssm.ps;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server').value = ssm.add;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.server_port').value = ssm.port;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.alter_id').value = ssm.aid;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.vmess_id').value = ssm.id;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.security').value = ssm.type;
|
||||
document.getElementById('cbid.shadowsocksr.' + sid + '.transport').value = ssm.net;
|
||||
|
||||
s.innerHTML = "<font color='green'>导入V2ray配置信息成功</font>";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<input type="button" class="cbi-button cbi-button-apply" value="导入配置信息" onclick="return import_ssr_url(this, '<%=self.option%>', '<%=self.value%>')" />
|
||||
<span id="<%=self.option%>-status"></span>
|
||||
|
||||
<%+cbi/valuefooter%>
|
||||
|
Loading…
Reference in New Issue
Block a user