-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeleteFile.php
43 lines (42 loc) · 1.39 KB
/
deleteFile.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
<?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 = [];
$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("DELETE",$permissions)){
$logfile = fopen($_SESSION["logfile"], "a");
fwrite($logfile, " DELETE at ".date('H:i:s')." on ".date('d F Y')."\r\n");
fwrite($logfile, " File : ".$file."\r\n");
fclose($logfile);
//echo $file;
if (file_exists($file)) {
unlink($file);
if (isset($_SERVER["HTTP_REFERER"])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
exit;
}
} else {
$logfile = fopen($_SESSION["logfile"], "a");
fwrite($logfile, " DENIED DELETE at ".date('H:i:s')." on ".date('d F Y')."\r\n");
fwrite($logfile, " File : ".$file."\r\n");
fclose($logfile);
header('Location: insufficientPermissions.php');
exit;
}
?>