mirror of
https://github.com/yhl452493373/frpc-panel.git
synced 2026-04-04 14:27:01 +08:00
support frp>=v0.52.0
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
var loadClientInfo = (function ($) {
|
||||
var i18n = {};
|
||||
|
||||
/**
|
||||
* get client info
|
||||
* @param lang {Map<string,string>} language json
|
||||
* @param title {string} page title
|
||||
*/
|
||||
function loadClientInfo(lang, title) {
|
||||
i18n = lang;
|
||||
function loadClientInfo( title) {
|
||||
$("#title").text(title);
|
||||
$('#content').empty();
|
||||
var loading = layui.layer.load();
|
||||
@@ -16,20 +12,6 @@ var loadClientInfo = (function ($) {
|
||||
type: 'none'
|
||||
}).done(function (result) {
|
||||
if (result.success) {
|
||||
var proxies = [];
|
||||
result.data.proxies.forEach(function (proxy) {
|
||||
var items = flatJSON(proxy.ProxyConfigurer);
|
||||
proxies.push(expandJSON(items))
|
||||
})
|
||||
var visitors = [];
|
||||
result.data.visitors.forEach(function (visitor) {
|
||||
var items = flatJSON(visitor.VisitorConfigurer);
|
||||
visitors.push(expandJSON(items))
|
||||
})
|
||||
|
||||
window.clientConfig = $.extend(true, {}, result.data);
|
||||
window.clientConfig.proxies = proxies;
|
||||
window.clientConfig.visitors = visitors;
|
||||
renderClientInfo(result.data);
|
||||
} else {
|
||||
layui.layer.msg(result.message);
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
var loadProxyInfo = (function ($) {
|
||||
var i18n = {}, currentProxyType, currentTitle;
|
||||
var currentProxyType, currentTitle;
|
||||
|
||||
/**
|
||||
* get proxy info
|
||||
* @param lang {{}} language json
|
||||
* @param title page title
|
||||
* @param proxyType proxy type
|
||||
*/
|
||||
function loadProxyInfo(lang, title, proxyType) {
|
||||
if (lang != null)
|
||||
i18n = lang;
|
||||
function loadProxyInfo(title, proxyType) {
|
||||
if (title != null)
|
||||
currentTitle = title;
|
||||
if (proxyType != null)
|
||||
@@ -24,6 +21,7 @@ var loadProxyInfo = (function ($) {
|
||||
if (result.success) {
|
||||
$('#content').html($('#proxyListTableTemplate').html());
|
||||
renderProxyListTable(result.data);
|
||||
loadFrpcConfig();
|
||||
} else {
|
||||
layui.layer.msg(result.message);
|
||||
}
|
||||
@@ -32,6 +30,32 @@ var loadProxyInfo = (function ($) {
|
||||
});
|
||||
}
|
||||
|
||||
function loadFrpcConfig() {
|
||||
$.getJSON('/proxy/api/config', {
|
||||
type: 'none'
|
||||
}).done(function (result) {
|
||||
if (result.success) {
|
||||
var proxies = [];
|
||||
result.data.proxies.forEach(function (proxy) {
|
||||
var items = flatJSON(proxy['ProxyConfigurer']);
|
||||
proxies.push(expandJSON(items))
|
||||
})
|
||||
var visitors = [];
|
||||
result.data.visitors.forEach(function (visitor) {
|
||||
var items = flatJSON(visitor['VisitorConfigurer']);
|
||||
visitors.push(expandJSON(items))
|
||||
});
|
||||
|
||||
window.clientConfig = $.extend(true, {}, result.data);
|
||||
window.clientConfig.proxies = proxies;
|
||||
window.clientConfig.visitors = visitors;
|
||||
} else {
|
||||
window.clientConfig = {};
|
||||
layui.layer.msg(result.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* render proxy list table
|
||||
* @param data {[Map<string,string>]} proxy data
|
||||
@@ -92,7 +116,11 @@ var loadProxyInfo = (function ($) {
|
||||
text: {none: i18n['EmptyData']},
|
||||
cols: [cols],
|
||||
page: {
|
||||
layout: navigator.language.indexOf("zh") === -1 ? ['first', 'prev', 'next', 'last'] : ['prev', 'page', 'next', 'skip', 'count', 'limit']
|
||||
limitTemplet: function (item) {
|
||||
return item + i18n['PerPage'];
|
||||
},
|
||||
skipText: [i18n['Goto'], '', i18n['Confirm']],
|
||||
countText: [i18n['Total'], i18n['Items']]
|
||||
},
|
||||
toolbar: '#proxyListToolbarTemplate',
|
||||
defaultToolbar: false,
|
||||
@@ -168,8 +196,8 @@ var loadProxyInfo = (function ($) {
|
||||
var name = basicName.name;
|
||||
if (name.indexOf('.') !== -1) {
|
||||
var keys = name.split('.');
|
||||
expandJSONKeys(tempData, keys, basicName.defaultValue);
|
||||
expandJSONKeys(basicData, keys, null);
|
||||
expandJSONKeys(tempData, keys, null);
|
||||
expandJSONKeys(basicData, keys, basicName.defaultValue);
|
||||
}
|
||||
|
||||
eval('basicData.' + name + ' = ' + 'tempData.' + name);
|
||||
@@ -177,7 +205,6 @@ var loadProxyInfo = (function ($) {
|
||||
});
|
||||
|
||||
var flatted = flatJSON(tempData);
|
||||
|
||||
for (var key in flatted) {
|
||||
var value = flatted[key];
|
||||
if (value == null || value === '')
|
||||
@@ -189,7 +216,7 @@ var loadProxyInfo = (function ($) {
|
||||
}
|
||||
}
|
||||
|
||||
var html = document.getElementById('addProxyTemplate').innerHTML;
|
||||
var html = document.getElementById('proxyFormTemplate').innerHTML;
|
||||
var content = layui.laytpl(html).render({
|
||||
type: currentProxyType,
|
||||
extraData: extraData
|
||||
@@ -202,15 +229,14 @@ var loadProxyInfo = (function ($) {
|
||||
content: content,
|
||||
btn: [i18n['Confirm'], i18n['Cancel']],
|
||||
btn1: function (index) {
|
||||
if (layui.form.validate('#addProxyTemplate')) {
|
||||
var formData = layui.form.val('addProxyForm');
|
||||
var $items = $('#addProxyForm .extra-param-tab-item .extra-param-item');
|
||||
if (layui.form.validate('#proxyForm')) {
|
||||
var formData = layui.form.val('proxyForm');
|
||||
var $items = $('#proxyForm .extra-param-tab-item .extra-param-item');
|
||||
$items.each(function () {
|
||||
var name = $(this).find('input').first().val();
|
||||
var value = $(this).find('input').last().val();
|
||||
formData[name] = value;
|
||||
});
|
||||
|
||||
addOrUpdate(formData, index, update);
|
||||
}
|
||||
},
|
||||
@@ -221,14 +247,14 @@ var loadProxyInfo = (function ($) {
|
||||
//get and set old name for update form
|
||||
var originalNameKey = layero.find('#originalNameKey').attr('name');
|
||||
basicData[originalNameKey] = basicData.name;
|
||||
layui.form.val('addProxyForm', flatJSON(basicData));
|
||||
layui.form.val('proxyForm', flatJSON(basicData));
|
||||
proxyPopupSuccess();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function proxyPopupSuccess() {
|
||||
layui.form.render(null, 'addProxyForm');
|
||||
layui.form.render(null, 'proxyForm');
|
||||
layui.form.on('input-affix(addition)', function (obj) {
|
||||
var $paramValue = $(obj.elem);
|
||||
var $paramName = $paramValue.closest('.layui-form-item').find('input[type=text]');
|
||||
@@ -258,27 +284,68 @@ var loadProxyInfo = (function ($) {
|
||||
* @param update update flag. true - update, false - add
|
||||
*/
|
||||
function addOrUpdate(data, index, update) {
|
||||
var loading = layui.layer.load();
|
||||
var originalNameKey = $('#originalNameKey').attr('name');
|
||||
var proxies = clientConfig.proxies;
|
||||
if (update) {
|
||||
for (var i = 0; i < proxies.length; i++) {
|
||||
if (data[originalNameKey] === proxies[i].name) {
|
||||
delete data[originalNameKey];
|
||||
proxies[i] = expandJSON(data);
|
||||
try {
|
||||
var originalNameKey = $('#originalNameKey').attr('name');
|
||||
var proxies = clientConfig.proxies;
|
||||
if (update) {
|
||||
for (var i = 0; i < proxies.length; i++) {
|
||||
if (data[originalNameKey] === proxies[i].name) {
|
||||
delete data[originalNameKey];
|
||||
proxies[i] = expandJSON(data);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
proxies.push(expandJSON(data));
|
||||
}
|
||||
} else {
|
||||
proxies.push(expandJSON(data));
|
||||
} catch (e) {
|
||||
layui.layer.msg(e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
var tomlStr = TOML.stringify(clientConfig);
|
||||
updateFrpcConfig(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* batch remove proxy popup
|
||||
* @param data {[Map<string,string>]} proxy data list
|
||||
*/
|
||||
function batchRemovePopup(data) {
|
||||
if (data.length === 0) {
|
||||
layui.layer.msg(i18n['ShouldCheckProxy']);
|
||||
return;
|
||||
}
|
||||
layui.layer.confirm(i18n['ConfirmRemoveProxy'], {
|
||||
title: i18n['OperationConfirm'],
|
||||
btn: [i18n['Confirm'], i18n['Cancel']]
|
||||
}, function (index) {
|
||||
layui.layer.close(index);
|
||||
var proxies = clientConfig.proxies;
|
||||
var newProxies = [];
|
||||
for (var i = 0; i < proxies.length; i++) {
|
||||
var proxy = proxies[i];
|
||||
for (var temp of data) {
|
||||
if (temp.name !== proxy.name) {
|
||||
newProxies.push(proxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
clientConfig.proxies = newProxies;
|
||||
updateFrpcConfig(index);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* update frpc's config
|
||||
* @param index popup index
|
||||
*/
|
||||
function updateFrpcConfig(index) {
|
||||
var loading = layui.layer.load();
|
||||
var content = TOML.stringify(clientConfig);
|
||||
$.ajax({
|
||||
url: '/update',
|
||||
type: 'post',
|
||||
contentType: 'text/plain',
|
||||
data: tomlStr,
|
||||
data: content,
|
||||
success: function (result) {
|
||||
if (result.success) {
|
||||
layui.layer.close(index);
|
||||
@@ -298,59 +365,11 @@ var loadProxyInfo = (function ($) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* batch remove proxy popup
|
||||
* @param data {[Map<string,string>]} proxy data list
|
||||
*/
|
||||
function batchRemovePopup(data) {
|
||||
if (data.length === 0) {
|
||||
layui.layer.msg(i18n['ShouldCheckProxy']);
|
||||
return;
|
||||
}
|
||||
data.forEach(function (temp) {
|
||||
for (var key in temp) {
|
||||
if (typeof temp[key] === 'boolean') {
|
||||
temp[key] = temp[key] + '';
|
||||
}
|
||||
}
|
||||
});
|
||||
layui.layer.confirm(i18n['ConfirmRemoveProxy'], {
|
||||
title: i18n['OperationConfirm'],
|
||||
btn: [i18n['Confirm'], i18n['Cancel']]
|
||||
}, function (index) {
|
||||
layui.layer.close(index);
|
||||
|
||||
var loading = layui.layer.load();
|
||||
$.post({
|
||||
url: '/remove',
|
||||
type: 'post',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
success: function (result) {
|
||||
if (result.success) {
|
||||
layui.layer.close(index);
|
||||
reloadTable();
|
||||
layui.layer.msg(i18n['OperateSuccess']);
|
||||
} else {
|
||||
errorMsg(result);
|
||||
if (result.code === 5) {
|
||||
layui.layer.close(index);
|
||||
reloadTable();
|
||||
}
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
layui.layer.close(loading);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* reload proxy table
|
||||
*/
|
||||
function reloadTable() {
|
||||
loadProxyInfo(null, null, null);
|
||||
loadProxyInfo(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
var loadOverview = (function ($) {
|
||||
var i18n = {};
|
||||
|
||||
/**
|
||||
* get proxy info
|
||||
* @param lang {{}} language json
|
||||
* @param title page title
|
||||
*/
|
||||
function loadOverview(lang, title) {
|
||||
i18n = lang;
|
||||
function loadOverview(title) {
|
||||
$("#title").text(title);
|
||||
$('#content').empty();
|
||||
var loading = layui.layer.load();
|
||||
@@ -63,7 +59,11 @@ var loadOverview = (function ($) {
|
||||
text: {none: i18n['EmptyData']},
|
||||
cols: [cols],
|
||||
page: {
|
||||
layout: navigator.language.indexOf("zh") === -1 ? ['first', 'prev', 'next', 'last'] : ['prev', 'page', 'next', 'skip', 'count', 'limit']
|
||||
limitTemplet: function (item) {
|
||||
return item + i18n['PerPage'];
|
||||
},
|
||||
skipText: [i18n['Goto'], '', i18n['Confirm']],
|
||||
countText: [i18n['Total'], i18n['Items']]
|
||||
},
|
||||
data: dataList,
|
||||
initSort: {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
window.clientConfig = {};
|
||||
window.i18n = {};
|
||||
(function ($) {
|
||||
$(function () {
|
||||
function init() {
|
||||
var langLoading = layui.layer.load()
|
||||
$.getJSON('/lang.json').done(function (lang) {
|
||||
window.i18n = lang;
|
||||
$.ajaxSetup({
|
||||
error: function (xhr,) {
|
||||
if (xhr.status === 401) {
|
||||
@@ -18,13 +20,13 @@ window.clientConfig = {};
|
||||
var id = elem.attr('id');
|
||||
var title = elem.text();
|
||||
if (id === 'clientInfo') {
|
||||
loadClientInfo(lang, title.trim());
|
||||
loadClientInfo(title.trim());
|
||||
} else if (id === 'overview') {
|
||||
loadOverview(lang, title.trim());
|
||||
loadOverview(title.trim());
|
||||
} else if (elem.closest('.layui-nav-item').attr('id') === 'proxies') {
|
||||
if (id != null && id.trim() !== '') {
|
||||
var suffix = elem.closest('.layui-nav-item').children('a').text().trim();
|
||||
loadProxyInfo(lang, title + " " + suffix, id);
|
||||
loadProxyInfo(title + " " + suffix, id);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -35,6 +37,45 @@ window.clientConfig = {};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* add verify rule to layui.form
|
||||
*/
|
||||
function initFormVerifyRule() {
|
||||
layui.form.verify({
|
||||
proxyName: function (value, elem) {
|
||||
if (value.trim() === '') {
|
||||
var nameI18n = $('#proxyName').closest('.layui-form-item').children('.layui-form-label').text();
|
||||
return nameI18n + i18n['RequireNotEmpty'];
|
||||
}
|
||||
},
|
||||
localPort: function (value, elem) {
|
||||
if (value !== '' && !/^\d+$/.test(value)) {
|
||||
var nameI18n = $('#localPort').closest('.layui-form-item').children('.layui-form-label').text();
|
||||
return nameI18n + i18n['RequireNumber'];
|
||||
}
|
||||
},
|
||||
domain: function (value, elem) {
|
||||
var proxyType = $('#proxyType').val().toLowerCase();
|
||||
var $customDomains = $('#customDomains');
|
||||
var customDomains = $customDomains.val();
|
||||
var $subdomain = $('#subdomain');
|
||||
var subdomain = $subdomain.val();
|
||||
if (proxyType === 'http' || proxyType === 'https') {
|
||||
if (customDomains.trim() === '' && subdomain.trim() === '') {
|
||||
var customDomainsNameI18n = $customDomains.closest('.layui-form-item').children('.layui-form-label').text();
|
||||
var subdomainNameI18n = $subdomain.closest('.layui-form-item').children('.layui-form-label').text();
|
||||
return customDomainsNameI18n + i18n['and'] + subdomainNameI18n + i18n['RequireNotAllEmpty'];
|
||||
} else if (customDomains.trim() !== '') {
|
||||
var nameI18n = $customDomains.closest('.layui-form-item').children('.layui-form-label').text();
|
||||
if (!/^\s*\[.*]\s*$/.test(customDomains)) {
|
||||
return nameI18n + i18n['RequireArray'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function logout() {
|
||||
$.get("/logout", function (result) {
|
||||
window.location.reload();
|
||||
@@ -46,5 +87,6 @@ window.clientConfig = {};
|
||||
});
|
||||
|
||||
init();
|
||||
initFormVerifyRule();
|
||||
});
|
||||
})(layui.$);
|
||||
@@ -1,4 +1,4 @@
|
||||
(function () {
|
||||
(function ($) {
|
||||
//param names in Basic tab
|
||||
var basicParams = [
|
||||
{
|
||||
@@ -24,10 +24,10 @@
|
||||
defaultValue: '-'
|
||||
}, {
|
||||
name: 'transport.useEncryption',
|
||||
defaultValue: 'false',
|
||||
defaultValue: false,
|
||||
}, {
|
||||
name: 'transport.useCompression',
|
||||
defaultValue: 'false',
|
||||
defaultValue: false,
|
||||
}
|
||||
];
|
||||
var mapParams = [{
|
||||
@@ -103,17 +103,41 @@
|
||||
|
||||
function expandJSON(obj) {
|
||||
var newObj = {};
|
||||
var inPopup = $('#proxyForm').length !== 0;
|
||||
for (var name in obj) {
|
||||
var value = obj[name];
|
||||
if (value === '') {
|
||||
continue;
|
||||
}
|
||||
var nameI18n = name;
|
||||
if (inPopup) {
|
||||
nameI18n = $('#proxyForm [name="' + name + '"]').closest('.layui-form-item').children('.layui-form-label').text();
|
||||
if (nameI18n === '') {
|
||||
nameI18n = name;
|
||||
}
|
||||
}
|
||||
|
||||
if (paramTypes.number.indexOf(name) !== -1) {
|
||||
value = parseInt(value) || 0;
|
||||
value = parseInt(value);
|
||||
if (isNaN(value)) {
|
||||
throw new Error(nameI18n + i18n['RequireNumber']);
|
||||
}
|
||||
} else if (paramTypes.boolean.indexOf(name) !== -1) {
|
||||
value = Boolean(value) || false;
|
||||
if (typeof value === "string" && (value === 'true' || value === 'false')) {
|
||||
value = value === 'true';
|
||||
} else if (typeof value !== 'boolean') {
|
||||
throw new Error(nameI18n + i18n['RequireBoolean']);
|
||||
}
|
||||
} else if (paramTypes.array.indexOf(name) !== -1) {
|
||||
value = eval('(' + value + ')') || [];
|
||||
try {
|
||||
if (/^\s*\[.*]\s*$/.test(value)) {
|
||||
value = eval('(' + value + ')') || [];
|
||||
} else {
|
||||
throw new Error('value format incorrect');
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(nameI18n + i18n['RequireArray']);
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < paramTypes.map.length; i++) {
|
||||
var key = paramTypes.map[i];
|
||||
@@ -126,6 +150,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expandJSONKeys(newObj, name.split("."), value, false);
|
||||
}
|
||||
return newObj;
|
||||
@@ -181,4 +206,4 @@
|
||||
window.expandJSONKeys = expandJSONKeys;
|
||||
window.expandJSON = expandJSON;
|
||||
window.flatJSON = flatJSON;
|
||||
})();
|
||||
})(layui.$);
|
||||
Reference in New Issue
Block a user