-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
executable file
·85 lines (65 loc) · 1.84 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var http = require('http');
var freedisk = require('freedisk');
var exec = require('child_process').exec;
var fs = require("fs");
var piRoute = require(__dirname+"/piRoute.js");
http.createServer(function (req, res) {
var shutdown = "/shutdown";
var restart = "/restart";
var getfreedisk = "/freedisk";
var staticfile = "png|js|css";
piRoute.init(req,res);
piRoute.staticFiles(staticfile);
piRoute.get(shutdown,function(req,res)
{
res.writeHead(200);
child = exec("shutdown -h now", function (error, stdout, stderr) {
res.end("Shutdown...");
});
res.write('Shutdown...');
});
piRoute.get(restart,function(req,res)
{
res.writeHead(200);
child = exec("reboot", function (error, stdout, stderr) {
res.end("Reboot...");
});
});
piRoute.get(getfreedisk,function(req,res)
{
var disks = [];
freedisk.drivelist(function(error,drives){
if (error !== null) {
console.log(error);
}
else {
var count = 0;
for (var i = 0; i < drives.length; i++) {
var mydrive = drives[i];
freedisk.detail(mydrive,function(error,total,used,free){
if (error !== null) {
console.log(error);
}
else {
var disk = {"name" : mydrive,"total":total,"free":free};
disks.push(disk);
count++;
if(count==drives.length)
{
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(disks));
}
}
});//end of detail
}
}
});
});
piRoute.get("/",function(req,res)
{
res.writeHead(200);
var fileData = fs.readFileSync(__dirname + "/index.html");
res.end(fileData);
});
//piRoute.notfound();
}).listen(1337);