ce0caaf4a67def494ea8ed9153053f062bb26ff2
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 webinterface => /webinterface

bernd authored 17 years ago

11) define('ROLE_SYSTEMUSER', 2);
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

12) define('ROLE_CUSTOMER', 4);
13) define('ROLE_SYSADMIN', 8);
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

32)     if ($hash == $db_password || $i_am_admin)
33)     {
34)       $role = ROLE_SYSTEMUSER;
35)       if ($entry->primary)
36)         $role = $role | ROLE_CUSTOMER;
37)       if ($entry->admin)
38)         $role = $role | ROLE_SYSADMIN;
39)       return $role;
40)     }
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

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

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

73)   // Nothing?
74)   return NULL;
75) }
76) 
77) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

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

bernd authored 17 years ago

79) {
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

83)   $customerno = (int) $customer;
84)   if ($customerno != 0)
85)   {
86)     DEBUG('Looking up customerinfo for customer no. '.$customerno);
87)     $result = db_query("SELECT id, anrede, firma, CONCAT_WS(' ', vorname, nachname) AS name FROM kundendaten.kunden WHERE id={$customerno} LIMIT 1;");
88)   }
89)   else
90)   {
91)     $username = mysql_real_escape_string($customer);
92)     DEBUG('looking up customer info for username '.$username);
93)     $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}'");
94)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

95)   if (@mysql_num_rows($result) == 0)
96)     system_failure("Konnte Kundendaten nicht auslesen!");
97)   $data = mysql_fetch_object($result);
98) 
99)   $ret['customerno'] = $data->id;
100)   $ret['title'] = $data->anrede;
101)   $ret['company'] = $data->firma;
102)   $ret['name'] = $data->name;
103)   
104)   return $ret;
105) }
106) 
107) 
108) function get_customer_email($customerno)
109) {
110)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

112)   if (@mysql_num_rows($result) == 0)
113)     system_failure("Konnte keine E-Mail-Adresse finden!");
114)   return mysql_fetch_object($result)->wert;
115) }
116) 
117) 
118) 
119) function get_user_info($username)
120) {
121)   $username = mysql_real_escape_string($username);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

128)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

129)   $val = @mysql_fetch_object($result);
130)   return array(
131)           'username'      => $val->username,
132)           'customerno'    => $val->customerno,
133)           'uid'           => $val->uid,
134)           'homedir'       => $val->homedir,
135)           'name'          => $val->name,
136)           );
137) }
138) 
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

139) function set_customer_verified($customerno)
140) {
141)   $customerno = (int) $customerno;
142)   db_query("UPDATE kundendaten.kunden SET status=0 WHERE id={$customerno};");
143)   logger("session/checkuser.php", "register", "set customer's status to 0.");
144) }
145) 
146) function set_customer_lastlogin($customerno)
147) {
148)   $customerno = (int) $customerno;
149)   db_query("UPDATE kundendaten.kunden SET lastlogin=NOW() WHERE id={$customerno};");
150) }
151) 
bernd webinterface => /webinterface

bernd authored 17 years ago

152) function set_customer_password($customerno, $newpass)
153) {
154)   $customerno = (int) $customerno;
155)   $newpass = sha1($newpass);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

158) }
159) 
160) 
161) function set_systemuser_password($uid, $newpass)
162) {
163)   $uid = (int) $uid;
164)   require_once('inc/base.php');
165)   $salt = random_string(8);
166)   $newpass = crypt($newpass, "\$1\${$salt}\$");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

169) }
170) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

171) 
172) function setup_session($role, $useridentity)
173) {
174)   session_regenerate_id();
175)   $_SESSION['role'] = $role;
176)   if ($role & ROLE_SYSTEMUSER)
177)   {
178)     DEBUG("We are system user");
179)     $info = get_user_info($useridentity);
180)     $_SESSION['userinfo'] = $info;
181)     logger("session/start.php", "login", "logged in user »{$info['username']}«");
182)     $useridentity = $info['customerno'];
183)   }
184)   if ($role & ROLE_CUSTOMER)
185)   {
186)     $info = get_customer_info($useridentity);
187)     $_SESSION['customerinfo'] = $info;
188)     set_customer_lastlogin($info['customerno']);
189)     logger("session/start.php", "login", "logged in customer no »{$info['customerno']}«");
190)   }
bernd Auch mailaccounts können si...

bernd authored 16 years ago

191)   if ($role & ROLE_MAILACCOUNT)
192)   {
193)     $id = $useridentity;
194)     if (! strstr($id, '@'))
195)       $id .= '@schokokeks.org';
196)     $_SESSION['mailaccount'] = $id;
197)     DEBUG("We are mailaccount: {$_SESSION['mailaccount']}");
198)   }
199) 
bernd * Initialisierung der Sessi...

bernd authored 16 years ago

200) }
201)