Skip to content

Commit

Permalink
Disable ghetto randomization for now while going on potential hiatus
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Aug 10, 2024
1 parent 0c10bc2 commit f8d6d5c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"title": "HU LTS",
"host": "0.0.0.0",
"minifyScripts": true,
"randomizeIdentifiers": true,
"randomizeIdentifiers": false,
"production": false
}
122 changes: 63 additions & 59 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -249,70 +249,74 @@ app.get('/github/:redirect', (req, reply) => {
else reply.code(404).type('text/html').send(preloaded404);
});

const encodingTable = (() => {
let yummyOneBytes = '';
for (let i = 0; i < 128; i++)
if (
JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1))
.length < 6
)
yummyOneBytes += String.fromCodePoint(i);
return yummyOneBytes;
})(),
randomValue = crypto
.randomUUID()
.split('-')
.map((gibberish) => {
let randomNumber = parseInt(gibberish, 16),
output = '';
while (randomNumber >= encodingTable.length) {
output +=
encodingTable[Math.floor(randomNumber) % encodingTable.length];
randomNumber = randomNumber / encodingTable.length;
}
return output + Math.floor(randomNumber);
})
.join(''),
randomizeGlobal = config.randomizeIdentifiers
? (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify(randomValue)
if (config.randomizeIdentifiers) {
const encodingTable = (() => {
let yummyOneBytes = '';
for (let i = 0; i < 128; i++)
if (
JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1))
.length < 6
)
: (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify('__uv$config')
);
yummyOneBytes += String.fromCodePoint(i);
return yummyOneBytes;
})(),
randomValue = crypto
.randomUUID()
.split('-')
.map((gibberish) => {
let randomNumber = parseInt(gibberish, 16),
output = '';
while (randomNumber >= encodingTable.length) {
output +=
encodingTable[Math.floor(randomNumber) % encodingTable.length];
randomNumber = randomNumber / encodingTable.length;
}
return output + Math.floor(randomNumber);
})
.join(''),
randomizeGlobal = config.randomizeIdentifiers
? (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify(randomValue)
)
: (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify('__uv$config')
);

app.get('/assets/js/common-16451543478.js', (req, reply) => {
reply
.type('text/javascript')
.send(
randomizeGlobal(
'../views' + (config.minifyScripts ? '/dist' : '') + req.url
)
);
});
app.get('/assets/js/common-16451543478.js', (req, reply) => {
reply
.type('text/javascript')
.send(
randomizeGlobal(
'../views' + (config.minifyScripts ? '/dist' : '') + req.url
)
);
});

app.get('/uv/:file.js', (req, reply) => {
const destination = existsSync(fileURLToPath(new URL('../views' + req.url, import.meta.url)))
? '../views' + (config.minifyScripts ? '/dist' : '') + req.url
: uvPath + '/' + req.params.file + '.js';
reply
.type('text/javascript')
.send(
randomizeGlobal(destination).replace(
/(["'`])\{\{ultraviolet-error\}\}\1/g,
JSON.stringify(
tryReadFile(
'../views/pages/proxnav/ultraviolet-error.html',
import.meta.url
app.get('/uv/:file.js', (req, reply) => {
const destination = existsSync(
fileURLToPath(new URL('../views' + req.url, import.meta.url))
)
? '../views' + (config.minifyScripts ? '/dist' : '') + req.url
: uvPath + '/' + req.params.file + '.js';
reply
.type('text/javascript')
.send(
randomizeGlobal(destination).replace(
/(["'`])\{\{ultraviolet-error\}\}\1/g,
JSON.stringify(
tryReadFile(
'../views/pages/proxnav/ultraviolet-error.html',
import.meta.url
)
)
)
)
);
});
);
});
}

// Set an error page for invalid paths outside the query string system.
app.setNotFoundHandler((req, reply) => {
Expand Down

0 comments on commit f8d6d5c

Please sign in to comment.