$user = "bbc";
$pass = "acorn";
$user2 = "fgdesign";
$pass2 = "FGD10165";
$myroot_dir = realpath ("/home/sites/www.fgdesign.nl/documenten");
$select__home = True; //
$select__up = True; //
$create__dir = True; //
$upload__file = True; //
$show_cwd = True; //
$show__dir = True; //
$open__dir = True; //
$delete__dir = True; //
$rename__dir = True; //
$show__file = True; //
$open__file = True; //
$delete__file = True; //
$rename__file = True; //
$files_to_upload = 1;
// Do not alter anything below this line LINE!
$upload_dir = $myroot_dir . $subdir;
session_cache_limiter('none');
session_start();
$version = "1.05";
if ($subdir == "")
{
$subdirarg1 = "";
$subdirarg2 = "";
}
else
{
$subdirarg1 = '?subdir=' . $subdir;
$subdirarg2 = '&subdir=' . $subdir;
}
$php_version = phpversion();
$php_version = eregi_replace("\.", "" , $php_version);
if(strlen($php_version) < 3){
$phpversion = $php_version."0";
}
if($php_version < (420)) {
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$_COOKIE = $HTTP_COOKIE_VARS;
$_SESSION = $HTTP_SESSION_VARS;
$_SERVER = $HTTP_SERVER_VARS;
global $_GET, $_POST, $_COOKIE, $_SESSION, $_SERVER;
}else{
$PHP_SELF = $_SERVER["PHP_SELF"];
}
//When logging in, check username and password
if($_GET['method'] == "login")
{
if($_POST['username'] == $user && $_POST['password'] == $pass)
{
//Set the session for logged in to true
session_register('logged_in');
$_SESSION['logged_in'] = true;
Header("Location: " . $PHP_SELF. $subdirarg1);
}
elseif($_POST['username'] == $user2 && $_POST['password'] == $pass2)
{
session_register('logged_in');
$_SESSION['logged_in'] = true;
Header("Location: " . $PHP_SELF . $subdirarg1 );
}
elseif($_POST['username'] == $user3 && $_POST['password'] == $pass3)
{
session_register('logged_in');
$_SESSION['logged_in'] = true;
Header("Location: " . $PHP_SELF . $subdirarg1 );
}
}
//Any other action the user must be logged in!
elseif($_GET['method'])
{
//When not logged in, the user will be notified with a message
if(!session_is_registered('logged_in'))
{
not_allowed();
exit;
}
session_register('message');
//Upload the file
if($_GET['method'] == "upload")
{
$file_array = $HTTP_POST_FILES['file'];
$_SESSION['message'] = "";
$uploads = false;
for($i = 0 ; $i < $files_to_upload; $i++)
{
if($HTTP_POST_FILES['file']['name'][$i])
{
$uploads = true;
if($HTTP_POST_FILES['file']['name'][$i])
{
$file_to_upload = $upload_dir . "/".$HTTP_POST_FILES['file']['name'][$i];
//$_SESSION['message'] .= $file_to_upload ."
";
move_uploaded_file($HTTP_POST_FILES['file']['tmp_name'][$i],$file_to_upload);
//$_SESSION['message'] .= $HTTP_POST_FILES['file']['tmp_name'][$i]."
";
chmod($file_to_upload,0777);
$_SESSION['message'] .= $HTTP_POST_FILES['file']['name'][$i]." uploaded.
";
}
}
}
if(!$uploads)
{
$_SESSION['message'] = "No files selected!";
}
}
//Logout
elseif($_GET['method'] == "logout")
{
session_destroy();
}
//Delete the file
elseif($_GET['method'] == "delete" && $_GET['file'])
{
if(!@unlink($upload_dir."/".$_GET['file']))
$_SESSION['message'] = "File not found!";
else
$_SESSION['message'] = $_GET['file'] . " deleted";
}
//Delete the directory
elseif($_GET['method'] == "deletedir" && $_GET['file'])
{
if(!@rmdir($upload_dir."/".$_GET['file']))
$_SESSION['message'] = "File not found!";
else
$_SESSION['message'] = $_GET['file'] . " deleted";
}
//Download a file
elseif($_GET['method'] == "download" && $_GET['file'])
{
$file = $upload_dir . "/" . $_GET['file'];
$filename = basename( $file );
$len = filesize( $file );
header( "content-type: application/stream" );
header( "content-length: " . $len );
header( "content-disposition: attachment; filename=" . $filename );
$fp=fopen( $file, "r" );
fpassthru( $fp );
exit;
}
//Create a directory
elseif( $_GET['method'] == "createdir" )
{
$createdir = $upload_dir . "/" . $_GET['dirname'];
$old = umask(0);
mkdir ( $createdir, 0777);
$_SESSION['message'] = "Directory created " . $createdir;
umask($old);
}
//Rename a file
elseif( $_GET['method'] == "rename" )
{
rename( $upload_dir . "/" . $_GET['file'] , $upload_dir . "/" . $_GET['to'] );
$_SESSION['message'] = "Renamed " . $_GET['file'] . " to " . $_GET['to'];
}
//Redirect to the script again
Header("Location: " . $PHP_SELF . $subdirarg1);
}
// securing subdir for abuse, using path modifiers to try escaping the myroot_dir
if (strpos(realpath($upload_dir), $myroot_dir)!==false)
{
// path valid, match is found of $myroot_dir in $upload_dir
// realsubdir contains the subdir, but has expanded all sybolic links and other path modifiers like /.. etc. to a real path!
$realsubdir=substr(realpath($upload_dir), strlen($myroot_dir), (strlen(realpath($upload_dir))-strlen($myroot_dir)));
$subdir=$realsubdir;
}
else
{
// illegal path, resetting upload dir
$upload_dir = $myroot_dir;
$subdir = "";
}
// is user allowed to go up one directory?
$dir_up = $upload_dir."/..";
if (strpos(realpath($dir_up), $myroot_dir)!==false)
{
$dir_up=substr(realpath($dir_up), strlen($myroot_dir), (strlen(realpath($dir_up))-strlen($myroot_dir)));
if($dir_up == "")
{
$dir_up="/";
}
}
else
{
$dir_up=false;
}
// HTML STARTING //
?>