From cd7cb282800ca9c6e53e969376aeeed22f903b09 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Sun, 8 May 2022 15:33:16 -0400 Subject: [PATCH] added https --- .gitignore | 3 ++- README.md | 12 ++++++++++-- index.js | 17 +++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f5be58f..92658f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules - *.log +ip-addresses.log +cert \ No newline at end of file diff --git a/README.md b/README.md index 1ae8fe8..418b60c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # IP Grabber + Logs the client IPv4 address and redirects them to a target website using Node.js. -The grabber will redirect the client to the first commandline argument (a link or IP) if it exists. Otherwise, it will use the default link defined in the code. A Node.js server will be hosted on port 3030 (by default) when script is running. -If you plan on using this script, edit where the `address.log` file is created. +The grabber will redirect the client to the first commandline argument (a link or IP) if it exists. Otherwise, it will use the default link defined in the code. 2 Node.js servers will be hosted on port 3030 (HTTP) and port 3031 (HTTPS) by default. +If you plan on using HTTPS, you can generate a certificate using these commands: + +```sh +openssl genrsa -out key.pem +openssl req -new -key key.pem -out csr.pem +openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem +mkdir cert && mv cert.pem key.pem cert && rm csr.pem +``` diff --git a/index.js b/index.js index 273ce49..112cef8 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,26 @@ const connect = require('connect'); const http = require('http'); +const https = require('https'); const file = require('fs'); const requestIp = require('request-ip'); const redirect = require('connect-redirection') -let redirectURL = 'https://arrayinamatrix.xyz/res/site/images/trollface.gif' +const redirectURL = 'https://arrayinamatrix.xyz/res/site/images/trollface.gif' if (process.argv[2] != undefined) { redirectURL = process.argv[2] } -let logFile = 'ip-addresses.log' -let httpPort = 3030 +const logFile = 'ip-addresses.log' +const httpPort = 3030 +const httpsPort = 3031 + +const options = { + key: file.readFileSync('cert/key.pem'), + cert: file.readFileSync('cert/cert.pem') +}; console.log(`Redirect: ${redirectURL}`); -console.log(`Port: ${httpPort}`) +console.log(`HTTP Port: ${httpPort}`) +console.log(`HTTPS Port: ${httpsPort}`) console.log(`Log file location: ${logFile}`) console.log("########## IP LOGGER STARTED ##########"); @@ -45,3 +53,4 @@ const app = connect() }); http.createServer(app).listen(httpPort); +https.createServer(options, app).listen(httpsPort); \ No newline at end of file