b631cd6b333df489dfe4cd0c306194fdc828ffe9
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;
40)       return $role;
41)     }
bernd webinterface => /webinterface

bernd authored 17 years ago

42)   }
43) 
44)   // Customer?
45)   $customerno = (int) $login;
46)   $pass = sha1($password);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

47)   $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

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

bernd authored 17 years ago

50)   if (@mysql_num_rows($result) > 0)
51)   {
52)     return ROLE_CUSTOMER;
53)   }
54) 
bernd Auch mailaccounts können si...

bernd authored 16 years ago

55)   // Mail-Account
56)   $account = $login;
57)   if (! strstr($account, '@')) {
58)     $account .= '@schokokeks.org';
59)   }
60)   $result = db_query("SELECT cryptpass FROM mail.courier_mailaccounts WHERE account='{$account}' LIMIT 1;");
61)   if (@mysql_num_rows($result) > 0)
62)   {
63)     $entry = mysql_fetch_object($result);
64)     $db_password = $entry->cryptpass;
65)     $hash = crypt($password, $db_password);
66)     if ($hash == $db_password || $i_am_admin)
67)     {
68)       return ROLE_MAILACCOUNT;
69)     }
70)   }
71)   
bernd VMail-accounts können sich...

bernd authored 16 years ago

72)   // virtueller Mail-Account
73)   $account = $login;
74)   $result = db_query("SELECT cryptpass FROM mail.courier_virtual_accounts WHERE account='{$account}' LIMIT 1;");
75)   if (@mysql_num_rows($result) > 0)
76)   {
77)     $entry = mysql_fetch_object($result);
78)     $db_password = $entry->cryptpass;
79)     $hash = crypt($password, $db_password);
80)     if ($hash == $db_password || $i_am_admin)
81)     {
82)       return ROLE_VMAIL_ACCOUNT;
83)     }
84)   }
85)   
bernd Auch mailaccounts können si...

bernd authored 16 years ago

86) 
87) 
bernd webinterface => /webinterface

bernd authored 17 years ago

88)   // Nothing?
89)   return NULL;
90) }
91) 
92) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

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

bernd authored 17 years ago

94) {
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

98)   $customerno = (int) $customer;
99)   if ($customerno != 0)
100)   {
101)     DEBUG('Looking up customerinfo for customer no. '.$customerno);
102)     $result = db_query("SELECT id, anrede, firma, CONCAT_WS(' ', vorname, nachname) AS name FROM kundendaten.kunden WHERE id={$customerno} LIMIT 1;");
103)   }
104)   else
105)   {
106)     $username = mysql_real_escape_string($customer);
107)     DEBUG('looking up customer info for username '.$username);
108)     $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}'");
109)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

110)   if (@mysql_num_rows($result) == 0)
111)     system_failure("Konnte Kundendaten nicht auslesen!");
112)   $data = mysql_fetch_object($result);
113) 
114)   $ret['customerno'] = $data->id;
115)   $ret['title'] = $data->anrede;
116)   $ret['company'] = $data->firma;
117)   $ret['name'] = $data->name;
118)   
119)   return $ret;
120) }
121) 
122) 
123) function get_customer_email($customerno)
124) {
125)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

127)   if (@mysql_num_rows($result) == 0)
128)     system_failure("Konnte keine E-Mail-Adresse finden!");
129)   return mysql_fetch_object($result)->wert;
130) }
131) 
132) 
133) 
134) function get_user_info($username)
135) {
136)   $username = mysql_real_escape_string($username);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

143)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

144)   $val = @mysql_fetch_object($result);
145)   return array(
146)           'username'      => $val->username,
147)           'customerno'    => $val->customerno,
148)           'uid'           => $val->uid,
149)           'homedir'       => $val->homedir,
150)           'name'          => $val->name,
151)           );
152) }
153) 
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

154) function set_customer_verified($customerno)
155) {
156)   $customerno = (int) $customerno;
157)   db_query("UPDATE kundendaten.kunden SET status=0 WHERE id={$customerno};");
158)   logger("session/checkuser.php", "register", "set customer's status to 0.");
159) }
160) 
161) function set_customer_lastlogin($customerno)
162) {
163)   $customerno = (int) $customerno;
164)   db_query("UPDATE kundendaten.kunden SET lastlogin=NOW() WHERE id={$customerno};");
165) }
166) 
bernd webinterface => /webinterface

bernd authored 17 years ago

167) function set_customer_password($customerno, $newpass)
168) {
169)   $customerno = (int) $customerno;
170)   $newpass = sha1($newpass);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

171)   db_query("UPDATE kundendaten.kunden SET passwort='$newpass' WHERE id='".$customerno."' LIMIT 1");
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 17 years ago

173) }
174) 
175) 
176) function set_systemuser_password($uid, $newpass)
177) {
178)   $uid = (int) $uid;
179)   require_once('inc/base.php');
180)   $salt = random_string(8);
181)   $newpass = crypt($newpass, "\$1\${$salt}\$");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

182)   db_query("UPDATE system.passwoerter SET passwort='$newpass' WHERE uid='".$uid."' LIMIT 1");
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 17 years ago

184) }
185) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

186) 
187) function setup_session($role, $useridentity)
188) {
189)   session_regenerate_id();
190)   $_SESSION['role'] = $role;
191)   if ($role & ROLE_SYSTEMUSER)
192)   {
193)     DEBUG("We are system user");
194)     $info = get_user_info($useridentity);
195)     $_SESSION['userinfo'] = $info;
196)     logger("session/start.php", "login", "logged in user »{$info['username']}«");
197)     $useridentity = $info['customerno'];
198)   }
199)   if ($role & ROLE_CUSTOMER)
200)   {
201)     $info = get_customer_info($useridentity);
202)     $_SESSION['customerinfo'] = $info;
203)     set_customer_lastlogin($info['customerno']);
204)     logger("session/start.php", "login", "logged in customer no »{$info['customerno']}«");
205)   }
bernd Auch mailaccounts können si...

bernd authored 16 years ago

206)   if ($role & ROLE_MAILACCOUNT)
207)   {
208)     $id = $useridentity;
209)     if (! strstr($id, '@'))
210)       $id .= '@schokokeks.org';
211)     $_SESSION['mailaccount'] = $id;
212)     DEBUG("We are mailaccount: {$_SESSION['mailaccount']}");
213)   }
bernd VMail-accounts können sich...

bernd authored 16 years ago

214)   if ($role & ROLE_VMAIL_ACCOUNT)
215)   {
216)     $id = $useridentity;
217)     $_SESSION['mailaccount'] = $id;
218)     DEBUG("We are virtual mailaccount: {$_SESSION['mailaccount']}");
219)   }
bernd Auch mailaccounts können si...

bernd authored 16 years ago

220) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

221) }
222)