bd22f03937341179a1beaf87aafcde8e61882589
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
16) 
Bernd Wurst changed subusers module to...

Bernd Wurst authored 12 years ago

17) require_role(ROLE_SYSTEMUSER);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

18) require_once("inc/base.php");
19) require_once("inc/security.php");
20) require_once("inc/debug.php");
21) 
22) 
23) function list_subusers()
24) {
25)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

26)   $result = db_query("SELECT id, username, modules FROM system.subusers WHERE uid={$uid}");
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

27)   $subusers = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

28)   while ($item = mysql_fetch_assoc($result))
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

29)   {
30)     $item['modules'] = explode(',', $item['modules']);
31)     $subusers[] = $item;
32)   }
33)   DEBUG($subusers);
34)   return $subusers;
35) }
36) 
37) 
38) function load_subuser($id) {
39)   $id = (int) $id;
40)   $uid = (int) $_SESSION['userinfo']['uid'];
41)   
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

42)   $result = db_query("SELECT id, username, modules FROM system.subusers WHERE uid={$uid} AND id={$id}");
43)   $item = mysql_fetch_assoc($result);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

44)   $item['modules'] = explode(',', $item['modules']);
45)   return $item;
46) }
47) 
48) 
49) function available_modules()
50) {
51)   $modules = array();
bernd Lese Modul-Infos aus den in...

bernd authored 12 years ago

52)   $allmodules = get_modules_info();
53) 
54)   // Das su-Modul ist hierfuer unwichtig
55)   unset($allmodules['su']);
56) 
57)   foreach ($allmodules as $modname => $modinfo)
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

58)   {
bernd Lese Modul-Infos aus den in...

bernd authored 12 years ago

59)     if (isset($modinfo['permission']))
60)       $modules[$modname] = $modinfo['permission'];
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

61)   }
62)   return $modules;
63) }
64) 
65) function delete_subuser($id) {
66)   $id = (int) $id;
67)   $uid = (int) $_SESSION['userinfo']['uid'];
68)   
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

69)   db_query("DELETE FROM system.subusers WHERE id={$id} AND uid={$uid}");
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

70) }
71) 
72) function empty_subuser()
73) {
74)   $subuser = array("id" => NULL, "username" => $_SESSION['userinfo']['username'].'_', "modules" => array('index'));
75)   return $subuser;
76) }
77) 
78) function new_subuser($username, $requested_modules, $password) 
79) {
80)   $uid = (int) $_SESSION['userinfo']['uid'];
81) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

82)   $username = mysql_real_escape_string(filter_input_username($username));
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

83)   if (strpos($username, $_SESSION['userinfo']['username']) !== 0) {
84)     // Username nicht enthalten (FALSE) oder nicht am Anfang (>0)
85)     system_failure("Ungültiger Benutzername!");
86)   }
87) 
88)   if (!is_array($requested_modules)) {
89)     system_failure("Module nicht als array erhalten!");
90)   }
91)   DEBUG($requested_modules);
92)   $allmods = available_modules();
93)   $modules = array();
94)   foreach ($requested_modules as $mod) {
95)     if (isset($allmods[$mod])) {
96)       $modules[] = $mod;
97)     }
98)   }
99)   DEBUG($modules);
100)   if (count($modules) == 0) {
101)     system_failure("Es sind (nach der Filterung) keine Module mehr übrig!");
102)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

103)   $modules = mysql_real_escape_string(implode(',', $modules));
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

104)   
105)   $result = strong_password($password);
106)   if ($result !== true) {
107)     system_failure("Unsicheres Passwort. Die Meldung von cracklib lautet: ".$result);
108)   }
109)   $password = hash("sha256", $password);
110) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

111)   db_query("INSERT INTO system.subusers (uid, username, password, modules) VALUES ({$uid}, '{$username}', '{$password}', '{$modules}')");
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

112) }
113) 
114) 
115) function edit_subuser($id, $username, $requested_modules, $password) 
116) {
117)   $uid = (int) $_SESSION['userinfo']['uid'];
118) 
119)   $id = (int) $id;
120)   $my_subusers = list_subusers();
121)   $valid = false;
122)   foreach ($my_subusers as $x) {
123)     if ($x['id'] == $id) {
124)       $valid = true;
125)     }
126)   }
127)   if (!$valid) {
128)     system_failure("Kann diesen Account nicht finden!");
129)   }
130) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

131)   $username = mysql_real_escape_string(filter_input_username($username));
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

132)   if (strpos($username, $_SESSION['userinfo']['username']) !== 0) {
133)     // Username nicht enthalten (FALSE) oder nicht am Anfang (>0)
134)     system_failure("Ungültiger Benutzername!");
135)   }
136) 
137) 
138)   if (!is_array($requested_modules)) {
139)     system_failure("Module nicht als array erhalten!");
140)   }
141)   $allmods = available_modules();
142)   $modules = array();
143)   foreach ($requested_modules as $mod) {
144)     if (isset($allmods[$mod])) {
145)       $modules[] = $mod;
146)     }
147)   }
148)   if (count($modules) == 0) {
149)     system_failure("Es sind (nach der Filterung) keine Module mehr übrig!");
150)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

151)   $modules = mysql_real_escape_string(implode(',', $modules));
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

152)   
153)   $pwchange = '';
154)   if ($password) {
155)     $result = strong_password($password);
156)     if ($result !== true) {
157)       system_failure("Unsicheres Passwort. Die Meldung von cracklib lautet: ".$result);
158)     }
159)     $password = hash("sha256", $password);
160)     $pwchange = ", password='{$password}'";
161)   }
162) 
163) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

164)   db_query("UPDATE system.subusers SET username='{$username}', modules='{$modules}'{$pwchange} WHERE id={$id} AND uid={$uid}");