From 5f79584917d9dd57777dfc7e991a4226736eec99 Mon Sep 17 00:00:00 2001 From: Joabutt <89288499+Joabutt@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:46:05 +0800 Subject: [PATCH] new --- .deta/prog_info | 2 +- .deta/state | 2 +- .env | 1 + .github/workflows/deta.yml | 17 ----- .gitignore | 1 - domains/john.json | 2 +- domains/semant.json | 5 ++ index.js | 2 +- tmp/JSON_TEMPLATE.md | 14 ++++ tmp/README.md | 39 +++++++++++ tmp/domains.json | 6 ++ tmp/domains/joabutt.json | 5 ++ tmp/domains/john.json | 5 ++ tmp/domains/nico.json | 5 ++ tmp/domains/semant.json | 5 ++ tmp/domains/slime.json | 5 ++ tmp/index.js | 124 +++++++++++++++++++++++++++++++++++ tmp/package.json | 19 ++++++ tmp/tmp/JSON_TEMPLATE.md | 14 ++++ tmp/tmp/README.md | 39 +++++++++++ tmp/tmp/domains.json | 6 ++ tmp/tmp/domains/joabutt.json | 5 ++ tmp/tmp/domains/john.json | 5 ++ tmp/tmp/domains/nico.json | 5 ++ tmp/tmp/domains/slime.json | 5 ++ tmp/tmp/index.js | 124 +++++++++++++++++++++++++++++++++++ tmp/tmp/package.json | 19 ++++++ tmp/tmp/tmp/domains.json | 5 ++ tmp/tmp/tmp/index.js | 123 ++++++++++++++++++++++++++++++++++ tmp/tmp/tmp/package.json | 18 +++++ 30 files changed, 605 insertions(+), 22 deletions(-) create mode 100644 .env delete mode 100644 .github/workflows/deta.yml create mode 100644 domains/semant.json create mode 100644 tmp/JSON_TEMPLATE.md create mode 100644 tmp/README.md create mode 100644 tmp/domains.json create mode 100644 tmp/domains/joabutt.json create mode 100644 tmp/domains/john.json create mode 100644 tmp/domains/nico.json create mode 100644 tmp/domains/semant.json create mode 100644 tmp/domains/slime.json create mode 100644 tmp/index.js create mode 100644 tmp/package.json create mode 100644 tmp/tmp/JSON_TEMPLATE.md create mode 100644 tmp/tmp/README.md create mode 100644 tmp/tmp/domains.json create mode 100644 tmp/tmp/domains/joabutt.json create mode 100644 tmp/tmp/domains/john.json create mode 100644 tmp/tmp/domains/nico.json create mode 100644 tmp/tmp/domains/slime.json create mode 100644 tmp/tmp/index.js create mode 100644 tmp/tmp/package.json create mode 100644 tmp/tmp/tmp/domains.json create mode 100644 tmp/tmp/tmp/index.js create mode 100644 tmp/tmp/tmp/package.json diff --git a/.deta/prog_info b/.deta/prog_info index 27230cf..00b8097 100644 --- a/.deta/prog_info +++ b/.deta/prog_info @@ -1 +1 @@ -{"id":"7794ff83-856d-4aba-a760-46d0507b13d9","space":34102,"runtime":"nodejs14.x","name":"api","path":"4z2do1","project":"c08joyf8","account":"144798365827","region":"ap-southeast-1","deps":["axios@^1.1.3","express@^4.18.2","fs@^0.0.1-security","json-format@^1.0.1"],"envs":null,"public":true,"log_level":"debug","cron":""} \ No newline at end of file +{"id":"7794ff83-856d-4aba-a760-46d0507b13d9","space":34102,"runtime":"nodejs14.x","name":"api","path":"4z2do1","project":"c08joyf8","account":"144798365827","region":"ap-southeast-1","deps":["axios@^1.1.3","express@^4.18.2","fs@^0.0.1-security","json-format@^1.0.1","dotenv@^16.0.3"],"envs":["API_KEY"],"public":true,"log_level":"debug","cron":""} \ No newline at end of file diff --git a/.deta/state b/.deta/state index 8a4acab..d522cea 100644 --- a/.deta/state +++ b/.deta/state @@ -1 +1 @@ -{"JSON_TEMPLATE.md":"abf7511641ebfa924fc03ae5ed861391e69e1cd30837f243833ae5079b169c7a","README.md":"2ac1d7b8c10f9459b1a65047490f4da51be97ff9f4619a0020566dac803e5098","domains.json":"6f3c0658c960f8f5d44a09120bba0d98bf848b2cb6ed3aef16c91ec304ab67d1","domains/joabutt.json":"7fa8908818fad8164130316f3998d083df81dad9a107defaf575baf8360f61e8","domains/john.json":"184be3d793ffd74df26b609e2f2781270aab3378f0b04c8a12a6cd02c5a83c14","domains/nico.json":"bfd57c11374c76423c7c7cf59c34503df062053c52cb01c38e177c8ab92a34dd","domains/slime.json":"3afe10a962cf73bd77cfb6f1b104479aa27d8dec78cf512804b75c71ec1b0d8a","index.js":"bd660095b8e0f90f06dacfa982daa77b7e2600270b14902975fc5ce860bfdf7c","package-lock.json":"cfb3ae51e9593b144506fb5ce782085bf9d72f2cc3a2fffcb920ab247bd2ac6e","package.json":"03a5b9cb9a33f7f9222e9bb973d864f208ceb51f29eb2c078c6538bd9d478235"} \ No newline at end of file +{"JSON_TEMPLATE.md":"abf7511641ebfa924fc03ae5ed861391e69e1cd30837f243833ae5079b169c7a","README.md":"2ac1d7b8c10f9459b1a65047490f4da51be97ff9f4619a0020566dac803e5098","domains.json":"332c71352b6b625f6d64889d9d2dc85099dbff48f38f0afd404be38254903c96","domains/joabutt.json":"7fa8908818fad8164130316f3998d083df81dad9a107defaf575baf8360f61e8","domains/john.json":"184be3d793ffd74df26b609e2f2781270aab3378f0b04c8a12a6cd02c5a83c14","domains/nico.json":"bfd57c11374c76423c7c7cf59c34503df062053c52cb01c38e177c8ab92a34dd","domains/slime.json":"3afe10a962cf73bd77cfb6f1b104479aa27d8dec78cf512804b75c71ec1b0d8a","index.js":"c92d8e4abd1d54191fb6cf5d338083165febdc0f27dca5cfd58e40f7f71f03df","package-lock.json":"06bef6d7bb7bd9e1bcbb2b61340a9f5ad35490e712a98a4ace76033c4a2c80d3","package.json":"4f7b892a40391aa1d6825f8eab43ca6d7dba1144b0e88d88ed237856730fc901"} \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 0000000..5aa55bf --- /dev/null +++ b/.env @@ -0,0 +1 @@ +API_KEY=60e5bb86dec42085c58ae1a85ede97a44f00c \ No newline at end of file diff --git a/.github/workflows/deta.yml b/.github/workflows/deta.yml deleted file mode 100644 index 098cbea..0000000 --- a/.github/workflows/deta.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Deploy to Deta -on: - pull_request_target: - types: - - closed - -jobs: - if_merged: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 #Be sure you check-out the repo first. Deta CLI needs access to the files - - uses: BogDAAAMN/deta-deploy-action@v1.0.1 - with: - deta-access-token: ${{ secrets.DETA_TOKEN }} #Deta access token https://docs.deta.sh/docs/cli/auth - deta-name: 'api' #Deta Micro name https://docs.deta.sh/docs/cli/commands/#deta-clone - deta-project-dir: './api' #Optional: directory to be deployed on Deta. Default is the root "." diff --git a/.gitignore b/.gitignore index d1420be..f846c68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules package-lock.json yarn.lock -.env \ No newline at end of file diff --git a/domains/john.json b/domains/john.json index 7a9ffad..587e956 100644 --- a/domains/john.json +++ b/domains/john.json @@ -1,5 +1,5 @@ { "subdomain": "john", "url": "joabuttisadev.pages.dev", - "email": "john@gmail.com" + "email": "leejoab75@gmail.com" } diff --git a/domains/semant.json b/domains/semant.json new file mode 100644 index 0000000..49c4cee --- /dev/null +++ b/domains/semant.json @@ -0,0 +1,5 @@ +{ + "subdomain": "semant", + "url": "semant.is-a.dev", + "email": "contact@semant.is-a.dev" +} diff --git a/index.js b/index.js index b6770a6..e243f8c 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,7 @@ app.get("/addnew", async (req, res) => { const finalname = filename.replaceAll(".json",""); - const response = await axios.get(`http://localhost:3000/check/${finalname}`).then((response) => { + const response = await axios.get(`https://api.is-really.cool/check/${finalname}`).then((response) => { if (response.data == "unavailable"){ console.log(`${finalname}.is-really.cool is already present.`) diff --git a/tmp/JSON_TEMPLATE.md b/tmp/JSON_TEMPLATE.md new file mode 100644 index 0000000..eeea10d --- /dev/null +++ b/tmp/JSON_TEMPLATE.md @@ -0,0 +1,14 @@ +## Template for json file under domains folder + +Please follow the template given here or your pull request will not be accepted or merged. + +### IMPORTANT: Please name your JSON file the subdomain you wish to have. If your subdomain in the JSON file does not match the file name, your PR will NOT be merged. Also please do **NOT** have a comma after your email, as it will cause internal server errors. Please do not add any line breaks in your json. + +## Template: +``` +{ + "subdomain": "YOUR_SUBDOMAIN_HERE", + "record": "YOUR_SITE_URL_HERE", + "email": "YOUR_EMAIL_HERE" +} +``` diff --git a/tmp/README.md b/tmp/README.md new file mode 100644 index 0000000..92f96c6 --- /dev/null +++ b/tmp/README.md @@ -0,0 +1,39 @@ +

