forked from OpenFPGAduino/Arduinojs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux.js
More file actions
65 lines (53 loc) · 1.61 KB
/
linux.js
File metadata and controls
65 lines (53 loc) · 1.61 KB
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
63
64
65
module.exports = function(app, logger, argv, express) {
logger.info('module linux');
require('shelljs/global');
var router = express.Router();
if (!which('git')) {
echo('Sorry, this script requires git');
//exit(1);
}
ls('*.js').forEach(function(file) {
console.log(file)
});
router.get('/shell/list', function(req, res) {
var shell = require('shelljs');
var cmdlist = [];
for (cmd in shell) {
cmdlist.push(cmd);
}
res.json(cmdlist);
});
router.post('/shell/cmd', function(req, res) {
var cmd = req.body.cmd;
var opt = req.body.opt;
var shell = require('shelljs');
shell[cmd](opt);
res.json({
message: 'call linux shell command!'
});
});
router.post('/call', function(req, res) {
var ffi = require('ffi');
var libm = ffi.Library('libm', {
'ceil': ['double', ['double']]
});
console.log(libm.ceil(1.5)); // 2
// You can also access just functions in the current process by passing a null
var current = ffi.Library(null, {
'atoi': ['int', ['string']]
});
console.log(current.atoi('1234')); // 1234
res.json({
message: 'call linux lib!'
});
});
router.get('/reboot', function(req, res) {
p.exec('sudo reboot',
function(error, stdout, stderr) {
console.log("reboot");
debuginf(stdout);
});
res.json("System rebooting");
});
app.use('/linux', router);
}