代码拉取完成,页面将自动刷新
同步操作将从 AvenirTech 未来科技/AvenirMQ 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//本程序用于管理AvenirMQ 相当于终端控制台
const INI = require('ini');
const os = require('os');
const fs = require('fs');
const libcu = require('libcu');
const readLine = require('readline-sync');
const amq = require('avenirmq');
//具备root权限的签名
const sign = libcu.cipher.AesEncode("AvenirMQ");
async function giveFileName() {
let fileName = "./run.ini"
return fileName;
}
async function readIni(fileName) {
let file = fs.readFileSync(fileName);
var Info = INI.parse(file.toString());
return Info;
}
async function main() {
let ini = await readIni(await giveFileName());
amq.init({
ip:ini.main.ip,
port:ini.main.port,
})
while (1) {
let command = readLine.question('AvenirMQ> ');
let type = command.split(' ');
if (type[0] === 'help' || !type[0]) {
console.log(Usage());
} else if (type[0] === 'addUser') {
if (type.length != 6) {
throw ('bad [addUser] command');
}
//如果是添加用户的话
let name = type[1];
let password = type[2];
let ip = type[3];
let port = type[4];
let key = type[5];
if (!name || !password ||!ip || !port ||!key) {
console.log('lack of params');
continue;
}
let send = {
type:'addUser',
data:{
name,
password:libcu.cipher.AesEncode(password),
ip,
port,
key
}
}
let res = await safeSend(send,'addUser');
console.log(res);
} else if (type[0] === 'deleteUser') {
let name = type[1];
if (!name) {
console.log('lack of name');
continue;
}
let send = {
type:'deleteUser',
data : {
name,
},
}
let res = await safeSend(send,'deleteUser');
console.log(res);
}else if (type[0] === 'updateUser') {
if (type.length != 6) {
throw ('bad [updateUser] command');
}
let name = type[1];
let password = type[2];
let ip = type[3];
let port = type[4];
let key = type[5];
if (!name || !password ||!ip || !port ||!key) {
console.log('lack of params');
continue;
}
let send = {
type:'updateUser',
data:{
name,
password:libcu.cipher.AesEncode(password),
ip,
port,
key
}
}
let res = await safeSend(send,'updateUser');
console.log(res);
}else if (type[0] === 'setKey') {
if(type.length!=3) {
console.log("bad [setKey] command");
continue;
}
let name = type[1];
let key = type[2];
if (!name||!key) {
console.log('lack of name or key');
continue;
}
let send = {
type:'setKey',
data:{
name,
key,
}
}
let res = await safeSend(send,'setKey');
console.log(res);
} else if (type[0] == 'exit') {
process.exit(0);
} else if(type[0] == 'login') {
if(type.length!=3) {
console.log('bad [login] command');
continue;
}
let name = type[1];
let password = type[2];
if(!name || !password) {
console.log('lacf of name or password');
continue;
}
let send = {
type:'login',
data:{
name,
password:libcu.cipher.AesEncode(password),
}
}
let res = await safeSend(send,'login');
console.log(res);
} else if(type[0] == 'userList') {
if(type.length!=1) {
console.log("bad [userList] command");
continue;
}
let send = {
type:'userList',
data:{
}
}
let res = await safeSend(send,'login');
console.log(res);
} else {
console.log("sorry,unknown command");
}
}
return 0;
}
//安全的连接操作
async function safeConnect() {
setTimeout(async () => {
return 'timeout';
}, 3000);
// let sign = await avenirsql.connect();
return sign;
}
//安全的发送操作
async function safeSend(send,type) {
let promise = new Promise(async(resolve,reject)=>{
setTimeout(async () => {
resolve('timeout');
}, 3000);
let res = await amq.asyncSend(send,type);
resolve(res);
})
return promise;
}
function Usage() {
const use = `\t欢迎使用AvenirMQ管理程序
\tlogin [name] [password]: 获得签名
\taddUser [name] [password] [ip] [port] [routingkey]: 新建用户
\tupdateUser [name] [password] [ip] [port] [routingkey]: 更新用户
\tdeleteUser [name]: 删除用户
\tuserList: 获取用户列表
\texit: 退出`;
return use;
}
// function getMessage(res) {
// return res.message ? res.message : res
// }
main();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。