-
Notifications
You must be signed in to change notification settings - Fork 0
/
synchronize.php
74 lines (60 loc) · 3.1 KB
/
synchronize.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
include_once 'data.php';
include_once 'functions.php';
set_time_limit(0);
if (isset($_SESSION['auth']) && $_SESSION['permissions'] == 'A') {
$directory = '';
if (isset($_GET['directory']))
$directory = $_GET['directory'];
if (substr($directory, -1) == DIRECTORY_SEPARATOR)
$directory = substr($directory, 0, -1);
if (!empty($directory)) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') $directory = str_replace("/", "\\", $directory);
if (filemtime($database_path.'library.sq3') >
filemtime($directory.DIRECTORY_SEPARATOR.'library'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'library.sq3'))
die('Error! This backup is older then your library. Use Restore function instead.');
if (!is_dir($directory)) {
$is_dir = false;
} else {
$is_dir = true;
}
if ($is_dir && is_writable(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library')) {
if (!is_readable($directory . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'library.sq3'))
die('Error! Access denied or directory does not exist.');
database_connect($usersdatabase_path, 'users');
save_setting($dbHandle, 'backup_dir', $directory);
$dbHandle = null;
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
exec("xcopy \"" . $directory . DIRECTORY_SEPARATOR . 'library' . "\" \"" . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . "\" /c /v /q /s /e /h /y /d");
} else {
exec(escapeshellcmd("cp -pru \"" . $directory . DIRECTORY_SEPARATOR . 'library' . "\" \"" . dirname(__FILE__) . DIRECTORY_SEPARATOR . "\""));
}
die('Done');
} else {
die('Error! Access denied or directory does not exist.');
}
}
database_connect($usersdatabase_path, 'users');
$backup_dir = get_setting($dbHandle, 'backup_dir');
$dbHandle = null;
?>
<table style="width: 100%"><tr><td class="details alternating_row"><b>Synchronize library with a backup copy</b></td></tr></table>
<div class="item-sticker ui-widget-content ui-corner-all" style="margin:auto;margin-top:100px;width:500px">
<div class="ui-widget-header ui-dialog-titlebar items ui-corner-top" style="border:0">
Enter the directory path, where the backup copy is stored:<br>
</div>
<div class="separator" style="margin:0"></div>
<div class="alternating_row items ui-corner-bottom">
<button class="open-dirs-button">Browse directories</button>
<form action="synchronize.php" method="GET">
<input type="text" size="50" style="width:435px" name="directory" value="<?php if (!empty($backup_dir)) print $backup_dir; ?>"><br>
<span class="ui-state-error-text">The backup must be newer then this library.</span><br>
<input type="submit" value="Proceed">
</form>
</div>
</div>
<?php
} else {
print "<p>Super User permissions required.</p>";
}
?>