X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/2dc4984ad57dfcb0ded829bfc9d45493484fe6e3..9d77c0fe903db4f4ab2e3c6b5d5fc956f58c227d:/admin.php diff --git a/admin.php b/admin.php index 4500a19..a42b20f 100644 --- a/admin.php +++ b/admin.php @@ -1,7 +1,7 @@ + * Copyright (C) 2015 Jerome Jutteau * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -53,72 +53,58 @@ if (php_sapi_name() == "cli") { } /* Unlog if asked. */ - if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) { - $_SESSION['admin_auth'] = false; + if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) { + jirafeau_admin_session_end(); } - /* Check classic admin password authentification. */ - if (isset($_POST['admin_password']) && empty($cfg['admin_http_auth_user'])) { - if ($cfg['admin_password'] === $_POST['admin_password'] || - $cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) { - $_SESSION['admin_auth'] = true; - } else { - $_SESSION['admin_auth'] = false; - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

'. - t('BAD_PSW') . '

'; + if (!jirafeau_admin_session_logged()) { + /* Test HTTP authentification. */ + if (!empty($cfg['admin_http_auth_user']) && + $cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) { + jirafeau_admin_session_start(); + } + /* Test web password authentification. */ + else if (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) { + if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) { + jirafeau_admin_session_start(); + } else { + require(JIRAFEAU_ROOT . 'lib/template/header.php'); + echo '

'. t('BAD_PSW') . '

'; + require(JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } + } + /* Admin password prompt form. */ + else { + require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?> +
+
+ + + + + + + + + + +
+
+
+
+
+ -
-
- - - - - - - - - -
- -
-
-
-

'. - t('NO_ADMIN_AUTH') . - '

'; - require(JIRAFEAU_ROOT.'lib/template/footer.php'); - exit; - } /* Operations may take a long time. * Be sure PHP's safe mode is off. @@ -138,6 +124,7 @@ if (php_sapi_name() == "cli") {
+ @@ -150,6 +137,7 @@ if (php_sapi_name() == "cli") { + @@ -162,6 +150,7 @@ if (php_sapi_name() == "cli") { + @@ -171,9 +160,23 @@ if (php_sapi_name() == "cli") {
+
+ + + + + + + + + + + +
+ @@ -188,6 +191,7 @@ if (php_sapi_name() == "cli") { + @@ -202,8 +206,9 @@ if (php_sapi_name() == "cli") { + - + @@ -216,10 +221,10 @@ if (php_sapi_name() == "cli") { +
'; echo t('CLEANED_FILES_CNT') . ' : ' . $total; echo '

'; + } elseif (strcmp($_POST['action'], 'size') == 0) { + $size = jirafeau_dir_size($cfg['var_root']); + $human_size = jirafeau_human_size($size); + echo '
' . NL; + echo '

' . t('SIZE_DATA') . ': ' . $human_size .'

'; + echo '
'; } elseif (strcmp($_POST['action'], 'list') == 0) { jirafeau_admin_list("", "", ""); } elseif (strcmp($_POST['action'], 'search_by_name') == 0) { @@ -249,7 +260,7 @@ if (php_sapi_name() == "cli") { echo '
' . NL; echo '

' . t('LINK_DELETED') . '

'; } elseif (strcmp($_POST['action'], 'delete_file') == 0) { - $count = jirafeau_delete_file($_POST['md5']); + $count = jirafeau_delete_file($_POST['hash']); echo '
' . NL; echo '

' . t('DELETED_LINKS') . ' : ' . $count . '

'; } elseif (strcmp($_POST['action'], 'download') == 0) { @@ -257,13 +268,18 @@ if (php_sapi_name() == "cli") { if (!count($l)) { return; } - $p = s2p($l['md5']); + $p = s2p($l['hash']); header('Content-Length: ' . $l['file_size']); header('Content-Type: ' . $l['mime_type']); header('Content-Disposition: attachment; filename="' . $l['file_name'] . '"'); - if (file_exists(VAR_FILES . $p . $l['md5'])) { - readfile(VAR_FILES . $p . $l['md5']); + if (file_exists(VAR_FILES . $p . $l['hash'])) { + $r = fopen(VAR_FILES . $p . $l['hash'], 'r'); + while (!feof($r)) { + print fread($r, 1024); + ob_flush(); + } + fclose($r); } exit; }