5b160d086d6d87aefab9a3daec981de08c4bdba8
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
2) 
bernd Logging aktiviert

bernd authored 16 years ago

3) require_once('inc/base.php');
bernd webinterface => /webinterface

bernd authored 17 years ago

4) require_once('inc/debug.php');
5) require_once('inc/error.php');
6) 
7) require_once('inc/db_connect.php');
8) 
9) define('ROLE_ANONYMOUS', 0);
bernd Auch mailaccounts können si...

bernd authored 16 years ago

10) define('ROLE_MAILACCOUNT', 1);
bernd VMail-accounts können sich...

bernd authored 16 years ago

11) define('ROLE_VMAIL_ACCOUNT', 2);
12) define('ROLE_SYSTEMUSER', 4);
13) define('ROLE_CUSTOMER', 8);
14) define('ROLE_SYSADMIN', 16);
bernd webinterface => /webinterface

bernd authored 17 years ago

15) 
16) 
17) // Gibt die Rolle aus, wenn das Passwort stimmt
18) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

19) function find_role($login, $password, $i_am_admin = False)
bernd webinterface => /webinterface

bernd authored 17 years ago

20) {
21)   $login = mysql_real_escape_string($login);
22)   // Domain-Admin?  <not implemented>
23)   // System-User?
24)   $uid = (int) $login;
25)   if ($uid == 0)
26)     $uid = 'NULL';
bernd nicht mehr der user mit der...

bernd authored 16 years ago

27)   $result = db_query("SELECT passwort AS password, kundenaccount AS `primary`, ((SELECT acc.uid FROM system.v_useraccounts AS acc LEFT JOIN system.gruppenzugehoerigkeit USING (uid) LEFT JOIN system.gruppen AS g ON (g.gid=gruppenzugehoerigkeit.gid) WHERE g.name='admin' AND acc.uid=u.uid) IS NOT NULL) AS admin FROM system.v_useraccounts AS u LEFT JOIN system.passwoerter USING(uid) WHERE u.uid={$uid} OR username='{$login}' LIMIT 1;");
bernd webinterface => /webinterface

bernd authored 17 years ago

28)   if (@mysql_num_rows($result) > 0)
29)   {
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

30)     $entry = mysql_fetch_object($result);
31)     $db_password = $entry->password;
bernd webinterface => /webinterface

bernd authored 17 years ago

32)     $hash = crypt($password, $db_password);
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

33)     if ($hash == $db_password || $i_am_admin)
34)     {
35)       $role = ROLE_SYSTEMUSER;
36)       if ($entry->primary)
37)         $role = $role | ROLE_CUSTOMER;
38)       if ($entry->admin)
39)         $role = $role | ROLE_SYSADMIN;
bernd eliminate .php extensions f...

bernd authored 15 years ago

40)       logger("session/checkuser", "login", "logged in systemuser »{$login}«.");
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

41)       return $role;
42)     }
bernd eliminate .php extensions f...

bernd authored 15 years ago

43)     logger("session/checkuser", "login", "wrong password for existing useraccount »{$login}«.");
bernd Mehr logging

bernd authored 15 years ago

44)   } else {
bernd eliminate .php extensions f...

bernd authored 15 years ago

45)     logger("session/checkuser", "login", "did not find useraccount »{$login}«. trying other roles...");
bernd webinterface => /webinterface

bernd authored 17 years ago

46)   }
47) 
48)   // Customer?
49)   $customerno = (int) $login;
50)   $pass = sha1($password);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

51)   $result = db_query("SELECT passwort AS password FROM kundendaten.kunden WHERE status=0 AND id={$customerno} AND passwort='{$pass}';");
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

52)   if ($i_am_admin)
53)     $result = db_query("SELECT passwort AS password FROM kundendaten.kunden WHERE status=0 AND id={$customerno}");
bernd webinterface => /webinterface

bernd authored 17 years ago

54)   if (@mysql_num_rows($result) > 0)
55)   {
56)     return ROLE_CUSTOMER;
57)   }
58) 
bernd Auch mailaccounts können si...

bernd authored 16 years ago

