mirror of
https://github.com/yhl452493373/frpc-panel.git
synced 2026-04-04 14:27:01 +08:00
complete full functions;
add some translations;
This commit is contained in:
@@ -7,5 +7,53 @@
|
|||||||
"Please input password": "Please input password",
|
"Please input password": "Please input password",
|
||||||
"Login success": "Login success",
|
"Login success": "Login success",
|
||||||
"Username or password incorrect": "Username or password incorrect",
|
"Username or password incorrect": "Username or password incorrect",
|
||||||
"Empty data": "Empty data"
|
"Empty data": "Empty data",
|
||||||
|
"Client Info": "Client Info",
|
||||||
|
"Proxies Status": "Proxies Status",
|
||||||
|
"Proxies": "Proxies",
|
||||||
|
"Server Address": "Server Address",
|
||||||
|
"Server Port": "Server Port",
|
||||||
|
"Protocol": "Protocol",
|
||||||
|
"TCP Mux": "TCP Mux",
|
||||||
|
"User": "User",
|
||||||
|
"User Token": "User Token",
|
||||||
|
"Admin Address": "Admin Address",
|
||||||
|
"Admin Port": "Admin Port",
|
||||||
|
"Admin User": "Admin User",
|
||||||
|
"Admin Pwd": "Admin Pwd",
|
||||||
|
"Heartbeat Interval": "Heartbeat Interval",
|
||||||
|
"Heartbeat Timeout": "Heartbeat Timeout",
|
||||||
|
"TLS Enable": "TLS Enable",
|
||||||
|
"TLS Key File": "TLS Key File",
|
||||||
|
"TLS Cert File": "TLS Cert File",
|
||||||
|
"TLS Trusted CA File": "TLS Trusted CA File",
|
||||||
|
"false": "No",
|
||||||
|
"true": "Yes",
|
||||||
|
"New Proxy": "New Proxy",
|
||||||
|
"Remove Proxy": "Remove Proxy",
|
||||||
|
"Update": "Update",
|
||||||
|
"Remove": "Remove",
|
||||||
|
"Basic": "Basic Params",
|
||||||
|
"Extra": "Extra Params",
|
||||||
|
"Proxy Name": "Proxy Name",
|
||||||
|
"Customize Domains": "Customize Domains",
|
||||||
|
"Subdomain": "Subdomain",
|
||||||
|
"Remote Port": "Remote Port",
|
||||||
|
"Use Encryption": "Use Encryption",
|
||||||
|
"Use Compression": "Use Compression",
|
||||||
|
"Param Name": "Param Name",
|
||||||
|
"Param Value": "Param Value",
|
||||||
|
"Name": "Name",
|
||||||
|
"Type": "Type",
|
||||||
|
"Local Address": "Local Address",
|
||||||
|
"Plugin": "Plugin",
|
||||||
|
"Remote Address": "Remote Address",
|
||||||
|
"Status": "Status",
|
||||||
|
"Info": "Info",
|
||||||
|
"running": "running",
|
||||||
|
"Local Ip": "Local Ip",
|
||||||
|
"Local Port": "Local Port",
|
||||||
|
"Operation": "Operation",
|
||||||
|
"Confirm": "Confirm",
|
||||||
|
"Cancel": "Cancel"
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,53 @@
|
|||||||
"Please input password": "请填写密码",
|
"Please input password": "请填写密码",
|
||||||
"Login success": "登录成功",
|
"Login success": "登录成功",
|
||||||
"Username or password incorrect": "用户名或密码错误",
|
"Username or password incorrect": "用户名或密码错误",
|
||||||
"Empty data": "无数据"
|
"Empty data": "无数据",
|
||||||
|
"Client Info": "客户端信息",
|
||||||
|
"Proxies Status": "代理状态",
|
||||||
|
"Proxies": "代理",
|
||||||
|
"Server Address": "服务器地址",
|
||||||
|
"Server Port": "服务器端口",
|
||||||
|
"Protocol": "连接协议",
|
||||||
|
"TCP Mux": "TCP端口复用",
|
||||||
|
"User": "用户",
|
||||||
|
"User Token": "鉴权凭证",
|
||||||
|
"Admin Address": "客户端管理监听地址",
|
||||||
|
"Admin Port": "客户端管理监听端口",
|
||||||
|
"Admin User": "客户端管理账号",
|
||||||
|
"Admin Pwd": "客户端管理密码",
|
||||||
|
"Heartbeat Interval": "心跳检测间隔",
|
||||||
|
"Heartbeat Timeout": "心跳检测超时时间",
|
||||||
|
"TLS Enable": "启用TLS加密",
|
||||||
|
"TLS Key File": "TLS密钥文件路径",
|
||||||
|
"TLS Cert File": "TLS证书文件路径",
|
||||||
|
"TLS Trusted CA File": "TLS CA证书文件路径",
|
||||||
|
"false": "否",
|
||||||
|
"true": "是",
|
||||||
|
"New Proxy": "新增代理",
|
||||||
|
"Remove Proxy": "删除代理",
|
||||||
|
"Update": "更新",
|
||||||
|
"Remove": "删除",
|
||||||
|
"Basic": "基础参数",
|
||||||
|
"Extra": "附加参数",
|
||||||
|
"Proxy Name": "代理名称",
|
||||||
|
"Customize Domains": "自定义域名",
|
||||||
|
"Subdomain": "子域名",
|
||||||
|
"Remote Port": "服务端端口",
|
||||||
|
"Use Encryption": "加密传输",
|
||||||
|
"Use Compression": "压缩传输",
|
||||||
|
"Param Name": "参数名称",
|
||||||
|
"Param Value": "参数值",
|
||||||
|
"Name": "代理名称",
|
||||||
|
"Type": "代理类型",
|
||||||
|
"Local Address": "本地地址",
|
||||||
|
"Plugin": "插件",
|
||||||
|
"Remote Address": "服务端地址",
|
||||||
|
"Status": "状态",
|
||||||
|
"Info": "消息",
|
||||||
|
"running": "运行中",
|
||||||
|
"Local Ip": "本地IP",
|
||||||
|
"Local Port": "本地端口",
|
||||||
|
"Operation": "操作",
|
||||||
|
"Confirm": "确定",
|
||||||
|
"Cancel": "取消"
|
||||||
}
|
}
|
||||||
@@ -118,25 +118,25 @@ section {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.common-info {
|
section.client-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.common-info .text-info {
|
section.client-info .text-info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.common-info .text-info {
|
section.client-info .text-info {
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.common-info .text-row {
|
section.client-info .text-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.common-info .text-row .text-col {
|
section.client-info .text-row .text-col {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var loadCommon = (function ($) {
|
var loadClientInfo = (function ($) {
|
||||||
var i18n = {};
|
var i18n = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6,7 +6,7 @@ var loadCommon = (function ($) {
|
|||||||
* @param lang {Map<string,string>} language json
|
* @param lang {Map<string,string>} language json
|
||||||
* @param title {string} page title
|
* @param title {string} page title
|
||||||
*/
|
*/
|
||||||
function loadCommon(lang, title) {
|
function loadClientInfo(lang, title) {
|
||||||
i18n = lang;
|
i18n = lang;
|
||||||
$("#title").text(title);
|
$("#title").text(title);
|
||||||
$('#content').empty();
|
$('#content').empty();
|
||||||
@@ -26,9 +26,11 @@ var loadCommon = (function ($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderCommonInfo(data) {
|
function renderCommonInfo(data) {
|
||||||
var html = layui.laytpl($('#commonTemplate').html()).render(data);
|
data.tcp_mux = i18n[data.tcp_mux];
|
||||||
|
data.tls_enable = i18n[data.tls_enable];
|
||||||
|
var html = layui.laytpl($('#clientInfoTemplate').html()).render(data);
|
||||||
$('#content').html(html);
|
$('#content').html(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadCommon;
|
return loadClientInfo;
|
||||||
})(layui.$);
|
})(layui.$);
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
var loadOverview = (function ($) {
|
|
||||||
var i18n = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get proxy info
|
|
||||||
* @param lang {{}} language json
|
|
||||||
* @param title page title
|
|
||||||
*/
|
|
||||||
function loadOverview(lang, title) {
|
|
||||||
i18n = lang;
|
|
||||||
$("#title").text(title);
|
|
||||||
$('#content').empty();
|
|
||||||
var loading = layui.layer.load();
|
|
||||||
|
|
||||||
$.getJSON('/proxy/api/status').done(function (result) {
|
|
||||||
if (result.success) {
|
|
||||||
$('#content').html($('#overviewTableTemplate').html());
|
|
||||||
renderOverviewTable(JSON.parse(result.data));
|
|
||||||
} else {
|
|
||||||
layui.layer.msg(result.message);
|
|
||||||
}
|
|
||||||
}).always(function () {
|
|
||||||
layui.layer.close(loading);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* render proxy list table
|
|
||||||
* @param data {Map<string,Map<string,string>>} proxy data
|
|
||||||
* @param proxyType proxy type
|
|
||||||
*/
|
|
||||||
function renderOverviewTable(data, proxyType) {
|
|
||||||
var dataList = [];
|
|
||||||
for (var type in data) {
|
|
||||||
var temp = data[type];
|
|
||||||
dataList = dataList.concat(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
var $section = $('#content > section');
|
|
||||||
var cols = [
|
|
||||||
{field: 'name', title: 'Name', sort: true},
|
|
||||||
{field: 'type', title: 'Type', width: 100, sort: true},
|
|
||||||
{
|
|
||||||
field: 'local_addr',
|
|
||||||
title: 'Local Address',
|
|
||||||
templet: '<span>{{= d.local_addr || "-" }}</span>',
|
|
||||||
width: 220,
|
|
||||||
sort: true
|
|
||||||
},
|
|
||||||
{field: 'plugin', title: 'plugin', templet: '<span>{{= d.plugin || "-" }}</span>', sort: true},
|
|
||||||
{field: 'remote_addr', title: 'Remote Address', sort: true},
|
|
||||||
{field: 'status', title: 'Status', width: 100, sort: true},
|
|
||||||
{field: 'err', title: 'Info',templet: '<span>{{= d.err || "-" }}</span>', width: 200}
|
|
||||||
];
|
|
||||||
|
|
||||||
var overviewTable = layui.table.render({
|
|
||||||
elem: '#overviewTable',
|
|
||||||
height: $section.height(),
|
|
||||||
text: {none: i18n['EmptyData']},
|
|
||||||
cols: [cols],
|
|
||||||
page: navigator.language.indexOf("zh") !== -1,
|
|
||||||
data: dataList,
|
|
||||||
initSort: {
|
|
||||||
field: 'name',
|
|
||||||
type: 'asc'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
window.onresize = function () {
|
|
||||||
overviewTable.resize();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindFormEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bind event of {{@link layui.form}}
|
|
||||||
*/
|
|
||||||
function bindFormEvent() {
|
|
||||||
layui.table.on('tool(proxyListTable)', function (obj) {
|
|
||||||
var data = obj.data;
|
|
||||||
|
|
||||||
switch (obj.event) {
|
|
||||||
case 'update':
|
|
||||||
break;
|
|
||||||
// updatePopup(data);
|
|
||||||
case 'remove':
|
|
||||||
// removePopup(data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return loadOverview;
|
|
||||||
})(layui.$);
|
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
var loadProxyInfo = (function ($) {
|
var loadProxyInfo = (function ($) {
|
||||||
var i18n = {}, currentProxyType, currentTitle;
|
var i18n = {}, currentProxyType, currentTitle;
|
||||||
//param names in Basic tab
|
//param names in Basic tab
|
||||||
var basicParamNames = ['name', 'type', 'local_ip', 'local_port', 'custom_domains', 'subdomain', 'remote_port', 'use_encryption', 'use_compression'];
|
var basicParamNames = ['name', 'type', 'local_ip', 'local_port', 'custom_domains', 'sub_domain', 'remote_port', 'use_encryption', 'use_compression'];
|
||||||
//param need to convert type
|
|
||||||
var intParamNames = ['local_port', 'health_check_timeout_s', 'health_check_max_failed', 'health_check_interval_s'];
|
|
||||||
var booleanParamNames = ['use_encryption', 'use_compression'];
|
|
||||||
var stringArrayParamNames = ['custom_domains', 'locations']
|
|
||||||
var mapParamPrefixes = [
|
|
||||||
{name: 'metas', prefix: 'meta_'},
|
|
||||||
{name: 'plugin_params', prefix: 'plugin_'},
|
|
||||||
{name: 'headers', prefix: 'header_'}
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get proxy info
|
* get proxy info
|
||||||
@@ -60,11 +51,11 @@ var loadProxyInfo = (function ($) {
|
|||||||
var $section = $('#content > section');
|
var $section = $('#content > section');
|
||||||
var cols = [
|
var cols = [
|
||||||
{type: 'checkbox'},
|
{type: 'checkbox'},
|
||||||
{field: 'name', title: 'Name', sort: true},
|
{field: 'name', title: i18n['Name'], sort: true},
|
||||||
{field: 'type', title: 'Type', sort: true},
|
{field: 'type', title: i18n['Type'], sort: true},
|
||||||
{field: 'local_ip', title: 'Local Ip', sort: true},
|
{field: 'local_ip', title: i18n['LocalIp'], sort: true},
|
||||||
{field: 'local_port', title: 'Local Port', sort: true},
|
{field: 'local_port', title: i18n['LocalPort'], sort: true},
|
||||||
{title: 'Operation', width: 150, toolbar: '#proxyListOperationTemplate'}
|
{title: i18n['Operation'], width: 150, toolbar: '#proxyListOperationTemplate'}
|
||||||
];
|
];
|
||||||
|
|
||||||
var proxyListTable = layui.table.render({
|
var proxyListTable = layui.table.render({
|
||||||
@@ -72,7 +63,9 @@ var loadProxyInfo = (function ($) {
|
|||||||
height: $section.height(),
|
height: $section.height(),
|
||||||
text: {none: i18n['EmptyData']},
|
text: {none: i18n['EmptyData']},
|
||||||
cols: [cols],
|
cols: [cols],
|
||||||
page: navigator.language.indexOf("zh") !== -1,
|
page: {
|
||||||
|
layout: navigator.language.indexOf("zh") === -1 ? ['first', 'prev', 'next', 'last'] : ['prev', 'page', 'next', 'skip', 'count', 'limit']
|
||||||
|
},
|
||||||
toolbar: '#proxyListToolbarTemplate',
|
toolbar: '#proxyListToolbarTemplate',
|
||||||
defaultToolbar: false,
|
defaultToolbar: false,
|
||||||
data: dataList,
|
data: dataList,
|
||||||
@@ -109,7 +102,7 @@ var loadProxyInfo = (function ($) {
|
|||||||
}, false);
|
}, false);
|
||||||
break
|
break
|
||||||
case 'remove':
|
case 'remove':
|
||||||
// batchRemovePopup(data);
|
batchRemovePopup(data);
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -123,11 +116,10 @@ var loadProxyInfo = (function ($) {
|
|||||||
|
|
||||||
switch (obj.event) {
|
switch (obj.event) {
|
||||||
case 'update':
|
case 'update':
|
||||||
data.oldName = data.name;
|
|
||||||
proxyPopup(data, true);
|
proxyPopup(data, true);
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove':
|
||||||
// removePopup(data);
|
batchRemovePopup([data]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -167,7 +159,7 @@ var loadProxyInfo = (function ($) {
|
|||||||
skin: 'proxy-popup',
|
skin: 'proxy-popup',
|
||||||
area: ['500px', '400px'],
|
area: ['500px', '400px'],
|
||||||
content: content,
|
content: content,
|
||||||
btn: ['Confirm', 'Cancel'],
|
btn: [i18n['Confirm'], i18n['Cancel']],
|
||||||
btn1: function (index) {
|
btn1: function (index) {
|
||||||
if (layui.form.validate('#addProxyTemplate')) {
|
if (layui.form.validate('#addProxyTemplate')) {
|
||||||
var formData = layui.form.val('addProxyForm');
|
var formData = layui.form.val('addProxyForm');
|
||||||
@@ -185,50 +177,16 @@ var loadProxyInfo = (function ($) {
|
|||||||
layui.layer.close(index);
|
layui.layer.close(index);
|
||||||
},
|
},
|
||||||
success: function (layero, index, that) {
|
success: function (layero, index, that) {
|
||||||
|
//get and set old name for update form
|
||||||
|
var oldNameKey = layero.find('#oldName').attr('name');
|
||||||
|
basicData[oldNameKey] = basicData.name;
|
||||||
layui.form.val('addProxyForm', basicData);
|
layui.form.val('addProxyForm', basicData);
|
||||||
proxyPopupSuccess(layero, index, that, basicData);
|
proxyPopupSuccess();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function proxyPopupSuccess() {
|
||||||
/**
|
|
||||||
* repack form data
|
|
||||||
* @param formData
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
function repackData(formData) {
|
|
||||||
mapParamPrefixes.forEach(function (temp) {
|
|
||||||
var name = temp.name;
|
|
||||||
var prefix = temp.prefix;
|
|
||||||
for (var key in formData) {
|
|
||||||
if (key !== name && key.startsWith(prefix)) {
|
|
||||||
formData[name] = formData[name] || {};
|
|
||||||
var newKey = key.replace(prefix, '');
|
|
||||||
formData[name][newKey] = formData[key];
|
|
||||||
delete formData[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
intParamNames.forEach(function (paramName) {
|
|
||||||
if (formData.hasOwnProperty(paramName) && formData[paramName] !== '') {
|
|
||||||
formData[paramName] = parseInt(formData[paramName]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
booleanParamNames.forEach(function (paramName) {
|
|
||||||
if (formData.hasOwnProperty(paramName) && formData[paramName] !== '') {
|
|
||||||
formData[paramName] = formData[paramName] === 'true';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
stringArrayParamNames.forEach(function (paramName) {
|
|
||||||
if (formData.hasOwnProperty(paramName) && formData[paramName] !== '') {
|
|
||||||
formData[paramName] = formData[paramName].split(',');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return formData;
|
|
||||||
}
|
|
||||||
|
|
||||||
function proxyPopupSuccess(layero, index, that) {
|
|
||||||
layui.form.render(null, 'addProxyForm');
|
layui.form.render(null, 'addProxyForm');
|
||||||
layui.form.on('input-affix(addition)', function (obj) {
|
layui.form.on('input-affix(addition)', function (obj) {
|
||||||
var $paramValue = $(obj.elem);
|
var $paramValue = $(obj.elem);
|
||||||
@@ -245,10 +203,6 @@ var loadProxyInfo = (function ($) {
|
|||||||
$paramValue.val('');
|
$paramValue.val('');
|
||||||
|
|
||||||
layui.form.render();
|
layui.form.render();
|
||||||
|
|
||||||
// var tabContent = $paramValue.closest('.layui-tab-content');
|
|
||||||
// var scrollHeight = tabContent.prop("scrollHeight");
|
|
||||||
// tabContent.scrollTop(scrollHeight)
|
|
||||||
});
|
});
|
||||||
layui.form.on('input-affix(subtraction)', function (obj) {
|
layui.form.on('input-affix(subtraction)', function (obj) {
|
||||||
var $elem = $(obj.elem);
|
var $elem = $(obj.elem);
|
||||||
@@ -294,23 +248,43 @@ var loadProxyInfo = (function ($) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* batch remove proxy popup
|
* batch remove proxy popup
|
||||||
* @param data {[{user:string, token:string, comment:string, enable:boolean, ports:[string|number], domains:[string], subdomains:[string]}]} user data list
|
* @param data {[Map<string,string>]} proxy data list
|
||||||
*/
|
*/
|
||||||
function batchRemovePopup(data) {
|
function batchRemovePopup(data) {
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
layui.layer.msg(i18n['ShouldCheckUser']);
|
layui.layer.msg('ShouldCheckProxy');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
layui.layer.confirm(i18n['ConfirmRemoveUser'], {
|
layui.layer.confirm('ConfirmRemoveProxy', {
|
||||||
title: i18n['OperationConfirm'],
|
title: 'OperationConfirm',
|
||||||
btn: [i18n['Confirm'], i18n['Cancel']]
|
btn: [i18n['Confirm'], i18n['Cancel']]
|
||||||
}, function (index) {
|
}, function (index) {
|
||||||
operate(apiType.Remove, data, index);
|
var loading = layui.layer.load();
|
||||||
|
$.post({
|
||||||
|
url: '/remove',
|
||||||
|
type: 'post',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
success: function (result) {
|
||||||
|
if (result.success) {
|
||||||
|
reloadTable();
|
||||||
|
layui.layer.close(index);
|
||||||
|
layui.layer.msg('OperateSuccess', function (index) {
|
||||||
|
layui.layer.close(index);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
errorMsg(result);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
complete: function () {
|
||||||
|
layui.layer.close(loading);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reload user table
|
* reload proxy table
|
||||||
*/
|
*/
|
||||||
function reloadTable() {
|
function reloadTable() {
|
||||||
loadProxyInfo(null, null, null);
|
loadProxyInfo(null, null, null);
|
||||||
|
|||||||
81
assets/static/js/index-proxy-status.js
Normal file
81
assets/static/js/index-proxy-status.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
var loadProxiesStatus = (function ($) {
|
||||||
|
var i18n = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get proxy info
|
||||||
|
* @param lang {{}} language json
|
||||||
|
* @param title page title
|
||||||
|
*/
|
||||||
|
function loadProxiesStatus(lang, title) {
|
||||||
|
i18n = lang;
|
||||||
|
$("#title").text(title);
|
||||||
|
$('#content').empty();
|
||||||
|
var loading = layui.layer.load();
|
||||||
|
|
||||||
|
$.getJSON('/proxy/api/status').done(function (result) {
|
||||||
|
if (result.success) {
|
||||||
|
$('#content').html($('#proxiesTableTemplate').html());
|
||||||
|
renderProxiesTable(JSON.parse(result.data));
|
||||||
|
} else {
|
||||||
|
layui.layer.msg(result.message);
|
||||||
|
}
|
||||||
|
}).always(function () {
|
||||||
|
layui.layer.close(loading);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render proxy list table
|
||||||
|
* @param data {Map<string,Map<string,string>>} proxy data
|
||||||
|
* @param proxyType proxy type
|
||||||
|
*/
|
||||||
|
function renderProxiesTable(data, proxyType) {
|
||||||
|
var dataList = [];
|
||||||
|
for (var type in data) {
|
||||||
|
var temp = data[type];
|
||||||
|
dataList = dataList.concat(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
var $section = $('#content > section');
|
||||||
|
var cols = [
|
||||||
|
{field: 'name', title: i18n['Name'], sort: true},
|
||||||
|
{field: 'type', title: i18n['Type'], width: 100, sort: true},
|
||||||
|
{
|
||||||
|
field: 'local_addr',
|
||||||
|
title: i18n['LocalAddress'],
|
||||||
|
templet: '<span>{{= d.local_addr || "-" }}</span>',
|
||||||
|
width: 220,
|
||||||
|
sort: true
|
||||||
|
},
|
||||||
|
{field: 'plugin', title: i18n['Plugin'], templet: '<span>{{= d.plugin || "-" }}</span>', sort: true},
|
||||||
|
{field: 'remote_addr', title: i18n['RemoteAddress'], sort: true},
|
||||||
|
{
|
||||||
|
field: 'status', title: i18n['Status'], templet: function (d) {
|
||||||
|
return i18n[d.status];
|
||||||
|
}, width: 100, sort: true
|
||||||
|
},
|
||||||
|
{field: 'err', title: i18n['Info'], templet: '<span>{{= d.err || "-" }}</span>', width: 200}
|
||||||
|
];
|
||||||
|
|
||||||
|
var proxiesTable = layui.table.render({
|
||||||
|
elem: '#proxiesTable',
|
||||||
|
height: $section.height(),
|
||||||
|
text: {none: i18n['EmptyData']},
|
||||||
|
cols: [cols],
|
||||||
|
page: {
|
||||||
|
layout: navigator.language.indexOf("zh") === -1 ? ['first', 'prev', 'next', 'last'] : ['prev', 'page', 'next', 'skip', 'count', 'limit']
|
||||||
|
},
|
||||||
|
data: dataList,
|
||||||
|
initSort: {
|
||||||
|
field: 'name',
|
||||||
|
type: 'asc'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.onresize = function () {
|
||||||
|
proxiesTable.resize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadProxiesStatus;
|
||||||
|
})(layui.$);
|
||||||
@@ -17,18 +17,16 @@ var http_port, https_port;
|
|||||||
layui.element.on('nav(leftNav)', function (elem) {
|
layui.element.on('nav(leftNav)', function (elem) {
|
||||||
var id = elem.attr('id');
|
var id = elem.attr('id');
|
||||||
var title = elem.text();
|
var title = elem.text();
|
||||||
if (id === 'overview') {
|
if (id === 'clientInfo') {
|
||||||
loadOverview(lang, title.trim());
|
loadClientInfo(lang, title.trim());
|
||||||
} else if (elem.closest('.layui-nav-item').attr('id') === 'configure') {
|
} else if (id === 'proxiesStatus') {
|
||||||
|
loadProxiesStatus(lang, title.trim());
|
||||||
|
} else if (elem.closest('.layui-nav-item').attr('id') === 'proxies') {
|
||||||
if (id != null && id.trim() !== '') {
|
if (id != null && id.trim() !== '') {
|
||||||
var suffix = elem.closest('.layui-nav-item').children('a').text().trim();
|
var suffix = elem.closest('.layui-nav-item').children('a').text().trim();
|
||||||
if (id === 'common') {
|
|
||||||
loadCommon(lang, title + " " + suffix);
|
|
||||||
} else {
|
|
||||||
loadProxyInfo(lang, title + " " + suffix, id);
|
loadProxyInfo(lang, title + " " + suffix, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#leftNav .layui-this > a').click();
|
$('#leftNav .layui-this > a').click();
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
<link rel="stylesheet" href="./static/css/index.css?v=${ .version }">
|
<link rel="stylesheet" href="./static/css/index.css?v=${ .version }">
|
||||||
<link rel="stylesheet" href="./static/css/color.css?v=${ .version }">
|
<link rel="stylesheet" href="./static/css/color.css?v=${ .version }">
|
||||||
<script src="./static/lib/layui/layui.js?v=${ .version }"></script>
|
<script src="./static/lib/layui/layui.js?v=${ .version }"></script>
|
||||||
<script src="./static/js/index-overview.js?v=${ .version }"></script>
|
<script src="./static/js/index-proxy-status.js?v=${ .version }"></script>
|
||||||
<script src="./static/js/index-configure.js?v=${ .version }"></script>
|
<script src="./static/js/index-client-info.js?v=${ .version }"></script>
|
||||||
<script src="./static/js/index-proxy-list.js?v=${ .version }"></script>
|
<script src="./static/js/index-proxy-list.js?v=${ .version }"></script>
|
||||||
<script src="./static/js/index.js?v=${ .version }"></script>
|
<script src="./static/js/index.js?v=${ .version }"></script>
|
||||||
</head>
|
</head>
|
||||||
@@ -27,14 +27,14 @@
|
|||||||
<div class="layui-side-scroll">
|
<div class="layui-side-scroll">
|
||||||
<ul class="layui-nav layui-nav-tree" lay-filter="leftNav" id="leftNav">
|
<ul class="layui-nav layui-nav-tree" lay-filter="leftNav" id="leftNav">
|
||||||
<li class="layui-nav-item layui-this">
|
<li class="layui-nav-item layui-this">
|
||||||
<a href="javascript:void(0)" id="overview">Overview</a>
|
<a href="javascript:void(0)" id="clientInfo">${ .ClientInfo }</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="layui-nav-item layui-nav-itemed" id="configure">
|
<li class="layui-nav-item">
|
||||||
<a class="" href="javascript:void(0)">Configure</a>
|
<a href="javascript:void(0)" id="proxiesStatus">${ .ProxiesStatus }</a>
|
||||||
|
</li>
|
||||||
|
<li class="layui-nav-item layui-nav-itemed" id="proxies">
|
||||||
|
<a class="" href="javascript:void(0)">${ .Proxies }</a>
|
||||||
<dl class="layui-nav-child">
|
<dl class="layui-nav-child">
|
||||||
<dd>
|
|
||||||
<a href="javascript:void(0)" id="common">Common</a>
|
|
||||||
</dd>
|
|
||||||
<dd>
|
<dd>
|
||||||
<a href="javascript:void(0)" id="tcp">TCP</a>
|
<a href="javascript:void(0)" id="tcp">TCP</a>
|
||||||
</dd>
|
</dd>
|
||||||
@@ -65,79 +65,79 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--代理列表-代理表格模板-->
|
<!--代理列表-代理表格模板-->
|
||||||
<script type="text/html" id="overviewTableTemplate">
|
<script type="text/html" id="proxiesTableTemplate">
|
||||||
<section class="overview">
|
<section class="proxies">
|
||||||
<table id="overviewTable" lay-filter="overviewTable"></table>
|
<table id="proxiesTable" lay-filter="proxiesTable"></table>
|
||||||
</section>
|
</section>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--配置信息模板-->
|
<!--配置信息模板-->
|
||||||
<script type="text/html" id="commonTemplate">
|
<script type="text/html" id="clientInfoTemplate">
|
||||||
<section class="common-info">
|
<section class="client-info">
|
||||||
<div class="text-info">
|
<div class="text-info">
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">server_addr</div>
|
<div class="text-col">${ .ServerAddress }</div>
|
||||||
<div class="text-col">{{= d.server_addr }}</div>
|
<div class="text-col">{{= d.server_addr || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">server_port</div>
|
<div class="text-col">${ .ServerPort }</div>
|
||||||
<div class="text-col">{{= d.server_port }}</div>
|
<div class="text-col">{{= d.server_port || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">protocol</div>
|
<div class="text-col">${ .Protocol }</div>
|
||||||
<div class="text-col">{{= d.protocol }}</div>
|
<div class="text-col">{{= d.protocol || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">tcp_mux</div>
|
<div class="text-col">${ .TCPMux }</div>
|
||||||
<div class="text-col">{{= d.tcp_mux }}</div>
|
<div class="text-col">{{= d.tcp_mux || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">user</div>
|
<div class="text-col">${ .User }</div>
|
||||||
<div class="text-col">{{= d.user }}</div>
|
<div class="text-col">{{= d.user || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">meta_token</div>
|
<div class="text-col">${ .UserToken }</div>
|
||||||
<div class="text-col">{{= d.metas.token }}</div>
|
<div class="text-col">{{= d.metas.token || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">admin_addr</div>
|
<div class="text-col">${ .AdminAddress }</div>
|
||||||
<div class="text-col">{{= d.admin_addr }}</div>
|
<div class="text-col">{{= d.admin_addr || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">admin_port</div>
|
<div class="text-col">${ .AdminPort }</div>
|
||||||
<div class="text-col">{{= d.admin_port }}</div>
|
<div class="text-col">{{= d.admin_port || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">admin_pwd</div>
|
<div class="text-col">${ .AdminUser }</div>
|
||||||
<div class="text-col">{{= d.admin_pwd }}</div>
|
<div class="text-col">{{= d.admin_user || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">admin_user</div>
|
<div class="text-col">${ .AdminPwd }</div>
|
||||||
<div class="text-col">{{= d.admin_user }}</div>
|
<div class="text-col">{{= d.admin_pwd || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">heartbeat_interval</div>
|
<div class="text-col">${ .HeartbeatInterval }</div>
|
||||||
<div class="text-col">{{= d.heartbeat_interval }}</div>
|
<div class="text-col">{{= d.heartbeat_interval || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">heartbeat_timeout</div>
|
<div class="text-col">${ .HeartbeatTimeout }</div>
|
||||||
<div class="text-col">{{= d.heartbeat_timeout }}</div>
|
<div class="text-col">{{= d.heartbeat_timeout || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">tls_enable</div>
|
<div class="text-col">${ .TLSEnable }</div>
|
||||||
<div class="text-col">{{= d.tls_enable }}</div>
|
<div class="text-col">{{= d.tls_enable || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">tls_key_file</div>
|
<div class="text-col">${ .TLSKeyFile }</div>
|
||||||
<div class="text-col">{{= d.tls_key_file }}</div>
|
<div class="text-col">{{= d.tls_key_file || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">tls_cert_file</div>
|
<div class="text-col">${ .TLSCertFile }</div>
|
||||||
<div class="text-col">{{= d.tls_cert_file }}</div>
|
<div class="text-col">{{= d.tls_cert_file || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-row">
|
<div class="text-row">
|
||||||
<div class="text-col">tls_trusted_ca_file</div>
|
<div class="text-col">${ .TLSTrustedCAFile }</div>
|
||||||
<div class="text-col">{{= d.tls_trusted_ca_file }}</div>
|
<div class="text-col">{{= d.tls_trusted_ca_file || '-' }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -148,59 +148,55 @@
|
|||||||
<form class="layui-form" id="addProxyForm" lay-filter="addProxyForm">
|
<form class="layui-form" id="addProxyForm" lay-filter="addProxyForm">
|
||||||
<div class="layui-tab layui-tab-brief">
|
<div class="layui-tab layui-tab-brief">
|
||||||
<ul class="layui-tab-title">
|
<ul class="layui-tab-title">
|
||||||
<li class="layui-this">Basic</li>
|
<li class="layui-this">${ .Basic }</li>
|
||||||
<li>Extra</li>
|
<li>${ .Extra }</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="layui-tab-content">
|
<div class="layui-tab-content">
|
||||||
|
<input type="hidden" name="type">
|
||||||
|
<input type="hidden" name="${ .oldNameKey }" id="oldName">
|
||||||
<div class="layui-tab-item layui-show">
|
<div class="layui-tab-item layui-show">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">ProxyName</label>
|
<label class="layui-form-label">${ .ProxyName }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="name" placeholder="ProxyName" autocomplete="off"
|
<input type="text" name="name" placeholder="${ .ProxyName }" autocomplete="off"
|
||||||
class="layui-input"/>
|
class="layui-input"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">ProxyType</label>
|
<label class="layui-form-label">${ .LocalIp }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="type" readonly class="layui-input">
|
<input type="text" name="local_ip" placeholder="${ .LocalIp }" autocomplete="off"
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">LocalIp</label>
|
|
||||||
<div class="layui-input-block">
|
|
||||||
<input type="text" name="local_ip" placeholder="LocalIp" autocomplete="off"
|
|
||||||
class="layui-input"/>
|
class="layui-input"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">LocalPort</label>
|
<label class="layui-form-label">${ .LocalPort }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="local_port" placeholder="LocalPort" autocomplete="off"
|
<input type="text" name="local_port" placeholder="${ .LocalPort }" autocomplete="off"
|
||||||
class="layui-input"/>
|
class="layui-input"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{# if (d.type === 'http' || d.type === 'https') { }}
|
{{# if (d.type === 'http' || d.type === 'https') { }}
|
||||||
<div class="layui-form-item http https">
|
<div class="layui-form-item http https">
|
||||||
<label class="layui-form-label">CustomizeDomains</label>
|
<label class="layui-form-label">${ .CustomizeDomains }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<textarea name="custom_domains" placeholder="CustomDomains" autocomplete="off"
|
<textarea name="custom_domains" placeholder="${ .CustomizeDomains }" autocomplete="off"
|
||||||
class="layui-textarea"></textarea>
|
class="layui-textarea"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item layui-form-text http https">
|
<div class="layui-form-item layui-form-text http https">
|
||||||
<label class="layui-form-label">Subdomain</label>
|
<label class="layui-form-label">${ .Subdomain }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<textarea name="sub_domain" placeholder="Subdomain" autocomplete="off"
|
<textarea name="sub_domain" placeholder="${ .Subdomain }" autocomplete="off"
|
||||||
class="layui-textarea"></textarea>
|
class="layui-textarea"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{# } }}
|
{{# } }}
|
||||||
{{# if (d.type === 'tcp' || d.type === 'udp') { }}
|
{{# if (d.type === 'tcp' || d.type === 'udp') { }}
|
||||||
<div class="layui-form-item tcp udp">
|
<div class="layui-form-item tcp udp">
|
||||||
<label class="layui-form-label">RemotePort</label>
|
<label class="layui-form-label">${ .RemotePort }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="remote_port" placeholder="RemotePort" autocomplete="off"
|
<input type="text" name="remote_port" placeholder="${ .RemotePort }" autocomplete="off"
|
||||||
class="layui-input"/>
|
class="layui-input"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -208,17 +204,17 @@
|
|||||||
<div class="layui-row">
|
<div class="layui-row">
|
||||||
<div class="layui-col-xs6">
|
<div class="layui-col-xs6">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">UseEncryption</label>
|
<label class="layui-form-label">${ .UseEncryption }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="checkbox" name="use_encryption" value="true" title="YES">
|
<input type="checkbox" name="use_encryption" value="true" title="${ .true }">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-xs6">
|
<div class="layui-col-xs6">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">UseCompression</label>
|
<label class="layui-form-label">${ .UseCompression }</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="checkbox" name="use_compression" value="true" title="YES">
|
<input type="checkbox" name="use_compression" value="true" title="${ .true }">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -227,24 +223,24 @@
|
|||||||
<div class="layui-tab-item extra-param-tab-item">
|
<div class="layui-tab-item extra-param-tab-item">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" class="layui-input" placeholder="paramName">
|
<input type="text" class="layui-input" placeholder="${ .ParamName }">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-mid">=</div>
|
<div class="layui-form-mid">=</div>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" class="layui-input" lay-filter="addition"
|
<input type="text" class="layui-input" lay-filter="addition"
|
||||||
lay-affix="addition" placeholder="paramValue">
|
lay-affix="addition" placeholder="${ .ParamValue }">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{# layui.each(d.extraData, function(index, extra){ }}
|
{{# layui.each(d.extraData, function(index, extra){ }}
|
||||||
<div class="layui-form-item extra-param-item">
|
<div class="layui-form-item extra-param-item">
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" value="{{= extra.name}}" class="layui-input"
|
<input type="text" value="{{= extra.name}}" class="layui-input"
|
||||||
placeholder="paramName">
|
placeholder="${ .ParamName }">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-mid">=</div>
|
<div class="layui-form-mid">=</div>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" value="{{= extra.value }}" class="layui-input"
|
<input type="text" value="{{= extra.value }}" class="layui-input"
|
||||||
lay-filter="subtraction" lay-affix="subtraction" placeholder="paramValue">
|
lay-filter="subtraction" lay-affix="subtraction" placeholder="${ .ParamValue }">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{# }); }}
|
{{# }); }}
|
||||||
@@ -257,12 +253,12 @@
|
|||||||
<script type="text/html" id="extraParamAddedTemplate">
|
<script type="text/html" id="extraParamAddedTemplate">
|
||||||
<div class="layui-form-item extra-param-item">
|
<div class="layui-form-item extra-param-item">
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" value="{{= d.name}}" class="layui-input" placeholder="paramName">
|
<input type="text" value="{{= d.name}}" class="layui-input" placeholder="${ .ParamName }">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-mid">=</div>
|
<div class="layui-form-mid">=</div>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" value="{{= d.value }}" class="layui-input"
|
<input type="text" value="{{= d.value }}" class="layui-input"
|
||||||
lay-filter="subtraction" lay-affix="subtraction" placeholder="paramValue">
|
lay-filter="subtraction" lay-affix="subtraction" placeholder="${ .ParamValue }">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
@@ -277,16 +273,16 @@
|
|||||||
<!--代理列表-表格工具条按钮模板-->
|
<!--代理列表-表格工具条按钮模板-->
|
||||||
<script type="text/html" id="proxyListToolbarTemplate">
|
<script type="text/html" id="proxyListToolbarTemplate">
|
||||||
<div class="layui-btn-container">
|
<div class="layui-btn-container">
|
||||||
<button class="layui-btn layui-btn-sm" lay-event="add">NewProxy</button>
|
<button class="layui-btn layui-btn-sm" lay-event="add">${ .NewProxy }</button>
|
||||||
<button class="layui-btn layui-btn-sm" lay-event="remove">RemoveProxy</button>
|
<button class="layui-btn layui-btn-sm" lay-event="remove">${ .RemoveProxy }</button>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--代理列表-操作按钮模板-->
|
<!--代理列表-操作按钮模板-->
|
||||||
<script type="text/html" id="proxyListOperationTemplate">
|
<script type="text/html" id="proxyListOperationTemplate">
|
||||||
<div class="layui-clear-space">
|
<div class="layui-clear-space">
|
||||||
<a class="layui-btn layui-btn-xs" lay-event="update">Update</a>
|
<a class="layui-btn layui-btn-xs" lay-event="update">${ .Update }</a>
|
||||||
<a class="layui-btn layui-btn-xs" lay-event="remove">Remove</a>
|
<a class="layui-btn layui-btn-xs" lay-event="remove">${ .Remove }</a>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ tls_mode = false
|
|||||||
#tls_key_file = "cert.key"
|
#tls_key_file = "cert.key"
|
||||||
|
|
||||||
# frpc dashboard info
|
# frpc dashboard info
|
||||||
dashboard_addr = "127.0.0.1"
|
dashboard_addr = "home.frp.yanghuanglin.com"
|
||||||
dashboard_port = 7400
|
dashboard_port = 80
|
||||||
dashboard_user = "admin"
|
dashboard_user = "admin"
|
||||||
dashboard_pwd = "admin"
|
dashboard_pwd = "19910621"
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,12 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
ginI18n "github.com/gin-contrib/i18n"
|
ginI18n "github.com/gin-contrib/i18n"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/vaughan0/go-ini"
|
"github.com/vaughan0/go-ini"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *HandleController) MakeLoginFunc() func(context *gin.Context) {
|
func (c *HandleController) MakeLoginFunc() func(context *gin.Context) {
|
||||||
@@ -61,8 +57,45 @@ func (c *HandleController) MakeIndexFunc() func(context *gin.Context) {
|
|||||||
return func(context *gin.Context) {
|
return func(context *gin.Context) {
|
||||||
context.HTML(http.StatusOK, "index.html", gin.H{
|
context.HTML(http.StatusOK, "index.html", gin.H{
|
||||||
"version": c.Version,
|
"version": c.Version,
|
||||||
"FrpcPanel": ginI18n.MustGetMessage(context, "Frpc Panel"),
|
"oldNameKey": oldNameKey,
|
||||||
"showExit": trimString(c.CommonInfo.AdminUser) != "" && trimString(c.CommonInfo.AdminPwd) != "",
|
"showExit": trimString(c.CommonInfo.AdminUser) != "" && trimString(c.CommonInfo.AdminPwd) != "",
|
||||||
|
"FrpcPanel": ginI18n.MustGetMessage(context, "Frpc Panel"),
|
||||||
|
"ClientInfo": ginI18n.MustGetMessage(context, "Client Info"),
|
||||||
|
"ProxiesStatus": ginI18n.MustGetMessage(context, "Proxies Status"),
|
||||||
|
"Proxies": ginI18n.MustGetMessage(context, "Proxies"),
|
||||||
|
"ServerAddress": ginI18n.MustGetMessage(context, "Server Address"),
|
||||||
|
"ServerPort": ginI18n.MustGetMessage(context, "Server Port"),
|
||||||
|
"Protocol": ginI18n.MustGetMessage(context, "Protocol"),
|
||||||
|
"TCPMux": ginI18n.MustGetMessage(context, "TCP Mux"),
|
||||||
|
"User": ginI18n.MustGetMessage(context, "User"),
|
||||||
|
"UserToken": ginI18n.MustGetMessage(context, "User Token"),
|
||||||
|
"AdminAddress": ginI18n.MustGetMessage(context, "Admin Address"),
|
||||||
|
"AdminPort": ginI18n.MustGetMessage(context, "Admin Port"),
|
||||||
|
"AdminUser": ginI18n.MustGetMessage(context, "Admin User"),
|
||||||
|
"AdminPwd": ginI18n.MustGetMessage(context, "Admin Pwd"),
|
||||||
|
"HeartbeatInterval": ginI18n.MustGetMessage(context, "Heartbeat Interval"),
|
||||||
|
"HeartbeatTimeout": ginI18n.MustGetMessage(context, "Heartbeat Timeout"),
|
||||||
|
"TLSEnable": ginI18n.MustGetMessage(context, "TLS Enable"),
|
||||||
|
"TLSKeyFile": ginI18n.MustGetMessage(context, "TLS Key File"),
|
||||||
|
"TLSCertFile": ginI18n.MustGetMessage(context, "TLS Cert File"),
|
||||||
|
"TLSTrustedCAFile": ginI18n.MustGetMessage(context, "TLS Trusted CA File"),
|
||||||
|
"NewProxy": ginI18n.MustGetMessage(context, "New Proxy"),
|
||||||
|
"RemoveProxy": ginI18n.MustGetMessage(context, "Remove Proxy"),
|
||||||
|
"Update": ginI18n.MustGetMessage(context, "Update"),
|
||||||
|
"Remove": ginI18n.MustGetMessage(context, "Remove"),
|
||||||
|
"Basic": ginI18n.MustGetMessage(context, "Basic"),
|
||||||
|
"Extra": ginI18n.MustGetMessage(context, "Extra"),
|
||||||
|
"ProxyName": ginI18n.MustGetMessage(context, "Proxy Name"),
|
||||||
|
"LocalIp": ginI18n.MustGetMessage(context, "Local Ip"),
|
||||||
|
"LocalPort": ginI18n.MustGetMessage(context, "Local Port"),
|
||||||
|
"RemotePort": ginI18n.MustGetMessage(context, "Remote Port"),
|
||||||
|
"CustomizeDomains": ginI18n.MustGetMessage(context, "Customize Domains"),
|
||||||
|
"Subdomain": ginI18n.MustGetMessage(context, "Subdomain"),
|
||||||
|
"UseEncryption": ginI18n.MustGetMessage(context, "Use Encryption"),
|
||||||
|
"true": ginI18n.MustGetMessage(context, "true"),
|
||||||
|
"UseCompression": ginI18n.MustGetMessage(context, "Use Compression"),
|
||||||
|
"ParamName": ginI18n.MustGetMessage(context, "Param Name"),
|
||||||
|
"ParamValue": ginI18n.MustGetMessage(context, "Param Value"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,6 +104,21 @@ func (c *HandleController) MakeLangFunc() func(context *gin.Context) {
|
|||||||
return func(context *gin.Context) {
|
return func(context *gin.Context) {
|
||||||
context.JSON(http.StatusOK, gin.H{
|
context.JSON(http.StatusOK, gin.H{
|
||||||
"EmptyData": ginI18n.MustGetMessage(context, "Empty data"),
|
"EmptyData": ginI18n.MustGetMessage(context, "Empty data"),
|
||||||
|
"true": ginI18n.MustGetMessage(context, "true"),
|
||||||
|
"false": ginI18n.MustGetMessage(context, "false"),
|
||||||
|
"Name": ginI18n.MustGetMessage(context, "Name"),
|
||||||
|
"Type": ginI18n.MustGetMessage(context, "Type"),
|
||||||
|
"LocalAddress": ginI18n.MustGetMessage(context, "Local Address"),
|
||||||
|
"Plugin": ginI18n.MustGetMessage(context, "Plugin"),
|
||||||
|
"RemoteAddress": ginI18n.MustGetMessage(context, "Remote Address"),
|
||||||
|
"Status": ginI18n.MustGetMessage(context, "Status"),
|
||||||
|
"Info": ginI18n.MustGetMessage(context, "Info"),
|
||||||
|
"running": ginI18n.MustGetMessage(context, "running"),
|
||||||
|
"LocalIp": ginI18n.MustGetMessage(context, "Local Ip"),
|
||||||
|
"LocalPort": ginI18n.MustGetMessage(context, "Local Port"),
|
||||||
|
"Operation": ginI18n.MustGetMessage(context, "Operation"),
|
||||||
|
"Confirm": ginI18n.MustGetMessage(context, "Confirm"),
|
||||||
|
"Cancel": ginI18n.MustGetMessage(context, "Cancel"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +143,7 @@ func (c *HandleController) MakeAddProxyFunc() func(context *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name := proxy["name"]
|
name := proxy[nameKey]
|
||||||
|
|
||||||
if trimString(name) == "" {
|
if trimString(name) == "" {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
@@ -115,10 +163,10 @@ func (c *HandleController) MakeAddProxyFunc() func(context *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(proxy, "name")
|
delete(proxy, nameKey)
|
||||||
clientProxies[name] = proxy
|
clientProxies[name] = proxy
|
||||||
|
|
||||||
res := c.ReloadFrpc()
|
res := c.UpdateFrpcConfig()
|
||||||
if !res.Success {
|
if !res.Success {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Code = SaveError
|
response.Code = SaveError
|
||||||
@@ -152,8 +200,8 @@ func (c *HandleController) MakeUpdateProxyFunc() func(context *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
oldName := proxy["oldName"]
|
oldName := proxy[oldNameKey]
|
||||||
name := proxy["name"]
|
name := proxy[nameKey]
|
||||||
|
|
||||||
if trimString(oldName) == "" || trimString(name) == "" {
|
if trimString(oldName) == "" || trimString(name) == "" {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
@@ -175,12 +223,12 @@ func (c *HandleController) MakeUpdateProxyFunc() func(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(proxy, "name")
|
delete(proxy, nameKey)
|
||||||
delete(proxy, "oldName")
|
delete(proxy, oldNameKey)
|
||||||
delete(clientProxies, oldName)
|
delete(clientProxies, oldName)
|
||||||
clientProxies[name] = proxy
|
clientProxies[name] = proxy
|
||||||
|
|
||||||
res := c.ReloadFrpc()
|
res := c.UpdateFrpcConfig()
|
||||||
if !res.Success {
|
if !res.Success {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Code = SaveError
|
response.Code = SaveError
|
||||||
@@ -196,7 +244,7 @@ func (c *HandleController) MakeUpdateProxyFunc() func(context *gin.Context) {
|
|||||||
|
|
||||||
func (c *HandleController) MakeRemoveProxyFunc() func(context *gin.Context) {
|
func (c *HandleController) MakeRemoveProxyFunc() func(context *gin.Context) {
|
||||||
return func(context *gin.Context) {
|
return func(context *gin.Context) {
|
||||||
proxy := make(map[string]interface{})
|
var proxies []ini.Section
|
||||||
|
|
||||||
response := OperationResponse{
|
response := OperationResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -204,21 +252,50 @@ func (c *HandleController) MakeRemoveProxyFunc() func(context *gin.Context) {
|
|||||||
Message: "proxy remove success",
|
Message: "proxy remove success",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := context.BindJSON(&proxy)
|
err := context.BindJSON(&proxies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Code = ParamError
|
response.Code = ParamError
|
||||||
response.Message = fmt.Sprintf("user remove failed, param error : %v", err)
|
response.Message = fmt.Sprintf("proxy remove failed, param error : %v", err)
|
||||||
log.Printf(response.Message)
|
log.Printf(response.Message)
|
||||||
context.JSON(http.StatusOK, &response)
|
context.JSON(http.StatusOK, &response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := c.ReloadFrpc()
|
tempProxyNames := make([]string, len(proxies))
|
||||||
|
for index, proxy := range proxies {
|
||||||
|
name := proxy[nameKey]
|
||||||
|
|
||||||
|
if trimString(name) == "" {
|
||||||
|
response.Success = false
|
||||||
|
response.Code = ParamError
|
||||||
|
response.Message = fmt.Sprintf("proxy remove failed, proxy %v name invalid", name)
|
||||||
|
log.Printf(response.Message)
|
||||||
|
context.JSON(http.StatusOK, &response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, exist := clientProxies[name]; !exist {
|
||||||
|
response.Success = false
|
||||||
|
response.Code = ProxyExist
|
||||||
|
response.Message = fmt.Sprintf("proxy remove failed, proxy %v not exist", name)
|
||||||
|
log.Printf(response.Message)
|
||||||
|
context.JSON(http.StatusOK, &response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tempProxyNames[index] = name
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, name := range tempProxyNames {
|
||||||
|
delete(clientProxies, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := c.UpdateFrpcConfig()
|
||||||
if !res.Success {
|
if !res.Success {
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Code = SaveError
|
response.Code = SaveError
|
||||||
response.Message = fmt.Sprintf("user update failed, error : %v", res.Message)
|
response.Message = fmt.Sprintf("proxy remvoe failed, error : %v", res.Message)
|
||||||
log.Printf(response.Message)
|
log.Printf(response.Message)
|
||||||
context.JSON(http.StatusOK, &response)
|
context.JSON(http.StatusOK, &response)
|
||||||
return
|
return
|
||||||
@@ -230,37 +307,11 @@ func (c *HandleController) MakeRemoveProxyFunc() func(context *gin.Context) {
|
|||||||
|
|
||||||
func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
|
func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
|
||||||
return func(context *gin.Context) {
|
return func(context *gin.Context) {
|
||||||
var client *http.Client
|
|
||||||
var protocol string
|
|
||||||
|
|
||||||
if c.CommonInfo.DashboardTls {
|
|
||||||
client = &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
InsecureSkipVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
protocol = "https://"
|
|
||||||
} else {
|
|
||||||
client = http.DefaultClient
|
|
||||||
protocol = "http://"
|
|
||||||
}
|
|
||||||
|
|
||||||
res := ProxyResponse{}
|
res := ProxyResponse{}
|
||||||
host := c.CommonInfo.DashboardAddr
|
|
||||||
port := c.CommonInfo.DashboardPort
|
|
||||||
serverApi := context.Param("serverApi")
|
serverApi := context.Param("serverApi")
|
||||||
requestUrl := protocol + host + ":" + strconv.Itoa(port) + serverApi
|
requestUrl := c.buildRequestUrl(serverApi)
|
||||||
request, _ := http.NewRequest("GET", requestUrl, nil)
|
request, _ := http.NewRequest("GET", requestUrl, nil)
|
||||||
username := c.CommonInfo.DashboardUser
|
response, err := c.getClientResponse(request, c.buildClient())
|
||||||
password := c.CommonInfo.DashboardPwd
|
|
||||||
if trimString(username) != "" && trimString(password) != "" {
|
|
||||||
request.SetBasicAuth(username, password)
|
|
||||||
log.Printf("Proxy to %s", requestUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := client.Do(request)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = FrpServerError
|
res.Code = FrpServerError
|
||||||
@@ -271,27 +322,7 @@ func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Code = response.StatusCode
|
c.parseResponse(&res, response)
|
||||||
body, err := io.ReadAll(response.Body)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
res.Success = false
|
|
||||||
res.Message = err.Error()
|
|
||||||
} else {
|
|
||||||
if res.Code == http.StatusOK {
|
|
||||||
res.Success = true
|
|
||||||
res.Data = string(body)
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s success", requestUrl)
|
|
||||||
} else {
|
|
||||||
res.Success = false
|
|
||||||
if res.Code == http.StatusNotFound {
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s error: url not found", requestUrl)
|
|
||||||
} else {
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s error: %s", requestUrl, string(body))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf(res.Message)
|
|
||||||
|
|
||||||
if serverApi == "/api/config" {
|
if serverApi == "/api/config" {
|
||||||
proxyType, _ := context.GetQuery("type")
|
proxyType, _ := context.GetQuery("type")
|
||||||
@@ -310,37 +341,11 @@ func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HandleController) ReloadFrpc() ProxyResponse {
|
func (c *HandleController) UpdateFrpcConfig() ProxyResponse {
|
||||||
var client *http.Client
|
|
||||||
var protocol string
|
|
||||||
|
|
||||||
if c.CommonInfo.DashboardTls {
|
|
||||||
client = &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
InsecureSkipVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
protocol = "https://"
|
|
||||||
} else {
|
|
||||||
client = http.DefaultClient
|
|
||||||
protocol = "http://"
|
|
||||||
}
|
|
||||||
|
|
||||||
res := ProxyResponse{}
|
res := ProxyResponse{}
|
||||||
host := c.CommonInfo.DashboardAddr
|
requestUrl := c.buildRequestUrl("/api/config")
|
||||||
port := c.CommonInfo.DashboardPort
|
|
||||||
serverApi := "/api/config"
|
|
||||||
requestUrl := protocol + host + ":" + strconv.Itoa(port) + serverApi
|
|
||||||
request, _ := http.NewRequest("PUT", requestUrl, bytes.NewReader(serializeSectionsToString()))
|
request, _ := http.NewRequest("PUT", requestUrl, bytes.NewReader(serializeSectionsToString()))
|
||||||
username := c.CommonInfo.DashboardUser
|
response, err := c.getClientResponse(request, c.buildClient())
|
||||||
password := c.CommonInfo.DashboardPwd
|
|
||||||
if trimString(username) != "" && trimString(password) != "" {
|
|
||||||
request.SetBasicAuth(username, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := client.Do(request)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = FrpServerError
|
res.Code = FrpServerError
|
||||||
@@ -350,45 +355,25 @@ func (c *HandleController) ReloadFrpc() ProxyResponse {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Code = response.StatusCode
|
c.parseResponse(&res, response)
|
||||||
body, err := io.ReadAll(response.Body)
|
if res.Success {
|
||||||
|
c.ReloadFrpcConfig(&res)
|
||||||
if err != nil {
|
|
||||||
res.Success = false
|
|
||||||
res.Message = err.Error()
|
|
||||||
} else {
|
|
||||||
if res.Code == http.StatusOK {
|
|
||||||
res.Success = true
|
|
||||||
res.Data = string(body)
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s success", requestUrl)
|
|
||||||
} else {
|
|
||||||
res.Success = false
|
|
||||||
if res.Code == http.StatusNotFound {
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s error: url not found", requestUrl)
|
|
||||||
} else {
|
|
||||||
res.Message = fmt.Sprintf("Proxy to %s error: %s", requestUrl, string(body))
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf(res.Message)
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func serializeSectionsToString() []byte {
|
func (c *HandleController) ReloadFrpcConfig(res *ProxyResponse) {
|
||||||
var build strings.Builder
|
requestUrl := c.buildRequestUrl("/api/reload")
|
||||||
build.WriteString("[common]\n")
|
request, _ := http.NewRequest("GET", requestUrl, nil)
|
||||||
for key, value := range clientCommon {
|
response, err := c.getClientResponse(request, c.buildClient())
|
||||||
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
|
||||||
}
|
|
||||||
build.WriteString("\n")
|
|
||||||
|
|
||||||
for name, section := range clientProxies {
|
if err != nil {
|
||||||
build.WriteString(fmt.Sprintf("[%s]\n", name))
|
res.Code = FrpServerError
|
||||||
for key, value := range section {
|
res.Success = false
|
||||||
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
res.Message = err.Error()
|
||||||
}
|
log.Print(err)
|
||||||
build.WriteString("\n")
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return []byte(build.String())
|
c.parseResponse(res, response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/vaughan0/go-ini"
|
"github.com/vaughan0/go-ini"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,17 +16,95 @@ func trimString(str string) string {
|
|||||||
return strings.TrimSpace(str)
|
return strings.TrimSpace(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanString(originalString string) string {
|
func serializeSectionsToString() []byte {
|
||||||
return trimString(originalString)
|
var build strings.Builder
|
||||||
|
build.WriteString("[common]\n")
|
||||||
|
for key, value := range clientCommon {
|
||||||
|
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
||||||
|
}
|
||||||
|
build.WriteString("\n")
|
||||||
|
|
||||||
|
for name, section := range clientProxies {
|
||||||
|
build.WriteString(fmt.Sprintf("[%s]\n", name))
|
||||||
|
for key, value := range section {
|
||||||
|
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
||||||
|
}
|
||||||
|
build.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte(build.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringContains(element string, data []string) bool {
|
func (c *HandleController) buildRequestUrl(serverApi string) string {
|
||||||
for _, v := range data {
|
var protocol string
|
||||||
if element == v {
|
|
||||||
return true
|
if c.CommonInfo.DashboardTls {
|
||||||
|
protocol = "https://"
|
||||||
|
} else {
|
||||||
|
protocol = "http://"
|
||||||
|
}
|
||||||
|
|
||||||
|
host := c.CommonInfo.DashboardAddr
|
||||||
|
port := c.CommonInfo.DashboardPort
|
||||||
|
requestUrl := protocol + host + ":" + strconv.Itoa(port) + serverApi
|
||||||
|
|
||||||
|
return requestUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HandleController) buildClient() *http.Client {
|
||||||
|
var client *http.Client
|
||||||
|
|
||||||
|
if c.CommonInfo.DashboardTls {
|
||||||
|
client = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client = http.DefaultClient
|
||||||
|
}
|
||||||
|
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HandleController) getClientResponse(request *http.Request, client *http.Client) (*http.Response, error) {
|
||||||
|
username := c.CommonInfo.DashboardUser
|
||||||
|
password := c.CommonInfo.DashboardPwd
|
||||||
|
if trimString(username) != "" && trimString(password) != "" {
|
||||||
|
request.SetBasicAuth(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := client.Do(request)
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HandleController) parseResponse(res *ProxyResponse, response *http.Response) string {
|
||||||
|
res.Code = response.StatusCode
|
||||||
|
body, err := io.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
res.Success = false
|
||||||
|
res.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
url := response.Request.URL
|
||||||
|
if res.Code == http.StatusOK {
|
||||||
|
res.Success = true
|
||||||
|
res.Data = string(body)
|
||||||
|
res.Message = fmt.Sprintf("Proxy to %s success", url)
|
||||||
|
} else {
|
||||||
|
res.Success = false
|
||||||
|
if res.Code == http.StatusNotFound {
|
||||||
|
res.Message = fmt.Sprintf("Proxy to %s error: url not found", url)
|
||||||
|
} else {
|
||||||
|
res.Message = fmt.Sprintf("Proxy to %s error: %s", url, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
}
|
||||||
|
|
||||||
|
log.Printf(res.Message)
|
||||||
|
|
||||||
|
return string(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HandleController) parseConfigure(content, proxyType string) (interface{}, error) {
|
func (c *HandleController) parseConfigure(content, proxyType string) (interface{}, error) {
|
||||||
@@ -44,7 +128,7 @@ func (c *HandleController) parseConfigure(content, proxyType string) (interface{
|
|||||||
currentProxies[name] = section
|
currentProxies[name] = section
|
||||||
}
|
}
|
||||||
clientProxies[name] = section
|
clientProxies[name] = section
|
||||||
delete(clientProxies[name], "name")
|
delete(clientProxies[name], nameKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxyType == "none" {
|
if proxyType == "none" {
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ const (
|
|||||||
ProxyRemove
|
ProxyRemove
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nameKey = "name"
|
||||||
|
oldNameKey = "_old_name"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SessionName = "GOSESSION"
|
SessionName = "GOSESSION"
|
||||||
AuthName = "_PANEL_AUTH"
|
AuthName = "_PANEL_AUTH"
|
||||||
|
|||||||
Reference in New Issue
Block a user