-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
93 lines (78 loc) · 2.86 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
86
87
88
89
90
91
92
/*
* Copyright (C) 2014-2015, Opersys inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var express = require("express");
var http = require("http");
var path = require("path");
var spawn = require("child_process").spawn;
var socketio = require("socket.io");
var routes = require("./routes");
var sysinfo = require("./routes/sysinfo");
var icon = require("./routes/icon");
var fs = require("./routes/fs");
var libos = require("./routes/os");
var proc = require("./routes/process");
var app = express();
app.set("env", process.env.ENV || "development");
app.set("port", process.env.PORT || 3000);
app.set("views", path.join(__dirname, "views"));
app.set("json spaces", 0);
app.use(express.favicon());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, "public")));
// development only
if ("development" == app.get("env")) {
app.use(express.logger("dev"));
app.use(express.errorHandler());
}
app.get("/", function (req, res) { res.redirect("/index.html"); });
app.get("/apropos", function (req, res) { res.redirect("/apropos.html"); });
app.get("/sysinfo", sysinfo.sysinfo);
app.get("/meminfo", sysinfo.meminfo);
app.get("/cpuinfo", sysinfo.cpuinfo);
app.get("/icon/:app", icon.get);
app.get("/fs", fs.get);
app.post("/os/kill", libos.kill);
app.get("/process/environ", proc.environ);
app.get("/process/maps", proc.maps);
app.get("/process/files", proc.files);
app.get("/process/memusage", proc.memusage);
app.get("/process/networkconnections", proc.networkconnections);
var server = http.createServer(app);
var ws = socketio.listen(server);
server.listen(app.get('port'), function() {});
ws.of("/logcat").on("connection", function (socket) {
var logcat;
// If we can't execute logcat, the socket will forever remain silent.
logcat = spawn("logcat", ["-v", "time"]).on("error", function() {
console.log("Could not execute logcat");
});
if (logcat) {
logcat.stdout.on("data", function (data) {
socket.emit("logcat", data.toString());
});
socket.on("disconnect", function () {
logcat.kill();
});
}
});
// Handle receiving the "quit" command from the UI.
process.stdin.on("data", function (chunk) {
if (chunk.toString().split("\n")[0].trim().toLowerCase() == "quit")
process.exit();
});