Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 8dd5b39

Browse files
Rammerhead added (almost)
1 parent 052e635 commit 8dd5b39

File tree

16 files changed

+1524
-28
lines changed

16 files changed

+1524
-28
lines changed

index.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,39 @@ import createBareServer from '@tomphttp/bare-server-node';
22
import express, { Request, Response, NextFunction } from 'express';
33
import { createServer } from 'node:http';
44
import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
5-
import { join } from 'node:path';
5+
import path, { join } from 'node:path';
66
import { hostname } from 'node:os';
77
import cluster from 'cluster';
88
import os from 'os';
9+
import chalk from 'chalk';
910
//@ts-ignore
1011
import { handler as ssrHandler } from './dist/server/entry.mjs';
11-
import path from 'node:path';
1212
const __dirname = path.resolve();
1313
import dotenv from 'dotenv';
1414
import fs from 'fs';
1515
import auth from 'http-auth';
16+
//rammerhead stuff
17+
//@ts-ignore
18+
import createRammerhead from 'rammerhead/src/server/index.js';
19+
const rh = createRammerhead();
20+
const rammerheadScopes = [
21+
'/rammerhead.js',
22+
'/hammerhead.js',
23+
'/transport-worker.js',
24+
'/task.js',
25+
'/iframe-task.js',
26+
'/worker-hammerhead.js',
27+
'/messaging',
28+
'/sessionexists',
29+
'/deletesession',
30+
'/newsession',
31+
'/editsession',
32+
'/needpassword',
33+
'/syncLocalStorage',
34+
'/api/shuffleDict',
35+
];
36+
const rammerheadSession = /^\/[a-z0-9]{32}/;
37+
//END rammerhead specific stuff
1638
dotenv.config();
1739
//getting environment vars
1840
const numCPUs = process.env.CPUS || os.cpus().length;
@@ -30,7 +52,6 @@ let disableKEY = process.env.KEYDISABLE || 'false';
3052
let educationWebsite = fs.readFileSync(join(__dirname, 'education/index.html'));
3153
let loadingPage = fs.readFileSync(join(__dirname, 'education/load.html'));
3254
const blacklisted: string[] = [];
33-
console.log(uri)
3455
const disableyt: string[] = [];
3556
fs.readFile(join(__dirname, 'blocklists/ADS.txt'), (err, data) => {
3657
if (err) {
@@ -75,9 +96,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
7596
try {
7697
if (!req.headers.cookie?.includes('allowads')) {
7798
for (let i in blacklisted)
78-
if (
79-
req.headers['x-bare-host']?.includes(blacklisted[i])
80-
)
99+
if (req.headers['x-bare-host']?.includes(blacklisted[i]))
81100
return res.end('Denied');
82101
}
83102
bare.routeRequest(req, res);
@@ -89,6 +108,8 @@ if (numCPUs > 0 && cluster.isPrimary) {
89108
res.end();
90109
return;
91110
}
111+
} else if (shouldRouteRh(req)) {
112+
routeRhRequest(req, res);
92113
//@ts-ignore
93114
} else if (req.headers.host === uri) {
94115
app(req, res);
@@ -114,7 +135,11 @@ if (numCPUs > 0 && cluster.isPrimary) {
114135
url.pathname.includes('/settings') ||
115136
url.pathname.includes('/index') ||
116137
url.pathname.includes('/ruby-assets') ||
117-
url.pathname.includes('/games')
138+
url.pathname.includes('/games') ||
139+
url.pathname.includes('/uv') ||
140+
url.pathname.includes('/aero') ||
141+
url.pathname.includes('/osana') ||
142+
url.pathname.includes('/dip')
118143
) {
119144
return res.end(educationWebsite);
120145
} else {
@@ -125,7 +150,11 @@ if (numCPUs > 0 && cluster.isPrimary) {
125150
server.on('upgrade', (req, socket, head) => {
126151
if (bare.shouldRoute(req)) {
127152
bare.routeUpgrade(req, socket, head);
128-
} else {
153+
}
154+
else if (shouldRouteRh(req)) {
155+
routeRhUpgrade(req, socket, head);
156+
}
157+
else {
129158
socket.end();
130159
}
131160
});
@@ -210,7 +239,6 @@ if (numCPUs > 0 && cluster.isPrimary) {
210239
return;
211240
}
212241
});
213-
// Define the /analytics endpoint
214242
app.use((req, res) => {
215243
res.writeHead(302, {
216244
Location: '/404',
@@ -219,6 +247,24 @@ if (numCPUs > 0 && cluster.isPrimary) {
219247
return;
220248
});
221249
//!CUSTOM ENDPOINTS END
250+
//RAMMERHEAD FUNCTIONS
251+
//@ts-ignore
252+
function shouldRouteRh(req) {
253+
const RHurl = new URL(req.url, 'http://0.0.0.0');
254+
return (
255+
rammerheadScopes.includes(RHurl.pathname) ||
256+
rammerheadSession.test(RHurl.pathname)
257+
);
258+
}
259+
//@ts-ignore
260+
function routeRhRequest(req, res) {
261+
rh.emit('request', req, res);
262+
}
263+
//@ts-ignore
264+
function routeRhUpgrade(req, socket, head) {
265+
rh.emit('upgrade', req, socket, head);
266+
}
267+
//END RAMMERHEAD SPECIFIC FUNCTIONS
222268
let port = parseInt(process.env.PORT || '');
223269

224270
if (isNaN(port)) port = 8080;
@@ -229,7 +275,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
229275
// by default we are listening on 0.0.0.0 (every interface)
230276
// we just need to list a few
231277
// LIST PID
232-
console.log(`Process id: ${process.pid}`);
278+
console.log(chalk.green(`Process id: ${process.pid}`));
233279
console.log('Listening on:');
234280
//@ts-ignore
235281
console.log(`\thttp://localhost:${address.port}`);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@tomphttp/bare-server-node": "^1.2.5",
3333
"astro": "^2.1.9",
3434
"astro-robots-txt": "^0.4.1",
35+
"chalk": "^5.2.0",
3536
"dotenv": "^16.0.3",
3637
"express": "^4.18.2",
3738
"framer-motion": "^10.9.1",
@@ -41,6 +42,7 @@
4142
"path-to-regexp": "^6.2.1",
4243
"postcss": "^8.4.21",
4344
"prettier": "^2.8.7",
45+
"rammerhead": "https://github.com/holy-unblocker/rammerhead/releases/download/v1.2.41-holy.5/rammerhead-1.2.41-holy.5.tgz",
4446
"react": "^18.0.0",
4547
"react-dom": "^18.0.0",
4648
"tailwindcss": "^3.0.24",

public/chrome-tabs/tabbedLogic.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var el = document.querySelector('.chrome-tabs')
2727
}
2828
}
2929
}
30-
function updateURL(id) {
30+
async function updateURL(id) {
3131
let iframeURL = document.getElementById(id).contentWindow.document.getElementById('uv-iframe').contentWindow.location.href
3232
if (iframeURL.includes('/loading')) {
3333
document.getElementById('url-bar').value = ''
@@ -46,6 +46,9 @@ var el = document.querySelector('.chrome-tabs')
4646
case 'Aero':
4747
iframeURL = iframeURL.split('/go/').slice(1).join('/go/')
4848
break;
49+
case 'Rammerhead':
50+
iframeURL = ''
51+
break;
4952
default:
5053
iframeURL = iframeURL
5154
}

public/js/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ if (proxytype === 'Aero') {
154154
return a;
155155
}
156156
}
157+
if (proxytype === 'Rammerhead') {
158+
document
159+
.getElementById('uv-form')
160+
.addEventListener('submit', async (event) => {
161+
event.preventDefault();
162+
let address = document.getElementById('uv-address');
163+
let topURL = window.location.origin
164+
let url = search(address.value, searchEngine.value)
165+
iframe.classList.remove('dnone')
166+
let endURL = await window.rh.rhInteract(`${topURL}`, `${url}`)
167+
iframe.src = endURL.href
168+
document.getElementById('control').classList.remove('dnone')
169+
})
170+
}
157171
function decoded(str) {
158172
if (str.charAt(str.length - 1) == '/') str = str.slice(0, -1);
159173
return decodeURIComponent(str)

public/js/settings.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,34 @@ function changeProxy(proxy) {
6969
});
7070
}
7171
});
72-
} else {
72+
} else if (proxy === 'Rammerhead') {
73+
Swal.fire({
74+
title: 'Some info about Rammerhead',
75+
text: 'Rammerhead is a proxy that runs more on the server instead of your end. This means that the response times may be slower then the other options.',
76+
icon: 'info',
77+
color: 'var(--text-color)',
78+
background: 'var(--bg-color)',
79+
}).then(() => {
80+
Swal.fire({
81+
title: 'Even more Info',
82+
icon: 'info',
83+
text: 'Rammerhead also adds a feature called sessions. This allows the server to sync with your localStorage and cookies to save across devices. NEVER share this session ID as it will allow them to use your logged in accounts. If your device clears cookies and other data when turning it off, you can export your settings and we will grab the Rammerhead session ID for you. After this you can re upload those exported settings and we will make sure the session ID is the same as before.',
84+
color: 'var(--text-color)',
85+
background: 'var(--bg-color)',
86+
}).then(() => {
87+
Swal.fire({
88+
title: 'You are now using Rammerhead',
89+
text: 'You can change this any time and remember NEVER share your session ID',
90+
icon: 'success',
91+
color: 'var(--text-color)',
92+
background: 'var(--bg-color)',
93+
}).then(() => {
94+
localStorage.setItem('proxy', proxy);
95+
})
96+
})
97+
})
98+
}
99+
else {
73100
localStorage.setItem('proxy', proxy);
74101
}
75102
}
@@ -247,6 +274,30 @@ function resetAll() {
247274
localStorage.removeItem('clickedoff');
248275
window.location.reload();
249276
}
277+
function downloadSettings() {
278+
const settingsElement = document.createElement('a')
279+
const settingsData = []
280+
function GetItem(item) {
281+
let data = localStorage.getItem(item)
282+
settingsData.push({item, data})
283+
}
284+
GetItem('title')
285+
GetItem('favicon')
286+
GetItem('proxy')
287+
GetItem('searchEngine')
288+
GetItem('theme')
289+
GetItem('bgeffect')
290+
GetItem('clickoff')
291+
GetItem('fullscreenBehavior')
292+
GetItem('adsallowed')
293+
GetItem('tabs')
294+
settingsElement.setAttribute('href', `data:application/json;charset=utf-8,${JSON.stringify(settingsData)}`)
295+
settingsElement.setAttribute('download', 'rubySettings.json')
296+
settingsElement.style.display = 'none'
297+
document.body.appendChild(settingsElement)
298+
settingsElement.click()
299+
document.body.removeChild(settingsElement)
300+
}
250301

