Ejemplo n.º 1
0
function listing ($list) {
	global $directory, $homedir, $sort, $reverse, $win, $cols, $date_format, $self;
	echo '<tr class="listing">
	<th style="text-align: center; vertical-align: middle"></th>
';
	$d = 'tool=Files&dir=' . urlencode($directory) . '&amp;';
	if (!$reverse && $sort == 'filename') $r = '&amp;reverse=true'; else $r = '';
	echo "\t<th class=\"filename\"><a href=\"$self?{$d}sort=filename$r\">" . word('filename') . "</a></th>\n";
	if (!$reverse && $sort == 'size') $r = '&amp;reverse=true'; else $r = '';
	echo "\t<th class=\"size\"><a href=\"$self?{$d}sort=size$r\">" . word('size') . "</a></th>\n";
	if (!$win) {
		if (!$reverse && $sort == 'permission') $r = '&amp;reverse=true'; else $r = '';
		echo "\t<th class=\"permission_header\"><a href=\"$self?{$d}sort=permission$r\">" . word('permission') . "</a></th>\n";
		if (!$reverse && $sort == 'owner') $r = '&amp;reverse=true'; else $r = '';
		echo "\t<th class=\"owner\"><a href=\"$self?{$d}sort=owner$r\">" . word('owner') . "</a></th>\n";
		if (!$reverse && $sort == 'group') $r = '&amp;reverse=true'; else $r = '';
		echo "\t<th class=\"group\"><a href=\"$self?{$d}sort=group$r\">" . word('group') . "</a></th>\n";
	}
	echo '	<th class="functions">' . word('functions') . '</th>
</tr>
';
	for ($i = 0; $i < sizeof($list); $i++) {
		$file = $list[$i];
		$timestamps  = 'mtime: ' . date($date_format, $file['mtime']) . ', ';
		$timestamps .= 'atime: ' . date($date_format, $file['atime']) . ', ';
		$timestamps .= 'ctime: ' . date($date_format, $file['ctime']);
		echo '<tr class="listing">
	<td class="checkbox"><input type="checkbox" name="checked' . $i . '" value="true" onfocus="activate(\'other\')" /></td>
	<td class="filename" title="' . html($timestamps) . '">';
		if ($file['is_link']) {
	
			echo html($file['filename']) . ' &rarr; ';
			$real_file = relative2absolute($file['target'], $directory);
			if (@is_readable($real_file)) {
				if (@is_dir($real_file)) {
					echo '[ <a href="' . $self . '?tool=Files&dir=' . urlencode($real_file) . '">' . html($file['target']) . '</a> ]';
				} else {
					echo '<a href="' . $self . '?tool=Files&action=view&amp;file=' . urlencode($real_file) . '">' . html($file['target']) . '</a>';
				}
			} else {
				echo html($file['target']);
			}
		} elseif ($file['is_dir']) {
			echo ' [ ';
			if ($win || $file['is_executable']) {
				echo '<a href="' . $self . '?tool=Files&dir=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
			} else {
				echo html($file['filename']);
			}
			echo ' ]';
		} else {
			if (substr($file['filename'], 0, 1) == '.') {
				echo '';
			} else {
				echo '';
			}
			if ($file['is_file'] && $file['is_readable']) {
			   echo '<a href="' . $self . '?tool=Files&action=view&amp;file=' . urlencode($file['path']) . '">' . html($file['filename']) . '</a>';
			} else {
				echo html($file['filename']);
			}
		}
		if ($file['size'] >= 1000) {
			$human = ' title="' . human_filesize($file['size']) . '"';
		} else {
			$human = '';
		}
		echo "\t<td class=\"size\"$human>{$file['size']} B</td>\n";
		if (!$win) {
			echo "\t<td class=\"permission\" title=\"" . decoct($file['permission']) . '">';
			$l = !$file['is_link'] && (!function_exists('posix_getuid') || $file['owner'] == posix_getuid());
			if ($l) echo '<a href="' . $self . '?tool=Files&action=permission&amp;file=' . urlencode($file['path']) . '&amp;dir=' . urlencode($directory) . '">';
			echo html(permission_octal2string($file['permission']));
			if ($l) echo '</a>';
			echo "</td>\n";
			if (array_key_exists('owner_name', $file)) {
				echo "\t<td class=\"owner\" title=\"uid: {$file['owner']}\">{$file['owner_name']}</td>\n";
			} else {
				echo "\t<td class=\"owner\">{$file['owner']}</td>\n";
			}
			if (array_key_exists('group_name', $file)) {
				echo "\t<td class=\"group\" title=\"gid: {$file['group']}\">{$file['group_name']}</td>\n";
			} else {
				echo "\t<td class=\"group\">{$file['group']}</td>\n";
			}
		}
		echo '	<td class="functions">
		<input type="hidden" name="file' . $i . '" value="' . html($file['path']) . '" />
';
		$actions = array();
		if (function_exists('symlink')) {
			$actions[] = 'create_symlink';
		}
		if (@is_writable(dirname($file['path']))) {
			$actions[] = 'delete';
			$actions[] = 'rename';
			$actions[] = 'move';
		}
		if ($file['is_file'] && $file['is_readable']) {
			$actions[] = 'copy';
			$actions[] = 'download';
			if ($file['is_writable']) $actions[] = 'edit';
		}
		if (!$win && function_exists('exec') && $file['is_file'] && $file['is_executable'] && file_exists('/bin/sh')) {
			$actions[] = 'execute';
		}
		if (sizeof($actions) > 0) {
			echo '		<select class="small" name="action' . $i . '" size="1">
		<option value="">' . str_repeat('&nbsp;', 30) . '</option>
';
			foreach ($actions as $action) {
				echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
			}
			echo '		</select>
		<input class="small" type="submit" name="submit' . $i . '" value=" &gt; " onfocus="activate(\'other\')" />
';
		}
		echo '	</td>
</tr>
';
	}
	echo '<tr class="listing_footer">
	<td style="text-align: right; vertical-align: top"></td>
	<td colspan="' . ($cols - 1) . '">
		<input type="hidden" name="num" value="' . sizeof($list) . '" />
		<input type="hidden" name="focus" value="" />
		<input type="hidden" name="olddir" value="' . html($directory) . '" />
';
	$actions = array();
	if (@is_writable(dirname($file['path']))) {
		$actions[] = 'delete';
		$actions[] = 'move';
	}
	$actions[] = 'copy';
	echo '		<select class="small" name="action_all" size="1">
		<option value="">' . str_repeat('&nbsp;', 30) . '</option>
';
	foreach ($actions as $action) {
		echo "\t\t<option value=\"$action\">" . word($action) . "</option>\n";
	}
	echo '		</select>
		<input class="small" type="submit" name="submit_all" value=" &gt; " onfocus="activate(\'other\')" />
	</td>
</tr>
';
}
Ejemplo n.º 2
0
/**
 * @return array
 * @param string  $file
 * @param boolean $debug
 */
function permission_stat($file, $debug = false)
{
    global $lang_fn;
    $opt = array();
    clearstatcache();
    $filestat = stat($file);
    if ($filestat == false) {
        return false;
    }
    clearstatcache();
    if ($debug) {
        $mode = fileperms($file);
    } else {
        $mode = @fileperms($file);
    }
    $opt['permsdec'] = substr(sprintf('%o', $mode), -4);
    $opt['permsstr'] = permission_octal2string($mode);
    // functions not available on WAMP systems
    if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
        if ($debug) {
            $userinfo = posix_getpwuid($filestat[4]);
            $groupinfo = posix_getgrgid($filestat[5]);
        } else {
            $userinfo = @posix_getpwuid($filestat[4]);
            $groupinfo = @posix_getgrgid($filestat[5]);
        }
        $opt['username'] = isset($userinfo['name']) ? $userinfo['name'] : $lang_fn('unknown');
        $opt['usergroup'] = isset($groupinfo['name']) ? $groupinfo['name'] : $lang_fn('unknown');
    } else {
        $opt['username'] = $lang_fn('unknown');
        $opt['usergroup'] = $lang_fn('unknown');
    }
    return $opt;
}