From b802e58af60ed517b176f465048bbf8a90af0bf2 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:04:25 -0800 Subject: [PATCH] working changes for redeployment --- config.example.json | 5 ++++ routes/etyd.js | 66 +++++++++++++++++++++++++++++++++++++++++++++ routes/ip.js | 30 +++++---------------- 3 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 routes/etyd.js diff --git a/config.example.json b/config.example.json index 05905d6..caddf19 100644 --- a/config.example.json +++ b/config.example.json @@ -19,6 +19,11 @@ "authKeyInDb": "apiAuthKeys.azure", "usageKeyPrefix": "apiUsage.azure." + }, + + "etyd": { + "randomHexLength": 6, + "authKeyInDb": "apiAuthKeys.etyd" } } \ No newline at end of file diff --git a/routes/etyd.js b/routes/etyd.js new file mode 100644 index 0000000..17d1cf4 --- /dev/null +++ b/routes/etyd.js @@ -0,0 +1,66 @@ +const { app, db, globalConfig } = require("../index.js") // Get globals from index + +function makeRandomHex() { + const characters = "1234567890abcdef" + let counter = 0 + let result = "" + while (counter < globalConfig.etyd.randomHexLength) { + result += characters.charAt(Math.floor(Math.random() * characters.length)) + counter += 1 + } + return result +} + +app.options("/etydwrite", (rreq,rres) => { + rres.set("Access-Control-Allow-Headers","Authorization") + rres.set("Access-Control-Allow-Origin","*") + rres.sendStatus(204) +}) + +// app.post("/etydwrite", (rreq,rres) => { +// db.get(globalConfig.etyd.authKeyInDb).then(dbres => { + +// if (dbres == null) { // If authkey key doesnt exist in redis then error out +// console.log("ERROR: Configured key containing etyd authkeys is null") +// rres.sendStatus(500) +// } else { // if it does exist +// let validKeys = dbres.split(",") // split the string into an array +// if (validKeys.includes(rreq.get("Authorization"))) { // check if authorization header key exists in that array + +// console.log(rreq.body) + +// switch(rreq.body.action) { +// case "set": // Write to db +// if (rreq.body.random == true) { +// let workingTarget = makeRandomHex() + +// } + + +// case "delete": +// db.get(rreq.body.target).then(dbres => { +// if (dbres == null) { //if key doesnt exist then log and return 400 +// console.log(`${rreq.get("cf-connecting-ip")} POST /etydwrite ACTION delete returned 400 KEY:${rreq.get("Authorization")}`) +// rres.set("Access-Control-Allow-Origin","*") +// rres.sendStatus(400) +// } else { + +// } +// }) + + +// default: +// rres.set("Access-Control-Allow-Origin","*") +// rres.sendStatus(400) // request json didnt include a valid action +// } + +// } else { // if it doesnt then its a unauthorized request +// console.log(`${rreq.get("cf-connecting-ip")} POST /etydwrite returned 401`) +// rres.set("Access-Control-Allow-Origin","*") +// rres.sendStatus(401) +// } +// } +// }) +// }) + +module.exports = {app} // export routes to be imported by index for execution \ No newline at end of file diff --git a/routes/ip.js b/routes/ip.js index 69f0c06..d955900 100644 --- a/routes/ip.js +++ b/routes/ip.js @@ -1,31 +1,13 @@ const { app } = require("../index.js") app.get("/ip", (rreq,rres) => { - rres.send(` - -
- ▐▀▄ ▄▀▌ ▄▄▄▄▄▄▄
- ▌▒▒▀▄▄▄▄▄▀▒▒▐▄▀▀▒██▒██▒▀▀▄
- ▐▒▒▒▒▀▒▀▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄
- ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▒▒▒▒▒▒▒▒▀▄
- ▀█▒▒▒█▌▒▒█▒▒▐█▒▒▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
- ▀▌▒▒▒▒▒▒▀▒▀▒▒▒▒▒▒▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ▄▄
- ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▄█▒█
- ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒█▀
- ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
- ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
- ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
- ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
- ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
- ▐▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▌
- ▀▄▄▀▀▀▀▀▄▄▀▀▀▀▀▀▀▄▄▀▀▀▀▀▄▄▀
-
- CF-Connecting-IP: ${rreq.get("cf-connecting-ip")}
- `)
-})
+ let jsonResponse = {
+ "IP": rreq.get("cf-connecting-ip") || "you_did",
+ "Country": rreq.get("cf-ipcountry") || "not_connect",
+ "CfRay": rreq.get("cf-ray") || "via_cloudflare"
+ }
-app.get("/iplain", (rreq,rres) => {
- rres.send(rreq.get("cf-connecting-ip"))
+ rres.send(jsonResponse);
})
module.exports = {app}
\ No newline at end of file