const express = require("express");
const bodyParser = require("body-parser");
const proc = require("child_process");
const request = require("request");
const ip = require("ip");
const manage = require("./manage.js");
const path = require("path");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "public")));
function isValidPath(segment) {
disallowedKeys.forEach(evilWord => {
if (segment.toString().indexOf(evilWord) !== -1) {
app.post("/add", (req, res) => {
if (ip.substr(0, 7) == "::ffff:") {
console.log(`method:${req.method},serverip:${server_ip},ip:${ip}`);
if (ip != "127.0.0.1" && ip != server_ip) {
res.status(403).send("Not Edit from Local!");
if (req.body.userName && req.body.nameVal) {
let username = req.body.userName;
let nameVal = req.body.nameVal;
if (!isValidPath(username) || !isValidPath(nameVal)) {
manage.set(object, username, nameVal);
<a href="/admin">View Admin Page</a>`);
app.get("/admin", (req, res) => {
if (manage.get(object, "username", "guest") === "admin") {
console.log("Current User:" + object.username);
const child = proc.fork(`${__dirname}/public/user.js`, ["admin"]);
child.on("message", body => {
res.status(200).send(body);
child.on("close", (code, signal) => {
console.log(`subproccess ended with ${signal}`);
res.status(403).send("Only Admin Can View this");
app.get("/getContent", (req, res) => {
res.sendfile(`${__dirname}/public/guest.html`);
app.get("/", (req, res) => {
let uri = req.query.url ? req.query.url : "http://127.0.0.1:3000/getContent";
request.get(uri, (err, response, data) => {
if (!err && response.statusCode == 200) {
console.log("Make Server Continue Running");
var object = { username: "guest" };
var server_ip = ip.address();
console.log(`${server_ip} is starting at port 3000`);