Skip to content

Commit 10d844f

Browse files
authored
Merge branch 'mahdiMGF2:main' into main
2 parents 9d4b616 + e36b778 commit 10d844f

5 files changed

Lines changed: 506 additions & 704 deletions

File tree

app/index.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,10 @@
1-
<?php
2-
$scriptName = $_SERVER['SCRIPT_NAME'] ?? '';
3-
$scriptDir = str_replace('\\', '/', dirname($scriptName));
4-
if ($scriptDir === '.' || $scriptDir === '') {
5-
$scriptDir = '';
6-
} elseif ($scriptDir !== '/') {
7-
$scriptDir = '/' . ltrim($scriptDir, '/');
8-
$scriptDir = rtrim($scriptDir, '/');
9-
} else {
10-
$scriptDir = '/';
11-
}
12-
$basename = $scriptDir === '' ? '/' : $scriptDir;
13-
$prefix = $basename === '/' ? '/' : $basename . '/';
14-
$rootForApi = $basename === '/' ? '/' : rtrim(dirname($basename), '/');
15-
if ($rootForApi === '' || $rootForApi === '.') {
16-
$rootForApi = '/';
17-
}
18-
$apiPath = $rootForApi === '/' ? '/api' : $rootForApi . '/api';
19-
$forwardedProto = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
20-
if (is_string($forwardedProto) && $forwardedProto !== '') {
21-
$scheme = explode(',', $forwardedProto)[0];
22-
} elseif (!empty($_SERVER['REQUEST_SCHEME'])) {
23-
$scheme = $_SERVER['REQUEST_SCHEME'];
24-
} else {
25-
$https = $_SERVER['HTTPS'] ?? '';
26-
$scheme = (!empty($https) && $https !== 'off') ? 'https' : 'http';
27-
}
28-
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
29-
$apiUrl = rtrim($scheme . '://' . $host, '/') . $apiPath;
30-
$config = [
31-
'basename' => $basename,
32-
'prefix' => $prefix,
33-
'apiUrl' => $apiUrl,
34-
];
35-
?>
361
<!DOCTYPE html>
372
<html lang="en">
383
<head>
394
<meta charset="UTF-8" />
405
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
416
<title>Mirza Web App</title>
427
<script src="./js/telegram-web-app.js"></script>
43-
<script>
44-
window.__APP_CONFIG__ = <?php echo json_encode($config, JSON_UNESCAPED_SLASHES); ?>;
45-
</script>
468
<script type="module" crossorigin src="./assets/index-C-2a0Dur.js"></script>
479
<link rel="modulepreload" crossorigin href="./assets/vendor-CIGJ9g2q.js">
4810
<link rel="stylesheet" crossorigin href="./assets/index-BoHBsj0Z.css">

cronbot/backupbot.php

