global.fs = require('fs') global.os = require('os') global.mime = require('node-mime'); global.dirconf = null; module.exports.start = function () { String.prototype.replacei = function (search, replace) { var regex = new RegExp(search, "ig"); return this.replace(regex, replace); } global.http = require('http'); http.createServer(function (req, res) { global.res = res; req.url_orig = req.url; if (req.headers["x-forwarded-for"]) { global.address = req.headers["x-forwarded-for"]; } else { global.address = req.connection.remoteAddress } log.verbose("request: " + address + "; " + req.url) if (req.url.startsWith("/@info")) { log.verbose("return info"); file = wwwdata + req.url.slice(6); json = new Object json.file = req.url.slice(6) if (fs.existsSync(file)) { if (fs.lstatSync(file).isDirectory()) { json.type = "inode/directory" json.size = null json.inode = null json.device = null json.mode = null } else { json.type = mime.lookUpType(file.split(".").pop()); // json.type = file.split(".").pop(); json.size = fs.lstatSync(file).size json.inode = fs.lstatSync(file).ino json.device = fs.lstatSync(file).dev json.mode = fs.lstatSync(file).mode } } else { if (json.file.startsWith("/debug")) { json.type = "mpws-special/debuginfo"; json.size = null json.inode = null json.device = null json.mode = null } else if (json.file.startsWith("/@info")) { json.type = "mpws-special/fileinfo"; json.size = null json.inode = null json.device = null json.mode = null } else if (json.file.startsWith("/@json")) { json.type = "mpws-special/fileapi"; json.size = null json.inode = null json.device = null json.mode = null } else { json.type = "error/notfound"; json.size = null json.inode = null json.device = null json.mode = null } } res.writeHead(200, {'Content-Type': 'application/json'}); res.write(JSON.stringify(json)); res.end() return; } if (req.url.startsWith("/@json")) { log.verbose("return json"); file = wwwdata + req.url.slice(6); json = new Object json.file = req.url.slice(6) if (fs.existsSync(file)) { if (fs.lstatSync(file).isDirectory()) { json.type = "inode/directory" json.size = null json.inode = null json.device = null json.mode = null json.lines = null } else { json.type = mime.lookUpType(file.split(".").pop()); json.size = fs.lstatSync(file).size json.inode = fs.lstatSync(file).ino json.device = fs.lstatSync(file).dev json.mode = fs.lstatSync(file).mode json.lines = fs.readFileSync(file).toString().split("\n"); } } else { if (json.file.startsWith("/debug")) { json.type = "mpws-special/debuginfo"; json.size = null json.inode = null json.device = null json.mode = null json.lines = null } else if (json.file.startsWith("/@info")) { json.type = "mpws-special/fileinfo"; json.size = null json.inode = null json.device = null json.mode = null json.lines = null } else if (json.file.startsWith("/@json")) { json.type = "mpws-special/fileapi"; json.size = null json.inode = null json.device = null json.mode = null json.lines = null } else { json.type = "error/notfound"; json.size = null json.inode = null json.device = null json.mode = null json.lines = null } } res.writeHead(200, {'Content-Type': 'application/json'}); res.write(JSON.stringify(json)); res.end() return; } if (req.url == "/debug") { log.verbose("return debug") res.writeHead(200, {'Content-Type': 'application/json'}); var date = new Date(); var hour = date.getHours(); // hour = (hour < 10 ? "0" : "") + hour; var min = date.getMinutes(); // min = (min < 10 ? "0" : "") + min; var sec = date.getSeconds(); // sec = (sec < 10 ? "0" : "") + sec; var year = date.getFullYear(); var month = date.getMonth() + 1; // month = (month < 10 ? "0" : "") + month; var day = date.getDate(); // day = (day < 10 ? "0" : "") + day; debug = { "version": { "server": mpws.version, "kernel": process.version.replace("v", "") }, "date": { "day": day, "month": month, "year": year, "hour": hour, "min": min, "sec": sec }, "server": { "process": { "pid": process.pid, "name": process.title, "priority": os.getPriority(process.pid) }, "software": { "hostname": os.hostname(), "arch": os.arch(), "platform": os.platform(), "release": os.release(), "type": os.type(), "uptime": os.uptime(), "tempfiles": os.tmpdir() }, "hardware": { "cpus": os.cpus(), "network": os.networkInterfaces(), "memory": { "total": os.totalmem(), "free": os.freemem(), "used": os.totalmem() - os.freemem(), "process": process.memoryUsage() } } } } res.write(JSON.stringify(debug)); res.end(); return; } // res.writeHead(200, {'Content-Type': 'text/html'}); // res.write('Node.js says hello!'); // res.end(); frhtml = false; ejs = false; if (req.url.includes(".")) { } else { if (fs.existsSync(wwwdata + req.url + "/index.html")) { req.url = req.url + "/index.html" } else if (fs.existsSync(wwwdata + req.url + "/index.fr.html")) { req.url = req.url + "/index.fr.html" frhtml = true; } else { req.url = req.url + "/index.ejs" ejs = true; } } if (req.url.endsWith('.fr.html')) { frhtml = true; } if (req.url.includes("..")) { if (config.errors_show_trace) { trace = "
Satellite Server - System Backtrace
Server Backtrace:
401F0000 PERMISSION_DENIED
00000001 SERVER_RUNTIME
0000001A HTTP_WEBSERVER
Kernel Backtrace:
Satellite Server - System Backtrace
Server Backtrace:
50A00000 INVALID_DIR_CONF
00000001 SERVER_RUNTIME
0000001A HTTP_WEBSERVER
Kernel Backtrace:
" + err.toString().replace('\n', '
') + "
Satellite Server - System Backtrace
Server Backtrace:
401F0000 PERMISSION_DENIED
00000001 SERVER_RUNTIME
0000001A HTTP_WEBSERVER
Kernel Backtrace:
Satellite Server - System Backtrace
Server Backtrace:
404F0000 FILE_NOT_FOUND
00000001 SERVER_RUNTIME
0000001A HTTP_WEBSERVER
Kernel Backtrace: