forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrightscheck.php
134 lines (116 loc) · 3.67 KB
/
rightscheck.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!doctype html>
<html>
<head>
<title>openDCIM rights check</title>
<style type="text/css">
.wanted { background-color: forestgreen; }
.warning { background-color: orange; }
table { background-color: azure; border-collapse: collapse; border: 1px solid black; display: inline-flex; }
td, th { padding: 0 8px; }
</style>
</head>
<body>
<?php
$userid=exec('id -u');
$grpid=exec('id -g');
// The directories we want writable for uploads
$wantedpaths=array('drawings', 'pictures','vendor'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'ttfontdata');
print "<table>
<tr>
<th>Directory</th>
<th>Writable</th>
<th colspan=2>Rights</th>
<th>Owner:Group</th>
</tr>";
function matches(&$check,$const){
if($check==$const){
$check="<font color=\"LimeGreen\">$check</font>";
}
}
function printrow($file,&$wantedpaths,$userid,$grpid){
$uploadDir=$file;
$not=(is_writable('.'.DIRECTORY_SEPARATOR.$uploadDir))?'<font color="LimeGreen">Yes</font>':'<font color="red">No</font>';
$perms = fileperms('.'.DIRECTORY_SEPARATOR.$uploadDir);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
$owner=fileowner($uploadDir);
$group=filegroup($uploadDir);
$perms=substr(sprintf('%o', $perms), -4);
matches($owner,$userid);
matches($group,$grpid);
$class=(in_array($uploadDir,$wantedpaths))?' class="wanted"':'';
$class=(preg_match('/LimeGreen/',$not) && !in_array($uploadDir,$wantedpaths))?' class="warning"':$class;
print "\n\t<tr$class>\n\t\t<td>$uploadDir</td><td>$not</td><td>$info</td><td>$perms</td><td>$owner:$group</td></tr>";
}
$directory=".";
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
foreach($scanned_directory as $i => $file){
if(!is_dir($file)){
continue;
}
printrow($file,$wantedpaths,$userid,$grpid);
}
# Add in extra paths here that aren't part of the root loop.
printrow('vendor'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'ttfontdata',$wantedpaths,$userid,$grpid);
# Handle paths that may or may not be set in the configuration screen for docker
# clowns.
if(file_exists("db.inc.php")){
require_once("db.inc.php");
foreach($config->ParameterArray as $option => $value){
if(preg_match('/path$/',$option)){
array_push($wantedpaths,$value);
printrow($value,$wantedpaths,$userid,$grpid);
}
}
}
print "\n</table>
<table>
<tr>
<th>Legend</th>
</tr>
<tr class=\"wanted\"><td>Directory that should be writable</td></tr>
<tr class=\"warning\"><td>Directory is writable and unexpected</td></tr>
<tr><td>Normal and expected rights</td></tr>
</table>
<p>Script is being executed as owner: $userid group: $grpid</p>";