-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.php
More file actions
executable file
·349 lines (291 loc) · 9.3 KB
/
scripts.php
File metadata and controls
executable file
·349 lines (291 loc) · 9.3 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
# TITLE : Application Scripts
# DESC : The scripts that are handling the admin control functions
# PROPRIETOR: VARSITYMARKET_TECHNOLOGIES
# VERSION : 1.0.1.1
# AUTHOR : HARDY HASTINGS
# RELEASE : 2026/01/30
define("__DB_MODULE__",initiate_database());
define("__DB_WEBSITE__",initiate_web_database());
function get_domain(){
// Standard method
$domain = $_SERVER['HTTP_HOST'] ?? false ;
if ($domain == false){
$domain = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'];
}
return $domain;
}
function map(){
$e = [
"auth" => "page.auth.php",
"home" => "page.dashboard.php",
"payments" => "page.payments.php",
"theme" => "page.theme.php",
"export-frame" => "page.export.frame.php",
"export-link" => "page.export.link.php",
"export-source" => "page.export.code.php",
];
return $e;
}
function account_data($index){
@include_once "config.php";
$AUTH = __ACCOUNT_INDEX__;
$tbl_index = $index;
$sql = "SELECT * FROM `sys_account` WHERE (`auth` = ?) LIMIT 1";
$e = __DB_MODULE__->query($sql, [$AUTH]);
$result = $e[0][$tbl_index] ?? false;
return $result;
}
function website_data($index,$auth=false){
@include_once "config.php";
if ($auth == false){
$AUTH = __ACCOUNT_INDEX__;
}else{
$AUTH = $auth;
}
$tbl_index = $index;
$sql = "SELECT * FROM `sys_websites` WHERE (`account_index` = ?) LIMIT 1";
$e = __DB_MODULE__->query($sql, [$AUTH]);
$result = $e[0][$tbl_index] ?? false;
return $result;
}
function banking_data($index){
@include_once "config.php";
$AUTH = __ACCOUNT_INDEX__;
$tbl_index = $index;
$sql = "SELECT * FROM `sys_banking` WHERE (`account_index` = ?) LIMIT 1";
$e = __DB_MODULE__->query($sql, [$AUTH]);
try {
$signature_key = $e[0]['signature_key'];
$result = $e[0]['data'];
$output = __decryption__($result,$signature_key);
$output = json_decode($output,JSON_PRETTY_PRINT);
$output = $output[$index];
return $output;
} catch (\Throwable $th) {
return false;
}
}
function admin_percentage(){
return 20;
}
function ex($section = 1)
{
$x = $_SERVER['REQUEST_URI'];
// Strip query string from the URI to ensure clean segment matching
$x = strtok($x, '?');
$_xm = explode("/", $x);
return $_xm[$section] ?? '';
}
function __account_index__(){
try {
$source = $_SESSION['vm_index'];
$source2 = $_SESSION['vm_key'];
$index = base_decryption($source);
$key = base64_decode($source2);
$e = __decryption__($index,$key);
return $e;
} catch (\Throwable $th) {
return false;
}
}
function base_encryption($plaintext) {
$key= create_enc_key();
$e = __encryption__($plaintext,$key);
return $e;
}
function base_decryption($ciphertext) {
$key= create_enc_key();
$e = __decryption__($ciphertext,$key);
return $e;
}
function __encryption__($data,$key){
$plaintext = $data;
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$ciphertext = openssl_encrypt($plaintext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return base64_encode($iv . $ciphertext);
}
function __decryption__($data,$key) {
$ciphertext = $data;
$ciphertext = base64_decode($ciphertext ?? '');
$iv = substr($ciphertext, 0, openssl_cipher_iv_length('aes-256-cbc'));
$plaintext = openssl_decrypt(substr($ciphertext, openssl_cipher_iv_length('aes-256-cbc')), 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return $plaintext;
}
function create_enc_key(){
$default = 'POIETRWQITHASURTO3985HD8JD7549DYH58FY';
return $default;
}
function database_services($domain){
if (!defined('__ANCHOR_SITE__')){
define("__ANCHOR_SITE__",$domain);
}
$service = dirname(__FILE__)."/services/database.install.php";
@include_once $service;
return true;
}
function website_services($domain,$theme){
if (!defined('__ANCHOR_SITE__')){
define("__ANCHOR_SITE__",$domain);
}
if (!defined('__ANCHOR_THEME__')){
define("__ANCHOR_THEME__",$theme);
}
$service = dirname(__FILE__)."/services/website.install.php";
@include_once $service;
return true;
}
function initiate_web_database(){
@include_once "config.php";
if (!defined('__DOMAIN__')){
trigger_error('Failed To Locate Defined Database');
return null;
}
$file = dirname(__FILE__)."/sites/".__DOMAIN__."/storage.data";
if (__DOMAIN__ == null){
return null;
}
$db_file = dirname(__FILE__)."/module/database.php";
@include_once $db_file;
$e = new database_manager($file);
return $e;
}
function initiate_sensitive_database(){
@include_once "config.php";
if (!defined('__DOMAIN__')){
return null;
}
$file = dirname(__FILE__)."/sites/".__DOMAIN__."/sensitive.data";
$db_file = dirname(__FILE__)."/module/database.php";
@include_once $db_file;
$e = new database_manager($file);
// Create the settings table if it doesn't exist
$e->createTable("settings", [
"key" => "VARCHAR(255) PRIMARY KEY",
"value" => "TEXT"
]);
return $e;
}
function initiate_private_database($domain){
if (empty($domain)){
return null;
}
$store_hash = hash('sha256', $domain);
$private_dir = dirname(dirname(__FILE__))."/data/".$store_hash;
// Fallback to local build dir if the external data dir isn't writable
if (!is_dir(dirname(dirname(__FILE__))."/data/") && !@mkdir(dirname(dirname(__FILE__))."/data/", 0755, true)) {
$private_dir = dirname(__FILE__)."/build/data/".$store_hash;
}
if (!is_dir($private_dir)){
@mkdir($private_dir, 0755, true);
}
$file = $private_dir."/".$domain;
$db_file = dirname(__FILE__)."/module/database.php";
@include_once $db_file;
$e = new database_manager($file);
// Create API keys table
$e->createTable("api_keys", [
"id" => "INTEGER PRIMARY KEY AUTOINCREMENT",
"key_name" => "VARCHAR(255)",
"api_key" => "VARCHAR(255) UNIQUE",
"active" => "INTEGER DEFAULT 1",
"last_used" => "DATETIME",
"created_at" => "DATETIME DEFAULT CURRENT_TIMESTAMP"
]);
// Create API access logs table
$e->createTable("api_logs", [
"id" => "INTEGER PRIMARY KEY AUTOINCREMENT",
"api_key" => "VARCHAR(255)",
"endpoint" => "VARCHAR(255)",
"ip_address" => "VARCHAR(45)",
"user_agent" => "TEXT",
"created_at" => "DATETIME DEFAULT CURRENT_TIMESTAMP"
]);
return $e;
}
function debug($output){
file_put_contents(dirname(__FILE__).'/build/raw.debug',$output,FILE_APPEND);
}
function initiate_database(){
$file = dirname(__FILE__)."/build/vm.engine.sql";
$db_file = dirname(__FILE__)."/module/database.php";
@include_once $db_file;
$e = new database_manager($file);
return $e;
}
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
function extract_theme_nodes($filePath) {
// 1. Check if the file exists to avoid errors
if (!file_exists($filePath)) {
return "Error: File not found.";
}
$content = file_get_contents($filePath);
$pattern = '/e\((__[A-Z_]+__)\)/';
// 4. Perform the search
if (preg_match_all($pattern, $content, $matches)) {
// $matches[1] contains the values inside the capture group parentheses
$e = $matches[1];
return $matches[1];
}
return []; // Return empty array if no matches found
}
function load_env($path)
{
if (!file_exists($path)) {
return false;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
// Skip comments starting with #
if (strpos(trim($line), '#') === 0) {
continue;
}
// Split by the first '=' found
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
// Remove surrounding quotes if they exist
$value = trim($value, '"\'');
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
return true;
}
function delete_folder($dir) {
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!delete_folder($dir . "/" . $item)) {
return false;
}
}
return rmdir($dir);
}