+ * @version 1.0.1
+ * @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/
+ * @param string $source Source path
+ * @param string $dest Destination path
+ * @return bool Returns TRUE on success, FALSE on failure
+ */
+ private function copyr( $source, $dest )
+ {
+ // Check for symlinks
+ if (is_link($source)) {
+ return symlink(readlink($source), $dest);
+ }
+
+ // Simple copy for a file
+ if (is_file($source)) {
+ $dest = ( is_dir( $dest ) ) ? $this->pathCombine( $dest, basename( $source ) ) : $dest;
+ return copy($source, $dest);
+ } else {
+ $dest = $this->pathCombine( $dest, basename( $source ) );
+ }
+
+ // Make destination directory
+ if (!is_dir($dest)) {
+ mkdir($dest);
+ }
+
+ // Loop through the folder
+ $dir = dir($source);
+ while (false !== $entry = $dir->read()) {
+ // Skip pointers
+ if ($entry == '.' || $entry == '..') {
+ continue;
+ }
+
+ // Deep copy directories
+ $this->copyr("$source/$entry", "$dest/$entry");
+ }
+
+ // Clean up
+ $dir->close();
+ return true;
+ }
+
+ // combines two parts to a valid path
+ private function pathCombine( $a, $b ) {
+ if( trim( $a ) == "" && trim( $b ) == "" )
+ return "";
+ elseif( trim( $a ) == "" )
+ return ltrim( $b, '/' );
+ else
+ return rtrim( $a, '/' ) . '/' . ltrim( $b, '/' );
+ }
+
+ // check if filename is allowed
+ private function allowedFileName( $f ) {
+ if( $this->config['showhtdocs'] != 1 && substr( $f, 0, 3 ) == ".ht" )
+ return false;
+ elseif( $this->config['showhiddenfiles'] != 1 && substr( $f, 0, 1 ) == "." )
+ return false;
+ elseif( ! $this->isPathValid( $f ) )
+ return false;
+ return true;
+ }
+
+ // sorting function for file and dir arrays
+ private function sortByName( $a, $b ) {
+ if( strtolower( $a['name'] ) == strtolower( $b['name'] ) ) return 0;
+ return ( strtolower( $a['name'] ) < strtolower( $b['name'] ) ) ? -1 : 1;
+ }
+
+ // is cURL extention avaliable?
+ private function checkCurl() {
+ if( !function_exists( "curl_init" ) ||
+ !function_exists( "curl_setopt" ) ||
+ !function_exists( "curl_exec" ) ||
+ !function_exists( "curl_close" ) ) return false;
+ else return true;
+ }
+
+ private function fileDownload( $file, $name="" ) {
+ header( 'Content-Description: File Transfer' );
+ header( 'Content-Type: application/octet-stream' );
+ header( 'Content-Disposition: attachment; filename="' . ( trim( $name ) == "" ? basename( $file ) : $name ) . '"' );
+ header( 'Expires: 0' );
+ header( 'Cache-Control: must-revalidate' );
+ header( 'Pragma: public' );
+ header( 'Content-Length: ' . filesize( $file ) );
+
+ $file_stream = fopen( $file, 'rb' );
+ $stdout_stream = fopen('php://output', 'wb');
+
+ stream_copy_to_stream($file_stream, $stdout_stream);
+
+ fclose($file_stream);
+ fclose($stdout_stream);
+ }
+
+ private function getTemplates() {
+ $templates = array();
+ $templates['app'] = <<<'f00bar'
+
+
+
+
+
+ Filename |
+ {{#config.download}}
+ |
+ {{/config.download}}
+ {{#config.showlastmodified}}
+ last modified |
+ {{/config.showlastmodified}}
+ {{#config.showfilesize}}
+ size |
+ {{/config.showfilesize}}
+ {{#config.showpermissions}}
+ permissions |
+ {{/config.showpermissions}}
+ {{#config.showowner}}
+ owner |
+ {{/config.showowner}}
+ {{#config.showgroup}}
+ group |
+ {{/config.showgroup}}
+ |
+
+
+
+
+
+
+
+
+
+
+f00bar;
+ $templates['filetable'] = <<<'f00bar'
+
+{{#items}}
+
+
+
+
+ {{linkname}}
+
+ |
+ {{#config.download}}
+
+
+
+
+
+ |
+ {{/config.download}}
+ {{#config.showlastmodified}}
+ {{lastmodified}} |
+ {{/config.showlastmodified}}
+ {{#config.showfilesize}}
+ {{size}} |
+ {{/config.showfilesize}}
+ {{#config.showpermissions}}
+
+
+ |
+ {{/config.showpermissions}}
+ {{#config.showowner}}
+
+ {{owner}}
+ |
+ {{/config.showowner}}
+ {{#config.showgroup}}
+
+ {{group}}
+ |
+ {{/config.showgroup}}
+
+ {{#button}}
+
+
+
+ {{/button}}
+ |
+
+{{/items}}
+
+
+f00bar;
+ $templates['file'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['createdir'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['ajaxrequest'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['createdir'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['deletefile'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['extractfile'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['file'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['multidelete'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['remoteupload'] = <<<'f00bar'
+
+
+f00bar;
+ $templates['renamefile'] = <<<'f00bar'
+
+
+
+
+f00bar;
+ $templates['uploadfile'] = <<<'f00bar'
+
+
+f00bar;
+
+ return $templates;
+ }
+}
+
+/* =======================================================================
+ * Improved File Manager
+ * ---------------------
+ * License: This project is provided under the terms of the MIT LICENSE
+ * http://github.com/misterunknown/ifm/blob/master/LICENSE
+ * =======================================================================
+ *
+ * zip class
+ *
+ * this was adapted from http://php.net/manual/de/class.ziparchive.php#110719
+*/
+
+class IFMZip {
+ /**
+ * Add a folder to the zip file
+ */
+ private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
+ $handle = opendir( $folder );
+ while( false !== $f = readdir( $handle ) ) {
+ if( $f != '.' && $f != '..' ) {
+ $filePath = "$folder/$f";
+ if( file_exists( $filePath ) && is_readable( $filePath ) ) {
+ // Remove prefix from file path before add to zip.
+ $localPath = substr($filePath, $exclusiveLength);
+ if( is_file( $filePath ) ) {
+ $zipFile->addFile( $filePath, $localPath );
+ } elseif( is_dir( $filePath ) ) {
+ // Add sub-directory.
+ $zipFile->addEmptyDir( $localPath );
+ self::folderToZip( $filePath, $zipFile, $exclusiveLength );
+ }
+ }
+ }
+ }
+ closedir( $handle );
+ }
+
+ /**
+ * Create a zip file
+ */
+ public static function create( $src, $out, $root=false )
+ {
+ $z = new ZipArchive();
+ $z->open( $out, ZIPARCHIVE::CREATE);
+ if( $root ) {
+ self::folderToZip( realpath( $src ), $z, strlen( realpath( $src ) . '/' ) );
+ } else {
+ $z->addEmptyDir( basename( $src ) );
+ self::folderToZip( realpath( $src ), $z, strlen( dirname( $src ) . '/' ) );
+ }
+ try {
+ if( ( $res = $z->close() ) !== true ) {
+ throw new Exception("Error while creating zip archive: ". $z->getStatusString());
+ }
+ } catch ( Exception $e ) {
+ throw $e;
+ }
+ }
+
+ /**
+ * Unzip a zip file
+ */
+ public static function extract( $file, $destination="./" ) {
+ $zip = new ZipArchive;
+ $res = $zip->open( $file );
+ if( $res === true ) {
+ $zip->extractTo( $destination );
+ $zip->close();
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/compiler.php b/compiler.php
index f6d471a..8192409 100755
--- a/compiler.php
+++ b/compiler.php
@@ -1,32 +1,56 @@
#!/usr/bin/env php
run();'
+), FILE_APPEND );
+
+/**
+ * Build library
+ */
+file_put_contents( $IFM_BUILD_LIB_PHP, $main );
+file_put_contents( $IFM_BUILD_LIB_PHP, $phpincludes, FILE_APPEND );
diff --git a/ifm.php b/ifm.php
index 4fe3dca..901b55e 100644
--- a/ifm.php
+++ b/ifm.php
@@ -1,157 +1,5 @@
not; 1 -> octal, 2 -> human readable
- const showhtdocs = 1; // show .htaccess and .htpasswd
- const showhiddenfiles = 1; // show files beginning with a dot (e.g. ".bashrc")
- const showpath = 0; // show absolute path
-
- /*
- authentication
-
- This provides a super simple authentication functionality. At the moment only one user can be
- configured. The credential information can be either set inline or read from a file. The
- password has to be a hash generated by PHPs password_hash function. The default credentials are
- admin:admin.
-
- If you specify a file it should only contain one line, with the credentials in the following
- format:
- :
-
- examples:
- const auth_source = 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC';
- const auth_source = 'file;/path/to/file';
- */
- const auth = 0;
- const auth_source = 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC';
-
- /*
- root_dir - set a custom root directory instead of the script location
-
- This option is highly experimental and should only be set if you definitely know what you do.
- Settings this option may cause black holes or other unwanted things. Use with special care.
-
- default setting:
- const root_dir = "";
- */
- const root_dir = "";
- const defaulttimezone = "Europe/Berlin"; // set default timezone
-
- /**
- * Temp directory for zip files
- *
- * Default is the upload_tmp_dir which is set in the php.ini, but you may also set an different path
- */
- const tmp_dir = "";
-
- // development tools
- const ajaxrequest = 1; // formular to perform an ajax request
-
- static function getConstants() {
- $oClass = new ReflectionClass(__CLASS__);
- return $oClass->getConstants();
- }
-}
-
-/* =======================================================================
- * Improved File Manager
- * ---------------------
- * License: This project is provided under the terms of the MIT LICENSE
- * http://github.com/misterunknown/ifm/blob/master/LICENSE
- * =======================================================================
- *
- * zip class
- *
- * this was adapted from http://php.net/manual/de/class.ziparchive.php#110719
-*/
-
-class IFMZip {
- private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
- $handle = opendir( $folder );
- while( false !== $f = readdir( $handle ) ) {
- if( $f != '.' && $f != '..' ) {
- $filePath = "$folder/$f";
- if( file_exists( $filePath ) && is_readable( $filePath ) ) {
- // Remove prefix from file path before add to zip.
- $localPath = substr($filePath, $exclusiveLength);
- if( is_file( $filePath ) ) {
- $zipFile->addFile( $filePath, $localPath );
- } elseif( is_dir( $filePath ) ) {
- // Add sub-directory.
- $zipFile->addEmptyDir( $localPath );
- self::folderToZip( $filePath, $zipFile, $exclusiveLength );
- }
- }
- }
- }
- closedir( $handle );
- }
-
- public static function create_zip( $src, $out, $root=false )
- {
- $z = new ZipArchive();
- $z->open( $out, ZIPARCHIVE::CREATE);
- if( $root ) {
- self::folderToZip( realpath( $src ), $z, strlen( realpath( $src ) . '/' ) );
- } else {
- $z->addEmptyDir( basename( $src ) );
- self::folderToZip( realpath( $src ), $z, strlen( dirname( $src ) . '/' ) );
- }
- try {
- if( ( $res = $z->close() ) !== true ) {
- throw new Exception("Error while creating zip archive: ". $z->getStatusString());
- }
- } catch ( Exception $e ) {
- throw $e;
- }
- }
-
- public static function unzip_file( $file ) {
- $zip = new ZipArchive();
- $res = $zip->open( $file );
- if( $res === true ) {
- $zip->extractTo( './' );
- $zip->close();
- return true;
- } else {
- return false;
- }
- }
-}
-
/* =======================================================================
* Improved File Manager
* ---------------------
@@ -165,17 +13,56 @@ class IFMZip {
error_reporting( E_ALL );
ini_set( 'display_errors', 'OFF' );
-class IFM {
- const VERSION = '2.3.1';
- public function __construct() {
- session_start();
+class IFM {
+ const VERSION = '2.4.0';
+
+ private $defaultconfig = array(
+ // general config
+ "auth" => 0,
+ "auth_source" => 'inlineadmin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC',
+ "root_dir" => "",
+ "tmp_dir" => "",
+ "defaulttimezone" => "Europe/Berlin",
+
+ // api controls
+ "ajaxrequest" => 1,
+ "chmod" => 1,
+ "copymove" => 1,
+ "createdir" => 1,
+ "createfile" => 1,
+ "edit" => 1,
+ "delete" => 1,
+ "download" => 1,
+ "extract" => 1,
+ "upload" => 1,
+ "remoteupload" => 1,
+ "rename" => 1,
+ "zipnload" => 1,
+
+ // gui controls
+ "showlastmodified" => 0,
+ "showfilesize" => 1,
+ "showowner" => 1,
+ "showgroup" => 1,
+ "showpermissions" => 2,
+ "showhtdocs" => 1,
+ "showhiddenfiles" => 1,
+ "showpath" => 0,
+ );
+
+ private $config = array();
+ public $mode = "";
+
+ public function __construct( $config=array() ) {
+ if( session_status() !== PHP_SESSION_ACTIVE )
+ session_start();
+ $this->config = array_merge( $this->defaultconfig, $config );
}
- /*
- this function contains the client-side application
+ /**
+ * This function contains the client-side application
*/
-
public function getApplication() {
print '
@@ -183,16 +70,35 @@ class IFM {
IFM - improved file manager
-
-
-
-
-
-
-
-
-
-
-
-
- Filename | ';
- if( IFMConfig::download == 1 ) print ' | ';
- if( IFMConfig::showlastmodified == 1 ) print 'last modified | ';
- if( IFMConfig::showfilesize == 1 ) print 'size | ';
- if( IFMConfig::showpermissions > 0 ) print 'permissions | ';
- if( IFMConfig::showowner == 1 && function_exists( "posix_getpwuid" ) ) print 'owner | ';
- if( IFMConfig::showgroup == 1 && function_exists( "posix_getgrgid" ) ) print 'group | ';
- if( in_array( 1, array( IFMConfig::edit, IFMConfig::rename, IFMConfig::delete, IFMConfig::zipnload, IFMConfig::extract ) ) ) print ' | ';
- print '
-
-
-
-
-
-
-
-
+ ';
+ }
+
+ public function getJS() {
+ print '
-
-
+
+
-
-