59)   // Mail-Account
60)   $account = $login;
61)   if (! strstr($account, '@')) {
62)     $account .= '@schokokeks.org';
63)   }
64)   $result = db_query("SELECT cryptpass FROM mail.courier_mailaccounts WHERE account='{$account}' LIMIT 1;");
65)   if (@mysql_num_rows($result) > 0)
66)   {
67)     $entry = mysql_fetch_object($result);
68)     $db_password = $entry->cryptpass;
69)     $hash = crypt($password, $db_password);
70)     if ($hash == $db_password || $i_am_admin)
71)     {
bernd eliminate .php extensions f...

bernd authored 15 years ago

72)       logger("session/checkuser", "login", "logged in e-mail-account »{$account}«.");
bernd Auch mailaccounts können si...

bernd authored 16 years ago

73)       return ROLE_MAILACCOUNT;
74)     }
bernd eliminate .php extensions f...

bernd authored 15 years ago

75)     logger("session/checkuser", "login", "wrong password for existing e-mail-account »{$account}«.");
bernd Auch mailaccounts können si...

bernd authored 16 years ago

76)   }
77)   
bernd VMail-accounts können sich...

bernd authored 16 years ago

78)   // virtueller Mail-Account
79)   $account = $login;
80)   $result = db_query("SELECT cryptpass FROM mail.courier_virtual_accounts WHERE account='{$account}' LIMIT 1;");
81)   if (@mysql_num_rows($result) > 0)
82)   {
83)     $entry = mysql_fetch_object($result);
84)     $db_password = $entry->cryptpass;
85)     $hash = crypt($password, $db_password);
86)     if ($hash == $db_password || $i_am_admin)
87)     {
bernd eliminate .php extensions f...

bernd authored 15 years ago

88)       logger("session/checkuser", "login", "logged in virtual e-mail-account »{$account}«.");
bernd VMail-accounts können sich...

bernd authored 16 years ago

89)       return ROLE_VMAIL_ACCOUNT;
90)     }
bernd eliminate .php extensions f...

bernd authored 15 years ago

91)     logger("session/checkuser", "login", "wrong password for existing virtual e-mail-account »{$account}«.");
bernd VMail-accounts können sich...

bernd authored 16 years ago

92)   }
93)   
bernd Auch mailaccounts können si...

bernd authored 16 years ago

94) 
95) 
bernd webinterface => /webinterface

bernd authored 17 years ago

96)   // Nothing?
97)   return NULL;
98) }
99) 
100) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

101) function get_customer_info($customer)
bernd webinterface => /webinterface

bernd authored 17 years ago

102) {
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

103)   if (! $_SESSION['role'] & ROLE_CUSTOMER)
104)     return array();
bernd webinterface => /webinterface

bernd authored 17 years ago

105)   $ret = array();
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

106)   $customerno = (int) $customer;
107)   if ($customerno != 0)
108)   {
109)     DEBUG('Looking up customerinfo for customer no. '.$customerno);
110)     $result = db_query("SELECT id, anrede, firma, CONCAT_WS(' ', vorname, nachname) AS name FROM kundendaten.kunden WHERE id={$customerno} LIMIT 1;");
111)   }
112)   else
113)   {
114)     $username = mysql_real_escape_string($customer);
115)     DEBUG('looking up customer info for username '.$username);
116)     $result = db_query("SELECT id, anrede, firma, CONCAT_WS(' ', vorname, nachname) AS name FROM kundendaten.kunden AS k JOIN system.v_useraccounts AS u ON (u.kunde=k.id) WHERE u.username='{$username}'");
117)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

118)   if (@mysql_num_rows($result) == 0)
119)     system_failure("Konnte Kundendaten nicht auslesen!");
120)   $data = mysql_fetch_object($result);
121) 
122)   $ret['customerno'] = $data->id;
123)   $ret['title'] = $data->anrede;
124)   $ret['company'] = $data->firma;
125)   $ret['name'] = $data->name;
126)   
127)   return $ret;
128) }
129) 
130) 
131) function get_customer_email($customerno)
132) {
133)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

134)   $result = db_query("SELECT wert FROM kundendaten.kundenkontakt WHERE kundennr={$customerno} AND typ='email' LIMIT 1;");
bernd webinterface => /webinterface

bernd authored 17 years ago

135)   if (@mysql_num_rows($result) == 0)
136)     system_failure("Konnte keine E-Mail-Adresse finden!");
137)   return mysql_fetch_object($result)->wert;
138) }
139) 
140) 
141) 
142) function get_user_info($username)
143) {
144)   $username = mysql_real_escape_string($username);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

145)   $result = db_query("SELECT kunde AS customerno, username, uid, homedir, name
146)                       FROM system.v_useraccounts WHERE username='{$username}' OR uid='{$username}' LIMIT 1");
bernd webinterface => /webinterface

