-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.php
55 lines (47 loc) · 1.82 KB
/
backup.php
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
<?php
// Ambil data POST
$servermikrotik = $_POST['nama'];
$token = $_POST['token'];
$id_own = $_POST['idtele'];
$filenya = $_POST['namafile'];
$password = $_POST['passwordzip'];
// Cek apakah semua data diperlukan ada
if (!empty($servermikrotik) && !empty($token) && !empty($id_own) && !empty($filenya)) {
// Tentukan path file yang akan dikirim
$backupFile = $filenya . '.backup';
$rscFile = $filenya . '.rsc';
$zipFile = $filenya . '.zip';
// Buat file ZIP dengan password menggunakan command line
$command = "zip -P " . escapeshellarg($password) . " " . escapeshellarg($zipFile) . " " . escapeshellarg($backupFile) . " " . escapeshellarg($rscFile);
exec($command, $output, $result);
if ($result === 0) {
// Kirim file ZIP ke Telegram
$website = "https://api.telegram.org/bot" . $token;
$params = [
'chat_id' => $id_own,
'document' => new CURLFile($zipFile),
'caption' => 'Backup ZIP file: ' . $zipFile . "\nServer: " . $servermikrotik,
'parse_mode' => 'html',
];
$ch = curl_init($website . '/sendDocument');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
// Hapus file ZIP setelah dikirim
unlink($zipFile);
// Hapus semua file dengan ekstensi .backup
array_map('unlink', glob("*.backup"));
} else {
echo 'Failed to create zip file with password.';
}
} else {
echo "MITHA BACKUP v1.0<br><br>Upload file sukses <br><br>";
}
?>