* The newest version of File Thingie can be found at
* Comments, suggestions etc. are welcome and encouraged at the above e-mail.
*
* LICENSE INFORMATION FOR FILE THINGIE:
* File Thingie is Copyright (c) 2003-2008 Andreas Haugstrup Pedersen. All Rights Reserved.
*
* File Thingie is free for non-commercial use. Commercial use costs $20 per copy of File Thingie.
* Read more at: http://www.solitude.dk/filethingie/download
* Contact for bulk discounts.
*/
# Version information #
define("VERSION", "2.5.5"); // Current version of File Thingie.
define("INSTALL", "SIMPLE"); // Type of File Thingie installation. EXPANDED or SIMPLE.
define("MUTEX", $_SERVER['PHP_SELF']);
$ft = array();
$ft['settings'] = array();
$ft['groups'] = array();
$ft['users'] = array();
$ft['plugins'] = array();
# Settings - Change as appropriate. See online documentation for explanations. #
define("USERNAME", "seanstar"); // Your default username.
define("PASSWORD", "omgwowwow"); // Your default password.
$ft["settings"]["DIR"] = "../../../"; // Your default directory. Do NOT include a trailing slash!
$ft["settings"]["LANG"] = "en"; // Language. Do not change unless you have downloaded language file.
$ft["settings"]["MAXSIZE"] = 2000000; // Maximum file upload size - in bytes.
$ft["settings"]["PERMISSION"] = 0777; // Permission for uploaded files.
$ft["settings"]["LOGIN"] = TRUE; // Set to FALSE if you want to disable password protection.
$ft["settings"]["UPLOAD"] = TRUE; // Set to FALSE if you want to disable file uploads.
$ft["settings"]["CREATE"] = TRUE; // Set to FALSE if you want to disable file/folder/url creation.
$ft["settings"]["FILEACTIONS"] = TRUE; // Set to FALSE if you want to disable file actions (rename, move, delete, edit, duplicate).
$ft["settings"]["HIDEFILEPATHS"] = FALSE; // Set to TRUE to not pass downloads through File Thingie.
$ft["settings"]["DELETEFOLDERS"] = TRUE; // Set to TRUE to allow deletion of non-empty folders.
$ft["settings"]["SHOWDATES"] = FALSE; // Set to a date format to display last modified date (e.g. 'Y-m-d'). See http://dk2.php.net/manual/en/function.date.php
$ft["settings"]["FILEBLACKLIST"] = ""; // Specific files that will not be shown.
$ft["settings"]["FOLDERBLACKLIST"] = ""; // Specifies folders that will not be shown. No starting or trailing slashes!
$ft["settings"]["FILETYPEBLACKLIST"] = ""; // File types that are not allowed for upload.
$ft["settings"]["FILETYPEWHITELIST"] = ""; // Add file types here to *only* allow those types to be uploaded.
$ft["settings"]["ADVANCEDACTIONS"] = TRUE; // Set to TRUE to enable advanced actions like chmod and symlinks.
$ft["settings"]["LIMIT"] = 0; // Restrict total dir file usage to this amount of bytes. Set to "0" for no limit.
$ft["settings"]["REQUEST_URI"] = FALSE; // Installation path. You only need to set this if $_SERVER['REQUEST_URI'] is not being set by your server.
$ft["settings"]["HTTPS"] = FALSE; // Change to TRUE to enable HTTPS support.
$ft["settings"]["AUTOUPDATES"] = "0"; // Number of days between checking for updates. Set to '0' to turn off.
$ft["settings"]["REMEMBERME"] = FALSE; // Set to TRUE to enable the "remember me" feature at login.
$ft["settings"]["PLUGINDIR"] = 'ft_plugins'; // Set to the path to your plugin folder. Do NOT include a trailing slash!
# Colours #
$ft["settings"]["COLOURONE"] = "#326532"; // Dark background colour - also used on menu links.
$ft["settings"]["COLOURONETEXT"] = "#fff"; // Text for the dark background.
$ft["settings"]["COLOURTWO"] = "#DAE3DA"; // Brighter color (for table rows and sidebar background).
$ft["settings"]["COLOURTEXT"] = "#000"; // Regular text colour.
$ft["settings"]["COLOURHIGHLIGHT"] = "#ffc"; // Hightlight colour for status messages.
# Plugin settings #
$ft["plugins"]["search"] = TRUE;
$ft["plugins"]["edit"] = array(
"settings" => array(
"editlist" => "txt html htm css php",
"converttabs" => FALSE
)
);
/*
$ft["plugins"]["tinymce"] = array(
"settings" => array(
"path" => "tinymce/jscripts/tiny_mce/tiny_mce.js",
"list" => "html htm"
)
);
*/
# Additional users - See guide at http://www.solitude.dk/filethingie/documentation/users #
/*
$ft['users']['REPLACE_WITH_USERNAME'] = array(
'password' => 'REPLACE_WITH_PASSWORD',
'group' => 'REPLACE_WITH_GROUPNAME'
);
*/
# User groups for additional users - - See guide at http://www.solitude.dk/filethingie/documentation/users #
/*
$ft['groups']['REPLACE_WITH_GROUPNAME'] = array(
'DIR' => 'REPLACE_WITH_CUSTOM_DIR',
);
*/
/**
* Check if a login cookie is valid.
*
* @param $c
* The login cookie from $_COOKIE.
* @return The username of the cookie user. FALSE if cookie is not valid.
*/
function ft_check_cookie($c) {
global $ft;
// Check primary user.
if ($c == md5(USERNAME.PASSWORD)) {
return USERNAME;
}
// Check users array.
if (is_array($ft['users']) && sizeof($ft['users']) > 0) {
// Loop through users.
foreach ($ft['users'] as $user => $a) {
if ($c == md5($user.$a['password'])) {
return $user;
}
}
}
return FALSE;
}
/**
* Check if directory is on the blacklist.
*
* @param $dir
* Directory path.
* @return TRUE if directory is not blacklisted.
*/
function ft_check_dir($dir) {
// Check against folder blacklist.
if (FOLDERBLACKLIST != "") {
$blacklist = explode(" ", FOLDERBLACKLIST);
foreach ($blacklist as $c) {
if (substr($dir, 0, strlen(ft_get_root().'/'.$c)) == ft_get_root().'/'.$c) {
return FALSE;
}
}
return TRUE;
} else {
return TRUE;
}
}
/**
* Check if file actions are allowed in the current directory.
*
* @return TRUE is file actions are allowed.
*/
function ft_check_fileactions() {
if (FILEACTIONS === TRUE) {
// Uploads are universally turned on.
return TRUE;
} else if (FILEACTIONS == TRUE && FILEACTIONS == substr(ft_get_dir(), 0, strlen(FILEACTIONS))) {
// Uploads are allowed in the current directory and subdirectories only.
return TRUE;
}
return FALSE;
}
/**
* Check if file is on the blacklist.
*
* @param $file
* File name.
* @return TRUE if file is not blacklisted.
*/
function ft_check_file($file) {
// Check against file blacklist.
if (FILEBLACKLIST != "") {
$blacklist = explode(" ", FILEBLACKLIST);
if (in_array(strtolower($file), $blacklist)) {
return FALSE;
} else {
return TRUE;
}
} else {
return TRUE;
}
}
/**
* Check if file type is on the blacklist.
*
* @param $file
* File name.
* @return TRUE if file is not blacklisted.
*/
function ft_check_filetype($file) {
$type = strtolower(ft_get_ext($file));
// Check if we are using a whitelist.
if (FILETYPEWHITELIST != "") {
// User wants a whitelist
$whitelist = explode(" ", FILETYPEWHITELIST);
if (in_array($type, $whitelist)) {
return TRUE;
} else {
return FALSE;
}
} else {
// Check against file blacklist.
if (FILETYPEBLACKLIST != "") {
$blacklist = explode(" ", FILETYPEBLACKLIST);
if (in_array($type, $blacklist)) {
return FALSE;
} else {
return TRUE;
}
} else {
return TRUE;
}
}
}
/**
* Check if a user is authenticated to view the page or not. Must be called on all pages.
*
* @return TRUE if the user is authenticated.
*/
function ft_check_login() {
global $ft;
$valid_login = 0;
if (LOGIN == TRUE) {
if (empty($_SESSION['ft_user_'.MUTEX])) {
$cookie_mutex = str_replace('.', '_', MUTEX);
// Session variable has not been set. Check if there is a valid cookie or login form has been submitted or return false.
if (REMEMBERME == TRUE && !empty($_COOKIE['ft_user_'.$cookie_mutex])) {
// Verify cookie.
$cookie = ft_check_cookie($_COOKIE['ft_user_'.$cookie_mutex]);
if (!empty($cookie)) {
// Cookie valid. Login.
$_SESSION['ft_user_'.MUTEX] = $cookie;
ft_invoke_hook('loginsuccess', $cookie);
ft_redirect();
}
}
if (!empty($_POST['act']) && $_POST['act'] == "dologin") {
// Check username and password from login form.
if (!empty($_POST['ft_user']) && $_POST['ft_user'] == USERNAME && $_POST['ft_pass'] == PASSWORD) {
// Valid login.
$_SESSION['ft_user_'.MUTEX] = USERNAME;
$valid_login = 1;
}
// Default user was not valid, we check additional users (if any).
if (is_array($ft['users']) && sizeof($ft['users']) > 0) {
// Check username and password.
if (array_key_exists($_POST['ft_user'], $ft['users']) && $ft['users'][$_POST['ft_user']]['password'] == $_POST['ft_pass']) {
// Valid login.
$_SESSION['ft_user_'.MUTEX] = $_POST['ft_user'];
$valid_login = 1;
}
}
if ($valid_login == 1) {
// Set cookie.
if (!empty($_POST['ft_cookie']) && REMEMBERME) {
setcookie('ft_user_'.MUTEX, md5($_POST['ft_user'].$_POST['ft_pass']), time()+60*60*24*3);
} else {
// Delete cookie
setcookie('ft_user_'.MUTEX, md5($_POST['ft_user'].$_POST['ft_pass']), time()-3600);
}
ft_invoke_hook('loginsuccess', $_POST['ft_user']);
ft_redirect();
} else {
ft_invoke_hook('loginfail', $_POST['ft_user']);
ft_redirect("act=error");
}
}
return FALSE;
} else {
return TRUE;
}
} else {
return TRUE;
}
}
/**
* Check if a move action is inside the file actions area if FILEACTIONS is set to a specific director.
*
* @param $dest
* The directory to move to.
* @return TRUE if move action is allowed.
*/
function ft_check_move($dest) {
if (FILEACTIONS === TRUE) {
return TRUE;
}
// Check if destination is within the fileactions area.
$dest = substr($dest, 0, strlen($dest));
$levels = substr_count(substr(ft_get_dir(), strlen(FILEACTIONS)), '/');
if ($levels <= substr_count($dest, '../')) {
return TRUE;
} else {
return FALSE;
}
}
/**
* Check if uploads are allowed in the current directory.
*
* @return TRUE if uploads are allowed.
*/
function ft_check_upload() {
if (UPLOAD === TRUE) {
// Uploads are universally turned on.
return TRUE;
} else if (UPLOAD == TRUE && UPLOAD == substr(ft_get_dir(), 0, strlen(UPLOAD))) {
// Uploads are allowed in the current directory and subdirectories only.
return TRUE;
}
return FALSE;
}
/**
* Check if a user exists.
*
* @param $username
* Username to check.
* @return TRUE if user exists.
*/
function ft_check_user($username) {
global $ft;
if ($username == USERNAME) {
return TRUE;
} elseif (is_array($ft['users']) && sizeof($ft['users']) > 0 && array_key_exists($username, $ft['users'])) {
return TRUE;
}
return FALSE;
}
/**
* Check if the a new version of File Thingie is available.
*
* @return A string describing the results. Contains a changelog if a new version is available.
*/
function ft_check_version() {
// Get newest version.
if ($c = ft_get_url("http://www.solitude.dk/filethingie/versioninfo2.php?act=check&from=".urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))) {
$c = explode('||', $c);
$version = trim($c[0]);
$log = trim($c[1]);
// Compare versions.
if (version_compare($version, VERSION) == 1) {
// New version available.
return ''.t('', array('!version' => $version)).'';
} else {
// Running newest version.
return '
'.t('No updates available.').'
- '.t('Your version:').' '.VERSION.'
- '.t('Newest version:').' '.$version.'
".t('Newest version is:')." {$version}
"; } else { return "".t('Could not connect (possible error: URL wrappers not enabled).')."
"; } } /** * Remove unwanted characters from the settings array. */ function ft_clean_settings($settings) { // TODO: Clean DIR, UPLOAD and FILEACTIONS so they can't start with ../ return $settings; } /** * Run all system actions based on the value of $_REQUEST['act']. */ function ft_do_action() { if (!empty($_REQUEST['act'])) { // Only one callback action is allowed. So only the first hook that acts on an action is run. ft_invoke_hook('action', $_REQUEST['act']); # mkdir if ($_REQUEST['act'] == "createdir" && CREATE === TRUE) { $_POST['newdir'] = trim($_POST['newdir']); if ($_POST['type'] == 'file') { // Check file against blacklists if (strlen($_POST['newdir']) > 0 && ft_check_filetype($_POST['newdir']) && ft_check_file($_POST['newdir'])) { // Create file. $newfile = ft_get_dir()."/{$_POST['newdir']}"; if (file_exists($newfile)) { // Redirect ft_set_message(t("File could not be created. File already exists."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } elseif (@touch($newfile)) { // Redirect. ft_set_message(t("File created.")); ft_redirect("dir=".$_REQUEST['dir']); } else { // Redirect ft_set_message(t("File could not be created."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } } else { // Redirect ft_set_message(t("File could not be created."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } } elseif ($_POST['type'] == 'url') { // Create from URL. $newname = trim(substr($_POST['newdir'], strrpos($_POST['newdir'], '/')+1)); if (strlen($newname) > 0 && ft_check_filetype($newname) && ft_check_file($newname)) { // Open file handlers. $rh = fopen($_POST['newdir'], 'rb'); if ($rh === FALSE) { ft_set_message(t("Could not open URL. Possible reason: URL wrappers not enabled."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } $wh = fopen(ft_get_dir().'/'.$newname, 'wb'); if ($wh === FALSE) { ft_set_message(t("File could not be created."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } // Download anf write file. while (!feof($rh)) { if (fwrite($wh, fread($rh, 1024)) === FALSE) { ft_set_message(t("File could not be saved."), 'error'); } } fclose($rh); fclose($wh); ft_redirect("dir=".$_REQUEST['dir']); } else { // Redirect ft_set_message(t("File could not be created."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } } else { // Create directory. // Check input. // if (strstr($_POST['newdir'], ".")) { // Throw error (redirect). // ft_redirect("status=createddirfail&dir=".$_REQUEST['dir']); // } else { $_POST['newdir'] = ft_stripslashes($_POST['newdir']); $newdir = ft_get_dir()."/{$_POST['newdir']}"; $oldumask = umask(0); if (strlen($_POST['newdir']) > 0 && @mkdir($newdir, 0777)) { ft_set_message(t("Directory created.")); ft_redirect("dir=".$_REQUEST['dir']); } else { // Redirect ft_set_message(t("Directory could not be created."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } umask($oldumask); // } } # Move } elseif ($_REQUEST['act'] == "move" && ft_check_fileactions() === TRUE) { // Check that both file and newvalue are set. $file = trim(ft_stripslashes($_REQUEST['file'])); $dir = trim(ft_stripslashes($_REQUEST['newvalue'])); if (substr($dir, -1, 1) != "/") { $dir .= "/"; } // Check for level. if (substr_count($dir, "../") <= substr_count(ft_get_dir(), "/") && ft_check_move($dir) === TRUE) { $dir = ft_get_dir()."/".$dir; if (!empty($file) && file_exists(ft_get_dir()."/".$file)) { // Check that destination exists and is a directory. if (is_dir($dir)) { // Move file. if (@rename(ft_get_dir()."/".$file, $dir."/".$file)) { // Success. ft_set_message(t("!old was moved to !new", array('!old' => $file, '!new' => $dir))); ft_redirect("dir={$_REQUEST['dir']}"); } else { // Error rename failed. ft_set_message(t("!old could not be moved.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error dest. isn't a dir or doesn't exist. ft_set_message(t("Could not move file. !old does not exist or is not a directory.", array('!old' => $dir)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error source file doesn't exist. ft_set_message(t("!old could not be moved. It doesn't exist.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error level ft_set_message(t("!old could not be moved outside the base directory.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } # Delete } elseif ($_REQUEST['act'] == "delete" && ft_check_fileactions() === TRUE) { // Check that file is set. $file = ft_stripslashes($_REQUEST['file']); if (!empty($file) && ft_check_file($file)) { if (is_dir(ft_get_dir()."/".$file)) { if (DELETEFOLDERS == TRUE) { ft_rmdir_recurse(ft_get_dir()."/".$file); } if (!@rmdir(ft_get_dir()."/".$file)) { ft_set_message(t("!old could not be deleted.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } else { ft_set_message(t("!old deleted.", array('!old' => $file))); ft_redirect("dir={$_REQUEST['dir']}"); } } else { if (!@unlink(ft_get_dir()."/".$file)) { ft_set_message(t("!old could not be deleted.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } else { ft_set_message(t("!old deleted.", array('!old' => $file))); ft_redirect("dir={$_REQUEST['dir']}"); } } } else { ft_set_message(t("!old could not be deleted.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } # Rename && Duplicate && Symlink } elseif ($_REQUEST['act'] == "rename" || $_REQUEST['act'] == "duplicate" || $_REQUEST['act'] == "symlink" && ft_check_fileactions() === TRUE) { // Check that both file and newvalue are set. $old = trim(ft_stripslashes($_REQUEST['file'])); $new = trim(ft_stripslashes($_REQUEST['newvalue'])); if ($_REQUEST['act'] == 'rename') { $m['typefail'] = t("!old was not renamed to !new (type not allowed).", array('!old' => $old, '!new' => $new)); $m['writefail'] = t("!old could not be renamed (write failed).", array('!old' => $old)); $m['destfail'] = t("File could not be renamed to !new since it already exists.", array('!new' => $new)); $m['emptyfail'] = t("File could not be renamed since you didn't specify a new name."); } elseif ($_REQUEST['act'] == 'duplicate') { $m['typefail'] = t("!old was not duplicated to !new (type not allowed).", array('!old' => $old, '!new' => $new)); $m['writefail'] = t("!old could not be duplicated (write failed).", array('!old' => $old)); $m['destfail'] = t("File could not be duplicated to !new since it already exists.", array('!new' => $new)); $m['emptyfail'] = t("File could not be duplicated since you didn't specify a new name."); } elseif ($_REQUEST['act'] == 'symlink') { $m['typefail'] = t("Could not create symlink to !old (type not allowed).", array('!old' => $old, '!new' => $new)); $m['writefail'] = t("Could not create symlink to !old (write failed).", array('!old' => $old)); $m['destfail'] = t("Could not create symlink !new since it already exists.", array('!new' => $new)); $m['emptyfail'] = t("Symlink could not be created since you didn't specify a name."); } if (!empty($old) && !empty($new)) { if (ft_check_filetype($new) && ft_check_file($new)) { // Make sure destination file doesn't exist. if (!file_exists(ft_get_dir()."/".$new)) { // Check that file exists. if (is_writeable(ft_get_dir()."/".$old)) { if ($_REQUEST['act'] == "rename") { if (@rename(ft_get_dir()."/".$old, ft_get_dir()."/".$new)) { // Success. ft_set_message(t("!old was renamed to !new", array('!old' => $old, '!new' => $new))); ft_redirect("dir={$_REQUEST['dir']}"); } else { // Error rename failed. ft_set_message(t("!old could not be renamed.", array('!old' => $old)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } elseif ($_REQUEST['act'] == 'symlink') { if (ADVANCEDACTIONS == TRUE) { if (@symlink(realpath(ft_get_dir()."/".$old), ft_get_dir()."/".$new)) { @chmod(ft_get_dir()."/{$new}", PERMISSION); // Success. ft_set_message(t("Created symlink !new", array('!old' => $old, '!new' => $new))); ft_redirect("dir={$_REQUEST['dir']}"); } else { // Error symlink failed. ft_set_message(t("Symlink to !old could not be created.", array('!old' => $old)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } } else { if (@copy(ft_get_dir()."/".$old, ft_get_dir()."/".$new)) { // Success. ft_set_message(t("!old was duplicated to !new", array('!old' => $old, '!new' => $new))); ft_redirect("dir={$_REQUEST['dir']}"); } else { // Error rename failed. ft_set_message(t("!old could not be duplicated.", array('!old' => $old)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } } else { // Error old file isn't writeable. ft_set_message($m['writefail'], 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error destination exists. ft_set_message($m['destfail'], 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error file type not allowed. ft_set_message($m['typefail'], 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { // Error. File name not set. ft_set_message($m['emptyfail'], 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } # upload } elseif ($_REQUEST['act'] == "upload" && ft_check_upload() === TRUE && (LIMIT <= 0 || LIMIT > ROOTDIRSIZE)) { // If we are to upload a file we will do so. $msglist = 0; foreach ($_FILES as $k => $c) { if (!empty($c['name'])) { $c['name'] = ft_stripslashes($c['name']); if ($c['error'] == 0) { // Upload was successfull if (ft_check_filetype($c['name']) && ft_check_file($c['name'])) { if (file_exists(ft_get_dir()."/{$c['name']}")) { $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("File already exists"), 'error'); } else { if (@move_uploaded_file($c['tmp_name'], ft_get_dir()."/{$c['name']}")) { @chmod(ft_get_dir()."/{$c['name']}", PERMISSION); // Success! $msglist++; ft_set_message(t('!file was uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20)))); ft_invoke_hook('upload', ft_get_dir(), $c['name']); } else { // File couldn't be moved. Throw error. $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("File couldn't be moved"), 'error'); } } } else { // File type is not allowed. Throw error. $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("File type not allowed"), 'error'); } } else { // An error occurred. switch($_FILES["localfile"]["error"]) { case 1: $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("The file was too large"), 'error'); break; case 2: $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("The file was larger than MAXSIZE setting."), 'error'); break; case 3: $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("Partial upload. Try again"), 'error'); break; case 4: $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("No file was uploaded. Please try again"), 'error'); break; default: $msglist++; ft_set_message(t('!file was not uploaded.', array('!file' => ft_get_nice_filename($c['name'], 20))) . ' ' . t("Unknown error"), 'error'); break; } } } } if ($msglist > 0) { ft_redirect("dir=".$_REQUEST['dir']); } else { ft_set_message(t("Upload failed."), 'error'); ft_redirect("dir=".$_REQUEST['dir']); } # Unzip } elseif ($_REQUEST['act'] == "unzip" && ft_check_fileactions() === TRUE) { // Check that file is set. $file = ft_stripslashes($_REQUEST['file']); if (!empty($file) && ft_check_file($file) && ft_check_filetype($file) && strtolower(ft_get_ext($file)) == 'zip' && is_file(ft_get_dir()."/".$file)) { $escapeddir = escapeshellarg(ft_get_dir()."/"); $escapedfile = escapeshellarg(ft_get_dir()."/".$file); if (!@exec("unzip -n ".$escapedfile." -d ".$escapeddir)) { ft_set_message(t("!old could not be unzipped.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } else { ft_set_message(t("!old unzipped.", array('!old' => $file))); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_set_message(t("!old could not be unzipped.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } # chmod } elseif ($_REQUEST['act'] == "chmod" && ft_check_fileactions() === TRUE && ADVANCEDACTIONS == TRUE) { // Check that file is set. $file = ft_stripslashes($_REQUEST['file']); if (!empty($file) && ft_check_file($file) && ft_check_filetype($file)) { // Check that chosen permission i valid if (is_numeric($_REQUEST['newvalue'])) { $chmod = $_REQUEST['newvalue']; if (substr($chmod, 0, 1) == '0') { $chmod = substr($chmod, 0, 4); } else { $chmod = '0'.substr($chmod, 0, 3); } // Chmod if (@chmod(ft_get_dir()."/".$file, intval($chmod, 8))) { ft_set_message(t("Permissions changed for !old.", array('!old' => $file))); ft_redirect("dir={$_REQUEST['dir']}"); clearstatcache(); } else { ft_set_message(t("Could not change permissions for !old.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_set_message(t("Could not change permissions for !old.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_set_message(t("Could not change permissions for !old.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } # logout } elseif ($_REQUEST['act'] == "logout") { ft_invoke_hook('logout', $_SESSION['ft_user_'.MUTEX]); $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); // Delete persistent cookie setcookie('ft_user_'.MUTEX, '', time()-3600); ft_redirect(); } } } /** * Convert PHP ini shorthand notation for file size to byte size. * * @return Size in bytes. */ function ft_get_bytes($val) { $val = trim($val); $last = strtolower($val{strlen($val)-1}); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } /** * Get the total disk space consumed by files available to the current user. * Files and directories on blacklists are not counted. * * @param $dirname * Name of the directory to scan. * @return Space consumed by this directory in bytes (not counting files and directories on blacklists). */ function ft_get_dirsize($dirname) { if (!is_dir($dirname) || !is_readable($dirname)) { return false; } $dirname_stack[] = $dirname; $size = 0; do { $dirname = array_shift($dirname_stack); $handle = opendir($dirname); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_readable($dirname . '/' . $file)) { if (is_dir($dirname . '/' . $file)) { if (ft_check_dir($dirname . '/' . $file)) { $dirname_stack[] = $dirname . '/' . $file; } } else { if (ft_check_file($file) && ft_check_filetype($file)) { $size += filesize($dirname . '/' . $file); } } } } closedir($handle); } while (count($dirname_stack) > 0); return $size; } /** * Get the current directory. * * @return The current directory. */ function ft_get_dir() { if (empty($_REQUEST['dir'])) { return ft_get_root(); } else { return ft_get_root().$_REQUEST['dir']; } } /** * Get file extension from a file name. * * @param $name * File name. * @return The file extension without the '.' */ function ft_get_ext($name) { if (strstr($name, ".")) { $ext = str_replace(".", "", strrchr($name, ".")); } else { $ext = ""; } return $ext; } /** * Get a list of files in a directory with metadata. * * @param $dir * The directory to scan. * @param $sort * Sorting parameter. Possible values: name, type, size, date. Defaults to 'name'. * @return An array of files. Each item is an array: * array( * 'name' => '', // File name. * 'shortname' => '', // File name. * 'type' => '', // 'file' or 'dir'. * 'ext' => '', // File extension. * 'writeable' => '', // TRUE if writeable. * 'perms' => '', // Permissions. * 'modified' => '', // Last modified. Unix timestamp. * 'size' => '', // File size in bytes. * 'extras' => '' // Array of extra classes for this file. * ) */ function ft_get_filelist($dir, $sort = 'name') { $filelist = array(); $subdirs = array(); if (ft_check_dir($dir) && $dirlink = @opendir($dir)) { // Creates an array with all file names in current directory. while (($file = readdir($dirlink)) !== false) { if ($file != "." && $file != ".." && ((!is_dir("{$dir}/{$file}") && ft_check_file($file) && ft_check_filetype($file)) || is_dir("{$dir}/{$file}") && ft_check_dir("{$dir}/{$file}"))) { // Hide these two special cases and files and filetypes in blacklists. $c = array(); $c['name'] = $file; // $c['shortname'] = ft_get_nice_filename($file, 20); $c['shortname'] = $file; $c['type'] = "file"; $c['ext'] = ft_get_ext($file); $c['writeable'] = is_writeable("{$dir}/{$file}"); // Grab extra options from plugins. $c['extras'] = array(); $c['extras'] = ft_invoke_hook('fileextras', $file, $dir); // File permissions. if ($c['perms'] = @fileperms("{$dir}/{$file}")) { if (is_dir("{$dir}/{$file}")) { $c['perms'] = substr(base_convert($c['perms'], 10, 8), 2); } else { $c['perms'] = substr(base_convert($c['perms'], 10, 8), 3); } } $c['modified'] = @filemtime("{$dir}/{$file}"); $c['size'] = @filesize("{$dir}/{$file}"); if (ft_check_dir("{$dir}/{$file}") && is_dir("{$dir}/{$file}")) { $c['size'] = 0; $c['type'] = "dir"; if ($sublink = @opendir("{$dir}/{$file}")) { while (($current = readdir($sublink)) !== false) { if ($current != "." && $current != ".." && ft_check_file($current)) { $c['size']++; } } closedir($sublink); } $subdirs[] = $c; } else { $filelist[] = $c; } } } closedir($dirlink); // sort($filelist); // Obtain a list of columns $ext = array(); $name = array(); $date = array(); $size = array(); foreach ($filelist as $key => $row) { $ext[$key] = strtolower($row['ext']); $name[$key] = strtolower($row['name']); $date[$key] = $row['modified']; $size[$key] = $row['size']; } if ($sort == 'type') { // Sort by file type and then name. array_multisort($ext, SORT_ASC, $name, SORT_ASC, $filelist); } elseif ($sort == 'size') { // Sort by filesize date and then name. array_multisort($size, SORT_ASC, $name, SORT_ASC, $filelist); } elseif ($sort == 'date') { // Sort by last modified date and then name. array_multisort($date, SORT_DESC, $name, SORT_ASC, $filelist); } else { // Sort by file name. array_multisort($name, SORT_ASC, $filelist); } // Always sort dirs by name. sort($subdirs); return array_merge($subdirs, $filelist); } else { return "dirfail"; } } /** * Determine the max. size for uploaded files. * * @return Human-readable string of upload limit. */ function ft_get_max_upload() { $post_max = ft_get_bytes(ini_get('post_max_size')); $upload = ft_get_bytes(ini_get('upload_max_filesize')); // Compare ini settings. $max = (($post_max > $upload) ? $upload : $post_max); // Compare with MAXSIZE. if ($max > MAXSIZE) { $max = MAXSIZE; } return ft_get_nice_filesize($max); } /** * Shorten a file name to a given length maintaining the file extension. * * @param $name * File name. * @param $limit * The maximum length of the file name. * @return The shortened file name. */ function ft_get_nice_filename($name, $limit = -1) { if ($limit > 0) { $noext = $name; if (strstr($name, '.')) { $noext = substr($name, 0, strrpos($name, '.')); } $ext = ft_get_ext($name); if (strlen($noext)-3 > $limit) { $name = substr($noext, 0, $limit).'...'; if ($ext != '') { $name = $name. '.' .$ext; } } } return $name; } /** * Convert a number of bytes to a human-readable format. * * @param $size * Integer. File size in bytes. * @return String. Human-readable file size. */ function ft_get_nice_filesize($size) { if (empty($size)) { return "—"; } elseif (strlen($size) > 6) { // Convert to megabyte return round($size/(1024*1024), 2)." MB"; } elseif (strlen($size) > 4 || $size > 1024) { // Convert to kilobyte return round($size/1024, 0)." Kb"; } else { return $size." b"; } } /** * Get the root directory. * * @return The root directory. */ function ft_get_root() { return DIR; } /** * Get the name of the File Thingie file. Used in
Grow lights
Dietary supplements
Construction Machinery
Hydraulic Hose
wigs
Tarps
Hydraulic power units
Hotel lock
Pearl rings
Energy saving lamps
Energy saving lamp
Energy saving bulbs
Energy saving bulb
Nails
Nail Art
Uv Lamp
Ray Ban sunglasses
Ray Ban
christmas wreath
Interactive whiteboard
Electronic whiteboard
GPS tracker
OTR Tire
Air hose
Mold
Fire hoses
Wig
DVD Ripper
