<?php
-$ALLOWED = [
- '127.0.0.1',
- '192.168.178.0/24',
- '94.208.83.16', # arie.ziggo
- '83.161.198.138', # shiar.demon
- '145.131.141.219', # shiar@1m
-];
-
-$editable = in_array($_SERVER['REMOTE_ADDR'], $ALLOWED) ?
- $_SERVER['REMOTE_ADDR'] : FALSE;
+function login($inuser, $inpass = NULL)
+{
+ if (empty($inuser)) return;
+ if (!isset($inpass)) {
+ @list ($inuser, $inauth) = explode(':', $inuser, 2);
+ }
+
+ # find password data by user name
+ $userdir = 'login/'.strtolower($inuser);
+ $pwfile = "$userdir/.passwd";
+ if (!file_exists($pwfile)) return;
+ $usertest = trim(file_get_contents($pwfile));
+ if (!$usertest) return;
+
+ # verify password
+ $authhash = md5($usertest);
+ if (isset($inpass)) {
+ if (!password_verify($inpass, $usertest)) return;
+ }
+ else {
+ if ($inauth !== $authhash) return;
+ }
+
+ if (function_exists('apache_note')) apache_note('user', $inuser);
+
+ return [
+ 'name' => $inuser,
+ 'admin' => file_exists("$userdir/.admin"),
+ 'auth' => "$inuser:$authhash",
+ ];
+}
+
+if (isset($_COOKIE['login'])) {
+ global $User;
+ $User = login($_COOKIE['login']);
+}