· 6 years ago · Nov 06, 2019, 04:14 PM
1<?
2/* PHP File manager ver 1.1 */
3
4// Configuration — do not change manually!
5$authorization = '{"authorize":"0","login":"admin","password":"phpfm","cookie_name":"fm_user","days_authorization":"30","script":"<script type=\"text\/javascript\" src=\"http:\/\/www.cdolivet.com\/editarea\/editarea\/edit_area\/edit_area_full.js\"><\/script>\r\n<script language=\"Javascript\" type=\"text\/javascript\">\r\neditAreaLoader.init({\r\nid: \"newcontent\"\r\n,display: \"later\"\r\n,start_highlight: true\r\n,allow_resize: \"both\"\r\n,allow_toggle: true\r\n,word_wrap: true\r\n,language: \"ru\"\r\n,syntax: \"php\"\t\r\n,toolbar: \"search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help\"\r\n,syntax_selection_allow: \"css,html,js,php,python,xml,c,cpp,sql,basic,pas\"\r\n});\r\n<\/script>"}';
6$php_templates = '{"Settings":"global $fm_config;\r\nvar_export($fm_config);","Backup SQL tables":"echo fm_backup_tables();"}';
7$sql_templates = '{"All bases":"SHOW DATABASES;","All tables":"SHOW TABLES;"}';
8// end configuration
9
10// Preparations
11$starttime = explode(' ', microtime());
12$starttime = $starttime[1] + $starttime[0];
13$langs = array('en','ru','de','fr','uk');
14$path = empty($_REQUEST['path']) ? $path = realpath('.') : realpath($_REQUEST['path']);
15$path = str_replace('\\', '/', $path) . '/';
16$main_path=str_replace('\\', '/',realpath('./'));
17$phar_maybe = (version_compare(phpversion(),"5.3.0","<"))?true:false;
18$msg = ''; // service string
19$default_language = 'ru';
20$detect_lang = true;
21$fm_version = 1.1;
22
23//Authorization
24$auth = json_decode($authorization,true);
25$auth['authorize'] = isset($auth['authorize']) ? $auth['authorize'] : 0;
26$auth['days_authorization'] = (isset($auth['days_authorization'])&&is_numeric($auth['days_authorization'])) ? (int)$auth['days_authorization'] : 30;
27$auth['login'] = isset($auth['login']) ? $auth['login'] : 'admin';
28$auth['password'] = isset($auth['password']) ? $auth['password'] : 'phpfm';
29$auth['cookie_name'] = isset($auth['cookie_name']) ? $auth['cookie_name'] : 'fm_user';
30$auth['script'] = isset($auth['script']) ? $auth['script'] : '';
31
32// Little default config
33$fm_default_config = array (
34 'make_directory' => true,
35 'new_file' => true,
36 'upload_file' => true,
37 'show_dir_size' => false, //if true, show directory size → maybe slow
38 'show_img' => true,
39 'show_php_ver' => true,
40 'show_php_ini' => false, // show path to current php.ini
41 'show_gt' => true, // show generation time
42 'enable_php_console' => true,
43 'enable_sql_console' => true,
44 'sql_server' => 'localhost',
45 'sql_username' => 'root',
46 'sql_password' => '',
47 'sql_db' => 'test_base',
48 'enable_proxy' => true,
49 'show_phpinfo' => true,
50 'show_xls' => true,
51 'fm_settings' => true,
52);
53
54if (empty($_COOKIE['fm_config'])) $fm_config = $fm_default_config;
55else $fm_config = unserialize($_COOKIE['fm_config']);
56
57// Change language
58if (isset($_POST['fm_lang'])) {
59 setcookie('fm_lang', $_POST['fm_lang'], time() + (86400 * $auth['days_authorization']));
60 $_COOKIE['fm_lang'] = $_POST['fm_lang'];
61}
62$language = $default_language;
63
64// Detect browser language
65if($detect_lang && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && empty($_COOKIE['fm_lang'])){
66 $lang_priority = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
67 if (!empty($lang_priority)){
68 foreach ($lang_priority as $lang_arr){
69 $lng = explode(';', $lang_arr);
70 $lng = $lng[0];
71 if(in_array($lng,$langs)){
72 $language = $lng;
73 break;
74 }
75 }
76 }
77}
78
79// Cookie language is primary for ever
80$language = (empty($_COOKIE['fm_lang'])) ? $language : $_COOKIE['fm_lang'];
81
82
83// Localization
84if ($language=='ru') {
85$lang['Add']='Добавить';
86$lang['Are you sure you want to delete this directory (recursively)?']='Вы уверены, что хотите удалить эту папку (рекурсивно)?';
87$lang['Are you sure you want to delete this file?']='Вы уверены, что хотите удалить этот файл?';
88$lang['Archiving']='Архивировать';
89$lang['Authorization']='Авторизация';
90$lang['Back']='Назад';
91$lang['Cancel']='Отмена';
92$lang['Chinese']='Китайский';
93$lang['Compress']='Сжать';
94$lang['Console']='Консоль';
95$lang['Cookie']='Куки';
96$lang['Created']='Создан';
97$lang['Date']='Дата';
98$lang['Days']='Дней';
99$lang['Decompress']='Распаковать';
100$lang['Delete']='Удалить';
101$lang['Deleted']='Удалено';
102$lang['Download']='Скачать';
103$lang['done']='закончена';
104$lang['Edit']='Редактировать';
105$lang['Enter']='Вход';
106$lang['English']='Английский';
107$lang['Error occurred']='Произошла ошибка';
108$lang['File manager']='Файловый менеджер';
109$lang['File selected']='Выбран файл';
110$lang['File updated']='Файл сохранен';
111$lang['Filename']='Имя файла';
112$lang['Files uploaded']='Файл загружен';
113$lang['French']='Французский';
114$lang['German']='Немецкий';
115$lang['Generation time']='Генерация страницы';
116$lang['Home']='Домой';
117$lang['Quit']='Выход';
118$lang['Language']='Язык';
119$lang['Login']='Логин';
120$lang['Manage']='Управление';
121$lang['Make directory']='Создать папку';
122$lang['Name']='Наименование';
123$lang['New']='Новое';
124$lang['New file']='Новый файл';
125$lang['no files']='нет файлов';
126$lang['Password']='Пароль';
127$lang['pictures']='изображения';
128$lang['Recursively']='Рекурсивно';
129$lang['Rename']='Переименовать';
130$lang['Reset']='Сбросить';
131$lang['Reset settings']='Сбросить настройки';
132$lang['Result']='Результат';
133$lang['Rights']='Права';
134$lang['Russian']='Русский';
135$lang['Save']='Сохранить';
136$lang['Select']='Выберите';
137$lang['Select the file']='Выберите файл';
138$lang['Settings']='Настройка';
139$lang['Show']='Показать';
140$lang['Size']='Размер';
141$lang['Spanish']='Испанский';
142$lang['Submit']='Отправить';
143$lang['Task']='Задача';
144$lang['templates']='шаблоны';
145$lang['Show size of the folder']='Показать размер папки';
146$lang['Ukrainian']='Украинский';
147$lang['Upload']='Загрузить';
148$lang['Value']='Значение';
149$lang['Hello']='Привет';
150} elseif ($language=='de') {
151$lang['Add']='Add';
152$lang['Are you sure you want to delete this directory (recursively)'] = 'Sind Sie sicher, dass Sie diesen Ordner löschen möchten (rekursiv)?';
153$lang['Are you sure you want to delete this file?'] = 'Sind Sie sicher, dass Sie diese Datei löschen möchten?';
154$lang['Archiving'] = 'Archivierung';
155$lang['Authorization']='Genehmigung';
156$lang['Back'] = 'Zurück';
157$lang['Cancel'] = 'Abbrechen';
158$lang['Chinese']='Chinesische';
159$lang['Compress'] = 'Compress';
160$lang['Console'] = 'Console';
161$lang['Cookie']='Cookie';
162$lang['Created'] = 'Erstellt';
163$lang['Date'] = 'Datum';
164$lang['Days'] = 'Tage';
165$lang['Decompress'] = 'Extract';
166$lang['Delete'] = 'Löschen';
167$lang['Deleted'] = 'Gelöschte';
168$lang['Download'] = 'Laden';
169$lang['done'] = 'fertig';
170$lang['Edit'] = 'Bearbeiten';
171$lang['Enter'] = 'Eintrag';
172$lang['Englisch'] = 'Englisch';
173$lang['Error occurred'] = 'Ein Fehler ist aufgetreten';
174$lang['File manager'] = 'Datei Manager';
175$lang['File selected'] = 'Die ausgewählte Datei';
176$lang['File updated'] = 'Die Datei wird gespeichert';
177$lang['Filename'] = 'Dateiname';
178$lang['Files uploaded'] = 'Datei hochgeladen';
179$lang['French'] = 'Französisch';
180$lang['Generation time'] = 'Generation Zeit';
181$lang['German']='Deutche';
182$lang['Home'] = 'Home';
183$lang['Quit'] = 'Abmelden';
184$lang['Language'] = 'Sprache';
185$lang['Login'] = 'Login';
186$lang['Manage'] = 'Management';
187$lang['Make directory'] = 'Neuer Ordner';
188$lang['Name']='Name';
189$lang['New']='Neu';
190$lang['New file'] = 'Neue Datei';
191$lang['no files'] = 'keine Dateien';
192$lang['Password'] = 'Passwort';
193$lang['pictures'] = 'Bilder';
194$lang['Recursively'] = 'rekursive';
195$lang['Reset']='Zurücksetzen';
196$lang['Rename'] = 'Umbenennen';
197$lang['Reset settings']='Einstellungen zurücksetzen';
198$lang['Result']='Result';
199$lang['Ergebnis'] = 'Ergebnis';
200$lang['Rights'] = 'Rechte';
201$lang['Russian'] = 'Russisch';
202$lang['Save']='Speichern';
203$lang['Select'] = 'Wählen';
204$lang['Select the file'] = 'Wählen Sie die Datei';
205$lang['Settings']='Einstellungen';
206$lang['Show'] = 'Show';
207$lang['Show size of the folder'] = 'Größe des Ordners anzeigen';
208$lang['Size'] = 'Größe';
209$lang['Spanish']='Spanisch';
210$lang['Submit'] = 'Senden';
211$lang['Task'] = 'Aufgabe';
212$lang['templates']='Vorlagen';
213$lang['Ukrainian'] = 'Ukrainisch';
214$lang['Upload'] = 'Upload';
215$lang['Value']='Wert';
216$lang['Hello'] = 'Hallo';
217} elseif ($language=='fr') {
218$lang['Add']='Ajouter';
219$lang['Are you sure you want to delete this directory (recursively)?']='Êtes-vous sûr de vouloir supprimer ce dossier (récursive)?';
220$lang['Are you sure you want to delete this file?']='Êtes-vous sûr de vouloir supprimer ce fichier?';
221$lang['Archiving']='Archives';
222$lang['Authorization']='Autorisation';
223$lang['Back']='Arrière';
224$lang['Cancel']='annulation';
225$lang['Chinese']='Chinois';
226$lang['Compress']='Presser';
227$lang['Console']='Console';
228$lang['Cookie']='Cookie';
229$lang['Created']='Êtabli';
230$lang['Date']='La date';
231$lang['Days']='Journées';
232$lang['Decompress']='Décompresser';
233$lang['Delete']='Supprimer';
234$lang['Deleted']='Supprimé';
235$lang['Download']='Télécharger';
236$lang['done']='terminé';
237$lang['Edit']='Editer';
238$lang['Enter']='Entrée';
239$lang['English']='Anglais';
240$lang['Error occurred']='Une erreur est survenue';
241$lang['File manager']='Gestionnaire de fichiers';
242$lang['File selected']='Fichier sélectionné';
243$lang['File updated']='Le fichier est enregistré';
244$lang['Filename']='Nom du fichier';
245$lang['Files uploaded']='Fichiers uploadés';
246$lang['French']='Française';
247$lang['Generation time']='Génération de la page';
248$lang['German']='Allemand';
249$lang['Home']='Home';
250$lang['Quit']='Quitter';
251$lang['Language']='Langue';
252$lang['Login']='Connexion';
253$lang['Manage']='Gestion';
254$lang['Make directory']='Nouveau dossier';
255$lang['Name']='Nom';
256$lang['New']='Nouveau';
257$lang['New file']='Nouveau fichier';
258$lang['no files']='aucun fichier';
259$lang['Password']='Mot de passe';
260$lang['pictures']='des photos';
261$lang['Recursively']='Récursive';
262$lang['Rename']='Renommer';
263$lang['Reset']='Réinitialiser';
264$lang['Reset settings']='Réinitialiser les paramètres';
265$lang['Result']='Résultat';
266$lang['Rights']='Permissions';
267$lang['Russian']='Russe';
268$lang['Save']='Enregistrer';
269$lang['Select']='Sélectionnez';
270$lang['Select the file']='Sélectionnez le fichier';
271$lang['Settings']='Réglages';
272$lang['Show']='Show';
273$lang['Show size of the folder']='Afficher la taille du dossier';
274$lang['Size']='Taille';
275$lang['Spanish']='Espagnol';
276$lang['Submit']='Envoyer';
277$lang['Task']='Tâche';
278$lang['templates']='templates';
279$lang['Ukrainian']='Ukrainien';
280$lang['Upload']='Télécharger';
281$lang['Value']='Valeur';
282$lang['Hello']='Bonjour';
283} else if ($language=='uk') {
284$lang['Add']='Додати';
285$lang['Are you sure you want to delete this directory (recursively)?']='Ви впевнені, що бажаєте видалити цю папку (рекурсивно)?';
286$lang['Are you sure you want to delete this file?']='Ви впевнені, що бажаєте видалити цей файл?';
287$lang['Archiving']='Архівувати';
288$lang['Authorization']='Авторизація';
289$lang['Back']='Назад';
290$lang['Cancel']='Відміна';
291$lang['Chinese']='Китайська';
292$lang['Compress']='Сжати';
293$lang['Console']='Консоль';
294$lang['Cookie']='Кукi';
295$lang['Created']='Створений';
296$lang['Date']='Дата';
297$lang['Date']='Днiв';
298$lang['Decompress']='Розпакувати';
299$lang['Delete']='Видалити';
300$lang['Deleted']='Видалено';
301$lang['Download']='Скачати';
302$lang['done']='закінчено';
303$lang['Edit']='Редагувати';
304$lang['Enter']='Вхід';
305$lang['English']='Англійська';
306$lang['Error occurred']='Виникла помилка';
307$lang['File manager']='Файловий менеджер';
308$lang['File selected']='Обрано файл';
309$lang['File updated']='Файл збережено';
310$lang['Filename']='Им\'я файла';
311$lang['Files uploaded']='Файл завантажено';
312$lang['French']='Французська';
313$lang['Generation time']='Генерація сторінки';
314$lang['German']='Німецька';
315$lang['Home']='Додому';
316$lang['Quit']='Вихід';
317$lang['Language']='Мова';
318$lang['Login']='Логін';
319$lang['Manage']='Управління';
320$lang['Make directory']='Створити папку';
321$lang['Name']='Найменування';
322$lang['New']='Нове';
323$lang['New file']='Новий файл';
324$lang['no files']='немає файлів';
325$lang['Password']='Пароль';
326$lang['pictures']='фотографії';
327$lang['Recursively']='Рекурсивно';
328$lang['Rename']='Перейменувати';
329$lang['Reset']='Скидання';
330$lang['Reset settings']='Скинути налаштування';
331$lang['Result']='Результат';
332$lang['Rights']='Права';
333$lang['Russian']='Російська';
334$lang['Save']='Зберегти';
335$lang['Select']='Виберіть';
336$lang['Select the file']='Виберіть файл';
337$lang['Settings']='Налаштування';
338$lang['Show']='Показати';
339$lang['Show size of the folder']='Показати розмір папки';
340$lang['Size']='Розмір';
341$lang['Spanish']='Іспанська';
342$lang['Submit']='Відправити';
343$lang['Task']='Завдання';
344$lang['templates']='шаблони';
345$lang['Ukrainian']='Українська';
346$lang['Upload']='Завантажити';
347$lang['Value']='Значення';
348$lang['Hello']='Вітаю';
349}
350
351/* Functions */
352
353//translation
354function __($text){
355 global $lang;
356 if (isset($lang[$text])) return $lang[$text];
357 else return $text;
358};
359
360//delete files and dirs recursively
361function fm_del_files($file, $recursive = false) {
362 if($recursive && @is_dir($file)) {
363 $els = fm_scan_dir($file, '', '', true);
364 foreach ($els as $el) {
365 if($el != '.' && $el != '..'){
366 fm_del_files($file . '/' . $el, true);
367 }
368 }
369 }
370 if(@is_dir($file)) {
371 return rmdir($file);
372 } else {
373 return @unlink($file);
374 }
375}
376
377//file perms
378function fm_rights_string($file, $if = false){
379 $perms = fileperms($file);
380 $info = '';
381 if(!$if){
382 if (($perms & 0xC000) == 0xC000) {
383 //Socket
384 $info = 's';
385 } elseif (($perms & 0xA000) == 0xA000) {
386 //Symbolic Link
387 $info = 'l';
388 } elseif (($perms & 0x8000) == 0x8000) {
389 //Regular
390 $info = '-';
391 } elseif (($perms & 0x6000) == 0x6000) {
392 //Block special
393 $info = 'b';
394 } elseif (($perms & 0x4000) == 0x4000) {
395 //Directory
396 $info = 'd';
397 } elseif (($perms & 0x2000) == 0x2000) {
398 //Character special
399 $info = 'c';
400 } elseif (($perms & 0x1000) == 0x1000) {
401 //FIFO pipe
402 $info = 'p';
403 } else {
404 //Unknown
405 $info = 'u';
406 }
407 }
408
409 //Owner
410 $info .= (($perms & 0x0100) ? 'r' : '-');
411 $info .= (($perms & 0x0080) ? 'w' : '-');
412 $info .= (($perms & 0x0040) ?
413 (($perms & 0x0800) ? 's' : 'x' ) :
414 (($perms & 0x0800) ? 'S' : '-'));
415
416 //Group
417 $info .= (($perms & 0x0020) ? 'r' : '-');
418 $info .= (($perms & 0x0010) ? 'w' : '-');
419 $info .= (($perms & 0x0008) ?
420 (($perms & 0x0400) ? 's' : 'x' ) :
421 (($perms & 0x0400) ? 'S' : '-'));
422
423 //World
424 $info .= (($perms & 0x0004) ? 'r' : '-');
425 $info .= (($perms & 0x0002) ? 'w' : '-');
426 $info .= (($perms & 0x0001) ?
427 (($perms & 0x0200) ? 't' : 'x' ) :
428 (($perms & 0x0200) ? 'T' : '-'));
429
430 return $info;
431}
432
433function fm_convert_rights($mode) {
434 $mode = str_pad($mode,9,'-');
435 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
436 $mode = strtr($mode,$trans);
437 $newmode = '0';
438 $owner = (int) $mode[0] + (int) $mode[1] + (int) $mode[2];
439 $group = (int) $mode[3] + (int) $mode[4] + (int) $mode[5];
440 $world = (int) $mode[6] + (int) $mode[7] + (int) $mode[8];
441 $newmode .= $owner . $group . $world;
442 return intval($newmode, 8);
443}
444
445function fm_chmod($file, $val, $rec = false) {
446 $res = @chmod(realpath($file), $val);
447 if(@is_dir($file) && $rec){
448 $els = fm_scan_dir($file);
449 foreach ($els as $el) {
450 $res = $res && fm_chmod($file . '/' . $el, $val, true);
451 }
452 }
453 return $res;
454}
455
456//load files
457function fm_download($file_name) {
458 if (!empty($file_name)) {
459 if (file_exists($file_name)) {
460 header("Content-Disposition: attachment; filename=" . basename($file_name));
461 header("Content-Type: application/force-download");
462 header("Content-Type: application/octet-stream");
463 header("Content-Type: application/download");
464 header("Content-Description: File Transfer");
465 header("Content-Length: " . filesize($file_name));
466 flush(); // this doesn't really matter.
467 $fp = fopen($file_name, "r");
468 while (!feof($fp)) {
469 echo fread($fp, 65536);
470 flush(); // this is essential for large downloads
471 }
472 fclose($fp);
473 die();
474 } else {
475 header('HTTP/1.0 404 Not Found', true, 404);
476 header('Status: 404 Not Found');
477 die();
478 }
479 }
480}
481
482//show folder size
483function fm_dir_size($f,$format=true) {
484 if($format) {
485 $size=fm_dir_size($f,false);
486 if($size<=1024) return $size.' bytes';
487 elseif($size<=1024*1024) return round($size/(1024),2).' Kb';
488 elseif($size<=1024*1024*1024) return round($size/(1024*1024),2).' Mb';
489 elseif($size<=1024*1024*1024*1024) return round($size/(1024*1024*1024),2).' Gb';
490 elseif($size<=1024*1024*1024*1024*1024) return round($size/(1024*1024*1024*1024),2).' Tb'; //:)))
491 else return round($size/(1024*1024*1024*1024*1024),2).' Pb'; // ;-)
492 } else {
493 if(is_file($f)) return filesize($f);
494 $size=0;
495 $dh=opendir($f);
496 while(($file=readdir($dh))!==false) {
497 if($file=='.' || $file=='..') continue;
498 if(is_file($f.'/'.$file)) $size+=filesize($f.'/'.$file);
499 else $size+=fm_dir_size($f.'/'.$file,false);
500 }
501 closedir($dh);
502 return $size+filesize($f);
503 }
504}
505
506//scan directory
507function fm_scan_dir($directory, $exp = '', $type = 'all', $do_not_filter = false) {
508 $dir = $ndir = array();
509 if(!empty($exp)){
510 $exp = '/^' . str_replace('*', '(.*)', str_replace('.', '\\.', $exp)) . '$/';
511 }
512 if(!empty($type) && $type !== 'all'){
513 $func = 'is_' . $type;
514 }
515 if(@is_dir($directory)){
516 $fh = opendir($directory);
517 while (false !== ($filename = readdir($fh))) {
518 if(substr($filename, 0, 1) != '.' || $do_not_filter) {
519 if((empty($type) || $type == 'all' || $func($directory . '/' . $filename)) && (empty($exp) || preg_match($exp, $filename))){
520 $dir[] = $filename;
521 }
522 }
523 }
524 closedir($fh);
525 natsort($dir);
526 }
527 return $dir;
528}
529
530function fm_link($get,$link,$name,$title='') {
531 if (empty($title)) $title=$name.' '.basename($link);
532 return ' <a href="?'.$get.'='.base64_encode($link).'" title="'.$title.'">'.$name.'</a>';
533}
534
535function fm_arr_to_option($arr,$n,$sel=''){
536 foreach($arr as $v){
537 $b=$v[$n];
538 $res.='<option value="'.$b.'" '.($sel && $sel==$b?'selected':'').'>'.$b.'</option>';
539 }
540 return $res;
541}
542
543function fm_lang_form ($current='en'){
544return '
545<form name="change_lang" method="post" action="">
546 <select name="fm_lang" title="'.__('Language').'" onchange="document.forms[\'change_lang\'].submit()" >
547 <option value="en" '.($current=='en'?'selected="selected" ':'').'>'.__('English').'</option>
548 <option value="de" '.($current=='de'?'selected="selected" ':'').'>'.__('German').'</option>
549 <option value="ru" '.($current=='ru'?'selected="selected" ':'').'>'.__('Russian').'</option>
550 <option value="fr" '.($current=='fr'?'selected="selected" ':'').'>'.__('French').'</option>
551 <option value="uk" '.($current=='uk'?'selected="selected" ':'').'>'.__('Ukrainian').'</option>
552 </select>
553</form>
554';
555}
556
557function fm_root($dirname){
558 return ($dirname=='.' OR $dirname=='..');
559}
560
561function fm_php($string){
562 $display_errors=ini_get('display_errors');
563 ini_set('display_errors', '1');
564 ob_start();
565 eval(trim($string));
566 $text = ob_get_contents();
567 ob_end_clean();
568 ini_set('display_errors', $display_errors);
569 return $text;
570}
571
572//SHOW DATABASES
573function fm_sql_connect(){
574 global $fm_config;
575 return new mysqli($fm_config['sql_server'], $fm_config['sql_username'], $fm_config['sql_password'], $fm_config['sql_db']);
576}
577
578function fm_sql($query){
579 global $fm_config;
580 $query=trim($query);
581 ob_start();
582 $connection = fm_sql_connect();
583 if ($connection->connect_error) {
584 ob_end_clean();
585 return $connection->connect_error;
586 }
587 $connection->set_charset('utf8');
588 $queried = mysqli_query($connection,$query);
589 if ($queried===false) {
590 ob_end_clean();
591 return mysqli_error($connection);
592 } else {
593 if(!empty($queried)){
594 while($row = mysqli_fetch_assoc($queried)) {
595 $query_result[]= $row;
596 }
597 }
598 $vdump=empty($query_result)?'':var_export($query_result,true);
599 ob_end_clean();
600 $connection->close();
601 return '<pre>'.stripslashes($vdump).'</pre>';
602 }
603}
604
605function fm_backup_tables($tables = '*', $full_backup = true) {
606 global $path;
607 $mysqldb = fm_sql_connect();
608 $delimiter = "; \n \n";
609 if($tables == '*') {
610 $tables = array();
611 $result = $mysqldb->query('SHOW TABLES');
612 while($row = mysqli_fetch_row($result)) {
613 $tables[] = $row[0];
614 }
615 } else {
616 $tables = is_array($tables) ? $tables : explode(',',$tables);
617 }
618
619 $return='';
620 foreach($tables as $table) {
621 $result = $mysqldb->query('SELECT * FROM '.$table);
622 $num_fields = mysqli_num_fields($result);
623 $return.= 'DROP TABLE IF EXISTS `'.$table.'`'.$delimiter;
624 $row2 = mysqli_fetch_row($mysqldb->query('SHOW CREATE TABLE '.$table));
625 $return.=$row2[1].$delimiter;
626 if ($full_backup) {
627 for ($i = 0; $i < $num_fields; $i++) {
628 while($row = mysqli_fetch_row($result)) {
629 $return.= 'INSERT INTO `'.$table.'` VALUES(';
630 for($j=0; $j<$num_fields; $j++) {
631 $row[$j] = addslashes($row[$j]);
632 $row[$j] = str_replace("\n","\\n",$row[$j]);
633 if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
634 if ($j<($num_fields-1)) { $return.= ','; }
635 }
636 $return.= ')'.$delimiter;
637 }
638 }
639 } else {
640 $return = preg_replace("#AUTO_INCREMENT=[\d]+ #is", '', $return);
641 }
642 $return.="\n\n\n";
643 }
644
645 //save file
646 $file=gmdate("Y-m-d_H-i-s",time()).'.sql';
647 $handle = fopen($file,'w+');
648 fwrite($handle,$return);
649 fclose($handle);
650 $alert = 'onClick="if(confirm(\''. __('File selected').': \n'. $file. '. \n'.__('Are you sure you want to delete this file?') . '\')) document.location.href = \'?delete=' . $file . '&path=' . $path . '\'"';
651 return $file.': '.fm_link('download',$path.$file,__('Download'),__('Download').' '.$file).' <a href="#" title="' . __('Delete') . ' '. $file . '" ' . $alert . '>' . __('Delete') . '</a>';
652}
653
654function fm_restore_tables($sqlFileToExecute) {
655 $mysqldb = fm_sql_connect();
656 $delimiter = "; \n \n";
657 // Load and explode the sql file
658 $f = fopen($sqlFileToExecute,"r+");
659 $sqlFile = fread($f,filesize($sqlFileToExecute));
660 $sqlArray = explode($delimiter,$sqlFile);
661
662 //Process the sql file by statements
663 foreach ($sqlArray as $stmt) {
664 if (strlen($stmt)>3){
665 $result = $mysqldb->query($stmt);
666 if (!$result){
667 $sqlErrorCode = mysqli_errno($mysqldb->connection);
668 $sqlErrorText = mysqli_error($mysqldb->connection);
669 $sqlStmt = $stmt;
670 break;
671 }
672 }
673 }
674if (empty($sqlErrorCode)) return __('Success').' — '.$sqlFileToExecute;
675else return $sqlErrorText.'<br/>'.$stmt;
676}
677
678function fm_img_link($filename){
679 return './'.basename(__FILE__).'?img='.base64_encode($filename);
680}
681
682function fm_home_style(){
683 return '
684
685input, input.fm_input {
686 text-indent: 2px;
687}
688
689input, textarea, select, input.fm_input {
690 color: black;
691 font: normal 8pt Verdana, Arial, Helvetica, sans-serif;
692 border-color: black;
693 background-color: #FCFCFC none !important;
694 border-radius: 0;
695 padding: 2px;
696}
697
698input.fm_input {
699 background: #FCFCFC none !important;
700 cursor: pointer;
701}
702
703.home {
704 background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAAgRQTFRF/f396Ojo////tT02zr+fw66Rtj432TEp3MXE2DAr3TYp1y4mtDw2/7BM/7BOqVpc/8l31jcqq6enwcHB2Tgi5jgqVpbFvra2nBAV/Pz82S0jnx0W3TUkqSgi4eHh4Tsre4wosz026uPjzGYd6Us3ynAydUBA5Kl3fm5eqZaW7ODgi2Vg+Pj4uY+EwLm5bY9U//7jfLtC+tOK3jcm/71u2jYo1UYh5aJl/seC3jEm12kmJrIA1jMm/9aU4Lh0e01BlIaE///dhMdC7IA//fTZ2c3MW6nN30wf95Vd4JdXoXVos8nE4efN/+63IJgSnYhl7F4csXt89GQUwL+/jl1c41Aq+fb2gmtI1rKa2C4kJaIA3jYrlTw5tj423jYn3cXE1zQoxMHBp1lZ3Dgmqiks/+mcjLK83jYkymMV3TYk//HM+u7Whmtr0odTpaOjfWJfrHpg/8Bs/7tW/7Ve+4U52DMm3MLBn4qLgNVM6MzB3lEflIuL/+jA///20LOzjXx8/7lbWpJG2C8k3TosJKMA1ywjopOR1zYp5Dspiay+yKNhqKSk8NW6/fjns7Oz2tnZuz887b+W3aRY/+ms4rCE3Tot7V85bKxjuEA3w45Vh5uhq6am4cFxgZZW/9qIuwgKy0sW+ujT4TQntz423C8i3zUj/+Kw/a5d6UMxuL6wzDEr////cqJQfAAAAKx0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAWVFbEAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAA2UlEQVQoU2NYjQYYsAiE8U9YzDYjVpGZRxMiECitMrVZvoMrTlQ2ESRQJ2FVwinYbmqTULoohnE1g1aKGS/fNMtk40yZ9KVLQhgYkuY7NxQvXyHVFNnKzR69qpxBPMez0ETAQyTUvSogaIFaPcNqV/M5dha2Rl2Timb6Z+QBDY1XN/Sbu8xFLG3eLDfl2UABjilO1o012Z3ek1lZVIWAAmUTK6L0s3pX+jj6puZ2AwWUvBRaphswMdUujCiwDwa5VEdPI7ynUlc7v1qYURLquf42hz45CBPDtwACrm+RDcxJYAAAAABJRU5ErkJggg==");
705 background-repeat: no-repeat;
706}';
707}
708
709function fm_config_checkbox_row($name,$value) {
710 global $fm_config;
711 return '<tr><td class="row1"><input id="fm_config_'.$value.'" name="fm_config['.$value.']" value="1" '.(empty($fm_config[$value])?'':'checked="true"').' type="checkbox"></td><td class="row2 whole"><label for="fm_config_'.$value.'">'.$name.'</td></tr>';
712}
713
714function fm_protocol() {
715 if (isset($_SERVER['HTTP_SCHEME'])) return $_SERVER['HTTP_SCHEME'].'://';
716 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') return 'https://';
717 if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) return 'https://';
718 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') return 'https://';
719 return 'http://';
720}
721
722function fm_site_url() {
723 return fm_protocol().$_SERVER['HTTP_HOST'];
724}
725
726function fm_url($full=false) {
727 $host=$full?fm_site_url():'.';
728 return $host.'/'.basename(__FILE__);
729}
730
731function fm_home($full=false){
732 return ' <a href="'.fm_url($full).'" title="'.__('Home').'"><span class="home"> </span></a>';
733}
734
735function fm_run_input($lng) {
736 global $fm_config;
737 $return = !empty($fm_config['enable_'.$lng.'_console']) ?
738 '
739 <form method="post" action="'.fm_url().'" style="display:inline">
740 <input type="submit" name="'.$lng.'run" value="'.strtoupper($lng).' '.__('Console').'">
741 </form>
742' : '';
743 return $return;
744}
745
746function fm_url_proxy($matches) {
747 $link = str_replace('&','&',$matches[2]);
748 $url = isset($_GET['url'])?$_GET['url']:'';
749 $parse_url = parse_url($url);
750 $host = $parse_url['scheme'].'://'.$parse_url['host'].'/';
751 if (substr($link,0,2)=='//') {
752 $link = substr_replace($link,fm_protocol(),0,2);
753 } elseif (substr($link,0,1)=='/') {
754 $link = substr_replace($link,$host,0,1);
755 } elseif (substr($link,0,2)=='./') {
756 $link = substr_replace($link,$host,0,2);
757 } elseif (substr($link,0,4)=='http') {
758 //alles machen wunderschon
759 } else {
760 $link = $host.$link;
761 }
762 if ($matches[1]=='href' && !strripos($link, 'css')) {
763 $base = fm_site_url().'/'.basename(__FILE__);
764 $baseq = $base.'?proxy=true&url=';
765 $link = $baseq.urlencode($link);
766 } elseif (strripos($link, 'css')){
767 //как-то тоже подменять надо
768 }
769 return $matches[1].'="'.$link.'"';
770}
771
772function fm_tpl_form($lng_tpl) {
773 global ${$lng_tpl.'_templates'};
774 $tpl_arr = json_decode(${$lng_tpl.'_templates'},true);
775 $str = '';
776 foreach ($tpl_arr as $ktpl=>$vtpl) {
777 $str .= '<tr><td class="row1"><input name="'.$lng_tpl.'_name[]" value="'.$ktpl.'"></td><td class="row2 whole"><textarea name="'.$lng_tpl.'_value[]" cols="55" rows="5" class="textarea_input">'.$vtpl.'</textarea> <input name="del_'.rand().'" type="button" onClick="this.parentNode.parentNode.remove();" value="'.__('Delete').'"/></td></tr>';
778 }
779return '
780<table>
781<tr><th colspan="2">'.strtoupper($lng_tpl).' '.__('templates').' '.fm_run_input($lng_tpl).'</th></tr>
782<form method="post" action="">
783<input type="hidden" value="'.$lng_tpl.'" name="tpl_edited">
784<tr><td class="row1">'.__('Name').'</td><td class="row2 whole">'.__('Value').'</td></tr>
785'.$str.'
786<tr><td colspan="2" class="row3"><input name="res" type="button" onClick="document.location.href = \''.fm_url().'?fm_settings=true\';" value="'.__('Reset').'"/> <input type="submit" value="'.__('Save').'" ></td></tr>
787</form>
788<form method="post" action="">
789<input type="hidden" value="'.$lng_tpl.'" name="tpl_edited">
790<tr><td class="row1"><input name="'.$lng_tpl.'_new_name" value="" placeholder="'.__('New').' '.__('Name').'"></td><td class="row2 whole"><textarea name="'.$lng_tpl.'_new_value" cols="55" rows="5" class="textarea_input" placeholder="'.__('New').' '.__('Value').'"></textarea></td></tr>
791<tr><td colspan="2" class="row3"><input type="submit" value="'.__('Add').'" ></td></tr>
792</form>
793</table>
794';
795}
796
797/* End Functions */
798
799// authorization
800if ($auth['authorize']) {
801 if (isset($_POST['login']) && isset($_POST['password'])){
802 if (($_POST['login']==$auth['login']) && ($_POST['password']==$auth['password'])) {
803 setcookie($auth['cookie_name'], $auth['login'].'|'.md5($auth['password']), time() + (86400 * $auth['days_authorization']));
804 $_COOKIE[$auth['cookie_name']]=$auth['login'].'|'.md5($auth['password']);
805 }
806 }
807 if (!isset($_COOKIE[$auth['cookie_name']]) OR ($_COOKIE[$auth['cookie_name']]!=$auth['login'].'|'.md5($auth['password']))) {
808 echo '
809<!doctype html>
810<html>
811<head>
812<meta charset="utf-8" />
813<meta name="viewport" content="width=device-width, initial-scale=1" />
814<title>'.__('File manager').'</title>
815</head>
816<body>
817<form action="" method="post">
818'.__('Login').' <input name="login" type="text">
819'.__('Password').' <input name="password" type="password">
820<input type="submit" value="'.__('Enter').'" class="fm_input">
821</form>
822'.fm_lang_form($language).'
823</body>
824</html>
825';
826die();
827 }
828 if (isset($_POST['quit'])) {
829 unset($_COOKIE[$auth['cookie_name']]);
830 setcookie($auth['cookie_name'], '', time() - (86400 * $auth['days_authorization']));
831 header('Location: '.fm_site_url().$_SERVER['REQUEST_URI']);
832 }
833}
834
835// Change config
836if (isset($_GET['fm_settings'])) {
837 if (isset($_GET['fm_config_delete'])) {
838 unset($_COOKIE['fm_config']);
839 setcookie('fm_config', '', time() - (86400 * $auth['days_authorization']));
840 header('Location: '.fm_url().'?fm_settings=true');
841 exit(0);
842 } elseif (isset($_POST['fm_config'])) {
843 $fm_config = $_POST['fm_config'];
844 setcookie('fm_config', serialize($fm_config), time() + (86400 * $auth['days_authorization']));
845 $_COOKIE['fm_config'] = serialize($fm_config);
846 $msg = __('Settings').' '.__('done');
847 } elseif (isset($_POST['fm_login'])) {
848 if (empty($_POST['fm_login']['authorize'])) $_POST['fm_login'] = array('authorize' => '0') + $_POST['fm_login'];
849 $fm_login = json_encode($_POST['fm_login']);
850 $fgc = file_get_contents('fm.php');
851 $search = preg_match('#authorization[\s]?\=[\s]?\'\{\"(.*?)\"\}\';#', $fgc, $matches);
852 if (!empty($matches[1])) {
853 $filemtime = filemtime(__FILE__);
854 $replace = str_replace('{"'.$matches[1].'"}',$fm_login,$fgc);
855 if (file_put_contents(__FILE__, $replace)) {
856 $msg .= __('File updated');
857 if ($_POST['fm_login']['login'] != $auth['login']) $msg .= ' '.__('Login').': '.$_POST['fm_login']['login'];
858 if ($_POST['fm_login']['password'] != $auth['password']) $msg .= ' '.__('Password').': '.$_POST['fm_login']['password'];
859 $auth = $_POST['fm_login'];
860 }
861 else $msg .= __('Error occurred');
862 touch(__FILE__,$filemtime);
863 }
864 } elseif (isset($_POST['tpl_edited'])) {
865 $lng_tpl = $_POST['tpl_edited'];
866 if (!empty($_POST[$lng_tpl.'_name'])) {
867 $fm_php = json_encode(array_combine($_POST[$lng_tpl.'_name'],$_POST[$lng_tpl.'_value']),JSON_HEX_APOS);
868 } elseif (!empty($_POST[$lng_tpl.'_new_name'])) {
869 $fm_php = json_encode(json_decode(${$lng_tpl.'_templates'},true)+array($_POST[$lng_tpl.'_new_name']=>$_POST[$lng_tpl.'_new_value']),JSON_HEX_APOS);
870 }
871 if (!empty($fm_php)) {
872 $fgc = file_get_contents('fm.php');
873 $search = preg_match('#'.$lng_tpl.'_templates[\s]?\=[\s]?\'\{\"(.*?)\"\}\';#', $fgc, $matches);
874 if (!empty($matches[1])) {
875 $filemtime = filemtime(__FILE__);
876 $replace = str_replace('{"'.$matches[1].'"}',$fm_php,$fgc);
877 if (file_put_contents(__FILE__, $replace)) {
878 ${$lng_tpl.'_templates'} = $fm_php;
879 $msg .= __('File updated');
880 } else $msg .= __('Error occurred');
881 touch(__FILE__,$filemtime);
882 }
883 } else $msg .= __('Error occurred');
884 }
885}
886
887// Just show image
888if (isset($_GET['img'])) {
889 $file=base64_decode($_GET['img']);
890 if ($info=getimagesize($file)){
891 switch ($info[2]){ //1=GIF, 2=JPG, 3=PNG, 4=SWF, 5=PSD, 6=BMP
892 case 1: $ext='gif'; break;
893 case 2: $ext='jpeg'; break;
894 case 3: $ext='png'; break;
895 case 6: $ext='bmp'; break;
896 default: die();
897 }
898 header("Content-type: image/$ext");
899 echo file_get_contents($file);
900 die();
901 }
902}
903
904// Just download file
905if (isset($_GET['download'])) {
906 $file=base64_decode($_GET['download']);
907 fm_download($file);
908}
909
910// Just show info
911if (isset($_GET['phpinfo'])) {
912 phpinfo();
913 die();
914}
915
916// Mini proxy, many bugs!
917if (isset($_GET['proxy']) && (!empty($fm_config['enable_proxy']))) {
918 $url = isset($_GET['url'])?urldecode($_GET['url']):'';
919 $proxy_form = '
920<div style="position:relative;z-index:100500;background: linear-gradient(to bottom, #e4f5fc 0%,#bfe8f9 50%,#9fd8ef 51%,#2ab0ed 100%);">
921 <form action="" method="GET">
922 <input type="hidden" name="proxy" value="true">
923 '.fm_home().' <a href="'.$url.'" target="_blank">Url</a>: <input type="text" name="url" value="'.$url.'" size="55">
924 <input type="submit" value="'.__('Show').'" class="fm_input">
925 </form>
926</div>
927';
928 if ($url) {
929 $ch = curl_init($url);
930 curl_setopt($ch, CURLOPT_USERAGENT, 'Den1xxx test proxy');
931 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
932 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
933 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
934 curl_setopt($ch, CURLOPT_HEADER, 0);
935 curl_setopt($ch, CURLOPT_REFERER, $url);
936 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
937 $result = curl_exec($ch);
938 curl_close($ch);
939 //$result = preg_replace('#(src)=["\'][http://]?([^:]*)["\']#Ui', '\\1="'.$url.'/\\2"', $result);
940 $result = preg_replace_callback('#(href|src)=["\'][http://]?([^:]*)["\']#Ui', 'fm_url_proxy', $result);
941 $result = preg_replace('%(<body.*?>)%i', '$1'.'<style>'.fm_home_style().'</style>'.$proxy_form, $result);
942 echo $result;
943 die();
944 }
945}
946?>
947<!doctype html>
948<html>
949<head>
950 <meta charset="utf-8" />
951 <meta name="viewport" content="width=device-width, initial-scale=1" />
952 <title><?=__('File manager')?></title>
953<style>
954body {
955 background-color: white;
956 font-family: Verdana, Arial, Helvetica, sans-serif;
957 font-size: 8pt;
958 margin: 0px;
959}
960
961a:link, a:active, a:visited { color: #006699; text-decoration: none; }
962a:hover { color: #DD6900; text-decoration: underline; }
963a.th:link { color: #FFA34F; text-decoration: none; }
964a.th:active { color: #FFA34F; text-decoration: none; }
965a.th:visited { color: #FFA34F; text-decoration: none; }
966a.th:hover { color: #FFA34F; text-decoration: underline; }
967
968table.bg {
969 background-color: #ACBBC6
970}
971
972th, td {
973 font: normal 8pt Verdana, Arial, Helvetica, sans-serif;
974 padding: 3px;
975}
976
977th {
978 height: 25px;
979 background-color: #006699;
980 color: #FFA34F;
981 font-weight: bold;
982 font-size: 11px;
983}
984
985.row1 {
986 background-color: #EFEFEF;
987}
988
989.row2 {
990 background-color: #DEE3E7;
991}
992
993.row3 {
994 background-color: #D1D7DC;
995 padding: 5px;
996}
997
998tr.row1:hover {
999 background-color: #F3FCFC;
1000}
1001
1002tr.row2:hover {
1003 background-color: #F0F6F6;
1004}
1005
1006.whole {
1007 width: 100%;
1008}
1009
1010.all tbody td:first-child{width:100%;}
1011
1012textarea {
1013 font: 9pt 'Courier New', courier;
1014 line-height: 125%;
1015 padding: 5px;
1016}
1017
1018.textarea_input {
1019 height: 1em;
1020}
1021
1022.textarea_input:focus {
1023 height: auto;
1024}
1025
1026input[type=submit]{
1027 background: #FCFCFC none !important;
1028 cursor: pointer;
1029}
1030
1031.folder {
1032 background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmA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IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfcCAwGMhleGAKOAAAByElEQVQ4y8WTT2sUQRDFf9XTM+PGIBHdEEQR8eAfggaPHvTuyU+i+A38AF48efJbKB5zE0IMAVcCiRhQE8gmm111s9mZ3Zl+Hmay5qAY8GBDdTWPeo9HVRf872O9xVv3/JnrCygIU406K/qbrbP3Vxb/qjD8+OSNtC+VX6RiUyrWpXJD2aenfyR3Xs9N3h5rFIw6EAYQxsAIKMFx+cfSg0dmFk+qJaQyGu0tvwT2KwEZhANQWZGVg3LS83eupM2F5yiDkE9wDPZ762vQfVUJhIKQ7TDaW8TiacCO2lNnd6xjlYvpm49f5FuNZ+XBxpon5BTfWqSzN4AELAFLq+wSbILFdXgguoibUj7+vu0RKG9jeYHk6uIEXIosQZZiNWYuQSQQTWFuYEV3acXTfwdxitKrQAwumYiYO3JzCkVTyDWwsg+DVZR9YNTL3nqNDnHxNBq2f1mc2I1AgnAIRRfGbVQOamenyQ7ay74sI3z+FWWH9aiOrlCFBOaqqLoIyijw+YWHW9u+CKbGsIc0/s2X0bFpHMNUEuKZVQC/2x0mM00P8idfAAetz2ETwG5fa87PnosuhYBOyo8cttMJW+83dlv/tIl3F+b4CYyp2Txw2VUwAAAAAElFTkSuQmCC");
1033}
1034
1035.file {
1036 background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplc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gzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfcCAwGMTg5XEETAAAB8klEQVQ4y3WSMW/TQBiGn++7sx3XddMAIm0nkCohRQiJDSExdAl/ATEwIPEzkFiYYGRlyMyGxMLExFhByy9ACAaa0gYnDol9x9DYiVs46dPnk/w+9973ngDJ/v7++yAICj+fI0HA/5ZzDu89zjmOjo6yfr//wAJBr9e7G4YhxWSCRFH902qVZdnYx3F8DIQWIMsy1pIEXxSoMfVJ50FeDKUrcGcwAVCANE1ptVqoKqqKMab+rvZhvMbn1y/wg6dItIaIAGABTk5OSJIE9R4AEUFVcc7VPf92wPbtlHz3CRt+jqpSO2i328RxXNtehYgIprXO+ONzrl3+gtEAEW0ChsMhWZY17l5DjOX00xuu7oz5ET3kUmejBteATqdDHMewEK9CPDA/fMVs6xab23tnIv2Hg/F43Jy494gNGH54SffGBqfrj0laS3HDQZqmhGGIW8RWxffn+Dv251t+te/R3enhEUSWVQNGoxF5nuNXxKKGrwfvCHbv4K88wmiJ6nKwjRijKMIYQzmfI4voRIQi3uZ39z5bm50zaHXq4v41YDqdgghSlohzAMymOddv7mGMUJZlI9ZqwE0Hqoi1F15hJVrtCxe+AkgYhgTWIsZgoggRwVp7YWCryxijFWAyGAyeIVKocyLW1o+o6ucL8Hmez4DxX+8dALG7MeVUAAAAAElFTkSuQmCC");
1037}
1038<?=fm_home_style()?>
1039.img {
1040 background-image:
1041url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAAdFQTFRF7e3t/f39pJ+f+cJajV8q6enpkGIm/sFO/+2O393c5ubm/sxbd29yimdneFg65OTk2zoY6uHi1zAS1crJsHs2nygo3Nrb2LBXrYtm2p5A/+hXpoRqpKOkwri46+vr0MG36Ysz6ujpmI6AnzUywL+/mXVSmIBN8bwwj1VByLGza1ZJ0NDQjYSB/9NjwZ6CwUAsxk0brZyWw7pmGZ4A6LtdkHdf/+N8yow27b5W87RNLZL/2biP7wAA//GJl5eX4NfYsaaLgp6h1b+t/+6R68Fe89ycimZd/uQv3r9NupCB99V25a1cVJbbnHhO/8xS+MBa8fDwi2Ji48qi/+qOdVIzs34x//GOXIzYp5SP/sxgqpiIcp+/siQpcmpstayszSANuKKT9PT04uLiwIky8LdE+sVWvqam8e/vL5IZ+rlH8cNg08Ccz7ad8vLy9LtU1qyUuZ4+r512+8s/wUpL3d3dx7W1fGNa/89Z2cfH+s5n6Ojob1Yts7Kz19fXwIg4p1dN+Pj4zLR0+8pd7strhKAs/9hj/9BV1KtftLS1np2dYlJSZFVV5LRWhEFB5rhZ/9Jq0HtT//CSkIqJ6K5D+LNNblVVvjM047ZMz7e31xEG////tKgu6wAAAJt0Uk5T/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wCVVpKYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUKFNjmKWiPQsZMMximsqPKpAb2MsAZNjLOwkzggVmJYnyps/QE59eKCEtBhaYFRfjZuThH27lY6kqBxYorS/OMC5wiHZkl2QCCVTkN+trtFj4ZSpMmawDFBD0lCoynzZBl1nIJj55ElBA09pdvc9buT1SYKYBWw1QIC0oNYsjrFHJpSkvRYsBKCCbM9HLN9tWrbqnjUUGZG1AhGuIXZRzpQl3aGwD2B2cZZ2zEoL7W+u6qyAunZXIOMvQrFykqwTiFzBQNOXj4QKzoAKzajtYIQwAlvtpl3V5c8MAAAAASUVORK5CYII=");
1042}
1043@media screen and (max-width:720px){
1044 table{display:block;}
1045 #fm_table td{display:inline;float:left;}
1046 #fm_table tbody td:first-child{width:100%;padding:0;}
1047 #fm_table tbody tr:nth-child(2n+1){background-color:#EFEFEF;}
1048 #fm_table tbody tr:nth-child(2n){background-color:#DEE3E7;}
1049 #fm_table tr{display:block;float:left;clear:left;width:100%;}
1050 #header_table .row2, #header_table .row3 {display:inline;float:left;width:100%;padding:0;}
1051 #header_table table td {display:inline;float:left;}
1052}
1053</style>
1054</head>
1055<body>
1056<?
1057$url_inc = '?fm=true';
1058if (isset($_POST['sqlrun'])&&!empty($fm_config['enable_sql_console'])){
1059 $res = empty($_POST['sql']) ? '' : $_POST['sql'];
1060 $res_lng = 'sql';
1061} elseif (isset($_POST['phprun'])&&!empty($fm_config['enable_php_console'])){
1062 $res = empty($_POST['php']) ? '' : $_POST['php'];
1063 $res_lng = 'php';
1064}
1065if (isset($_GET['fm_settings'])) {
1066 echo '
1067<table class="whole">
1068<form method="post" action="">
1069<tr><th colspan="2">'.__('File manager').' - '.__('Settings').'</th></tr>
1070'.(empty($msg)?'':'<tr><td class="row2" colspan="2">'.$msg.'</td></tr>').'
1071'.fm_config_checkbox_row(__('Show size of the folder'),'show_dir_size').'
1072'.fm_config_checkbox_row(__('Show').' '.__('pictures'),'show_img').'
1073'.fm_config_checkbox_row(__('Show').' '.__('Make directory'),'make_directory').'
1074'.fm_config_checkbox_row(__('Show').' '.__('New file'),'new_file').'
1075'.fm_config_checkbox_row(__('Show').' '.__('Upload'),'upload_file').'
1076'.fm_config_checkbox_row(__('Show').' PHP version','show_php_ver').'
1077'.fm_config_checkbox_row(__('Show').' PHP ini','show_php_ini').'
1078'.fm_config_checkbox_row(__('Show').' '.__('Generation time'),'show_gt').'
1079'.fm_config_checkbox_row(__('Show').' xls','show_xls').'
1080'.fm_config_checkbox_row(__('Show').' PHP '.__('Console'),'enable_php_console').'
1081'.fm_config_checkbox_row(__('Show').' SQL '.__('Console'),'enable_sql_console').'
1082<tr><td class="row1"><input name="fm_config[sql_server]" value="'.$fm_config['sql_server'].'" type="text"></td><td class="row2 whole">SQL server</td></tr>
1083<tr><td class="row1"><input name="fm_config[sql_username]" value="'.$fm_config['sql_username'].'" type="text"></td><td class="row2 whole">SQL user</td></tr>
1084<tr><td class="row1"><input name="fm_config[sql_password]" value="'.$fm_config['sql_password'].'" type="text"></td><td class="row2 whole">SQL password</td></tr>
1085<tr><td class="row1"><input name="fm_config[sql_db]" value="'.$fm_config['sql_db'].'" type="text"></td><td class="row2 whole">SQL DB</td></tr>
1086'.fm_config_checkbox_row(__('Show').' Proxy','enable_proxy').'
1087'.fm_config_checkbox_row(__('Show').' phpinfo()','show_phpinfo').'
1088'.fm_config_checkbox_row(__('Show').' '.__('Settings'),'fm_settings').'
1089<tr><td class="row3"><a href="'.fm_url().'?fm_settings=true&fm_config_delete=true">'.__('Reset settings').'</a></td><td class="row3"><input type="submit" value="'.__('Save').'" name="fm_config[fm_set_submit]"></td></tr>
1090</form>
1091</table>
1092<table>
1093<form method="post" action="">
1094<tr><th colspan="2">'.__('Settings').' - '.__('Authorization').'</th></tr>
1095<tr><td class="row1"><input name="fm_login[authorize]" value="1" '.($auth['authorize']?'checked':'').' type="checkbox" id="auth"></td><td class="row2 whole"><label for="auth">'.__('Authorization').'</label></td></tr>
1096<tr><td class="row1"><input name="fm_login[login]" value="'.$auth['login'].'" type="text"></td><td class="row2 whole">'.__('Login').'</td></tr>
1097<tr><td class="row1"><input name="fm_login[password]" value="'.$auth['password'].'" type="text"></td><td class="row2 whole">'.__('Password').'</td></tr>
1098<tr><td class="row1"><input name="fm_login[cookie_name]" value="'.$auth['cookie_name'].'" type="text"></td><td class="row2 whole">'.__('Cookie').'</td></tr>
1099<tr><td class="row1"><input name="fm_login[days_authorization]" value="'.$auth['days_authorization'].'" type="text"></td><td class="row2 whole">'.__('Days').'</td></tr>
1100<tr><td class="row1"><textarea name="fm_login[script]" cols="35" rows="7" class="textarea_input" id="auth_script">'.$auth['script'].'</textarea></td><td class="row2 whole">'.__('Script').'</td></tr>
1101<tr><td colspan="2" class="row3"><input type="submit" value="'.__('Save').'" ></td></tr>
1102</form>
1103</table>';
1104echo fm_tpl_form('php'),fm_tpl_form('sql');
1105} elseif (isset($proxy_form)) {
1106 die($proxy_form);
1107} elseif (isset($res_lng)) {
1108?>
1109<table class="whole">
1110<tr>
1111 <th><?=__('File manager').' - '.$path?></th>
1112</tr>
1113<tr>
1114 <td class="row2"><table><tr><td><h2><?=strtoupper($res_lng)?> <?=__('Console')?><?
1115 if($res_lng=='sql') echo ' - Database: '.$fm_config['sql_db'].'</h2></td><td>'.fm_run_input('php');
1116 else echo '</h2></td><td>'.fm_run_input('sql');
1117 ?></td></tr></table></td>
1118</tr>
1119<tr>
1120 <td class="row1">
1121 <a href="<?=$url_inc.'&path=' . $path;?>"><?=__('Back')?></a>
1122 <form action="" method="POST" name="console">
1123 <textarea name="<?=$res_lng?>" cols="80" rows="10" style="width: 90%"><?=$res?></textarea><br/>
1124 <input type="reset" value="<?=__('Reset')?>">
1125 <input type="submit" value="<?=__('Submit')?>" name="<?=$res_lng?>run">
1126<?
1127$str_tmpl = $res_lng.'_templates';
1128$tmpl = !empty($$str_tmpl) ? json_decode($$str_tmpl,true) : '';
1129if (!empty($tmpl)){
1130 $active = isset($_POST[$res_lng.'_tpl']) ? $_POST[$res_lng.'_tpl'] : '';
1131 $select = '<select name="'.$res_lng.'_tpl" title="'.__('Template').'" onchange="if (this.value!=-1) document.forms[\'console\'].elements[\''.$res_lng.'\'].value = this.options[selectedIndex].value; else document.forms[\'console\'].elements[\''.$res_lng.'\'].value =\'\';" >'."\n";
1132 $select .= '<option value="-1">' . __('Select') . "</option>\n";
1133 foreach ($tmpl as $key=>$value){
1134 $select.='<option value="'.$value.'" '.((!empty($value)&&($value==$active))?'selected':'').' >'.__($key)."</option>\n";
1135 }
1136 $select .= "</select>\n";
1137 echo $select;
1138}
1139?>
1140 </form>
1141 </td>
1142</tr>
1143</table>
1144<?
1145 if (!empty($res)) {
1146 $fun='fm_'.$res_lng;
1147 echo '<h3>'.strtoupper($res_lng).' '.__('Result').'</h3><pre>'.$fun($res).'</pre>';
1148 }
1149} elseif(!empty($_REQUEST['edit'])){
1150 if(!empty($_REQUEST['save'])) {
1151 $fn = $path . $_REQUEST['edit'];
1152 $filemtime = filemtime($fn);
1153 if (file_put_contents($fn, $_REQUEST['newcontent'])) $msg .= __('File updated');
1154 else $msg .= __('Error occurred');
1155 if ($_GET['edit']==basename(__FILE__)) touch(__FILE__,1415116371);
1156 else touch($fn,$filemtime);
1157 }
1158 $oldcontent = @file_get_contents($path . $_REQUEST['edit']);
1159 $editlink = $url_inc . '&edit=' . $_REQUEST['edit'] . '&path=' . $path;
1160 $backlink = $url_inc . '&path=' . $path;
1161?>
1162<table border='0' cellspacing='0' cellpadding='1' width="100%">
1163<tr>
1164 <th><?=__('File manager').' - '.__('Edit').' - '.$path.$_REQUEST['edit']?></th>
1165</tr>
1166<tr>
1167 <td class="row1">
1168 <?=$msg?>
1169 </td>
1170</tr>
1171<tr>
1172 <td class="row1">
1173 <?=fm_home()?> <a href="<?=$backlink?>"><?=__('Back')?></a>
1174 </td>
1175</tr>
1176<tr>
1177 <td class="row1" align="center">
1178 <form name="form1" method="post" action="<?=$editlink?>">
1179 <textarea name="newcontent" id="newcontent" cols="45" rows="15" style="width:99%" spellcheck="false"><?=htmlspecialchars($oldcontent)?></textarea>
1180 <input type="submit" name="save" value="<?=__('Submit')?>">
1181 <input type="submit" name="cancel" value="<?=__('Cancel')?>">
1182 </form>
1183 </td>
1184</tr>
1185</table>
1186<?
1187} elseif(!empty($_REQUEST['rights'])){
1188 if(!empty($_REQUEST['save'])) {
1189 if(fm_chmod($path . $_REQUEST['rights'], fm_convert_rights($_REQUEST['rights_val']), @$_REQUEST['recursively']))
1190 $msg .= (__('File updated'));
1191 else $msg .= (__('Error occurred'));
1192 }
1193 clearstatcache();
1194 $oldrights = fm_rights_string($path . $_REQUEST['rights'], true);
1195 $link = $url_inc . '&rights=' . $_REQUEST['rights'] . '&path=' . $path;
1196 $backlink = $url_inc . '&path=' . $path;
1197?>
1198<table class="whole">
1199<tr>
1200 <th><?=__('File manager').' - '.$path?></th>
1201</tr>
1202<tr>
1203 <td class="row1">
1204 <?=$msg?>
1205 </td>
1206</tr>
1207<tr>
1208 <td class="row1">
1209 <a href="<?=$backlink?>"><?=__('Back')?></a>
1210 </td>
1211</tr>
1212<tr>
1213 <td class="row1" align="center">
1214 <form name="form1" method="post" action="<?=$link?>">
1215 <?=__('Rights').' - '.$_REQUEST['rights']?> <input type="text" name="rights_val" value="<?=$oldrights?>">
1216 <? if (is_dir($path.$_REQUEST['rights'])) {?>
1217 <input type="checkbox" name="recursively" value="1"> <?=__('Recursively')?><br/>
1218 <? } ?>
1219 <input type="submit" name="save" value="<?=__('Submit')?>">
1220 </form>
1221 </td>
1222</tr>
1223</table>
1224<?
1225} elseif (!empty($_REQUEST['rename'])&&$_REQUEST['rename']<>'.') {
1226 if(!empty($_REQUEST['save'])) {
1227 rename($path . $_REQUEST['rename'], $path . $_REQUEST['newname']);
1228 $msg .= (__('File updated'));
1229 $_REQUEST['rename'] = $_REQUEST['newname'];
1230 }
1231 clearstatcache();
1232 $link = $url_inc . '&rename=' . $_REQUEST['rename'] . '&path=' . $path;
1233 $backlink = $url_inc . '&path=' . $path;
1234
1235?>
1236<table class="whole">
1237<tr>
1238 <th><?=__('File manager').' - '.$path?></th>
1239</tr>
1240<tr>
1241 <td class="row1">
1242 <?=$msg?>
1243 </td>
1244</tr>
1245<tr>
1246 <td class="row1">
1247 <a href="<?=$backlink?>"><?=__('Back')?></a>
1248 </td>
1249</tr>
1250<tr>
1251 <td class="row1" align="center">
1252 <form name="form1" method="post" action="<?=$link?>">
1253 <?=__('Rename')?>: <input type="text" name="newname" value="<?=$_REQUEST['rename']?>"><br/>
1254 <input type="submit" name="save" value="<?=__('Submit')?>">
1255 </form>
1256 </td>
1257</tr>
1258</table>
1259<?
1260} else {
1261//Let's rock!
1262 $msg = '';
1263 if(!empty($_FILES['upload'])&&!empty($fm_config['upload_file'])) {
1264 if(!empty($_FILES['upload']['name'])){
1265 $_FILES['upload']['name'] = str_replace('%', '', $_FILES['upload']['name']);
1266 if(!move_uploaded_file($_FILES['upload']['tmp_name'], $path . $_FILES['upload']['name'])){
1267 $msg .= __('Error occurred');
1268 } else {
1269 $msg .= __('Files uploaded').': '.$_FILES['upload']['name'];
1270 }
1271 }
1272 } elseif(!empty($_REQUEST['delete'])&&$_REQUEST['delete']<>'.') {
1273 if(!fm_del_files(($path . $_REQUEST['delete']), true)) {
1274 $msg .= __('Error occurred');
1275 } else {
1276 $msg .= __('Deleted').' '.$_REQUEST['delete'];
1277 }
1278 } elseif(!empty($_REQUEST['mkdir'])&&!empty($fm_config['make_directory'])) {
1279 if(!@mkdir($path . $_REQUEST['dirname'],0777)) {
1280 $msg .= __('Error occurred');
1281 } else {
1282 $msg .= __('Created').' '.$_REQUEST['dirname'];
1283 }
1284 } elseif(!empty($_REQUEST['mkfile'])&&!empty($fm_config['new_file'])) {
1285 if(!$fp=@fopen($path . $_REQUEST['filename'],"w")) {
1286 $msg .= __('Error occurred');
1287 } else {
1288 fclose($fp);
1289 $msg .= __('Created').' '.$_REQUEST['filename'];
1290 }
1291 } elseif (isset($_GET['zip'])) {
1292 $source = base64_decode($_GET['zip']);
1293 $destination = basename($source).'.zip';
1294 set_time_limit(0);
1295 $phar = new PharData($destination);
1296 $phar->buildFromDirectory($source);
1297 if (is_file($destination))
1298 $msg .= __('Task').' "'.__('Archiving').' '.$destination.'" '.__('done').
1299 '. '.fm_link('download',$path.$destination,__('Download'),__('Download').' '. $destination)
1300 .' <a href="'.$url_inc.'&delete='.$destination.'&path=' . $path.'" title="'.__('Delete').' '. $destination.'" >'.__('Delete') . '</a>';
1301 else $msg .= __('Error occurred').': '.__('no files');
1302 } elseif (isset($_GET['gz'])) {
1303 $source = base64_decode($_GET['gz']);
1304 $archive = $source.'.tar';
1305 $destination = basename($source).'.tar';
1306 if (is_file($archive)) unlink($archive);
1307 if (is_file($archive.'.gz')) unlink($archive.'.gz');
1308 clearstatcache();
1309 set_time_limit(0);
1310 //die();
1311 $phar = new PharData($destination);
1312 $phar->buildFromDirectory($source);
1313 $phar->compress(Phar::GZ,'.tar.gz');
1314 unset($phar);
1315 if (is_file($archive)) {
1316 if (is_file($archive.'.gz')) {
1317 unlink($archive);
1318 $destination .= '.gz';
1319 }
1320
1321 $msg .= __('Task').' "'.__('Archiving').' '.$destination.'" '.__('done').
1322 '. '.fm_link('download',$path.$destination,__('Download'),__('Download').' '. $destination)
1323 .' <a href="'.$url_inc.'&delete='.$destination.'&path=' . $path.'" title="'.__('Delete').' '.$destination.'" >'.__('Delete').'</a>';
1324 } else $msg .= __('Error occurred').': '.__('no files');
1325 } elseif (isset($_GET['decompress'])) {
1326 // $source = base64_decode($_GET['decompress']);
1327 // $destination = basename($source);
1328 // $ext = end(explode(".", $destination));
1329 // if ($ext=='zip' OR $ext=='gz') {
1330 // $phar = new PharData($source);
1331 // $phar->decompress();
1332 // $base_file = str_replace('.'.$ext,'',$destination);
1333 // $ext = end(explode(".", $base_file));
1334 // if ($ext=='tar'){
1335 // $phar = new PharData($base_file);
1336 // $phar->extractTo(dir($source));
1337 // }
1338 // }
1339 // $msg .= __('Task').' "'.__('Decompress').' '.$source.'" '.__('done');
1340 } elseif (isset($_GET['gzfile'])) {
1341 $source = base64_decode($_GET['gzfile']);
1342 $archive = $source.'.tar';
1343 $destination = basename($source).'.tar';
1344 if (is_file($archive)) unlink($archive);
1345 if (is_file($archive.'.gz')) unlink($archive.'.gz');
1346 set_time_limit(0);
1347 //echo $destination;
1348 $ext_arr = explode('.',basename($source));
1349 if (isset($ext_arr[1])) {
1350 unset($ext_arr[0]);
1351 $ext=implode('.',$ext_arr);
1352 }
1353 $phar = new PharData($destination);
1354 $phar->addFile($source);
1355 $phar->compress(Phar::GZ,$ext.'.tar.gz');
1356 unset($phar);
1357 if (is_file($archive)) {
1358 if (is_file($archive.'.gz')) {
1359 unlink($archive);
1360 $destination .= '.gz';
1361 }
1362 $msg .= __('Task').' "'.__('Archiving').' '.$destination.'" '.__('done').
1363 '. '.fm_link('download',$path.$destination,__('Download'),__('Download').' '. $destination)
1364 .' <a href="'.$url_inc.'&delete='.$destination.'&path=' . $path.'" title="'.__('Delete').' '.$destination.'" >'.__('Delete').'</a>';
1365 } else $msg .= __('Error occurred').': '.__('no files');
1366 }
1367?>
1368<table class="whole" id="header_table" >
1369<tr>
1370 <th colspan="2"><?=__('File manager')?><?=(!empty($path)?' - '.$path:'')?></th>
1371</tr>
1372<?if(!empty($msg)){?>
1373<tr>
1374 <td colspan="2" class="row2"><?=$msg?></td>
1375</tr>
1376<?}?>
1377<tr>
1378 <td class="row2">
1379 <table>
1380 <tr>
1381 <td>
1382 <?=fm_home()?>
1383 </td>
1384 <td>
1385 <?if(!empty($fm_config['make_directory'])) {?>
1386 <form method="post" action="<?=$url_inc?>">
1387 <input type="hidden" name="path" value="<?=$path?>" />
1388 <input type="text" name="dirname" size="15">
1389 <input type="submit" name="mkdir" value="<?=__('Make directory')?>">
1390 </form>
1391 <?}?>
1392 </td>
1393 <td>
1394 <?if(!empty($fm_config['new_file'])) {?>
1395 <form method="post" action="<?=$url_inc?>">
1396 <input type="hidden" name="path" value="<?=$path?>" />
1397 <input type="text" name="filename" size="15">
1398 <input type="submit" name="mkfile" value="<?=__('New file')?>">
1399 </form>
1400 <?}?>
1401 </td>
1402 <td>
1403 <?=fm_run_input('php')?>
1404 </td>
1405 <td>
1406 <?=fm_run_input('sql')?>
1407 </td>
1408 </tr>
1409 </table>
1410 </td>
1411 <td class="row3">
1412 <table>
1413 <tr>
1414 <td>
1415 <?if (!empty($fm_config['upload_file'])) {?>
1416 <form name="form1" method="post" action="<?=$url_inc?>" enctype="multipart/form-data">
1417 <input type="hidden" name="path" value="<?=$path?>" />
1418 <input type="file" name="upload" id="upload_hidden" style="position: absolute; display: block; overflow: hidden; width: 0; height: 0; border: 0; padding: 0;" onchange="document.getElementById('upload_visible').value = this.value;" />
1419 <input type="text" readonly="1" id="upload_visible" placeholder="<?=__('Select the file')?>" style="cursor: pointer;" onclick="document.getElementById('upload_hidden').click();" />
1420 <input type="submit" name="test" value="<?=__('Upload')?>" />
1421 </form>
1422 <?}?>
1423 </td>
1424 <td>
1425 <?if ($auth['authorize']) {?>
1426 <form action="" method="post">
1427 <input name="quit" type="hidden" value="1">
1428 <?=__('Hello')?>, <?=$auth['login']?>
1429 <input type="submit" value="<?=__('Quit')?>">
1430 </form>
1431 <?}?>
1432 </td>
1433 <td>
1434 <?=fm_lang_form($language)?>
1435 </td>
1436 <tr>
1437 </table>
1438 </td>
1439</tr>
1440</table>
1441<table class="all" border='0' cellspacing='1' cellpadding='1' id="fm_table" width="100%">
1442<thead>
1443<tr>
1444 <th style="white-space:nowrap"> <?=__('Filename')?> </th>
1445 <th style="white-space:nowrap"> <?=__('Size')?> </th>
1446 <th style="white-space:nowrap"> <?=__('Date')?> </th>
1447 <th style="white-space:nowrap"> <?=__('Rights')?> </th>
1448 <th colspan="4" style="white-space:nowrap"> <?=__('Manage')?> </th>
1449</tr>
1450</thead>
1451<tbody>
1452<?
1453$elements = fm_scan_dir($path, '', 'all', true);
1454$dirs = array();
1455$files = array();
1456foreach ($elements as $file){
1457 if(@is_dir($path . $file)){
1458 $dirs[] = $file;
1459 } else {
1460 $files[] = $file;
1461 }
1462}
1463natsort($dirs); natsort($files);
1464$elements = array_merge($dirs, $files);
1465
1466foreach ($elements as $file){
1467 $filename = $path . $file;
1468 $filedata = @stat($filename);
1469 if(@is_dir($filename)){
1470 $filedata[7] = '';
1471 if (!empty($fm_config['show_dir_size'])&&!fm_root($file)) $filedata[7] = fm_dir_size($filename);
1472 $link = '<a href="'.$url_inc.'&path='.$path.$file.'" title="'.__('Show').' '.$file.'"><span class="folder"> </span> '.$file.'</a>';
1473 $loadlink= (fm_root($file)||$phar_maybe) ? '' : fm_link('zip',$filename,__('Compress').' zip',__('Archiving').' '. $file);
1474 $arlink = (fm_root($file)||$phar_maybe) ? '' : fm_link('gz',$filename,__('Compress').' .tar.gz',__('Archiving').' '.$file);
1475 $style = 'row2';
1476 if (!fm_root($file)) $alert = 'onClick="if(confirm(\'' . __('Are you sure you want to delete this directory (recursively)?').'\n /'. $file. '\')) document.location.href = \'' . $url_inc . '&delete=' . $file . '&path=' . $path . '\'"'; else $alert = '';
1477 } else {
1478 $link =
1479 $fm_config['show_img']&&getimagesize($filename)
1480 ? '<a target="_blank" onclick="var lefto = screen.availWidth/2-320;window.open(\''
1481 . fm_img_link($filename)
1482 .'\',\'popup\',\'width=640,height=480,left=\' + lefto + \',scrollbars=yes,toolbar=no,location=no,directories=no,status=no\');return false;" href="'.fm_img_link($filename).'"><span class="img"> </span> '.$file.'</a>'
1483 : '<a href="' . $url_inc . '&edit=' . $file . '&path=' . $path. '" title="' . __('Edit') . '"><span class="file"> </span> '.$file.'</a>';
1484 $e_arr = explode(".", $file);
1485 $ext = end($e_arr);
1486 $loadlink = fm_link('download',$filename,__('Download'),__('Download').' '. $file);
1487 $arlink = in_array($ext,array('zip','gz','tar'))
1488 ? ''
1489 : ((fm_root($file)||$phar_maybe) ? '' : fm_link('gzfile',$filename,__('Compress').' .tar.gz',__('Archiving').' '. $file));
1490 $style = 'row1';
1491 $alert = 'onClick="if(confirm(\''. __('File selected').': \n'. $file. '. \n'.__('Are you sure you want to delete this file?') . '\')) document.location.href = \'' . $url_inc . '&delete=' . $file . '&path=' . $path . '\'"';
1492 }
1493 $deletelink = fm_root($file) ? '' : '<a href="#" title="' . __('Delete') . ' '. $file . '" ' . $alert . '>' . __('Delete') . '</a>';
1494 $renamelink = fm_root($file) ? '' : '<a href="' . $url_inc . '&rename=' . $file . '&path=' . $path . '" title="' . __('Rename') .' '. $file . '">' . __('Rename') . '</a>';
1495 $rightstext = ($file=='.' || $file=='..') ? '' : '<a href="' . $url_inc . '&rights=' . $file . '&path=' . $path . '" title="' . __('Rights') .' '. $file . '">' . @fm_rights_string($filename) . '</a>';
1496?>
1497<tr class="<?=$style?>">
1498 <td><?=$link?></td>
1499 <td><?=$filedata[7]?></td>
1500 <td style="white-space:nowrap"><?=gmdate("Y-m-d H:i:s",$filedata[9])?></td>
1501 <td><?=$rightstext?></td>
1502 <td><?=$deletelink?></td>
1503 <td><?=$renamelink?></td>
1504 <td><?=$loadlink?></td>
1505 <td><?=$arlink?></td>
1506</tr>
1507<?
1508 }
1509}
1510?>
1511</tbody>
1512</table>
1513<div class="row3"><?
1514 $mtime = explode(' ', microtime());
1515 $totaltime = $mtime[0] + $mtime[1] - $starttime;
1516 echo fm_home().' | ver. '.$fm_version.' | <a href="https://github.com/Den1xxx/Filemanager">Github</a> | <a href="'.fm_site_url().'">.</a>';
1517 if (!empty($fm_config['show_php_ver'])) echo ' | PHP '.phpversion();
1518 if (!empty($fm_config['show_php_ini'])) echo ' | '.php_ini_loaded_file();
1519 if (!empty($fm_config['show_gt'])) echo ' | '.__('Generation time').': '.round($totaltime,2);
1520 if (!empty($fm_config['enable_proxy'])) echo ' | <a href="?proxy=true">proxy</a>';
1521 if (!empty($fm_config['show_phpinfo'])) echo ' | <a href="?phpinfo=true">phpinfo</a>';
1522 if (!empty($fm_config['show_xls'])&&!empty($link)) echo ' | <a href="javascript: void(0)" onclick="var obj = new table2Excel(); obj.CreateExcelSheet(\'fm_table\',\'export\');" title="'.__('Download').' xls">xls</a>';
1523 if (!empty($fm_config['fm_settings'])) echo ' | <a href="?fm_settings=true">'.__('Settings').'</a>';
1524 ?>
1525</div>
1526<?=$auth['script']?>
1527<script type="text/javascript">
1528function download_xls(filename, text) {
1529 var element = document.createElement('a');
1530 element.setAttribute('href', 'data:application/vnd.ms-excel;base64,' + text);
1531 element.setAttribute('download', filename);
1532 element.style.display = 'none';
1533 document.body.appendChild(element);
1534 element.click();
1535 document.body.removeChild(element);
1536}
1537
1538function base64_encode(m) {
1539 for (var k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""), c, d, h, e, a, g = "", b = 0, f, l = 0; l < m.length; ++l) {
1540 c = m.charCodeAt(l);
1541 if (128 > c) d = 1;
1542 else
1543 for (d = 2; c >= 2 << 5 * d;) ++d;
1544 for (h = 0; h < d; ++h) 1 == d ? e = c : (e = h ? 128 : 192, a = d - 2 - 6 * h, 0 <= a && (e += (6 <= a ? 1 : 0) + (5 <= a ? 2 : 0) + (4 <= a ? 4 : 0) + (3 <= a ? 8 : 0) + (2 <= a ? 16 : 0) + (1 <= a ? 32 : 0), a -= 5), 0 > a && (u = 6 * (d - 1 - h), e += c >> u, c -= c >> u << u)), f = b ? f << 6 - b : 0, b += 2, f += e >> b, g += k[f], f = e % (1 << b), 6 == b && (b = 0, g += k[f])
1545 }
1546 b && (g += k[f << 6 - b]);
1547 return g
1548}
1549
1550
1551var tableToExcelData = (function() {
1552 var uri = 'data:application/vnd.ms-excel;base64,',
1553 template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines></x:DisplayGridlines></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>',
1554 format = function(s, c) {
1555 return s.replace(/{(\w+)}/g, function(m, p) {
1556 return c[p];
1557 })
1558 }
1559 return function(table, name) {
1560 if (!table.nodeType) table = document.getElementById(table)
1561 var ctx = {
1562 worksheet: name || 'Worksheet',
1563 table: table.innerHTML.replace(/<span(.*?)\/span> /g,"").replace(/<a\b[^>]*>(.*?)<\/a>/g,"$1")
1564 }
1565 t = new Date();
1566 filename = 'fm_' + t.toISOString() + '.xls'
1567 download_xls(filename, base64_encode(format(template, ctx)))
1568 }
1569})();
1570
1571var table2Excel = function () {
1572
1573 var ua = window.navigator.userAgent;
1574 var msie = ua.indexOf("MSIE ");
1575
1576 this.CreateExcelSheet =
1577 function(el, name){
1578 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {// If Internet Explorer
1579
1580 var x = document.getElementById(el).rows;
1581
1582 var xls = new ActiveXObject("Excel.Application");
1583
1584 xls.visible = true;
1585 xls.Workbooks.Add
1586 for (i = 0; i < x.length; i++) {
1587 var y = x[i].cells;
1588
1589 for (j = 0; j < y.length; j++) {
1590 xls.Cells(i + 1, j + 1).Value = y[j].innerText;
1591 }
1592 }
1593 xls.Visible = true;
1594 xls.UserControl = true;
1595 return xls;
1596 } else {
1597 tableToExcelData(el, name);
1598 }
1599 }
1600}
1601</script>
1602</body>
1603</html>
1604
1605<?
1606//Ported from ReloadCMS project http://reloadcms.com
1607class archiveTar {
1608 var $archive_name = '';
1609 var $tmp_file = 0;
1610 var $file_pos = 0;
1611 var $isGzipped = true;
1612 var $errors = array();
1613 var $files = array();
1614
1615 function __construct(){
1616 if (!isset($this->errors)) $this->errors = array();
1617 }
1618
1619 function createArchive($file_list){
1620 $result = false;
1621 if (file_exists($this->archive_name) && is_file($this->archive_name)) $newArchive = false;
1622 else $newArchive = true;
1623 if ($newArchive){
1624 if (!$this->openWrite()) return false;
1625 } else {
1626 if (filesize($this->archive_name) == 0) return $this->openWrite();
1627 if ($this->isGzipped) {
1628 $this->closeTmpFile();
1629 if (!rename($this->archive_name, $this->archive_name.'.tmp')){
1630 $this->errors[] = __('Cannot rename').' '.$this->archive_name.__(' to ').$this->archive_name.'.tmp';
1631 return false;
1632 }
1633 $tmpArchive = gzopen($this->archive_name.'.tmp', 'rb');
1634 if (!$tmpArchive){
1635 $this->errors[] = $this->archive_name.'.tmp '.__('is not readable');
1636 rename($this->archive_name.'.tmp', $this->archive_name);
1637 return false;
1638 }
1639 if (!$this->openWrite()){
1640 rename($this->archive_name.'.tmp', $this->archive_name);
1641 return false;
1642 }
1643 $buffer = gzread($tmpArchive, 512);
1644 if (!gzeof($tmpArchive)){
1645 do {
1646 $binaryData = pack('a512', $buffer);
1647 $this->writeBlock($binaryData);
1648 $buffer = gzread($tmpArchive, 512);
1649 }
1650 while (!gzeof($tmpArchive));
1651 }
1652 gzclose($tmpArchive);
1653 unlink($this->archive_name.'.tmp');
1654 } else {
1655 $this->tmp_file = fopen($this->archive_name, 'r+b');
1656 if (!$this->tmp_file) return false;
1657 }
1658 }
1659 if (isset($file_list) && is_array($file_list)) {
1660 if (count($file_list)>0)
1661 $result = $this->packFileArray($file_list);
1662 } else $this->errors[] = __('No file').__(' to ').__('Archive');
1663 if (($result)&&(is_resource($this->tmp_file))){
1664 $binaryData = pack('a512', '');
1665 $this->writeBlock($binaryData);
1666 }
1667 $this->closeTmpFile();
1668 if ($newArchive && !$result){
1669 $this->closeTmpFile();
1670 unlink($this->archive_name);
1671 }
1672 return $result;
1673 }
1674
1675 function restoreArchive($path){
1676 $fileName = $this->archive_name;
1677 if (!$this->isGzipped){
1678 if (file_exists($fileName)){
1679 if ($fp = fopen($fileName, 'rb')){
1680 $data = fread($fp, 2);
1681 fclose($fp);
1682 if ($data == '\37\213'){
1683 $this->isGzipped = true;
1684 }
1685 }
1686 }
1687 elseif ((substr($fileName, -2) == 'gz') OR (substr($fileName, -3) == 'tgz')) $this->isGzipped = true;
1688 }
1689 $result = true;
1690 if ($this->isGzipped) $this->tmp_file = gzopen($fileName, 'rb');
1691 else $this->tmp_file = fopen($fileName, 'rb');
1692 if (!$this->tmp_file){
1693 $this->errors[] = $fileName.' '.__('is not readable');
1694 return false;
1695 }
1696 $result = $this->unpackFileArray($path);
1697 $this->closeTmpFile();
1698 return $result;
1699 }
1700
1701 function showErrors ($message = '') {
1702 $Errors = $this->errors;
1703 if(count($Errors)>0) {
1704 if (!empty($message)) $message = ' ('.$message.')';
1705 $message = __('Error occurred').$message.': <br/>';
1706 foreach ($Errors as $value)
1707 $message .= $value.'<br/>';
1708 return $message;
1709 } else return '';
1710
1711 }
1712
1713 function packFileArray($file_array){
1714 $result = true;
1715 if (!$this->tmp_file){
1716 $this->errors[] = __('Invalid file descriptor');
1717 return false;
1718 }
1719 if (!is_array($file_array) || count($file_array)<=0)
1720 return true;
1721 for ($i = 0; $i<count($file_array); $i++){
1722 $filename = $file_array[$i];
1723 if ($filename == $this->archive_name)
1724 continue;
1725 if (strlen($filename)<=0)
1726 continue;
1727 if (!file_exists($filename)){
1728 $this->errors[] = __('No file').' '.$filename;
1729 continue;
1730 }
1731 if (!$this->tmp_file){
1732 $this->errors[] = __('Invalid file descriptor');
1733 return false;
1734 }
1735 if (strlen($filename)<=0){
1736 $this->errors[] = __('Filename').' '.__('is incorrect');;
1737 return false;
1738 }
1739 $filename = str_replace('\\', '/', $filename);
1740 $keep_filename = $this->makeGoodPath($filename);
1741 if (is_file($filename)){
1742 if (($file = fopen($filename, 'rb')) == 0){
1743 $this->errors[] = __('Mode ').__('is incorrect');
1744 }
1745 if(($this->file_pos == 0)){
1746 if(!$this->writeHeader($filename, $keep_filename))
1747 return false;
1748 }
1749 while (($buffer = fread($file, 512)) != ''){
1750 $binaryData = pack('a512', $buffer);
1751 $this->writeBlock($binaryData);
1752 }
1753 fclose($file);
1754 } else $this->writeHeader($filename, $keep_filename);
1755 if (@is_dir($filename)){
1756 if (!($handle = opendir($filename))){
1757 $this->errors[] = __('Error').': '.__('Directory ').$filename.__('is not readable');
1758 continue;
1759 }
1760 while (false !== ($dir = readdir($handle))){
1761 if ($dir!='.' && $dir!='..'){
1762 $file_array_tmp = array();
1763 if ($filename != '.')
1764 $file_array_tmp[] = $filename.'/'.$dir;
1765 else
1766 $file_array_tmp[] = $dir;
1767
1768 $result = $this->packFileArray($file_array_tmp);
1769 }
1770 }
1771 unset($file_array_tmp);
1772 unset($dir);
1773 unset($handle);
1774 }
1775 }
1776 return $result;
1777 }
1778
1779 function unpackFileArray($path){
1780 $path = str_replace('\\', '/', $path);
1781 if ($path == '' || (substr($path, 0, 1) != '/' && substr($path, 0, 3) != '../' && !strpos($path, ':'))) $path = './'.$path;
1782 clearstatcache();
1783 while (strlen($binaryData = $this->readBlock()) != 0){
1784 if (!$this->readHeader($binaryData, $header)) return false;
1785 if ($header['filename'] == '') continue;
1786 if ($header['typeflag'] == 'L'){ //reading long header
1787 $filename = '';
1788 $decr = floor($header['size']/512);
1789 for ($i = 0; $i < $decr; $i++){
1790 $content = $this->readBlock();
1791 $filename .= $content;
1792 }
1793 if (($laspiece = $header['size'] % 512) != 0){
1794 $content = $this->readBlock();
1795 $filename .= substr($content, 0, $laspiece);
1796 }
1797 $binaryData = $this->readBlock();
1798 if (!$this->readHeader($binaryData, $header)) return false;
1799 else $header['filename'] = $filename;
1800 return true;
1801 }
1802 if (($path != './') && ($path != '/')){
1803 while (substr($path, -1) == '/') $path = substr($path, 0, strlen($path)-1);
1804 if (substr($header['filename'], 0, 1) == '/') $header['filename'] = $path.$header['filename'];
1805 else $header['filename'] = $path.'/'.$header['filename'];
1806 }
1807
1808 if (file_exists($header['filename'])){
1809 if ((@is_dir($header['filename'])) && ($header['typeflag'] == '')){
1810 $this->errors[] =__('File ').$header['filename'].__(' already exists').__(' as folder');
1811 return false;
1812 }
1813 if ((is_file($header['filename'])) && ($header['typeflag'] == '5')){
1814 $this->errors[] =__('Cannot create directory').'. '.__('File ').$header['filename'].__(' already exists');
1815 return false;
1816 }
1817 if (!is_writeable($header['filename'])){
1818 $this->errors[] = __('Cannot write to file').'. '.__('File ').$header['filename'].__(' already exists');
1819 return false;
1820 }
1821 } elseif (($this->dirCheck(($header['typeflag'] == '5' ? $header['filename'] : dirname($header['filename'])))) != 1){
1822 $this->errors[] = __('Cannot create directory').' '.__(' for ').$header['filename'];
1823 return false;
1824 }
1825
1826 if ($header['typeflag'] == '5'){
1827 if (!file_exists($header['filename'])) {
1828 if (!mkdir($header['filename'], 0777)) {
1829
1830 $this->errors[] = __('Cannot create directory').' '.$header['filename'];
1831 return false;
1832 }
1833 }
1834 } else {
1835 if (($destination = fopen($header['filename'], 'wb')) == 0) {
1836 $this->errors[] = __('Cannot write to file').' '.$header['filename'];
1837 return false;
1838 } else {
1839 $decr = floor($header['size']/512);
1840 for ($i = 0; $i < $decr; $i++) {
1841 $content = $this->readBlock();
1842 fwrite($destination, $content, 512);
1843 }
1844 if (($header['size'] % 512) != 0) {
1845 $content = $this->readBlock();
1846 fwrite($destination, $content, ($header['size'] % 512));
1847 }
1848 fclose($destination);
1849 touch($header['filename'], $header['time']);
1850 }
1851 clearstatcache();
1852 if (filesize($header['filename']) != $header['size']) {
1853 $this->errors[] = __('Size of file').' '.$header['filename'].' '.__('is incorrect');
1854 return false;
1855 }
1856 }
1857 if (($file_dir = dirname($header['filename'])) == $header['filename']) $file_dir = '';
1858 if ((substr($header['filename'], 0, 1) == '/') && ($file_dir == '')) $file_dir = '/';
1859 $this->dirs[] = $file_dir;
1860 $this->files[] = $header['filename'];
1861
1862 }
1863 return true;
1864 }
1865
1866 function dirCheck($dir){
1867 $parent_dir = dirname($dir);
1868
1869 if ((@is_dir($dir)) or ($dir == ''))
1870 return true;
1871
1872 if (($parent_dir != $dir) and ($parent_dir != '') and (!$this->dirCheck($parent_dir)))
1873 return false;
1874
1875 if (!mkdir($dir, 0777)){
1876 $this->errors[] = __('Cannot create directory').' '.$dir;
1877 return false;
1878 }
1879 return true;
1880 }
1881
1882 function readHeader($binaryData, &$header){
1883 if (strlen($binaryData)==0){
1884 $header['filename'] = '';
1885 return true;
1886 }
1887
1888 if (strlen($binaryData) != 512){
1889 $header['filename'] = '';
1890 $this->__('Invalid block size').': '.strlen($binaryData);
1891 return false;
1892 }
1893
1894 $checksum = 0;
1895 for ($i = 0; $i < 148; $i++) $checksum+=ord(substr($binaryData, $i, 1));
1896 for ($i = 148; $i < 156; $i++) $checksum += ord(' ');
1897 for ($i = 156; $i < 512; $i++) $checksum+=ord(substr($binaryData, $i, 1));
1898
1899 $unpack_data = unpack('a100filename/a8mode/a8user_id/a8group_id/a12size/a12time/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor', $binaryData);
1900
1901 $header['checksum'] = OctDec(trim($unpack_data['checksum']));
1902 if ($header['checksum'] != $checksum){
1903 $header['filename'] = '';
1904 if (($checksum == 256) && ($header['checksum'] == 0)) return true;
1905 $this->errors[] = __('Error checksum for file ').$unpack_data['filename'];
1906 return false;
1907 }
1908
1909 if (($header['typeflag'] = $unpack_data['typeflag']) == '5') $header['size'] = 0;
1910 $header['filename'] = trim($unpack_data['filename']);
1911 $header['mode'] = OctDec(trim($unpack_data['mode']));
1912 $header['user_id'] = OctDec(trim($unpack_data['user_id']));
1913 $header['group_id'] = OctDec(trim($unpack_data['group_id']));
1914 $header['size'] = OctDec(trim($unpack_data['size']));
1915 $header['time'] = OctDec(trim($unpack_data['time']));
1916 return true;
1917 }
1918
1919 function writeHeader($filename, $keep_filename){
1920 $packF = 'a100a8a8a8a12A12';
1921 $packL = 'a1a100a6a2a32a32a8a8a155a12';
1922 if (strlen($keep_filename)<=0) $keep_filename = $filename;
1923 $filename_ready = $this->makeGoodPath($keep_filename);
1924
1925 if (strlen($filename_ready) > 99){ //write long header
1926 $dataFirst = pack($packF, '././LongLink', 0, 0, 0, sprintf('%11s ', DecOct(strlen($filename_ready))), 0);
1927 $dataLast = pack($packL, 'L', '', '', '', '', '', '', '', '', '');
1928
1929 // Calculate the checksum
1930 $checksum = 0;
1931 // First part of the header
1932 for ($i = 0; $i < 148; $i++)
1933 $checksum += ord(substr($dataFirst, $i, 1));
1934 // Ignore the checksum value and replace it by ' ' (space)
1935 for ($i = 148; $i < 156; $i++)
1936 $checksum += ord(' ');
1937 // Last part of the header
1938 for ($i = 156, $j=0; $i < 512; $i++, $j++)
1939 $checksum += ord(substr($dataLast, $j, 1));
1940 // Write the first 148 bytes of the header in the archive
1941 $this->writeBlock($dataFirst, 148);
1942 // Write the calculated checksum
1943 $checksum = sprintf('%6s ', DecOct($checksum));
1944 $binaryData = pack('a8', $checksum);
1945 $this->writeBlock($binaryData, 8);
1946 // Write the last 356 bytes of the header in the archive
1947 $this->writeBlock($dataLast, 356);
1948
1949 $tmp_filename = $this->makeGoodPath($filename_ready);
1950
1951 $i = 0;
1952 while (($buffer = substr($tmp_filename, (($i++)*512), 512)) != ''){
1953 $binaryData = pack('a512', $buffer);
1954 $this->writeBlock($binaryData);
1955 }
1956 return true;
1957 }
1958 $file_info = stat($filename);
1959 if (@is_dir($filename)){
1960 $typeflag = '5';
1961 $size = sprintf('%11s ', DecOct(0));
1962 } else {
1963 $typeflag = '';
1964 clearstatcache();
1965 $size = sprintf('%11s ', DecOct(filesize($filename)));
1966 }
1967 $dataFirst = pack($packF, $filename_ready, sprintf('%6s ', DecOct(fileperms($filename))), sprintf('%6s ', DecOct($file_info[4])), sprintf('%6s ', DecOct($file_info[5])), $size, sprintf('%11s', DecOct(filemtime($filename))));
1968 $dataLast = pack($packL, $typeflag, '', '', '', '', '', '', '', '', '');
1969 $checksum = 0;
1970 for ($i = 0; $i < 148; $i++) $checksum += ord(substr($dataFirst, $i, 1));
1971 for ($i = 148; $i < 156; $i++) $checksum += ord(' ');
1972 for ($i = 156, $j = 0; $i < 512; $i++, $j++) $checksum += ord(substr($dataLast, $j, 1));
1973 $this->writeBlock($dataFirst, 148);
1974 $checksum = sprintf('%6s ', DecOct($checksum));
1975 $binaryData = pack('a8', $checksum);
1976 $this->writeBlock($binaryData, 8);
1977 $this->writeBlock($dataLast, 356);
1978 return true;
1979 }
1980
1981 function openWrite(){
1982 if ($this->isGzipped)
1983 $this->tmp_file = gzopen($this->archive_name, 'wb9f');
1984 else
1985 $this->tmp_file = fopen($this->archive_name, 'wb');
1986
1987 if (!($this->tmp_file)){
1988 $this->errors[] = __('Cannot write to file').' '.$this->archive_name;
1989 return false;
1990 }
1991 return true;
1992 }
1993
1994 function readBlock(){
1995 if (is_resource($this->tmp_file)){
1996 if ($this->isGzipped)
1997 $block = gzread($this->tmp_file, 512);
1998 else
1999 $block = fread($this->tmp_file, 512);
2000 } else $block = '';
2001
2002 return $block;
2003 }
2004
2005 function writeBlock($data, $length = 0){
2006 if (is_resource($this->tmp_file)){
2007
2008 if ($length === 0){
2009 if ($this->isGzipped)
2010 gzputs($this->tmp_file, $data);
2011 else
2012 fputs($this->tmp_file, $data);
2013 } else {
2014 if ($this->isGzipped)
2015 gzputs($this->tmp_file, $data, $length);
2016 else
2017 fputs($this->tmp_file, $data, $length);
2018 }
2019 }
2020 }
2021
2022 function closeTmpFile(){
2023 if (is_resource($this->tmp_file)){
2024 if ($this->isGzipped)
2025 gzclose($this->tmp_file);
2026 else
2027 fclose($this->tmp_file);
2028
2029 $this->tmp_file = 0;
2030 }
2031 }
2032
2033 function makeGoodPath($path){
2034 if (strlen($path)>0){
2035 $path = str_replace('\\', '/', $path);
2036 $partPath = explode('/', $path);
2037 $els = count($partPath)-1;
2038 for ($i = $els; $i>=0; $i--){
2039 if ($partPath[$i] == '.'){
2040 // Ignore this directory
2041 } elseif ($partPath[$i] == '..'){
2042 $i--;
2043 }
2044 elseif (($partPath[$i] == '') and ($i!=$els) and ($i!=0)){
2045 } else
2046 $result = $partPath[$i].($i!=$els ? '/'.$result : '');
2047 }
2048 } else $result = '';
2049
2050 return $result;
2051 }
2052}
2053?>