2 date_default_timezone_set('Europe/Amsterdam');
6 function __construct($dir, $existing = TRUE)
8 if (!file_exists($dir) and $existing) {
9 throw new Exception("Gebruiker niet gevonden in $dir");
12 $this->login = basename($dir);
17 return $this->$col = $this->$col(); # run method and cache
22 return rtrim(@file_get_contents("{$this->dir}/name.txt"));
27 return htmlspecialchars(implode(' & ', explode("\n", $this->rawname)));
32 return $this->name ?: $this->login;
37 return rtrim(@file_get_contents("{$this->dir}/email.txt"));
40 function admin($permission = NULL)
42 if (isset($permission)) {
44 return FALSE; # empty results
46 @list ($rootlevel, $sublevel) = explode(' ', $permission);
47 if ($sublevel and isset($this->admin[$rootlevel])) {
48 return TRUE; # root match
50 return isset($this->admin[$permission]); # check level
52 if (!@file_exists("{$this->dir}/.admin")) {
53 return FALSE; # not an admin
55 return array_fill_keys(explode("\n", file_get_contents("{$this->dir}/.admin")), TRUE);
60 return @filemtime("{$this->dir}/last.log");
65 if ($log = @fopen("{$this->dir}/last.log", 'w')) {
66 $line = $_SERVER['REMOTE_ADDR'].' '.$_SERVER['HTTP_USER_AGENT'];
67 fwrite($log, $line."\n");
72 function login_password_verify($input, $test)
74 if (substr($test, 0, 1) != '$') {
75 # plaintext match for uncrypted passwords
76 return $input === $test;
78 return password_verify($input, $test);
81 function login_setcookie()
84 return setcookie('login', $User->auth, 0, '/');
87 function login($inuser, $inpass = NULL)
89 if (empty($inuser)) return;
90 if (!isset($inpass)) {
91 @list ($inuser, $inauth) = explode(':', $inuser, 2);
94 # find password data by user name
95 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
96 $pwfile = "$userdir/.passwd";
97 if (!file_exists($pwfile)) return;
98 $usertest = trim(file_get_contents($pwfile));
99 if (!$usertest) return;
102 $authhash = md5($usertest);
103 if (isset($inpass)) {
104 if (!login_password_verify($inpass, $usertest)) return;
107 if ($inauth !== $authhash) return;
110 if (function_exists('apache_note')) apache_note('user', $inuser);
112 $user = new User($userdir);
114 $user->pass = $usertest;
115 $user->auth = "$inuser:$authhash";
119 if (isset($_COOKIE['login'])) {
121 $User = login($_COOKIE['login']);