251302
function setSettingsValues() {
252303
let titleVal = document.getElementById('title');

public/rh/bad.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RammerheadAPI, StrShuffler } from './rhAPI.js';
2+
3+
async function startRH(){
4+
let api = new RammerheadAPI('http://localhost:3000');
5+
await fetch('http://localhost:3000');
6+
if ( localStorage.getItem('rammerhead_session') && (await api.sessionExists(localStorage.getItem('rammerhead_session'))) ) {
7+
const test = await fetch( new URL(localStorage.getItem('rammerhead_session'), 'http://localhost:3000') );
8+
await api.deleteSession(localStorage.getItem('rammerhead_session'));
9+
// 404 = good, 403 = Sessions must come from the same IP
10+
if (test.status === 403) localStorage.removeItem('rammerhead_session');
11+
} else {
12+
localStorage.removeItem('rammerhead_session');
13+
}
14+
let session = (async api.newSession());
15+
localStorage.setItem('rammerhead_session', session)
16+
await api.editSession(session, false, true);
17+
const dict = await api.shuffleDict(session);
18+
const shuffler = new StrShuffler(dict);
19+
location.replace(new URL(`${session}/${shuffler.shuffle('https://google.com')}`, 'http://localhost:3000'));
20+
}
21+
window.onload = startRH()

public/rh/rh.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { rhFunc } from './rhHelper.js';
2+
window.rh = rhFunc

0 commit comments

Comments
 (0)