add-config-edit
This commit is contained in:
378
ejs/manage.ejs
378
ejs/manage.ejs
@@ -137,154 +137,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-4 col-md-6 mb-4">
|
||||
<div class="col-xl-8 col-md-6 mb-4">
|
||||
|
||||
<div class="card shadow" style="margin-top:1.5rem;border-radius:10px">
|
||||
<div class="card-body" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<span>管理员账号:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="ADMIN_USERNAME">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>管理员密码:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" id="ADMIN_PASSWORD">
|
||||
</td>
|
||||
<tr>
|
||||
<td>
|
||||
<span>离线模式:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" id="OFFLINE_MODE">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>允许自助注册:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" id="ALLOW_REGISTER">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>允许离线数据:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" id="ALLOW_HOOK">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>HTTP 端口:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" id="MIXIO_HTTP_PORT">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>HTTPS 端口:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" id="MIXIO_HTTPS_PORT">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>MQTT 端口:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" id="MIXIO_MQTT_PORT">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>WS 端口:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" id="MIXIO_WS_PORT">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>WSS 端口:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" id="MIXIO_WSS_PORT">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>SSL证书私钥:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="HTTPS_PRIVATE_PEM">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>SSL证书公钥:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="HTTPS_CRT_FILE">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>单用户最大项目数:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="MAX_PROJECT_NUM_PER_USER">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>单用户最大消息数:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="MAX_MESSAGE_PER_USER">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>消息频率限制(次/秒):</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="MAX_MESSAGE_PER_SECOND">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>百度地图开发者AK(客户端应用):</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="BAIDU_MAP_AK">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>百度地图开发者AK(服务端应用):</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="BAIDU_MAP_SERVER_AK">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span>百度统计链接AK:</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="BAIDU_STAT_LINK">
|
||||
</td>
|
||||
</tr>
|
||||
<table id="configTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="30%">配置项</th>
|
||||
<th scope="col" width="30%">含义</th>
|
||||
<th scope="col" width="10%">数据类型</th>
|
||||
<th scope="col" width="30%">值</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="btn btn-lg btn-success" style="margin-top:20px;" onclick="saveAndRestart()" id="saveAndRestart"><i class="fa fa-check"></i> 保存设置并重新启动</button>
|
||||
</div>
|
||||
@@ -343,6 +211,61 @@
|
||||
td{
|
||||
min-height: 30px;
|
||||
}
|
||||
table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
th {
|
||||
background-color: #2c3e50;
|
||||
color: white;
|
||||
font-weight: 500;
|
||||
}
|
||||
th:first-child {
|
||||
border-top-left-radius: 8px;
|
||||
}
|
||||
th:last-child {
|
||||
border-top-right-radius: 8px;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
tr:hover {
|
||||
background-color: #e8f4fc;
|
||||
}
|
||||
td, th {
|
||||
padding: 12px 15px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 25px;
|
||||
}
|
||||
.badge-type {
|
||||
font-size: 0.8em;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.badge-string {
|
||||
background-color: #3498db;
|
||||
}
|
||||
.badge-number {
|
||||
background-color: #2ecc71;
|
||||
}
|
||||
.badge-boolean {
|
||||
background-color: #e74c3c;
|
||||
}
|
||||
.form-control:focus, .form-select:focus {
|
||||
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
|
||||
border-color: #3498db;
|
||||
}
|
||||
.table-responsive {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var clearMessage = function(userName){
|
||||
@@ -366,24 +289,7 @@
|
||||
setInterval(() => {
|
||||
$("#time").html(new Date().toLocaleTimeString())
|
||||
}, 1000);
|
||||
var MIXIO_HTTP_PORT = "<%=configs["MIXIO_HTTP_PORT"]%>"
|
||||
var MIXIO_HTTPS_PORT = "<%=configs["MIXIO_HTTPS_PORT"]%>"
|
||||
var MIXIO_MQTT_PORT = "<%=configs["MIXIO_MQTT_PORT"]%>"
|
||||
var MIXIO_WS_PORT = "<%=configs["MIXIO_WS_PORT"]%>"
|
||||
var MIXIO_WSS_PORT = "<%=configs["MIXIO_WSS_PORT"]%>"
|
||||
var HTTPS_PRIVATE_PEM = "<%=configs["HTTPS_PRIVATE_PEM"]%>"
|
||||
var HTTPS_CRT_FILE = "<%=configs["HTTPS_CRT_FILE"]%>"
|
||||
var MAX_PROJECT_NUM_PER_USER = "<%=configs["MAX_PROJECT_NUM_PER_USER"]%>"
|
||||
var MAX_MESSAGE_PER_USER = "<%=configs["MAX_MESSAGE_PER_USER"]%>"
|
||||
var MAX_MESSAGE_PER_SECOND= "<%=configs["MAX_MESSAGE_PER_SECOND"]%>"
|
||||
var ALLOW_REGISTER = <%=configs["ALLOW_REGISTER"]%>
|
||||
var ALLOW_HOOK = <%=configs["ALLOW_HOOK"]%>
|
||||
var OFFLINE_MODE = <%=configs["OFFLINE_MODE"]%>
|
||||
var BAIDU_MAP_AK = "<%=configs["BAIDU_MAP_AK"]%>"
|
||||
var BAIDU_MAP_SERVER_AK = "<%=configs["BAIDU_MAP_SERVER_AK"]%>"
|
||||
var BAIDU_STAT_LINK = "<%=configs["BAIDU_STAT_LINK"]%>"
|
||||
var ADMIN_USERNAME = "<%=configs["ADMIN_USERNAME"]%>"
|
||||
var ADMIN_PASSWORD = "<%=configs["ADMIN_PASSWORD"]%>"
|
||||
var configs = JSON.parse(stringendecoder.decodeHtml("<%=configs%>"))
|
||||
$("#OFFLINE_MODE").bind('change',function(){
|
||||
if($("#OFFLINE_MODE").prop("checked"))
|
||||
{
|
||||
@@ -397,59 +303,110 @@
|
||||
}
|
||||
})
|
||||
var loadConfig = function(){
|
||||
$("#MIXIO_HTTP_PORT").val(MIXIO_HTTP_PORT)
|
||||
$("#MIXIO_HTTPS_PORT").val(MIXIO_HTTPS_PORT)
|
||||
$("#MIXIO_MQTT_PORT").val(MIXIO_MQTT_PORT)
|
||||
$("#MIXIO_WS_PORT").val(MIXIO_WS_PORT)
|
||||
$("#MIXIO_WSS_PORT").val(MIXIO_WSS_PORT)
|
||||
$("#HTTPS_PRIVATE_PEM").val(HTTPS_PRIVATE_PEM)
|
||||
$("#HTTPS_CRT_FILE").val(HTTPS_CRT_FILE)
|
||||
$("#ALLOW_REGISTER").prop("checked",ALLOW_REGISTER)
|
||||
$("#ALLOW_HOOK").prop("checked",ALLOW_HOOK)
|
||||
$("#OFFLINE_MODE").prop("checked",OFFLINE_MODE)
|
||||
$("#BAIDU_MAP_AK").val(BAIDU_MAP_AK)
|
||||
$("#BAIDU_MAP_SERVER_AK").val(BAIDU_MAP_SERVER_AK)
|
||||
$("#MAX_PROJECT_NUM_PER_USER").val(MAX_PROJECT_NUM_PER_USER)
|
||||
$("#MAX_MESSAGE_PER_USER").val(MAX_MESSAGE_PER_USER)
|
||||
$("#MAX_MESSAGE_PER_SECOND").val(MAX_MESSAGE_PER_SECOND)
|
||||
$("#ADMIN_USERNAME").val(ADMIN_USERNAME)
|
||||
$("#ADMIN_PASSWORD").val(ADMIN_PASSWORD)
|
||||
$("#BAIDU_STAT_LINK").val(BAIDU_STAT_LINK)
|
||||
if($("#OFFLINE_MODE").prop("checked"))
|
||||
{
|
||||
$("#BAIDU_MAP_AK").attr("disabled","true")
|
||||
$("#BAIDU_MAP_SERVER_AK").attr("disabled","true")
|
||||
var mapping = {
|
||||
"MIXIO_HTTP_PORT": "HTTP端口",
|
||||
"MIXIO_HTTPS_PORT": "HTTPS端口",
|
||||
"HTTPS_PRIVATE_PEM": "私钥链接(本地或在线地址)",
|
||||
"HTTPS_CRT_FILE": "证书链接(本地或在线地址)",
|
||||
"MIXIO_MQTT_PORT": "MQTT端口",
|
||||
"MIXIO_WS_PORT": "MQTT-ws端口",
|
||||
"MIXIO_WSS_PORT": "MQTT-wss端口",
|
||||
"MAX_PROJECT_NUM_PER_USER": "用户的最大项目数",
|
||||
"MAX_MESSAGE_PER_USER": "用户的最大离线消息存储数",
|
||||
"MAX_MESSAGE_PER_SECOND": "用户每秒的最大消息数",
|
||||
"ALLOW_REGISTER": "是否允许自主注册",
|
||||
"ALLOW_HOOK": "是否允许离线存储消息",
|
||||
"OFFLINE_MODE": "是否禁用天气/地图数据",
|
||||
"BAIDU_MAP_AK": "百度地图客户端应用AK",
|
||||
"BAIDU_MAP_SERVER_AK": "百度地图服务端应用AK",
|
||||
"TENCENT_MAP_KEY": "腾讯地图key",
|
||||
"BAIDU_STAT_LINK": "百度统计链接",
|
||||
"ADMIN_USERNAME": "管理后台用户名",
|
||||
"ADMIN_PASSWORD": "管理后台密码",
|
||||
"STORAGE_ENGINE": "数据库引擎",
|
||||
"MYSQL_HOST": "mysql地址",
|
||||
"MYSQL_PORT": "mysql端口",
|
||||
"MYSQL_USER": "mysql用户名",
|
||||
"MYSQL_PASS": "mysql密码",
|
||||
"MYSQL_DB": "mysql数据库名",
|
||||
"FOOTER": "显示在首页的备案信息"
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#BAIDU_MAP_AK").removeAttr("disabled")
|
||||
$("#BAIDU_MAP_SERVER_AK").removeAttr("disabled")
|
||||
const tbody = document.querySelector('#configTable tbody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
for (const [key, value] of Object.entries(configs)) {
|
||||
const tr = document.createElement('tr');
|
||||
|
||||
// 配置名
|
||||
const tdKey = document.createElement('td');
|
||||
tdKey.textContent = key;
|
||||
const tdName = document.createElement('td');
|
||||
tdName.textContent = mapping[key];
|
||||
|
||||
// 数据类型
|
||||
const tdType = document.createElement('td');
|
||||
const type = typeof value;
|
||||
const badge = document.createElement('span');
|
||||
badge.className = `badge badge-type badge-${type}`;
|
||||
badge.textContent = type;
|
||||
tdType.appendChild(badge);
|
||||
|
||||
// 配置值
|
||||
const tdValue = document.createElement('td');
|
||||
let inputElement;
|
||||
|
||||
if (type === 'boolean') {
|
||||
inputElement = document.createElement('select');
|
||||
inputElement.className = 'form-control';
|
||||
inputElement.innerHTML = `
|
||||
<option value="true" ${value ? 'selected' : ''}>是 (true)</option>
|
||||
<option value="false" ${!value ? 'selected' : ''}>否 (false)</option>
|
||||
`;
|
||||
} else if (type === 'number') {
|
||||
inputElement = document.createElement('input');
|
||||
inputElement.type = 'number';
|
||||
inputElement.className = 'form-control';
|
||||
inputElement.value = value;
|
||||
inputElement.step = Number.isInteger(value) ? '1' : '0.01';
|
||||
} else {
|
||||
console.log(key)
|
||||
inputElement = document.createElement('input');
|
||||
inputElement.type = (mapping[key].indexOf('密码')==-1?'text':'password');
|
||||
inputElement.className = 'form-control';
|
||||
inputElement.value = value;
|
||||
}
|
||||
inputElement.setAttribute('data-key', key);
|
||||
tdValue.appendChild(inputElement);
|
||||
tr.appendChild(tdKey);
|
||||
tr.appendChild(tdName);
|
||||
tr.appendChild(tdType);
|
||||
tr.appendChild(tdValue);
|
||||
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
|
||||
}
|
||||
loadConfig()
|
||||
|
||||
|
||||
var saveAndRestart = function(){
|
||||
var modald = showmodaltext("<div style='text-align:center'><i class='fa fa-spin fa-cog' style='font-size:2rem;color:#4e73df'></i><p style='margin-top:6px;margin-bottom:0;color:#4e73df;font-size:1rem;font-weight:bold'>"+JSLang[lang].loading2+"</p></div>")
|
||||
configs = {}
|
||||
configs["MIXIO_HTTP_PORT"] = parseInt($("#MIXIO_HTTP_PORT").val())
|
||||
configs["MIXIO_HTTPS_PORT"] = parseInt($("#MIXIO_HTTPS_PORT").val())
|
||||
configs["MIXIO_MQTT_PORT"] = parseInt($("#MIXIO_MQTT_PORT").val())
|
||||
configs["MIXIO_WS_PORT"] = parseInt($("#MIXIO_WS_PORT").val())
|
||||
configs["MIXIO_WSS_PORT"] = parseInt($("#MIXIO_WSS_PORT").val())
|
||||
configs["HTTPS_PRIVATE_PEM"] = $("#HTTPS_PRIVATE_PEM").val()
|
||||
configs["HTTPS_CRT_FILE"] = $("#HTTPS_CRT_FILE").val()
|
||||
configs["MAX_PROJECT_NUM_PER_USER"] = parseInt($("#MAX_PROJECT_NUM_PER_USER").val())
|
||||
configs["MAX_MESSAGE_PER_USER"] = parseInt($("#MAX_MESSAGE_PER_USER").val())
|
||||
configs["MAX_MESSAGE_PER_SECOND"] = parseInt($("#MAX_MESSAGE_PER_SECOND").val())
|
||||
configs["ALLOW_REGISTER"] = $("#ALLOW_REGISTER").prop("checked")
|
||||
configs["ALLOW_HOOK"] = $("#ALLOW_HOOK").prop("checked")
|
||||
configs["OFFLINE_MODE"] = $("#OFFLINE_MODE").prop("checked")
|
||||
configs["BAIDU_MAP_AK"] = $("#BAIDU_MAP_AK").val()
|
||||
configs["BAIDU_MAP_SERVER_AK"] = $("#BAIDU_MAP_SERVER_AK").val()
|
||||
configs["ADMIN_USERNAME"] = $("#ADMIN_USERNAME").val()
|
||||
configs["ADMIN_PASSWORD"] = $("#ADMIN_PASSWORD").val()
|
||||
configs["BAIDU_STAT_LINK"] = $("#BAIDU_STAT_LINK").val()
|
||||
const inputs = document.querySelectorAll('#configTable input, #configTable select');
|
||||
configs = {};
|
||||
|
||||
inputs.forEach(input => {
|
||||
const key = input.getAttribute('data-key');
|
||||
const originalType = input.getAttribute('type');
|
||||
|
||||
if (originalType === 'text' || originalType === 'password') {
|
||||
configs[key] = input.value;
|
||||
} else if (originalType === 'number') {
|
||||
configs[key] = Number(input.value);
|
||||
} else {
|
||||
configs[key] = input.value === 'true'
|
||||
}
|
||||
});
|
||||
console.log(configs)
|
||||
$.get('/saveAndRestart',{'configs':JSON.stringify(configs,null,2)},function(res){
|
||||
if(res=="1")
|
||||
{
|
||||
@@ -538,7 +495,10 @@
|
||||
window.location.reload()
|
||||
}
|
||||
, 10000)
|
||||
alert("更新已完成,请手动重启服务器!")
|
||||
alert("更新已完成,请务必手动重启MIXIO服务,请务必手动重启MIXIO服务,如果是支持自动启动,那么请直接重启服务器机器即可!!!")
|
||||
}
|
||||
else{
|
||||
alert("更新已完成!")
|
||||
}
|
||||
add_text('5秒后自动退出...');
|
||||
setTimeout(function(){
|
||||
|
||||
@@ -9,7 +9,7 @@ function showmodaltext(text) {
|
||||
return d
|
||||
}
|
||||
$(function() {
|
||||
$("#admin").attr("href", "http://" + window.location.href.split("//")[1].split(":")[0].replace("/", "") + ":18084")
|
||||
$("#admin").attr("href", "https://" + window.location.href.split("//")[1].split(":")[0].replace("/", "") + ":18084")
|
||||
fullHeight = $("#cd").height() + "px"
|
||||
halfHeight = "calc( " + ($("#cd").height() - $("#ref1").height() - $("#reset_text").height() - 10) + "px - 1rem)"
|
||||
if (window.screen.width < 800)
|
||||
|
||||
188
mixio.js
188
mixio.js
@@ -1,4 +1,4 @@
|
||||
var VERSION = "1.10.5.0906"
|
||||
var VERSION = "1.10.5.0907"
|
||||
require('events').EventEmitter.defaultMaxListeners = 50;
|
||||
const extract = require('extract-zip')
|
||||
defaultCrt =
|
||||
@@ -56,7 +56,6 @@ HKqIhewfd473iyVbGW5PfCPXEH4oJI5NLbd2MvUJPi8oSHupmc+JbkD8n2uMU7s3
|
||||
mUGpI4CFOgtRwpo9KRebaqfq
|
||||
-----END PRIVATE KEY-----
|
||||
`
|
||||
|
||||
// change pwd to src
|
||||
if (process.argv[0].indexOf("node") != -1) {
|
||||
// exec from source
|
||||
@@ -110,7 +109,28 @@ var globalQPSControl = {}
|
||||
const os = require('os');
|
||||
const arch = os.arch(); // 或者 process.arch
|
||||
// 获取操作系统平台(如win32, linux, darwin)
|
||||
function isOpenWrt() {
|
||||
try {
|
||||
// 检查 /etc/openwrt_release 文件是否存在
|
||||
fs.accessSync('/etc/openwrt_release');
|
||||
return true;
|
||||
} catch (e) {
|
||||
// 如果文件不存在,再检查 /etc/openwrt_version
|
||||
try {
|
||||
fs.accessSync('/etc/openwrt_version');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const platform = os.platform(); // 或者 process.platform
|
||||
if(isOpenWrt())
|
||||
{
|
||||
platform = "openwrt"
|
||||
}
|
||||
|
||||
const platformString = `${arch}-${platform}`;
|
||||
|
||||
function init(cb) {
|
||||
@@ -344,6 +364,84 @@ stringendecoder = function() {
|
||||
stringendecoder.call(stringendecoder)
|
||||
|
||||
async function daemon_start() {
|
||||
var keyPath = HTTPS_PRIVATE_PEM
|
||||
var crtPath = HTTPS_CRT_FILE
|
||||
var privateKey = ""
|
||||
var certificate = ""
|
||||
if (keyPath.indexOf("http") == 0) {
|
||||
try {
|
||||
var privateKeyFileName = keyPath.split("/").pop()
|
||||
console.log("[INFO] Downloading private key from", keyPath)
|
||||
var filePath = "config/certs/" + privateKeyFileName
|
||||
var resp = await axios.get(keyPath, { timeout: 5000 })
|
||||
body = resp.data
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
fs.writeFileSync(filePath, body, 'utf8')
|
||||
privateKey = fs.readFileSync(filePath, 'utf8')
|
||||
console.log("[INFO] Private key downloaded to", filePath)
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to download private key from", keyPath)
|
||||
if (fs.existsSync(filePath)) {
|
||||
console.log("[INFO] Using existing private key with the same file name")
|
||||
privateKey = fs.readFileSync(filePath, 'utf8')
|
||||
} else {
|
||||
console.log("[INFO] Falling back to default private key")
|
||||
privateKey = defaultPem
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fs.existsSync(keyPath)) {
|
||||
privateKey = fs.readFileSync(keyPath, 'utf8')
|
||||
} else {
|
||||
console.log("[ERROR] Private key path not found")
|
||||
console.log("[INFO] Falling back to default private key")
|
||||
privateKey = defaultPem
|
||||
}
|
||||
}
|
||||
if (crtPath.indexOf("http") == 0) {
|
||||
try {
|
||||
var crtFileName = crtPath.split("/").pop()
|
||||
console.log("[INFO] Downloading certificate from", crtPath)
|
||||
var filePath = "config/certs/" + crtFileName
|
||||
|
||||
var resp = await axios.get(crtPath, { timeout: 5000 })
|
||||
body = resp.data
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
fs.writeFileSync(filePath, body, 'utf8')
|
||||
certificate = fs.readFileSync(filePath, 'utf8')
|
||||
console.log("[INFO] Certificate downloaded to", filePath)
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to download certificate from", crtPath)
|
||||
if (fs.existsSync(filePath)) {
|
||||
console.log("[INFO] Using existing certificate with the same file name")
|
||||
certificate = fs.readFileSync(filePath, 'utf8')
|
||||
} else {
|
||||
console.log("[INFO] Falling back to default certificate")
|
||||
certificate = defaultCrt
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fs.existsSync(crtPath)) {
|
||||
certificate = fs.readFileSync(crtPath, 'utf8')
|
||||
} else {
|
||||
console.log("[ERROR] Certificate path not found")
|
||||
console.log("[INFO] Falling back to default certificate")
|
||||
certificate = defaultCrt
|
||||
}
|
||||
}
|
||||
|
||||
credentials = {
|
||||
key: privateKey,
|
||||
cert: certificate
|
||||
};
|
||||
|
||||
var chainPath = "config/certs/chain.crt"
|
||||
if (fs.existsSync(chainPath))
|
||||
credentials['ca'] = fs.readFileSync(chainPath, 'utf8')
|
||||
var app = express();
|
||||
app.use(bodyParser.json({
|
||||
limit: '50mb'
|
||||
@@ -424,7 +522,7 @@ async function daemon_start() {
|
||||
app.get('/admin', function(req, res) {
|
||||
if (req.session.admin) {
|
||||
ejs.renderFile(__dirname + '/ejs/manage.ejs', {
|
||||
'configs': configs,
|
||||
'configs': JSON.stringify(configs),
|
||||
'platform': platformString,
|
||||
'status': serverStatus ? "运行中" : "已暂停",
|
||||
'version': VERSION,
|
||||
@@ -808,94 +906,14 @@ del "%~f0"`;
|
||||
app.use('/icons', express.static(path.join(__dirname, 'icons')));
|
||||
|
||||
app.use('/documentation', express.static(path.join(__dirname, 'documentation')));
|
||||
app.listen(18084, function() {
|
||||
backServer = https.createServer(credentials, app)
|
||||
backServer.listen(18084, function() {
|
||||
console.log("[INFO] MixIO Admin server listening on port", 18084)
|
||||
})
|
||||
}
|
||||
|
||||
var mixioServer = async function() {
|
||||
var keyPath = HTTPS_PRIVATE_PEM
|
||||
var crtPath = HTTPS_CRT_FILE
|
||||
var privateKey = ""
|
||||
var certificate = ""
|
||||
if (keyPath.indexOf("http") == 0) {
|
||||
try {
|
||||
var privateKeyFileName = keyPath.split("/").pop()
|
||||
console.log("[INFO] Downloading private key from", keyPath)
|
||||
var filePath = "config/certs/" + privateKeyFileName
|
||||
// 如果存在就覆盖
|
||||
|
||||
// 下载文件
|
||||
var resp = await axios.get(keyPath, { timeout: 5000 })
|
||||
body = resp.data
|
||||
// 不存在就创建
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
fs.writeFileSync(filePath, body, 'utf8')
|
||||
privateKey = fs.readFileSync(filePath, 'utf8')
|
||||
console.log("[INFO] Private key downloaded to", filePath)
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to download private key from", keyPath)
|
||||
if (fs.existsSync(filePath)) {
|
||||
console.log("[INFO] Using existing private key with the same file name")
|
||||
privateKey = fs.readFileSync(filePath, 'utf8')
|
||||
} else {
|
||||
console.log("[INFO] Falling back to default private key")
|
||||
privateKey = defaultPem
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fs.existsSync(keyPath)) {
|
||||
privateKey = fs.readFileSync(keyPath, 'utf8')
|
||||
} else {
|
||||
console.log("[ERROR] Private key path not found")
|
||||
console.log("[INFO] Falling back to default private key")
|
||||
privateKey = defaultPem
|
||||
}
|
||||
}
|
||||
if (crtPath.indexOf("http") == 0) {
|
||||
try {
|
||||
var crtFileName = crtPath.split("/").pop()
|
||||
console.log("[INFO] Downloading certificate from", crtPath)
|
||||
var filePath = "config/certs/" + crtFileName
|
||||
|
||||
var resp = await axios.get(crtPath, { timeout: 5000 })
|
||||
body = resp.data
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
fs.writeFileSync(filePath, body, 'utf8')
|
||||
certificate = fs.readFileSync(filePath, 'utf8')
|
||||
console.log("[INFO] Certificate downloaded to", filePath)
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to download certificate from", crtPath)
|
||||
if (fs.existsSync(filePath)) {
|
||||
console.log("[INFO] Using existing certificate with the same file name")
|
||||
certificate = fs.readFileSync(filePath, 'utf8')
|
||||
} else {
|
||||
console.log("[INFO] Falling back to default certificate")
|
||||
certificate = defaultCrt
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fs.existsSync(crtPath)) {
|
||||
certificate = fs.readFileSync(crtPath, 'utf8')
|
||||
} else {
|
||||
console.log("[ERROR] Certificate path not found")
|
||||
console.log("[INFO] Falling back to default certificate")
|
||||
certificate = defaultCrt
|
||||
}
|
||||
}
|
||||
|
||||
var credentials = {
|
||||
key: privateKey,
|
||||
cert: certificate
|
||||
};
|
||||
|
||||
var chainPath = "config/certs/chain.crt"
|
||||
if (fs.existsSync(chainPath))
|
||||
credentials['ca'] = fs.readFileSync(chainPath, 'utf8')
|
||||
|
||||
aedes = aedesmodule()
|
||||
const httpServer = http.createServer()
|
||||
|
||||
Reference in New Issue
Block a user