is-really.cool is A place for software devs to host their really cool projects and personal websites for Free
+ +## About + +We are a group of people who want to help developers have a platform to showcase their projects and websites, while being absolutely 100% free at the same time. Our goal is to allow developers have a place to showcase their talents and skills while also giving others a way to access and view their work. We offer a free subdomain on is-really.cool, like `foo.is-really.cool` or `bar.is-really.cool` for your sites with the [CNAME record](https://en.wikipedia.org/wiki/CNAME_record). + + +## Registration + +1. Create a static site with some hosting providers, some being: [Github pages](https://pages.github.com), [Surge](https://surge.sh), etc. +2. After setting up your site, [Fork](https://github.com/is-really-cool/register/fork) this repo and under the domains folder, then read the file template [Here](https://github.com/is-really-cool/register/blob/main/JSON_TEMPLATE.md). If yourfile does not follow the required template, your pull request will **NOT** be merged. After reading the template, you can add your json file under the domains folder, and then create a pull request. +3. Send your pull request, and your request will be reviewed and if the requirements are met, will be merged. Do keep an eye on it!~ +4. After your request has been merged, please give us up to 24 hours for the servers to propagate the changes. +5. Enjoy your new `is-really.cool` domain!! 🥳 + +## Similar Services +- [is-a-good.dev](https://github.com/is-a-good-dev/Register) +- [is-not-a.dev](https://is-not-a.dev) +- [cluster.ws & wip.la](https://github.com/Olivr/free-domain) +- [js.org](https://github.com/js-org/js.org/tree/master) (*JavaScript projects only*) +- [is-a.dev](https://github.com/is-a-dev/register) + +## Donate + +This service cannot be going on forever without your help, Thank you all! +[](https://ko-fi.com/E1E8GE56L) + +## Contact + +You can contact us at help@is-really.cool + + +## Thanks +Thanks to is-a.dev and thedev.id for the huge help and inspiration in this project. More updates will be pushed out soon! + diff --git a/tmp/domains.json b/tmp/domains.json new file mode 100644 index 0000000..ef8091e --- /dev/null +++ b/tmp/domains.json @@ -0,0 +1,6 @@ +[ + "joabutt", + "john", + "nico", + "slime" +] \ No newline at end of file diff --git a/tmp/domains/joabutt.json b/tmp/domains/joabutt.json new file mode 100644 index 0000000..0959caa --- /dev/null +++ b/tmp/domains/joabutt.json @@ -0,0 +1,5 @@ +{ + "subdomain": "joabutt", + "url": "joabuttisadev.pages.dev", + "email": "me@joabutt.dev" +} diff --git a/tmp/domains/john.json b/tmp/domains/john.json new file mode 100644 index 0000000..587e956 --- /dev/null +++ b/tmp/domains/john.json @@ -0,0 +1,5 @@ +{ + "subdomain": "john", + "url": "joabuttisadev.pages.dev", + "email": "leejoab75@gmail.com" +} diff --git a/tmp/domains/nico.json b/tmp/domains/nico.json new file mode 100644 index 0000000..fa5b294 --- /dev/null +++ b/tmp/domains/nico.json @@ -0,0 +1,5 @@ +{ + "subdomain": "nico", + "url": "nico.is-a.dev", + "email": "nicodreyer7@icloud.com" +} diff --git a/tmp/domains/semant.json b/tmp/domains/semant.json new file mode 100644 index 0000000..49c4cee --- /dev/null +++ b/tmp/domains/semant.json @@ -0,0 +1,5 @@ +{ + "subdomain": "semant", + "url": "semant.is-a.dev", + "email": "contact@semant.is-a.dev" +} diff --git a/tmp/domains/slime.json b/tmp/domains/slime.json new file mode 100644 index 0000000..590c1d9 --- /dev/null +++ b/tmp/domains/slime.json @@ -0,0 +1,5 @@ +{ + "subdomain": "slime", + "url": "slimeu.glitch.me", + "email": "purpleblueslime@gmail.com" +} diff --git a/tmp/index.js b/tmp/index.js new file mode 100644 index 0000000..b6770a6 --- /dev/null +++ b/tmp/index.js @@ -0,0 +1,124 @@ + +const express = require('express') +const app = express() +const PORT = 3000 +const axios = require("axios") +const fs = require("fs") +const jsonFormat = require("json-format"); +app.listen(PORT, () => console.log(`Coffee ready at ${PORT}, Caffeine ftw`)) +require('dotenv').config(); + + + + +app.get("/check/:subdomain", async (req, res) => { + + + const response = await axios.get(`https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records?type=CNAME&name=${req.params.subdomain}.is-really.cool`, { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': process.env.API_KEY, + 'Content-Type': 'application/json' + } + }); + + + + + if (response.data.result.length === 0) { + res.send("available") + + } else { + res.send("unavailable") + + } +}) + + +app.get("/addnew", async (req, res) => { + + + + fs.promises.readdir("./domains").then(filenames => { + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + }) + + + fs.promises.readdir("./domains") + .then(async filenames => { + + + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + + fs.writeFile('./domains.json',jsonFormat(finalreal),function(err){ + if(err) console.log("error:" + err); + + }) + + for (let filename of filenames) { + + const finalname = filename.replaceAll(".json",""); + + const response = await axios.get(`http://localhost:3000/check/${finalname}`).then((response) => { + + if (response.data == "unavailable"){ + console.log(`${finalname}.is-really.cool is already present.`) + } else if (response.data == "available"){ + const prefinal = JSON.stringify(filename) + const final = prefinal.replaceAll(".json", ""); + const realfinal = final.replaceAll('"', '') + + const filedata = fs.promises.readFile(`./domains/${filename}`) + .then(async function(result) { + const newres = JSON.parse(result) + + const realresult = newres.url + const response = await axios.post( + 'https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records', + { + 'type': 'CNAME', + 'name': realfinal, + 'content': realresult, + 'ttl': 1, + 'priority': 10, + 'proxied': true + }, + { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': process.env.API_KEY, + 'Content-Type': 'application/json' + } + } + ); + + + if(response.data.success == true){ + console.log(`${finalname}.is-really.cool has been successfully added!`) + + } + }) + } + }) + + + + + } + + }) + res.sendStatus(200); +}) + + + +// export 'app' +module.exports = app diff --git a/tmp/package.json b/tmp/package.json new file mode 100644 index 0000000..ee2b036 --- /dev/null +++ b/tmp/package.json @@ -0,0 +1,19 @@ +{ + "name": "api", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "axios": "^1.1.3", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "fs": "^0.0.1-security", + "json-format": "^1.0.1" + } +} diff --git a/tmp/tmp/JSON_TEMPLATE.md b/tmp/tmp/JSON_TEMPLATE.md new file mode 100644 index 0000000..eeea10d --- /dev/null +++ b/tmp/tmp/JSON_TEMPLATE.md @@ -0,0 +1,14 @@ +## Template for json file under domains folder + +Please follow the template given here or your pull request will not be accepted or merged. + +### IMPORTANT: Please name your JSON file the subdomain you wish to have. If your subdomain in the JSON file does not match the file name, your PR will NOT be merged. Also please do **NOT** have a comma after your email, as it will cause internal server errors. Please do not add any line breaks in your json. + +## Template: +``` +{ + "subdomain": "YOUR_SUBDOMAIN_HERE", + "record": "YOUR_SITE_URL_HERE", + "email": "YOUR_EMAIL_HERE" +} +``` diff --git a/tmp/tmp/README.md b/tmp/tmp/README.md new file mode 100644 index 0000000..92f96c6 --- /dev/null +++ b/tmp/tmp/README.md @@ -0,0 +1,39 @@ +
is-really.cool is A place for software devs to host their really cool projects and personal websites for Free
+ +## About + +We are a group of people who want to help developers have a platform to showcase their projects and websites, while being absolutely 100% free at the same time. Our goal is to allow developers have a place to showcase their talents and skills while also giving others a way to access and view their work. We offer a free subdomain on is-really.cool, like `foo.is-really.cool` or `bar.is-really.cool` for your sites with the [CNAME record](https://en.wikipedia.org/wiki/CNAME_record). + + +## Registration + +1. Create a static site with some hosting providers, some being: [Github pages](https://pages.github.com), [Surge](https://surge.sh), etc. +2. After setting up your site, [Fork](https://github.com/is-really-cool/register/fork) this repo and under the domains folder, then read the file template [Here](https://github.com/is-really-cool/register/blob/main/JSON_TEMPLATE.md). If yourfile does not follow the required template, your pull request will **NOT** be merged. After reading the template, you can add your json file under the domains folder, and then create a pull request. +3. Send your pull request, and your request will be reviewed and if the requirements are met, will be merged. Do keep an eye on it!~ +4. After your request has been merged, please give us up to 24 hours for the servers to propagate the changes. +5. Enjoy your new `is-really.cool` domain!! 🥳 + +## Similar Services +- [is-a-good.dev](https://github.com/is-a-good-dev/Register) +- [is-not-a.dev](https://is-not-a.dev) +- [cluster.ws & wip.la](https://github.com/Olivr/free-domain) +- [js.org](https://github.com/js-org/js.org/tree/master) (*JavaScript projects only*) +- [is-a.dev](https://github.com/is-a-dev/register) + +## Donate + +This service cannot be going on forever without your help, Thank you all! +[](https://ko-fi.com/E1E8GE56L) + +## Contact + +You can contact us at help@is-really.cool + + +## Thanks +Thanks to is-a.dev and thedev.id for the huge help and inspiration in this project. More updates will be pushed out soon! + diff --git a/tmp/tmp/domains.json b/tmp/tmp/domains.json new file mode 100644 index 0000000..ef8091e --- /dev/null +++ b/tmp/tmp/domains.json @@ -0,0 +1,6 @@ +[ + "joabutt", + "john", + "nico", + "slime" +] \ No newline at end of file diff --git a/tmp/tmp/domains/joabutt.json b/tmp/tmp/domains/joabutt.json new file mode 100644 index 0000000..0959caa --- /dev/null +++ b/tmp/tmp/domains/joabutt.json @@ -0,0 +1,5 @@ +{ + "subdomain": "joabutt", + "url": "joabuttisadev.pages.dev", + "email": "me@joabutt.dev" +} diff --git a/tmp/tmp/domains/john.json b/tmp/tmp/domains/john.json new file mode 100644 index 0000000..7a9ffad --- /dev/null +++ b/tmp/tmp/domains/john.json @@ -0,0 +1,5 @@ +{ + "subdomain": "john", + "url": "joabuttisadev.pages.dev", + "email": "john@gmail.com" +} diff --git a/tmp/tmp/domains/nico.json b/tmp/tmp/domains/nico.json new file mode 100644 index 0000000..fa5b294 --- /dev/null +++ b/tmp/tmp/domains/nico.json @@ -0,0 +1,5 @@ +{ + "subdomain": "nico", + "url": "nico.is-a.dev", + "email": "nicodreyer7@icloud.com" +} diff --git a/tmp/tmp/domains/slime.json b/tmp/tmp/domains/slime.json new file mode 100644 index 0000000..590c1d9 --- /dev/null +++ b/tmp/tmp/domains/slime.json @@ -0,0 +1,5 @@ +{ + "subdomain": "slime", + "url": "slimeu.glitch.me", + "email": "purpleblueslime@gmail.com" +} diff --git a/tmp/tmp/index.js b/tmp/tmp/index.js new file mode 100644 index 0000000..b6770a6 --- /dev/null +++ b/tmp/tmp/index.js @@ -0,0 +1,124 @@ + +const express = require('express') +const app = express() +const PORT = 3000 +const axios = require("axios") +const fs = require("fs") +const jsonFormat = require("json-format"); +app.listen(PORT, () => console.log(`Coffee ready at ${PORT}, Caffeine ftw`)) +require('dotenv').config(); + + + + +app.get("/check/:subdomain", async (req, res) => { + + + const response = await axios.get(`https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records?type=CNAME&name=${req.params.subdomain}.is-really.cool`, { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': process.env.API_KEY, + 'Content-Type': 'application/json' + } + }); + + + + + if (response.data.result.length === 0) { + res.send("available") + + } else { + res.send("unavailable") + + } +}) + + +app.get("/addnew", async (req, res) => { + + + + fs.promises.readdir("./domains").then(filenames => { + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + }) + + + fs.promises.readdir("./domains") + .then(async filenames => { + + + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + + fs.writeFile('./domains.json',jsonFormat(finalreal),function(err){ + if(err) console.log("error:" + err); + + }) + + for (let filename of filenames) { + + const finalname = filename.replaceAll(".json",""); + + const response = await axios.get(`http://localhost:3000/check/${finalname}`).then((response) => { + + if (response.data == "unavailable"){ + console.log(`${finalname}.is-really.cool is already present.`) + } else if (response.data == "available"){ + const prefinal = JSON.stringify(filename) + const final = prefinal.replaceAll(".json", ""); + const realfinal = final.replaceAll('"', '') + + const filedata = fs.promises.readFile(`./domains/${filename}`) + .then(async function(result) { + const newres = JSON.parse(result) + + const realresult = newres.url + const response = await axios.post( + 'https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records', + { + 'type': 'CNAME', + 'name': realfinal, + 'content': realresult, + 'ttl': 1, + 'priority': 10, + 'proxied': true + }, + { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': process.env.API_KEY, + 'Content-Type': 'application/json' + } + } + ); + + + if(response.data.success == true){ + console.log(`${finalname}.is-really.cool has been successfully added!`) + + } + }) + } + }) + + + + + } + + }) + res.sendStatus(200); +}) + + + +// export 'app' +module.exports = app diff --git a/tmp/tmp/package.json b/tmp/tmp/package.json new file mode 100644 index 0000000..ee2b036 --- /dev/null +++ b/tmp/tmp/package.json @@ -0,0 +1,19 @@ +{ + "name": "api", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "axios": "^1.1.3", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "fs": "^0.0.1-security", + "json-format": "^1.0.1" + } +} diff --git a/tmp/tmp/tmp/domains.json b/tmp/tmp/tmp/domains.json new file mode 100644 index 0000000..9aa9f1f --- /dev/null +++ b/tmp/tmp/tmp/domains.json @@ -0,0 +1,5 @@ +[ + "joabutt", + "nico", + "slime" +] \ No newline at end of file diff --git a/tmp/tmp/tmp/index.js b/tmp/tmp/tmp/index.js new file mode 100644 index 0000000..67f5baa --- /dev/null +++ b/tmp/tmp/tmp/index.js @@ -0,0 +1,123 @@ + +const express = require('express') +const app = express() +const PORT = 3000 +const axios = require("axios") +const fs = require("fs") +const jsonFormat = require("json-format"); +app.listen(PORT, () => console.log(`Coffee ready at ${PORT}, Caffeine ftw`)) + + + + +app.get("/check/:subdomain", async (req, res) => { + + + const response = await axios.get(`https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records?type=CNAME&name=${req.params.subdomain}.is-really.cool`, { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': '60e5bb86dec42085c58ae1a85ede97a44f00c', + 'Content-Type': 'application/json' + } + }); + + + + + if (response.data.result.length === 0) { + res.send("available") + + } else { + res.send("unavailable") + + } +}) + + +app.get("/addnew", async (req, res) => { + + + + fs.promises.readdir("../domains").then(filenames => { + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + }) + + + fs.promises.readdir("../domains") + .then(async filenames => { + + + + const prefinal = JSON.stringify(filenames) + const final = prefinal.replaceAll(".json", ""); + const finalreal = JSON.parse(final) + + + fs.writeFile('./domains.json',jsonFormat(finalreal),function(err){ + if(err) console.log("error:" + err); + + }) + + for (let filename of filenames) { + + const finalname = filename.replaceAll(".json",""); + + const response = await axios.get(`http://localhost:3000/check/${finalname}`).then((response) => { + + if (response.data == "unavailable"){ + console.log(`${finalname}.is-really.cool is already present.`) + } else if (response.data == "available"){ + const prefinal = JSON.stringify(filename) + const final = prefinal.replaceAll(".json", ""); + const realfinal = final.replaceAll('"', '') + + const filedata = fs.promises.readFile(`../domains/${filename}`) + .then(async function(result) { + const newres = JSON.parse(result) + + const realresult = newres.url + const response = await axios.post( + 'https://api.cloudflare.com/client/v4/zones/d76cdc117a7173dd501a5f212176c203/dns_records', + { + 'type': 'CNAME', + 'name': realfinal, + 'content': realresult, + 'ttl': 1, + 'priority': 10, + 'proxied': true + }, + { + headers: { + 'X-Auth-Email': 'leejoab75@gmail.com', + 'X-Auth-Key': '60e5bb86dec42085c58ae1a85ede97a44f00c', + 'Content-Type': 'application/json' + } + } + ); + + + if(response.data.success == true){ + console.log(`${finalname}.is-really.cool has been successfully added!`) + + } + }) + } + }) + + + + + } + + }) + res.sendStatus(200); +}) + + + +// export 'app' +module.exports = app \ No newline at end of file diff --git a/tmp/tmp/tmp/package.json b/tmp/tmp/tmp/package.json new file mode 100644 index 0000000..783fe91 --- /dev/null +++ b/tmp/tmp/tmp/package.json @@ -0,0 +1,18 @@ +{ + "name": "api", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "axios": "^1.1.3", + "express": "^4.18.2", + "fs": "^0.0.1-security", + "json-format": "^1.0.1" + } +}