Skip to content

Commit 7fefa20

Browse files
committed
FileManager bugfixes + file permission module
1 parent ffec2e7 commit 7fefa20

File tree

6 files changed

+339
-464
lines changed

6 files changed

+339
-464
lines changed

web/css/file_manager.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ ul.listing { list-style-type: none; padding: 18px 0 0; margin: -4px 0 0 -1px; b
309309
.confirm-box { background-color: #333; width: 480px; font-family: arial; margin-left: 50px; border-radius: 3px; box-shadow: 0 2px 11px 0 rgba(0, 0, 0, 0.5); }
310310
/*.confirm-box.replace { height: 230px; }*/
311311
.confirm-box .message { color: #EBE697; font-size: 16px; padding: 25px; margin-bottom: 60px; display: inline-block; }
312+
.confirm-box .results,
312313
.confirm-box .warning { color: #FF9500; font-size: 16px; padding: 25px; }
313314
.confirm-box .warning .title,
314315
.confirm-box .message .title { color: #48B1B7; }
@@ -346,6 +347,13 @@ ul.listing { list-style-type: none; padding: 18px 0 0; margin: -4px 0 0 -1px; b
346347
.confirm-box.rename.warning .controls.replace { display: inline-block; }
347348
.confirm-box.rename.warning .message { padding-bottom: 0; }
348349

350+
.confirm-box.chmod .message { margin-bottom: 0; }
351+
.confirm-box.chmod .warning { padding: 10px 25px; }
352+
.confirm-box.chmod ul { padding: 10px 25px; }
353+
.confirm-box.chmod ul:last-of-type { margin-bottom: 38px; }
354+
.confirm-box.chmod li { list-style-type: none; }
355+
356+
349357
/*.confirm-box.archive { height: 468px; }*/
350358
.confirm-box.archive .message { margin-bottom: 38px; }
351359
.confirm-box.archive.warning .controls,

web/edit/file/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<input type="submit" name="save" value="Save" class="save" />
7575

7676

77-
<textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?php echo $content ?></textarea>
77+
<textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?=htmlentities($content)?></textarea>
7878

7979
</form>
8080

web/file_manager/files.php

Lines changed: 1 addition & 359 deletions
Original file line numberDiff line numberDiff line change
@@ -1,359 +1 @@
1-
<?php
2-
3-
//define(MAX_FILES_TO_SORT, 5);
4-
//define(LISTING_TIMEOUT, 0.000001);
5-
define(LISTING_TIMEOUT, 5);
6-
7-
8-
9-
10-
//echo 'files: ';
11-
//$files = scandir(__DIR__);
12-
13-
14-
//echo '<pre>';
15-
//print_r($files);
16-
17-
18-
//$_REQUEST['sort_field'] = 'size';
19-
$_REQUEST['sort_field'] = 'name';
20-
//$_REQUEST['sort_field'] = 'atime';
21-
//$_REQUEST['sort_field'] = 'mtime';
22-
$_REQUEST['sort_desc'] = 1;
23-
24-
25-
26-
/*
27-
+- copy file / dir [ recursive ]
28-
+- rename(move) file / dir
29-
+- delete file / dir [ recursive ]
30-
+- chmod file / dir
31-
+- chown file / dir
32-
+- create file
33-
+- create dir
34-
*/
35-
36-
switch($_REQUEST['action']){
37-
case 'copy': fm_copy($_REQUEST['source'], $_REQUEST['dest']); break;
38-
case 'rename': fm_rename($_REQUEST['source'], $_REQUEST['dest']); break;
39-
case 'delete': fm_delete($_REQUEST['source']); break;
40-
case 'chmod': fm_chmod($_REQUEST['source'], $_REQUEST['mode']); break;
41-
case 'chown': fm_chown($_REQUEST['source'], $_REQUEST['uid'], $_REQUEST['gid']); break;
42-
case 'create_file': fm_create_file($_REQUEST['source'], $_REQUEST['mode'] || FALSE); break;
43-
case 'create_dir': fm_create_dir($_REQUEST['source'], $_REQUEST['mode'] || FALSE); break;
44-
45-
default:
46-
$pwd = $_REQUEST['path'] ? $_REQUEST['path'] : __DIR__;
47-
$listing = dir_list($pwd, $_REQUEST['sort_field']);
48-
$writable = is_writable($pwd);
49-
50-
$pwd = array_merge(array('/'), explode('/', trim($pwd, '/')));
51-
52-
include('templates/filemanager.php');
53-
break;
54-
}
55-
56-
57-
58-
59-
60-
61-
//echo $_GET['sort_field'];
62-
63-
// if(in_array($_GET['sort_field'], $available_sort_fields)){
64-
// echo '1';
65-
// }
66-
67-
68-
69-
70-
71-
72-
73-
74-
/*
75-
upload_file
76-
77-
+ list_dir
78-
+- copy file / dir [ recursive ]
79-
+- rename(move) file / dir
80-
+- delete file / dir [ recursive ]
81-
+- chmod file / dir
82-
+- chown file / dir
83-
+- create file
84-
+- create dir
85-
86-
view file / image
87-
download file / image
88-
*/
89-
90-
91-
92-
function fm_create_file($filename){
93-
if(is_file($filename))
94-
return array('error' => 'file exists', 'code' => 1);
95-
96-
return !!fopen($filename, 'w');
97-
}
98-
99-
100-
function fm_create_dir($dirname){
101-
if(is_dir($filename))
102-
return array('error' => 'directory exists', 'code' => 1);
103-
104-
// TODO set parent directory mode
105-
return mkdir($dirname);
106-
}
107-
108-
109-
function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE){
110-
if(is_dir($filename) && $recursive){
111-
$dir_handle = opendir($dir);
112-
while ($item = readdir($dir_handle)){
113-
if (!in_array($item, array('.','..'))){
114-
$new_item = $filename.'/'.$item;
115-
116-
if($uid !== FALSE) chown($new_item, (int)$uid);
117-
if($gid !== FALSE) chgrp($new_item, (int)$gid);
118-
119-
if(is_dir($new_item)){
120-
fm_chown($new_item, $recursive, $uid, $gid);
121-
}
122-
}
123-
}
124-
}else{
125-
if($uid !== FALSE) chown($filename, (int)$uid);
126-
if($gid !== FALSE) chgrp($filename, (int)$gid);
127-
}
128-
}
129-
130-
131-
function fm_chmod($filename, $recursive = 0, $mode){
132-
if(is_dir($filename) && $recursive){
133-
$dir_handle = opendir($dir);
134-
while ($item = readdir($dir_handle)){
135-
if (!in_array($item, array('.','..'))){
136-
$new_item = $filename.'/'.$item;
137-
chmod($new_item, octdec($mode));
138-
139-
if(is_dir($new_item)){
140-
fm_chmod($new_item, $recursive, $mode);
141-
}
142-
}
143-
}
144-
}else{
145-
chmod($filename, octdec($mode));
146-
}
147-
}
148-
149-
150-
function fm_delete($filename){
151-
if(is_dir($filename)){
152-
foreach (
153-
$iterator = new RecursiveIteratorIterator(
154-
new RecursiveDirectoryIterator($filename, RecursiveDirectoryIterator::SKIP_DOTS),
155-
RecursiveIteratorIterator::SELF_FIRST) as $item
156-
) {
157-
if ($item->isDir()) {
158-
rmdir($item);
159-
// mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), decoct(fileperms($item->getPerms())));
160-
} else {
161-
unlink($item);
162-
// copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
163-
}
164-
}
165-
}else{
166-
return unlink($filename);
167-
}
168-
}
169-
170-
171-
function fm_rename($source, $dest){
172-
return rename($source, $dest);
173-
}
174-
175-
176-
function fm_copy($source, $dest){
177-
if(is_dir($source)){
178-
foreach (
179-
$iterator = new RecursiveIteratorIterator(
180-
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
181-
RecursiveIteratorIterator::SELF_FIRST) as $item
182-
) {
183-
if ($item->isDir()) {
184-
// TODO set dir perms
185-
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), decoct(fileperms($item->getPerms())));
186-
} else {
187-
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
188-
}
189-
}
190-
191-
}else{
192-
return copy($source, $dest);
193-
}
194-
}
195-
196-
197-
function list_dir(){
198-
$dir_iterator = new RecursiveDirectoryIterator("/path");
199-
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
200-
// could use CHILD_FIRST if you so wish
201-
202-
foreach ($iterator as $file) {
203-
echo $file, "\n";
204-
}
205-
206-
$size = 0;
207-
foreach ($iterator as $file) {
208-
if ($file->isFile()) {
209-
echo substr($file->getPathname(), 27) . ": " . $file->getSize() . " B; modified " . date("Y-m-d", $file->getMTime()) . "\n";
210-
$size += $file->getSize();
211-
}
212-
}
213-
214-
echo "\nTotal file size: ", $size, " bytes\n";
215-
}
216-
217-
218-
219-
220-
/// fast removing directory
221-
function rmrf($dir) {
222-
223-
foreach (glob($dir) as $file) {
224-
if (is_dir($file)) {
225-
rmrf("$file/*");
226-
rmdir($file);
227-
} else {
228-
unlink($file);
229-
}
230-
}
231-
}
232-
233-
234-
235-
236-
function dir_list($dir, $sort = 0)
237-
{
238-
$sort_order_for_filename = SORT_ASC;
239-
//$available_sort_fields = array('size, type', 'mtime', 'atime', 'owner', 'group');
240-
$available_sort_fields = array('name', 'size', 'type', 'mtime', 'atime', 'owner', 'group');
241-
$sort_order = SORT_ASC;
242-
243-
if ($dir[strlen($dir)-1] != '/') $dir .= '/';
244-
if (!is_dir($dir)) return array();
245-
246-
$start = microtime(TRUE);
247-
248-
$listing = array('dirs' => array(), 'files' => array(), 'dir_names' => array(), 'file_names' => array() ,'count' => 0, 'timeout_exeeded' => 0, 'time' => 0);
249-
$dir_handle = opendir($dir);
250-
$dir_objects = array();
251-
while ($object = readdir($dir_handle)){
252-
if (!in_array($object, array('.','..'))){
253-
$filename = $dir . $object;
254-
$time = microtime(true) - $start;
255-
if($time <= LISTING_TIMEOUT){
256-
$stats = stat($filename);
257-
$mode = explain_mode($stats['mode']);
258-
$perms = decoct(fileperms($filename));
259-
$item = array(
260-
'name' => $object,
261-
'size' => $stats['size'],
262-
'mode' => array('owner' => $mode['owner'], 'group' => $mode['owner'], 'other' => $mode['owner']),
263-
'perms' => decoct($stats['mode']),
264-
'type' => $mode['type'],
265-
'mtime' => $stats['mtime'],
266-
'atime' => $stats['atime'],
267-
'mdate_human' => date("Y F d", $stats['mtime']),
268-
'mtime_human' => date("H:i:s", $stats['mtime']),
269-
'adate_human' => date("Y F d", $stats['atime']),
270-
'atime_human' => date("H:i:s", $stats['atime']),
271-
'nlink' => $stats['nlink'],
272-
'owner' => posix_getpwuid($stats['uid'])['name'],
273-
'group' => posix_getgrgid($stats['gid'])['name']
274-
);
275-
}else{
276-
$listing['timeout_exeeded'] = TRUE;
277-
if(is_dir($filename)){ $type = 'd';
278-
}else{ $type = '-'; }
279-
280-
$item = array(
281-
'name' => $object,
282-
'size' => FALSE,
283-
'mode' => array('owner' => FALSE, 'group' => FALSE, 'other' => FALSE),
284-
'type' => $type,
285-
'mtime' => FALSE,
286-
'atime' => FALSE,
287-
'mdate_human' => FALSE,
288-
'mtime_human' => FALSE,
289-
'adate_human' => FALSE,
290-
'atime_human' => FALSE,
291-
'nlink' => FALSE,
292-
'owner' => FALSE,
293-
'group' => FALSE
294-
);
295-
}
296-
297-
298-
$listing['count']++;
299-
300-
if($item['type'] == 'd'){
301-
$listing['dirs'][] = $item;
302-
$listing['dir_names'][] = $item['name'];
303-
}else{
304-
if($sort && !$listing['timeout_exeeded']){
305-
$listing[$sort][] = $item[$sort];
306-
}
307-
$listing['files'][] = $item;
308-
$listing['file_names'][] = $item['name'];
309-
}
310-
}
311-
}
312-
$listing['time'] = microtime(TRUE) - $start;
313-
314-
315-
if(!$listing['timeout_exeeded']){
316-
if(in_array($_REQUEST['sort_field'], $available_sort_fields)){
317-
if($_REQUEST['sort_desc']){
318-
$sort_order = SORT_DESC;
319-
}
320-
array_multisort($listing[$_REQUEST['sort_field']], $sort_order, $listing['file_names'], $sort_order_for_filename, $listing['files']);
321-
}
322-
array_multisort($listing['dir_names'], $sort_order_for_filename, $listing['dirs']);
323-
}
324-
325-
return $listing;
326-
}
327-
328-
329-
function explain_mode($mode)
330-
{
331-
$info = array();
332-
333-
if (($mode & 0xC000) == 0xC000) { $info['type'] = 's'; }
334-
elseif (($mode & 0xA000) == 0xA000) { $info['type'] = 'l'; }
335-
elseif (($mode & 0x8000) == 0x8000) { $info['type'] = '-'; }
336-
elseif (($mode & 0x6000) == 0x6000) { $info['type'] = 'b'; }
337-
elseif (($mode & 0x4000) == 0x4000) { $info['type'] = 'd'; }
338-
elseif (($mode & 0x2000) == 0x2000) { $info['type'] = 'c'; }
339-
elseif (($mode & 0x1000) == 0x1000) { $info['type'] = 'p'; }
340-
else { $info['type'] = 'u'; }
341-
342-
$info['owner'] = (($mode & 0x0100) ? 'r' : '-');
343-
$info['owner'] .= (($mode & 0x0080) ? 'w' : '-');
344-
$info['owner'] .= (($mode & 0x0040) ? (($mode & 0x0800) ? 's' : 'x' ) : (($mode & 0x0800) ? 'S' : '-'));
345-
346-
// group
347-
$info['group'] = (($mode & 0x0020) ? 'r' : '-');
348-
$info['group'] .= (($mode & 0x0010) ? 'w' : '-');
349-
$info['group'] .= (($mode & 0x0008) ? (($mode & 0x0400) ? 's' : 'x' ) : (($mode & 0x0400) ? 'S' : '-'));
350-
351-
// other
352-
$info['other'] = (($mode & 0x0004) ? 'r' : '-');
353-
$info['other'] .= (($mode & 0x0002) ? 'w' : '-');
354-
$info['other'] .= (($mode & 0x0001) ? (($mode & 0x0200) ? 't' : 'x' ) : (($mode & 0x0200) ? 'T' : '-'));
355-
356-
return $info;
357-
}
358-
359-
?>
1+
// absolete

0 commit comments

Comments
 (0)