Lines changed: 38 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,211 +1,59 @@
11
<?php
2-
require_once __DIR__ . '/../config.php';
3-
require_once __DIR__ . '/../function.php';
4-
require_once __DIR__ . '/../botapi.php';
5-
6-
function manualDbBackup($host, $user, $pass, $dbname, $filename) {
7-
$mysqli = new mysqli($host, $user, $pass, $dbname);
8-
if ($mysqli->connect_error) {
9-
throw new Exception("اتصال به دیتابیس شکست خورد: " . $mysqli->connect_error);
10-
}
11-
$mysqli->set_charset("utf8mb4");
12-
13-
$tables = [];
14-
$result = $mysqli->query("SHOW TABLES");
15-
while ($row = $result->fetch_row()) {
16-
$tables[] = $row[0];
17-
}
18-
19-
$sql = "SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";\n";
20-
$sql .= "START TRANSACTION;\n";
21-
$sql .= "SET time_zone = \"+00:00\";\n\n";
22-
23-
foreach ($tables as $table) {
24-
$sql .= "DROP TABLE IF EXISTS `$table`;\n";
25-
$create = $mysqli->query("SHOW CREATE TABLE `$table`");
26-
$createRow = $create->fetch_row();
27-
$sql .= $createRow[1] . ";\n\n";
28-
29-
$data = $mysqli->query("SELECT * FROM `$table`");
30-
$numFields = $data->field_count;
31-
32-
for ($i = 0; $i < $data->num_rows; $i++) {
33-
$row = $data->fetch_row();
34-
$sql .= "INSERT INTO `$table` VALUES(";
35-
for ($j = 0; $j < $numFields; $j++) {
36-
$row[$j] = isset($row[$j]) ? addslashes($row[$j]) : 'NULL';
37-
$row[$j] = str_replace("\n", "\\n", $row[$j]);
38-
if (!isset($row[$j]) || $row[$j] == 'NULL') {
39-
$sql .= "NULL";
40-
} else {
41-
$sql .= "'" . $row[$j] . "'";
42-
}
43-
if ($j < ($numFields - 1)) {
44-
$sql .= ',';
45-
}
46-
}
47-
$sql .= ");\n";
48-
}
49-
$sql .= "\n\n";
50-
}
51-
52-
$sql .= "COMMIT;\n";
53-
54-
if (file_put_contents($filename, $sql) === false) {
55-
throw new Exception("خطا در ذخیره فایل بکاپ: $filename");
56-
}
57-
58-
$mysqli->close();
59-
return true;
60-
}
61-
62-
function createAndSendZip($filePath, $caption, $chatId, $threadId) {
63-
if (!file_exists($filePath)) return false;
64-
65-
$zipPath = $filePath . '.zip';
66-
67-
if (class_exists('ZipArchive')) {
68-
$zip = new ZipArchive();
69-
if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
70-
$zip->addFile($filePath, basename($filePath));
71-
$zip->close();
72-
$sendFile = $zipPath;
73-
} else {
74-
$sendFile = $filePath;
75-
}
76-
} else {
77-
$sendFile = $filePath;
78-
}
79-
80-
try {
81-
telegram('sendDocument', [
82-
'chat_id' => $chatId,
83-
'message_thread_id' => $threadId,
84-
'document' => new CURLFile(realpath($sendFile)),
85-
'caption' => $caption,
86-
]);
87-
88-
if (file_exists($sendFile)) unlink($sendFile);
89-
if (file_exists($filePath)) unlink($filePath);
90-
} catch (Exception $e) {
91-
error_log("خطا در ارسال فایل: " . $e->getMessage());
92-
return false;
93-
}
94-
95-
return true;
96-
}
97-
2+
require_once '../config.php';
3+
require_once '../function.php';
4+
require_once '../botapi.php';
985

996
$reportbackup = select("topicid", "idreport", "report", "backupfile", "select")['idreport'];
1007
$destination = getcwd();
1018
$setting = select("setting", "*");
1029
$sourcefir = dirname($destination);
10310
$botlist = select("botsaz", "*", null, null, "fetchAll");
104-
105-
10611
if ($botlist) {
10712
foreach ($botlist as $bot) {
10813
$folderName = $bot['id_user'] . $bot['username'];
109-
$botBasePath = $sourcefir . '/vpnbot/' . $folderName;
110-
$zipFilePath = $destination . '/file_' . $folderName . '.zip';
111-
112-
if (!is_dir($botBasePath)) continue;
113-
114-
$filesToZip = [];
115-
foreach (['data', 'product.json', 'product_name.json'] as $item) {
116-
$fullPath = $botBasePath . '/' . $item;
117-
if (file_exists($fullPath)) {
118-
$filesToZip[] = $fullPath;
119-
}
120-
}
121-
122-
if (empty($filesToZip)) continue;
123-
124-
if (class_exists('ZipArchive')) {
125-
$zip = new ZipArchive();
126-
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
127-
foreach ($filesToZip as $path) {
128-
if (is_dir($path)) {
129-
$iterator = new RecursiveIteratorIterator(
130-
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
131-
RecursiveIteratorIterator::SELF_FIRST
132-
);
133-
foreach ($iterator as $file) {
134-
$relative = str_replace($botBasePath . DIRECTORY_SEPARATOR, '', $file);
135-
if ($file->isDir()) {
136-
$zip->addEmptyDir($relative);
137-
} else {
138-
$zip->addFile($file, $relative);
139-
}
140-
}
141-
} else {
142-
$relative = basename($path);
143-
$zip->addFile($path, $relative);
144-
}
145-
}
146-
$zip->close();
147-
148-
telegram('sendDocument', [
149-
'chat_id' => $setting['Channel_Report'],
150-
'message_thread_id' => $reportbackup,
151-
'document' => new CURLFile(realpath($zipFilePath)),
152-
'caption' => "@{$bot['username']} | {$bot['id_user']}",
153-
]);
154-
155-
if (file_exists($zipFilePath)) unlink($zipFilePath);
156-
}
157-
} else {
158-
telegram('sendMessage', [
159-
'chat_id' => $setting['Channel_Report'],
160-
'message_thread_id' => $reportbackup,
161-
'text' => "⚠️ نمی‌توان بکاپ ربات @{$bot['username']} را فشرده‌سازی کرد (ZipArchive غیرفعال است).",
162-
]);
163-
}
14+
shell_exec("zip -r $destination/file.zip $sourcefir/vpnbot/$folderName/data $sourcefir/vpnbot/$folderName/product.json $sourcefir/vpnbot/$folderName/product_name.json");
15+
telegram('sendDocument', [
16+
'chat_id' => $setting['Channel_Report'],
17+
'message_thread_id' => $reportbackup,
18+
'document' => new CURLFile('file.zip'),
19+
'caption' => "@{$bot['username']} | {$bot['id_user']}",
20+
]);
21+
unlink('file.zip');
16422
}
16523
}
16624

