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

Commit

Permalink
Rammerhead added (almost)
Browse files Browse the repository at this point in the history
  • Loading branch information
MotorTruck1221 committed Apr 6, 2023
1 parent 052e635 commit 8dd5b39
Show file tree
Hide file tree
Showing 16 changed files with 1,524 additions and 28 deletions.
66 changes: 56 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@ import createBareServer from '@tomphttp/bare-server-node';
import express, { Request, Response, NextFunction } from 'express';
import { createServer } from 'node:http';
import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
import { join } from 'node:path';
import path, { join } from 'node:path';
import { hostname } from 'node:os';
import cluster from 'cluster';
import os from 'os';
import chalk from 'chalk';
//@ts-ignore
import { handler as ssrHandler } from './dist/server/entry.mjs';
import path from 'node:path';
const __dirname = path.resolve();
import dotenv from 'dotenv';
import fs from 'fs';
import auth from 'http-auth';
//rammerhead stuff
//@ts-ignore
import createRammerhead from 'rammerhead/src/server/index.js';
const rh = createRammerhead();
const rammerheadScopes = [
'/rammerhead.js',
'/hammerhead.js',
'/transport-worker.js',
'/task.js',
'/iframe-task.js',
'/worker-hammerhead.js',
'/messaging',
'/sessionexists',
'/deletesession',
'/newsession',
'/editsession',
'/needpassword',
'/syncLocalStorage',
'/api/shuffleDict',
];
const rammerheadSession = /^\/[a-z0-9]{32}/;
//END rammerhead specific stuff
dotenv.config();
//getting environment vars
const numCPUs = process.env.CPUS || os.cpus().length;
Expand All @@ -30,7 +52,6 @@ let disableKEY = process.env.KEYDISABLE || 'false';
let educationWebsite = fs.readFileSync(join(__dirname, 'education/index.html'));
let loadingPage = fs.readFileSync(join(__dirname, 'education/load.html'));
const blacklisted: string[] = [];
console.log(uri)
const disableyt: string[] = [];
fs.readFile(join(__dirname, 'blocklists/ADS.txt'), (err, data) => {
if (err) {
Expand Down Expand Up @@ -75,9 +96,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
try {
if (!req.headers.cookie?.includes('allowads')) {
for (let i in blacklisted)
if (
req.headers['x-bare-host']?.includes(blacklisted[i])
)
if (req.headers['x-bare-host']?.includes(blacklisted[i]))
return res.end('Denied');
}
bare.routeRequest(req, res);
Expand All @@ -89,6 +108,8 @@ if (numCPUs > 0 && cluster.isPrimary) {
res.end();
return;
}
} else if (shouldRouteRh(req)) {
routeRhRequest(req, res);
//@ts-ignore
} else if (req.headers.host === uri) {
app(req, res);
Expand All @@ -114,7 +135,11 @@ if (numCPUs > 0 && cluster.isPrimary) {
url.pathname.includes('/settings') ||
url.pathname.includes('/index') ||
url.pathname.includes('/ruby-assets') ||
url.pathname.includes('/games')
url.pathname.includes('/games') ||
url.pathname.includes('/uv') ||
url.pathname.includes('/aero') ||
url.pathname.includes('/osana') ||
url.pathname.includes('/dip')
) {
return res.end(educationWebsite);
} else {
Expand All @@ -125,7 +150,11 @@ if (numCPUs > 0 && cluster.isPrimary) {
server.on('upgrade', (req, socket, head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else {
}
else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head);
}
else {
socket.end();
}
});
Expand Down Expand Up @@ -210,7 +239,6 @@ if (numCPUs > 0 && cluster.isPrimary) {
return;
}
});
// Define the /analytics endpoint
app.use((req, res) => {
res.writeHead(302, {
Location: '/404',
Expand All @@ -219,6 +247,24 @@ if (numCPUs > 0 && cluster.isPrimary) {
return;
});
//!CUSTOM ENDPOINTS END
//RAMMERHEAD FUNCTIONS
//@ts-ignore
function shouldRouteRh(req) {
const RHurl = new URL(req.url, 'http://0.0.0.0');
return (
rammerheadScopes.includes(RHurl.pathname) ||
rammerheadSession.test(RHurl.pathname)
);
}
//@ts-ignore
function routeRhRequest(req, res) {
rh.emit('request', req, res);
}
//@ts-ignore
function routeRhUpgrade(req, socket, head) {
rh.emit('upgrade', req, socket, head);
}
//END RAMMERHEAD SPECIFIC FUNCTIONS
let port = parseInt(process.env.PORT || '');

if (isNaN(port)) port = 8080;
Expand All @@ -229,7 +275,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
// by default we are listening on 0.0.0.0 (every interface)
// we just need to list a few
// LIST PID
console.log(`Process id: ${process.pid}`);
console.log(chalk.green(`Process id: ${process.pid}`));
console.log('Listening on:');
//@ts-ignore
console.log(`\thttp://localhost:${address.port}`);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tomphttp/bare-server-node": "^1.2.5",
"astro": "^2.1.9",
"astro-robots-txt": "^0.4.1",
"chalk": "^5.2.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"framer-motion": "^10.9.1",
Expand All @@ -41,6 +42,7 @@
"path-to-regexp": "^6.2.1",
"postcss": "^8.4.21",
"prettier": "^2.8.7",
"rammerhead": "https://github.com/holy-unblocker/rammerhead/releases/download/v1.2.41-holy.5/rammerhead-1.2.41-holy.5.tgz",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"tailwindcss": "^3.0.24",
Expand Down
5 changes: 4 additions & 1 deletion public/chrome-tabs/tabbedLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var el = document.querySelector('.chrome-tabs')
}
}
}
function updateURL(id) {
async function updateURL(id) {
let iframeURL = document.getElementById(id).contentWindow.document.getElementById('uv-iframe').contentWindow.location.href
if (iframeURL.includes('/loading')) {
document.getElementById('url-bar').value = ''
Expand All @@ -46,6 +46,9 @@ var el = document.querySelector('.chrome-tabs')
case 'Aero':
iframeURL = iframeURL.split('/go/').slice(1).join('/go/')
break;
case 'Rammerhead':
iframeURL = ''
break;
default:
iframeURL = iframeURL
}
Expand Down
14 changes: 14 additions & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ if (proxytype === 'Aero') {
return a;
}
}
if (proxytype === 'Rammerhead') {
document
.getElementById('uv-form')
.addEventListener('submit', async (event) => {
event.preventDefault();
let address = document.getElementById('uv-address');
let topURL = window.location.origin
let url = search(address.value, searchEngine.value)
iframe.classList.remove('dnone')
let endURL = await window.rh.rhInteract(`${topURL}`, `${url}`)
iframe.src = endURL.href
document.getElementById('control').classList.remove('dnone')
})
}
function decoded(str) {
if (str.charAt(str.length - 1) == '/') str = str.slice(0, -1);
return decodeURIComponent(str)
Expand Down
53 changes: 52 additions & 1 deletion public/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,34 @@ function changeProxy(proxy) {
});
}
});
} else {
} else if (proxy === 'Rammerhead') {
Swal.fire({
title: 'Some info about Rammerhead',
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.',
icon: 'info',
color: 'var(--text-color)',
background: 'var(--bg-color)',
}).then(() => {
Swal.fire({
title: 'Even more Info',
icon: 'info',
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.',
color: 'var(--text-color)',
background: 'var(--bg-color)',
}).then(() => {
Swal.fire({
title: 'You are now using Rammerhead',
text: 'You can change this any time and remember NEVER share your session ID',
icon: 'success',
color: 'var(--text-color)',
background: 'var(--bg-color)',
}).then(() => {
localStorage.setItem('proxy', proxy);
})
})
})
}
else {
localStorage.setItem('proxy', proxy);
}
}
Expand Down Expand Up @@ -247,6 +274,30 @@ function resetAll() {
localStorage.removeItem('clickedoff');
window.location.reload();
}
function downloadSettings() {
const settingsElement = document.createElement('a')
const settingsData = []
function GetItem(item) {
let data = localStorage.getItem(item)
settingsData.push({item, data})
}
GetItem('title')
GetItem('favicon')
GetItem('proxy')
GetItem('searchEngine')
GetItem('theme')
GetItem('bgeffect')
GetItem('clickoff')
GetItem('fullscreenBehavior')
GetItem('adsallowed')
GetItem('tabs')
settingsElement.setAttribute('href', `data:application/json;charset=utf-8,${JSON.stringify(settingsData)}`)
settingsElement.setAttribute('download', 'rubySettings.json')
settingsElement.style.display = 'none'
document.body.appendChild(settingsElement)
settingsElement.click()
document.body.removeChild(settingsElement)
}

