From 8e3222c4134025279f04c0a3eaa01f8946254640 Mon Sep 17 00:00:00 2001
From: imebeh <1243962+imebeh@users.noreply.github.com>
Date: Fri, 15 Jan 2021 20:15:50 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=EF=BC=9A=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89IP=E6=9F=A5=E8=AF=A2?=
=?UTF-8?q?=E7=9A=84URL=20(#516)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 设置:增加可自定义IP查询服务的URL
* 设置:增加IP查询URL的测试按钮
* fix put ip detail into img.alt by mistake
* 优化获取ip详情的逻辑
修复 某些情况 flag 以 ipv6 作为 css 类名时出现的错误
---
src/tr-web-control/config.js | 8 +-
src/tr-web-control/i18n/en.json | 6 +-
src/tr-web-control/i18n/zh_CN.json | 7 +-
src/tr-web-control/script/system.js | 98 +++++++++++++------
.../template/dialog-system-config.html | 49 +++++++++-
5 files changed, 129 insertions(+), 39 deletions(-)
diff --git a/src/tr-web-control/config.js b/src/tr-web-control/config.js
index 2adf966..5b597f7 100644
--- a/src/tr-web-control/config.js
+++ b/src/tr-web-control/config.js
@@ -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: ''
+
});
// 主题样式
diff --git a/src/tr-web-control/i18n/en.json b/src/tr-web-control/i18n/en.json
index 279f1fa..5985efc 100644
--- a/src/tr-web-control/i18n/en.json
+++ b/src/tr-web-control/i18n/en.json
@@ -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: %ip: peer ip(required), %lang: language code use by tr-web-control
%host: host, %hostname: hostname, %protocol: protocol, %navlang: navigation language code",
+ "ipInfoCountryCodeUrl": "URL to get country code:",
+ "ipInfoDetailUrl": "URL to get details:"
},
"public": {
"button-ok": "OK",
diff --git a/src/tr-web-control/i18n/zh_CN.json b/src/tr-web-control/i18n/zh_CN.json
index 87f8730..e4fc02d 100644
--- a/src/tr-web-control/i18n/zh_CN.json
+++ b/src/tr-web-control/i18n/zh_CN.json
@@ -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": "可用变量: %ip: 查询的用户IP(必需), %lang: tr-web-control 使用的语言代号
%host: 域名,含端口号, %hostname: 域名, %protocol: 协议, %navlang: 浏览器首选的语言代号",
+ "ipInfoCountryCodeUrl": "自定义IP国家代码URL:",
+ "ipInfoDetailUrl": "自定义IP详情URL:"
},
"public": {
"button-ok": "确定",
diff --git a/src/tr-web-control/script/system.js b/src/tr-web-control/script/system.js
index cbfcf16..beb3d74 100644
--- a/src/tr-web-control/script/system.js
+++ b/src/tr-web-control/script/system.js
@@ -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 = ' ';
- } else {
- img = ' ';
- }
- 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 = '
';
+ } else {
+ img = ' ';
+ }
+ 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);
}
};
diff --git a/src/tr-web-control/template/dialog-system-config.html b/src/tr-web-control/template/dialog-system-config.html
index 1b55a91..7eafd5d 100644
--- a/src/tr-web-control/template/dialog-system-config.html
+++ b/src/tr-web-control/template/dialog-system-config.html
@@ -405,15 +405,36 @@