3477e99fff354a892f45fa511aaa20dc50d804ea
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);
10) define('ROLE_DOMAINADMIN', 1);
11) define('ROLE_SYSTEMUSER', 2);
12) define('ROLE_CUSTOMER', 3);
13) define('ROLE_SYSADMIN', 4);
14) 
15) 
16) // Gibt die Rolle aus, wenn das Passwort stimmt
17) 
18) function find_role($login, $password)
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 sql-abfragen abstrahiert

bernd authored 16 years ago

26)   $result = db_query("SELECT passwort AS password FROM system.v_useraccounts LEFT JOIN system.passwoerter USING (uid) WHERE uid={$uid} OR username='{$login}' LIMIT 1;");
bernd webinterface => /webinterface

bernd authored 17 years ago

27)   if (@mysql_num_rows($result) > 0)
28)   {
29)     $db_password = mysql_fetch_object($result)->password;
30)     $hash = crypt($password, $db_password);
31)     if ($hash == $db_password)
32)       return ROLE_SYSTEMUSER;
33)   }
34) 
35)   // Customer?
36)   $customerno = (int) $login;
37)   $pass = sha1($password);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

39)   if (@mysql_num_rows($result) > 0)
40)   {
41)     return ROLE_CUSTOMER;
42)   }
43) 
44)   // Nothing?
45)   return NULL;
46) }
47) 
48) 
49) function get_customer_info($customerno)
50) {
51)   $ret = array();
52)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

53)   $result = db_query("SELECT id, anrede, firma, CONCAT_WS(' ', vorname, nachname) AS name FROM kundendaten.kunden WHERE id={$customerno} LIMIT 1;");
bernd webinterface => /webinterface

bernd authored 17 years ago

54)   if (@mysql_num_rows($result) == 0)
55)     system_failure("Konnte Kundendaten nicht auslesen!");
56)   $data = mysql_fetch_object($result);
57) 
58)   $ret['customerno'] = $data->id;
59)   $ret['title'] = $data->anrede;
60)   $ret['company'] = $data->firma;
61)   $ret['name'] = $data->name;
62)   
63)   return $ret;
64) }
65) 
66) 
67) function get_customer_email($customerno)
68) {
69)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

71)   if (@mysql_num_rows($result) == 0)
72)     system_failure("Konnte keine E-Mail-Adresse finden!");
73)   return mysql_fetch_object($result)->wert;
74) }
75) 
76) 
77) 
78) function get_user_info($username)
79) {
80)   $username = mysql_real_escape_string($username);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

87)   }
bernd webinterface => /webinterface

bernd authored 17 years ago

88)   $val = @mysql_fetch_object($result);
89)   return array(
90)           'username'      => $val->username,
91)           'customerno'    => $val->customerno,
92)           'uid'           => $val->uid,
93)           'homedir'       => $val->homedir,
94)           'name'          => $val->name,
95)           );
96) }
97) 
bernd Kunden-Status wird benutzt...

bernd authored 16 years ago

98) function set_customer_verified($customerno)
99) {
100)   $customerno = (int) $customerno;
101)   db_query("UPDATE kundendaten.kunden SET status=0 WHERE id={$customerno};");
102)   logger("session/checkuser.php", "register", "set customer's status to 0.");
103) }
104) 
105) function set_customer_lastlogin($customerno)
106) {
107)   $customerno = (int) $customerno;
108)   db_query("UPDATE kundendaten.kunden SET lastlogin=NOW() WHERE id={$customerno};");
109) }
110) 
bernd webinterface => /webinterface

bernd authored 17 years ago

111) function set_customer_password($customerno, $newpass)
112) {
113)   $customerno = (int) $customerno;
114)   $newpass = sha1($newpass);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

117) }
118) 
119) 
120) function set_systemuser_password($uid, $newpass)
121) {
122)   $uid = (int) $uid;
123)   require_once('inc/base.php');
124)   $salt = random_string(8);
125)   $newpass = crypt($newpass, "\$1\${$salt}\$");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

127)   logger("session/checkuser.php", "pwchange", "changed user's password.");