2018-06-02 14:05:21 +08:00
|
|
|
|
const {
|
|
|
|
|
WebSocketObserver
|
|
|
|
|
} = require('../../model/WebSocketModel');
|
|
|
|
|
const permssion = require('../../helper/Permission');
|
2018-06-02 15:04:20 +08:00
|
|
|
|
const response = require('../../helper/Response');
|
2018-06-02 14:05:21 +08:00
|
|
|
|
const schedulejob = require('../../helper/Schedule');
|
|
|
|
|
const UUID = require('uuid');
|
2018-06-02 14:16:18 +08:00
|
|
|
|
const tools = require('../../core/tools');
|
2018-06-02 14:05:21 +08:00
|
|
|
|
const serverModel = require('../../model/ServerModel');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let e = {
|
|
|
|
|
servername: "xxxxxx",
|
|
|
|
|
commande: "xxxxxx",
|
|
|
|
|
timestr: "",
|
|
|
|
|
count: 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CreateScheduleJob(obj) {
|
|
|
|
|
let id = tools.randomString(6) + "_" + new Date().getTime();
|
2018-06-02 17:46:14 +08:00
|
|
|
|
let thisServer = serverModel.ServerManager().getServer(obj.servername);
|
2018-06-02 14:05:21 +08:00
|
|
|
|
|
2018-06-02 17:46:14 +08:00
|
|
|
|
schedulejob.createScheduleJobCount(id, obj.time, obj.count, obj.commande, obj.servername);
|
2018-06-02 14:05:21 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//列出计划任务
|
|
|
|
|
WebSocketObserver().listener('schedule/list', (data) => {
|
|
|
|
|
let username = data.WsSession.username;
|
|
|
|
|
let servername = data.body;
|
|
|
|
|
|
|
|
|
|
if (permssion.isCanServer(username, servername)) {
|
|
|
|
|
let thisServer = serverModel.ServerManager().getServer(servername);
|
2018-06-02 15:04:20 +08:00
|
|
|
|
response.wsSend(data.ws, 'schedule/list', {
|
|
|
|
|
username: data.WsSession.username,
|
|
|
|
|
servername: servername,
|
|
|
|
|
schedules: [{
|
|
|
|
|
id: "test_123456",
|
|
|
|
|
count: 0,
|
|
|
|
|
time: "5 * * * * *",
|
|
|
|
|
commande: "__restart__",
|
|
|
|
|
}, {
|
2018-06-02 16:43:36 +08:00
|
|
|
|
id: "test_123457",
|
2018-06-02 15:04:20 +08:00
|
|
|
|
count: 0,
|
2018-06-02 16:43:36 +08:00
|
|
|
|
time: "*/6 * * * * *",
|
|
|
|
|
commande: "kill xxxx",
|
2018-06-02 15:04:20 +08:00
|
|
|
|
}, {
|
2018-06-02 16:43:36 +08:00
|
|
|
|
id: "test_123458",
|
2018-06-02 15:04:20 +08:00
|
|
|
|
count: 0,
|
|
|
|
|
time: "5 * * * * *",
|
2018-06-02 16:43:36 +08:00
|
|
|
|
commande: "stop",
|
2018-06-02 15:04:20 +08:00
|
|
|
|
}]
|
|
|
|
|
});
|
2018-06-02 14:05:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
MCSERVER.log('权限不足!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//创建计划任务
|
|
|
|
|
WebSocketObserver().listener('schedule/create', (data) => {
|
|
|
|
|
let username = data.WsSession.username;
|
|
|
|
|
let obj = JSON.parse(data.body);
|
|
|
|
|
|
|
|
|
|
if (permssion.isCanServer(username, obj.servername || "")) {
|
|
|
|
|
CreateScheduleJob(obj);
|
|
|
|
|
} else {
|
|
|
|
|
MCSERVER.log('权限不足!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//删除计划任务
|
|
|
|
|
WebSocketObserver().listener('schedule/delete', (data) => {
|
|
|
|
|
let username = data.WsSession.username;
|
|
|
|
|
let obj = JSON.parse(data.body);
|
|
|
|
|
|
|
|
|
|
if (permssion.isCanServer(username, obj.servername || "")) {
|
|
|
|
|
schedulejob.deleteScheduleJob(obj.id);
|
|
|
|
|
} else {
|
|
|
|
|
MCSERVER.log('权限不足!2');
|
|
|
|
|
}
|
|
|
|
|
});
|