login: replace page editability var by admin status
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 11 Jul 2017 15:30:57 +0000 (17:30 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 12 Jul 2017 02:46:06 +0000 (04:46 +0200)
Code cleanup, same results.

auth.inc.php
edit.php
foot.inc.php
login.php

index 6a5d1d2d83458fc1f84f56dd96093c1cb36c0c5b..ecd29b5cc36ca971c9183f9a11ddd31d180d9f24 100755 (executable)
@@ -1,8 +1,7 @@
 <?php
-global $User, $editable;
-$User = FALSE;
+global $User, $Admin;
 
-function Auth() {
+call_user_func(function () {
        if (isset($_SERVER['PHP_AUTH_USER'])) {
                $authinfo = [ $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ];
        }
@@ -29,10 +28,8 @@ function Auth() {
        $salt = substr($usertest, 0, 2);
        if (crypt($authpass, $salt) != $usertest) return;
 
-       $GLOBALS['User'] = $authname;
-}
-
-Auth();
-
-$editable = !empty($User) && $User != 'lid';
+       global $User, $Admin;
+       $User = $authname;
+       $Admin = !empty($User) && $User != 'lid' ? $User : FALSE;
+});
 
index 9532e423e202291aa469397567f4a3246b90cc05..3774bfc51407bf441ed055b8ffcbd7342a129887 100755 (executable)
--- a/edit.php
+++ b/edit.php
@@ -6,7 +6,7 @@ function abort($status, $body) {
 }
 
 require 'auth.inc.php';
-if (!$editable)
+if (!$Admin)
        abort('401 unauthorised', "geen beheersrechten");
 
 if (!$_POST)
index e1ea486747d37aee7372df16f418fe2c4a4e1f55..e61346a1fab0b7e815bb94bbf1221a10ce748b1d 100755 (executable)
@@ -3,15 +3,15 @@
 <?php
 define('N', "\n");
 
-global $User, $editable;
+global $User, $Admin;
 
 $curfile = ltrim($_SERVER['SCRIPT_NAME'], '/');
 if (is_executable(__DIR__ . '/' . $curfile)) {
        // dynamic code is +x
-       $editable = FALSE;
+       $Admin = FALSE;
 }
 
-if ($editable) {
+if ($Admin) {
        $edit = preg_match('/[?]edit$/', $_SERVER['REQUEST_URI']);
 
        if ($edit) {
index c83534cbd2d6946f1be7cc44c829e840a5f3c5b5..eb09f8a571dbb80e765d0f11ae9df9554549b488 100644 (file)
--- a/login.php
+++ b/login.php
@@ -1,7 +1,7 @@
 <?php
 require 'auth.inc.php';
 
-if (!$editable) {
+if (!$Admin) {
        require 'logout.php';
        exit;
 }