1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-10 10:04:01 +02:00

new builds for standalone and library

This commit is contained in:
Marco Dickert
2017-07-06 16:07:41 +02:00
parent ca505fe4c7
commit d7c6427a38
3 changed files with 2959 additions and 188 deletions

1
build/ifm.js Normal file
View File

@@ -0,0 +1 @@
src/ifm.js

2831
build/ifmlib.php Normal file

File diff suppressed because one or more lines are too long

315
ifm.php
View File

@@ -1,174 +1,6 @@
<?php
/* =======================================================================
* Improved File Manager
* ---------------------
* License: This project is provided under the terms of the MIT LICENSE
* http://github.com/misterunknown/ifm/blob/master/LICENSE
* =======================================================================
*
* config
*/
class IFMConfig {
// 0 = no/not allowed;; 1 = yes/allowed;; default: no/forbidden;
// action controls
const upload = 1; // allow uploads
const remoteupload = 1; // allow remote uploads using cURL
const delete = 1; // allow deletions
const rename = 1; // allow renamings
const edit = 1; // allow editing
const chmod = 1; // allow to change rights
const extract = 1; // allow extracting zip archives
const download = 1; // allow to download files and skripts (even php scripts!)
const selfdownload = 1; // allow to download this skript itself
const createdir = 1; // allow to create directorys
const createfile = 1; // allow to create files
const zipnload = 1; // allow to zip and download directorys
const copymove = 1; // allow to copy and move files and directories
// view controls
const showlastmodified = 0; // show the last modified date?
const showfilesize = 1; // show filesize?
const showowner = 1; // show file owner?
const showgroup = 1; // show file group?
const showpermissions = 2; // show permissions 0 -> 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:
<username>:<passwordhash>
LDAP auth syntax
const auth_source = 'ldap;<ldap_sever_host>;<rootdn>';
The script will add "uid=<username>," to the rootdn for binding. If your ldap server
does not use uid for usernames you can change it in the function checkCredentials.
examples:
const auth_source = 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC';
const auth_source = 'file;/path/to/file';
const auth_source = 'ldap;<ldap_sever_host>;<rootdn>';
*/
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
const debug = true;
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 {
/**
* 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;
}
}
}
namespace IFM;
/* =======================================================================
* Improved File Manager
@@ -183,16 +15,42 @@ class IFMZip {
error_reporting( E_ALL );
ini_set( 'display_errors', 'OFF' );
class IFM {
const VERSION = '2.4.0';
private $defaultconfig = array(
"upload" => 1,"remoteupload" => 1,"delete" => 1,"rename" => 1,"edit" => 1,"chmod" => 1,
"extract" => 1,"download" => 1,"selfdownload" => 1,"createdir" => 1,"createfile" => 1,
"zipnload" => 1,"copymove" => 1,"showlastmodified" => 0,"showfilesize" => 1,"showowner" => 1,
"showgroup" => 1,"showpermissions" => 2,"showhtdocs" => 1,"showhiddenfiles" => 1,"showpath" => 0,
"auth" => 0,"auth_source" => 'inlineadmin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC',
"root_dir" => "","defaulttimezone" => "Europe/Berlin","tmp_dir" => "","ajaxrequest" => 1
// 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();
@@ -557,7 +415,7 @@ function IFM( params ) {
} else {
item.download.action = "download";
item.download.icon = "icon icon-download";
if( item.icon.indexOf( 'file-image' ) !== -1 )
if( item.icon.indexOf( 'file-image' ) !== -1 && self.config.isDocroot )
item.tooltip = 'data-toggle="tooltip" title="<img src=\'' + self.pathCombine( self.currentDir, item.name ) + '\' class=\'imgpreview\'>"';
if( item.name.toLowerCase().substr(-4) == ".zip" )
item.eaction = "extract";
@@ -1313,6 +1171,8 @@ function IFM( params ) {
/**
* Prevents a user to submit a form via clicking enter
*
* @param object e - click event
*/
this.preventEnter = function(e) {
if( e.keyCode == 13 ) return false;
@@ -1576,11 +1436,20 @@ function IFM( params ) {
}
break;
case ' ': // todo: make it work only when noting other is focused
if( $(':focus').is( '.clickable-row td:first-child a:first-child' ) ) {
e.preventDefault();
var item = $('.highlightedItem');
if( item.is( 'tr' ) )
item.toggleClass( 'selectedItem' );
case 'Enter':
if( $(':focus').is( '.clickable-row td:first-child a:first-child' ) ) {
var trParent = $(':focus').parent().parent();
if( e.key == 'Enter' && trParent.hasClass( 'isDir' ) ) {
e.preventDefault();
e.stopPropagation();
self.changeDirectory( trParent.data( 'filename' ) );
} else if( e.key == ' ' && ! trParent.is( ':first-child' ) ) {
e.preventDefault();
e.stopPropagation();
var item = $('.highlightedItem');
if( item.is( 'tr' ) )
item.toggleClass( 'selectedItem' );
}
}
break;
}
@@ -1750,7 +1619,7 @@ ifm.init( "ifm" );
else
chdir( realpath( $this->config['root_dir'] ) );
$this->mode = $mode;
if ( isset($_REQUEST['api']) ) {
if ( isset($_REQUEST['api']) || $mode == "api" ) {
$this->handleRequest();
} elseif( $mode == "standalone" ) {
$this->getApplication();
@@ -1830,7 +1699,7 @@ ifm.init( "ifm" );
private function getConfig() {
$ret = $this->config;
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
$ret['isDocroot'] = ( realpath( IFMConfig::root_dir ) == dirname( __FILE__ ) ) ? "true" : "false";
$ret['isDocroot'] = ( realpath( $this->config['root_dir'] ) == dirname( __FILE__ ) ) ? "true" : "false";
echo json_encode( $ret );
}
@@ -2886,8 +2755,78 @@ f00bar;
}
}
/**
* start IFM
*/
$ifm = new IFM( IFMConfig::getConstants() );
$ifm->run();
/* =======================================================================
* 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;
}
}
}
/** * start IFM */$ifm = new IFM();$ifm->run();