-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Oct 17, 2023
0 parents
commit c01b601
Showing
8 changed files
with
1,183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const http = require('http'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
|
||
// CONFIGURATION | ||
const prefix = '/web'; // Set your prefix here | ||
const localAddresses = []; // Set your local addresses here | ||
const blockedHostnames = ["https://sevenworks.eu.org/bad-site"]; // Set your blocked hostnames here | ||
const ssl = false; // Set SSL configuration here | ||
const port = 6969; // Set the desired port | ||
const index_file = 'index.html'; // Set index file shown by the browser | ||
// END OF CONFIGURATION | ||
|
||
const proxy = new (require('./lib/index'))(prefix, { | ||
localAddress: localAddresses, | ||
blacklist: blockedHostnames | ||
}); | ||
|
||
const atob = str => Buffer.from(str, 'base64').toString('utf-8'); | ||
|
||
const app = (req, res) => { | ||
if (req.url.startsWith(prefix)) { | ||
proxy.http(req, res); | ||
return; | ||
} | ||
|
||
req.pathname = req.url.split('#')[0].split('?')[0]; | ||
req.query = {}; | ||
req.url | ||
.split('#')[0] | ||
.split('?') | ||
.slice(1) | ||
.join('?') | ||
.split('&') | ||
.forEach(query => (req.query[query.split('=')[0]] = query.split('=').slice(1).join('='))); | ||
|
||
if (req.query.url && (req.pathname == '/prox' || req.pathname == '/prox/' || req.pathname == '/session' || req.pathname == '/session/')) { | ||
var url = atob(req.query.url); | ||
|
||
if (url.startsWith('https://') || url.startsWith('http://')) url = url; | ||
else if (url.startsWith('//')) url = 'http:' + url; | ||
else url = 'http://' + url; | ||
|
||
res.writeHead(301, { location: prefix + proxy.proxifyRequestURL(url) }); | ||
res.end(''); | ||
return; | ||
} | ||
|
||
const publicPath = __dirname + '/public' + req.pathname; | ||
|
||
const error = () => { | ||
res.statusCode = 404; | ||
res.end(fs.readFileSync(__dirname + '/lib/error.html', 'utf-8').replace('%ERR%', `Cannot ${req.method} ${req.pathname}`)); | ||
}; | ||
|
||
fs.lstat(publicPath, (err, stats) => { | ||
if (err) return error(); | ||
|
||
if (stats.isDirectory()) { | ||
fs.existsSync(publicPath + index_file) ? fs.createReadStream(publicPath + index_file).pipe(res) : error(); | ||
} else if (stats.isFile()) { | ||
!publicPath.endsWith('/') ? fs.createReadStream(publicPath).pipe(res) : error(); | ||
} else { | ||
error(); | ||
} | ||
}); | ||
}; | ||
|
||
const server = ssl | ||
? https.createServer({ key: fs.readFileSync('./ssl/default.key'), cert: fs.readFileSync('./ssl/default.crt') }, app) | ||
: http.createServer(app); | ||
|
||
proxy.ws(server); | ||
server.listen(process.env.PORT || port, () => console.log(`${ssl ? 'https://' : 'http://'}0.0.0.0:${port}`)); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>‌</title> | ||
<meta name="description" content="A no‌de.js web pr‌oxy featuring UR‌L enco‌ding, and amazing compatablity!"> | ||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet"> | ||
<style> | ||
body { | ||
font-family: "Noto Sans JP"; | ||
font-size: "25px"; | ||
text-align: center; | ||
background-color:#222; | ||
} | ||
|
||
.container { | ||
margin-top: 10%; | ||
font-family: "Noto Sans JP"; | ||
font-size: "50px"; | ||
color: #FFF; | ||
|
||
} | ||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>%ERR%</h1> | ||
</div> | ||
<!--Scripts--> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.