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
|
<?php
// $Header$
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
// Initialization
namespace Bitweaver;
require_once '../../kernel/includes/setup_inc.php';
require_once KERNEL_PKG_INCLUDE_PATH.'backups_lib.php';
// Check for admin permission
$gBitSystem->verifyPermission( 'p_admin' );
global $gBitDbType;
$backupPath = STORAGE_PKG_PATH."backups/$bitdomain";
KernelTools::mkdir_p( $backupPath );
if (isset($_REQUEST["generate"])) {
$filename = md5($gBitSystem->genPass()). '.sql';
$backuplib->backup_database( $backupPath.$filename );
}
$gBitSmarty->assign('restore', 'n');
if (isset($_REQUEST["restore"])) {
$gBitSmarty->assign('restore', 'y');
$gBitSmarty->assign('restorefile', basename($_REQUEST["restore"]));
}
if (isset($_REQUEST["rrestore"])) {
$backuplib->restore_database( $backupPath.basename($_REQUEST["rrestore"]));
}
if (isset($_REQUEST["remove"])) {
$filename = $backupPath.basename($_REQUEST["remove"]);
unlink ($filename);
}
if (isset($_REQUEST["upload"])) {
if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
$fp = fopen($_FILES['userfile1']['tmp_name'], "r");
$fw = fopen( $backupPath.$_FILES['userfile1']['name'], "w");
while (!feof($fp)) {
$data = fread($fp, 4096);
fwrite($fw, $data);
}
fclose ($fp);
fclose ($fw);
unlink ($_FILES['userfile1']['tmp_name']);
} else {
$gBitSmarty->assign('msg', KernelTools::tra("Upload failed"));
$gBitSystem->display( 'error.tpl' , null, [ 'display_mode' => 'admin' ] );
die;
}
}
// Get all the files listed in the backups directory
// And put them in an array with the filemtime of
// each file activated
$backups = [];
$h = opendir( $backupPath.$bitdomain );
while ($file = readdir($h)) {
if (strstr($file, "sql")) {
$row["filename"] = $file;
$row["created"] = filemtime( $backupPath.$file );
$row["size"] = filesize( $backupPath.$file ) / 1000000;
$backups[] = $row;
}
}
closedir ($h);
$gBitSmarty->assign('backups', $backups);
$gBitSmarty->assign('bitdomain', $bitdomain);
$gBitSystem->display( 'bitpackage:kernel/backup.tpl', KernelTools::tra( 'Backups') , [ 'display_mode' => 'admin' ]);
|