-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
117 lines (113 loc) · 4.57 KB
/
action.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
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
<?php
# +--------------------------------------------------------------------+
# | phpEasyVCS |
# | The file-based version control system |
# +--------------------------------------------------------------------+
# | Copyright (c) 2011 Martin Vlcek |
# | License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html) |
# +--------------------------------------------------------------------+
if (isset($_REQUEST['start-delete']) || isset($_REQUEST['start-copy']) || isset($_REQUEST['start-move'])) {
include('browse.php');
exit(0);
}
require_once('inc/basic.php');
$msg = $err = '';
$dir = sanitizeDir($_REQUEST['dir']);
$vcs = new FileVCS(DATAPATH, $_REQUEST['tag'], getUserName(), isReadOnly());
$names = $_REQUEST['name'];
if ($names) {
foreach ($names as $i => $name) {
$names[$i] = sanitizeName($name);
}
if (isset($_REQUEST['delete'])) {
$num = 0;
foreach ($names as $name) {
if ($vcs->delete($dir, $name, @$_REQUEST['comment']) >= 0) $num++;
}
if ($num == count($names)) {
$msg = "$num files/directories have been successfully deleted.";
} else if ($num > 0) {
$failed = count($names) - $num;
$err = "$num files/directories have been successfully deleted, $failed files/directories could not be deleted.";
} else {
$err = "Error deleting files/directories.";
}
} else if (isset($_REQUEST['move'])) {
$targetdir = sanitizeDir(@$_REQUEST['targetdir']);
$overwrite = true && @$_REQUEST['overwrite'];
$num = 0;
foreach ($names as $name) {
if ($vcs->move($dir, $name, $targetdir, $name, $overwrite, @$_REQUEST['comment']) >= 0) $num++;
}
if ($num == count($names)) {
$msg = "$num files/directories have been successfully moved.";
} else if ($num > 0) {
$failed = count($names) - $num;
$err = "$num files/directories have been successfully moved, $failed files/directories could not be moved.";
} else {
$err = "Error moving files/directories.";
}
} else if (isset($_REQUEST['copy'])) {
$targetdir = sanitizeDir(@$_REQUEST['targetdir']);
$overwrite = true && @$_REQUEST['overwrite'];
$num = 0;
foreach ($names as $name) {
if ($vcs->copy($dir, $name, $targetdir, $name, $overwrite, @$_REQUEST['comment']) >= 0) $num++;
}
if ($num == count($names)) {
$msg = "$num files/directories have been successfully copied.";
} else if ($num > 0) {
$failed = count($names) - $num;
$err = "$num files/directories have been successfully copied, $failed files/directories could not be copied.";
} else {
$err = "Error copying files/directories.";
}
} else if (isset($_REQUEST['download'])) {
$tmpfile = tempnam(TMP_DIR,'vcs');
$zip = new ZipArchive();
if (!$zip || ($result = $zip->open($tmpfile, ZipArchive::CREATE)) !== true) {
$err = "Error downloading files/directories.";
} else {
$result = null;
foreach ($names as $name) {
$result = addFile($zip, $vcs->getEntry($dir, $name));
if ($result) break;
}
if ($result) {
$zip->close();
$err = "Error adding $result to zip. ";
} else if (!$zip->close()) {
$err = "Error creating ZIP.";
} else {
header('Content-type: application/zip');
header('Content-disposition: attachment; filename="download.zip"');
readfile($tmpfile);
unlink($tmpfile);
exit(0);
}
}
}
} else {
$msg = 'Please select at least one file or directory.';
}
$url = 'browse.php?dir='.urlencode($dir);
if (@$_REQUEST['tag']) $url .= '&tag='.urlencode($_REQUEST['tag']);
if (@$msg) $url .= '&msg='.urlencode($msg);
if (@$err) $url .= '&error='.urlencode($err);
header('Location: '.$url);
function addFile(&$zip, $entry) {
global $dir, $vcs;
$path = substr($entry->dir.$entry->name, strlen($dir));
if ($entry->isDirectory) {
if (!$zip->addEmptyDir($path.'/')) return $entry->dir.$entry->name;
$listing = $vcs->getListing($entry->dir.$entry->name);
foreach ($listing->directories as $directory) {
if ($result = addFile($zip, $directory)) return $result;
}
foreach ($listing->files as $file) {
if ($result = addFile($zip, $file)) return $result;
}
} else {
if (!$zip->addFile(DATAPATH.$entry->_content, $path)) return $entry->dir.$entry->name;
}
}