mirror of
https://github.com/ronggang/transmission-web-control.git
synced 2025-04-14 10:00:56 +00:00
设置:增加可自定义IP查询的URL (#516)
* 设置:增加可自定义IP查询服务的URL * 设置:增加IP查询URL的测试按钮 * fix put ip detail into img.alt by mistake * 优化获取ip详情的逻辑 修复 某些情况 flag 以 ipv6 作为 css 类名时出现的错误
This commit is contained in:
parent
cdd961a9c7
commit
8e3222c413
|
@ -21,8 +21,12 @@ system.config = $.extend(system.config, {
|
|||
theme: "default",
|
||||
// 是否显示BT服务器
|
||||
showBTServers: false,
|
||||
// ipinfo.io token
|
||||
ipInfoToken: ''
|
||||
// ipinfo.io token
|
||||
ipInfoToken: '',
|
||||
// custom ip information server url
|
||||
ipInfoFlagUrl: '',
|
||||
ipInfoDetailUrl: ''
|
||||
|
||||
});
|
||||
|
||||
// 主题样式
|
||||
|
|
|
@ -226,7 +226,11 @@
|
|||
"export-config": "Export current configuration",
|
||||
"import-config-confirm": "Do you want to import these configurations? This overrides the current configuration.",
|
||||
"script-torrent-done-enabled": "Execute the following script when the torrent download is complete:",
|
||||
"ipinfo": "IPinfo.io access token:"
|
||||
"ipinfo": "IPinfo.io access token:",
|
||||
"ipInfoCustom": "Additional IP query service settings, custom URL can be used, suitable for local query services",
|
||||
"ipInfoCustomTips": "Available variables: <b>%ip</b>: peer ip(required), <b>%lang</b>: language code use by tr-web-control<br/> <b>%host</b>: host, <b>%hostname</b>: hostname, <b>%protocol</b>: protocol, <b>%navlang</b>: navigation language code",
|
||||
"ipInfoCountryCodeUrl": "URL to get country code:",
|
||||
"ipInfoDetailUrl": "URL to get details:"
|
||||
},
|
||||
"public": {
|
||||
"button-ok": "OK",
|
||||
|
|
|
@ -225,7 +225,12 @@
|
|||
"import-config": "从备份文件中导入配置",
|
||||
"export-config": "导出当前配置到配置文件(内容包括:Transmission 参数、WebUI 配置)",
|
||||
"import-config-confirm": "是否确认导入这些配置信息?这将覆盖当前配置。",
|
||||
"script-torrent-done-enabled": "种子下载完成后执行以下脚本:"
|
||||
"script-torrent-done-enabled": "种子下载完成后执行以下脚本:",
|
||||
"ipinfo": "IPinfo.io 访问令牌:",
|
||||
"ipInfoCustom": "额外的IP查询服务设置,可使用自定义URL,适合使用本地架设的查询服务",
|
||||
"ipInfoCustomTips": "可用变量: <b>%ip</b>: 查询的用户IP(必需), <b>%lang</b>: tr-web-control 使用的语言代号<br/> <b>%host</b>: 域名,含端口号, <b>%hostname</b>: 域名, <b>%protocol</b>: 协议, <b>%navlang</b>: 浏览器首选的语言代号",
|
||||
"ipInfoCountryCodeUrl": "自定义IP国家代码URL:",
|
||||
"ipInfoDetailUrl": "自定义IP详情URL:"
|
||||
},
|
||||
"public": {
|
||||
"button-ok": "确定",
|
||||
|
|
|
@ -21,6 +21,8 @@ var system = {
|
|||
showBTServers: false,
|
||||
// ipinfo.io token
|
||||
ipInfoToken: '',
|
||||
ipInfoFlagUrl: '',
|
||||
ipInfoDetailUrl: '',
|
||||
ui: {
|
||||
status: {
|
||||
tree: {},
|
||||
|
@ -69,6 +71,7 @@ var system = {
|
|||
// The currently selected torrent number
|
||||
currentTorrentId: 0,
|
||||
flags: [],
|
||||
ipdetail: [],
|
||||
control: {
|
||||
tree: null,
|
||||
torrentlist: null
|
||||
|
@ -2888,37 +2891,60 @@ var system = {
|
|||
rowdata[key] = item[key];
|
||||
}
|
||||
|
||||
if (system.config.ipInfoToken !== '') {
|
||||
let flag = '';
|
||||
let ip = rowdata['address'];
|
||||
if (system.config.ipInfoToken !== '' || system.config.ipInfoFlagUrl !== '') {
|
||||
let flag = '';
|
||||
let detail = '';
|
||||
let ip = rowdata['address'];
|
||||
|
||||
if (this.flags[ip] === undefined) {
|
||||
let url = 'https://ipinfo.io/' + ip + '/country?token=' + system.config.ipInfoToken;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url
|
||||
}).done((data) => {
|
||||
if (data) {
|
||||
flag = data.toLowerCase().trim();
|
||||
this.flags[ip] = flag;
|
||||
$("img.img_ip-"+ip).attr({
|
||||
src: this.rootPath + 'style/flags/' + flag + '.png',
|
||||
alt: flag,
|
||||
title: flag
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
flag = this.flags[ip];
|
||||
}
|
||||
let img = "";
|
||||
if (flag) {
|
||||
img = '<img src="' + this.rootPath + 'style/flags/' + flag + '.png" alt="' + flag + '" title="' + flag + '"> ';
|
||||
} else {
|
||||
img = '<img src="" class="img_ip-'+ip+'" style="display:none;"> ';
|
||||
}
|
||||
rowdata['address'] = img + ip;
|
||||
}
|
||||
if (system.config.ipInfoDetailUrl !== '') {
|
||||
if (this.ipdetail[ip] === undefined ){
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: this.expandIpInfoUrl(system.config.ipInfoDetailUrl, ip)
|
||||
}).done((data) => {
|
||||
if (data) {
|
||||
detail = data.trim();
|
||||
this.ipdetail[ip] = detail;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
detail = this.ipdetail[ip];
|
||||
}
|
||||
}
|
||||
|
||||
if (this.flags[ip] === undefined) {
|
||||
let url = ''
|
||||
if (system.config.ipInfoFlagUrl !== '') {
|
||||
url = this.expandIpInfoUrl(system.config.ipInfoFlagUrl, ip);
|
||||
} else {
|
||||
url = 'https://ipinfo.io/' + ip + '/country?token=' + system.config.ipInfoToken;
|
||||
}
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url
|
||||
}).done((data) => {
|
||||
if (data) {
|
||||
flag = data.toLowerCase().trim();
|
||||
this.flags[ip] = flag;
|
||||
$("img.img_ip-"+ip.replaceAll(/[:.]+/g,'_')).attr({
|
||||
src: this.rootPath + 'style/flags/' + flag + '.png',
|
||||
alt: flag,
|
||||
title: detail!==''? detail : flag
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
flag = this.flags[ip];
|
||||
}
|
||||
|
||||
let img = "";
|
||||
if (flag) {
|
||||
img = '<img src="' + this.rootPath + 'style/flags/' + flag + '.png" alt="' + flag + '" title="' + (detail!==''? detail : flag) + '"> ';
|
||||
} else {
|
||||
img = '<img src="" class="img_ip-'+ip.replaceAll(/[:.]+/g,'_')+'" style="display:none;"> ';
|
||||
}
|
||||
rowdata['address'] = img + ip;
|
||||
}
|
||||
|
||||
// 使用同类已有的翻译文本
|
||||
rowdata.isUTP = system.lang.torrent.attribute["status"][item.isUTP];
|
||||
|
@ -3415,6 +3441,18 @@ var system = {
|
|||
if (!text) return "";
|
||||
var _key = this.B64.encode(text);
|
||||
return _key.replace(/[+|\/|=]/g,"0");
|
||||
},
|
||||
|
||||
expandIpInfoUrl: function (url, ip) {
|
||||
if (url=='' || url==undefined) {
|
||||
return '';
|
||||
}
|
||||
return url.replace("%ip", ip)
|
||||
.replace("%lang", system.lang.name)
|
||||
.replace("%hostname", document.location.hostname)
|
||||
.replace("%host", document.location.host)
|
||||
.replace("%protocol", document.location.protocol)
|
||||
.replace("%navlang", navigator.language);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -405,15 +405,36 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<label system-lang="dialog['system-config']['ipinfo']"></label>
|
||||
<a id="system-config-test-port" href="http://ipinfo.io" target="_blank"
|
||||
class="easyui-linkbutton"
|
||||
data-options="plain:true,iconCls:'icon-about'"></a>
|
||||
<hr/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input id="ipInfoToken" value="" type="text" style="width:100%;"/>
|
||||
<label system-lang="dialog['system-config']['ipinfo']"></label>
|
||||
<a id="system-config-test-port" href="http://ipinfo.io" target="_blank"
|
||||
class="easyui-linkbutton"
|
||||
data-options="plain:true,iconCls:'icon-about'"></a>
|
||||
<input id="ipInfoToken" value="" class="easyui-textbox" type="text" style="width: 100%;"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<hr/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<label system-lang="dialog['system-config']['ipInfoCustom']"></label><br>
|
||||
|
||||
<label system-lang="dialog['system-config']['ipInfoCountryCodeUrl']"></label>
|
||||
<input id="ipInfoFlagUrl" value="" class="easyui-textbox"
|
||||
data-options="prompt:'%protocol//%hostname:5000/code/%ip',buttonText:'Test'" type="text" style="width: 100%"/><br>
|
||||
|
||||
<label system-lang="dialog['system-config']['ipInfoDetailUrl']"></label>
|
||||
<input id="ipInfoDetailUrl" value="" class="easyui-textbox"
|
||||
data-options="prompt:'%protocol//%hostname:5000/detail/%ip/%navlang',buttonText:'Test'" type="text" style="width: 100%"/><br>
|
||||
|
||||
<label system-lang="dialog['system-config']['ipInfoCustomTips']"></label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -657,6 +678,9 @@
|
|||
|
||||
thisDialog.find('#ipInfoToken').val(system.config.ipInfoToken);
|
||||
|
||||
thisDialog.find('#ipInfoFlagUrl').val(system.config.ipInfoFlagUrl);
|
||||
thisDialog.find('#ipInfoDetailUrl').val(system.config.ipInfoDetailUrl);
|
||||
|
||||
for (var key in system.config.nav) {
|
||||
var value = system.config.nav[key];
|
||||
thisDialog.find('#nav-' + key).switchbutton({
|
||||
|
@ -800,6 +824,8 @@
|
|||
system.config.hideSubfolders = thisDialog.find('#hide-subfolders').prop('checked');
|
||||
system.config.simpleCheckMode = thisDialog.find('#simpleCheckMode').prop('checked');
|
||||
system.config.ipInfoToken = thisDialog.find('#ipInfoToken').val();
|
||||
system.config.ipInfoFlagUrl = thisDialog.find('#ipInfoFlagUrl').val();
|
||||
system.config.ipInfoDetailUrl = thisDialog.find('#ipInfoDetailUrl').val();
|
||||
|
||||
var _temp = JSON.stringify(system.config.nav);
|
||||
for (var key in system.config.nav) {
|
||||
|
@ -895,6 +921,19 @@
|
|||
});
|
||||
});
|
||||
|
||||
thisDialog.find('#ipInfoFlagUrl').textbox({onClickButton: function (){
|
||||
if (this.value !== '' && this.value !== undefined) {
|
||||
alert(system.expandIpInfoUrl(this.value, '8.8.8.8'));
|
||||
}
|
||||
}});
|
||||
|
||||
thisDialog.find('#ipInfoDetailUrl').textbox({onClickButton: function (){
|
||||
if (this.value !== '' && this.value !== undefined) {
|
||||
alert(system.expandIpInfoUrl(this.value, '8.8.8.8'));
|
||||
}
|
||||
}});
|
||||
|
||||
|
||||
// 恢复界面默认设置
|
||||
$('#restore-default-settings', thisDialog).click(function () {
|
||||
if (confirm(system.lang['public']['text-confirm']) == false) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user