1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-09 09:36:29 +02:00

Merge pull request #70 from misterunknown/js-rewrite

Js rewrite
This commit is contained in:
Marco Dickert
2017-08-06 23:24:39 +02:00
committed by GitHub
28 changed files with 3638 additions and 2608 deletions

View File

@@ -89,6 +89,8 @@ listed below:
| `root_dir` | `IFM_ROOT_DIR` |
| `tmp_dir` | `IFM_TMP_DIR` |
| `defaulttimezone` | `IFM_DEFAULTTIMEZONE` |
| `forbiddenchars` | `IFM_FORBIDDENCHARS` |
| `language` | `IFM_LANGUAGE` |
| `ajaxrequest` | `IFM_API_AJAXREQUEST` |
| `chmod` | `IFM_API_CHMOD` |
| `copymove` | `IFM_API_COPYMOVE` |
@@ -110,6 +112,7 @@ listed below:
| `showhtdocs` | `IFM_GUI_SHOWHTDOCS` |
| `showhiddenfiles` | `IFM_GUI_SHOWHIDDENFILES` |
| `showpath` | `IFM_GUI_SHOWPATH` |
| `contextmenu` | `IFM_GUI_CONTEXTMENU` |
## screenshots
<a href="https://misterunknown.de/static/ifm_screenshot_desktop_filelist.png"><img src="https://misterunknown.de/static/ifm_screenshot_desktop_filelist.png" height="300px"></a>

File diff suppressed because one or more lines are too long

2078
ifm.php

File diff suppressed because one or more lines are too long

55
src/i18n/de.json Normal file
View File

@@ -0,0 +1,55 @@
{
"ajax_request": "AJAX Request",
"cancel": "Abbrechen",
"close": "Schließen",
"copy": "Kopieren",
"data": "Daten",
"delete": "Löschen",
"directoryname": "Ordner Name",
"editor_options": "Editor Optionen",
"extract": "Auspacken",
"extract_filename": "Folgende Datei auspacken -",
"file_delete_confirm": "Soll die folgende Datei wirklich gelöscht werden -",
"file_edit_success": "Datei erfolgreich geändert / angelegt.",
"file_multi_delete_confirm": "Sollen diese Dateien wirklich gelöscht werden -",
"file_new": "Neue Datei",
"file_save_confirm": "Soll diese Datei wirklich gelöscht werden -",
"filename": "Dateiname",
"filename_new": "Neuer Dateiname",
"folder_new": "Neue Ordner",
"footer": "IFM - verbesserter file manager | ifm.php versteckt |",
"github": "Besuche das Projekt auf GitHub",
"group": "Gruppe",
"last_modified": "Zuletzt geändert",
"login": "Anmeldung",
"logout": "Abmelden",
"method": "Methode",
"move": "Verschieben",
"options": "Optionen",
"owner": "Besitzer",
"password": "Passwort",
"path_content": "Inhalt von",
"permissions": "Berechtigungen",
"refresh": "Auffrischen",
"rename": "Umbenennen",
"rename_filename": "Folgende Datei umbenennen -",
"request": "Anfrage",
"response": "Antwort",
"save": "Speichen",
"save_wo_close": "Speichen ohne Schließen",
"search": "Suchen",
"search_pattern": "Muster",
"select_destination": "Zielort auswählen",
"size": "Größe",
"soft_tabs": "Leichte Tabulatoren",
"tab_size": "Tabulatoren Größe",
"tasks": "Aufgaben",
"toggle_nav": "Navigation umschalten",
"upload": "Hochladen",
"upload_drop": "Dateien zum hochladen hier hinziehen",
"upload_file": "Datei hochladen",
"upload_remote": "Hochladen von ausserhalb",
"upload_remote_url": "Entfernte URL zum hochladen",
"username": "Benutzername",
"word_wrap": "Zeilenumbruch"
}

54
src/i18n/en.json Normal file
View File

@@ -0,0 +1,54 @@
{
"ajax_request": "AJAX Request",
"cancel": "Cancel",
"close": "Close",
"copy": "Copy",
"data": "Data",
"delete": "Delete",
"directoryname": "Directory Name",
"editor_options": "Editor Options",
"extract": "Extract",
"extract_filename": "Extract file - ",
"file_delete_confirm": "Do you really want to delete the following file -",
"file_edit_success": "File successfully edited / created.",
"file_multi_delete_confirm": "Do you really want to delete these files -",
"file_new": "New File",
"file_save_confirm": "Do you want to save the following file -",
"filename": "Filename",
"filename_new": "New Filename",
"folder_new": "New Folder",
"footer": "IFM - improved file manager | ifm.php hidden |",
"github": "Visit the project on GitHub",
"group": "Group",
"last_modified": "Last Modified",
"login": "Login",
"logout": "Log Off",
"method": "Method",
"move": "Move",
"options": "Options",
"owner": "Owner",
"password": "Password",
"path_content": "Content of",
"permissions": "Permissions",
"refresh": "Refresh",
"rename": "Rename",
"rename_filename": "Rename file -",
"request": "Request",
"response": "Response",
"save": "Save",
"save_wo_close": "Save w/o Close",
"search_pattern": "Pattern",
"select_destination": "Select Destination",
"size": "Size",
"soft_tabs": "Soft Tabs",
"tab_size": "Tab Size",
"tasks": "Tasks",
"toggle_nav": "Toggle navigation",
"upload": "Upload",
"upload_drop": "Drop files to upload",
"upload_file": "Upload File",
"upload_remote": "Remote Upload",
"upload_remote_url": "Remote Upload URL",
"username": "username",
"word_wrap": "Word Wrap"
}

