2 date_default_timezone_set('Europe/Amsterdam');
8 function __construct($dir = NULL, $existing = TRUE)
13 if (!file_exists($dir) and $existing) {
14 throw new Exception("Gebruiker niet gevonden in $dir");
17 $this->login = basename($dir);
22 return $this->$col = $this->$col(); # run method and cache
27 return rtrim(@file_get_contents("{$this->dir}/name.txt"));
32 return htmlspecialchars(implode(' & ', explode("\n", $this->rawname)));
37 $name = htmlspecialchars($this->login);
38 if ($this->name and $this->name != $name) {
39 $name = "{$this->name}<small> @$name</small>";
46 return rtrim(@file_get_contents("{$this->dir}/email.txt"));
49 function admin($permission = NULL)
51 if (isset($permission)) {
53 return FALSE; # empty results
55 preg_match_all('{[ /]}', $permission, $parts, PREG_OFFSET_CAPTURE);
56 foreach ($parts[0] as $part) {
57 if (isset($this->admin[substr($permission, 0, $part[1])])) {
58 return TRUE; # partial match
61 return isset($this->admin[$permission]); # check level
63 if (!$this->dir or !@file_exists("{$this->dir}/.admin")) {
64 return FALSE; # not an admin
66 return array_fill_keys(explode("\n", file_get_contents("{$this->dir}/.admin")), TRUE);
71 return @filemtime("{$this->dir}/last.log");
76 if ($log = @fopen("{$this->dir}/last.log", 'w')) {
77 $line = $_SERVER['REMOTE_ADDR'].' '.$_SERVER['HTTP_USER_AGENT'];
78 fwrite($log, $line."\n");
83 function login_password_verify($input, $test)
85 if (substr($test, 0, 1) != '$') {
86 # plaintext match for uncrypted passwords
87 return $input === $test;
89 return password_verify($input, $test);
92 function login_setcookie()
95 return setcookie('login', $User->auth, 0, '/');
98 function login($inuser, $inpass = NULL)
100 if (empty($inuser)) return;
101 if (!isset($inpass)) {
102 @list ($inuser, $inauth) = explode(':', $inuser, 2);
105 # find password data by user name
106 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
107 $pwfile = "$userdir/.passwd";
108 if (!file_exists($pwfile)) return;
109 $usertest = trim(file_get_contents($pwfile));
110 if (!$usertest) return;
113 $authhash = md5($usertest);
114 if (isset($inpass)) {
115 if (!login_password_verify($inpass, $usertest)) return;
118 if ($inauth !== $authhash) return;
121 if (function_exists('apache_note')) apache_note('user', $inuser);
123 $user = new User($userdir);
125 $user->pass = $usertest;
126 $user->auth = "$inuser:$authhash";
131 if (isset($_COOKIE['login'])) {
132 $User = login($_COOKIE['login']);