0,
"auth_source" => 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC',
"root_dir" => "",
"root_public_url" => "",
"tmp_dir" => "",
"timezone" => "",
"forbiddenChars" => array(),
"dateLocale" => "en-US",
"language" => "en",
"selfoverwrite" => 0,
// 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,
"createarchive" => 1,
"search" => 1,
"pagination" => 0,
// gui controls
"showlastmodified" => 0,
"showfilesize" => 1,
"showowner" => 1,
"showgroup" => 1,
"showpermissions" => 2,
"showhtdocs" => 0,
"showhiddenfiles" => 1,
"showpath" => 0,
"contextmenu" => 1,
"disable_mime_detection" => 0,
"showrefresh" => 1,
"forceproxy" => 0,
"confirmoverwrite" => 1
);
private $config = array();
private $templates = array();
private $i18n = array();
public $mode = "standalone";
public function __construct( $config=array() ) {
// load the default config
$this->config = $this->defaultconfig;
// load config from environment variables
$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['root_public_url'] = getenv('IFM_ROOT_PUBLIC_URL') !== false ? getenv('IFM_ROOT_PUBLIC_URL') : $this->config['root_public_url'] ;
$this->config['tmp_dir'] = getenv('IFM_TMP_DIR') !== false ? getenv('IFM_TMP_DIR') : $this->config['tmp_dir'] ;
$this->config['timezone'] = getenv('IFM_TIMEZONE') !== false ? getenv('IFM_TIMEZONE') : $this->config['timezone'] ;
$this->config['dateLocale'] = getenv('IFM_DATELOCALE') !== false ? getenv('IFM_DATELOCALE') : $this->config['dateLocale'] ;
$this->config['forbiddenChars'] = getenv('IFM_FORBIDDENCHARS') !== false ? str_split( getenv('IFM_FORBIDDENCHARS') ) : $this->config['forbiddenChars'] ;
$this->config['language'] = getenv('IFM_LANGUAGE') !== false ? getenv('IFM_LANGUAGE') : $this->config['language'] ;
$this->config['selfoverwrite'] = getenv('IFM_SELFOVERWRITE') !== false ? getenv('IFM_SELFOVERWRITE') : $this->config['selfoverwrite'] ;
$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['createarchive'] = getenv('IFM_API_CREATEARCHIVE') !== false ? intval( getenv('IFM_API_CREATEARCHIVE') ) : $this->config['createarchive'] ;
$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'] ;
$this->config['search'] = getenv('IFM_API_SEARCH') !== false ? intval( getenv('IFM_API_SEARCH') ) : $this->config['search'] ;
$this->config['showrefresh'] = getenv('IFM_GUI_REFRESH') !== false ? intval( getenv('IFM_GUI_REFRESH') ) : $this->config['showrefresh'] ;
$this->config['forceproxy'] = getenv('IFM_GUI_FORCEPROXY') !== false ? intval( getenv('IFM_GUI_FORCEPROXY') ) : $this->config['forceproxy'] ;
$this->config['confirmoverwrite'] = getenv('IFM_GUI_CONFIRMOVERWRITE') !== false ? intval( getenv('IFM_GUI_CONFIRMOVERWRITE') ) : $this->config['confirmoverwrite'] ;
// optional settings
if( getenv('IFM_SESSION_LIFETIME') !== false )
$this->config['session_lifetime'] = getenv('IFM_SESSION_LIFETIME');
if( getenv('IFM_FORCE_SESSION_LIFETIME') !== false )
$this->config['session_lifetime'] = getenv('IFM_FORCE_SESSION_LIFETIME');
// load config from passed array
$this->config = array_merge( $this->config, $config );
// get list of ace includes
$this->config['ace_includes'] = <<<'f00bar'
f00bar;
// templates
$templates = array();
$templates['app'] = <<<'f00bar'
{{i18n.upload_drop}}
|
{{i18n.filename}} |
{{#config.download}}
|
{{/config.download}}
{{#config.showlastmodified}}
{{i18n.last_modified}} |
{{/config.showlastmodified}}
{{#config.showfilesize}}
{{i18n.size}} |
{{/config.showfilesize}}
{{#config.showpermissions}}
{{i18n.permissions}} |
{{/config.showpermissions}}
{{#config.showowner}}
{{i18n.owner}} |
{{/config.showowner}}
{{#config.showgroup}}
{{i18n.group}} |
{{/config.showgroup}}
|
f00bar;
$templates['login'] = <<<'f00bar'
f00bar;
$templates['filetable'] = <<<'f00bar'
{{#items}}
{{#fixtop}}
|
{{/fixtop}}
{{^fixtop}}
|
{{/fixtop}}
{{linkname}}
|
{{#config.download}}
|
{{/config.download}}
{{#config.showlastmodified}}
{{lastmodified_hr}} |
{{/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['footer'] = <<<'f00bar'
f00bar;
$templates['task'] = <<<'f00bar'
f00bar;
$templates['ajaxrequest'] = <<<'f00bar'
f00bar;
$templates['copymove'] = <<<'f00bar'
f00bar;
$templates['createdir'] = <<<'f00bar'
f00bar;
$templates['createarchive'] = <<<'f00bar'
f00bar;
$templates['deletefile'] = <<<'f00bar'
f00bar;
$templates['extractfile'] = <<<'f00bar'
f00bar;
$templates['file'] = <<<'f00bar'
f00bar;
$templates['file_editoroptions'] = <<<'f00bar'
f00bar;
$templates['remoteupload'] = <<<'f00bar'
f00bar;
$templates['renamefile'] = <<<'f00bar'
f00bar;
$templates['search'] = <<<'f00bar'
f00bar;
$templates['searchresults'] = <<<'f00bar'
{{#items}}
{{linkname}} ({{folder}})
|
{{/items}}
{{^items}}
No results found.
|
{{/items}}
f00bar;
$templates['uploadfile'] = <<<'f00bar'
f00bar;
$templates['uploadconfirmoverwrite'] = <<<'f00bar'
f00bar;
$this->templates = $templates;
$i18n = array();
$i18n["ar"] = <<<'f00bar'
{
"ajax_request": "AJAXطلب",
"archive_create_error": "تعذر أنشاء الأرشيف",
"archive_create_success": "تم إنشاء الأرشيف بنجاح",
"archive_invalid_format": "صيغة الأرشيف غير صحيحة",
"archivename": "اسم الأرشيف",
"cancel": "إلغاء",
"close": "إغلاق",
"copy": "نسخ",
"copy_error": "تعذر نسخ الملفات التالية",
"copy_success": "تم نسخ الملف / الملفات بنجاح",
"copylink": "نسخ الرابط",
"create_archive": "إنشاء أرشيف",
"data": "بيانات",
"delete": "حذف",
"directoryname": "اسم الدليل",
"download": "تحميل",
"edit": "تحرير ",
"editor_options": "خيارات المحرر",
"error": "خطأ ",
"extract": "استخراج",
"extract_error": "تعذر استخراج الملف",
"extract_filename": "استخراج الملف",
"extract_success": "تم استخراج الملف بنجاح",
"file_copy_to": "الى",
"file_delete_confirm": "هل تود حذف الملف التالي؟",
"file_delete_error": "تعذر حذف الملف / الملفات",
"file_delete_success": "تم حذف الملف / الملفات بنجاح",
"file_display_error": "لا يمكن عرض أو تحرير الملف",
"file_load_error": "تعذر تحميل الملف",
"file_new": "ملف جديد",
"file_no_permission": "ليس لديك صلاحية لإنشاء أو تحرير الملف",
"file_not_found": "تعذر العثور على الملف ",
"file_open_error": "تعذر فتح الملف",
"file_rename": "تعديل اسم الملف",
"file_rename_error": "تعذر تعديل اسم الملف",
"file_rename_success": "تم تعديل اسم الملف بنجاح",
"file_save_confirm": "هل تود حفظ الملف التالي؟",
"file_save_error": "تعذر إنشاء أو تحرير الملف ",
"file_save_success": "تم حفظ الملف بنجاح",
"file_upload_error": "تعذر رفع الملف",
"file_upload_success": "تم رفع الملف بنجاح",
"filename": "اسم الملف",
"filename_new": "اسم الملف الجديد",
"filename_slashes": "يجب ألا يحتوي اسم الملف على علامة ترقيم الشرطة المائلة",
"filter": "تصفية النتائج",
"folder_create_error": "تعذر إنشاء المجلد",
"folder_create_success": "تم إنشاء المجلد بنجاح",
"folder_new": "مجلد جديد",
"folder_not_found": "تعذر العثور على المجلد",
"folder_tree_load_error": "حدث خطأ أثناء البحث عن المجلد",
"footer": "IFM - improved file manager | ifm.php hidden |",
"general_error": "خطأ عام",
"github": "GitHub قم بزيارة المشروع على ",
"group": "مجموعة",
"invalid_action": "الإجراء غير صحيح",
"invalid_archive_format": "zip, tar, tar.gz, tar.bz2 صيغة الأرشيف غير صحيحة، الصيغ الممكنة هي",
"invalid_data": "بيانات غير صحيحة من الخادم",
"invalid_dir": "الدليل غير صحيح",
"invalid_filename": "اسم الملف غير صحيح",
"invalid_params": "المعامل غير صحيح",
"invalid_url": "العنوان غير صحيح",
"json_encode_error": "JSONتعذر الصياغة في ",
"last_modified": "آخر تعديل",
"load_config_error": "تعذر تحميل التكوين",
"load_template_error": "تعذر تحميل النماذج",
"load_text_error": "تعذر تحميل النصوص",
"login": "تسجيل الدخول",
"login_failed": "لم يتم تسجيل الدخول بنجاح",
"logout": "تسجيل الخروج",
"method": "طريقة",
"move": "نقل",
"move_error": "تعذر نقل الملفات التالية",
"move_success": "تم نقل الملف / الملفات بنجاح",
"nopermissions": "ليس لديك الصلاحية للقيام بذلك",
"options": "خيارات",
"owner": "المالك",
"password": "كلمة المرور",
"path_content": "محتوى",
"pattern_error_slashes": "يجب ألا يحتوي النمط على علامة ترقيم الشرطة المائلة ",
"permission_change_error": "تعذر تغيير الصلاحيات",
"permission_change_success": "تم تغيير الصلاحيات بنجاح",
"permission_parse_error": "تعذر تحليل الصلاحيات بنجاح",
"permissions": "صلاحيات",
"refresh": "تحديث",
"remaining_tasks": "لا يزال هناك مهام قائمة. هل تود إعادة التحميل؟",
"rename": "إعادة تسمية",
"rename_filename": "إعادة تسمية الملف",
"request": "طلب",
"response": "استجابة",
"save": "حفظ",
"save_wo_close": "حفظ بدون إغلاق",
"search": "بحث",
"search_pattern": "نمط",
"select_destination": "حدد الوجهة",
"size": "حجم",
"soft_tabs": "إضافة فراغ",
"tab_size": "حجم علامة التبويب",
"tasks": "مهام",
"toggle_nav": "تبديل التنقل",
"upload": "رفع",
"upload_drop": "قم بإسقاط الملف / الملفات للرفع",
"upload_file": "رفع ملف",
"upload_overwrite_hint": "سيتم استبدال الملف / الملفات التالية",
"upload_overwrite_confirm": "هل تريد الرفع على أية حال؟",
"upload_remote": "الرفع عن بعد",
"upload_remote_url": "عنوان الرفع عن بعد",
"username": "اسم المستخدم",
"word_wrap": "التفاف النص"
}
f00bar;
$i18n["ar"] = json_decode( $i18n["ar"], true );
$i18n["de"] = <<<'f00bar'
{
"ajax_request": "AJAX Request",
"archivename": "Name des Archivs",
"archive_create_success": "Das Archiv wurde erfolgreich erstellt.",
"archive_create_error": "Das Archiv konnte nicht erstellt werden.",
"archive_invalid_format": "Ungültiges Archivformat angegeben.",
"cancel": "Abbrechen",
"close": "Schließen",
"copy": "Kopieren",
"copylink": "Link kopieren",
"copy_error": "Folgende Dateien konnten nicht kopiert werden:",
"copy_success": "Datei(en) erfolgreich kopiert.",
"create_archive": "Archiv erstellen",
"data": "Daten",
"delete": "Löschen",
"directoryname": "Ordner Name",
"download": "Download",
"edit": "Bearbeiten",
"editor_options": "Editor Optionen",
"error": "Fehler:",
"extract": "Entpacken",
"extract_error": "Das Archiv konnte nicht entpackt werden.",
"extract_filename": "Folgende Datei entpacken -",
"extract_success": "Das Archiv wurde erfolgreich entpackt.",
"file_copy_to": "nach",
"file_delete_confirm": "Soll die folgende Datei wirklich gelöscht werden:",
"file_delete_error": "Folgende Dateien konnten nicht gelöscht werden:",
"file_delete_success": "Datei(en) erfolgreich gelöscht",
"file_display_error": "Die Datei kann nicht angezeigt oder geändert werden",
"file_new": "Neue Datei",
"file_load_error": "Der Inhalt der Datei konnte nicht geladen werden",
"file_open_error": "Die Datei konnte nicht geöffnet werden.",
"file_no_permission": "Sie haben keine Berechtigung diese Datei zu erstellen/bearbeiten.",
"file_not_found": "Die Datei wurde nicht gefunden, oder kann nicht geöffnet werden.",
"file_rename": "Datei umbenennen",
"file_rename_error": "Datei konnte nicht umbenannt werden: ",
"file_rename_success": "Datei erfolgreich umbenannt.",
"file_save_error": "Datei konnte nicht gespeichert werden.",
"file_save_success": "Datei erfolgreich gespeichert.",
"file_save_confirm": "Soll diese Datei wirklich gespeichert werden -",
"file_upload_error": "Datei konnte nicht hochgeladen werden.",
"file_upload_success": "Datei erfolgreich hochgeladen",
"filename": "Dateiname",
"filename_new": "Neuer Dateiname",
"filename_slashes": "Der Dateiname darf keine Schrägstriche enthalten.",
"filter": "Filtern",
"folder_create_error": "Verzeichnis konnte nicht angelegt werden.",
"folder_create_success": "Verzeichnis erfolgreich angelegt.",
"folder_new": "Neue Ordner",
"folder_not_found": "Das Verzeichnis wurde nicht gefunden.",
"folder_tree_load_error": "Fehler bei Laden des Verzeichnisbaums.",
"footer": "IFM - verbesserter file manager | ifm.php versteckt |",
"general_error": "Genereller Fehler aufgetreten: Keine oder unvollständige Antwort vom Server",
"github": "Besuche das Projekt auf GitHub",
"group": "Gruppe",
"invalid_action": "Fehlerhafte Aktion übergeben.",
"invalid_archive_format": "Ungültiges Archiv-Format. Möglich sind zip, tar, tar.gz oder tar.bz2.",
"invalid_data": "Fehlerhafte Daten vom Server erhalten.",
"invalid_dir": "Ungültiges Verzeichnis übergegeben.",
"invalid_filename": "Ungültiger Dateiname übergegeben.",
"invalid_params": "Ungültige Parameter übergegeben.",
"invalid_url": "Ungültige URL übergegeben.",
"json_encode_error": "Konnte die Antwort nicht als JSON formatieren:",
"last_modified": "Zuletzt geändert",
"load_config_error": "Konfiguration konnte nicht geladen werden.",
"load_template_error": "Vorlagen konnten nicht geladen werden.",
"load_text_error": "Texte konnten nicht geladen werden.",
"login": "Anmeldung",
"login_failed": "Anmeldung fehlgeschlagen.",
"logout": "Abmelden",
"method": "Methode",
"move": "Verschieben",
"move_error": "Folgende Dateien konnten nicht verschoben werden:",
"move_success": "Datei(en) erfolgreich verschoben.",
"nopermissions": "Sie haben nicht die nötige Berechtigung dafür.",
"options": "Optionen",
"owner": "Besitzer",
"password": "Passwort",
"path_content": "Inhalt von",
"pattern_error_slashes": "Das Muster darf keine Slashes enthalten.",
"permission_change_error": "Berechtigungen konnten nicht geändert werden.",
"permission_change_success": "Berechtigungen erfolgreich geändert.",
"permission_parse_error": "Berechtigungen konnten nicht geparst werden.",
"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",
"remaining_tasks": "Es gibt noch laufende Prozesse. Wollen Sie wirklich neu laden?",
"toggle_nav": "Navigation umschalten",
"upload": "Hochladen",
"upload_drop": "Dateien zum hochladen hier ablegen",
"upload_file": "Datei hochladen",
"upload_overwrite_hint": "Die folgenden Dateien würden überschrieben:",
"upload_overwrite_confirm": "Sollen die Dateien dennoch hochgeladen werden?",
"upload_remote": "Hochladen von ausserhalb",
"upload_remote_url": "Entfernte URL zum hochladen",
"username": "Benutzername",
"word_wrap": "Zeilenumbruch"
}
f00bar;
$i18n["de"] = json_decode( $i18n["de"], true );
$i18n["en"] = <<<'f00bar'
{
"ajax_request": "AJAX request",
"archive_create_error": "Could not create archive.",
"archive_create_success": "Archive successfully created.",
"archive_invalid_format": "Invalid archive format given.",
"archivename": "Name of the archive",
"cancel": "Cancel",
"close": "Close",
"copy": "Copy",
"copy_error": "The following files could not be copied:",
"copy_success": "File(s) copied successfully.",
"copylink": "Copy link",
"create_archive": "Create archive",
"data": "Data",
"delete": "Delete",
"directoryname": "Directory Name",
"download": "Download",
"edit": "Edit",
"editor_options": "Editor Options",
"error": "Error:",
"extract": "Extract",
"extract_error": "Could not extract archive.",
"extract_filename": "Extract file - ",
"extract_success": "Archive extracted successfully.",
"file_copy_to": "to",
"file_delete_confirm": "Do you really want to delete the following file -",
"file_delete_error": "File(s) could not be deleted.",
"file_delete_success": "File(s) successfully deleted.",
"file_display_error": "This file can not be displayed or edited.",
"file_load_error": "Content could not be loaded.",
"file_new": "New file",
"file_no_permission": "No permission to edit/create file.",
"file_not_found": "File was not found or could not be opened.",
"file_open_error": "Could not open the file.",
"file_rename": "Rename File",
"file_rename_error": "File could not be renamed: ",
"file_rename_success": "File successfully renamed.",
"file_save_confirm": "Do you want to save the following file -",
"file_save_error": "File could not be saved.",
"file_save_success": "File was saved successfully.",
"file_upload_error": "File could not be uploaded.",
"file_upload_success": "File successfully uploaded.",
"filename": "Filename",
"filename_new": "New Filename",
"filename_slashes": "The filename must not contain slashes.",
"filter": "Filter",
"folder_create_error": "Directory could not be created: ",
"folder_create_success": "Directory sucessfully created.",
"folder_new": "New Folder",
"folder_not_found": "The directory could not be found.",
"folder_tree_load_error": "Error while fetching the folder tree.",
"footer": "IFM - improved file manager | ifm.php hidden |",
"general_error": "General error occured: No or broken response.",
"github": "Visit the project on GitHub",
"group": "Group",
"invalid_action": "Invalid action given.",
"invalid_archive_format": "Invalid archive format given. Possible formats are zip, tar, tar.gz or tar.bz2.",
"invalid_data": "Invalid data from server.",
"invalid_dir": "Invalid directory given.",
"invalid_filename": "Invalid filename given.",
"invalid_params": "Invalid parameter given.",
"invalid_url": "Invalid URL given.",
"json_encode_error": "Could not format the response as JSON:",
"last_modified": "Last Modified",
"load_config_error": "Could not load configuration.",
"load_template_error": "Could not load templates.",
"load_text_error": "Could not load texts.",
"login": "Login",
"login_failed": "Login failed.",
"logout": "Log Off",
"method": "Method",
"move": "Move",
"move_error": "The following files could not be moved:",
"move_success": "File(s) successfully moved.",
"nopermissions": "You don't have the permission to do that.",
"options": "Options",
"owner": "Owner",
"password": "Password",
"path_content": "Content of",
"pattern_error_slashes": "Pattern must not contain slashes.",
"permission_change_error": "Permissions could not be changed: ",
"permission_change_success": "Permissions successfully changed.",
"permission_parse_error": "Permissions could not be parsed correctly.",
"permissions": "Permissions",
"refresh": "Refresh",
"remaining_tasks": "There are remaining tasks. Do you really want to reload?",
"rename": "Rename",
"rename_filename": "Rename file -",
"request": "Request",
"response": "Response",
"save": "Save",
"save_wo_close": "Save w/o Close",
"search": "Search",
"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_overwrite_hint": "The following files would be overwritten:",
"upload_overwrite_confirm": "Upload anyway?",
"upload_remote": "Remote Upload",
"upload_remote_url": "Remote Upload URL",
"username": "Username",
"word_wrap": "Word Wrap"
}
f00bar;
$i18n["en"] = json_decode( $i18n["en"], true );
$i18n["fr"] = <<<'f00bar'
{
"ajax_request": "requête AJAX ",
"archivename": "Nom de l'archive",
"archive_create_success": "Archive créée avec succès.",
"archive_create_error": "Echec lors de la création de l'archive.",
"archive_invalid_format": "Le format de l'archive indiqué est invalide.",
"cancel": "Annuler",
"close": "Fermer",
"copy": "Copier",
"copylink": "Copier le lien",
"copy_error": "Les fichiers suivants n'ont pu être copiés :",
"copy_success": "Le(s) fichiers(s) a/ont été copié(s) avec succès.",
"create_archive": "Créer l'archive",
"data": "Données",
"delete": "Supprimer",
"directoryname": "Nom du dossier",
"download": "Téléchargement",
"edit": "Editer",
"editor_options": "Options de l'éditeur",
"error": "Erreur:",
"extract": "Extraire",
"extract_error": "Echec lors de l'extraction de l'archive.",
"extract_filename": "Extraire le fichier - ",
"extract_success": "Archive extraite avec succès.",
"file_copy_to": "vers",
"file_delete_confirm": "Voulez-vous vraiment supprimer le fichier -",
"file_delete_error": "Echec lors de la suppression des fichiers.",
"file_delete_success": "Les fichiers ont été supprimés avec succès.",
"file_display_error": "Ce fichier ne peut pas être affiché ni supprimé.",
"file_new": "Nouveau fichier",
"file_load_error": "Le contenu n'a pas pu être chargé.",
"file_open_error": "Impossible d'ouvrir le fichier.",
"file_no_permission": "Permissions insuffisantes pour éditer ou créer le fichier.",
"file_not_found": "Le fichier n'a pas été trouvé ou n'a pas pu être ouvert.",
"file_rename": "Renommer fichier",
"file_rename_error": "Le fichier n'a pas pu être renommé : ",
"file_rename_success": "Le fichier a été renommé avec succès.",
"file_save_error": "Le fichier n'a pas pu être enregistré.",
"file_save_success": "Le fichier a été enregistré avec succès.",
"file_save_confirm": "Voulez-vous enregistré le fichier -",
"file_upload_error": "Le fichier n'a pas pu être envoyé.",
"file_upload_success": "Le fichier a été envoyé avec succès.",
"filename": "Nom de fichier",
"filename_new": "Nouveau nom de fichier",
"filename_slashes": "Le Nom de fichier ne doit pas contenir de slash (/barre oblique/).",
"filter": "Filtrer",
"folder_create_error": "Le dossier n'a pas pu être créé : ",
"folder_create_success": "Le dossier n'a pas pu être créé avec succès.",
"folder_new": "Nouveau dossier",
"folder_not_found": "Dossier non trouvé.",
"folder_tree_load_error": "Error lors du chargement d le'arborescence.",
"footer": "IFM - improved file manager | ifm.php hidden |",
"general_error": "Erreur générale : pas de réponse, ou réponse incorrecte.",
"github": "Voir le projet sur GitHub",
"group": "Groupe",
"invalid_action": "Action demandée invalide.",
"invalid_archive_format": "Format d'archive invalide : les formats autorisés sont zip, tar, tar.gz ou tar.bz2.",
"invalid_data": "Données invalides reçues du serveur.",
"invalid_dir": "Le dossier indiqué est invalide.",
"invalid_filename": "Le nom de fichier indiqué est invalide.",
"invalid_params": "Le paramètre indiqué est invalide.",
"invalid_url": "L'URL indiquée est invalide.",
"json_encode_error": "Impossible de formater la réponse en JSON :",
"last_modified": "Dernière modification",
"load_config_error": "Impossible de charger la configuration.",
"load_template_error": "Impossible de charger les modèles.",
"load_text_error": "Impossible de charger les chaînes de textes.",
"login": "Connexion",
"login_failed": "Echec de connexion.",
"logout": "Déconnexion",
"method": "Méthode",
"move": "Déplacer",
"move_error": "Les fichiers suivants n'ont pu être déplacés :",
"move_success": "Fichiers déplacés avec succès.",
"nopermissions": "Vous n'avez pas les permissions pour faire cela.",
"options": "Options",
"owner": "Propriétaire",
"password": "Mot de passe",
"path_content": "Contenu de",
"pattern_error_slashes": "Le motif ne doit pas contenir de slashes.",
"permission_change_error": "Les permissions n'ont pu être changées : ",
"permission_change_success": "Permissions changées avec succès.",
"permission_parse_error": "Les permissions n'ont pu être interprétées correctement.",
"permissions": "Permissions",
"refresh": "Rafraîchir",
"rename": "Renommer",
"rename_filename": "Renommer fichier -",
"request": "Requête",
"response": "Réponse",
"save": "Enregistrer",
"save_wo_close": "Enregistrer sans fermer",
"search": "Recherche",
"search_pattern": "Motif",
"select_destination": "Seélectionner la destination",
"size": "Taille",
"soft_tabs": "Tabulations par espaces",
"tab_size": "Taille de tabulation",
"tasks": "Tâches",
"remaining_tasks": "Il reste des tâches en cours. Voulez-vous vraiment recharger la page ?",
"toggle_nav": "Basculer la navigation",
"upload": "Envoyer",
"upload_drop": "Glisser-déplacer les fichier pour les envoyer",
"upload_file": "Envoyer fichier",
"upload_remote": "Envoi distant",
"upload_remote_url": "URL pour l'envoi distant",
"username": "Nom d'utilisateur",
"word_wrap": "Revenir à la ligne"
}
f00bar;
$i18n["fr"] = json_decode( $i18n["fr"], true );
$i18n["pt-br"] = <<<'f00bar'
{
"ajax_request": "requisição AJAX",
"archivename": "Nome do arquivo compactado",
"archive_create_success": "Arquivo compactado com sucesso.",
"archive_create_error": "Não foi possível compactar o arquivo.",
"archive_invalid_format": "Formato do arquivo dado é inválido.",
"cancel": "Cancelar",
"close": "Fechar",
"copy": "Copiar",
"copylink": "Copiar endereço",
"copy_error": "Os seguintes arquivos não puderam ser copiados:",
"copy_success": "Arquivo(s) copiado(s) com sucesso.",
"create_archive": "Compactar",
"data": "Dados",
"delete": "Excluir",
"directoryname": "Nome do Diretório",
"download": "Baixar",
"edit": "Editar",
"editor_options": "Opções do Editor",
"error": "Erro:",
"extract": "Extrair",
"extract_error": "Não foi possível extrair o arquivo.",
"extract_filename": "Extrair arquivo - ",
"extract_success": "Arquivo extraído com sucesso.",
"file_copy_to": "para",
"file_delete_confirm": "Você tem certeza que quer excluir o seguinte arquivo -",
"file_delete_error": "Arquivo(s) não puderam/pôde ser excluído(s).",
"file_delete_success": "Arquivo(s) excluído(s) com sucesso.",
"file_display_error": "Este arquivo não pode ser exibido ou editado.",
"file_new": "Novo Arquivo",
"file_load_error": "Conteúdo não pôde ser carregado.",
"file_open_error": "Não foi possível abrir o arquivo.",
"file_no_permission": "Sem permissão para editar/criar o arquivo.",
"file_not_found": "Arquivo não foi encontrado ou não pôde ser aberto.",
"file_rename": "Renomear arquivo",
"file_rename_error": "Arquivo não pôde ser renomeado: ",
"file_rename_success": "Arquivo renomeado com sucesso.",
"file_save_error": "Não foi possível salvar o arquivo.",
"file_save_success": "Arquivo salvo com sucesso.",
"file_save_confirm": "Você quer salvar o seguinte arquivo -",
"file_upload_error": "Não foi possível enviar o arquivo.",
"file_upload_success": "Arquivo enviado com sucesso.",
"filename": "Nome do arquivo",
"filename_new": "Novo nome do arquivo",
"filename_slashes": "O nome do arquivo não deve ter barras.",
"filter": "Filtrar",
"folder_create_error": "Diretónio não pôde ser criado: ",
"folder_create_success": "Diretório criado com sucesso.",
"folder_new": "Novo Diretório",
"folder_not_found": "Não foi possível achar o diretório.",
"folder_tree_load_error": "Error durante a construção da árvore de diretórios.",
"footer": "IFM - improved file manager | ifm.php escondido |",
"general_error": "Erro genérico: Sem respsota ou resposta inválida.",
"github": "Visite o projeto no GitHub",
"group": "Grupo",
"invalid_action": "Ação inválida dada.",
"invalid_archive_format": "Formato de arquivo inválido dado. Formatos possíveis são zip, tar, tar.gz ou tar.bz2.",
"invalid_data": "Dados inválidos vindos do servidor.",
"invalid_dir": "Diretório inválido dado.",
"invalid_filename": "Nome do arquivo inválido dado.",
"invalid_params": "Parâmetro inválido dado.",
"invalid_url": "URL Inválida dada.",
"json_encode_error": "Não foi possível formatar a resposta como JSON:",
"last_modified": "Última Modificação",
"load_config_error": "Não foi possível carregar as configurações.",
"load_template_error": "Não foi possível carregar o template.",
"load_text_error": "Não foi possível carregar os textos.",
"login": "Logar",
"login_failed": "Login falhou.",
"logout": "Deslogar",
"method": "Método",
"move": "Mover",
"move_error": "Os seguintes arquivos não puderam ser movidos:",
"move_success": "Arquivo(s) movidos com sucesso.",
"nopermissions": "Você não tem permissão para fazer isto.",
"options": "Opções",
"owner": "Dono",
"password": "Senha",
"path_content": "Conteúdo de",
"pattern_error_slashes": "Padrão não deve conter barras.",
"permission_change_error": "Não foi possível alterar as permissões: ",
"permission_change_success": "Permissões alteradas com sucesso.",
"permission_parse_error": "Não foi possível mapear as permissões corretamente.",
"permissions": "Permissões",
"refresh": "Atualizar",
"rename": "Renomear",
"rename_filename": "Renomear arquivo -",
"request": "Requisição",
"response": "Resposta",
"save": "Salvar",
"save_wo_close": "Salvar sem Fechar",
"search": "Procurar",
"search_pattern": "Padrão",
"select_destination": "Selecione Destino",
"size": "Tamanho",
"soft_tabs": "Tabulação suave",
"tab_size": "Tamanho da tabulação",
"tasks": "Tarefas",
"remaining_tasks": "Existem tarefas remanescentes. Você realmente deseja recarregar?",
"toggle_nav": "Ativar/Desativar Navegação",
"upload": "Enviar",
"upload_drop": "Solte arquivo aqui para enviar",
"upload_file": "Enviar Arquivo",
"upload_remote": "Envio Remoto",
"upload_remote_url": "URL para Envio Remoto",
"username": "Nome de usuário",
"word_wrap": "Quebra de Linha"
}
f00bar;
$i18n["pt-br"] = json_decode( $i18n["pt-br"], true );
$i18n["ru"] = <<<'f00bar'
{
"ajax_request": "AJAX запрос",
"archivename": "Название архива",
"archive_create_success": "Архив успешно создан.",
"archive_create_error": "Не удалось создать архив.",
"archive_invalid_format": "Указан неверный формат архива.",
"cancel": "Отмена",
"close": "Закрыть",
"copy": "Копировать",
"copylink": "Копировать ссылку",
"copy_error": "Не удалось скопировать следующие файлы:",
"copy_success": "Файл(ы) успешно скопированы.",
"create_archive": "Создать архив",
"data": "Данные",
"delete": "Удалить",
"directoryname": "Название каталога",
"download": "Скачать",
"edit": "Редактировать",
"editor_options": "Параметры редактора",
"error": "Ошибка:",
"extract": "Извлечь",
"extract_error": "Не удалось извлечь архив.",
"extract_filename": "Извлечь файл - ",
"extract_success": "Архив извлечен успешно.",
"file_copy_to": "в",
"file_delete_confirm": "Вы действительно хотите удалить следующий файл - ",
"file_delete_error": "Файл(ы) не может быть удалены.",
"file_delete_success": "Файл(ы) успешно удалены.",
"file_display_error": "Файл не может быть отображен или отредактирован.",
"file_new": "Новый файл",
"file_load_error": "Не удалось загрузить содержимое.",
"file_open_error": "Не удалось открыть файл.",
"file_no_permission": "Нет прав на редактирование/создание файла.",
"file_not_found": "Файл не найден или не может быть открыт.",
"file_rename": "Переименовать файл",
"file_rename_error": "Файл не может быть переименован: ",
"file_rename_success": "Файл успешно переименован.",
"file_save_error": "Не удалось сохранить файл.",
"file_save_success": "Файл успешно сохранен.",
"file_save_confirm": "Хотите сохранить следующий файл -",
"file_upload_error": "Не удалось загрузить файл.",
"file_upload_success": "Файл успешно загружен.",
"filename": "Имя файла",
"filename_new": "Новое имя файла",
"filename_slashes": "Имя файла не должно содержать косую черту.",
"filter": "Фильтр",
"folder_create_error": "Не удалось создать каталог: ",
"folder_create_success": "Каталог успешно сохранен.",
"folder_new": "Новый каталог",
"folder_not_found": "Каталог не найден.",
"folder_tree_load_error": "Ошибка при получении дерева папок.",
"footer": "IFM - improved file manager | ifm.php hidden |",
"general_error": "Ошибка: Отсутствующий или неверный ответ.",
"github": "Страница проекта на GitHub",
"group": "Группа",
"invalid_action": "Неверное действие.",
"invalid_archive_format": "Неверный формат архива. Допустимые форматы: zip, tar, tar.gz или tar.bz2.",
"invalid_data": "Неверные данные от сервера.",
"invalid_dir": "Неверный каталог.",
"invalid_filename": "Неверное имя файла.",
"invalid_params": "Неверный параметр.",
"invalid_url": "Неверный URL.",
"json_encode_error": "Не удалось представить ответ в виде JSON:",
"last_modified": "Изменено",
"load_config_error": "Ошибка загрузки конфигурации.",
"load_template_error": "Ошибка загрузки шаблона.",
"load_text_error": "Ошибка загрузки текста.",
"login": "Вход",
"login_failed": "Ошибка входа.",
"logout": "Выйти",
"method": "Метод",
"move": "Переместить",
"move_error": "Следующие файлы не могут быть перемещены:",
"move_success": "Файл(ы) успешно перемещены.",
"nopermissions": "Нет прав.",
"options": "Опции",
"owner": "Владелец",
"password": "Пароль",
"path_content": "Содержимое",
"pattern_error_slashes": "Шаблон не должен содержать косую черту.",
"permission_change_error": "Права не могут быть изменены: ",
"permission_change_success": "Права успешно изменены.",
"permission_parse_error": "Не удалось разобрать права.",
"permissions": "Права",
"refresh": "Обновить",
"rename": "Переименовать",
"rename_filename": "Переименовать файл -",
"request": "Запрос",
"response": "Ответ",
"save": "Сохранить и выйти",
"save_wo_close": "Сохранить",
"search": "Поиск",
"search_pattern": "Шаблон",
"select_destination": "Выберите назначение",
"size": "Размер",
"soft_tabs": "Пробелы вместо табуляции",
"tab_size": "Размер табов",
"tasks": "Задачи",
"remaining_tasks": "Есть оставшиеся задачи. Вы действительно хотите перезагрузить?",
"toggle_nav": "Переключить вид",
"upload": "Загрузить",
"upload_drop": "Перетащите файлы для загрузки",
"upload_file": "Загрузить файл",
"upload_remote": "Удаленная загрузка",
"upload_remote_url": "Удаленная загрузка по URL",
"username": "Имя пользователя",
"word_wrap": "Перенос строк"
}
f00bar;
$i18n["ru"] = json_decode( $i18n["ru"], true );
$this->i18n = $i18n;
if( in_array( $this->config['language'], array_keys( $this->i18n ) ) )
// Merge english with the language in case of missing keys
$this->l = array_merge($this->i18n['en'], $this->i18n[$this->config['language']]);
else
$this->l = $this->i18n['en'];
if ($this->config['timezone'])
date_default_timezone_set($this->config['timezone']);
}
/**
* This function contains the client-side application
*/
public function getApplication() {
$this->getHTMLHeader();
print '';
$this->getJS();
print '';
$this->getHTMLFooter();
}
public function getInlineApplication() {
$this->getCSS();
print '';
$this->getJS();
}
public function getCSS() {
print '
';
}
public function getJS() {
echo <<<'f00bar'
f00bar;
}
public function getHTMLHeader() {
print '
IFM - improved file manager
';
$this->getCSS();
print '';
}
public function getHTMLFooter() {
print '';
}
/*
main functions
*/
private function handleRequest() {
if( $_REQUEST["api"] == "getRealpath" ) {
if( isset( $_REQUEST["dir"] ) && $_REQUEST["dir"] != "" )
$this->jsonResponse( array( "realpath" => $this->getValidDir( $_REQUEST["dir"] ) ) );
else
$this->jsonResponse( array( "realpath" => "" ) );
}
elseif( $_REQUEST["api"] == "getFiles" ) {
if( isset( $_REQUEST["dir"] ) && $this->isPathValid( $_REQUEST["dir"] ) )
$this->getFiles( $_REQUEST["dir"] );
else
$this->getFiles( "" );
}
elseif( $_REQUEST["api"] == "getConfig" ) {
$this->getConfig();
}
elseif( $_REQUEST["api"] == "getFolders" ) {
$this->getFolders( $_REQUEST );
} elseif( $_REQUEST["api"] == "getTemplates" ) {
$this->jsonResponse( $this->templates );
} elseif( $_REQUEST["api"] == "getI18N" ) {
$this->jsonResponse( $this->l );
} elseif( $_REQUEST["api"] == "logout" ) {
unset( $_SESSION['ifmauth'] );
session_destroy();
header( "Location: " . strtok( $_SERVER["REQUEST_URI"], '?' ) );
exit( 0 );
} else {
if( isset( $_REQUEST["dir"] ) && $this->isPathValid( $_REQUEST["dir"] ) ) {
$this->chDirIfNecessary( $_REQUEST['dir'] );
switch( $_REQUEST["api"] ) {
case "createDir": $this->createDir( $_REQUEST["dir"], $_REQUEST["dirname"] ); break;
case "saveFile": $this->saveFile( $_REQUEST ); break;
case "getContent": $this->getContent( $_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;
case "upload": $this->uploadFile( $_REQUEST ); break;
case "copyMove": $this->copyMove( $_REQUEST ); break;
case "changePermissions": $this->changePermissions( $_REQUEST ); break;
case "zipnload": $this->zipnload( $_REQUEST); break;
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
case "searchItems": $this->searchItems( $_REQUEST ); break;
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
case "createArchive": $this->createArchive( $_REQUEST ); break;
case "proxy": $this->downloadFile( $_REQUEST, false ); break;
default:
$this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
break;
}
} else {
print $this->jsonResponse( array( "status" => "ERROR", "message" => "Invalid working directory" ) );
}
}
exit( 0 );
}
public function run( $mode="standalone" ) {
if ( $this->checkAuth() ) {
// go to our root_dir
if( ! is_dir( realpath( $this->config['root_dir'] ) ) || ! is_readable( realpath( $this->config['root_dir'] ) ) )
die( "Cannot access root_dir.");
else
chdir( realpath( $this->config['root_dir'] ) );
$this->mode = $mode;
if( isset( $_REQUEST['api'] ) || $mode == "api" ) {
$this->handleRequest();
} elseif( $mode == "standalone" ) {
$this->getApplication();
} else {
$this->getInlineApplication();
}
}
}
/*
api functions
*/
private function getFiles( $dir ) {
$this->chDirIfNecessary( $dir );
unset( $files ); unset( $dirs ); $files = array(); $dirs = array();
if( $handle = opendir( "." ) ) {
while( false !== ( $result = readdir( $handle ) ) ) {
if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && $this->getScriptRoot() == getcwd() ) { }
elseif( ( $result == ".htaccess" || $result==".htpasswd" ) && $this->config['showhtdocs'] != 1 ) {}
elseif( $result == "." ) {}
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
else {
$item = $this->getItemInformation( $result );
if( $item['type'] == "dir" ) $dirs[] = $item;
else $files[] = $item;
}
}
closedir( $handle );
}
usort( $dirs, array( $this, "sortByName" ) );
usort( $files, array( $this, "sortByName" ) );
$this->jsonResponse( array_merge( $dirs, $files ) );
}
private function getItemInformation( $name ) {
$item = array();
$item["name"] = $name;
if( is_dir( $name ) ) {
$item["type"] = "dir";
if( $name == ".." )
$item["icon"] = "icon icon-up-open";
else
$item["icon"] = "icon icon-folder-empty";
} else {
$item["type"] = "file";
if( in_array( substr( $name, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
$type = substr( $name, -6 );
elseif( substr( $name, -8 ) == ".tar.bz2" )
$type = "tar.bz2";
else
$type = substr( strrchr( $name, "." ), 1 );
$item["icon"] = $this->getTypeIcon( $type );
$item["ext"] = strtolower($type);
if( !$this->config['disable_mime_detection'] )
$item["mime_type"] = mime_content_type( $name );
}
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = filemtime( $name ); }
if( $this->config['showfilesize'] == 1 ) {
if( $item['type'] == "dir" ) {
$item['size_raw'] = 0;
$item['size'] = "";
} else {
$item["size_raw"] = filesize( $name );
if( $item["size_raw"] > 1073741824 ) $item["size"] = round( ( $item["size_raw"]/1073741824 ), 2 ) . " GB";
elseif($item["size_raw"]>1048576)$item["size"] = round( ( $item["size_raw"]/1048576 ), 2 ) . " MB";
elseif($item["size_raw"]>1024)$item["size"] = round( ( $item["size_raw"]/1024 ), 2 ) . " KB";
else $item["size"] = $item["size_raw"] . " Byte";
}
}
if( $this->config['showpermissions'] > 0 ) {
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $name ) ), -3 );
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $name ) );
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
}
if( $this->config['showowner'] == 1 ) {
if ( function_exists( "posix_getpwuid" ) && fileowner($name) !== false ) {
$ownerarr = posix_getpwuid( fileowner( $name ) );
$item["owner"] = $ownerarr['name'];
} else $item["owner"] = false;
}
if( $this->config['showgroup'] == 1 ) {
if( function_exists( "posix_getgrgid" ) && filegroup( $name ) !== false ) {
$grouparr = posix_getgrgid( filegroup( $name ) );
$item["group"] = $grouparr['name'];
} else $item["group"] = false;
}
return $item;
}
private function getConfig() {
$ret = $this->config;
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
$ret['isDocroot'] = ($this->getRootDir() == $this->getScriptRoot());
foreach (array("auth_source", "root_dir") as $field) {
unset($ret[$field]);
}
$this->jsonResponse($ret);
}
private function getFolders( $d ) {
if( ! isset( $d['dir'] ) )
$d['dir'] = $this->getRootDir();
if( ! $this->isPathValid( $d['dir'] ) )
echo "[]";
else {
$ret = array();
foreach( glob( $this->pathCombine( $d['dir'], "*" ), GLOB_ONLYDIR ) as $dir ) {
array_push( $ret, array(
"text" => htmlspecialchars( basename( $dir ) ),
"lazyLoad" => true,
"dataAttr" => array( "path" => $dir )
));
}
sort( $ret );
if( $this->getScriptRoot() == realpath( $d['dir'] ) )
$ret = array_merge(
array(
0 => array(
"text" => "/ [root]",
"dataAttr" => array( "path" => $this->getRootDir() )
)
),
$ret
);
$this->jsonResponse( $ret );
}
}
private function searchItems( $d ) {
if( $this->config['search'] != 1 ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
return;
}
if( strpos( $d['pattern'], '/' ) !== false ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['pattern_error_slashes'] ) );
exit( 1 );
}
try {
$results = $this->searchItemsRecursive( $d['pattern'] );
$this->jsonResponse( $results );
} catch( Exception $e ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['error'] . " " . $e->getMessage() ) );
}
}
private function searchItemsRecursive( $pattern, $dir="" ) {
$items = array();
$dir = $dir ? $dir : '.';
foreach( glob( $this->pathCombine( $dir, $pattern ) ) as $result ) {
array_push( $items, $this->getItemInformation( $result ) );
}
foreach( glob( $this->pathCombine( $dir, '*') , GLOB_ONLYDIR ) as $subdir ) {
$items = array_merge( $items, $this->searchItemsRecursive( $pattern, $subdir ) );
}
return $items;
}
private function getFolderTree( $d ) {
$this->jsonResponse(
array_merge(
array(
0 => array(
"text" => "/ [root]",
"nodes" => array(),
"dataAttributes" => array( "path" => $this->getRootDir() )
)
),
$this->getFolderTreeRecursive( $d['dir'] )
)
);
}
private function getFolderTreeRecursive( $start_dir ) {
$ret = array();
$start_dir = realpath( $start_dir );
if( $handle = opendir( $start_dir ) ) {
while (false !== ( $result = readdir( $handle ) ) ) {
if( is_dir( $this->pathCombine( $start_dir, $result ) ) && $result != "." && $result != ".." ) {
array_push(
$ret,
array(
"text" => htmlspecialchars( $result ),
"dataAttributes" => array(
"path" => $this->pathCombine( $start_dir, $result )
),
"nodes" => $this->getFolderTreeRecursive( $this->pathCombine( $start_dir, $result ) )
)
);
}
}
}
sort( $ret );
return $ret;
}
private function copyMove( $d ) {
if( $this->config['copymove'] != 1 ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
exit( 1 );
}
if( ! isset( $d['destination'] ) || ! $this->isPathValid( realpath( $d['destination'] ) ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_dir'] ) );
exit( 1 );
}
if( ! is_array( $d['filenames'] ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_params'] ) );
exit( 1 );
}
if( ! in_array( $d['action'], array( 'copy', 'move' ) ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_action'] ) );
exit( 1 );
}
$err = array(); $errFlag = -1; // -1 -> all errors; 0 -> at least some errors; 1 -> no errors
foreach( $d['filenames'] as $file ) {
if( ! file_exists( $file ) || $file == ".." || ! $this->isFilenameValid( $file ) ) {
array_push( $err, $file );
}
if( $d['action'] == "copy" ) {
if( $this->xcopy( $file, $d['destination'] ) )
$errFlag = 0;
else
array_push( $err, $file );
} elseif( $d['action'] == "move" ) {
if( rename( $file, $this->pathCombine( $d['destination'], basename( $file ) ) ) )
$errFlag = 0;
else
array_push( $err, $file );
}
}
$action = ( $d['action'] == "copy" ? "copied" : "moved" );
if( empty( $err ) ) {
$this->jsonResponse( array( "status" => "OK", "message" => ( $d['action'] == "copy" ? $this->l['copy_success'] : $this->l['move_success'] ), "errflag" => "1" ) );
}
else {
$errmsg = ( $d['action'] == "copy" ? $this->l['copy_error'] : $this->l['move_error'] ) . "";
foreach( $err as $item )
$errmsg .= "- ".$item."
";
$errmsg .= "
";
$this->jsonResponse( array( "status" => "OK", "message" => $errmsg, "flag" => $errFlag ) );
}
}
// creates a directory
private function createDir($w, $dn) {
if( $this->config['createdir'] != 1 ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
exit( 1 );
}
if( $dn == "" )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_dir'] ) );
elseif( ! $this->isFilenameValid( $dn ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_dir'] ) );
else {
if( @mkdir( $dn ) )
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['folder_create_success'] ) );
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['folder_create_error'] ) );
}
}
// 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 ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
exit( 1 );
}
if( isset( $d['filename'] ) && $this->isFilenameValid( $d['filename'] ) ) {
if( isset( $d['content'] ) ) {
// work around magic quotes
$content = get_magic_quotes_gpc() == 1 ? stripslashes( $d['content'] ) : $d['content'];
if( @file_put_contents( $d['filename'], $content ) !== false ) {
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_save_success'] ) );
} else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_save_error'] ) );
} else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_save_error'] ) );
} else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
}
// 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 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['npermissions'] ) );
else {
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 );
$this->jsonResponse( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
} else $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_not_found'] ) );
}
}
// deletes a bunch of files or directories
private function deleteFiles( array $d ) {
if( $this->config['delete'] != 1 ) $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
else {
$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 ) ) {
$res = $this->rec_rmdir( $file );
if( $res != 0 )
array_push( $err, $file );
else
$errFLAG = 0;
} else {
if( @unlink($file) )
$errFLAG = 0;
else
array_push($err, $file);
}
} else {
array_push( $err, $file );
}
}
if( empty( $err ) ) {
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_delete_success'], "errflag" => "1" ) );
}
else {
$errmsg = $this->l['file_delete_error'] . "";
foreach($err as $item)
$errmsg .= "- ".$item."
";
$errmsg .= "
";
$this->jsonResponse( array( "status" => "ERROR", "message" => $errmsg, "flag" => $errFLAG ) );
}
}
}
// renames a file
private function renameFile( array $d ) {
if( $this->config['rename'] != 1 ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
} elseif( ! $this->isFilenameValid( $d['filename'] ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
} elseif( ! $this->isFilenameValid( $d['newname'] ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
} else {
if( strpos( $d['newname'], '/' ) !== false )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['filename_slashes'] ) );
elseif( $this->config['showhtdocs'] != 1 && ( substr( $d['newname'], 0, 3) == ".ht" || substr( $d['filename'], 0, 3 ) == ".ht" ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
elseif( $this->config['showhiddenfiles'] != 1 && ( substr( $d['newname'], 0, 1) == "." || substr( $d['filename'], 0, 1 ) == "." ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
else {
if( @rename( $d['filename'], $d['newname'] ) )
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_rename_success'] ) );
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_rename_error'] ) );
}
}
}
// provides a file for downloading
private function downloadFile( array $d, $forceDL=true ) {
if( $this->config['download'] != 1 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
elseif( ! $this->isFilenameValid( $d['filename'] ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
elseif( $this->config['showhtdocs'] != 1 && ( substr( $d['filename'], 0, 3 ) == ".ht" || substr( $d['filename'],0,3 ) == ".ht" ) )
$this->jsonResponse( array( "status" => "ERROR", "message"=> $this->l['nopermissions'] ) );
elseif( $this->config['showhiddenfiles'] != 1 && ( substr( $d['filename'], 0, 1 ) == "." || substr( $d['filename'],0,1 ) == "." ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
else {
if( ! is_file( $d['filename' ] ) )
http_response_code( 404 );
else
$this->fileDownload( array( "file" => $d['filename'], "forceDL" => $forceDL ) );
}
}
// extracts a zip-archive
private function extractFile( array $d ) {
$restoreIFM = false;
$tmpSelfContent = null;
$tmpSelfChecksum = null;
if( $this->config['extract'] != 1 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
else {
if( ! file_exists( $d['filename'] ) ) {
$this->jsonResponse( array( "status" => "ERROR","message" => $this->l['invalid_filename'] ) );
exit( 1 );
}
if( ! isset( $d['targetdir'] ) || trim( $d['targetdir'] ) == "" )
$d['targetdir'] = "./";
if( ! $this->isPathValid( $d['targetdir'] ) ) {
$this->jsonResponse( array( "status" => "ERROR","message" => $this->l['invalid_dir'] ) );
exit( 1 );
}
if( ! is_dir( $d['targetdir'] ) && ! mkdir( $d['targetdir'], 0777, true ) ) {
$this->jsonResponse( array( "status" => "ERROR","message" => $this->l['folder_create_error'] ) );
exit( 1 );
}
if( realpath( $d['targetdir'] ) == substr( $this->getScriptRoot(), 0, strlen( realpath( $d['targetdir'] ) ) ) ) {
$tmpSelfContent = tmpfile();
fwrite( $tmpSelfContent, file_get_contents( __FILE__ ) );
$tmpSelfChecksum = hash_file( "sha256", __FILE__ );
$restoreIFM = true;
}
if( substr( strtolower( $d['filename'] ), -4 ) == ".zip" ) {
if( ! IFMArchive::extractZip( $d['filename'], $d['targetdir'] ) ) {
$this->jsonResponse( array( "status" => "ERROR","message" => $this->l['extract_error'] ) );
} else {
$this->jsonResponse( array( "status" => "OK","message" => $this->l['extract_success'] ) );
}
} else {
if( ! IFMArchive::extractTar( $d['filename'], $d['targetdir'] ) ) {
$this->jsonResponse( array( "status" => "ERROR","message" => $this->l['extract_error'] ) );
} else {
$this->jsonResponse( array( "status" => "OK","message" => $this->l['extract_success'] ) );
}
}
if( $restoreIFM ) {
if( $tmpSelfChecksum != hash_file( "sha256", __FILE__ ) ) {
rewind( $tmpSelfContent );
$fh = fopen( __FILE__, "w" );
while( ! feof( $tmpSelfContent ) ) {
fwrite( $fh, fread( $tmpSelfContent, 8196 ) );
}
fclose( $fh );
}
fclose( $tmpSelfContent );
}
}
}
// uploads a file
private function uploadFile( array $d ) {
if( $this->config['upload'] != 1 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
elseif( !isset( $_FILES['file'] ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_upload_error'] ) );
else {
$newfilename = ( isset( $d["newfilename"] ) && $d["newfilename"]!="" ) ? $d["newfilename"] : $_FILES['file']['name'];
if( ! $this->isFilenameValid( $newfilename ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
else {
if( $_FILES['file']['tmp_name'] ) {
if( is_writable( getcwd( ) ) ) {
if( move_uploaded_file( $_FILES['file']['tmp_name'], $newfilename ) )
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_upload_success'], "cd" => $d['dir'] ) );
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_upload_error'] ) );
}
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_upload_error'] ) );
} else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_not_found'] ) );
}
}
}
// change permissions of a file
private function changePermissions( array $d ) {
if( $this->config['chmod'] != 1 ) $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
elseif( ! isset( $d["chmod"] )||$d['chmod']=="" ) $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['permission_parse_error'] ) );
elseif( ! $this->isPathValid( $this->pathCombine( $d['dir'],$d['filename'] ) ) ) { $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) ); }
else {
$chmod = $d["chmod"]; $cmi = true;
if( ! is_numeric( $chmod ) ) {
$cmi = false;
$chmod = str_replace( " ","",$chmod );
if( strlen( $chmod )==9 ) {
$cmi = true;
$arr = array( substr( $chmod,0,3 ),substr( $chmod,3,3 ),substr( $chmod,6,3 ) );
$chtmp = "0";
foreach( $arr as $right ) {
$rtmp = 0;
if( substr( $right,0,1 )=="r" ) $rtmp = $rtmp + 4; elseif( substr( $right,0,1 )<>"-" ) $cmi = false;
if( substr( $right,1,1 )=="w" ) $rtmp = $rtmp + 2; elseif( substr( $right,1,1 )<>"-" ) $cmi = false;
if( substr( $right,2,1 )=="x" ) $rtmp = $rtmp + 1; elseif( substr( $right,2,1 )<>"-" ) $cmi = false;
$chtmp = $chtmp . $rtmp;
}
$chmod = intval( $chtmp );
}
}
else $chmod = "0" . $chmod;
if( $cmi ) {
try {
chmod( $d["filename"], (int)octdec( $chmod ) );
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['permission_change_success'] ) );
} catch ( Exception $e ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['permission_change_error'] ) );
}
}
else $this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['permission_parse_error'] ) );
}
}
// zips a directory and provides it for downloading
// 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 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermission'] ) );
else {
if( ! file_exists( $d['filename'] ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['folder_not_found'] ) );
elseif (!$this->isPathValid($d['filename']))
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_dir'] ) );
elseif ($d['filename'] != "." && !$this->isFilenameValid($d['filename']))
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
else {
unset( $zip );
if ($this->isAbsolutePath($this->config['tmp_dir']))
$dfile = $this->pathCombine( $this->config['tmp_dir'], uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename
else
$dfile = $this->pathCombine( __DIR__, $this->config['tmp_dir'], uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename
try {
IFMArchive::createZip(realpath($d['filename']), $dfile, array($this, 'isFilenameValid'));
if( $d['filename'] == "." ) {
if( getcwd() == $this->getScriptRoot() )
$d['filename'] = "root";
else
$d['filename'] = basename( getcwd() );
}
$this->fileDownload( array( "file" => $dfile, "name" => $d['filename'] . ".zip", "forceDL" => true ) );
} catch ( Exception $e ) {
echo $this->l['error'] . " " . $e->getMessage();
} finally {
if( file_exists( $dfile ) ) @unlink( $dfile );
}
}
}
}
// uploads a file from an other server using the curl extention
private function remoteUpload( array $d ) {
if( $this->config['remoteupload'] != 1 )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
elseif( !isset( $d['method'] ) || !in_array( $d['method'], array( "curl", "file" ) ) )
$this->jsonResponse( array( "status" => "error", "message" => $this->l['invalid_params'] ) );
elseif( $d['method']=="curl" && $this->checkCurl( ) == false )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['error']." cURL extention not installed." ) );
elseif( $d['method']=="curl" && $this->checkCurl( ) == true ) {
$filename = ( isset( $d['filename'] )&&$d['filename']!="" )?$d['filename']:"curl_".uniqid( );
$ch = curl_init( );
if( $ch ) {
if( $this->isFilenameValid( $filename ) == false )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
elseif( filter_var( $d['url'], FILTER_VALIDATE_URL ) === false )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_url'] ) );
else {
$fp = fopen( $filename, "w" );
if( $fp ) {
if( !curl_setopt( $ch, CURLOPT_URL, urldecode( $d['url'] ) ) || !curl_setopt( $ch, CURLOPT_FILE, $fp ) || !curl_setopt( $ch, CURLOPT_HEADER, 0 ) || !curl_exec( $ch ) )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['error']." ".curl_error( $ch ) ) );
else {
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_upload_success'] ) );
}
curl_close( $ch );
fclose( $fp );
} else {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['file_open_error'] ) );
}
}
} else {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['error']." curl init" ) );
}
}
elseif( $d['method']=='file' ) {
$filename = ( isset( $d['filename'] ) && $d['filename']!="" ) ? $d['filename'] : "curl_".uniqid( );
if( $this->isFilenameValid( $filename ) == false )
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
else {
try {
file_put_contents( $filename, file_get_contents( $d['url'] ) );
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['file_upload_success'] ) );
} catch( Exception $e ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['error'] . " " . $e->getMessage() ) );
}
}
}
else
$this->jsonResponse( array( "status" => "error", "message" => $this->l['invalid_params'] ) );
}
private function createArchive( $d ) {
if( $this->config['createarchive'] != 1 ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['nopermissions'] ) );
return false;
}
if( ! $this->isFilenameValid( $d['archivename'] ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
return false;
}
$filenames = array();
foreach( $d['filenames'] as $file )
if( ! $this->isFilenameValid( $file ) ) {
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['invalid_filename'] ) );
exit( 1 );
} else
array_push( $filenames, realpath( $file ) );
switch( $d['format'] ) {
case "zip":
if( IFMArchive::createZip( $filenames, $d['archivename'] ) )
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['archive_create_success'] ) );
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['archive_create_error'] ) );
break;
case "tar":
case "tar.gz":
case "tar.bz2":
if( IFMArchive::createTar( $filenames, $d['archivename'], $d['format'] ) )
$this->jsonResponse( array( "status" => "OK", "message" => $this->l['archive_create_success'] ) );
else
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['archive_create_error'] ) );
break;
default:
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['archive_invalid_format'] ) );
break;
}
}
/*
help functions
*/
private function log( $d ) {
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 ) {
$this->convertToUTF8( $array );
$json = json_encode( $array );
if( $json === false ) {
switch(json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
$this->jsonResponse( array( "status" => "ERROR", "message" => $this->l['json_encode_error'] . " " . $err ) );
} else {
echo $json;
}
}
private function convertToUTF8( &$item ) {
if( is_array( $item ) )
array_walk(
$item,
array( $this, 'convertToUTF8' )
);
else
if( function_exists( "mb_check_encoding" ) && ! mb_check_encoding( $item, "UTF-8" ) )
$item = utf8_encode( $item );
}
function checkAuth() {
if( $this->config['auth'] == 0 )
return true;
if( isset( $_SERVER['HTTP_X_IFM_AUTH'] ) && ! empty( $_SERVER['HTTP_X_IFM_AUTH'] ) ) {
$cred = explode( ":", base64_decode( str_replace( "Basic ", "", $_SERVER['HTTP_X_IFM_AUTH'] ) ) );
if( count( $cred ) == 2 && $this->checkCredentials( $cred[0], $cred[1] ) )
return true;
}
if( session_status() !== PHP_SESSION_ACTIVE ) {
if( isset( $this->config['session_lifetime'] ) )
ini_set( 'session.gc_maxlifetime', $this->config['session_lifetime'] );
if( isset( $this->config['force_session_lifetime'] ) && $this->config['force_session_lifetime'] ) {
ini_set( 'session.gc_divisor', 1 );
ini_set( 'session.gc_probability', 1 );
}
session_start();
}
if( ! isset( $_SESSION['ifmauth'] ) || $_SESSION['ifmauth'] !== true ) {
$login_failed = false;
if( isset( $_POST["inputLogin"] ) && isset( $_POST["inputPassword"] ) ) {
if( $this->checkCredentials( $_POST["inputLogin"], $_POST["inputPassword"] ) ) {
$_SESSION['ifmauth'] = true;
}
else {
$_SESSION['ifmauth'] = false;
$login_failed = true;
}
}
if( isset( $_SESSION['ifmauth'] ) && $_SESSION['ifmauth'] === true ) {
return true;
} else {
if( isset( $_POST["api"] ) ) {
if( $login_failed === true )
$this->jsonResponse( array( "status"=>"ERROR", "message"=>"authentication failed" ) );
else
$this->jsonResponse( array( "status"=>"ERROR", "message"=>"not authenticated" ) );
} else {
$this->loginForm($login_failed);
}
return false;
}
} else {
return true;
}
}
private function checkCredentials( $user, $pass ) {
list( $src, $srcopt ) = explode( ";", $this->config['auth_source'], 2 );
switch( $src ) {
case "inline":
list( $uname, $hash ) = explode( ":", $srcopt );
$htpasswd = new Htpasswd();
return $htpasswd->verifyPassword( $pass, $hash ) ? ( $uname == $user ) : false;
break;
case "file":
if( @file_exists( $srcopt ) && @is_readable( $srcopt ) ) {
$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;
case "ldap":
$authenticated = false;
$ldapopts = explode( ";", $srcopt );
if( count( $ldapopts ) === 3 ) {
list( $ldap_server, $rootdn, $ufilter ) = explode( ";", $srcopt );
} else {
list( $ldap_server, $rootdn ) = explode( ";", $srcopt );
$ufilter = false;
}
$u = "uid=" . $user . "," . $rootdn;
if( ! $ds = ldap_connect( $ldap_server ) ) {
trigger_error( "Could not reach the ldap server.", E_USER_ERROR );
return false;
}
ldap_set_option( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 );
if( $ds ) {
$ldbind = @ldap_bind( $ds, $u, $pass );
if( $ldbind ) {
if( $ufilter ) {
if( ldap_count_entries( $ds, ldap_search( $ds, $rootdn, $ufilter ) ) > 0 ){
$authenticated = true;
} else {
trigger_error( "User not allowed.", E_USER_ERROR );
$authenticated = false;
}
} else {
$authenticated = true;
}
} else {
trigger_error( ldap_error( $ds ), E_USER_ERROR );
$authenticated = false;
}
ldap_unbind( $ds );
} else
$authenticated = false;
return $authenticated;
break;
}
return false;
}
private function loginForm($loginFailed=false, $loginMessage="") {
$err = "";
if( $loginFailed )
$err = ''.$loginMessage.'
';
$this->getHTMLHeader();
$html = str_replace( "{{error}}", $err, $this->templates['login'] );
$html = str_replace( "{{i18n.username}}", $this->l['username'], $html );
$html = str_replace( "{{i18n.password}}", $this->l['password'], $html );
$html = str_replace( "{{i18n.login}}", $this->l['login'], $html );
print $html;
$this->getHTMLFooter();
}
private function filePermsDecode( $perms ) {
$oct = str_split( strrev( decoct( $perms ) ), 1 );
$masks = array( '---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx' );
return(
sprintf(
'%s %s %s',
array_key_exists( $oct[ 2 ], $masks ) ? $masks[ $oct[ 2 ] ] : '###',
array_key_exists( $oct[ 1 ], $masks ) ? $masks[ $oct[ 1 ] ] : '###',
array_key_exists( $oct[ 0 ], $masks ) ? $masks[ $oct[ 0 ] ] : '###')
);
}
private function isAbsolutePath( $path ) {
if( $path === null || $path === '' )
return false;
return $path[0] === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i',$path) > 0;
}
private function getRootDir() {
if( $this->config['root_dir'] == "" )
return realpath( $this->getScriptRoot() );
elseif( $this->isAbsolutePath( $this->config['root_dir'] ) )
return realpath( $this->config['root_dir'] );
else
return realpath( $this->pathCombine( $this->getScriptRoot(), $this->config['root_dir'] ) );
}
private function getScriptRoot() {
return ( defined( 'IFM_FILENAME' ) ? dirname( realpath( IFM_FILENAME ) ) : dirname( __FILE__ ) );
}
private function getValidDir( $dir ) {
if( ! $this->isPathValid( $dir ) || ! is_dir( $dir ) )
return "";
else {
$rpDir = realpath( $dir );
$rpConfig = $this->getRootDir();
if( $rpConfig == "/" )
return $rpDir;
elseif( $rpDir == $rpConfig )
return "";
else {
$part = substr( $rpDir, strlen( $rpConfig ) );
$part = ( in_array( substr( $part, 0, 1 ), ["/", "\\"] ) ) ? substr( $part, 1 ) : $part;
return $part;
}
}
}
private function isPathValid( $dir ) {
/**
* This function is also used to check non-existent paths, but the PHP realpath function returns false for
* nonexistent paths. Hence we need to check the path manually in the following lines.
*/
$tmp_d = $dir;
$tmp_missing_parts = array();
while( realpath( $tmp_d ) === false ) {
$tmp_i = pathinfo( $tmp_d );
array_push( $tmp_missing_parts, $tmp_i['filename'] );
$tmp_d = dirname( $tmp_d );
if( $tmp_d == dirname( $tmp_d ) ) break;
}
$rpDir = $this->pathCombine( realpath( $tmp_d ), implode( "/", array_reverse( $tmp_missing_parts ) ) );
$rpConfig = $this->getRootDir();
if( ! is_string( $rpDir ) || ! is_string( $rpConfig ) ) // can happen if open_basedir is in effect
return false;
elseif( $rpDir == $rpConfig )
return true;
elseif( 0 === strpos( $rpDir, $rpConfig ) )
return true;
else
return false;
}
private function chDirIfNecessary($d) {
if( substr( getcwd(), strlen( $this->getScriptRoot() ) ) != $this->getValidDir($d) && !empty( $d ) ) {
chdir( $d );
}
}
private function getTypeIcon( $type ) {
$type = strtolower($type);
switch( $type ) {
case "aac": case "aiff": case "mid": case "mp3": case "wav": return 'icon icon-file-audio'; break;
case "ai": case "bmp": case "eps": case "tiff": case "gif": case "jpg": case "jpeg": case "png": case "psd": case "svg": return 'icon icon-file-image'; break;
case "avi": case "flv": case "mp4": case "mpg": case "mkv": case "mpeg": case "webm": case "wmv": case "mov": return 'icon icon-file-video'; break;
case "c": case "cpp": case "css": case "dat": case "h": case "html": case "java": case "js": case "php": case "py": case "sql": case "xml": case "yml": case "json": return 'icon icon-file-code'; break;
case "doc": case "docx": case "odf": case "odt": case "rtf": return 'icon icon-file-word'; break;
case "txt": case "log": return 'icon icon-doc-text'; break;
case "ods": case "xls": case "xlsx": return 'icon icon-file-excel'; break;
case "odp": case "ppt": case "pptx": return 'icon icon-file-powerpoint'; break;
case "pdf": return 'icon icon-file-pdf'; break;
case "tgz": case "zip": case "tar": case "tgz": case "tar.gz": case "tar.xz": case "tar.bz2": case "7z": case "rar": return 'icon icon-file-archive';
default: return 'icon icon-doc';
}
}
private function rec_rmdir( $path ) {
if( !is_dir( $path ) ) {
return -1;
}
$dir = @opendir( $path );
if( !$dir ) {
return -2;
}
while( ( $entry = @readdir( $dir ) ) !== false ) {
if( $entry == '.' || $entry == '..' ) continue;
if( is_dir( $path . '/' . $entry ) ) {
$res = $this->rec_rmdir( $path . '/' . $entry );
if( $res == -1 ) { @closedir( $dir ); return -2; }
else if( $res == -2 ) { @closedir( $dir ); return -2; }
else if( $res == -3 ) { @closedir( $dir ); return -3; }
else if( $res != 0 ) { @closedir( $dir ); return -2; }
} else if( is_file( $path . '/' . $entry ) || is_link( $path . '/' . $entry ) ) {
$res = @unlink( $path . '/' . $entry );
if( !$res ) { @closedir( $dir ); return -2; }
} else { @closedir( $dir ); return -3; }
}
@closedir( $dir );
$res = @rmdir( $path );
if( !$res ) { return -2; }
return 0;
}
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 ) ) );
chdir( $source );
foreach( glob( '*' ) as $item )
$this->xcopy( $item, $dest );
chdir( '..' );
return true;
}
// combines two parts to a valid path
private function pathCombine(...$parts) {
$ret = "";
foreach($parts as $part)
if (trim($part) != "")
$ret .= (empty($ret)?rtrim($part,"/"):trim($part, '/'))."/";
return rtrim($ret, "/");
}
// check if filename is allowed
public function isFilenameValid( $f ) {
if( ! $this->isFilenameAllowed( $f ) )
return false;
if( strtoupper( substr( PHP_OS, 0, 3 ) ) == "WIN" ) {
// windows-specific limitations
foreach( array( '\\', '/', ':', '*', '?', '"', '<', '>', '|' ) as $char )
if( strpos( $f, $char ) !== false )
return false;
} else {
// *nix-specific limitations
foreach( array( '/', '\0' ) as $char )
if( strpos( $f, $char ) !== false )
return false;
}
// custom limitations
foreach( $this->config['forbiddenChars'] as $char )
if( strpos( $f, $char ) !== false )
return false;
return true;
}
private function isFilenameAllowed( $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->config['selfoverwrite'] != 1 && getcwd() == $this->getScriptRoot() && $f == basename( __FILE__ ) )
return false;
else
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( array $options ) {
if( ! isset( $options['name'] ) || trim( $options['name'] ) == "" )
$options['name'] = basename( $options['file'] );
if( isset( $options['forceDL'] ) && $options['forceDL'] ) {
$content_type = "application/octet-stream";
header( 'Content-Disposition: attachment; filename="' . $options['name'] . '"' );
} else {
$content_type = mime_content_type( $options['file'] );
}
// This header was quite some time present, but I don't know why...
//header( 'Content-Description: File Transfer' );
header( 'Content-Type: ' . $content_type );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate' );
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize( $options['file'] ) );
$file_stream = fopen( $options['file'], 'rb' );
$stdout_stream = fopen('php://output', 'wb');
stream_copy_to_stream($file_stream, $stdout_stream);
fclose($file_stream);
fclose($stdout_stream);
}
}
/**
* =======================================================================
* Improved File Manager
* ---------------------
* License: This project is provided under the terms of the MIT LICENSE
* http://github.com/misterunknown/ifm/blob/master/LICENSE
* =======================================================================
*
* archive class
*
* This class provides support for various archive types for the IFM. It can
* create and extract the following formats:
* * zip
* * tar
* * tar.gz
* * tar.bz2
*/
class IFMArchive {
/**
* Add a folder to an archive
*/
private static function addFolder(&$archive, $folder, $offset=0, $exclude_callback=null) {
if ($offset == 0)
$offset = strlen(dirname($folder)) + 1;
$archive->addEmptyDir(substr($folder, $offset));
$handle = opendir($folder);
while (false !== $f = readdir($handle)) {
if ($f != '.' && $f != '..') {
$filePath = $folder . '/' . $f;
if (file_exists($filePath) && is_readable($filePath)) {
if (is_file($filePath)) {
if (!is_callable($exclude_callback) || $exclude_callback($f))
$archive->addFile( $filePath, substr( $filePath, $offset ) );
} elseif (is_dir($filePath)) {
if (is_callable($exclude_callback))
self::addFolder($archive, $filePath, $offset, $exclude_callback);
else
self::addFolder($archive, $filePath, $offset);
}
}
}
}
closedir($handle);
}
/**
* Create a zip file
*/
public static function createZip($src, $out, $exclude_callback=null) {
$a = new ZipArchive();
$a->open($out, ZIPARCHIVE::CREATE);
if (!is_array($src))
$src = array($src);
foreach ($src as $s)
if (is_dir($s))
if (is_callable($exclude_callback))
self::addFolder( $a, $s, null, $exclude_callback );
else
self::addFolder( $a, $s );
elseif (is_file($s))
if (!is_callable($exclude_callback) || $exclude_callback($s))
$a->addFile($s, substr($s, strlen(dirname($s)) + 1));
try {
return $a->close();
} catch (Exception $e) {
return false;
}
}
/**
* Unzip a zip file
*/
public static function extractZip($file, $destination="./") {
if (!file_exists($file))
return false;
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === true) {
$zip->extractTo($destination);
$zip->close();
return true;
} else
return false;
}
/**
* Creates a tar archive
*/
public static function createTar($src, $out, $t) {
$tmpf = substr($out, 0, strlen($out) - strlen($t)) . "tar";
$a = new PharData($tmpf);
try {
if (!is_array($src))
$src = array($src);
foreach ($src as $s)
if (is_dir($s))
self::addFolder($a, $s);
elseif (is_file($s))
$a->addFile($s, substr($s, strlen(dirname($s)) +1));
switch ($t) {
case "tar.gz":
$a->compress(Phar::GZ);
@unlink($tmpf);
break;
case "tar.bz2":
$a->compress(Phar::BZ2);
@unlink($tmpf);
break;
}
return true;
} catch (Exception $e) {
@unlink($tmpf);
return false;
}
}
/**
* Extracts a tar archive
*/
public static function extractTar($file, $destination="./") {
if (!file_exists($file))
return false;
$tar = new PharData($file);
try {
$tar->extractTo($destination, null, true);
return true;
} catch (Exception $e) {
return false;
}
}
}
/**
* htpasswd parser
*/
class Htpasswd {
public $users = [];
public function __construct( $filename="" ) {
if( $filename )
$this->load( $filename );
}
/**
* Load a new htpasswd file
*/
public function load( $filename ) {
unset( $this->users );
if( file_exists( $filename ) && is_readable( $filename ) ) {
$lines = file( $filename );
foreach( $lines as $line ) {
list( $user, $pass ) = explode( ":", $line );
$this->users[$user] = trim( $pass );
}
return true;
} else
return false;
}
public function getUsers() {
return array_keys( $this->users );
}
public function userExist( $user ) {
return isset( $this->users[ $user ] );
}
public function verify( $user, $pass ) {
if( isset( $this->users[$user] ) ) {
return $this->verifyPassword( $pass, $this->users[$user] );
} else {
return false;
}
}
public function verifyPassword( $pass, $hash ) {
if( substr( $hash, 0, 4 ) == '$2y$' ) {
return password_verify( $pass, $hash );
} elseif( substr( $hash, 0, 6 ) == '$apr1$' ) {
$apr1 = new APR1_MD5();
return $apr1->check( $pass, $hash );
} elseif( substr( $hash, 0, 5 ) == '{SHA}' ) {
return base64_encode( sha1( $pass, TRUE ) ) == substr( $hash, 5 );
} else { // assume CRYPT
return crypt( $pass, $hash ) == $hash;
}
}
}
/**
* APR1_MD5 class
*
* Source: https://github.com/whitehat101/apr1-md5/blob/master/src/APR1_MD5.php
*/
class APR1_MD5 {
const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const APRMD5_ALPHABET = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
// Source/References for core algorithm:
// http://www.cryptologie.net/article/126/bruteforce-apr1-hashes/
// http://svn.apache.org/viewvc/apr/apr-util/branches/1.3.x/crypto/apr_md5.c?view=co
// http://www.php.net/manual/en/function.crypt.php#73619
// http://httpd.apache.org/docs/2.2/misc/password_encryptions.html
// Wikipedia
public static function hash($mdp, $salt = null) {
if (is_null($salt))
$salt = self::salt();
$salt = substr($salt, 0, 8);
$max = strlen($mdp);
$context = $mdp.'$apr1$'.$salt;
$binary = pack('H32', md5($mdp.$salt.$mdp));
for($i=$max; $i>0; $i-=16)
$context .= substr($binary, 0, min(16, $i));
for($i=$max; $i>0; $i>>=1)
$context .= ($i & 1) ? chr(0) : $mdp[0];
$binary = pack('H32', md5($context));
for($i=0; $i<1000; $i++) {
$new = ($i & 1) ? $mdp : $binary;
if($i % 3) $new .= $salt;
if($i % 7) $new .= $mdp;
$new .= ($i & 1) ? $binary : $mdp;
$binary = pack('H32', md5($new));
}
$hash = '';
for ($i = 0; $i < 5; $i++) {
$k = $i+6;
$j = $i+12;
if($j == 16) $j = 5;
$hash = $binary[$i].$binary[$k].$binary[$j].$hash;
}
$hash = chr(0).chr(0).$binary[11].$hash;
$hash = strtr(
strrev(substr(base64_encode($hash), 2)),
self::BASE64_ALPHABET,
self::APRMD5_ALPHABET
);
return '$apr1$'.$salt.'$'.$hash;
}
// 8 character salts are the best. Don't encourage anything but the best.
public static function salt() {
$alphabet = self::APRMD5_ALPHABET;
$salt = '';
for($i=0; $i<8; $i++) {
$offset = hexdec(bin2hex(openssl_random_pseudo_bytes(1))) % 64;
$salt .= $alphabet[$offset];
}
return $salt;
}
public static function check($plain, $hash) {
$parts = explode('$', $hash);
return self::hash($plain, $parts[2]) === $hash;
}
}
/**
* start IFM
*/
$ifm = new IFM();
$ifm->run();