Skip to content

Commit

Permalink
tProxy is good now holy moly
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 17, 2023
0 parents commit c01b601
Show file tree
Hide file tree
Showing 8 changed files with 1,183 additions and 0 deletions.
74 changes: 74 additions & 0 deletions index.js
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}`));
274 changes: 274 additions & 0 deletions lib/dom.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions lib/error.html
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>&zwnj;</title>
<meta name="description" content="A no&zwnj;de.js web pr&zwnj;oxy featuring UR&zwnj;L enco&zwnj;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>
Loading

0 comments on commit c01b601

Please sign in to comment.