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 $name = htmlspecialchars($this->login);
33 if ($this->name and $this->name != $name) {
34 $name = "{$this->name}<small> @$name</small>";
41 return rtrim(@file_get_contents("{$this->dir}/email.txt"));
44 function admin($permission = NULL)
46 if (isset($permission)) {
48 return FALSE; # empty results
50 preg_match_all('{[ /]}', $permission, $parts, PREG_OFFSET_CAPTURE);
51 foreach ($parts[0] as $part) {
52 if (isset($this->admin[substr($permission, 0, $part[1])])) {
53 return TRUE; # partial match
56 return isset($this->admin[$permission]); # check level
58 if (!@file_exists("{$this->dir}/.admin")) {
59 return FALSE; # not an admin
61 return array_fill_keys(explode("\n", file_get_contents("{$this->dir}/.admin")), TRUE);
66 return @filemtime("{$this->dir}/last.log");
71 if ($log = @fopen("{$this->dir}/last.log", 'w')) {
72 $line = $_SERVER['REMOTE_ADDR'].' '.$_SERVER['HTTP_USER_AGENT'];
73 fwrite($log, $line."\n");
78 function login_password_verify($input, $test)
80 if (substr($test, 0, 1) != '$') {
81 # plaintext match for uncrypted passwords
82 return $input === $test;
84 return password_verify($input, $test);
87 function login_setcookie()
90 return setcookie('login', $User->auth, 0, '/');
93 function login($inuser, $inpass = NULL)
95 if (empty($inuser)) return;
96 if (!isset($inpass)) {
97 @list ($inuser, $inauth) = explode(':', $inuser, 2);
100 # find password data by user name
101 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
102 $pwfile = "$userdir/.passwd";
103 if (!file_exists($pwfile)) return;
104 $usertest = trim(file_get_contents($pwfile));
105 if (!$usertest) return;
108 $authhash = md5($usertest);
109 if (isset($inpass)) {
110 if (!login_password_verify($inpass, $usertest)) return;
113 if ($inauth !== $authhash) return;
116 if (function_exists('apache_note')) apache_note('user', $inuser);
118 $user = new User($userdir);
120 $user->pass = $usertest;
121 $user->auth = "$inuser:$authhash";
125 if (isset($_COOKIE['login'])) {
127 $User = login($_COOKIE['login']);