1340
src/ifm.js

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1,85 @@
.animate-spin{-moz-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;-webkit-animation:spin 2s infinite linear;animation:spin 2s infinite linear;display:inline-block}@-moz-keyframes spin{0%{-moz-transform:rotate(0);-o-transform:rotate(0);-webkit-transform:rotate(0);transform:rotate(0)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-moz-transform:rotate(0);-o-transform:rotate(0);-webkit-transform:rotate(0);transform:rotate(0)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-o-keyframes spin{0%{-moz-transform:rotate(0);-o-transform:rotate(0);-webkit-transform:rotate(0);transform:rotate(0)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-ms-keyframes spin{0%{-moz-transform:rotate(0);-o-transform:rotate(0);-webkit-transform:rotate(0);transform:rotate(0)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes spin{0%{-moz-transform:rotate(0);-o-transform:rotate(0);-webkit-transform:rotate(0);transform:rotate(0)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}
/*
Animation example, for spinners
*/
.animate-spin {
-moz-animation: spin 2s infinite linear;
-o-animation: spin 2s infinite linear;
-webkit-animation: spin 2s infinite linear;
animation: spin 2s infinite linear;
display: inline-block;
}
@-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@-webkit-keyframes spin {
0% {
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@-o-keyframes spin {
0% {
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@-ms-keyframes spin {
0% {
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@keyframes spin {
0% {
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(359deg);
-o-transform: rotate(359deg);
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -24,6 +24,7 @@ class IFM {
"tmp_dir" => "",
"defaulttimezone" => "Europe/Berlin",
"forbiddenChars" => array(),
"language" => "en",
// api controls
"ajaxrequest" => 1,
@@ -54,6 +55,7 @@ class IFM {
private $config = array();
private $templates = array();
private $i18n = array();
public $mode = "";
public function __construct( $config=array() ) {
@@ -64,33 +66,35 @@ class IFM {
$this->config = $this->defaultconfig;
// load config from environment variables
$this->config['auth'] = getenv('IFM_AUTH') !== false ? getenv('IFM_AUTH') : $this->config['auth'] ;
$this->config['auth'] = getenv('IFM_AUTH') !== false ? intval( getenv('IFM_AUTH') ) : $this->config['auth'] ;
$this->config['auth_source'] = getenv('IFM_AUTH_SOURCE') !== false ? getenv('IFM_AUTH_SOURCE') : $this->config['auth_source'] ;
$this->config['root_dir'] = getenv('IFM_ROOT_DIR') !== false ? getenv('IFM_ROOT_DIR') : $this->config['root_dir'] ;
$this->config['tmp_dir'] = getenv('IFM_TMP_DIR') !== false ? getenv('IFM_TMP_DIR') : $this->config['tmp_dir'] ;
$this->config['defaulttimezone'] = getenv('IFM_DEFAULTTIMEZONE') !== false ? getenv('IFM_DEFAULTTIMEZONE') : $this->config['defaulttimezone'] ;
$this->config['forbiddenChars'] = getenv('IFM_FORBIDDENCHARS') !== false ? str_split( getenv('IFM_FORBIDDENCHARS') ) : $this->config['forbiddenChars'] ;
$this->config['ajaxrequest'] = getenv('IFM_API_AJAXREQUEST') !== false ? getenv('IFM_API_AJAXREQUEST') : $this->config['ajaxrequest'] ;
$this->config['chmod'] = getenv('IFM_API_CHMOD') !== false ? getenv('IFM_API_CHMOD') : $this->config['chmod'] ;
$this->config['copymove'] = getenv('IFM_API_COPYMOVE') !== false ? getenv('IFM_API_COPYMOVE') : $this->config['copymove'] ;
$this->config['createdir'] = getenv('IFM_API_CREATEDIR') !== false ? getenv('IFM_API_CREATEDIR') : $this->config['createdir'] ;
$this->config['createfile'] = getenv('IFM_API_CREATEFILE') !== false ? getenv('IFM_API_CREATEFILE') : $this->config['createfile'] ;
$this->config['edit'] = getenv('IFM_API_EDIT') !== false ? getenv('IFM_API_EDIT') : $this->config['edit'] ;
$this->config['delete'] = getenv('IFM_API_DELETE') !== false ? getenv('IFM_API_DELETE') : $this->config['delete'] ;
$this->config['download'] = getenv('IFM_API_DOWNLOAD') !== false ? getenv('IFM_API_DOWNLOAD') : $this->config['download'] ;
$this->config['extract'] = getenv('IFM_API_EXTRACT') !== false ? getenv('IFM_API_EXTRACT') : $this->config['extract'] ;
$this->config['upload'] = getenv('IFM_API_UPLOAD') !== false ? getenv('IFM_API_UPLOAD') : $this->config['upload'] ;
$this->config['remoteupload'] = getenv('IFM_API_REMOTEUPLOAD') !== false ? getenv('IFM_API_REMOTEUPLOAD') : $this->config['remoteupload'] ;
$this->config['rename'] = getenv('IFM_API_RENAME') !== false ? getenv('IFM_API_RENAME') : $this->config['rename'] ;
$this->config['zipnload'] = getenv('IFM_API_ZIPNLOAD') !== false ? getenv('IFM_API_ZIPNLOAD') : $this->config['zipnload'] ;
$this->config['showlastmodified'] = getenv('IFM_GUI_SHOWLASTMODIFIED') !== false ? getenv('IFM_GUI_SHOWLASTMODIFIED') : $this->config['showlastmodified'] ;
$this->config['showfilesize'] = getenv('IFM_GUI_SHOWFILESIZE') !== false ? getenv('IFM_GUI_SHOWFILESIZE') : $this->config['showfilesize'] ;
$this->config['showowner'] = getenv('IFM_GUI_SHOWOWNER') !== false ? getenv('IFM_GUI_SHOWOWNER') : $this->config['showowner'] ;
$this->config['showgroup'] = getenv('IFM_GUI_SHOWGROUP') !== false ? getenv('IFM_GUI_SHOWGROUP') : $this->config['showgroup'] ;
$this->config['showpermissions'] = getenv('IFM_GUI_SHOWPERMISSIONS') !== false ? getenv('IFM_GUI_SHOWPERMISSIONS') : $this->config['showpermissions'] ;
$this->config['showhtdocs'] = getenv('IFM_GUI_SHOWHTDOCS') !== false ? getenv('IFM_GUI_SHOWHTDOCS') : $this->config['showhtdocs'] ;
$this->config['showhiddenfiles'] = getenv('IFM_GUI_SHOWHIDDENFILES') !== false ? getenv('IFM_GUI_SHOWHIDDENFILES') : $this->config['showhiddenfiles'] ;
$this->config['showpath'] = getenv('IFM_GUI_SHOWPATH') !== false ? getenv('IFM_GUI_SHOWPATH') : $this->config['showpath'] ;
$this->config['language'] = getenv('IFM_LANGUAGE') !== false ? getenv('IFM_LANGUAGE') : $this->config['language'] ;
$this->config['ajaxrequest'] = getenv('IFM_API_AJAXREQUEST') !== false ? intval( getenv('IFM_API_AJAXREQUEST') ) : $this->config['ajaxrequest'] ;
$this->config['chmod'] = getenv('IFM_API_CHMOD') !== false ? intval( getenv('IFM_API_CHMOD') ) : $this->config['chmod'] ;
$this->config['copymove'] = getenv('IFM_API_COPYMOVE') !== false ? intval( getenv('IFM_API_COPYMOVE') ) : $this->config['copymove'] ;
$this->config['createdir'] = getenv('IFM_API_CREATEDIR') !== false ? intval( getenv('IFM_API_CREATEDIR') ) : $this->config['createdir'] ;
$this->config['createfile'] = getenv('IFM_API_CREATEFILE') !== false ? intval( getenv('IFM_API_CREATEFILE') ) : $this->config['createfile'] ;
$this->config['edit'] = getenv('IFM_API_EDIT') !== false ? intval( getenv('IFM_API_EDIT') ) : $this->config['edit'] ;
$this->config['delete'] = getenv('IFM_API_DELETE') !== false ? intval( getenv('IFM_API_DELETE') ) : $this->config['delete'] ;
$this->config['download'] = getenv('IFM_API_DOWNLOAD') !== false ? intval( getenv('IFM_API_DOWNLOAD') ) : $this->config['download'] ;
$this->config['extract'] = getenv('IFM_API_EXTRACT') !== false ? intval( getenv('IFM_API_EXTRACT') ) : $this->config['extract'] ;
$this->config['upload'] = getenv('IFM_API_UPLOAD') !== false ? intval( getenv('IFM_API_UPLOAD') ) : $this->config['upload'] ;
$this->config['remoteupload'] = getenv('IFM_API_REMOTEUPLOAD') !== false ? intval( getenv('IFM_API_REMOTEUPLOAD') ) : $this->config['remoteupload'] ;
$this->config['rename'] = getenv('IFM_API_RENAME') !== false ? intval( getenv('IFM_API_RENAME') ) : $this->config['rename'] ;
$this->config['zipnload'] = getenv('IFM_API_ZIPNLOAD') !== false ? intval( getenv('IFM_API_ZIPNLOAD') ) : $this->config['zipnload'] ;
$this->config['showlastmodified'] = getenv('IFM_GUI_SHOWLASTMODIFIED') !== false ? intval( getenv('IFM_GUI_SHOWLASTMODIFIED') ) : $this->config['showlastmodified'] ;
$this->config['showfilesize'] = getenv('IFM_GUI_SHOWFILESIZE') !== false ? intval( getenv('IFM_GUI_SHOWFILESIZE') ) : $this->config['showfilesize'] ;
$this->config['showowner'] = getenv('IFM_GUI_SHOWOWNER') !== false ? intval( getenv('IFM_GUI_SHOWOWNER') ) : $this->config['showowner'] ;
$this->config['showgroup'] = getenv('IFM_GUI_SHOWGROUP') !== false ? intval( getenv('IFM_GUI_SHOWGROUP') ) : $this->config['showgroup'] ;
$this->config['showpermissions'] = getenv('IFM_GUI_SHOWPERMISSIONS') !== false ? intval( getenv('IFM_GUI_SHOWPERMISSIONS') ) : $this->config['showpermissions'] ;
$this->config['showhtdocs'] = getenv('IFM_GUI_SHOWHTDOCS') !== false ? intval( getenv('IFM_GUI_SHOWHTDOCS') ) : $this->config['showhtdocs'] ;
$this->config['showhiddenfiles'] = getenv('IFM_GUI_SHOWHIDDENFILES') !== false ? intval( getenv('IFM_GUI_SHOWHIDDENFILES') ) : $this->config['showhiddenfiles'] ;
$this->config['showpath'] = getenv('IFM_GUI_SHOWPATH') !== false ? intval( getenv('IFM_GUI_SHOWPATH') ) : $this->config['showpath'] ;
$this->config['contextmenu'] = getenv('IFM_GUI_CONTEXTMENU') !== false ? intval( getenv('IFM_GUI_CONTEXTMENU') ) : $this->config['contextmenu'] ;
// load config from passed array
$this->config = array_merge( $this->config, $config );
@@ -129,8 +133,8 @@ f00bar;
$templates['file'] = <<<'f00bar'
@@@file:src/templates/modal.file.html@@@
f00bar;
$templates['multidelete'] = <<<'f00bar'
@@@file:src/templates/modal.multidelete.html@@@
$templates['file_editoroptions'] = <<<'f00bar'
@@@file:src/templates/modal.file_editoroptions.html@@@
f00bar;
$templates['remoteupload'] = <<<'f00bar'
@@@file:src/templates/modal.remoteupload.html@@@
@@ -148,6 +152,17 @@ f00bar;
@@@file:src/templates/modal.uploadfile.html@@@
f00bar;
$this->templates = $templates;
$i18n = array();
$i18n['en'] = <<<'f00bar'
@@@file:src/i18n/en.json@@@
f00bar;
$i18n['en'] = json_decode($i18n['en'], true);
$i18n['de'] = <<<'f00bar'
@@@file:src/i18n/de.json@@@
f00bar;
$i18n['de'] = json_decode($i18n['de'], true);
$this->i18n = $i18n;
}
/**
@@ -213,9 +228,9 @@ f00bar;
private function handleRequest() {
if( $_REQUEST["api"] == "getRealpath" ) {
if( isset( $_REQUEST["dir"] ) && $_REQUEST["dir"] != "" )
echo json_encode( array( "realpath" => $this->getValidDir( $_REQUEST["dir"] ) ) );
echo $this->jsonResponse( array( "realpath" => $this->getValidDir( $_REQUEST["dir"] ) ) );
else
echo json_encode( array( "realpath" => "" ) );
echo $this->jsonResponse( array( "realpath" => "" ) );
}
elseif( $_REQUEST["api"] == "getFiles" ) {
if( isset( $_REQUEST["dir"] ) && $this->isPathValid( $_REQUEST["dir"] ) )
@@ -229,7 +244,9 @@ f00bar;
elseif( $_REQUEST["api"] == "getFolders" ) {
$this->getFolders( $_REQUEST );
} elseif( $_REQUEST["api"] == "getTemplates" ) {
echo json_encode( $this->templates );
echo $this->jsonResponse( $this->templates );
} elseif( $_REQUEST["api"] == "getI18N" ) {
echo $this->jsonResponse( $this->i18n[$this->config['language']] );
} elseif( $_REQUEST["api"] == "logout" ) {
unset( $_SESSION );
session_destroy();
@@ -241,7 +258,7 @@ f00bar;
case "createDir": $this->createDir( $_REQUEST["dir"], $_REQUEST["dirname"] ); break;
case "saveFile": $this->saveFile( $_REQUEST ); break;
case "getContent": $this->getContent( $_REQUEST ); break;
case "delete": $this->deleteFile( $_REQUEST ); break;
case "delete": $this->deleteFiles( $_REQUEST ); break;
case "rename": $this->renameFile( $_REQUEST ); break;
case "download": $this->downloadFile( $_REQUEST ); break;
case "extract": $this->extractFile( $_REQUEST ); break;
@@ -250,15 +267,15 @@ f00bar;
case "changePermissions": $this->changePermissions( $_REQUEST ); break;
case "zipnload": $this->zipnload( $_REQUEST); break;
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
case "searchItems": $this->searchItems( $_REQUEST ); break;
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
case "createArchive": $this->createArchive( $_REQUEST ); break;
default:
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
break;
}
} else {
print json_encode( array( "status" => "ERROR", "message" => "Invalid working directory" ) );
print $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid working directory" ) );
}
}
exit( 0 );
@@ -363,8 +380,8 @@ f00bar;
private function getConfig() {
$ret = $this->config;
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
$ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? "true" : "false";
echo json_encode( $ret );
$ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? true : false;
echo $this->jsonResponse( $ret );
}
private function getFolders( $d ) {
@@ -387,12 +404,12 @@ f00bar;
array(
0 => array(
"text" => "/ [root]",
"dataAttributes" => array( "path" => $this->getRootDir() )
"dataAttr" => array( "path" => $this->getRootDir() )
)
),
$ret
);
echo json_encode( $ret );
echo $this->jsonResponse( $ret );
}
}
@@ -404,9 +421,9 @@ f00bar;
}
try {
$results = $this->searchItemsRecursive( $d['pattern'] );
echo json_encode( $results );
echo $this->jsonResponse( $results );
} catch( Exception $e ) {
echo json_encode( array( "status" => "ERROR", "message" => $e->getMessage() ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => $e->getMessage() ) );
}
}
@@ -423,7 +440,7 @@ f00bar;
}
private function getFolderTree( $d ) {
echo json_encode(
echo $this->jsonResponse(
array_merge(
array(
0 => array(
@@ -462,38 +479,38 @@ f00bar;
private function copyMove( $d ) {
if( $this->config['copymove'] != 1 ) {
echo json_encode( array( "status" => "ERROR", "message" => "No permission to copy or move files." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to copy or move files." ) );
exit( 1 );
}
$this->chDirIfNecessary( $d['dir'] );
if( ! isset( $d['destination'] ) || ! $this->isPathValid( realpath( $d['destination'] ) ) ) {
echo json_encode( array( "status" => "ERROR", "message" => "Invalid destination directory given." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid destination directory given." ) );
exit( 1 );
}
if( ! file_exists( $d['filename'] ) || $d['filename'] == ".." ) {
echo json_encode( array( "status" => "ERROR", "message" => "Invalid filename given." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid filename given." ) );
exit( 1 );
}
if( $d['action'] == "copy" ) {
if( $this->copyr( $d['filename'], $d['destination'] ) ) {
echo json_encode( array( "status" => "OK", "message" => "File(s) were successfully copied." ) );
if( $this->xcopy( $d['filename'], $d['destination'] ) ) {
echo $this->jsonResponse( array( "status" => "OK", "message" => "File(s) were successfully copied." ) );
exit( 0 );
} else {
$err = error_get_last();
echo json_encode( array( "status" => "ERROR", "message" => $err['message'] ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => $err['message'] ) );
exit( 1 );
}
} elseif( $d['action'] == "move" ) {
if( rename( $d['filename'], $this->pathCombine( $d['destination'], basename( $d['filename'] ) ) ) ) {
echo json_encode( array( "status" => "OK", "message" => "File(s) were successfully moved." ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "File(s) were successfully moved." ) );
exit( 0 );
} else {
$err = error_get_last();
echo json_encode( array( "status" => "ERROR", "message" => $err['message'] ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => $err['message'] ) );
exit( 1 );
}
} else {
echo json_encode( array( "status" => "ERROR", "message" => "Invalid action given." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid action given." ) );
exit( 1 );
}
}
@@ -501,26 +518,26 @@ f00bar;
// creates a directory
private function createDir($w, $dn) {
if( $this->config['createdir'] != 1 ) {
echo json_encode( array( "status" => "ERROR", "message" => "No permission to create directories.") );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to create directories.") );
exit( 1 );
}
if( $dn == "" )
echo json_encode( array( "status" => "ERROR", "message" => "Invalid directory name") );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid directory name") );
elseif( ! $this->isFilenameValid( $dn ) )
echo json_encode( array( "status" => "ERROR", "message" => "Invalid directory name" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid directory name" ) );
else {
$this->chDirIfNecessary( $w );
if( @mkdir( $dn ) )
echo json_encode( array( "status" => "OK", "message" => "Directory successful created" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "Directory successful created" ) );
else
echo json_encode( array( "status" => "ERROR", "message" => "Could not create directory" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Could not create directory" ) );
}
}
// save a file
private function saveFile( $d ) {
if( ( file_exists( $this->pathCombine( $d['dir'], $d['filename'] ) ) && $this->config['edit'] != 1 ) || ( ! file_exists( $this->pathCombine( $d['dir'], $d['filename'] ) ) && $this->config['createfile'] != 1 ) ) {
echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit/create this file." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "You are not allowed to edit/create this file." ) );
exit( 1 );
}
if( isset( $d['filename'] ) && $this->isFilenameValid( $d['filename'] ) ) {
@@ -529,63 +546,40 @@ f00bar;
// work around magic quotes
$content = get_magic_quotes_gpc() == 1 ? stripslashes( $d['content'] ) : $d['content'];
if( @file_put_contents( $d['filename'], $content ) !== false ) {
echo json_encode( array( "status" => "OK", "message" => "File successfully saved" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "File successfully saved" ) );
} else
echo json_encode( array( "status" => "ERROR", "message" => "Could not write content" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Could not write content" ) );
} else
echo json_encode( array( "status" => "ERROR", "message" => "Got no content" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Got no content" ) );
} else
echo json_encode( array( "status" => "ERROR", "message" => "Invalid filename given" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid filename given" ) );
}
// gets the content of a file
// notice: if the content is not JSON encodable it returns an error
private function getContent( array $d ) {
if( $this->config['edit'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
else {
$this->chDirIfNecessary( $d['dir'] );
if( isset( $d['filename'] ) && $this->isFilenameAllowed( $d['filename'] ) && file_exists( $d['filename'] ) && is_readable( $d['filename'] ) ) {
$content = @file_get_contents( $d['filename'] );
if( function_exists( "mb_check_encoding" ) && ! mb_check_encoding( $content, "UTF-8" ) )
$content = utf8_encode( $content );
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found or not readable." ) );
}
}
// deletes a file or a directory (recursive!)
private function deleteFile( array $d ) {
if( $this->config['delete'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to delete files" ) );
elseif( ! $this->isFilenameAllowed( $d['filename'] ) )
echo json_encode( array( "status" => "ERROR", "message" => "Invalid filename given" ) );
else {
$this->chDirIfNecessary( $d['dir'] );
if( is_dir( $d['filename'] ) ) {
$res = $this->rec_rmdir( $d['filename'] );
if( $res != 0 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to delete files" ) );
else
echo json_encode( array( "status" => "OK", "message" => "Directoy successful deleted" ) );
} else {
if( @unlink( $d['filename'] ) )
echo json_encode( array( "status" => "OK", "message" => "File successful deleted" ) );
else
echo json_encode( array( "status"=>"ERROR", "message" => "File could not be deleted" ) );
}
echo $this->jsonResponse( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
} else echo $this->jsonResponse( array( "status" => "ERROR", "message" => "File not found or not readable." ) );
}
}
// deletes a bunch of files or directories
private function deleteMultipleFiles( array $d ) {
if( $this->config['delete'] != 1 ) echo json_encode( array( "status" => "ERROR", "message" => "No permission to delete files" ) );
private function deleteFiles( array $d ) {
if( $this->config['delete'] != 1 ) $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to delete files" ) );
else {
$this->chDirIfNecessary( $d['dir'] );
$err = array(); $errFLAG = -1; // -1 -> no files deleted; 0 -> at least some files deleted; 1 -> all files deleted
foreach( $d['filenames'] as $file ) {
if( $this->isFilenameAllowed( $file ) ) {
if( is_dir($file) ) {
if( is_dir( $file ) ) {
$res = $this->rec_rmdir( $file );
if( $res != 0 )
array_push( $err, $file );
@@ -602,14 +596,14 @@ f00bar;
}
}
if( empty( $err ) ) {
echo json_encode( array( "status" => "OK", "message" => "Files deleted successfully", "errflag" => "1" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "Files deleted successfully", "errflag" => "1" ) );
}
else {
$errmsg = "The following files could not be deleted:<ul>";
foreach($err as $item)
$errmsg .= "<li>".$item."</li>";
$errmsg .= "</ul>";
echo json_encode( array( "status" => "OK", "message" => $errmsg, "flag" => $errFLAG ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => $errmsg, "flag" => $errFLAG ) );
}
}
}
@@ -617,22 +611,22 @@ f00bar;
// renames a file
private function renameFile( array $d ) {
if( $this->config['rename'] != 1 ) {
echo json_encode( array( "status" => "ERROR", "message" => "No permission to rename files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to rename files" ) );
} elseif( ! $this->isFilenameValid( $d['filename'] ) ) {
echo json_encode( array( "status" => "ERROR", "message" => "Invalid file name given" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid file name given" ) );
} else {
$this->chDirIfNecessary( $d['dir'] );
if( strpos( $d['newname'], '/' ) !== false )
echo json_encode( array( "status" => "ERROR", "message" => "No slashes allowed in filenames" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No slashes allowed in filenames" ) );
elseif( $this->config['showhtdocs'] != 1 && ( substr( $d['newname'], 0, 3) == ".ht" || substr( $d['filename'], 0, 3 ) == ".ht" ) )
echo json_encode( array( "status" => "ERROR", "message" => "Not allowed to rename this file" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Not allowed to rename this file" ) );
elseif( $this->config['showhiddenfiles'] != 1 && ( substr( $d['newname'], 0, 1) == "." || substr( $d['filename'], 0, 1 ) == "." ) )
echo json_encode( array( "status" => "ERROR", "message" => "Not allowed to rename file" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Not allowed to rename file" ) );
else {
if( @rename( $d['filename'], $d['newname'] ) )
echo json_encode( array( "status" => "OK", "message" => "File successful renamed" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "File successful renamed" ) );
else
echo json_encode( array( "status" => "ERROR", "message" => "File could not be renamed" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "File could not be renamed" ) );
}
}
}
@@ -640,11 +634,11 @@ f00bar;
// provides a file for downloading
private function downloadFile( array $d ) {
if( $this->config['download'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "Not allowed to download files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Not allowed to download files" ) );
elseif( $this->config['showhtdocs'] != 1 && ( substr( $d['filename'], 0, 3 ) == ".ht" || substr( $d['filename'],0,3 ) == ".ht" ) )
echo json_encode( array( "status" => "ERROR", "message"=>"Not allowed to download htdocs" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message"=>"Not allowed to download htdocs" ) );
elseif( $this->config['showhiddenfiles'] != 1 && ( substr( $d['filename'], 0, 1 ) == "." || substr( $d['filename'],0,1 ) == "." ) )
echo json_encode( array( "status" => "ERROR", "message" => "Not allowed to download hidden files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Not allowed to download hidden files" ) );
else {
$this->chDirIfNecessary( $d["dir"] );
$this->fileDownload( $d['filename'] );
@@ -654,34 +648,34 @@ f00bar;
// extracts a zip-archive
private function extractFile( array $d ) {
if( $this->config['extract'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to extract files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to extract files" ) );
else {
$this->chDirIfNecessary( $d['dir'] );
if( ! file_exists( $d['filename'] ) ) {
echo json_encode( array( "status" => "ERROR","message" => "No valid archive found" ) );
echo $this->jsonResponse( array( "status" => "ERROR","message" => "No valid archive found" ) );
exit( 1 );
}
if( ! isset( $d['targetdir'] ) || trim( $d['targetdir'] ) == "" )
$d['targetdir'] = "./";
if( ! $this->isPathValid( $d['targetdir'] ) ) {
echo json_encode( array( "status" => "ERROR","message" => "Target directory is not valid." ) );
echo $this->jsonResponse( array( "status" => "ERROR","message" => "Target directory is not valid." ) );
exit( 1 );
}
if( ! is_dir( $d['targetdir'] ) && ! mkdir( $d['targetdir'], 0777, true ) ) {
echo json_encode( array( "status" => "ERROR","message" => "Could not create target directory." ) );
echo $this->jsonResponse( array( "status" => "ERROR","message" => "Could not create target directory." ) );
exit( 1 );
}
if( substr( strtolower( $d['filename'] ), -4 ) == ".zip" ) {
if( ! IFMArchive::extractZip( $d['filename'], $d['targetdir'] ) ) {
echo json_encode( array( "status" => "ERROR","message" => "File could not be extracted" ) );
echo $this->jsonResponse( array( "status" => "ERROR","message" => "File could not be extracted" ) );
} else {
echo json_encode( array( "status" => "OK","message" => "File successfully extracted." ) );
echo $this->jsonResponse( array( "status" => "OK","message" => "File successfully extracted." ) );
}
} else {
if( ! IFMArchive::extractTar( $d['filename'], $d['targetdir'] ) ) {
echo json_encode( array( "status" => "ERROR","message" => "File could not be extracted" ) );
echo $this->jsonResponse( array( "status" => "ERROR","message" => "File could not be extracted" ) );
} else {
echo json_encode( array( "status" => "OK","message" => "File successfully extracted." ) );
echo $this->jsonResponse( array( "status" => "OK","message" => "File successfully extracted." ) );
}
}
}
@@ -690,35 +684,35 @@ f00bar;
// uploads a file
private function uploadFile( array $d ) {
if( $this->config['upload'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to upload files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to upload files" ) );
elseif( !isset( $_FILES['file'] ) )
echo json_encode( array( "file" => $_FILE,"files" => $_FILES ) );
echo $this->jsonResponse( array( "file" => $_FILE,"files" => $_FILES ) );
else {
$this->chDirIfNecessary( $d['dir'] );
$newfilename = ( isset( $d["newfilename"] ) && $d["newfilename"]!="" ) ? $d["newfilename"] : $_FILES['file']['name'];
if( ! $this->isFilenameValid( $newfilename ) )
echo json_encode( array( "status" => "ERROR", "message" => "Invalid filename given" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid filename given" ) );
else {
if( $_FILES['file']['tmp_name'] ) {
if( is_writable( getcwd( ) ) ) {
if( move_uploaded_file( $_FILES['file']['tmp_name'], $newfilename ) )
echo json_encode( array( "status" => "OK", "message" => "The file ".$_FILES['file']['name']." was uploaded successfully", "cd" => $d['dir'] ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "The file ".$_FILES['file']['name']." was uploaded successfully", "cd" => $d['dir'] ) );
else
echo json_encode( array( "status" => "ERROR", "message" => "File could not be uploaded" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "File could not be uploaded" ) );
}
else
echo json_encode( array( "status" => "ERROR", "message" => "File could not be uploaded since it has no permissions to write in this directory" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "File could not be uploaded since it has no permissions to write in this directory" ) );
} else
echo json_encode( array( "status" => "ERROR", "message" => "No file found" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No file found" ) );
}
}
}
// change permissions of a file
private function changePermissions( array $d ) {
if( $this->config['chmod'] != 1 ) echo json_encode( array( "status" => "ERROR", "message" => "No rights to change permissions" ) );
elseif( ! isset( $d["chmod"] )||$d['chmod']=="" ) echo json_encode( array( "status" => "ERROR", "message" => "Could not identify new permissions" ) );
elseif( ! $this->isPathValid( $this->pathCombine( $d['dir'],$d['filename'] ) ) ) { echo json_encode( array( "status" => "ERROR", "message" => "Not allowed to change the permissions" ) ); }
if( $this->config['chmod'] != 1 ) echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No rights to change permissions" ) );
elseif( ! isset( $d["chmod"] )||$d['chmod']=="" ) echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Could not identify new permissions" ) );
elseif( ! $this->isPathValid( $this->pathCombine( $d['dir'],$d['filename'] ) ) ) { echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Not allowed to change the permissions" ) ); }
else {
$this->chDirIfNecessary( $d['dir'] ); $chmod = $d["chmod"]; $cmi = true;
if( ! is_numeric( $chmod ) ) {
@@ -743,12 +737,12 @@ f00bar;
if( $cmi ) {
try {
chmod( $d["filename"], (int)octdec( $chmod ) );
echo json_encode( array( "status" => "OK", "message" => "Permissions changed successfully" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "Permissions changed successfully" ) );
} catch ( Exception $e ) {
echo json_encode( array( "status" => "ERROR", "message" => "Error while changing permissions" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Error while changing permissions" ) );
}
}
else echo json_encode( array( "status" => "ERROR", "message" => "Could not determine permission format" ) );
else echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Could not determine permission format" ) );
}
}
@@ -756,13 +750,13 @@ f00bar;
// it creates a temporary zip file in the current directory, so it has to be as much space free as the file size is
private function zipnload( array $d ) {
if( $this->config['zipnload'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to download directories" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to download directories" ) );
else {
$this->chDirIfNecessary( $d['dir'] );
if( ! file_exists( $d['filename'] ) )
echo json_encode( array( "status" => "ERROR", "message" => "Directory not found" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Directory not found" ) );
elseif ( ! $this->isFilenameValid( $d['filename'] ) )
echo json_encode( array( "status" => "ERROR", "message" => "Filename not valid" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Filename not valid" ) );
else {
unset( $zip );
$dfile = $this->pathCombine( $this->config['tmp_dir'], uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename
@@ -787,54 +781,65 @@ f00bar;
// uploads a file from an other server using the curl extention
private function remoteUpload( array $d ) {
if( $this->config['remoteupload'] != 1 )
echo json_encode( array( "status" => "ERROR", "message" => "No permission to remote upload files" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to remote upload files" ) );
elseif( !isset( $d['method'] ) || !in_array( $d['method'], array( "curl", "file" ) ) )
echo json_encode( array( "status" => "error", "message" => "Invalid method given. Valid methods: ['curl', 'file']" ) );
echo $this->jsonResponse( array( "status" => "error", "message" => "Invalid method given. Valid methods: ['curl', 'file']" ) );
elseif( $d['method']=="curl" && $this->checkCurl( ) == false )
echo json_encode( array( "status" => "ERROR", "message" => "cURL extention not installed. Please install the cURL extention to use remote file upload." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "cURL extention not installed. Please install the cURL extention to use remote file upload." ) );
elseif( $d['method']=="curl" && $this->checkCurl( ) == true ) {
$filename = ( isset( $d['filename'] )&&$d['filename']!="" )?$d['filename']:"curl_".uniqid( );
$this->chDirIfNecessary( $d['dir'] );
$ch = curl_init( );
if( $ch ) {
if( $this->isFilenameValid( $filename ) == false )
echo json_encode( array( "status" => "ERROR", "message" => "This filename is not valid." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "This filename is not valid." ) );
elseif( filter_var( $d['url'], FILTER_VALIDATE_URL ) === false )
echo json_encode( array( "status" => "ERROR", "message" => "The passed URL is not valid" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "The passed URL is not valid" ) );
else {
$fp = fopen( $filename, "w" );
if( $fp ) {
if( !curl_setopt( $ch, CURLOPT_URL, $d['url'] ) || !curl_setopt( $ch, CURLOPT_FILE, $fp ) || !curl_setopt( $ch, CURLOPT_HEADER, 0 ) || !curl_exec( $ch ) )
echo json_encode( array( "status" => "ERROR", "message" => "Failed to set options and execute cURL" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Failed to set options and execute cURL" ) );
else {
echo json_encode( array( "status" => "OK", "message" => "File sucessfully uploaded" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "File sucessfully uploaded" ) );
}
curl_close( $ch );
fclose( $fp );
} else {
echo json_encode( array( "status" => "ERROR", "message" => "Failed to open file" ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Failed to open file" ) );
}
}
} else {
echo json_encode( array( "status" => "ERROR", "message" => "Failed to init cURL." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "Failed to init cURL." ) );
}
}
elseif( $d['method']=='file' ) {
$filename = ( isset( $d['filename'] ) && $d['filename']!="" ) ? $d['filename'] : "curl_".uniqid( );
if( $this->isFilenameValid( $filename ) == false )
echo json_encode( array( "status" => "ERROR", "message" => "This filename is not valid." ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => "This filename is not valid." ) );
else {
$this->chDirIfNecessary( $d['dir'] );
try {
file_put_contents( $filename, file_get_contents( $d['url'] ) );
echo json_encode( array( "status" => "OK", "message" => "File successfully uploaded" ) );
echo $this->jsonResponse( array( "status" => "OK", "message" => "File successfully uploaded" ) );
} catch( Exception $e ) {
echo json_encode( array( "status" => "ERROR", "message" => $e->getMessage() ) );
echo $this->jsonResponse( array( "status" => "ERROR", "message" => $e->getMessage() ) );
}
}
}
else
echo json_encode( array( "status" => "error", "message" => "Corrupt parameter data" ) );
echo $this->jsonResponse( array( "status" => "error", "message" => "Corrupt parameter data" ) );
}
private function createArchive( $d ) {
// if( $config['createarchive'] != 1 ) {
// echo $this->jsonResponse( array( "status" => "ERROR", "message" => "No permission to create archives" ) );
// return false;
// }
// $this->chDirIfNecessary( $d['dir'] );
// switch( $d['format'] ) {
// case "zip":
//
}
/*
@@ -842,7 +847,7 @@ f00bar;
*/
private function log( $d ) {
file_put_contents( $this->pathCombine( $this->getRootDir(), "debug.ifm.log" ), ( is_array( $d ) ? print_r( $d, true ) : $d ), FILE_APPEND );
file_put_contents( $this->pathCombine( $this->getRootDir(), "debug.ifm.log" ), ( is_array( $d ) ? print_r( $d, true ) . "\n" : $d . "\n" ), FILE_APPEND );
}
private function jsonResponse( $array ) {
@@ -908,9 +913,9 @@ f00bar;
} else {
if( isset( $_POST["api"] ) ) {
if( $login_failed === true )
echo json_encode( array( "status"=>"ERROR", "message"=>"authentication failed" ) );
echo $this->jsonResponse( array( "status"=>"ERROR", "message"=>"authentication failed" ) );
else
echo json_encode( array( "status"=>"ERROR", "message"=>"not authenticated" ) );
echo $this->jsonResponse( array( "status"=>"ERROR", "message"=>"not authenticated" ) );
} else {
$this->loginForm($login_failed);
}
@@ -929,10 +934,13 @@ f00bar;
return password_verify( $pass, trim( $hash ) ) ? ( $uname == $user ) : false;
break;
case "file":
$this->log( "srcopt: $srcopt" );
if( @file_exists( $srcopt ) && @is_readable( $srcopt ) ) {
$this->log( "file exists" );
$htpasswd = new Htpasswd( $srcopt );
return $htpasswd->verify( $user, $pass );
} else {
trigger_error( "IFM: Fatal: Credential file does not exist or is not readable" );
return false;
}
break;
@@ -968,7 +976,11 @@ f00bar;
if( $loginFailed )
$err = '<div class="alert alert-danger">Login failed.</div>';
$this->getHTMLHeader();
print str_replace( "{{error}}", $err, $this->templates['login'] );
$html = str_replace( "{{error}}", $err, $this->templates['login'] );
$html = str_replace( "{{i18n.username}}", $this->i18n[$this->config['language']]['username'], $html );
$html = str_replace( "{{i18n.password}}", $this->i18n[$this->config['language']]['password'], $html );
$html = str_replace( "{{i18n.login}}", $this->i18n[$this->config['language']]['login'], $html );
print $html;
$this->getHTMLFooter();
}
@@ -1096,50 +1108,19 @@ f00bar;
return 0;
}
/**
* Copy a file, or recursively copy a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @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 {
private function xcopy( $source, $dest ) {
$isDir = is_dir( $source );
if( $isDir )
$dest = $this->pathCombine( $dest, basename( $source ) );
}
if( ! is_dir( $dest ) )
mkdir($dest, 0777, true);
if( is_file( $source ) )
return copy( $source, $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();
chdir( $source );
foreach( glob( '*' ) as $item )
$this->xcopy( $item, $dest );
chdir( '..' );
return true;
}

View File

@@ -21,6 +21,7 @@ body {
}
a { cursor: pointer !important; }
a.ifmitem:focus { outline: 0 }
img.imgpreview { max-width: 100%; }

View File

@@ -7,7 +7,7 @@
<div class="navbar-header">
<a class="navbar-brand">IFM</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="sr-only">{{i18n.toggle_nav}}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@@ -17,32 +17,33 @@
<form class="navbar-form navbar-left">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="currentDirLabel">Content of <span id="docroot">{{showpath}}</span></span>
<span class="input-group-addon" id="currentDirLabel">{{i18n.path_content}} <span id="docroot">{{showpath}}</span></span>
<input class="form-control" id="currentDir" aria-describedby="currentDirLabel" type="text">
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a id="refresh"><span title="refresh" class="icon icon-arrows-cw"></span> <span class="visible-xs">refresh</span></a></li>
<li><a id="refresh"><span title="{{i18n.refresh}}" class="icon icon-arrows-cw"></span> <span class="visible-xs">{{i18n.refresh}}</span></a></li>
<li><a id="search"><span title="{{i18n.search}}" class="icon icon-search"></span> <span class="visible-xs">{{i18n.search}}</span></a></li>
{{#config.upload}}
<li><a id="upload"><span title="upload" class="icon icon-upload"></span> <span class="visible-xs">upload</span></a></li>
<li><a id="upload"><span title="{{i18n.upload}}" class="icon icon-upload"></span> <span class="visible-xs">{{i18n.upload}}</span></a></li>
{{/config.upload}}
{{#config.createfile}}
<li><a id="createFile"><span title="new file" class="icon icon-doc-inv"></span> <span class="visible-xs">new file</span></a></li>
<li><a id="createFile"><span title="{{i18n.file_new}}" class="icon icon-doc-inv"></span> <span class="visible-xs">{{i18n.file_new}}</span></a></li>
{{/config.createfile}}
{{#config.createdir}}
<li><a id="createDir"><span title="new folder" class="icon icon-folder"></span> <span class="visible-xs">new folder</span></a></li>
<li><a id="createDir"><span title="{{i18n.folder_new}}" class="icon icon-folder"></span> <span class="visible-xs">{{i18n.folder_new}}</span></a></li>
{{/config.createdir}}
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="icon icon-down-open"></span></a>
<ul class="dropdown-menu" role="menu">
{{#config.remoteupload}}
<li><a id="buttonRemoteUpload"><span class="icon icon-upload-cloud"></span> remote upload</a></li>
<li><a id="buttonRemoteUpload"><span class="icon icon-upload-cloud"></span> {{i18n.upload_remote}}</a></li>
{{/config.remoteupload}}
{{#config.ajaxrequest}}
<li><a id="buttonAjaxRequest"><span class="icon icon-link-ext"></span> ajax request</a></li>
<li><a id="buttonAjaxRequest"><span class="icon icon-link-ext"></span> {{i18n.ajax_request}}</a></li>
{{/config.ajaxrequest}}
{{#config.auth}}
<li><a id="buttonLogout" href="?api=logout"><span class="icon icon-logout"></span> logout</a></li>
<li><a id="buttonLogout" href="?api=logout"><span class="icon icon-logout"></span> {{i18n.logout}}</a></li>
{{/config.auth}}
</ul>
</li>
@@ -51,30 +52,30 @@
</div>
</nav>
<div id="filedropoverlay">
<div>Drop files to upload</div>
<div>{{i18n.upload_drop}}</div>
</div>
<div class="container">
<table id="filetable" class="table">
<thead>
<tr>
<th>Filename</th>
<th>{{i18n.filename}}</th>
{{#config.download}}
<th><!-- column for download link --></th>
{{/config.download}}
{{#config.showlastmodified}}
<th>last modified</th>
<th>{{i18n.last_modified}}</th>
{{/config.showlastmodified}}
{{#config.showfilesize}}
<th>size</th>
<th>{{i18n.size}}</th>
{{/config.showfilesize}}
{{#config.showpermissions}}
<th class="hidden-xs">permissions</th>
<th class="hidden-xs">{{i18n.permissions}}</th>
{{/config.showpermissions}}
{{#config.showowner}}
<th class="hidden-xs hidden-sm">owner</th>
<th class="hidden-xs hidden-sm">{{i18n.owner}}</th>
{{/config.showowner}}
{{#config.showgroup}}
<th class="hidden-xs hidden-sm hidden-md">group</th>
<th class="hidden-xs hidden-sm hidden-md">{{i18n.group}}</th>
{{/config.showgroup}}
<th class="buttons"><!-- column for buttons --></th>
</tr>
@@ -84,5 +85,5 @@
</table>
</div>
<div class="container">
<div class="panel panel-default ifminfo"><div class="panel-body">IFM - improved file manager | ifm.php hidden | <a href="http://github.com/misterunknown/ifm">Visit the project on GitHub</a></div></div>
<div class="panel panel-default ifminfo"><div class="panel-body">{{i18n.footer}} <a href="http://github.com/misterunknown/ifm">{{i18n.github}}</a></div></div>
</div>

View File

@@ -1,8 +1,7 @@
<tbody>
{{#items}}
<tr class="clickable-row {{rowclasses}}" data-filename="{{name}}" data-eaction="{{eaction}}">
<td>
<a tabindex="0" id="{{guid}}" class="ifmitem" {{{tooltip}}} data-type="{{type}}">
<a {{{href}}} tabindex="0" id="{{guid}}" class="ifmitem" {{{tooltip}}} data-type="{{type}}">
<span class="{{icon}}"></span>
{{linkname}}
</a>
@@ -42,11 +41,10 @@
{{/config.showgroup}}
<td>
{{#button}}
<a tabindex="0" name="do-{{action}}" data-name="{{name}}">
<a tabindex="0" name="do-{{action}}" data-id="{{guid}}">
<span class="{{icon}}" title="{{title}}"</span>
</a>
{{/button}}
</td>
</tr>
{{/items}}
</tbody>

View File

@@ -2,7 +2,7 @@
<div class="container">
<div class="row">
<div class="col-xs-1">
<a name="showAll">Tasks <span class="badge" name="taskCount">1</span></a>
<a name="showAll">{{i18n.tasks}} <span class="badge" name="taskCount">1</span></a>
</div>
<div id="waitqueue" class="col-xs-11">
</div>

View File

@@ -43,12 +43,12 @@ body {
<div class="container">
<form action="" method="post" class="form-signin">
<h2 class="form-signin-heading text-center">IFM Login</h2>
<h2 class="form-signin-heading text-center">IFM {{i18n.login}}</h2>
{{error}}
<label for="inputEmail" class="sr-only">Username</label>
<input type="text" id="user" name="user" class="form-control" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="pass" name="pass" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
<label for="inputEmail" class="sr-only">{{i18n.username}}</label>
<input type="text" id="user" name="user" class="form-control" placeholder="{{i18n.username}}" required autofocus>
<label for="inputPassword" class="sr-only">{{i18n.password}}</label>
<input type="password" id="pass" name="pass" class="form-control" placeholder="{{i18n.password}}" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">{{i18n.login}}</button>
</form>
</div> <!-- /container -->

View File

@@ -1,5 +1,5 @@
<div id="savequestion">
<label>Do you want to save this file?</label><br>
<button id="buttonSave">Save</button>
<button id="buttonDismiss">Dismiss</button>
<label>{{i18n.file_save_confirm}}?</label><br>
<button id="buttonSave">{{i18n.save}}</button>
<button id="buttonDismiss">{{i18n.cancel}}</button>
</div>

View File

@@ -3,13 +3,13 @@
<fieldset>
<label>URL</label><br>
<input class="form-control" type="text" id="ajaxurl" required><br>
<label>Data</label><br>
<label>{{i18n.data}}</label><br>
<textarea class="form-control" id="ajaxdata"></textarea><br>
<label>Method</label><br>
<label>{{i18n.method}}</label><br>
<input type="radio" name="arMethod" value="GET">GET</input><input type="radio" name="arMethod" value="POST" checked="checked">POST</input><br>
<button type="button" class="btn btn-success" id="buttonRequest">Request</button>
<button type="button" class="btn btn-default" id="buttonClose">Close</button><br>
<label>Response</label><br>
<button type="button" class="btn btn-success" id="buttonRequest">{{i18n.request}}</button>
<button type="button" class="btn btn-default" id="buttonClose">{{i18n.cancel}}</button><br>
<label>{{i18n.response}}</label><br>
<textarea class="form-control" id="ajaxresponse"></textarea>
</fieldset>
</form>

View File

@@ -1,13 +1,13 @@
<form id="formCopyMove">
<fieldset>
<div class="modal-body">
<label>Select destination:</label>
<label>{{i18n.select_destination}}:</label>
<div id="copyMoveTree"><div class="text-center"><span class="icon icon-spin5 animate-spin"></span></div></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="copyButton">copy</button>
<button type="button" class="btn btn-default" id="moveButton">move</button>
<button type="button" class="btn btn-default" id="cancelButton">cancel</button>
<button type="button" class="btn btn-default" id="copyButton">{{i18n.copy}}</button>
<button type="button" class="btn btn-default" id="moveButton">{{i18n.move}}</button>
<button type="button" class="btn btn-default" id="cancelButton">{{i18n.cancel}}</button>
</div>
</fieldset>
</form>

View File

@@ -1,12 +1,12 @@
<form id="formCreateDir">
<div class="modal-body">
<fieldset>
<label>Directoy name:</label>
<label>{{i18n.directoryname}}:</label>
<input class="form-control" type="text" name="dirname" value="" />
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="buttonSave">Save</button>
<button type="button" class="btn btn-default" id="buttonCancel">Cancel</button>
<button type="button" class="btn btn-default" id="buttonSave">{{i18n.save}}</button>
<button type="button" class="btn btn-default" id="buttonCancel">{{i18n.cancel}}</button>
</div>
</form>

View File

@@ -1,9 +1,14 @@
<form id="formDeleteFile">
<form id="formDeleteFiles">
<div class="modal-body">
<label>Do you really want to delete the file {{filename}}?
{{#multiple}}
<label>{{i18n.file_delete_confirm}} <code>{{count}}</code>?</label>
{{/multiple}}
{{^multiple}}
<label>{{i18n.file_delete_confirm}} <code>{{filename}}</code>?</label>
{{/multiple}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="buttonYes">Yes</button>
<button type="button" class="btn btn-default" id="buttonNo">No</button>
<button type="button" class="btn btn-danger" id="buttonYes">{{i18n.delete}}</button>
<button type="button" class="btn btn-default" id="buttonNo">{{i18n.cancel}}</button>
</div>
</form>

View File

@@ -1,7 +1,7 @@
<form id="formExtractFile">
<fieldset>
<div class="modal-body">
<label>Extract {{filename}} to:</label>
<div class="modal-body">
<fieldset>
<label>{{i18n.extract_filename}} {{filename}}:</label>
<div class="input-group">
<span class="input-group-addon"><input type="radio" name="extractTargetLocation" value="./" checked="checked"></span>
<span class="form-control">./</span>
@@ -14,10 +14,10 @@
<span class="input-group-addon"><input type="radio" name="extractTargetLocation" value="custom"></span>
<input id="extractCustomLocation" type="text" class="form-control" placeholder="custom location" value="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="buttonExtract">extract</button>
<button type="button" class="btn btn-default" id="buttonCancel">cancel</button>
</div>
</fieldset>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="buttonExtract">{{i18n.extract}}</button>
<button type="button" class="btn btn-default" id="buttonCancel">{{i18n.cancel}}</button>
</div>
</form>

View File

@@ -1,21 +1,15 @@
<form id="formFile">
<div class="modal-body">
<fieldset>
<label>Filename:</label>
<label>{{i18n.filename}}:</label>
<input type="text" class="form-control" name="filename" value="{{filename}}"><br>
<div id="content" name="content"></div><br>
<button type="button" class="btn btn-default" id="editoroptions">editor options</button>
<div class="hide" id="editoroptions-head">options</div>
<div class="hide" id="editoroptions-content">
<input type="checkbox" id="editor-wordwrap"> word wrap</input><br>
<input type="checkbox" id="editor-softtabs"> use soft tabs</input>
<div class="input-group"><span class="input-group-addon">tabsize</span><input class="form-control" type="text" size="2" id="editor-tabsize"title="tabsize"></div>
</div>
<button type="button" class="btn btn-default" id="editoroptions">{{i18n.editor_options}}</button>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" id="buttonSave" class="btn btn-default">Save</button>
<button type="button" id="buttonSaveNotClose" class="btn btn-default">Save without closing</button>
<button type="button" id="buttonClose" class="btn btn-default">Close</button>
<button type="button" id="buttonSave" class="btn btn-default">{{i18n.save}}</button>
<button type="button" id="buttonSaveNotClose" class="btn btn-default">{{i18n.save_wo_close}}</button>
<button type="button" id="buttonClose" class="btn btn-default">{{i18n.close}}</button>
</div>
</form>

View File

@@ -0,0 +1,11 @@
<input type="checkbox" id="editor-wordwrap"
{{#wordwrap}}
checked="checked"
{{/wordwrap}}
> {{i18n.word_wrap}}</input><br>
<input type="checkbox" id="editor-softtabs"
{{#softtabs}}
checked="checked"
{{/softtabs}}
> {{i18n.soft_tabs}}</input>
<div class="input-group"><span class="input-group-addon">{{i18n.tab_size}}</span><input class="form-control" type="text" size="2" id="editor-tabsize" title="{{i18n.tab_size}}" value="{{tabsize}}"></div>

View File

@@ -1,9 +0,0 @@
<form id="formDeleteFiles">
<div class="modal-body">
<label>Do you really want to delete these {{count}} files?</label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="buttonYes">Yes</button>
<button type="button" class="btn btn-default" id="buttonNo">No</button>
</div>
</form>

View File

@@ -1,16 +1,16 @@
<form id="formRemoteUpload">
<div class="modal-body">
<fieldset>
<label>Remote upload URL</label><br>
<label>{{i18n.upload_remote_url}}</label><br>
<input class="form-control" type="text" id="url" name="url" required><br>
<label>Filename (required)</label>
<label>{{i18n.filename}}</label>
<input class="form-control" type="text" id="filename" name="filename" required><br>
<label>Method</label>
<label>{{i18n.method}}</label>
<input type="radio" name="method" value="curl" checked="checked">cURL<input type="radio" name="method" value="file">file</input><br>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="buttonUpload">Upload</button>
<button type="button" class="btn btn-default" id="buttonCancel">Cancel</button>
<button type="button" class="btn btn-default" id="buttonUpload">{{i18n.upload}}</button>
<button type="button" class="btn btn-default" id="buttonCancel">{{i18n.cancel}}</button>
</div>
</form>

View File

@@ -1,10 +1,12 @@
<div class="modal-body">
<form id="formRenameFile">
<div class="modal-body">
<fieldset>
<label>Rename {{filename}} to:</label>
<input class="form-control" type="text" name="newname" /><br>
<button class="btn btn-default" id="buttonRename">Rename</button>
<button class="btn btn-default" id="buttonCancel">Cancel</button>
<label>{{i18n.rename_filename}} {{filename}}:</label>
<input class="form-control" type="text" name="newname" value="" /><br>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="buttonRename">{{i18n.rename_filename}}</button>
<button type="button" class="btn btn-default" id="buttonCancel">{{i18n.cancel}} </button>
</div>
</form>

View File

@@ -1,7 +1,7 @@
<form id="searchForm">
<div class="modal-body">
<fieldset>
<label>Pattern:</label>
<label>{{i18n.search_pattern}}:</label>
<input type="text" class="form-control" id="searchPattern" name="pattern" value="{{lastSearch}}"><br>
<table id="searchResults" class="table">
</table>

View File

@@ -1,4 +1,3 @@
<tbody>
{{#items}}
<tr class="{{rowclasses}}" data-filename="{{name}}">
<td>
@@ -8,4 +7,10 @@
</td>
</tr>
{{/items}}
</tbody>
{{^items}}
<tr>
<td>
No results found.
</td>
</tr>
{{/items}}

View File

@@ -1,14 +1,14 @@
<form id="formUploadFile">
<div class="modal-body">
<fieldset>
<label>Upload file</label><br>
<label>{{i18n.upload_file}}</label><br>
<input class="file" type="file" name="files" multiple><br>
<label>new filename</label>
<label>{{i18n.filename_new}}</label>
<input class="form-control" type="text" name="newfilename"><br>
</fieldset>
</div>
<div class="modal-footer">
<button class="btn btn-default" id="buttonUpload">Upload</button>
<button class="btn btn-default" id="buttonCancel">Cancel</button>
<button class="btn btn-default" id="buttonUpload">{{i18n.upload}}</button>
<button class="btn btn-default" id="buttonCancel">{{i18n.cancel}}</button>
</div>
</form>