bernd authored 17 years ago

147)   if (mysql_num_rows($result) < 1)
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

148)   {
bernd eliminate .php extensions f...

bernd authored 15 years ago

149)     logger("session/checkuser", "login", "error reading user's data: »{$username}«");
bernd webinterface => /webinterface

bernd authored 17 years ago

150)     system_failure('Das Auslesen Ihrer Benutzerdaten ist fehlgeschlagen. Bitte melden Sie dies einem Administrator');
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

151)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

152)   $val = @mysql_fetch_object($result);
153)   return array(
154)           'username'      => $val->username,
155)           'customerno'    => $val->customerno,
156)           'uid'           => $val->uid,
157)           'homedir'       => $val->homedir,
158)           'name'          => $val->name,
159)           );
160) }
161) 
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

162) function set_customer_verified($customerno)
163) {
164)   $customerno = (int) $customerno;
165)   db_query("UPDATE kundendaten.kunden SET status=0 WHERE id={$customerno};");
bernd eliminate .php extensions f...

bernd authored 15 years ago

166)   logger("session/checkuser", "register", "set customer's status to 0.");
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

167) }
168) 
169) function set_customer_lastlogin($customerno)
170) {
171)   $customerno = (int) $customerno;
172)   db_query("UPDATE kundendaten.kunden SET lastlogin=NOW() WHERE id={$customerno};");
173) }
174) 
bernd webinterface => /webinterface

bernd authored 17 years ago

175) function set_customer_password($customerno, $newpass)
176) {
177)   $customerno = (int) $customerno;
178)   $newpass = sha1($newpass);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

179)   db_query("UPDATE kundendaten.kunden SET passwort='$newpass' WHERE id='".$customerno."' LIMIT 1");
bernd eliminate .php extensions f...

bernd authored 15 years ago

180)   logger("session/checkuser", "pwchange", "changed customer's password.");
bernd webinterface => /webinterface

bernd authored 17 years ago

181) }
182) 
183) 
184) function set_systemuser_password($uid, $newpass)
185) {
186)   $uid = (int) $uid;
187)   require_once('inc/base.php');
188)   $salt = random_string(8);
189)   $newpass = crypt($newpass, "\$1\${$salt}\$");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

190)   db_query("UPDATE system.passwoerter SET passwort='$newpass' WHERE uid='".$uid."' LIMIT 1");
bernd eliminate .php extensions f...

bernd authored 15 years ago

191)   logger("session/checkuser", "pwchange", "changed user's password.");
bernd webinterface => /webinterface

bernd authored 17 years ago

192) }
193) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

194) 
195) function setup_session($role, $useridentity)
196) {
197)   session_regenerate_id();
198)   $_SESSION['role'] = $role;
199)   if ($role & ROLE_SYSTEMUSER)
200)   {
201)     DEBUG("We are system user");
202)     $info = get_user_info($useridentity);
203)     $_SESSION['userinfo'] = $info;
bernd eliminate .php extensions f...

bernd authored 15 years ago

204)     logger("session/start", "login", "logged in user »{$info['username']}«");
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

205)     $useridentity = $info['customerno'];
206)   }
207)   if ($role & ROLE_CUSTOMER)
208)   {
209)     $info = get_customer_info($useridentity);
210)     $_SESSION['customerinfo'] = $info;
211)     set_customer_lastlogin($info['customerno']);
bernd eliminate .php extensions f...

bernd authored 15 years ago

212)     logger("session/start", "login", "logged in customer no »{$info['customerno']}«");
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

213)   }
bernd Auch mailaccounts können si...

bernd authored 16 years ago

214)   if ($role & ROLE_MAILACCOUNT)
215)   {
216)     $id = $useridentity;
217)     if (! strstr($id, '@'))
218)       $id .= '@schokokeks.org';
219)     $_SESSION['mailaccount'] = $id;
220)     DEBUG("We are mailaccount: {$_SESSION['mailaccount']}");
221)   }
bernd VMail-accounts können sich...

bernd authored 16 years ago

222)   if ($role & ROLE_VMAIL_ACCOUNT)
223)   {
224)     $id = $useridentity;
225)     $_SESSION['mailaccount'] = $id;
226)     DEBUG("We are virtual mailaccount: {$_SESSION['mailaccount']}");
227)   }
bernd Auch mailaccounts können si...

bernd authored 16 years ago

228) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

229) }
230)