修改IP监听地址,包装了一层Write函数
这个提交包含在:
2
Debug.js
2
Debug.js
@ -284,7 +284,7 @@ exports.add={
|
|||||||
var IP = (req.body).split(".");
|
var IP = (req.body).split(".");
|
||||||
IP[2] = "*";
|
IP[2] = "*";
|
||||||
IP[3] = "*";
|
IP[3] = "*";
|
||||||
Core.frame.SendMsgconnect,info,`${IP[0]}.${IP[1]}.${IP[2]}.${IP[3]}`);
|
Core.frame.SendMsg(connect,info,`${IP[0]}.${IP[1]}.${IP[2]}.${IP[3]}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
97
WebUI.js
97
WebUI.js
@ -1,45 +1,32 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
exports.__esModule = true;
|
||||||
if (k2 === undefined) k2 = k;
|
var net = require("net");
|
||||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
var Core = require("./Core");
|
||||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
var fs = require("fs");
|
||||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
||||||
}
|
|
||||||
Object.defineProperty(o, k2, desc);
|
|
||||||
}) : (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
o[k2] = m[k];
|
|
||||||
}));
|
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
||||||
}) : function(o, v) {
|
|
||||||
o["default"] = v;
|
|
||||||
});
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const net = __importStar(require("net"));
|
|
||||||
const Core = __importStar(require("./Core"));
|
|
||||||
const fs = __importStar(require("fs"));
|
|
||||||
var MainConnect;
|
var MainConnect;
|
||||||
var MainGroup;
|
var MainGroup;
|
||||||
var ServerWeb = new net.Server();
|
var ServerWeb = new net.Server();
|
||||||
var MessageCount = 0;
|
var MessageCount = 0;
|
||||||
ServerWeb.on("listening", () => {
|
ServerWeb.on("listening", function () {
|
||||||
process.on("exit", () => {
|
process.on("exit", function () {
|
||||||
ServerWeb.close();
|
ServerWeb.close();
|
||||||
});
|
});
|
||||||
ServerWeb.on("connection", (UserSock) => {
|
ServerWeb.on("connection", function (UserSock) {
|
||||||
|
var Write = (function (str) {
|
||||||
|
if (UserSock.writable) {
|
||||||
|
try {
|
||||||
|
UserSock.write(str);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
// UserSock.end("102");
|
// UserSock.end("102");
|
||||||
var TOC = setTimeout(() => {
|
var TOC = setTimeout(function () {
|
||||||
UserSock.end("102 Timeout");
|
UserSock.end("102 Timeout");
|
||||||
}, 500);
|
}, 500);
|
||||||
UserSock.on("data", (data) => {
|
UserSock.on("data", function (data) {
|
||||||
clearTimeout(TOC);
|
clearTimeout(TOC);
|
||||||
if (data.toString().indexOf(" ") != 0) {
|
if (data.toString().indexOf(" ") != 0) {
|
||||||
var path = data.toString().split(" ");
|
var path = data.toString().split(" ");
|
||||||
@ -47,25 +34,25 @@ ServerWeb.on("listening", () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (path[1] == "/") {
|
if (path[1] == "/") {
|
||||||
fs.readFile("./WebUI.html", (err, data) => {
|
fs.readFile("./WebUI.html", function (err, data) {
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(data.length, "\r\n\r\n"));
|
||||||
UserSock.write(data);
|
Write(data);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (path[1].substring(0, 5) == "/OAC_") {
|
else if (path[1].substring(0, 5) == "/OAC_") {
|
||||||
var Do = path[1].replace("/OAC_", "");
|
var Do = path[1].replace("/OAC_", "");
|
||||||
if (Do == "GETMESSAGE") {
|
if (Do == "GETMESSAGE") {
|
||||||
fs.readFile("./Message.json", (err, data) => {
|
fs.readFile("./Message.json", function (err, data) {
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(data.length, "\r\n\r\n"));
|
||||||
UserSock.write(data);
|
Write(data);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (Do.substring(0, new String("SETMESSAGE_").length) == "SETMESSAGE_") {
|
else if (Do.substring(0, new String("SETMESSAGE_").length) == "SETMESSAGE_") {
|
||||||
var Token = Do.replace("SETMESSAGE_", "");
|
var Token = Do.replace("SETMESSAGE_", "");
|
||||||
var T2 = Token.split("_");
|
var T2 = Token.split("_");
|
||||||
fs.readFile("./Message.json", (err, data) => {
|
fs.readFile("./Message.json", function (err, data) {
|
||||||
var data_obj = JSON.parse(data.toString());
|
var data_obj = JSON.parse(data.toString());
|
||||||
T2[0] = decodeURIComponent(T2[0]);
|
T2[0] = decodeURIComponent(T2[0]);
|
||||||
if (T2[1] == "") {
|
if (T2[1] == "") {
|
||||||
@ -75,17 +62,17 @@ ServerWeb.on("listening", () => {
|
|||||||
else {
|
else {
|
||||||
data_obj[T2[0]] = decodeURIComponent(T2[1]);
|
data_obj[T2[0]] = decodeURIComponent(T2[1]);
|
||||||
}
|
}
|
||||||
fs.writeFile("./Message.json", JSON.stringify(data_obj), (err) => {
|
fs.writeFile("./Message.json", JSON.stringify(data_obj), function (err) {
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String("DONE").length}\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(new String("DONE").length, "\r\n\r\n"));
|
||||||
UserSock.write(new String("DONE").valueOf());
|
Write(new String("DONE").valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (Do == "GETCOUNT") {
|
else if (Do == "GETCOUNT") {
|
||||||
var ret = new String(MessageCount);
|
var ret = new String(MessageCount);
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(new String(ret).length, "\r\nContent-Type:text/html;charset=utf-8\r\n\r\n"));
|
||||||
UserSock.write(ret.valueOf());
|
Write(ret.valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
}
|
}
|
||||||
else if (Do == "RESTART") {
|
else if (Do == "RESTART") {
|
||||||
@ -94,29 +81,29 @@ ServerWeb.on("listening", () => {
|
|||||||
var ret = new String("");
|
var ret = new String("");
|
||||||
if (IsIPv4) {
|
if (IsIPv4) {
|
||||||
ret = new String("DOING!");
|
ret = new String("DOING!");
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(new String(ret).length, "\r\nContent-Type:text/html;charset=utf-8\r\n\r\n"));
|
||||||
UserSock.end(ret.valueOf());
|
UserSock.end(ret.valueOf());
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ret = new String("我们不允许IPv6重启Ai");
|
ret = new String("我们不允许IPv6重启Ai");
|
||||||
UserSock.write(`HTTP/1.1 403 Forbidden\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`);
|
Write("HTTP/1.1 403 Forbidden\r\nContent-Length: ".concat(new String(ret).length, "\r\nContent-Type:text/html;charset=utf-8\r\n\r\n"));
|
||||||
UserSock.end(ret.valueOf());
|
UserSock.end(ret.valueOf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Do == "GETSERVICES") {
|
else if (Do == "GETSERVICES") {
|
||||||
fs.readFile("./MoudelV2.json", (err2, data2) => {
|
fs.readFile("./MoudelV2.json", function (err2, data2) {
|
||||||
var ret = data2;
|
var ret = data2;
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${ret.length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`);
|
Write("HTTP/1.1 200 OK\r\nContent-Length: ".concat(ret.length, "\r\nContent-Type:text/html;charset=utf-8\r\n\r\n"));
|
||||||
UserSock.write(ret);
|
Write(ret);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var data2 = "404";
|
var data2 = "404";
|
||||||
UserSock.write(`HTTP/1.1 404\r\nContent-Length: ${data2.length}\r\n\r\n`);
|
Write("HTTP/1.1 404\r\nContent-Length: ".concat(data2.length, "\r\n\r\n"));
|
||||||
UserSock.write(data2.valueOf());
|
Write(data2.valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,16 +111,16 @@ ServerWeb.on("listening", () => {
|
|||||||
UserSock.end("HTTP/1.1 404");
|
UserSock.end("HTTP/1.1 404");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
UserSock.on("close", () => {
|
UserSock.on("close", function () {
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
UserSock.on("end", () => {
|
UserSock.on("end", function () {
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ServerWeb.listen(8093, "0.0.0.0");
|
ServerWeb.listen(8093, "0.0.0.0");
|
||||||
ServerWeb.listen(8093, "::1");
|
ServerWeb.listen(8093, "::0");
|
||||||
Core.AddListener((connect, Info) => {
|
Core.AddListener(function (connect, Info) {
|
||||||
MessageCount = MessageCount.valueOf() + 1;
|
MessageCount = MessageCount.valueOf() + 1;
|
||||||
});
|
});
|
||||||
|
|||||||
39
WebUI.ts
39
WebUI.ts
@ -10,6 +10,15 @@ ServerWeb.on("listening",()=>{
|
|||||||
ServerWeb.close();
|
ServerWeb.close();
|
||||||
});
|
});
|
||||||
ServerWeb.on("connection",(UserSock)=>{
|
ServerWeb.on("connection",(UserSock)=>{
|
||||||
|
var Write = ((str:string|Buffer)=>{
|
||||||
|
if(UserSock.writable){
|
||||||
|
try{
|
||||||
|
UserSock.write(str)
|
||||||
|
}catch(err){
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
// UserSock.end("102");
|
// UserSock.end("102");
|
||||||
var TOC = setTimeout(()=>{
|
var TOC = setTimeout(()=>{
|
||||||
UserSock.end("102 Timeout")
|
UserSock.end("102 Timeout")
|
||||||
@ -23,16 +32,16 @@ ServerWeb.on("listening",()=>{
|
|||||||
}
|
}
|
||||||
if(path[1]=="/"){
|
if(path[1]=="/"){
|
||||||
fs.readFile("./WebUI.html",(err,data)=>{
|
fs.readFile("./WebUI.html",(err,data)=>{
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
||||||
UserSock.write(data);
|
Write(data);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
}else if(path[1].substring(0,5)=="/OAC_"){
|
}else if(path[1].substring(0,5)=="/OAC_"){
|
||||||
var Do = path[1].replace("/OAC_","");
|
var Do = path[1].replace("/OAC_","");
|
||||||
if(Do == "GETMESSAGE"){
|
if(Do == "GETMESSAGE"){
|
||||||
fs.readFile("./Message.json",(err,data)=>{
|
fs.readFile("./Message.json",(err,data)=>{
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${data.length}\r\n\r\n`);
|
||||||
UserSock.write(data);
|
Write(data);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
}else if(Do.substring(0,new String("SETMESSAGE_").length) == "SETMESSAGE_"){
|
}else if(Do.substring(0,new String("SETMESSAGE_").length) == "SETMESSAGE_"){
|
||||||
@ -49,15 +58,15 @@ ServerWeb.on("listening",()=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFile("./Message.json",JSON.stringify(data_obj),(err)=>{
|
fs.writeFile("./Message.json",JSON.stringify(data_obj),(err)=>{
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String("DONE").length}\r\n\r\n`);
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String("DONE").length}\r\n\r\n`);
|
||||||
UserSock.write(new String("DONE").valueOf());
|
Write(new String("DONE").valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}else if(Do == "GETCOUNT"){
|
}else if(Do == "GETCOUNT"){
|
||||||
var ret = new String(MessageCount);
|
var ret = new String(MessageCount);
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
||||||
UserSock.write(ret.valueOf());
|
Write(ret.valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
}else if(Do == "RESTART"){
|
}else if(Do == "RESTART"){
|
||||||
|
|
||||||
@ -66,26 +75,26 @@ ServerWeb.on("listening",()=>{
|
|||||||
var ret = new String("");
|
var ret = new String("");
|
||||||
if(IsIPv4){
|
if(IsIPv4){
|
||||||
ret = new String("DOING!");
|
ret = new String("DOING!");
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
||||||
UserSock.end(ret.valueOf());
|
UserSock.end(ret.valueOf());
|
||||||
process.exit();
|
process.exit();
|
||||||
}else{
|
}else{
|
||||||
ret = new String("我们不允许IPv6重启Ai");
|
ret = new String("我们不允许IPv6重启Ai");
|
||||||
UserSock.write(`HTTP/1.1 403 Forbidden\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
Write(`HTTP/1.1 403 Forbidden\r\nContent-Length: ${new String(ret).length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
||||||
UserSock.end(ret.valueOf());
|
UserSock.end(ret.valueOf());
|
||||||
}
|
}
|
||||||
}else if(Do == "GETSERVICES"){
|
}else if(Do == "GETSERVICES"){
|
||||||
fs.readFile("./MoudelV2.json",(err2,data2)=>{
|
fs.readFile("./MoudelV2.json",(err2,data2)=>{
|
||||||
var ret = data2;
|
var ret = data2;
|
||||||
UserSock.write(`HTTP/1.1 200 OK\r\nContent-Length: ${ret.length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
Write(`HTTP/1.1 200 OK\r\nContent-Length: ${ret.length}\r\nContent-Type:text/html;charset=utf-8\r\n\r\n`)
|
||||||
UserSock.write(ret);
|
Write(ret);
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
var data2:String ="404";
|
var data2:String ="404";
|
||||||
UserSock.write(`HTTP/1.1 404\r\nContent-Length: ${data2.length}\r\n\r\n`);
|
Write(`HTTP/1.1 404\r\nContent-Length: ${data2.length}\r\n\r\n`);
|
||||||
UserSock.write(data2.valueOf());
|
Write(data2.valueOf());
|
||||||
UserSock.end();
|
UserSock.end();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -101,7 +110,7 @@ ServerWeb.on("listening",()=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
ServerWeb.listen(8093,"0.0.0.0");
|
ServerWeb.listen(8093,"0.0.0.0");
|
||||||
ServerWeb.listen(8093,"::1");
|
ServerWeb.listen(8093,"::0");
|
||||||
Core.AddListener((connect:Core.InfoSocket,Info:Core.InfoType)=>{
|
Core.AddListener((connect:Core.InfoSocket,Info:Core.InfoType)=>{
|
||||||
MessageCount = MessageCount.valueOf() + 1;
|
MessageCount = MessageCount.valueOf() + 1;
|
||||||
})
|
})
|
||||||
在新工单中引用
屏蔽一个用户