forked from HolaClient/4x8a-98hf-pah2-0410
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
275 lines (254 loc) · 9.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"use strict";
//load modules
const log = require('./routes/handlers/webhook')
const arciotext = require('./routes/handlers/arciotext')
const indexjs = require("./index.js");
global.debuglog = require('./lib/debug');
global.l = require('./lib/debug');
//indicate startup
l.s(`Startup initiated...`)
l.s(`Loading modules...`)
//load packages
l.s(`Loading packages...`)
const chalk = require("chalk");
const fs = require("fs");
const { renderFile } = require('ejs')
const ora = require('ora');
const geoip = require('geoip-lite');
const fetch = require('node-fetch');
const path = require('path');
const express = require("express");
const app = express();
const ejs = require("ejs");
const session = require("express-session");
//load settings
l.s(`Loading settings...`)
global.settings = require('./handlers/settings').settings();
global.eggconfig = require('./eggs.json')
global.alerts = require(`./lang/${settings.website.language}/alerts.json`).alerts
const newsettings = require('./handlers/settings').settings();
const defaultthemesettings = {
index: "index.ejs",
notfound: "index.ejs",
redirect: {},
pages: {},
mustbeloggedin: [],
mustbeadmin: [],
variables: {}
};
//load express addons
l.s(`Loading addons...`)
require('express-ws')(app);
module.exports.app = app;
//load database
l.s(`Loading database...`)
const db = require('./handlers/database').db();
module.exports.db = db;
//load website
l.s(`Loading website...`)
app.use(session({
secret: settings.website.secret,
resave: false,
saveUninitialized: false
}));
app.use(express.json({
inflate: true,
limit: '500kb',
reviver: null,
strict: true,
type: 'application/json',
verify: undefined
}));
//load country blacklist
const blacklistedCountry = settings.features.blacklist.country;
app.use((req, res, next) => {
const userCountry = geoip.lookup(req.ip);
if (blacklistedCountry.includes(userCountry?.country)) {
res.status(403)
renderFile(
`./views/${settings.defaulttheme}/alerts/blacklisted.ejs`,
{ settings: settings, db, extra: { home: { name: 'error' } } },
null,
(err, str) => {
if (err) return res.send('Access restriected from your country!');
res.status(403);
res.send(str);
}
);
} else {
next();
}
});
//load routes
l.s(`Loading routes...`)
loadRoute(path.join(__dirname, 'routes'), app, db); l.r(`admins`)
loadRoute(path.join(__dirname, 'routes', 'admin'), app, db);
if (settings.api.enabled === true) { l.r(`APIs`); loadRoute(path.join(__dirname, 'routes', 'application'), app, db); }
loadRoute(path.join(__dirname, 'routes', 'authentication'), app, db); l.r(`authenticators`)
loadRoute(path.join(__dirname, 'routes', 'billing'), app, db); l.r(`billers`)
loadRoute(path.join(__dirname, 'routes', 'earn'), app, db); l.r(`earn`)
loadRoute(path.join(__dirname, 'routes', 'structures'), app, db); l.r(`structures`)
loadRoute(path.join(__dirname, 'routes', 'controller'), app, db); l.r(`controllers`)
loadRoute(path.join(__dirname, 'routes', 'users'), app, db); l.r(`clients`)
loadRoute(path.join(__dirname, 'routes', 'features'), app, db); l.r(`features`)
loadRoute(path.join(__dirname, 'routes', 'router'), app, db);
l.s(`Loading theme settings...`)
module.exports.get = function (req) {
let defaulttheme = settings.defaulttheme;
let tname = encodeURIComponent(getCookie(req, "theme"));
let name = (
tname ?
fs.existsSync(`./views/${tname}`) ?
tname :
defaulttheme :
defaulttheme
)
return {
settings: (
fs.existsSync(`./views/${name}/pages.json`) ?
JSON.parse(fs.readFileSync(`./views/${name}/pages.json`).toString()) :
defaultthemesettings
),
name: name
};
};
module.exports.renderdataeval =
`(async () => {
const JavaScriptObfuscator = require('javascript-obfuscator');
const newsettings = settings
let renderdata = {
req: req,
settings: newsettings,
eggs: eggconfig,
user: req.session.user,
userinfo: req.session.userinfo,
packagename: req.session.userinfo ? (await db.get("package-" + req.session.userinfo.hcid)) || newsettings.packages.default : null,
extraresources: !req.session.userinfo ? null : (await db.get("extra-" + req.session.userinfo.hcid) ? await db.get("extra-" + req.session.userinfo.hcid) : {
ram: 0,
disk: 0,
cpu: 0,
servers: 0,
backups: 0,
allocations: 0,
databases: 0
}),
packages: req.session.userinfo ? newsettings.packages.list[await db.get("package-" + req.session.userinfo.hcid) ? await db.get("package-" + req.session.userinfo.hcid) : newsettings.packages.default] : null,
coins: newsettings.coins.enabled == true ? (req.session.userinfo ? (await db.get("coins-" + req.session.userinfo.hcid) ? await db.get("coins-" + req.session.userinfo.hcid) : 0) : null) : null,
pterodactyl: req.session.pterodactyl,
theme: theme.name,
extra: theme.settings.variables,
db: db
};
if (newsettings.earn.arcio.enabled == true && req.session.arcsessiontoken) {
renderdata.arcioafktext = JavaScriptObfuscator.obfuscate(\`
let token = "\${req.session.arcsessiontoken}";
let everywhat = \${newsettings.earn.arcio["afk page"].every};
let gaincoins = \${newsettings.earn.arcio["afk page"].coins};
let arciopath = "\${newsettings.earn.arcio["afk page"].path.replace(/\\\\/g, "\\\\\\\\").replace(/"/g, "\\\\\\"")}";
\${arciotext}
\`);
};
return renderdata;
})();`;
l.s(`Sending startup indication...`)
log('status', `Successfully loaded HolaClient at ${settings.website.hostname}/`)
//show startup logs
const listener = app.listen(settings.website.port, function () {
console.clear()
console.log(chalk.gray(" "));
console.log(" _ _ _ _____ _ _ _ ");
console.log(" | | | | | | / ____| (_) | | ");
console.log(" | |__| | ___ | | __ _| | | |_ ___ _ __ | |_ ");
console.log(" | __ |/ _ \\| |/ _` | | | | |/ _ \\ '_ \\| __|");
console.log(" | | | | (_) | | (_| | |____| | | __/ | | | |_ ");
console.log(" |_| |_|\\___/|_|\\__,_|\\_____|_|_|\\___|_| |_|\\__|");
console.log(chalk.white(" "))
console.log(chalk.white("=====================SOCIAL======================"));
console.log(`${chalk.gray("[+]")} ${chalk.white("[")}${chalk.cyan("Discord")}${chalk.white("]")}${chalk.white(" https://discord.gg/CvqRH9TrYK ")}`);
console.log(`${chalk.gray("[+]")} ${chalk.white("[")}${chalk.cyan("Github")}${chalk.white("]")}${chalk.white(" https://github.com/CR072/HolaClient ")}`);
console.log(`${chalk.gray("[+]")} ${chalk.white("[")}${chalk.cyan("Website")}${chalk.white("]")}${chalk.white(" https://holaclient.tech ")}`);
console.log(chalk.white("================================================="));
console.log(" ");
console.log(chalk.gray("[🔗]") + chalk.cyan("[") + chalk.white("HolaClient") + chalk.cyan("]") + chalk.white(" Successfully loaded HolaClient at ") + chalk.cyan(settings.website.hostname + "/"));
if (settings.features.security.enabled === true) {
if (settings.features.security.anti_ddos.enabled === true) {
const challenge = require('./security/challenge')
}
if (settings.features.security.rate_limiter.enabled === true) {
const ratelimiter = require('./security/ratelimiter')
}
if (settings.features.security.anti_crawler.enabled === true) {
const crawlers = require('./security/crawlers')
}
}
setTimeout(() => {
loadRoute(path.join(__dirname, 'lib'), app, db);
}, 3000);
function st() {
console.log("")
const spinner = ora({
text: chalk.yellow('Generating endpoints...'),
spinner: 'dots',
}).start();
setTimeout(() => {
spinner.succeed(chalk.gray("[✅]") + chalk.cyan("[") + chalk.white("HolaClient") + chalk.cyan("]") + chalk.white(" Endpoints generated successfully. "));
}, 3000);
}
setTimeout(() => {
st();
setTimeout(() => {
}, 3000);
}, 4000);
});
module.exports.islimited = async function () {
return cache == true ? false : true;
}
module.exports.ratelimits = async function (length) {
if (cache == true) return setTimeout(
indexjs.ratelimits, 1
);
cache = true;
setTimeout(
async function () {
cache = false;
}, length * 1000
)
}
global.Buffer = global.Buffer || require('buffer').Buffer;
if (typeof btoa === 'undefined') {
global.btoa = function (str) {
return new Buffer(str, 'binary').toString('base64');
};
}
if (typeof atob === 'undefined') {
global.atob = function (b64Encoded) {
return new Buffer(b64Encoded, 'base64').toString('binary');
};
}
function loadRoute(directory, app, db) {
const files = fs.readdirSync(directory).filter(file => file.endsWith('.js'));
files.forEach(file => {
const routeModule = require(path.join(directory, file));
if (typeof routeModule.load === 'function') {
routeModule.load(app, db);
} else {
console.log(`${chalk.white("[")}${chalk.blue("LOADER")}${chalk.white("] [")}${chalk.gray("ROUTER")}${chalk.white("] ")}${chalk.red(`Error while loading ${chalk.cyan(`${file}`)}`)}`)
}
});
}
function getCookie(req, cname) {
let cookies = req.headers.cookie;
if (!cookies) return null;
let name = cname + "=";
let ca = cookies.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return decodeURIComponent(c.substring(name.length, c.length));
}
}
return "";
}