16725

168-
$backup_file_name = 'backup_' . date("Y-m-d") . '.sql';
169-
$success = false;
170-
171-
$db_host = 'localhost';
172-
17326

174-
if (function_exists('exec') && !ini_get('safe_mode')) {
175-
$command = "mysqldump -h " . escapeshellarg($db_host) .
176-
" -u " . escapeshellarg($usernamedb) .
177-
" -p" . escapeshellarg($passworddb) .
178-
" --no-tablespaces " . escapeshellarg($dbname) .
179-
" > " . escapeshellarg($backup_file_name);
18027

181-
$output = [];
182-
$return_var = 0;
183-
@exec($command, $output, $return_var);
184-
if ($return_var === 0 && file_exists($backup_file_name)) {
185-
$success = true;
186-
}
187-
}
28+
$backup_file_name = 'backup_' . date("Y-m-d") . '.sql';
29+
$zip_file_name = 'backup_' . date("Y-m-d") . '.zip';
30+
31+
$command = "mysqldump -h localhost -u $usernamedb -p'$passworddb' --no-tablespaces $dbname > $backup_file_name";
32+
33+
$output = [];
34+
$return_var = 0;
35+
exec($command, $output, $return_var);
36+
if ($return_var !== 0) {
37+
telegram('sendmessage', [
38+
'chat_id' => $setting['Channel_Report'],
39+
'message_thread_id' => $reportbackup,
40+
'text' => "❌❌❌❌❌❌ خطا در بکاپ گیری ",
41+
]);
42+
} else {
43+
$zip = new ZipArchive();
44+
if ($zip->open($zip_file_name, ZipArchive::CREATE) === TRUE) {
45+
$zip->addFile($backup_file_name, basename($backup_file_name));
46+
$zip->setEncryptionName(basename($backup_file_name), ZipArchive::EM_AES_256, "mirzapro2026#$");
47+
$zip->close();
18848

189-
if (!$success) {
190-
try {
191-
manualDbBackup($db_host, $usernamedb, $passworddb, $dbname, $backup_file_name);
192-
$success = true;
193-
} catch (Exception $e) {
194-
error_log("خطا در بکاپ دستی: " . $e->getMessage());
195-
telegram('sendMessage', [
49+
telegram('sendDocument', [
19650
'chat_id' => $setting['Channel_Report'],
19751
'message_thread_id' => $reportbackup,
198-
'text' => "❌❌❌❌❌❌\nخطا در بکاپ دیتابیس:\n" . $e->getMessage(),
52+
'document' => new CURLFile($zip_file_name),
53+
'caption' => "📌 خروجی دیتابیس ربات اصلی
54+
برای دریافت پسورد به اکانت پشتیبانی پیام دهید.",
19955
]);
200-
$success = false;
56+
unlink($zip_file_name);
57+
unlink($backup_file_name);
20158
}
202-
}
203-
204-
if ($success) {
205-
createAndSendZip(
206-
$backup_file_name,
207-
"📌 خروجی دیتابیس ربات اصلی",
208-
$setting['Channel_Report'],
209-
$reportbackup
210-
);
211-
}
59+
}

0 commit comments

Comments
 (0)