-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeleteFolder.php
63 lines (59 loc) · 1.9 KB
/
deleteFolder.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
<?php
session_start();
$file = str_replace("/","\\",str_replace(array("///aphe///","///quot///","///equa///","///ques///","///amps///","///fstp///"),array("'",'"',"=","?","&","."),$_GET['path']));
$f1 = fopen("groups.json", "r") or die("No groups file");
$json = fread($f1,filesize("groups.json"));
fclose($f1);
$groupSettings = json_decode($json,true)[$_SESSION["group"]];
$allPermissions = $groupSettings['permissions'];
$permissions = [];
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
self::deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
$breadcrumbs = explode("\\", $file);
$i = 1;
$temp1 = "";
foreach ($breadcrumbs as &$value) {
$temp1 = $temp1.$value."/";
if (array_key_exists($temp1, $allPermissions)) {
$permissions = $allPermissions[$temp1];
}
$i = $i + 1;
}
//echo json_encode($permissions);
if (in_array("DELETEFOLDER",$permissions)){
//echo $file;
$logfile = fopen($_SESSION["logfile"], "a");
fwrite($logfile, " DELETE FOLDER at ".date('H:i:s')." on ".date('d F Y')."\r\n");
fwrite($logfile, " Folder : ".$file."\r\n");
fclose($logfile);
if (file_exists($file)) {
deleteDir($file);
if (isset($_SERVER["HTTP_REFERER"])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
exit;
}
} else {
$logfile = fopen($_SESSION["logfile"], "a");
fwrite($logfile, " DENIED DELETE FOLDER at ".date('H:i:s')." on ".date('d F Y')."\r\n");
fwrite($logfile, " Folder : ".$file."\r\n");
fclose($logfile);
header('Location: insufficientPermissions.php');
exit;
}
?>