Inital commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
ENGLISH
|
||||
0. If you want to set a password for upload and deletion, open lister.php with an editor
|
||||
an define your password in line 15:
|
||||
define('PASSWORD', 'My-secret-Passwort');
|
||||
If you do not change this, no password is needed.
|
||||
1. Make a new directory on the server
|
||||
2. Change file permissions: chmod 757 directory
|
||||
3. Copy lister.php and lister_download_button.gif in the new directory
|
||||
4. Change file permissions of the script: chmod 646 lister.php
|
||||
5. Done.
|
||||
|
||||
DEUTSCH
|
||||
0. Falls gewünscht: lister.php mit einem Editor öffnen und in Zeile 15 ein Passwort
|
||||
für das Hochladen und Löschen festlegen:
|
||||
define('PASSWORD', 'Mein-geheimes-Passwort');
|
||||
Wenn die Zeile nicht verändert wird, muss kein Passwort eingegeben werden.
|
||||
1. Das Verzeichnis auf dem Server anlegen
|
||||
2. Rechte setzen: chmod 757 verzeichnis
|
||||
3. lister.php und lister_download_button.gif in das Verzeichnis kopieren
|
||||
4. Rechte setzen: chmod 646 lister.php
|
||||
5. Fertig. Jetzt kann das Skript aufgerufen werden.
|
||||
+534
@@ -0,0 +1,534 @@
|
||||
<?php
|
||||
/*
|
||||
* Lister - a directory listing, upload and download script - version 3.2
|
||||
* http://www.tilman.de/programme/lister/
|
||||
* Author: Tilman Walther
|
||||
* This work is licensed under the Creative Commons Attribution-ShareAlike 2.0 Germany License.
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/de/
|
||||
* or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
|
||||
*
|
||||
* The software is made available free of charge, no express or implied warranties are made.
|
||||
* USE AT YOUR OWN RISK.
|
||||
*/
|
||||
|
||||
// The Password for uploads and deletion. If empty, no password is needed for upload and deletion.
|
||||
define('PASSWORD', '');
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
define('SCRIPTNAME', basename($_SERVER['PHP_SELF']));
|
||||
|
||||
// The file list. Hands off!
|
||||
/* Filelist:
|
||||
:Filelist */
|
||||
|
||||
//-- Hilfsfunktionen -------------------------------------------------------------------------------
|
||||
|
||||
$totalFiles = 0;
|
||||
$totalFileSize = 0;
|
||||
|
||||
function readFileList() {
|
||||
|
||||
global $totalFiles;
|
||||
global $totalFileSize;
|
||||
$lines = file(SCRIPTNAME);
|
||||
|
||||
if ($lines) {
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ((!strstr(substr($lines[$i],0,14), "* Filelist:")) and ($i <= count($lines))) // Lies bis zur Dateiliste
|
||||
{
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (strstr(substr($lines[$i],0,14), "* Filelist:")) {
|
||||
|
||||
// Dateiliste aus Datei lesen
|
||||
$i++;
|
||||
$j = 0;
|
||||
|
||||
while (!strstr(substr($lines[$i+$j],0,14), ":Filelist *")) {
|
||||
|
||||
$liste[$j] = explode("//", $lines[$i+$j]);
|
||||
$liste[$j][1] = preg_replace("/\r|\n/s", "", $liste[$j][1]); // Zeilenumbruch hinter Beschreibung entfernen
|
||||
|
||||
/*
|
||||
$descPos = strpos($lines[$i+$j], '//');
|
||||
$liste[$j][0] = substr($lines[$i+$j], 0, $descPos);
|
||||
|
||||
// Zeilenumbruch hinter Beschreibung entfernen
|
||||
$liste[$j][1] = preg_replace("/\r|\n/s", "", substr($lines[$i+$j], $descPos+2));
|
||||
*/
|
||||
|
||||
$liste[$j][2] = filesize(urlencode($liste[$j][0]));
|
||||
|
||||
$totalFiles++;
|
||||
$totalFileSize += $liste[$j][2];
|
||||
|
||||
$j++;
|
||||
}
|
||||
return $liste;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSizeAsString($size) {
|
||||
if ($size < 2) {
|
||||
return $size." Byte";
|
||||
}
|
||||
else if ($size < 1024) {
|
||||
return $size." Bytes";
|
||||
}
|
||||
else if ($size < 1048576) {
|
||||
return round(($size/1024), 2)." KB";
|
||||
}
|
||||
else {
|
||||
return round(($size/1048576), 2)." MB";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($_GET['action'] != 'download') {
|
||||
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
||||
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body { font-family: "Trebuchet MS", Georgia, serif; }
|
||||
a { color:#0000CC; }
|
||||
table { border-collapse: collapse; }
|
||||
th { text-align: left; background-color:#EEEEEE; font-size: 80%; }
|
||||
|
||||
.menu { font-size: 80%; }
|
||||
.smallsize { font-size: 80%; }
|
||||
.download a { font-size: 60%; color:#0000CC; text-decoration: none; font-weight: bold; }
|
||||
-->
|
||||
</style>
|
||||
|
||||
<title>Lister</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
//-- Hinzufügen ------------------------------------------------------------------------------------
|
||||
|
||||
if ($_GET['action'] == 'add') {
|
||||
|
||||
echo '<p class="menu"><a href="'.$_SERVER['PHP_SELF'].'">zurück zur Liste</a></p>';
|
||||
|
||||
// massive Login-Versuche abblocken
|
||||
sleep(1);
|
||||
|
||||
// Passwort checken
|
||||
if ($_POST['password'] == PASSWORD) {
|
||||
|
||||
$already_exists = file_exists(urlencode($_FILES['datei']['name']));
|
||||
|
||||
if (($already_exists) and (!$_POST['overwrite'] == 'on')) {
|
||||
echo "<p><b>Fehler:</b> Datei mit Namen <i>" . htmlspecialchars($_FILES['datei']['name']) . "</i> ist bereits vorhanden. (Überschreiben abgeschaltet.)</p>\n";
|
||||
}
|
||||
else {
|
||||
|
||||
$filename = $_FILES['datei']['name'];
|
||||
|
||||
if (move_uploaded_file($_FILES['datei']['tmp_name'], urlencode($filename))) {
|
||||
|
||||
echo "<p>Die Datei <i>" . htmlspecialchars($_FILES['datei']['name']) . "</i> wurde übertragen.</p>\n";
|
||||
|
||||
$liste = readFileList();
|
||||
|
||||
if ($liste !== false) {
|
||||
|
||||
if ($liste !== NULL) {
|
||||
foreach($liste as $v) $s[] = $v[0];
|
||||
$idx = array_search($filename, $s);
|
||||
}
|
||||
|
||||
// FUNKY!
|
||||
if (gettype($idx) == 'integer') { // Dateiname bereits in Liste enthalten
|
||||
|
||||
$lines = file(SCRIPTNAME);
|
||||
|
||||
if ($lines) {
|
||||
|
||||
$fp = fopen(SCRIPTNAME,'w+'); // Index-Datei zum Schreiben öffnen
|
||||
$i = 0;
|
||||
|
||||
while (!strstr(substr($lines[$i],0,14), "* Filelist:")) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
while (!strstr(substr($lines[$i], 0, strpos($lines[$i], '//')), $filename)) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
fputs($fp, $filename."//".$_POST['description']."\n");
|
||||
|
||||
while ($i < count($lines)) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
|
||||
echo "<p>Tabelleneintrag wurde aktualisiert.</p>\n";
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> <i>".$_SERVER['PHP_SELF']."</i> wurde nicht gefunden!</p>\n";
|
||||
}
|
||||
}
|
||||
else { // Dateiname noch nicht in Liste enthalten
|
||||
|
||||
$lines = file(SCRIPTNAME);
|
||||
|
||||
if ($lines) {
|
||||
|
||||
$fp = fopen(SCRIPTNAME,'w+'); // Index-Datei zum Schreiben öffnen
|
||||
$i = 0;
|
||||
|
||||
while (!strstr(substr($lines[$i],0,14), "* Filelist:")) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
while (!strstr($lines[$i], "*/")) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
fputs($fp, $filename."//".$_POST['description']."\n");
|
||||
|
||||
while ($i < count($lines)) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
echo "<p>Tabelleneintrag wurde erzeugt.</p>\n";
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> <i>".$_SERVER['PHP_SELF']."</i> wurde nicht gefunden!</p>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> Liste mit Dateien konnte nicht gefunden werden.</p>\n";
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> Datei konnte nicht übertragen werden!</p>\n";
|
||||
echo "<p>\n";
|
||||
print_r($_FILES);
|
||||
echo "\n</p>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // Passwort falsch
|
||||
echo "<p><b>Fehler:</b> Falsches Passwort!</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
//-- Sicherheitsabfrage vor Löschen -------------------------------------------------------------------
|
||||
|
||||
else if ($_GET['action'] == 'deleteCheck') {
|
||||
|
||||
echo '<p class="menu"><a href="'.$_SERVER['PHP_SELF'].'">zurück zur Liste</a></p>';
|
||||
|
||||
if (isset($_REQUEST['delButton'])) {
|
||||
|
||||
echo "<div style=\"margin:2em\">\n";
|
||||
echo " <b>Auswahl löschen:</b><br>\n";
|
||||
echo " <form action=\"".$_SERVER['PHP_SELF']."?action=delete\" method=\"post\">\n";
|
||||
echo " <table>\n";
|
||||
|
||||
reset($_REQUEST['delButton']);
|
||||
foreach ($_REQUEST['delButton'] as $idx => $filename) {
|
||||
echo " <tr>\n";
|
||||
echo " <td>".$filename."</td>\n";
|
||||
echo " <td align=\"right\"><input type=\"checkbox\" name=\"delButton[]\" value=\"".$filename."\" checked /></td>\n";
|
||||
echo " </tr>\n";
|
||||
}
|
||||
|
||||
if (PASSWORD != '') {
|
||||
echo " <tr>\n";
|
||||
echo " <td colspan=\"2\">\n";
|
||||
echo " <br>\n";
|
||||
echo " <span class=\"menu\">Passwort:</span>\n";
|
||||
echo " <input name=\"password\" type=\"password\" size=\"10\" /><br>\n";
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
}
|
||||
|
||||
echo " <tr>\n";
|
||||
echo " <td class=\"menu\" colspan=\"2\" align=\"right\">\n";
|
||||
echo " <input type=\"submit\" value=\"";
|
||||
if (count($_REQUEST['delButton']) > 1) {
|
||||
echo "Dateien löschen\" />\n";
|
||||
}
|
||||
else {
|
||||
echo "Datei löschen\" />\n";
|
||||
}
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
echo " </table>\n";
|
||||
echo " </form>\n";
|
||||
echo "</div>\n";
|
||||
|
||||
} else {
|
||||
echo "<p><b>Fehler:</b> Keine Datei ausgewählt.</p>\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-- Löschen ---------------------------------------------------------------------------------------
|
||||
|
||||
else if ($_GET['action'] == 'delete') {
|
||||
|
||||
echo '<p class="menu"><a href="'.$_SERVER['PHP_SELF'].'">zurück zur Liste</a></p>';
|
||||
|
||||
// massive Login-Versuche abblocken
|
||||
sleep(1);
|
||||
|
||||
// Passwort checken
|
||||
if ($_POST['password'] == PASSWORD) {
|
||||
|
||||
if (isset($_REQUEST['delButton'])) {
|
||||
|
||||
reset($_REQUEST['delButton']);
|
||||
|
||||
foreach ($_REQUEST['delButton'] as $idx => $filename) {
|
||||
|
||||
echo "<p>Lösche <i>$filename</i>...</p>\n";
|
||||
unlink(urlencode($filename));
|
||||
|
||||
$lines = file(SCRIPTNAME);
|
||||
|
||||
if ($lines) {
|
||||
|
||||
$fp = fopen(SCRIPTNAME,'w+'); // Index-Datei zum Schreiben öffnen
|
||||
$i = 0;
|
||||
|
||||
while (!strstr(substr($lines[$i],0,14), "* Filelist:")) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
while (!strstr(substr($lines[$i], 0, strpos($lines[$i], '//')), $filename)) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
|
||||
while ($i < count($lines)) {
|
||||
fputs($fp, $lines[$i]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
echo "<p>Tabelleneintrag wurde entfernt.</p>\n";
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> <i>".$_SERVER['PHP_SELF']."</i> wurde nicht gefunden!</p>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> Keine Dateien ausgewählt.</p>\n";
|
||||
}
|
||||
}
|
||||
else { // Passwort falsch
|
||||
echo "<p><b>Fehler:</b> Falsches Passwort!</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
//-- Anzeigen --------------------------------------------------------------------------------------
|
||||
|
||||
else {
|
||||
?>
|
||||
|
||||
<div align="center">
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=deleteCheck" method="post">
|
||||
|
||||
<table cellspacing="5" cellpadding="5" border="1">
|
||||
<tr>
|
||||
<th><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php if (($_GET['action'] == 'ascByName') || ($_GET['action'] == '')) echo "descByName"; else echo 'ascByName';?>">Datei</a></th>
|
||||
<th><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php if ($_GET['action'] == 'ascByDescription') echo "descByDescription"; else echo 'ascByDescription';?>">Beschreibung</a></th>
|
||||
<th><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php if ($_GET['action'] == 'ascBySize') echo "descBySize"; else echo 'ascBySize';?>">Größe</a></th>
|
||||
<th>Auswahl</th>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
$liste = readFileList();
|
||||
|
||||
if ($liste !== false) {
|
||||
|
||||
if (isset($liste)) {
|
||||
|
||||
// Liste sortieren
|
||||
if ($_GET['action'] == 'ascByDescription') {
|
||||
foreach($liste as $v) $s[] = $v[1];
|
||||
array_multisort($s, SORT_ASC, $liste);
|
||||
}
|
||||
else if ($_GET['action'] == 'descByDescription') {
|
||||
foreach($liste as $v) $s[] = $v[1];
|
||||
array_multisort($s, SORT_DESC, $liste);
|
||||
}
|
||||
else if ($_GET['action'] == 'ascBySize') {
|
||||
foreach($liste as $v) $s[] = $v[2];
|
||||
array_multisort($s, SORT_ASC, $liste);
|
||||
}
|
||||
else if ($_GET['action'] == 'descBySize') {
|
||||
foreach($liste as $v) $s[] = $v[2];
|
||||
array_multisort($s, SORT_DESC, $liste);
|
||||
}
|
||||
else if ($_GET['action'] == 'descByName') {
|
||||
foreach($liste as $v) $s[] = $v[0];
|
||||
array_multisort($s, SORT_DESC, $liste);
|
||||
}
|
||||
else {
|
||||
sort($liste);
|
||||
}
|
||||
|
||||
// Liste ausgeben
|
||||
foreach ($liste as $eintrag) {
|
||||
echo " <tr>\n";
|
||||
echo " <td><a href=\"".urlencode(urlencode($eintrag[0]))."\">".htmlentities($eintrag[0])."</a> <span class=\"download\"><a href=\"".SCRIPTNAME."?action=download&file=".urlencode(urlencode($eintrag[0]))."\"><img src=\"lister_download_button.gif\" border=\"0\" alt=\"[download]\"></a></span></td>\n";
|
||||
echo " <td>".htmlentities($eintrag[1])."</td>\n";
|
||||
echo " <td align=\"right\"><span class=\"smallsize\">".getSizeAsString($eintrag[2])."</span></td>\n";
|
||||
echo " <td align=\"center\"><input type=\"checkbox\" name=\"delButton[]\" value=\"".htmlentities($eintrag[0])."\" /></td>\n";
|
||||
echo " </tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
echo "<p><b>Fehler:</b> Liste mit Dateien konnte nicht gefunden werden.</p>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td class="menu" colspan="4" align="right">
|
||||
<input type="submit" value="Ausgewählte Dateien löschen" style="font-size:105%" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" align="center" class="smallsize">
|
||||
<?php echo $totalFiles; ?> Dateien, <?php echo getSizeAsString($totalFileSize); ?><br>
|
||||
<span style="font-size: 80%"><a href="http://www.tilman.de/programme/lister/">Lister</a> v3.2</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
<table cellspacing="5" cellpadding="5" border="1">
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<div style="padding:8px">
|
||||
<div class="menu">Datei hinzufügen:</div>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=add" method="post" enctype="multipart/form-data">
|
||||
<table border="0" cellpadding="2" class="menu">
|
||||
<tr>
|
||||
<td>
|
||||
Datei:
|
||||
</td>
|
||||
<td>
|
||||
<input name="datei" type="file" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Beschreibung:
|
||||
</td>
|
||||
<td>
|
||||
<input name="description" type="text" size="30" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="checkbox" name="overwrite" /><span style="font-size:small">bereits vorhandene überschreiben</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if (PASSWORD != '') { ?>
|
||||
<tr>
|
||||
<td>
|
||||
Passwort:
|
||||
</td>
|
||||
<td>
|
||||
<input name="password" type="password" size="10" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="2" align="right" class="menu">
|
||||
<input type="submit" value="Datei hochladen" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div style="position: absolute; top: 8px; right: 5px;">
|
||||
<a href="http://validator.w3.org/check?uri=referer"><img border="0" src="http://www.w3.org/Icons/valid-html40" alt="Valid HTML 4.0!" height="31" width="88"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
}
|
||||
else {
|
||||
//-- Download --------------------------------------------------------------------------------------
|
||||
$fileList = readFileList();
|
||||
$physicalFileName = $_GET['file'];
|
||||
$logicalFileName = urldecode($_GET['file']);
|
||||
|
||||
// security check: search for the file in the file list
|
||||
for ($i = 0; $i <= sizeof($fileList); $i++) {
|
||||
if ($fileList[$i][0] == $logicalFileName) {
|
||||
header('Content-Type: application/octet-stream');
|
||||
//header('Content-type: application/force-download');
|
||||
|
||||
header('Content-Disposition: attachment; filename="'.$logicalFileName.'"');
|
||||
header('Content-Length: '.filesize($physicalFileName));
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: 0');
|
||||
|
||||
readfile($physicalFileName);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// if the file is unknown, forward to the standard view
|
||||
header('Location: http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']), '/\\').'/'.SCRIPTNAME);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 822 B |
Binary file not shown.
|
After Width: | Height: | Size: 1021 B |
Reference in New Issue
Block a user