function setSettingsValues() {
let titleVal = document.getElementById('title');
Expand Down
21 changes: 21 additions & 0 deletions public/rh/bad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { RammerheadAPI, StrShuffler } from './rhAPI.js';

async function startRH(){
let api = new RammerheadAPI('http://localhost:3000');
await fetch('http://localhost:3000');
if ( localStorage.getItem('rammerhead_session') && (await api.sessionExists(localStorage.getItem('rammerhead_session'))) ) {
const test = await fetch( new URL(localStorage.getItem('rammerhead_session'), 'http://localhost:3000') );
await api.deleteSession(localStorage.getItem('rammerhead_session'));
// 404 = good, 403 = Sessions must come from the same IP
if (test.status === 403) localStorage.removeItem('rammerhead_session');
} else {
localStorage.removeItem('rammerhead_session');
}
let session = (async api.newSession());
localStorage.setItem('rammerhead_session', session)
await api.editSession(session, false, true);
const dict = await api.shuffleDict(session);
const shuffler = new StrShuffler(dict);
location.replace(new URL(`${session}/${shuffler.shuffle('https://google.com')}`, 'http://localhost:3000'));
}
window.onload = startRH()
2 changes: 2 additions & 0 deletions public/rh/rh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { rhFunc } from './rhHelper.js';
window.rh = rhFunc
Loading

0 comments on commit 8dd5b39

Please sign in to comment.