| version 1.3, 2001/09/25 16:16:02 |
version 1.4, 2001/09/26 10:37:35 |
| Line 29 include("url_utils.lib.php"); |
|
| Line 29 include("url_utils.lib.php"); |
|
| */ |
*/ |
| function write_origvars_html($origvars) { |
function write_origvars_html($origvars) { |
| foreach (split("&", $origvars) as $param) { |
foreach (split("&", $origvars) as $param) { |
| if (strpos($param, '=') != false) { |
if (strpos($param, '=') != false) |
| echo "<input type=hidden name=".substr($param, 0, strpos($param, '=')); |
echo "<input type=hidden name=" |
| echo " value=".substr($param, strpos($param, '=')+1).">"; |
. substr($param, 0, strpos($param, '=')) |
| } |
. " value=" . substr($param, strpos($param, '=')+1).">"; |
| } |
} |
| } |
} |
| |
|
| Line 43 function write_origvars_html($origvars) |
|
| Line 43 function write_origvars_html($origvars) |
|
| |
|
| <?php |
<?php |
| |
|
| if (strlen($phpWebFileManager_ROOT_DIR) > 0 |
if (strlen($phpWebFileManager_ROOT_DIR) > 0 && |
| && $phpWebFileManager_ROOT_DIR[strlen($phpWebFileManager_ROOT_DIR)-1] != '/') $phpWebFileManager_ROOT_DIR .= '/'; |
$phpWebFileManager_ROOT_DIR[strlen($phpWebFileManager_ROOT_DIR)-1] != '/') |
| if (! isset($dir)) $dir = $phpWebFileManager_START_DIR; |
$phpWebFileManager_ROOT_DIR .= '/'; |
| |
|
| |
if (! isset($dir) || $phpWebFileManager_DENY_DIR_ENTER) |
| |
$dir = $phpWebFileManager_START_DIR; |
| |
|
| $dir = preg_replace('/\/\/+/','/', $dir . '/'); |
$dir = preg_replace('/\/\/+/','/', $dir . '/'); |
| $dir = preg_replace("/^(|.*\/)\.\.\/([^\.\/][^\.\/]|[^\/][^\.\/]|[^\/][^\.\/]|[^\/]{3,})\/(.*)$/", "\\1\\3", $dir); |
$dir = preg_replace("/^(|.*\/)\.\.\/([^\.\/][^\.\/]|[^\/][^\.\/]|[^\/][^\.\/]|[^\/]{3,})\/(.*)$/", "\\1\\3", $dir); |
| $dir = preg_replace("/^(|.*\/)([^\/\.][^\.\/]|[^\/][^\.\/]|[^\/][^\.\/]|[^\/]{3,})\/\.\.\/(.*)$/", "\\1\\3", $dir); |
$dir = preg_replace("/^(|.*\/)([^\/\.][^\.\/]|[^\/][^\.\/]|[^\/][^\.\/]|[^\/]{3,})\/\.\.\/(.*)$/", "\\1\\3", $dir); |
| |
|
| while (preg_match("/^(|.*\/)\.\.\/(.*)$/", $dir)) $dir = preg_replace("/^(|.*\/)\.\.\/(.*)$/", "\\1\\2", $dir); |
while (preg_match("/^(|.*\/)\.\.\/(.*)$/", $dir)) |
| while ($dir[0] == '/') $dir = substr($dir, 1, strlen($dir)); |
$dir = preg_replace("/^(|.*\/)\.\.\/(.*)$/", "\\1\\2", $dir); |
| |
while ($dir[0] == '/') |
| |
$dir = substr($dir, 1, strlen($dir)); |
| |
|
| |
/* Hidden parameters */ |
| $origvars = $phpWebFileManager_ORIGINAL_VARIABLES; |
$origvars = $phpWebFileManager_ORIGINAL_VARIABLES; |
| if ($origvars[strlen($origvars)-1] != '&') $origvars .= '&'; |
if ($origvars[strlen($origvars)-1] != '&') $origvars .= '&'; |
| |
|
| |
|
| /* Hidden parameters */ |
|
| write_origvars_html($origvars); |
write_origvars_html($origvars); |
| |
|
| echo "<input type=hidden value=\"$filename\" name=filename>"; |
echo "<input type=hidden value=\"$filename\" name=filename>"; |
| Line 68 echo "<input type=hidden value=\"$dir\" |
|
| Line 72 echo "<input type=hidden value=\"$dir\" |
|
| $orig_dir = getcwd(); |
$orig_dir = getcwd(); |
| |
|
| /* Change directory to upload root */ |
/* Change directory to upload root */ |
| if (is_dir($phpWebFileManager_ROOT_DIR)) chdir($phpWebFileManager_ROOT_DIR); |
if (is_dir($phpWebFileManager_ROOT_DIR)) |
| |
chdir($phpWebFileManager_ROOT_DIR); |
| $root_dir = getcwd(); |
$root_dir = getcwd(); |
| |
|
| if (is_dir($dir)) chdir($dir); |
if (is_dir($dir)) { |
| else $dir = ''; |
chdir($dir); |
| |
|
| |
/* |
| |
* On some systems chdir() is modifying $dir variable, |
| |
* so we must improve it. |
| |
*/ |
| |
if (strlen($dir) > 0 && |
| |
$dir[strlen($dir)-1] != '/') |
| |
$dir .= '/'; |
| |
} |
| |
else |
| |
$dir = ''; |
| |
|
| /* Write current working direcotry information */ |
/* Write current working direcotry information */ |
| echo "<big><b>$dir</b></big><br><br>"; |
echo "<big><b>$dir</b></big><br><br>"; |
| Line 84 if ($action == "confirm_delete_file") { |
|
| Line 100 if ($action == "confirm_delete_file") { |
|
| echo "<input type=hidden value=delete_file name=action>"; |
echo "<input type=hidden value=delete_file name=action>"; |
| |
|
| echo "Really delete file<br><br><i>$filename</i><br><br>from "; |
echo "Really delete file<br><br><i>$filename</i><br><br>from "; |
| echo $dir != '' ? "directory<br><br><i>$dir</i><br><br>" : "root directory?<br><br>"; |
echo $dir != '' ? "directory<br><br><i>$dir</i><br><br>" |
| |
: "root directory?<br><br>"; |
| echo "<input type=submit name=submit value=Delete> "; |
echo "<input type=submit name=submit value=Delete> "; |
| echo "<input type=submit name=submit value=Cancel> "; |
echo "<input type=submit name=submit value=Cancel> "; |
| } |
} |
|
|
| if ($action == "delete_file" && ! $phpWebFileManager_DENY_FILE_DELETE) { |
if ($action == "delete_file" && ! $phpWebFileManager_DENY_FILE_DELETE) { |
| if ($submit == "Delete") { |
if ($submit == "Delete") { |
| if (@unlink($filename) == false) |
if (@unlink($filename) == false) |
| echo "<small>File removing failed. Delete was not successful.</small>"; |
echo "<small>File removing failed." |
| |
. " Delete was not successful.</small>"; |
| else echo "<small>File was succesfully removed.</small>"; |
else echo "<small>File was succesfully removed.</small>"; |
| } |
} |
| else echo "<small>Operation canceled.</small>"; |
else echo "<small>Operation canceled.</small>"; |
|
|
| || ($action == "rename_file" && ! $phpWebFileManager_DENY_FILE_RENAME)) { |
|| ($action == "rename_file" && ! $phpWebFileManager_DENY_FILE_RENAME)) { |
| if ($submit == "Rename" and $new_filename != "") { |
if ($submit == "Rename" and $new_filename != "") { |
| if (@rename($filename, $new_filename) == false) |
if (@rename($filename, $new_filename) == false) |
| echo "<small>Filename changing failed. File was not renamed.</small>"; |
echo "<small>Filename changing failed." |
| |
. " File was not renamed.</small>"; |
| else echo "<small>File was succesfully renamed.</small>"; |
else echo "<small>File was succesfully renamed.</small>"; |
| } |
} |
| else echo "<small>Operation canceled.</small>"; |
else echo "<small>Operation canceled.</small>"; |
|
|
| || ($action == "create_file" && ! $phpWebFileManager_DENY_FILE_CREATE)) { |
|| ($action == "create_file" && ! $phpWebFileManager_DENY_FILE_CREATE)) { |
| if ($submit == "Create" and $new_filename != "") { |
if ($submit == "Create" and $new_filename != "") { |
| if ($action == "create_directory") { |
if ($action == "create_directory") { |
| if (@mkdir($new_filename, $phpWebFileManager_DIR_MODE) == false) |
if (@mkdir($new_filename, $phpWebFileManager_DIR_MODE) == false) |
| echo "<small>Directory creating failed. Already exists?</small>"; |
echo "<small>Directory creating failed." |
| |
. " Already exists?</small>"; |
| else echo "<small>Directory was succesfully created.</small>"; |
else echo "<small>Directory was succesfully created.</small>"; |
| } |
} |
| else { |
else { |
|
|
| echo "<small>Creation failed. File already exists.</small>"; |
echo "<small>Creation failed. File already exists.</small>"; |
| else { |
else { |
| if (($fh = @fopen($new_filename, "w")) == false) |
if (($fh = @fopen($new_filename, "w")) == false) |
| echo "<small>Creation failed. No space left on the device?</small>"; |
echo "<small>Creation failed." |
| |
. " No space left on the device?</small>"; |
| else { |
else { |
| fclose($fh); |
fclose($fh); |
| echo "<small>File was successfully created"; |
echo "<small>File was successfully created"; |
| |
|
| if ($phpWebFileManager_FILE_MODE != 0) { |
if ($phpWebFileManager_FILE_MODE != 0) { |
| if (chmod($new_filename, $phpWebFileManager_FILE_MODE) == false) |
if (@chmod($new_filename, |
| |
$phpWebFileManager_FILE_MODE) == false) |
| echo ", but chmod() failed"; |
echo ", but chmod() failed"; |
| else echo ", chmod() OK"; |
else echo ", chmod() OK"; |
| } |
} |
|
|
| $i = 2; |
$i = 2; |
| while (file_exists($tmp_target_filename)) { |
while (file_exists($tmp_target_filename)) { |
| if ($i == 2) |
if ($i == 2) |
| echo "<small>Filename already exists. Filename changed.</small><br>"; |
echo "<small>Filename already exists." |
| |
. " Filename changed.</small><br>"; |
| $tmp_target_filename = $target_filename . "-" . $i; |
$tmp_target_filename = $target_filename . "-" . $i; |
| $i++; |
$i++; |
| } |
} |
|
|
| echo "<small>File was successfully uploaded"; |
echo "<small>File was successfully uploaded"; |
| |
|
| if ($phpWebFileManager_FILE_MODE != 0) { |
if ($phpWebFileManager_FILE_MODE != 0) { |
| if (chmod($target_filename, $phpWebFileManager_FILE_MODE) == false) echo ", but chmod() failed"; |
if (@chmod($target_filename, |
| |
$phpWebFileManager_FILE_MODE) == false) |
| |
echo ", but chmod() failed"; |
| else echo ", chmod() OK"; |
else echo ", chmod() OK"; |
| } |
} |
| echo ".</small>"; |
echo ".</small>"; |
| } |
} |
| else echo "<small>Transmission error. File was not successfully uploaded.</small>"; |
else |
| |
echo "<small>Transmission error." |
| |
. " File was not successfully uploaded.</small>"; |
| } |
} |
| else echo "<small>Operation canceled.</small>"; |
else echo "<small>Operation canceled.</small>"; |
| |
|
|
|
| $line = 0; |
$line = 0; |
| |
|
| if (strlen(getcwd()) > strlen($root_dir)) { |
if (strlen(getcwd()) > strlen($root_dir)) { |
| echo "<tr valign=middle><td align=center>"; |
echo "<tr valign=middle>"; |
| echo "<a href=\"$PHPSELF?$origvars"."dir=$dir..\"><img alt=\"Back\" border=0 src=\"icons/back.gif\"></a>"; |
|
| echo "</td><td width=100% colspan=4><a href=\"$PHPSELF?$origvars"."dir=$dir..\">(parent directory)</a></td>"; |
echo "<td align=center>" |
| |
. "<a href=\"$PHPSELF?$origvars" . "dir=$dir..\">" |
| |
. "<img alt=\"Back\" border=0 src=\"icons/back.gif\"></a>" |
| |
. "</td>"; |
| |
|
| |
echo "<td width=100% colspan=4>" |
| |
. "<a href=\"$PHPSELF?$origvars" . "dir=$dir..\">" |
| |
. "(parent directory)</a>" |
| |
. "</td>"; |
| |
|
| echo "</tr>\n"; |
echo "</tr>\n"; |
| |
|
| $line++; |
$line++; |
| } |
} |
| |
|
| |
/* |
| |
* Column display counting. |
| |
*/ |
| |
|
| |
$rename_column = ! $phpWebFileManager_DENY_DIR_RENAME |
| |
|| ! $phpWebFileManager_DENY_FILE_RENAME; |
| |
$delete_column = ! $phpWebFileManager_DENY_DIR_REMOVE |
| |
|| ! $phpWebFileManager_DENY_FILE_DELETE; |
| |
$view_column = ! $phpWebFileManager_DENY_DIR_ENTER |
| |
|| ! $phpWebFileManager_DENY_FILE_VIEW; |
| |
$last_row = ! $phpWebFileManager_DENY_DIR_CREATE |
| |
|| ! $phpWebFileManager_DENY_FILE_CREATE |
| |
|| ! $phpWebFileManager_DENY_FILE_UPLOAD; |
| |
|
| /* Two steps for() cyclus. */ |
/* Two steps for() cyclus. */ |
| /* One for directories and one for files. */ |
/* One for directories and one for files. */ |
|
|
| |
|
| $d = dir("./"); |
$d = dir("./"); |
| |
|
| |
/* Order in alphabetical order. */ |
| /* Order in alphabetical order */ |
|
| $listing = array(); |
$listing = array(); |
| while ($entry=$d->read()) |
while ($entry = $d->read()) |
| array_push($listing, $entry); |
array_push($listing, $entry); |
| sort($listing); |
sort($listing); |
| |
|
| while ($entry = array_shift($listing)) { |
while ($entry = array_shift($listing)) { |
| if ($entry != "." && $entry != ".." && (($k == 0 && is_dir($entry))||($k == 1 && ! is_dir($entry)))) { |
if ($entry != "." && $entry != ".." && |
| echo "<tr valign=middle".($line++%2?" bgcolor=#a0c9c9":"").">"; // lightblue: add8e6 |
(($k == 0 && is_dir($entry))||($k == 1 && ! is_dir($entry)))) { |
| |
|
| |
// lightblue: add8e6 |
| |
echo "<tr valign=middle".($line++%2?" bgcolor=#a0c9c9":"").">"; |
| echo "<td align=center>"; |
echo "<td align=center>"; |
| |
|
| if (is_dir($entry)) { |
if (is_dir($entry)) { |
| echo "<a href=\"$PHPSELF?$origvars"."dir=$dir$entry\"><img alt=\"Directory\" border=0 src=\"icons/dir.gif\"></a>"; |
if (! $phpWebFileManager_DENY_DIR_ENTER) |
| |
echo "<a href=\"$PHPSELF?$origvars" |
| |
. "dir=$dir$entry\">"; |
| |
echo "<img alt=\"Directory\" border=0" |
| |
. " src=\"icons/dir.gif\">"; |
| |
if (! $phpWebFileManager_DENY_DIR_ENTER) |
| |
echo "</a>"; |
| |
|
| echo "</td><td width=100%>"; |
echo "</td><td width=100%>"; |
| echo "<a href=\"$PHPSELF?$origvars"."dir=$dir$entry\">"; |
|
| //echo str_replace("_"," ",$entry); |
if (! $phpWebFileManager_DENY_DIR_ENTER) |
| echo $entry; |
echo "<a href=\"$PHPSELF?$origvars" |
| echo "</a>"; |
. "dir=$dir$entry\">" |
| |
. $entry . "</a>"; |
| |
else |
| |
echo "$entry"; |
| } |
} |
| else echo " </td><td width=100%>$entry"; |
else echo " </td><td width=100%>$entry"; |
| |
|
|
|
| |
|
| if (! is_dir($entry)) { |
if (! is_dir($entry)) { |
| |
|
| echo "<td><small>"; |
if ($rename_column) { |
| echo "[<a href=\"$PHPSELF?$origvars"."dir=$dir&action=confirm_rename_file&filename=$entry\">Rename</a>]"; |
echo "<td><small>"; |
| echo "</small></td>"; |
if (! $phpWebFileManager_DENY_FILE_RENAME) |
| |
echo "[<a href=\"$PHPSELF?$origvars" |
| |
. "dir=$dir&action=confirm_rename_file" |
| |
. "&filename=$entry\">Rename</a>]"; |
| |
echo "</small></td>"; |
| |
} |
| |
|
| |
if ($delete_column) { |
| |
echo "<td><small>"; |
| |
if (! $phpWebFileManager_DENY_FILE_DELETE) |
| |
echo "[<a href=\"$PHPSELF?$origvars" |
| |
."dir=$dir&action=confirm_delete_file" |
| |
. "&filename=$entry\">Delete</a>]"; |
| |
echo "</small></td>"; |
| |
} |
| |
|
| $url = parse_url("http://${HTTP_HOST}${REQUEST_URI}"); |
$url = parse_url("http://${HTTP_HOST}${REQUEST_URI}"); |
| $url['path'] = get_path_without_scriptname($url) . $phpWebFileManager_ROOT_DIR . $dir . $entry; |
$url['path'] = get_path_without_scriptname($url) |
| |
. $phpWebFileManager_ROOT_DIR . $dir . $entry; |
| unset($url['query']); |
unset($url['query']); |
| unset($url['fragment']); |
unset($url['fragment']); |
| |
|
| echo "<td><small>"; |
if ($view_column) { |
| echo "[<a href=\"$PHPSELF?$origvars"."dir=$dir&action=confirm_delete_file&filename=$entry\">Delete</a>]"; |
echo "<td><small>"; |
| echo "</small></td>"; |
if (! $phpWebFileManager_DENY_FILE_VIEW) |
| |
echo "[<a target=_blank href=\"" |
| echo "<td><small>"; |
. glue_url($url) . "\">View</a>]"; |
| |
echo "</small></td>"; |
| echo "[<a target=_blank href=\"".glue_url($url)."\">View</a>]"; |
} |
| echo "</small></td>"; |
|
| } |
} |
| else { |
else { |
| |
|
| echo "<td><small>"; |
if ($rename_column) { |
| echo "[<a href=\"$PHPSELF?$origvars"."dir=$dir&action=confirm_rename_directory&filename=$entry\">Rename</a>]"; |
echo "<td><small>"; |
| echo "</small></td>"; |
if (! $phpWebFileManager_DENY_DIR_RENAME) |
| |
echo "[<a href=\"$PHPSELF?$origvars" |
| echo "<td><small>"; |
. "dir=$dir&action=confirm_rename_directory" |
| echo "[<a href=\"$PHPSELF?$origvars"."dir=$dir&action=confirm_remove_directory&filename=$entry\">Remove</a>]"; |
. "&filename=$entry\">Rename</a>]"; |
| echo "</small></td>"; |
echo "</small></td>"; |
| |
} |
| |
|
| |
if ($delete_column) { |
| |
echo "<td><small>"; |
| |
if (! $phpWebFileManager_DENY_DIR_REMOVE) |
| |
echo "[<a href=\"$PHPSELF?$origvars" |
| |
. "dir=$dir&action=confirm_remove_directory" |
| |
. "&filename=$entry\">Remove</a>]"; |
| |
echo "</small></td>"; |
| |
} |
| |
|
| echo "<td> </td>"; |
if ($view_column) { |
| |
echo "<td><small>"; |
| |
if (! $phpWebFileManager_DENY_DIR_ENTER) |
| |
echo "[<a href=\"$PHPSELF?$origvars" |
| |
. "dir=$dir$entry\">Enter</a>]"; |
| |
echo "</small></td>"; |
| |
} |
| } |
} |
| |
|
| echo "</tr>\n"; |
echo "</tr>\n"; |
|
|
| $d->close(); |
$d->close(); |
| } |
} |
| |
|
| echo "<tr><td colspan=5 align=center><small>"; |
if ($last_row) { |
| echo "<br>[<a href=$PHP_SELF?$origvars"."dir=".urlencode($dir)."&action=confirm_create_directory>Create a new directory</a>]"; |
echo "<tr><td colspan=5 align=center><small>"; |
| echo " [<a href=$PHP_SELF?$origvars"."dir=".urlencode($dir)."&action=confirm_create_file>Create an empty file</a>]"; |
|
| echo " [<a href=$PHP_SELF?$origvars"."dir=".urlencode($dir)."&action=confirm_upload_file>File upload</a>]"; |
if (! $phpWebFileManager_DENY_DIR_CREATE) |
| echo "</small></td></tr>"; |
echo "<br>[<a href=$PHP_SELF?$origvars" |
| |
. "dir=" . urlencode($dir) |
| |
. "&action=confirm_create_directory>" |
| |
. "Create a new directory</a>]"; |
| |
|
| |
if (! $phpWebFileManager_DENY_FILE_CREATE) |
| |
echo " [<a href=$PHP_SELF?$origvars" |
| |
. "dir=" . urlencode($dir) |
| |
. "&action=confirm_create_file>" |
| |
. "Create an empty file</a>]"; |
| |
|
| |
if (! $phpWebFileManager_DENY_FILE_UPLOAD) |
| |
echo " [<a href=$PHP_SELF?$origvars" |
| |
. "dir=" . urlencode($dir) |
| |
. "&action=confirm_upload_file>" |
| |
. "File upload</a>]"; |
| |
|
| |
echo "</small></td></tr>"; |
| |
} |
| |
|
| echo "</table>"; |
echo "</table>"; |
| |
|