Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b97548f24 |
@@ -1,10 +0,0 @@
|
|||||||
node_modules
|
|
||||||
npm-debug.log
|
|
||||||
.git
|
|
||||||
.gitignore
|
|
||||||
.env
|
|
||||||
*.md
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
cookiesecret.txt
|
|
||||||
mysql_password.txt
|
|
||||||
@@ -8,4 +8,3 @@ avatars/*
|
|||||||
etc/*
|
etc/*
|
||||||
*newrelic*
|
*newrelic*
|
||||||
user_uploads/*
|
user_uploads/*
|
||||||
swagger-api.json
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
FROM node:slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package files
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
# Copy application code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Expose ports
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
# Start the application
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# IPost
|
# IPost
|
||||||
IPost, formerly known as "authwebsite" is a chatting platform that also server as a gateway for me to have authentication for my other projects.
|
IPost, formerly known as "authwebsite" is a chatting platform that mainly has one thing in mind: privacy.
|
||||||
You can visit IPost under https://ipost.rocks
|
You can visit IPost under https://ipost.rocks
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
services:
|
|
||||||
app:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- "23080:80"
|
|
||||||
environment:
|
|
||||||
- MYSQL_HOST=db
|
|
||||||
- MYSQL_USER=ipost
|
|
||||||
- MYSQL_PASSWORD=ipost_password
|
|
||||||
- MYSQL_DATABASE=ipost
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
volumes:
|
|
||||||
- ./logs:/app/logs
|
|
||||||
- ./server_config.json:/app/server_config.json
|
|
||||||
- ./cookiesecret.txt:/app/cookiesecret.txt
|
|
||||||
- ./mysql_password.txt:/app/mysql_password.txt
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: mysql:8.0
|
|
||||||
environment:
|
|
||||||
- MYSQL_ROOT_PASSWORD=root_password
|
|
||||||
- MYSQL_DATABASE=ipost
|
|
||||||
- MYSQL_USER=ipost
|
|
||||||
- MYSQL_PASSWORD=ipost_password
|
|
||||||
volumes:
|
|
||||||
- mysql_data:/var/lib/mysql
|
|
||||||
- ./createSchema.sql:/docker-entrypoint-initdb.d/createSchema.sql
|
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mysql_data:
|
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
403: login error (no cookie)
|
403: login error (no cookie)
|
||||||
404: invalid url / not found
|
404: invalid url / not found
|
||||||
410-419: argument/data error
|
410-419: argument/data error
|
||||||
420: invalid authentication object
|
420: invalid authetication object
|
||||||
429: ratelimit
|
429: ratelimit
|
||||||
|
|
||||||
500: server error
|
500: server error
|
||||||
+2
-2
@@ -56,9 +56,9 @@ const cape = m => unes[m];
|
|||||||
const unescape = un => replace.call(un, es, cape);
|
const unescape = un => replace.call(un, es, cape);
|
||||||
|
|
||||||
function escape_special(str) {
|
function escape_special(str) {
|
||||||
return str.replace(/\\/g,"\\\\").replace(/`/g,"\\`");
|
return str.replace(/\\/g,"\\\\").replace(/`/g,"\\`")
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescape_special(str) {
|
function unescape_special(str) {
|
||||||
return str.replace(/\\\\/g,"\\").replace(/\\`/,"`");
|
return str.replace(/\\\\/g,"\\").replace(/\\`/,"`")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
const warn_messages = [
|
const warn_messages = [
|
||||||
["%cDo not paste any text in here","background: red; color: yellow; font-size: x-large"],
|
["%cDo not paste any text in here","background: red; color: yellow; font-size: x-large"],
|
||||||
["Pasting anything in here may give others access to your account."]
|
["Pasting anything in here may give others access to your account.",""]
|
||||||
]
|
]
|
||||||
function warnmessage() {
|
function warnmessage() {
|
||||||
for (let message of warn_messages) {
|
for (let message of warn_messages) {
|
||||||
|
|||||||
Generated
+2632
-1757
File diff suppressed because it is too large
Load Diff
+17
-17
@@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^2.2",
|
"body-parser": "^1.20.1",
|
||||||
"clean-css": "^5.3",
|
"clean-css": "^5.3.2",
|
||||||
"compression": "^1.8",
|
"compression": "^1.7.4",
|
||||||
"cookie-parser": "^1.4",
|
"cookie-parser": "^1.4.6",
|
||||||
"ejs": "^3.1",
|
"ejs": "^3.1.8",
|
||||||
"express": "^5.1",
|
"express": "^4.18.2",
|
||||||
"express-fileupload": "^1.5",
|
"express-fileupload": "^1.3.1",
|
||||||
"express-useragent": "^1.0",
|
"express-useragent": "^1.0.15",
|
||||||
"hcaptcha": "^0.2",
|
"hcaptcha": "^0.1.1",
|
||||||
"html-minifier-terser": "^7.2.0",
|
"html-minifier-terser": "^7.1.0",
|
||||||
"lru-cache": "^11.1",
|
"lru-cache": "^7.14.1",
|
||||||
"mysql2": "^3.14",
|
"mysql2": "^3.1.2",
|
||||||
"sharp": "^0.34",
|
"newrelic": "^9.8.1",
|
||||||
"swagger-autogen": "^2.23",
|
"sharp": "^0.31.3",
|
||||||
"uglify-js": "^3.19",
|
"spdy": "^4.0.2",
|
||||||
|
"uglify-js": "^3.17.4",
|
||||||
"unsafe_encrypt": "^1.0.4",
|
"unsafe_encrypt": "^1.0.4",
|
||||||
"ws": "^8.13.0",
|
"ws": "^8.12.0"
|
||||||
"cookie-signature": "^1.2.2"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
|
|||||||
Generated
-1474
File diff suppressed because it is too large
Load Diff
@@ -1,2 +0,0 @@
|
|||||||
onlyBuiltDependencies:
|
|
||||||
- sharp
|
|
||||||
+50
-47
@@ -1,41 +1,39 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { SHA256 } from "../../extra_modules/SHA.js";
|
import {SHA256} from "../../extra_modules/SHA.js";
|
||||||
import { unsign } from "../../extra_modules/unsign.js";
|
import {unsign} from "../../extra_modules/unsign.js";
|
||||||
const config = JSON.parse(fs.readFileSync("server_config.json"));
|
const config = JSON.parse(fs.readFileSync("server_config.json"));
|
||||||
const HASHES_DB = config.cookies.server_hashes;
|
const HASHES_DB = config.cookies.server_hashes;
|
||||||
const HASHES_COOKIE = config.cookies.client_hashes;
|
const HASHES_COOKIE = config.cookies.client_hashes;
|
||||||
const HASHES_DIFF = HASHES_DB - HASHES_COOKIE;
|
const HASHES_DIFF = HASHES_DB - HASHES_COOKIE;
|
||||||
|
|
||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
router.use("/*path", (req, res, next) => {
|
router.use("/*", (req, res, next) => {
|
||||||
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
||||||
let unsigned;
|
let unsigned;
|
||||||
|
if (req.body.user === undefined || req.body.pass === undefined) {
|
||||||
req.body = req.body || {};
|
if(typeof req.get("ipost-auth-token") === "string") {
|
||||||
|
try{
|
||||||
if (typeof req.get("ipost-auth-token") === "string") {
|
req.body.auth = JSON.parse(req.get("ipost-auth-token"))
|
||||||
try {
|
} catch(err) {
|
||||||
req.body.auth = JSON.parse(req.get("ipost-auth-token"))
|
console.log("error parsing header",err)
|
||||||
} catch (err) {
|
|
||||||
console.log("error parsing header", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (req.body.auth !== undefined && req.originalUrl !== "/redeemauthcode") {
|
|
||||||
if (typeof req.body.auth === "string") {
|
|
||||||
try {
|
|
||||||
req.body.auth = JSON.parse(req.body.auth)
|
|
||||||
} catch (err) {
|
|
||||||
console.log("error parsing", err)
|
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
if (
|
if(req.body.auth !== undefined && req.originalUrl !== "/redeemauthcode") {
|
||||||
typeof req.body.auth !== "object" ||
|
if(typeof req.body.auth === "string") {
|
||||||
typeof req.body.auth.secret !== "string" ||
|
try{
|
||||||
typeof req.body.auth.appid !== "number" ||
|
req.body.auth = JSON.parse(req.body.auth)
|
||||||
|
} catch(err) {
|
||||||
|
console.log("error parsing",err)
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if(
|
||||||
|
typeof req.body.auth !== "object" ||
|
||||||
|
typeof req.body.auth.secret !== "string" ||
|
||||||
|
typeof req.body.auth.appid !== "number" ||
|
||||||
typeof req.body.auth.auth_token !== "string" ||
|
typeof req.body.auth.auth_token !== "string" ||
|
||||||
req.body.auth.secret.length !== 200 ||
|
req.body.auth.secret.length !== 200 ||
|
||||||
req.body.auth.auth_token.length !== 200 ||
|
req.body.auth.auth_token.length !== 200 ||
|
||||||
Buffer.from(req.body.auth.secret, "base64").length !== 150
|
Buffer.from(req.body.auth.secret,"base64").length !== 150
|
||||||
) {
|
) {
|
||||||
res.status(420).send("invalid authentication object")
|
res.status(420).send("invalid authentication object")
|
||||||
return;
|
return;
|
||||||
@@ -44,10 +42,10 @@ export const setup = function (router, con, server) {
|
|||||||
//appid : number
|
//appid : number
|
||||||
//auth_token: string(200 chars)
|
//auth_token: string(200 chars)
|
||||||
let sql = "select User_ID,User_Name,User_Bio,User_Avatar,User_Settings from ipost.auth_tokens inner join ipost.application on auth_token_isfrom_application_id=application_id inner join ipost.users on auth_token_u_id=User_ID where auth_token=? and application_secret=? and application_id=?"
|
let sql = "select User_ID,User_Name,User_Bio,User_Avatar,User_Settings from ipost.auth_tokens inner join ipost.application on auth_token_isfrom_application_id=application_id inner join ipost.users on auth_token_u_id=User_ID where auth_token=? and application_secret=? and application_id=?"
|
||||||
con.query(sql, [SHA256(req.body.auth.auth_token, req.body.auth.appid, HASHES_DB), SHA256(req.body.auth.secret, req.body.auth.appid, HASHES_DB), req.body.auth.appid], (err, result) => {
|
con.query(sql,[SHA256(req.body.auth.auth_token,req.body.auth.appid, HASHES_DB),SHA256(req.body.auth.secret,req.body.auth.appid, HASHES_DB),req.body.auth.appid],(err,result) => {
|
||||||
if (err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
if (result.length !== 1) {
|
if(result.length !== 1) {
|
||||||
res.status(420).send("invalid authentication object (or server error?)")
|
res.status(420).send("invalid authentication object (or server error?)")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -64,16 +62,24 @@ export const setup = function (router, con, server) {
|
|||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!req.cookies.AUTH_COOKIE) {
|
if(!req.cookies.AUTH_COOKIE) {
|
||||||
next()
|
next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
unsigned = unsign(req.cookies.AUTH_COOKIE, req, res);
|
unsigned = unsign(req.cookies.AUTH_COOKIE, req, res);
|
||||||
if (!unsigned) {
|
if (!unsigned){
|
||||||
next()
|
next()
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unsigned = `${req.body.user} ${SHA256(req.body.pass, req.body.user, HASHES_COOKIE)}`;
|
||||||
|
res.set("message","user+pass authentication is deprecated as of february 2023, consider switching to auth tokens")
|
||||||
|
//basically we generate the unsigned cookie
|
||||||
|
res.locals.isbot = true; //only bots use user+pass
|
||||||
}
|
}
|
||||||
let sql = `select User_ID,User_Name,User_Bio,User_Avatar,User_Settings from ipost.users where User_Name=? and User_PW=?;`;
|
let sql = `select User_ID,User_Name,User_Bio,User_Avatar,User_Settings from ipost.users where User_Name=? and User_PW=?;`;
|
||||||
let values = unsigned.split(" ");
|
let values = unsigned.split(" ");
|
||||||
@@ -86,10 +92,10 @@ export const setup = function (router, con, server) {
|
|||||||
throw err;
|
throw err;
|
||||||
if (result[0] && result[0].User_Name && result[0].User_Name === values[0]) {
|
if (result[0] && result[0].User_Name && result[0].User_Name === values[0]) {
|
||||||
|
|
||||||
res.locals.userid = result[0].User_ID;
|
res.locals.userid = result[0].User_ID;
|
||||||
res.locals.username = result[0].User_Name;
|
res.locals.username = result[0].User_Name;
|
||||||
res.locals.bio = result[0].User_Bio || "";
|
res.locals.bio = result[0].User_Bio || "";
|
||||||
res.locals.avatar = result[0].User_Avatar || "";
|
res.locals.avatar = result[0].User_Avatar || "";
|
||||||
res.locals.settings = result[0].User_Settings || {};
|
res.locals.settings = result[0].User_Settings || {};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -97,13 +103,13 @@ export const setup = function (router, con, server) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.use("/api/*path", (req, res, next) => {
|
router.use("/api/*", (req, res, next) => {
|
||||||
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
res.set("Access-Control-Allow-Origin", "*"); //we'll allow it for now
|
||||||
if (config["allow_getotheruser_without_cookie"] && req.originalUrl.split("\?")[0] === "/api/getotheruser") {
|
if (config["allow_getotheruser_without_cookie"] && req.originalUrl.split("\?")[0] === "/api/getotheruser") {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!server.increaseAPICall(req, res)) return;
|
if (!server.increaseAPICall(req, res))return;
|
||||||
|
|
||||||
if (res.locals.username !== undefined) {
|
if (res.locals.username !== undefined) {
|
||||||
next();
|
next();
|
||||||
@@ -112,9 +118,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.status(402);
|
res.status(402);
|
||||||
res.json({ "error": "you cannot access the api without being logged in" });
|
res.json({ "error": "you cannot access the api without being logged in" });
|
||||||
}
|
}
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ export const setup = function (router, con, server) {
|
|||||||
throw err;
|
throw err;
|
||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/dms/conversations", function (req, res) {
|
router.get("/api/dms/conversations", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -33,16 +30,10 @@ export const setup = function (router, con, server) {
|
|||||||
throw err;
|
throw err;
|
||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/dms/encrypt.js", function (req, res) {
|
router.get("/api/dms/encrypt.js", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
res.send(web_version());
|
res.send(web_version());
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
router.get("/api/dms/getDM", function (req, res) {
|
router.get("/api/dms/getDM", function (req, res) {
|
||||||
@@ -61,9 +52,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({ "error": "there is no such dm!" });
|
res.json({ "error": "there is no such dm!" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ export const setup = function (router, con, server) {
|
|||||||
router.get("/api/dms/pid", function (req, res) {
|
router.get("/api/dms/pid", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
res.json({ "pid": createPID() });
|
res.json({ "pid": createPID() });
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.post("/api/dms/post", function (req, res) {
|
router.post("/api/dms/post", function (req, res) {
|
||||||
if (!req.body.message) {
|
if (!req.body.message) {
|
||||||
@@ -92,10 +89,6 @@ export const setup = function (router, con, server) {
|
|||||||
console.log(5, `posted new dm by ${res.locals.username} to ${otherperson} : ${xor(encodeURIComponent(res.locals.username), otherperson)}`);
|
console.log(5, `posted new dm by ${res.locals.username} to ${otherperson} : ${xor(encodeURIComponent(res.locals.username), otherperson)}`);
|
||||||
});
|
});
|
||||||
//TODO: bring dms up-to-date with normal posts
|
//TODO: bring dms up-to-date with normal posts
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
return createPID
|
return createPID
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ async function addTextOnImage(text,buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
router.get("/api/getFileIcon/:icon",async function(req,res){
|
router.get("/api/getFileIcon/*",async function(req,res){
|
||||||
let path = req.params.icon
|
let path = req.path.split("/api/getFileIcon/")[1]
|
||||||
if(path.length > 4) {
|
if(path.length > 4) {
|
||||||
res.status(410).json({"error":"file ending is too long"})
|
res.status(410).json({"error":"file ending is too long"})
|
||||||
return;
|
return;
|
||||||
@@ -41,8 +41,5 @@ export const setup = function (router, con, server) {
|
|||||||
res.set("content-type","image/png")
|
res.set("content-type","image/png")
|
||||||
res.send(buf)
|
res.send(buf)
|
||||||
})
|
})
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
|
router.get("/api/getPosts/*", function (_req, res) {
|
||||||
|
res.set("Access-Control-Allow-Origin", "");
|
||||||
|
res.redirect("/api/getPosts");
|
||||||
|
});
|
||||||
router.get("/api/getPosts", function (req, res) {
|
router.get("/api/getPosts", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
if (req.query.channel !== undefined) {
|
if (req.query.channel !== undefined) {
|
||||||
@@ -17,9 +21,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/getPostsLowerThan", function (req, res) {
|
router.get("/api/getPostsLowerThan", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -39,9 +40,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/getPost", function (req, res) {
|
router.get("/api/getPost", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -58,8 +56,5 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({ "error": "there is no such post!" });
|
res.json({ "error": "there is no such post!" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,6 @@ export const setup = function (router, con, server) {
|
|||||||
router.get("/api/pid", function (req, res) {
|
router.get("/api/pid", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
res.json({ "pid": createPID() });
|
res.json({ "pid": createPID() });
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function validateMessage(message) {
|
function validateMessage(message) {
|
||||||
@@ -207,9 +204,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({"error":"internal server error", "status": 500})
|
res.json({"error":"internal server error", "status": 500})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
return createPID
|
return createPID
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,9 +34,5 @@ export const setup = function (router, con, server) {
|
|||||||
else {
|
else {
|
||||||
res.json({ "error": "invalid type passed along, expected `user` or `post`", "message": "search has been deprecated as of 11/30/2022"});
|
res.json({ "error": "invalid type passed along, expected `user` or `post`", "message": "search has been deprecated as of 11/30/2022"});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,6 @@ const allowed_settings = {
|
|||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
router.get("/api/settings", function (req, res) {
|
router.get("/api/settings", function (req, res) {
|
||||||
res.json(res.locals.settings);
|
res.json(res.locals.settings);
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.post("/api/settings", function (req, res) {
|
router.post("/api/settings", function (req, res) {
|
||||||
if (!req.body.setting) {
|
if (!req.body.setting) {
|
||||||
@@ -49,10 +45,6 @@ export const setup = function (router, con, server) {
|
|||||||
}
|
}
|
||||||
res.json({ "status": "success" });
|
res.json({ "status": "success" });
|
||||||
});
|
});
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -48,15 +48,9 @@ export const setup = function (router, con, server) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/getuser", function (_req, res) {
|
router.get("/api/getuser", function (_req, res) {
|
||||||
res.json({ "username": res.locals.username, "bio": res.locals.bio, "avatar": res.locals.avatar, "userid": res.locals.userid });
|
res.json({ "username": res.locals.username, "bio": res.locals.bio, "avatar": res.locals.avatar, "userid": res.locals.userid });
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/getalluserinformation", function (req, res) {
|
router.get("/api/getalluserinformation", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", ""); //we don't want that here
|
res.set("Access-Control-Allow-Origin", ""); //we don't want that here
|
||||||
@@ -79,9 +73,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({ "error": "you cannot access the api without being logged in" });
|
res.json({ "error": "you cannot access the api without being logged in" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.get("/api/getotheruser", function (req, res) {
|
router.get("/api/getotheruser", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "*");
|
res.set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -118,9 +109,6 @@ export const setup = function (router, con, server) {
|
|||||||
throw err;
|
throw err;
|
||||||
res.json({ "success": "updated bio" });
|
res.json({ "success": "updated bio" });
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.post("/api/changePW", (req, res) => {
|
router.post("/api/changePW", (req, res) => {
|
||||||
res.set("Access-Control-Allow-Origin", "");
|
res.set("Access-Control-Allow-Origin", "");
|
||||||
@@ -161,9 +149,6 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({ "error": "invalid password" });
|
res.json({ "error": "invalid password" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
router.post("/api/changeUsername", function (req, res) {
|
router.post("/api/changeUsername", function (req, res) {
|
||||||
res.set("Access-Control-Allow-Origin", "");
|
res.set("Access-Control-Allow-Origin", "");
|
||||||
@@ -227,8 +212,5 @@ export const setup = function (router, con, server) {
|
|||||||
res.json({ "error": "invalid password" });
|
res.json({ "error": "invalid password" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
+3
-15
@@ -23,7 +23,7 @@ export const setup = function (router, con, server) {
|
|||||||
|
|
||||||
let tokencode;
|
let tokencode;
|
||||||
while(tokencode===undefined || temp_code_to_token[tokencode]!==undefined) {
|
while(tokencode===undefined || temp_code_to_token[tokencode]!==undefined) {
|
||||||
tokencode = randomBytes(15).toString("base64").replaceAll("/","f").replaceAll("+","A") //"/" and "+" may break some apps
|
tokencode = randomBytes(15).toString("base64")
|
||||||
}
|
}
|
||||||
temp_code_to_token[tokencode]={
|
temp_code_to_token[tokencode]={
|
||||||
"userid":res.locals.userid,
|
"userid":res.locals.userid,
|
||||||
@@ -35,7 +35,7 @@ export const setup = function (router, con, server) {
|
|||||||
if(data !== undefined && data.token===token && data.appid === appid && data.userid === res.locals.userid) {
|
if(data !== undefined && data.token===token && data.appid === appid && data.userid === res.locals.userid) {
|
||||||
temp_code_to_token[tokencode]=undefined
|
temp_code_to_token[tokencode]=undefined
|
||||||
}
|
}
|
||||||
}, 1000*60*5);
|
}, 300000); //wait for 5 minutes
|
||||||
|
|
||||||
const sql = "SELECT application_auth_url FROM ipost.application where application_id=?"
|
const sql = "SELECT application_auth_url FROM ipost.application where application_id=?"
|
||||||
|
|
||||||
@@ -45,11 +45,7 @@ export const setup = function (router, con, server) {
|
|||||||
res.redirect(`/authorize?id=${req.body.application_id}`)
|
res.redirect(`/authorize?id=${req.body.application_id}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let extra = ""
|
res.redirect(`${result[0].application_auth_url}?code=${tokencode}`)
|
||||||
if(req.body.application_extra !== "") {
|
|
||||||
extra = "&extra="+String(req.body.application_extra)
|
|
||||||
}
|
|
||||||
res.redirect(`${result[0].application_auth_url}?code=${tokencode}${extra}`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -59,10 +55,6 @@ export const setup = function (router, con, server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.redirect(`/authorize?id=${req.body.application_id}`)
|
res.redirect(`/authorize?id=${req.body.application_id}`)
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post("/redeemauthcode", (req,res) => {
|
router.post("/redeemauthcode", (req,res) => {
|
||||||
@@ -128,8 +120,4 @@ export const setup = function (router, con, server) {
|
|||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
}
|
}
|
||||||
@@ -5,43 +5,43 @@ export const setup = function (router, con, server) {
|
|||||||
const __dirname = server.dirname
|
const __dirname = server.dirname
|
||||||
const dir = __dirname + "/"
|
const dir = __dirname + "/"
|
||||||
|
|
||||||
router.get("/users/:user", function (req, res) {
|
router.get("/users/*", function (req, res) {
|
||||||
if (!increaseUSERCall(req, res))
|
if (!increaseUSERCall(req, res))
|
||||||
return;
|
return;
|
||||||
res.sendFile(dir + "views/otheruser.html");
|
res.sendFile(dir + "views/otheruser.html");
|
||||||
});
|
});
|
||||||
router.get("/css/:file", (request, response) => {
|
router.get("/css/*", (request, response) => {
|
||||||
if (!increaseUSERCall(request, response))
|
if (!increaseUSERCall(request, response))
|
||||||
return;
|
return;
|
||||||
if (existsSync(`${__dirname}/css/${request.params.file}`)) {
|
if (existsSync(__dirname + request.originalUrl)) {
|
||||||
response.sendFile(`${__dirname}/css/${request.params.file}`);
|
response.sendFile(__dirname + request.originalUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response.status(404).send("no file with that name found");
|
response.status(404).send("no file with that name found");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
router.get("/js/:file", (request, response) => {
|
router.get("/js/*", (request, response) => {
|
||||||
if (!increaseUSERCall(request, response))
|
if (!increaseUSERCall(request, response))
|
||||||
return;
|
return;
|
||||||
if (existsSync(`${__dirname}/js/${request.params.file}`)) {
|
if (existsSync(__dirname + request.originalUrl)) {
|
||||||
response.sendFile(`${__dirname}/js/${request.params.file}`);
|
response.sendFile(__dirname + request.originalUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response.status(404).send("no file with that name found");
|
response.status(404).send("no file with that name found");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
router.get("/images/:file", (request, response) => {
|
router.get("/images/*", (request, response) => {
|
||||||
if (!increaseUSERCall(request, response))
|
if (!increaseUSERCall(request, response))
|
||||||
return;
|
return;
|
||||||
if (existsSync(`${__dirname}/images/${request.params.file}`)) {
|
if (existsSync(__dirname + request.originalUrl)) {
|
||||||
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
||||||
response.sendFile(`${__dirname}/images/${request.params.file}`);
|
response.sendFile(__dirname + request.originalUrl);
|
||||||
}
|
}
|
||||||
else if(existsSync(`${__dirname}/images/${request.params.file.toLowerCase()}`)){
|
else if(existsSync(__dirname + request.originalUrl.toLowerCase())){
|
||||||
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
||||||
response.sendFile(`${__dirname}/images/${request.params.file.toLowerCase()}`);
|
response.sendFile(__dirname + request.originalUrl.toLowerCase());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response.status(404).send("no file with that name found");
|
response.status(404).send("no file with that name found");
|
||||||
@@ -49,12 +49,12 @@ export const setup = function (router, con, server) {
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/user_uploads/:file", (request, response) => {
|
router.get("/user_uploads/*", (request, response) => {
|
||||||
if (!increaseUSERCall(request, response))
|
if (!increaseUSERCall(request, response))
|
||||||
return;
|
return;
|
||||||
if (existsSync(`${__dirname}/user_uploads/${request.params.file}`)) {
|
if (existsSync(__dirname + request.originalUrl)) {
|
||||||
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
||||||
response.sendFile(`${__dirname}/user_uploads/${request.params.file}`);
|
response.sendFile(__dirname + request.originalUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response.status(404).send("no file with that name found");
|
response.status(404).send("no file with that name found");
|
||||||
@@ -62,12 +62,13 @@ export const setup = function (router, con, server) {
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/avatars/:avatar", (request, response) => {
|
router.get("/avatars/*", (request, response) => {
|
||||||
if (!increaseUSERCall(request, response))
|
if (!increaseUSERCall(request, response))
|
||||||
return;
|
return;
|
||||||
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
response.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
|
||||||
if (existsSync(`${__dirname}/avatars/${request.params.avatar}`)) {
|
let originalUrl = request.originalUrl.split("?").shift();
|
||||||
return response.sendFile(`${__dirname}/avatars/${request.params.avatar}`);
|
if (existsSync(dir + originalUrl)) {
|
||||||
|
return response.sendFile(dir + originalUrl);
|
||||||
}
|
}
|
||||||
response.status(404).send("No avatar with that name found");
|
response.status(404).send("No avatar with that name found");
|
||||||
});
|
});
|
||||||
|
|||||||
+64
-75
@@ -1,17 +1,17 @@
|
|||||||
import ejs from "ejs"
|
import ejs from "ejs"
|
||||||
import { LRUCache as LRU } from "lru-cache"
|
import LRU from "lru-cache"
|
||||||
import { minify as min_js } from "uglify-js"
|
import {minify as min_js} from "uglify-js"
|
||||||
import Clean from 'clean-css';
|
import Clean from 'clean-css';
|
||||||
import Minifier from 'html-minifier-terser';
|
import Minifier from 'html-minifier-terser';
|
||||||
import { web_version } from "unsafe_encrypt";
|
import { web_version } from "unsafe_encrypt";
|
||||||
import { existsSync, readFileSync, readFile } from "fs"
|
import {existsSync, readFileSync, readFile} from "fs"
|
||||||
|
|
||||||
export const setup = function (router, con, server) {
|
export const setup = function (router, con, server) {
|
||||||
|
|
||||||
const increaseUSERCall = server.increaseUSERCall
|
const increaseUSERCall = server.increaseUSERCall
|
||||||
const dir = server.dirname + "/"
|
const dir = server.dirname + "/"
|
||||||
|
|
||||||
ejs.cache = new LRU({ max: 20 })
|
ejs.cache = new LRU({max:20})
|
||||||
|
|
||||||
const load_var_cache = new LRU({
|
const load_var_cache = new LRU({
|
||||||
max: 20,
|
max: 20,
|
||||||
@@ -25,39 +25,39 @@ export const setup = function (router, con, server) {
|
|||||||
updateAgeOnHas: true
|
updateAgeOnHas: true
|
||||||
})
|
})
|
||||||
|
|
||||||
function load_var(filePath) {
|
function load_var(fina) {
|
||||||
if (load_var_cache.has(filePath)) {
|
if(load_var_cache.get(fina))return load_var_cache.get(fina)
|
||||||
return load_var_cache.get(filePath);
|
if(!existsSync(fina)) {
|
||||||
|
console.log(1,"tried loading non-existent file",fina)
|
||||||
|
load_var_cache.set(fina,"")
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
let out = readFileSync(fina)
|
||||||
|
if(fina.endsWith(".js")) {
|
||||||
|
out = min_js(out.toString()).code
|
||||||
|
}
|
||||||
|
else if(fina.endsWith(".css")) {
|
||||||
|
const {
|
||||||
|
styles,
|
||||||
|
} = new Clean({}).minify(out.toString());
|
||||||
|
out = styles
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(filePath)) {
|
load_var_cache.set(fina,out)
|
||||||
console.log(1, 'Tried loading non-existent file', filePath);
|
|
||||||
load_var_cache.set(filePath, '');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
let output = readFileSync(filePath);
|
return out
|
||||||
|
|
||||||
if (filePath.endsWith('.js')) {
|
|
||||||
output = min_js(output.toString()).code;
|
|
||||||
} else if (filePath.endsWith('.css')) {
|
|
||||||
const { styles } = new Clean({}).minify(output.toString());
|
|
||||||
output = styles;
|
|
||||||
}
|
|
||||||
load_var_cache.set(filePath, output);
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_channels() {
|
function get_channels(){
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
let sql = `select post_receiver_name from ipost.posts where post_is_private = '0' group by post_receiver_name;`;
|
let sql = `select post_receiver_name from ipost.posts where post_is_private = '0' group by post_receiver_name;`;
|
||||||
con.query(sql, [], function (err, result) {
|
con.query(sql, [], function (err, result) {
|
||||||
if (err) reject(err)
|
if (err)reject(err)
|
||||||
|
|
||||||
let out = []
|
let out = []
|
||||||
|
|
||||||
for (let channel of result) {
|
for(let channel of result){
|
||||||
if (channel.post_receiver_name === "") continue;
|
if(channel.post_receiver_name === "")continue;
|
||||||
out[out.length] = channel.post_receiver_name
|
out[out.length] = channel.post_receiver_name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,25 +66,21 @@ export const setup = function (router, con, server) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const appId_Cache = new LRU({ max: 20, ttl: 1000 * 60 * 15 }) //cache for 15 minutes
|
const appId_Cache = new LRU({max:20,ttl: 1000 * 60 * 15}) //cache for 15 minutes
|
||||||
function getAppWithId(appid) {
|
function getAppWithId(appid) {
|
||||||
appid = Number(appid)
|
appid = Number(appid)
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res,rej) => {
|
||||||
if (isNaN(appid)) {
|
if(appId_Cache.has(appid)) {
|
||||||
res({})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (appId_Cache.has(appid)) {
|
|
||||||
res(appId_Cache.get(appid) || {})
|
res(appId_Cache.get(appid) || {})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
con.query("SELECT * FROM ipost.application WHERE application_id=?", [appid], (err, result) => {
|
con.query("SELECT * FROM ipost.application WHERE application_id=?",[appid],(err,result) => {
|
||||||
if (err) {
|
if(err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
rej({})
|
rej({})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
appId_Cache.set(appid, result[0])
|
appId_Cache.set(appid,result[0])
|
||||||
res(result[0] || {})
|
res(result[0] || {})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -101,6 +97,7 @@ export const setup = function (router, con, server) {
|
|||||||
getChannels: get_channels,
|
getChannels: get_channels,
|
||||||
encryptJS: min_js(web_version().toString()).code,
|
encryptJS: min_js(web_version().toString()).code,
|
||||||
cookiebanner: `<script id="cookieyes" type="text/javascript" src="https://cdn-cookieyes.com/client_data/3cf33f6b631f3587bf83813b/script.js" async></script>`,
|
cookiebanner: `<script id="cookieyes" type="text/javascript" src="https://cdn-cookieyes.com/client_data/3cf33f6b631f3587bf83813b/script.js" async></script>`,
|
||||||
|
newrelic: load_var("./extra_modules/newrelic_monitor.html"),
|
||||||
getPID: server.global_page_variables.getPID,
|
getPID: server.global_page_variables.getPID,
|
||||||
getDMPID: server.global_page_variables.getDMPID,
|
getDMPID: server.global_page_variables.getDMPID,
|
||||||
unauthorized_description: "Chat now by creating an account on IPost",
|
unauthorized_description: "Chat now by creating an account on IPost",
|
||||||
@@ -111,21 +108,19 @@ export const setup = function (router, con, server) {
|
|||||||
|
|
||||||
|
|
||||||
async function handleUserFiles(request, response, overrideurl) {
|
async function handleUserFiles(request, response, overrideurl) {
|
||||||
if (!increaseUSERCall(request, response)) return;
|
if (!increaseUSERCall(request, response))return;
|
||||||
if (typeof overrideurl !== "string") overrideurl = undefined;
|
if(typeof overrideurl !== "string")overrideurl = undefined;
|
||||||
|
|
||||||
let originalUrl = overrideurl
|
let originalUrl = overrideurl || request.originalUrl.split("?").shift();
|
||||||
|| request.params.file
|
|
||||||
|| request.originalUrl.split("?").shift(); //backup in case anything goes wrong
|
|
||||||
|
|
||||||
let path = ""
|
let path = ""
|
||||||
if (existsSync(dir + "views/" + originalUrl)) {
|
if (existsSync(dir + "views" + originalUrl)) {
|
||||||
path = dir + "views/" + originalUrl
|
path = dir + "views" + originalUrl
|
||||||
//send .txt files as plaintext to help browsers interpret it correctly
|
//send .txt files as plaintext to help browsers interpret it correctly
|
||||||
if (originalUrl.endsWith(".txt")) {
|
if(originalUrl.endsWith(".txt")) {
|
||||||
response.set('Content-Type', 'text/plain');
|
response.set('Content-Type', 'text/plain');
|
||||||
readFile(path, (err, data) => {
|
readFile(path,(err,data)=> {
|
||||||
if (err) return
|
if(err)return
|
||||||
response.send(data)
|
response.send(data)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -141,25 +136,24 @@ export const setup = function (router, con, server) {
|
|||||||
path = dir + "views" + originalUrl + ".html"
|
path = dir + "views" + originalUrl + ".html"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path !== "" && originalUrl !== "favicon.ico" && originalUrl !== "api_documentation" && originalUrl !== "api_documentation.html") {
|
if(path !== "" && originalUrl !== "/favicon.ico" && originalUrl !== "/api/documentation/") {
|
||||||
console.log(originalUrl)
|
|
||||||
global_page_variables.user = { "username": response.locals.username, "bio": response.locals.bio, "avatar": response.locals.avatar }
|
global_page_variables.user = { "username": response.locals.username, "bio": response.locals.bio, "avatar": response.locals.avatar }
|
||||||
global_page_variables.query = request.query
|
global_page_variables.query = request.query
|
||||||
if (originalUrl === "authorize") {
|
if(originalUrl === "/authorize") {
|
||||||
global_page_variables.application = await getAppWithId(request.query.id)
|
global_page_variables.application = await getAppWithId(request.query.id)
|
||||||
}
|
}
|
||||||
ejs.renderFile(path, global_page_variables, { async: true }, async function (err, str) {
|
ejs.renderFile(path,global_page_variables,{async: true},async function(err,str){
|
||||||
str = await str
|
str = await str
|
||||||
err = await err
|
err = await err
|
||||||
if (err) {
|
if(err) {
|
||||||
console.log(1, err)
|
console.log(1,err)
|
||||||
response.status(500)
|
response.status(500)
|
||||||
response.send("error")
|
response.send("error")
|
||||||
//TODO: make error page
|
//TODO: make error page
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
str = await Minifier.minify(str, {
|
str = await Minifier.minify(str,{
|
||||||
removeComments: true,
|
removeComments: true,
|
||||||
removeCommentsFromCDATA: true,
|
removeCommentsFromCDATA: true,
|
||||||
removeCDATASectionsFromCDATA: true,
|
removeCDATASectionsFromCDATA: true,
|
||||||
@@ -170,36 +164,36 @@ export const setup = function (router, con, server) {
|
|||||||
useShortDoctype: true,
|
useShortDoctype: true,
|
||||||
removeEmptyAttributes: true
|
removeEmptyAttributes: true
|
||||||
})
|
})
|
||||||
} catch (ignored) {
|
} catch(ignored){
|
||||||
console.log(2, "error minifying", originalUrl);
|
console.log(2,"error minifying",originalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response.send(str)
|
response.send(str)
|
||||||
} catch (err) {
|
} catch(err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originalUrl === "api_documentation" || originalUrl === "api_documentation.html") {
|
if(originalUrl === "/favicon.ico") {
|
||||||
response.set('Cache-Control', 'public, max-age=2592000');
|
|
||||||
response.set('Content-Type', 'text/html')
|
|
||||||
response.send(load_var("./views/api_documentation.html"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalUrl === "favicon.ico") {
|
|
||||||
response.set('Cache-Control', 'public, max-age=2592000');
|
response.set('Cache-Control', 'public, max-age=2592000');
|
||||||
response.sendFile(dir + "/views/favicon.ico")
|
response.sendFile(dir + "/views/favicon.ico")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(5, "no file found", originalUrl);
|
if(originalUrl === "/api/documentation/") {
|
||||||
|
readFile(path,function(_err,res){
|
||||||
|
response.send(res.toString())
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(5,"no file found",originalUrl);
|
||||||
try {
|
try {
|
||||||
response.status(404).send("No file with that name found");
|
response.status(404).send("No file with that name found");
|
||||||
} catch (err) {
|
} catch(err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,14 +201,9 @@ export const setup = function (router, con, server) {
|
|||||||
/**
|
/**
|
||||||
* Handle default URI as /index (interpreted redirect: "localhost" -> "localhost/index" )
|
* Handle default URI as /index (interpreted redirect: "localhost" -> "localhost/index" )
|
||||||
*/
|
*/
|
||||||
router.get("/", (req, res) => {
|
router.get("/", function (req, res) {
|
||||||
req.params.file = "index"
|
handleUserFiles(req,res,"/index")
|
||||||
handleUserFiles(req, res, "/index")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/:file", handleUserFiles);
|
router.get("/*", handleUserFiles);
|
||||||
router.get("/:folder/:file", (req, res) => {
|
|
||||||
req.params.file = req.params.folder + "/" + req.params.file
|
|
||||||
handleUserFiles(req, res)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import "newrelic"
|
||||||
|
|
||||||
import http from "http";
|
import http from "http";
|
||||||
import express,{Router} from "express";
|
import express,{Router} from "express";
|
||||||
import useragent from "express-useragent";
|
import useragent from "express-useragent";
|
||||||
@@ -55,7 +57,7 @@ function log_info(level, ...info) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//console.log = log_info;
|
console.log = log_info;
|
||||||
|
|
||||||
|
|
||||||
const hcaptcha_secret = config.hcaptcha_secret
|
const hcaptcha_secret = config.hcaptcha_secret
|
||||||
@@ -260,16 +262,6 @@ app.use(fileUpload({
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use((_req, res, next) => {
|
|
||||||
res.set("x-powered-by", "ipost");
|
|
||||||
res.set("X-Frame-Options","DENY");
|
|
||||||
res.set("X-XSS-Protection","1; mode=block");
|
|
||||||
res.set("X-Content-Type-Options","nosniff");
|
|
||||||
res.set("Referrer-Policy","no-referrer");
|
|
||||||
|
|
||||||
next()
|
|
||||||
})
|
|
||||||
|
|
||||||
app.use(bodyParser.default.json({ limit: "100mb" }));
|
app.use(bodyParser.default.json({ limit: "100mb" }));
|
||||||
app.use(bodyParser.default.urlencoded({ limit: "100mb", extended: true }));
|
app.use(bodyParser.default.urlencoded({ limit: "100mb", extended: true }));
|
||||||
app.use(cookieParser(cookiesecret));
|
app.use(cookieParser(cookiesecret));
|
||||||
@@ -299,7 +291,20 @@ app.use(function (_req, res, next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use("/*path", function (req, res, next) {
|
//auto redirect to https
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
if (req.secure) {
|
||||||
|
//already secure
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//redirect to https
|
||||||
|
res.redirect('https://' + req.headers.host + req.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use("/*", function (req, res, next) {
|
||||||
|
res.set("x-powered-by", "ipost");
|
||||||
for (let i = 0; i < blocked_headers.length; i++) {
|
for (let i = 0; i < blocked_headers.length; i++) {
|
||||||
if (req.header(blocked_headers[i]) !== undefined) {
|
if (req.header(blocked_headers[i]) !== undefined) {
|
||||||
res.json({ "error": "we don't allow proxies on our website." });
|
res.json({ "error": "we don't allow proxies on our website." });
|
||||||
@@ -353,9 +358,6 @@ router.get("/api/getChannels", function (_req, res) {
|
|||||||
throw err;
|
throw err;
|
||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
/* #swagger.security = [{
|
|
||||||
"appTokenAuthHeader": []
|
|
||||||
}] */
|
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@@ -369,9 +371,21 @@ const httpServer = http.createServer(app);
|
|||||||
httpServer.listen(config["ports"]["http"], function () {
|
httpServer.listen(config["ports"]["http"], function () {
|
||||||
console.log(5, "HTTP Server is listening");
|
console.log(5, "HTTP Server is listening");
|
||||||
});
|
});
|
||||||
|
const privateKey = readFileSync(config["ssl"]["privateKey"]).toString();
|
||||||
|
const certificate = readFileSync(config["ssl"]["certificate"]).toString();
|
||||||
|
const credentials = { key: privateKey, cert: certificate };
|
||||||
|
var httpsServer;
|
||||||
|
|
||||||
|
import spdy from "spdy"
|
||||||
|
|
||||||
|
httpsServer = spdy.createServer(credentials,app)
|
||||||
|
//httpsServer = https.createServer(credentials, app);
|
||||||
|
httpsServer.listen(config["ports"]["https"], function () {
|
||||||
|
console.log(5, "HTTPS Server is listening");
|
||||||
|
});
|
||||||
|
|
||||||
wss = new WebSocket({
|
wss = new WebSocket({
|
||||||
server: httpServer,
|
server: httpsServer,
|
||||||
perMessageDeflate: {
|
perMessageDeflate: {
|
||||||
zlibDeflateOptions: {
|
zlibDeflateOptions: {
|
||||||
chunkSize: 1024,
|
chunkSize: 1024,
|
||||||
|
|||||||
+6
-6
@@ -4,8 +4,8 @@
|
|||||||
"only_prefer_when_ip": "::ffff:127.0.0.1",
|
"only_prefer_when_ip": "::ffff:127.0.0.1",
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"connections":1000,
|
"connections":1000,
|
||||||
"host":"db",
|
"host":"localhost",
|
||||||
"user":"ipost",
|
"user":"root",
|
||||||
"password_file":"mysql_password.txt"
|
"password_file":"mysql_password.txt"
|
||||||
},
|
},
|
||||||
"cookies": {
|
"cookies": {
|
||||||
@@ -155,12 +155,12 @@
|
|||||||
"level": 5
|
"level": 5
|
||||||
},
|
},
|
||||||
"ssl": {
|
"ssl": {
|
||||||
"privateKey": "/etc/letsencrypt/live/ipost.rocks-0002/privkey.pem",
|
"privateKey": "./etc/letsencrypt/live/ipost.rocks/privkey.pem",
|
||||||
"certificate" : "/etc/letsencrypt/live/ipost.rocks-0002/fullchain.pem"
|
"certificate" : "./etc/letsencrypt/live/ipost.rocks/fullchain.pem"
|
||||||
},
|
},
|
||||||
"ports": {
|
"ports": {
|
||||||
"http": 80,
|
"http": 9999,
|
||||||
"https": 443
|
"https": 9998
|
||||||
},
|
},
|
||||||
"disallow_proxies_by_headers": true,
|
"disallow_proxies_by_headers": true,
|
||||||
"hcaptcha_secret": "0x0000000000000000000000000000000000000000",
|
"hcaptcha_secret": "0x0000000000000000000000000000000000000000",
|
||||||
|
|||||||
-78
@@ -1,78 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const swaggerAutogen = require('swagger-autogen')();
|
|
||||||
|
|
||||||
const doc = {
|
|
||||||
info: {
|
|
||||||
title: 'IPost API',
|
|
||||||
description: 'the official IPost.rocks API documentation',
|
|
||||||
},
|
|
||||||
host: 'ipost.rocks',
|
|
||||||
schemes: ['https'],
|
|
||||||
securityDefinitions: {
|
|
||||||
appTokenAuthHeader: {
|
|
||||||
type: 'apiKey',
|
|
||||||
in: 'header', // can be 'header', 'query' or 'cookie'
|
|
||||||
name: 'ipost-auth-token', // name of the header, query parameter or cookie
|
|
||||||
description: 'authenticate using the authentication object in the header'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const outputFile = './swagger-api.json';
|
|
||||||
const tempFile = './swagger-output.json';
|
|
||||||
const endpointsFiles = ['./server.js'];
|
|
||||||
|
|
||||||
function pushdirectory(currentpath) {
|
|
||||||
fs.readdirSync(currentpath, {
|
|
||||||
withFileTypes: true
|
|
||||||
}).forEach(dirent => {
|
|
||||||
if (dirent.isFile()) {
|
|
||||||
endpointsFiles.push(currentpath + dirent.name);
|
|
||||||
} else {
|
|
||||||
pushdirectory(currentpath + dirent.name + "/");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pushdirectory("./routes/");
|
|
||||||
|
|
||||||
swaggerAutogen(tempFile, endpointsFiles, doc);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Replace some error codes with own error codes, as described in error_codes.txt
|
|
||||||
*/
|
|
||||||
const to_replace = {
|
|
||||||
"401": "login error (invalid cookie)",
|
|
||||||
"402": "login error (bad cookie)",
|
|
||||||
"403": "login error (no cookie)",
|
|
||||||
|
|
||||||
"410": "argument/data error",
|
|
||||||
"411": "argument/data error",
|
|
||||||
"412": "argument/data error",
|
|
||||||
"413": "argument/data error",
|
|
||||||
"414": "argument/data error",
|
|
||||||
"415": "argument/data error",
|
|
||||||
"416": "argument/data error",
|
|
||||||
"417": "argument/data error",
|
|
||||||
"418": "argument/data error",
|
|
||||||
"419": "argument/data error",
|
|
||||||
"420": "invalid authetication object",
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let file = JSON.parse(fs.readFileSync(tempFile, 'utf8'));
|
|
||||||
|
|
||||||
for (let path in file.paths) {
|
|
||||||
for (let method in file.paths[path]) {
|
|
||||||
for (let response in file.paths[path][method].responses) {
|
|
||||||
if (to_replace[response]) {
|
|
||||||
file.paths[path][method].responses[response].description = to_replace[response];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file = JSON.stringify(file);
|
|
||||||
console.log(file)
|
|
||||||
fs.writeFileSync(outputFile, file);
|
|
||||||
fs.rmSync(tempFile);
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>IPost Privacy Policy</title>
|
<title>IPost Privacy Policy</title>
|
||||||
<meta name="description" content="IPosts PrivacyPolicy">
|
<meta name="description" content="IPosts PrivacyPolicy">
|
||||||
|
<%- newrelic %>
|
||||||
<script>
|
<script>
|
||||||
<%- warnmessagejs %>
|
<%- warnmessagejs %>
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>IPost Terms of Service</title>
|
<title>IPost Terms of Service</title>
|
||||||
|
<%- newrelic %>
|
||||||
<meta name="description" content="IPosts Terms of Service">
|
<meta name="description" content="IPosts Terms of Service">
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||||
<script src="/js/warn_message.js" charset="utf-8"></script>
|
<script src="/js/warn_message.js" charset="utf-8"></script>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,6 @@
|
|||||||
<p>Please authorize the app "<%= application.application_name %>" to access your information:</p>
|
<p>Please authorize the app "<%= application.application_name %>" to access your information:</p>
|
||||||
<form action="/authorize" method="post">
|
<form action="/authorize" method="post">
|
||||||
<input type="number" value=<%= query.id %> class="hidden" name="application_id" id="application_id">
|
<input type="number" value=<%= query.id %> class="hidden" name="application_id" id="application_id">
|
||||||
<input type="number" value=<%= query.extra || "" %> class="hidden" name="application_extra" id="application_extra">
|
|
||||||
<div class="h-captcha" data-sitekey="<%- hcaptcha_sitekey %>"></div>
|
<div class="h-captcha" data-sitekey="<%- hcaptcha_sitekey %>"></div>
|
||||||
<input type="submit" value="Authorize">
|
<input type="submit" value="Authorize">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
<% if(user.username === undefined) { %>
|
<% if(user.username === undefined) { %>
|
||||||
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<%- newrelic %>
|
||||||
<style>
|
<style>
|
||||||
<%- globalcss %>
|
<%- globalcss %>
|
||||||
<%- loadfile("./css/posts.css") %>
|
<%- loadfile("./css/posts.css") %>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>IPost</title>
|
<title>IPost</title>
|
||||||
<meta name="description" content="<%-unauthorized_description%>">
|
<meta name="description" content="<%-unauthorized_description%>">
|
||||||
|
<%- newrelic %>
|
||||||
<style>
|
<style>
|
||||||
<%- globalcss %>
|
<%- globalcss %>
|
||||||
<%- loadfile("./css/logon.css") %>
|
<%- loadfile("./css/logon.css") %>
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Login | IPost</title>
|
<title>Login | IPost</title>
|
||||||
<meta name="description" content="Chat on IPost by logging in today">
|
<meta name="description" content="Chat on IPost by logging in today">
|
||||||
|
<%- newrelic %>
|
||||||
<link rel="stylesheet" href="/css/logon.css">
|
<link rel="stylesheet" href="/css/logon.css">
|
||||||
<script src="/js/warn_message.js" charset="utf-8"></script>
|
<script src="/js/warn_message.js" charset="utf-8"></script>
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>USERS Page</title>
|
<title>USERS Page</title>
|
||||||
<meta name="description" content="view other users pages on IPost today">
|
<meta name="description" content="view other users pages on IPost today">
|
||||||
|
<%- newrelic %>
|
||||||
<link rel="stylesheet" href="/css/style.css">
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
<link rel="stylesheet" href="/css/global.css">
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
<meta name="description" content="Chat on IPost now">
|
<meta name="description" content="Chat on IPost now">
|
||||||
<% } %>
|
<% } %>
|
||||||
<title>Posts | IPost</title>
|
<title>Posts | IPost</title>
|
||||||
|
<%- newrelic %>
|
||||||
<style>
|
<style>
|
||||||
<%- globalcss %>
|
<%- globalcss %>
|
||||||
<%- loadfile("./css/posts.css") %>
|
<%- loadfile("./css/posts.css") %>
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" dir="ltr">
|
<html lang="en" dir="ltr">
|
||||||
<head>
|
<head>
|
||||||
|
<%- newrelic %>
|
||||||
<link rel="stylesheet" href="/css/logon.css">
|
<link rel="stylesheet" href="/css/logon.css">
|
||||||
<script src="/js/warn_message.js" charset="utf-8"></script>
|
<script src="/js/warn_message.js" charset="utf-8"></script>
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
<% } else { %>
|
<% } else { %>
|
||||||
<meta name="description" content="search IPost now">
|
<meta name="description" content="search IPost now">
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<%- newrelic %>
|
||||||
<link rel="stylesheet" href="/css/search.css">
|
<link rel="stylesheet" href="/css/search.css">
|
||||||
<script type="text/javascript" src="/js/htmlescape.js"></script>
|
<script type="text/javascript" src="/js/htmlescape.js"></script>
|
||||||
<link rel="stylesheet" href="/css/global.css">
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
<% if(user.username === undefined) { %>
|
<% if(user.username === undefined) { %>
|
||||||
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<%- newrelic %>
|
||||||
<link rel="stylesheet" href="/css/style.css">
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
<link rel="stylesheet" href="/css/global.css">
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
<script src="/js/addnavbar.js" charset="utf-8"></script>
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
<% if(user.username === undefined) { %>
|
<% if(user.username === undefined) { %>
|
||||||
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
<script> document.location.href = '/no_login?r='+encodeURIComponent(document.location.pathname) </script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<%- newrelic %>
|
||||||
<style>
|
<style>
|
||||||
<%- globalcss %>
|
<%- globalcss %>
|
||||||
<%- loadfile("./css/style.css") %>
|
<%- loadfile("./css/style.css") %>
|
||||||
|
|||||||
Reference in New Issue
Block a user