-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
62 lines (57 loc) · 1.69 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
require('dotenv').config()
var express = require('express'),
app = express(),
chalk = require('chalk'),
pck = require('./package.json'),
path = require('path'),
argv = process.argv[2],
port = argv || process.env.PORT || 3000,
cron = require('node-cron'),
key = process.env.KEY || process.argv[3] || 'key',
{ exec } = require('child_process');
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
if(argv== '-v' ||argv == '--version'){
console.log( `${pck.version}`)
process.exit(1);
}
else if (argv =='-h'|| argv == '--help') { // checking undifined args
console.log(`
Usage: ${pck.name} <Port> <Key>
`);
}
else if (argv =='-i'|| argv == '--issue') { // checking undifined args
console.log(`
Issues at ${pck.bugs.url}
`);
}
else if (argv =='-a'|| argv == '--author') { // checking undifined args
console.log(`
Author: ${pck.author}
`);
}
else if (argv =='-d'|| argv == '--docs') { // checking undifined args
console.log(`
Docs at ${pck.homepage}
`);}
else{
app.listen(port, () => console.log(chalk.green(`Server running at ${port}`)))
console.log(chalk.green('Your Auth Key : ' + key))
}
app.post('/api/v1', (req, res) => {
if(req.body.key==key){
console.log(chalk.green(Date() + ': Command : ' +req.body.command))
res.send('Sucess')
cron.schedule(req.body.cron, () => {
exec(req.body.command, (err) => {
console.log(chalk.red(Date() + ': exec' + req.ip + ' Command : ' + req.body.command))
if (err) {
console.error(chalk.red(`exec error: ${err}`));
}});
})}
else{
res.status(401).send('Auth Error')
console.log(chalk.red(Date() + ':' + req.ip + ' Auth Error 401'))
}})