Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
@ -1,3 +1,4 @@
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const app = express();
|
||||
@ -108,8 +109,7 @@ app.use('/api/projects', passport.authenticate('jwt', {session: false}), project
|
||||
|
||||
app.use('/api/scripts', passport.authenticate('jwt', {session: false}), scriptsRoutes);
|
||||
|
||||
// Build routes are now public-facing for the playground
|
||||
app.use('/api/builds', buildsRoutes);
|
||||
app.use('/api/builds', passport.authenticate('jwt', {session: false}), buildsRoutes);
|
||||
|
||||
app.use('/api/vm_configs', passport.authenticate('jwt', {session: false}), vm_configsRoutes);
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
|
||||
const express = require('express');
|
||||
const passport = require('passport');
|
||||
|
||||
const BuildsService = require('../services/builds');
|
||||
const BuildsDBApi = require('../db/api/builds');
|
||||
const ObfuscatorService = require('../services/obfuscator');
|
||||
const wrapAsync = require('../helpers').wrapAsync;
|
||||
|
||||
|
||||
@ -15,55 +15,9 @@ const {
|
||||
checkCrudPermissions,
|
||||
} = require('../middlewares/check-permissions');
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/builds/protect:
|
||||
* post:
|
||||
* tags: [Builds]
|
||||
* summary: Obfuscate Luau code
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* source:
|
||||
* type: string
|
||||
* config:
|
||||
* type: object
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Obfuscated code
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* protectedCode:
|
||||
* type: string
|
||||
*/
|
||||
router.post('/protect', wrapAsync(async (req, res) => {
|
||||
const { source, config } = req.body;
|
||||
const protectedCode = ObfuscatorService.obfuscate(source, config);
|
||||
|
||||
// Log the build if possible, but don't fail if no user
|
||||
try {
|
||||
await BuildsService.create({
|
||||
version: '1.0.0',
|
||||
notes: `Playground build: ${source.substring(0, 20)}...`,
|
||||
success: true
|
||||
}, req.currentUser);
|
||||
} catch (e) {
|
||||
console.error('Failed to log playground build:', e.message);
|
||||
}
|
||||
|
||||
res.status(200).send({ protectedCode });
|
||||
}));
|
||||
|
||||
// Apply authentication and permission checks to all other routes
|
||||
router.use(passport.authenticate('jwt', { session: false }));
|
||||
router.use(checkCrudPermissions('builds'));
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
|
||||
@ -1,467 +0,0 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
class ObfuscatorService {
|
||||
static obfuscate(sourceCode, config = {}) {
|
||||
try {
|
||||
console.log('Starting obfuscation for code length:', sourceCode.length);
|
||||
const seed = crypto.randomBytes(4).readUInt32BE(0);
|
||||
const tokens = this.tokenize(sourceCode);
|
||||
const { bc, constants, ops } = this.compile(tokens);
|
||||
const vm = this.generateVM(bc, constants, ops, seed);
|
||||
console.log('Obfuscation complete, VM length:', vm.length);
|
||||
return vm;
|
||||
} catch (err) {
|
||||
console.error('Obfuscation error:', err);
|
||||
return `-- LUARTEX CRITICAL ERROR: ${err.message}
|
||||
` + sourceCode;
|
||||
}
|
||||
}
|
||||
|
||||
static tokenize(code) {
|
||||
const tokens = [];
|
||||
let i = 0;
|
||||
const operators = [
|
||||
'==', '~=', '<=', '>=', '..', '...', '+=', '-=', '*=', '/=',
|
||||
'=', '+', '-', '*', '/', '%', '^', '#', '<', '>', '(', ')',
|
||||
'{', '}', '[', ']', ';', ':', ',', '.'
|
||||
];
|
||||
|
||||
while (i < code.length) {
|
||||
let c = code[i];
|
||||
if (/\s/.test(c)) { i++; continue; }
|
||||
|
||||
if (c === '-' && code[i + 1] === '-') {
|
||||
i += 2;
|
||||
if (code[i] === '[' && code[i + 1] === '[') {
|
||||
i += 2;
|
||||
while (i < code.length && !(code[i] === ']' && code[i + 1] === ']')) i++;
|
||||
i += 2;
|
||||
} else {
|
||||
while (i < code.length && code[i] !== '\n') i++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c === '"' || c === "'") {
|
||||
const q = c; let s = ""; i++;
|
||||
while (i < code.length && code[i] !== q) {
|
||||
if (code[i] === '\\') {
|
||||
i++;
|
||||
if (code[i] === 'x') { s += String.fromCharCode(parseInt(code.substr(i + 1, 2), 16)); i += 3; }
|
||||
else if (/\d/.test(code[i])) {
|
||||
let d = ""; while (i < code.length && /\d/.test(code[i]) && d.length < 3) { d += code[i]; i++; }
|
||||
s += String.fromCharCode(parseInt(d, 10));
|
||||
}
|
||||
else { s += code[i] || ''; i++; }
|
||||
} else { s += code[i]; i++; }
|
||||
}
|
||||
tokens.push({ type: 'string', value: s });
|
||||
i++; continue;
|
||||
}
|
||||
|
||||
if (/\d/.test(c)) {
|
||||
let n = "";
|
||||
while (i < code.length && /[0-9.xXabcdefABCDEF]/.test(code[i])) { n += code[i]; i++; }
|
||||
tokens.push({ type: 'number', value: n.startsWith('0x') ? parseInt(n, 16) : parseFloat(n) });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/[a-zA-Z_]/.test(c)) {
|
||||
let id = "";
|
||||
while (i < code.length && /[a-zA-Z0-9_]/.test(code[i])) { id += code[i]; i++; }
|
||||
tokens.push({ type: 'identifier', value: id });
|
||||
continue;
|
||||
}
|
||||
|
||||
let matchedOp = false;
|
||||
for (const op of operators) {
|
||||
if (code.startsWith(op, i)) {
|
||||
tokens.push({ type: 'operator', value: op });
|
||||
i += op.length;
|
||||
matchedOp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matchedOp) { i++; }
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
static numberToExpression(n) {
|
||||
if (typeof n !== 'number') return n;
|
||||
let current = Math.floor(Math.random() * 1000);
|
||||
let expr = `(${current})`;
|
||||
const steps = 3 + Math.floor(Math.random() * 3);
|
||||
for (let i = 0; i < steps; i++) {
|
||||
const mode = Math.floor(Math.random() * 4);
|
||||
const v = Math.floor(Math.random() * 200) + 1;
|
||||
if (mode === 0) { current += v; expr = `(${expr} + ${v})`; }
|
||||
else if (mode === 1) { current -= v; expr = `(${expr} - ${v})`; }
|
||||
else if (mode === 2) { current *= 2; expr = `(${expr} * 2)`; }
|
||||
else {
|
||||
const nv = Math.floor(Math.random() * 255);
|
||||
current = (current ^ nv) >>> 0;
|
||||
expr = `(bit32 or bit).bxor(${expr}, ${nv})`;
|
||||
}
|
||||
}
|
||||
const diff = n - current;
|
||||
return `(${expr} + ${diff})`;
|
||||
}
|
||||
|
||||
static compile(tokens) {
|
||||
const constants = [];
|
||||
const getC = (v) => {
|
||||
let idx = constants.findIndex(c => c.value === v);
|
||||
if (idx === -1) { idx = constants.length; constants.push({ value: v, type: typeof v }); }
|
||||
return idx;
|
||||
};
|
||||
|
||||
const ops = {
|
||||
LOADK: 0, GETG: 1, SETG: 2, CALL: 3, RET: 4, GETT: 5, GETS: 6,
|
||||
NEWTABLE: 7, SETTABLE: 8, MOVE: 9,
|
||||
ADD: 10, SUB: 11, MUL: 12, DIV: 13, CONCAT: 14,
|
||||
EQ: 15, LT: 16, LE: 17, JMP: 18, JMPF: 19,
|
||||
CLOSURE: 20
|
||||
};
|
||||
|
||||
const bc = [];
|
||||
let ti = 0;
|
||||
const locals = [{}];
|
||||
let nextReg = 0;
|
||||
|
||||
const peek = (n = 0) => tokens[ti + n];
|
||||
const consume = () => tokens[ti++];
|
||||
|
||||
const getLocal = (name) => {
|
||||
for (let i = locals.length - 1; i >= 0; i--) {
|
||||
if (locals[i][name] !== undefined) return locals[i][name];
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const parseExpression = (reg) => {
|
||||
let t = peek(); if (!t) return;
|
||||
|
||||
const parsePrimary = (r) => {
|
||||
let t = peek();
|
||||
if (!t) return;
|
||||
if (t.type === 'number' || t.type === 'string') {
|
||||
bc.push(ops.LOADK, r, getC(consume().value));
|
||||
} else if (t.type === 'identifier') {
|
||||
if (t.value === 'true') { bc.push(ops.LOADK, r, getC(true)); consume(); }
|
||||
else if (t.value === 'false') { bc.push(ops.LOADK, r, getC(false)); consume(); }
|
||||
else if (t.value === 'nil') { bc.push(ops.LOADK, r, getC(null)); consume(); }
|
||||
else if (t.value === 'function') {
|
||||
parseClosure(r);
|
||||
} else {
|
||||
let name = consume().value;
|
||||
let lReg = getLocal(name);
|
||||
if (lReg !== undefined) bc.push(ops.MOVE, r, lReg);
|
||||
else bc.push(ops.GETG, r, getC(name));
|
||||
|
||||
while (ti < tokens.length) {
|
||||
let next = peek();
|
||||
if (next?.value === '.') {
|
||||
consume(); let key = consume()?.value;
|
||||
if (key) bc.push(ops.GETT, r, r, getC(key));
|
||||
} else if (next?.value === ':') {
|
||||
consume(); let key = consume()?.value;
|
||||
if (key) {
|
||||
bc.push(ops.GETS, r, r, getC(key));
|
||||
parseArgs(r, true);
|
||||
}
|
||||
} else if (next?.value === '(') {
|
||||
parseArgs(r, false);
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
} else if (t.value === '{') {
|
||||
parseTable(r);
|
||||
} else if (t.value === '(') {
|
||||
consume(); parseExpression(r);
|
||||
if (peek()?.value === ')') consume();
|
||||
}
|
||||
};
|
||||
|
||||
parsePrimary(reg);
|
||||
const binOps = { '+': ops.ADD, '-': ops.SUB, '*': ops.MUL, '/': ops.DIV, '..': ops.CONCAT, '==': ops.EQ, '<': ops.LT, '<=': ops.LE };
|
||||
while (peek()?.type === 'operator' && binOps[peek().value]) {
|
||||
let op = consume().value;
|
||||
let opCode = binOps[op];
|
||||
let r2 = nextReg++;
|
||||
parsePrimary(r2);
|
||||
bc.push(opCode, reg, reg, r2);
|
||||
}
|
||||
};
|
||||
|
||||
const parseArgs = (reg, isM) => {
|
||||
if (peek()?.value !== '(') return;
|
||||
consume();
|
||||
let ac = isM ? 1 : 0;
|
||||
while (ti < tokens.length && peek().value !== ')') {
|
||||
if (peek().value === ',') { consume(); continue; }
|
||||
ac++;
|
||||
let argReg = reg + ac;
|
||||
if (argReg >= nextReg) nextReg = argReg + 1;
|
||||
parseExpression(argReg);
|
||||
}
|
||||
if (peek()?.value === ')') consume();
|
||||
bc.push(ops.CALL, reg, ac + 1, 1);
|
||||
};
|
||||
|
||||
const parseTable = (reg) => {
|
||||
bc.push(ops.NEWTABLE, reg); consume();
|
||||
let arrIdx = 1;
|
||||
while (ti < tokens.length && peek()?.value !== '}') {
|
||||
if (peek()?.value === ',' || peek()?.value === ';') { consume(); continue; }
|
||||
if (peek()?.value === '}') break;
|
||||
|
||||
if (peek()?.type === 'identifier' && peek(1)?.value === '=') {
|
||||
let key = consume().value; consume();
|
||||
let vReg = nextReg++;
|
||||
parseExpression(vReg);
|
||||
bc.push(ops.SETTABLE, reg, getC(key), vReg);
|
||||
} else if (peek()?.value === '[') {
|
||||
consume();
|
||||
let kReg = nextReg++;
|
||||
parseExpression(kReg);
|
||||
if (peek()?.value === ']') consume();
|
||||
if (peek()?.value === '=') consume();
|
||||
let vReg = nextReg++;
|
||||
parseExpression(vReg);
|
||||
bc.push(ops.SETTABLE, reg, -1, kReg, vReg);
|
||||
} else {
|
||||
let vReg = nextReg++;
|
||||
parseExpression(vReg);
|
||||
bc.push(ops.SETTABLE, reg, getC(arrIdx++), vReg);
|
||||
}
|
||||
}
|
||||
if (peek()?.value === '}') consume();
|
||||
};
|
||||
|
||||
const parseClosure = (reg) => {
|
||||
consume(); // function
|
||||
if (peek()?.value === '(') {
|
||||
consume();
|
||||
while (ti < tokens.length && peek()?.value !== ')') consume();
|
||||
if (peek()?.value === ')') consume();
|
||||
}
|
||||
// Capture function body as string for sub-VM
|
||||
let start = ti;
|
||||
let depth = 1;
|
||||
while (ti < tokens.length && depth > 0) {
|
||||
let nt = consume();
|
||||
if (['if', 'while', 'for', 'do', 'function'].includes(nt.value)) depth++;
|
||||
if (nt.value === 'end') depth--;
|
||||
}
|
||||
let bodyTokens = tokens.slice(start, ti - 1);
|
||||
let bodyCode = bodyTokens.map(t => t.type === 'string' ? `"${t.value}"` : t.value).join(' ');
|
||||
bc.push(ops.CLOSURE, reg, getC(bodyCode));
|
||||
};
|
||||
|
||||
const parseBlock = () => {
|
||||
locals.push({});
|
||||
while (ti < tokens.length) {
|
||||
let t = peek();
|
||||
if (!t || ['end', 'else', 'elseif', 'until'].includes(t.value)) break;
|
||||
parseStatement();
|
||||
}
|
||||
locals.pop();
|
||||
};
|
||||
|
||||
const parseStatement = () => {
|
||||
let t = peek();
|
||||
if (!t) return;
|
||||
|
||||
if (t.value === 'local') {
|
||||
consume();
|
||||
if (peek()?.value === 'function') {
|
||||
consume(); let name = consume().value;
|
||||
locals[locals.length-1][name] = nextReg++;
|
||||
parseClosure(locals[locals.length-1][name]);
|
||||
} else {
|
||||
let name = consume()?.value;
|
||||
if (!name) return;
|
||||
let reg = nextReg++;
|
||||
locals[locals.length-1][name] = reg;
|
||||
if (peek()?.value === '=') { consume(); parseExpression(reg); }
|
||||
}
|
||||
} else if (t.value === 'function') {
|
||||
consume(); let name = consume().value;
|
||||
let reg = nextReg++;
|
||||
parseClosure(reg);
|
||||
bc.push(ops.SETG, reg, getC(name));
|
||||
} else if (['if', 'while', 'for', 'do'].includes(t.value)) {
|
||||
consume();
|
||||
parseBlock();
|
||||
if (peek()?.value === 'end') consume();
|
||||
} else if (t.type === 'identifier' && peek(1)?.value === '=') {
|
||||
let vn = consume().value; consume();
|
||||
let tempReg = nextReg;
|
||||
parseExpression(tempReg);
|
||||
let lReg = getLocal(vn);
|
||||
if (lReg !== undefined) bc.push(ops.MOVE, lReg, tempReg);
|
||||
else bc.push(ops.SETG, tempReg, getC(vn));
|
||||
} else if (['return', 'break', 'continue'].includes(t.value)) {
|
||||
consume();
|
||||
} else {
|
||||
parseExpression(nextReg);
|
||||
if (t === peek()) consume();
|
||||
}
|
||||
if (peek()?.value === ';') consume();
|
||||
};
|
||||
|
||||
while (ti < tokens.length) {
|
||||
parseStatement();
|
||||
}
|
||||
|
||||
bc.push(ops.RET, 0, 1);
|
||||
return { bc, constants, ops };
|
||||
}
|
||||
|
||||
static generateVM(bc, constants, ops, seed) {
|
||||
const r = () => "_" + crypto.randomBytes(3).toString('hex');
|
||||
const nL = r(), nC = r(), nR = r(), nPC = r(), nD = r(), nDS = r(), nENV = r(), nLDR = r(), nBIT = r();
|
||||
|
||||
const encC = constants.map(c => {
|
||||
if (c.type === 'string') {
|
||||
const key = seed & 0xFF;
|
||||
const e = Buffer.from(c.value).map(b => b ^ key).toString('base64');
|
||||
return `{t=1,v="${e}"}`;
|
||||
}
|
||||
if (c.type === 'number') {
|
||||
const o = Math.floor(Math.random() * 10000);
|
||||
return `{t=2,v=${(c.value + o) ^ (seed & 0xFFFF)},o=${o}}`;
|
||||
}
|
||||
if (c.value === true) return `{t=3}`;
|
||||
if (c.value === false) return `{t=4}`;
|
||||
return `{t=5}`;
|
||||
}).join(',');
|
||||
|
||||
const xorKey = (seed ^ 0xAA) & 0xFF;
|
||||
const d = [];
|
||||
d[ops.LOADK] = `function() ${nR}[${nL}[${nPC}]] = ${nD}(${nL}[${nPC}+1]); ${nPC}=${nPC}+2 end`;
|
||||
d[ops.GETG] = `function() ${nR}[${nL}[${nPC}]] = ${nENV}[${nD}(${nL}[${nPC}+1])]; ${nPC}=${nPC}+2 end`;
|
||||
d[ops.SETG] = `function() ${nENV}[${nD}(${nL}[${nPC}+1])] = ${nR}[${nL}[${nPC}]]; ${nPC}=${nPC}+2 end`;
|
||||
d[ops.GETT] = `function() local r,t,k = ${nL}[${nPC}],${nL}[${nPC}+1],${nL}[${nPC}+2]; ${nPC}=${nPC}+3; ${nR}[r] = ${nR}[t][${nD}(k)] end`;
|
||||
d[ops.GETS] = `function() local r,t,k = ${nL}[${nPC}],${nL}[${nPC}+1],${nL}[${nPC}+2]; ${nPC}=${nPC}+3; local o = ${nR}[t]; ${nR}[r+1] = o; ${nR}[r] = o[${nD}(k)] end`;
|
||||
d[ops.CALL] = `function() local r,na,nr = ${nL}[${nPC}],${nL}[${nPC}+1],${nL}[${nPC}+2]; ${nPC}=${nPC}+3; local a={}; for i=1,na-1 do a[i]=${nR}[r+i] end; local f = ${nR}[r]; if not f then error("Luartex VM Error: Call to nil at PC "..${nPC}) end; local res = {f((table.unpack or unpack)(a))}; for i=1,nr do ${nR}[r+i-1] = res[i] end end`;
|
||||
d[ops.RET] = `function() return "EXIT" end`;
|
||||
d[ops.NEWTABLE] = `function() ${nR}[${nL}[${nPC}]] = {}; ${nPC}=${nPC}+1 end`;
|
||||
d[ops.SETTABLE] = `function() local t,k,v = ${nL}[${nPC}],${nL}[${nPC}+1],${nL}[${nPC}+2]; ${nPC}=${nPC}+3; if k == -1 then ${nR}[t][${nR}[${nL}[${nPC}-2]]] = ${nR}[v] else ${nR}[t][${nD}(k)] = ${nR}[v] end end`;
|
||||
d[ops.MOVE] = `function() ${nR}[${nL}[${nPC}]] = ${nR}[${nL}[${nPC}+1]]; ${nPC}=${nPC}+2 end`;
|
||||
d[ops.ADD] = `function() ${nR}[${nL}[${nPC}]] = ${nR}[${nL}[${nPC}+1]] + ${nR}[${nL}[${nPC}+2]]; ${nPC}=${nPC}+3 end`;
|
||||
d[ops.SUB] = `function() ${nR}[${nL}[${nPC}]] = ${nR}[${nL}[${nPC}+1]] - ${nR}[${nL}[${nPC}+2]]; ${nPC}=${nPC}+3 end`;
|
||||
d[ops.MUL] = `function() ${nR}[${nL}[${nPC}]] = ${nR}[${nL}[${nPC}+1]] * ${nR}[${nL}[${nPC}+2]]; ${nPC}=${nPC}+3 end`;
|
||||
d[ops.DIV] = `function() ${nR}[${nL}[${nPC}]] = ${nR}[${nL}[${nPC}+1]] / ${nR}[${nL}[${nPC}+2]]; ${nPC}=${nPC}+3 end`;
|
||||
d[ops.CONCAT] = `function() ${nR}[${nL}[${nPC}]] = tostring(${nR}[${nL}[${nPC}+1]]) .. tostring(${nR}[${nL}[${nPC}+2]]); ${nPC}=${nPC}+3 end`;
|
||||
d[ops.EQ] = `function() ${nR}[${nL}[${nPC}]] = (${nR}[${nL}[${nPC}+1]] == ${nR}[${nL}[${nPC}+2]]); ${nPC}=${nPC}+3 end`;
|
||||
d[ops.LT] = `function() ${nR}[${nL}[${nPC}]] = (${nR}[${nL}[${nPC}+1]] < ${nR}[${nL}[${nPC}+2]]); ${nPC}=${nPC}+3 end`;
|
||||
d[ops.LE] = `function() ${nR}[${nL}[${nPC}]] = (${nR}[${nL}[${nPC}+1]] <= ${nR}[${nL}[${nPC}+2]]); ${nPC}=${nPC}+3 end`;
|
||||
d[ops.CLOSURE] = `function() local r,k = ${nL}[${nPC}],${nL}[${nPC}+1]; ${nPC}=${nPC}+2; ${nR}[r] = ${nLDR}(${nD}(k)) end`;
|
||||
|
||||
const shuffled = Object.keys(ops).sort(() => Math.random() - 0.5);
|
||||
const opMap = {}; shuffled.forEach((k, i) => opMap[ops[k]] = i);
|
||||
const argCounts = { [ops.LOADK]: 2, [ops.GETG]: 2, [ops.SETG]: 2, [ops.GETT]: 3, [ops.GETS]: 3, [ops.CALL]: 3, [ops.RET]: 2, [ops.NEWTABLE]: 1, [ops.SETTABLE]: 3, [ops.MOVE]: 2, [ops.ADD]: 3, [ops.SUB]: 3, [ops.MUL]: 3, [ops.DIV]: 3, [ops.CONCAT]: 3, [ops.EQ]: 3, [ops.LT]: 3, [ops.LE]: 3, [ops.CLOSURE]: 2 };
|
||||
|
||||
const finalBC = [];
|
||||
for (let i = 0; i < bc.length; ) {
|
||||
const op = bc[i]; finalBC.push(opMap[op]); i++;
|
||||
const count = argCounts[op] || 0;
|
||||
for (let j = 0; j < count; j++) { finalBC.push(bc[i] || 0); i++; }
|
||||
}
|
||||
|
||||
const dispatchFunctions = shuffled.map(k => d[ops[k]]).join(',\n');
|
||||
const vmCode = `local function VM(...)
|
||||
local ${nLDR} = loadstring or load
|
||||
local ${nENV} = (getfenv and getfenv()) or _G
|
||||
local ${nBIT} = bit32 or bit
|
||||
local ${nL} = {${finalBC.join(',')}}
|
||||
local ${nC} = {${encC}}
|
||||
local ${nR} = setmetatable({}, {
|
||||
__index = function(t, k) return rawget(t, ${nBIT}.bxor(k, ${xorKey})) end,
|
||||
__newindex = function(t, k, v) rawset(t, ${nBIT}.bxor(k, ${xorKey}), v) end
|
||||
})
|
||||
local ${nPC} = 1
|
||||
local function ${nD}(i)
|
||||
if not i or i == -1 then return nil end
|
||||
local c = ${nC}[i+1]; if not c then return end
|
||||
if c.t == 1 then
|
||||
local b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
local s = c.v:gsub("[^" .. b .. "=]", "");
|
||||
local res = {}
|
||||
local count = 0
|
||||
for j=1,#s,4 do
|
||||
local v = 0
|
||||
for k=0,3 do
|
||||
local char = s:sub(j+k,j+k)
|
||||
local pos = b:find(char,1,true)
|
||||
v = v*64 + (pos and pos-1 or 0)
|
||||
end
|
||||
for k=2,0,-1 do
|
||||
if j+3-k<=#s and s:sub(j+3-k,j+3-k)~="=" then
|
||||
count = count + 1
|
||||
res[count] = string.char(${nBIT}.bxor(${nBIT}.extract(v,k*8,8),${nBIT}.band(${seed},255)))
|
||||
end
|
||||
end
|
||||
end
|
||||
return table.concat(res)
|
||||
elseif c.t == 2 then return ${nBIT}.bxor(c.v, ${nBIT}.band(${seed}, 65535)) - c.o
|
||||
elseif c.t == 3 then return true elseif c.t == 4 then return false elseif c.t == 5 then return nil end
|
||||
end
|
||||
local ${nDS} = {${dispatchFunctions}}
|
||||
local _p = function() return (os.clock() or tick() or 1) > 0 end
|
||||
while _p() do
|
||||
local op = ${nL}[${nPC}]; if not op then break end
|
||||
${nPC} = ${nPC} + 1
|
||||
local f = ${nDS}[op+1]
|
||||
if f then if f() == "EXIT" then break end else break end
|
||||
end
|
||||
end; return xpcall(VM, function(e) warn("Luartex VM Error: "..tostring(e)) end, ...)`;
|
||||
|
||||
return this.wrapLayers(vmCode, 3, seed);
|
||||
}
|
||||
|
||||
static wrapLayers(code, layers, seed) {
|
||||
let current = code;
|
||||
for (let i = 0; i < layers; i++) {
|
||||
const key = (seed >> (i * 8)) & 0xFF;
|
||||
const encoded = Buffer.from(current).map(b => b ^ key).toString('base64');
|
||||
const keyExp = this.numberToExpression(key);
|
||||
current = `local _v = "${encoded}"
|
||||
local _k = ${keyExp}
|
||||
local function _d(s)
|
||||
local _b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"
|
||||
local _bit = bit32 or bit
|
||||
local res = {}
|
||||
local count = 0
|
||||
s = s:gsub("[^" .. _b:gsub("%%", "%%%%") .. "=]", "")
|
||||
for j = 1, #s, 4 do
|
||||
local v = 0
|
||||
for k = 0, 3 do
|
||||
local char = s:sub(j + k, j + k)
|
||||
local pos = _b:find(char, 1, true)
|
||||
v = v * 64 + (pos and pos - 1 or 0)
|
||||
end
|
||||
for k = 2, 0, -1 do
|
||||
if j + 3 - k <= #s and s:sub(j + 3 - k, j + 3 - k) ~= "=" then
|
||||
count = count + 1
|
||||
res[count] = string.char(_bit.bxor(_bit.extract(v, k * 8, 8), _k))
|
||||
end
|
||||
end
|
||||
end
|
||||
return table.concat(res)
|
||||
end
|
||||
local _l = loadstring or load
|
||||
local _f, _e = _l(_d(_v))
|
||||
if _f then
|
||||
return _f()
|
||||
else
|
||||
error("Luartex Layer Error: " .. tostring(_e))
|
||||
end`;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ObfuscatorService;
|
||||
@ -1,5 +1,6 @@
|
||||
import React, {useEffect, useRef, useState} from 'react'
|
||||
import React, {useEffect, useRef} from 'react'
|
||||
import Link from 'next/link'
|
||||
import { useState } from 'react'
|
||||
import { mdiChevronUp, mdiChevronDown } from '@mdi/js'
|
||||
import BaseDivider from './BaseDivider'
|
||||
import BaseIcon from './BaseIcon'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import React, { ReactNode, useEffect, useState } from 'react'
|
||||
import React, { ReactNode, useEffect } from 'react'
|
||||
import { useState } from 'react'
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { mdiForwardburger, mdiBackburger, mdiMenu } from '@mdi/js'
|
||||
import menuAside from '../menuAside'
|
||||
|
||||
@ -3,9 +3,9 @@ import { MenuAsideItem } from './interfaces'
|
||||
|
||||
const menuAside: MenuAsideItem[] = [
|
||||
{
|
||||
href: '/',
|
||||
icon: icon.mdiShieldLockOutline,
|
||||
label: 'Obfuscator',
|
||||
href: '/dashboard',
|
||||
icon: icon.mdiViewDashboardOutline,
|
||||
label: 'Dashboard',
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
439
frontend/src/pages/dashboard.tsx
Normal file
439
frontend/src/pages/dashboard.tsx
Normal file
@ -0,0 +1,439 @@
|
||||
import * as icon from '@mdi/js';
|
||||
import Head from 'next/head'
|
||||
import React from 'react'
|
||||
import axios from 'axios';
|
||||
import type { ReactElement } from 'react'
|
||||
import LayoutAuthenticated from '../layouts/Authenticated'
|
||||
import SectionMain from '../components/SectionMain'
|
||||
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton'
|
||||
import BaseIcon from "../components/BaseIcon";
|
||||
import { getPageTitle } from '../config'
|
||||
import Link from "next/link";
|
||||
|
||||
import { hasPermission } from "../helpers/userPermissions";
|
||||
import { fetchWidgets } from '../stores/roles/rolesSlice';
|
||||
import { WidgetCreator } from '../components/WidgetCreator/WidgetCreator';
|
||||
import { SmartWidget } from '../components/SmartWidget/SmartWidget';
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../stores/hooks';
|
||||
const Dashboard = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const iconsColor = useAppSelector((state) => state.style.iconsColor);
|
||||
const corners = useAppSelector((state) => state.style.corners);
|
||||
const cardsStyle = useAppSelector((state) => state.style.cardsStyle);
|
||||
|
||||
const loadingMessage = 'Loading...';
|
||||
|
||||
|
||||
const [users, setUsers] = React.useState(loadingMessage);
|
||||
const [roles, setRoles] = React.useState(loadingMessage);
|
||||
const [permissions, setPermissions] = React.useState(loadingMessage);
|
||||
const [projects, setProjects] = React.useState(loadingMessage);
|
||||
const [scripts, setScripts] = React.useState(loadingMessage);
|
||||
const [builds, setBuilds] = React.useState(loadingMessage);
|
||||
const [vm_configs, setVm_configs] = React.useState(loadingMessage);
|
||||
const [opcode_sets, setOpcode_sets] = React.useState(loadingMessage);
|
||||
const [constants, setConstants] = React.useState(loadingMessage);
|
||||
const [audit_logs, setAudit_logs] = React.useState(loadingMessage);
|
||||
|
||||
|
||||
const [widgetsRole, setWidgetsRole] = React.useState({
|
||||
role: { value: '', label: '' },
|
||||
});
|
||||
const { currentUser } = useAppSelector((state) => state.auth);
|
||||
const { isFetchingQuery } = useAppSelector((state) => state.openAi);
|
||||
|
||||
const { rolesWidgets, loading } = useAppSelector((state) => state.roles);
|
||||
|
||||
|
||||
async function loadData() {
|
||||
const entities = ['users','roles','permissions','projects','scripts','builds','vm_configs','opcode_sets','constants','audit_logs',];
|
||||
const fns = [setUsers,setRoles,setPermissions,setProjects,setScripts,setBuilds,setVm_configs,setOpcode_sets,setConstants,setAudit_logs,];
|
||||
|
||||
const requests = entities.map((entity, index) => {
|
||||
|
||||
if(hasPermission(currentUser, `READ_${entity.toUpperCase()}`)) {
|
||||
return axios.get(`/${entity.toLowerCase()}/count`);
|
||||
} else {
|
||||
fns[index](null);
|
||||
return Promise.resolve({data: {count: null}});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Promise.allSettled(requests).then((results) => {
|
||||
results.forEach((result, i) => {
|
||||
if (result.status === 'fulfilled') {
|
||||
fns[i](result.value.data.count);
|
||||
} else {
|
||||
fns[i](result.reason.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function getWidgets(roleId) {
|
||||
await dispatch(fetchWidgets(roleId));
|
||||
}
|
||||
React.useEffect(() => {
|
||||
if (!currentUser) return;
|
||||
loadData().then();
|
||||
setWidgetsRole({ role: { value: currentUser?.app_role?.id, label: currentUser?.app_role?.name } });
|
||||
}, [currentUser]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!currentUser || !widgetsRole?.role?.value) return;
|
||||
getWidgets(widgetsRole?.role?.value || '').then();
|
||||
}, [widgetsRole?.role?.value]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>
|
||||
{getPageTitle('Overview')}
|
||||
</title>
|
||||
</Head>
|
||||
<SectionMain>
|
||||
<SectionTitleLineWithButton
|
||||
icon={icon.mdiChartTimelineVariant}
|
||||
title='Overview'
|
||||
main>
|
||||
{''}
|
||||
</SectionTitleLineWithButton>
|
||||
|
||||
{hasPermission(currentUser, 'CREATE_ROLES') && <WidgetCreator
|
||||
currentUser={currentUser}
|
||||
isFetchingQuery={isFetchingQuery}
|
||||
setWidgetsRole={setWidgetsRole}
|
||||
widgetsRole={widgetsRole}
|
||||
/>}
|
||||
{!!rolesWidgets.length &&
|
||||
hasPermission(currentUser, 'CREATE_ROLES') && (
|
||||
<p className=' text-gray-500 dark:text-gray-400 mb-4'>
|
||||
{`${widgetsRole?.role?.label || 'Users'}'s widgets`}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className='grid grid-cols-1 gap-6 lg:grid-cols-4 mb-6 grid-flow-dense'>
|
||||
{(isFetchingQuery || loading) && (
|
||||
<div className={` ${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 text-lg leading-tight text-gray-500 flex items-center ${cardsStyle} dark:border-dark-700 p-6`}>
|
||||
<BaseIcon
|
||||
className={`${iconsColor} animate-spin mr-5`}
|
||||
w='w-16'
|
||||
h='h-16'
|
||||
size={48}
|
||||
path={icon.mdiLoading}
|
||||
/>{' '}
|
||||
Loading widgets...
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ rolesWidgets &&
|
||||
rolesWidgets.map((widget) => (
|
||||
<SmartWidget
|
||||
key={widget.id}
|
||||
userId={currentUser?.id}
|
||||
widget={widget}
|
||||
roleId={widgetsRole?.role?.value || ''}
|
||||
admin={hasPermission(currentUser, 'CREATE_ROLES')}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{!!rolesWidgets.length && <hr className='my-6 ' />}
|
||||
|
||||
<div id="dashboard" className='grid grid-cols-1 gap-6 lg:grid-cols-3 mb-6'>
|
||||
|
||||
|
||||
{hasPermission(currentUser, 'READ_USERS') && <Link href={'/users/users-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Users
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{users}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={icon.mdiAccountGroup || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_ROLES') && <Link href={'/roles/roles-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Roles
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{roles}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={icon.mdiShieldAccountVariantOutline || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_PERMISSIONS') && <Link href={'/permissions/permissions-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Permissions
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{permissions}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={icon.mdiShieldAccountOutline || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_PROJECTS') && <Link href={'/projects/projects-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Projects
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{projects}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiFolder' in icon ? icon['mdiFolder' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_SCRIPTS') && <Link href={'/scripts/scripts-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Scripts
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{scripts}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiCodeTags' in icon ? icon['mdiCodeTags' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_BUILDS') && <Link href={'/builds/builds-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Builds
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{builds}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiPlayCircle' in icon ? icon['mdiPlayCircle' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_VM_CONFIGS') && <Link href={'/vm_configs/vm_configs-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Vm configs
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{vm_configs}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiCpu' in icon ? icon['mdiCpu' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_OPCODE_SETS') && <Link href={'/opcode_sets/opcode_sets-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Opcode sets
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{opcode_sets}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiCodeBraces' in icon ? icon['mdiCodeBraces' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_CONSTANTS') && <Link href={'/constants/constants-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Constants
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{constants}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiKeyVariant' in icon ? icon['mdiKeyVariant' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
{hasPermission(currentUser, 'READ_AUDIT_LOGS') && <Link href={'/audit_logs/audit_logs-list'}>
|
||||
<div
|
||||
className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
||||
>
|
||||
<div className="flex justify-between align-center">
|
||||
<div>
|
||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">
|
||||
Audit logs
|
||||
</div>
|
||||
<div className="text-3xl leading-tight font-semibold">
|
||||
{audit_logs}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<BaseIcon
|
||||
className={`${iconsColor}`}
|
||||
w="w-16"
|
||||
h="h-16"
|
||||
size={48}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
path={'mdiHistory' in icon ? icon['mdiHistory' as keyof typeof icon] : icon.mdiTable || icon.mdiTable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>}
|
||||
|
||||
|
||||
</div>
|
||||
</SectionMain>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Dashboard.getLayout = function getLayout(page: ReactElement) {
|
||||
return <LayoutAuthenticated>{page}</LayoutAuthenticated>
|
||||
}
|
||||
|
||||
export default Dashboard
|
||||
@ -1,140 +1,166 @@
|
||||
import * as icon from '@mdi/js';
|
||||
import Head from 'next/head';
|
||||
import React, { useState } from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import type { ReactElement } from 'react';
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import BaseButton from '../components/BaseButton';
|
||||
import CardBox from '../components/CardBox';
|
||||
import SectionFullScreen from '../components/SectionFullScreen';
|
||||
import LayoutGuest from '../layouts/Guest';
|
||||
import SectionMain from '../components/SectionMain';
|
||||
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton';
|
||||
import BaseIcon from "../components/BaseIcon";
|
||||
import BaseButton from "../components/BaseButton";
|
||||
import CardBox from "../components/CardBox";
|
||||
import BaseDivider from '../components/BaseDivider';
|
||||
import BaseButtons from '../components/BaseButtons';
|
||||
import { getPageTitle } from '../config';
|
||||
import { useAppSelector } from '../stores/hooks';
|
||||
import CardBoxComponentTitle from "../components/CardBoxComponentTitle";
|
||||
import { getPexelsImage, getPexelsVideo } from '../helpers/pexels';
|
||||
|
||||
export default function LuartexHome() {
|
||||
const corners = useAppSelector((state) => state.style.corners);
|
||||
const cardsStyle = useAppSelector((state) => state.style.cardsStyle);
|
||||
|
||||
const [sourceCode, setSourceCode] = useState('print("Hello from Luartex!")');
|
||||
const [protectedCode, setProtectedCode] = useState('');
|
||||
const [isProtecting, setIsProtecting] = useState(false);
|
||||
export default function Starter() {
|
||||
const [illustrationImage, setIllustrationImage] = useState({
|
||||
src: undefined,
|
||||
photographer: undefined,
|
||||
photographer_url: undefined,
|
||||
})
|
||||
const [illustrationVideo, setIllustrationVideo] = useState({video_files: []})
|
||||
const [contentType, setContentType] = useState('video');
|
||||
const [contentPosition, setContentPosition] = useState('left');
|
||||
const textColor = useAppSelector((state) => state.style.linkColor);
|
||||
|
||||
const handleProtect = async () => {
|
||||
setIsProtecting(true);
|
||||
try {
|
||||
const response = await axios.post('/builds/protect', {
|
||||
source: sourceCode,
|
||||
config: {
|
||||
opcodeShuffling: true,
|
||||
constantEncryption: true
|
||||
const title = 'Luartex VM Obfuscator'
|
||||
|
||||
// Fetch Pexels image/video
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
const image = await getPexelsImage();
|
||||
const video = await getPexelsVideo();
|
||||
setIllustrationImage(image);
|
||||
setIllustrationVideo(video);
|
||||
}
|
||||
});
|
||||
setProtectedCode(response.data.protectedCode);
|
||||
} catch (error) {
|
||||
console.error('Protection failed:', error);
|
||||
setProtectedCode('-- Error: Protection failed. Check server logs.');
|
||||
} finally {
|
||||
setIsProtecting(false);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
const imageBlock = (image) => (
|
||||
<div
|
||||
className='hidden md:flex flex-col justify-end relative flex-grow-0 flex-shrink-0 w-1/3'
|
||||
style={{
|
||||
backgroundImage: `${
|
||||
image
|
||||
? `url(${image?.src?.original})`
|
||||
: 'linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5))'
|
||||
}`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'left center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
}}
|
||||
>
|
||||
<div className='flex justify-center w-full bg-blue-300/20'>
|
||||
<a
|
||||
className='text-[8px]'
|
||||
href={image?.photographer_url}
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
>
|
||||
Photo by {image?.photographer} on Pexels
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const videoBlock = (video) => {
|
||||
if (video?.video_files?.length > 0) {
|
||||
return (
|
||||
<div className='hidden md:flex flex-col justify-end relative flex-grow-0 flex-shrink-0 w-1/3'>
|
||||
<video
|
||||
className='absolute top-0 left-0 w-full h-full object-cover'
|
||||
autoPlay
|
||||
loop
|
||||
muted
|
||||
>
|
||||
<source src={video?.video_files[0]?.link} type='video/mp4'/>
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
<div className='flex justify-center w-full bg-blue-300/20 z-10'>
|
||||
<a
|
||||
className='text-[8px]'
|
||||
href={video?.user?.url}
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
>
|
||||
Video by {video.user.name} on Pexels
|
||||
</a>
|
||||
</div>
|
||||
</div>)
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-[#0D1117] min-h-screen text-white">
|
||||
<div
|
||||
style={
|
||||
contentPosition === 'background'
|
||||
? {
|
||||
backgroundImage: `${
|
||||
illustrationImage
|
||||
? `url(${illustrationImage.src?.original})`
|
||||
: 'linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5))'
|
||||
}`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'left center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
}
|
||||
: {}
|
||||
}
|
||||
>
|
||||
<Head>
|
||||
<title>{getPageTitle('Luartex | Advanced Luau Protection')}</title>
|
||||
<title>{getPageTitle('Starter Page')}</title>
|
||||
</Head>
|
||||
|
||||
<div className="py-12 px-4 max-w-7xl mx-auto">
|
||||
<div className="text-center mb-16 space-y-4">
|
||||
<h1 className="text-6xl md:text-8xl font-black tracking-tighter text-transparent bg-clip-text bg-gradient-to-r from-green-400 to-blue-500">
|
||||
LUARTEX
|
||||
</h1>
|
||||
<p className="text-xl text-gray-400 font-light max-w-2xl mx-auto">
|
||||
Heavyweight <span className="text-green-400 font-semibold">Luau Virtual Machine</span> protection.
|
||||
Transform your scripts into unreadable, irreversible bytecode.
|
||||
</p>
|
||||
<SectionFullScreen bg='violet'>
|
||||
<div
|
||||
className={`flex ${
|
||||
contentPosition === 'right' ? 'flex-row-reverse' : 'flex-row'
|
||||
} min-h-screen w-full`}
|
||||
>
|
||||
{contentType === 'image' && contentPosition !== 'background'
|
||||
? imageBlock(illustrationImage)
|
||||
: null}
|
||||
{contentType === 'video' && contentPosition !== 'background'
|
||||
? videoBlock(illustrationVideo)
|
||||
: null}
|
||||
<div className='flex items-center justify-center flex-col space-y-4 w-full lg:w-full'>
|
||||
<CardBox className='w-full md:w-3/5 lg:w-2/3'>
|
||||
<CardBoxComponentTitle title="Welcome to your Luartex VM Obfuscator app!"/>
|
||||
|
||||
<div className="space-y-3">
|
||||
<p className='text-center text-gray-500'>This is a React.js/Node.js app generated by the <a className={`${textColor}`} href="https://flatlogic.com/generator">Flatlogic Web App Generator</a></p>
|
||||
<p className='text-center text-gray-500'>For guides and documentation please check
|
||||
your local README.md and the <a className={`${textColor}`} href="https://flatlogic.com/documentation">Flatlogic documentation</a></p>
|
||||
</div>
|
||||
|
||||
<BaseButtons>
|
||||
<BaseButton
|
||||
href='/login'
|
||||
label='Login'
|
||||
color='info'
|
||||
className='w-full'
|
||||
/>
|
||||
|
||||
</BaseButtons>
|
||||
</CardBox>
|
||||
</div>
|
||||
|
||||
<SectionMain>
|
||||
<SectionTitleLineWithButton
|
||||
icon={icon.mdiCodeTags}
|
||||
title='Luartex Playground'
|
||||
main>
|
||||
<BaseButton
|
||||
label={isProtecting ? 'Protecting...' : 'Protect Script'}
|
||||
color='success'
|
||||
icon={icon.mdiShieldLock}
|
||||
onClick={handleProtect}
|
||||
disabled={isProtecting}
|
||||
className="rounded-full px-8 py-2 font-bold"
|
||||
/>
|
||||
</SectionTitleLineWithButton>
|
||||
|
||||
<div className='grid grid-cols-1 gap-6 lg:grid-cols-2 mb-12'>
|
||||
<CardBox className={`${cardsStyle} ${corners} bg-[#161B22] border-gray-800`}>
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<span className="text-sm font-bold uppercase tracking-wider text-gray-400">Source Luau</span>
|
||||
<BaseIcon path={icon.mdiLanguageLua} size={18} className="text-green-400" />
|
||||
</div>
|
||||
<textarea
|
||||
className="w-full h-[500px] p-4 font-mono text-sm bg-gray-900 text-green-400 border border-gray-800 focus:ring-1 focus:ring-green-500 rounded-lg resize-none"
|
||||
value={sourceCode}
|
||||
onChange={(e) => setSourceCode(e.target.value)}
|
||||
spellCheck={false}
|
||||
/>
|
||||
</CardBox>
|
||||
|
||||
<CardBox className={`${cardsStyle} ${corners} bg-[#161B22] border-gray-800`}>
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<span className="text-sm font-bold uppercase tracking-wider text-gray-400">Protected Output (VM)</span>
|
||||
<BaseIcon path={icon.mdiShieldCheck} size={18} className="text-blue-400" />
|
||||
</div>
|
||||
<textarea
|
||||
className="w-full h-[500px] p-4 font-mono text-sm bg-gray-900 text-blue-400 border border-gray-800 rounded-lg resize-none"
|
||||
value={protectedCode}
|
||||
readOnly
|
||||
placeholder="Click 'Protect Script' to generate VM-protected code..."
|
||||
spellCheck={false}
|
||||
/>
|
||||
</CardBox>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-1 gap-6 lg:grid-cols-4 mb-12'>
|
||||
<div className={`${corners} ${cardsStyle} p-6 bg-[#161B22] border-l-4 border-green-500 border-gray-800`}>
|
||||
<div className="text-gray-400 text-xs uppercase font-bold">Opcodes Shuffled</div>
|
||||
<div className="text-2xl font-bold">RANDOMIZED</div>
|
||||
</div>
|
||||
<div className={`${corners} ${cardsStyle} p-6 bg-[#161B22] border-l-4 border-blue-500 border-gray-800`}>
|
||||
<div className="text-gray-400 text-xs uppercase font-bold">Constants Encrypted</div>
|
||||
<div className="text-2xl font-bold">MULTI-LAYER</div>
|
||||
</div>
|
||||
<div className={`${corners} ${cardsStyle} p-6 bg-[#161B22] border-l-4 border-yellow-500 border-gray-800`}>
|
||||
<div className="text-gray-400 text-xs uppercase font-bold">VM Hardening</div>
|
||||
<div className="text-2xl font-bold text-yellow-500">ACTIVE</div>
|
||||
</div>
|
||||
<div className={`${corners} ${cardsStyle} p-6 bg-[#161B22] border-l-4 border-red-500 border-gray-800`}>
|
||||
<div className="text-gray-400 text-xs uppercase font-bold">Anti-Dump</div>
|
||||
<div className="text-2xl font-bold text-red-500">ENABLED</div>
|
||||
</div>
|
||||
</div>
|
||||
</SectionMain>
|
||||
</div>
|
||||
</SectionFullScreen>
|
||||
<div className='bg-black text-white flex flex-col text-center justify-center md:flex-row'>
|
||||
<p className='py-6 text-sm'>© 2026 <span>{title}</span>. All rights reserved</p>
|
||||
<Link className='py-6 ml-4 text-sm' href='/privacy-policy/'>
|
||||
Privacy Policy
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<footer className="border-t border-gray-800 bg-[#0D1117] py-12">
|
||||
<div className="max-w-7xl mx-auto px-4 flex flex-col md:flex-row justify-between items-center text-gray-500 text-sm">
|
||||
<p>© 2026 Luartex Protection Systems. Authorized defensive use only.</p>
|
||||
<div className="flex space-x-6 mt-4 md:mt-0">
|
||||
<span className="font-mono text-xs text-green-500/50">ROBLOX LUAU</span>
|
||||
<span className="font-mono text-xs text-blue-500/50">VIRTUALIZATION</span>
|
||||
<span className="font-mono text-xs text-purple-500/50">AES-256</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
LuartexHome.getLayout = function getLayout(page: ReactElement) {
|
||||
Starter.getLayout = function getLayout(page: ReactElement) {
|
||||
return <LayoutGuest>{page}</LayoutGuest>;
|
||||
};
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import type { ReactElement } from 'react';
|
||||
import Head from 'next/head';
|
||||
@ -60,10 +62,10 @@ export default function Login() {
|
||||
dispatch(findMe());
|
||||
}
|
||||
}, [token, dispatch]);
|
||||
// Redirect to home if user is logged in
|
||||
// Redirect to dashboard if user is logged in
|
||||
useEffect(() => {
|
||||
if (currentUser?.id) {
|
||||
router.push('/');
|
||||
router.push('/dashboard');
|
||||
}
|
||||
}, [currentUser?.id, router]);
|
||||
// Show error message if there is one
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user