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

Bernd Wurst authored 13 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
13) 
Bernd Wurst changed subusers module to...

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 13 years ago

15) require_once("inc/base.php");
16) require_once("inc/security.php");
17) require_once("inc/debug.php");
18) 
19) 
20) function list_subusers()
21) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

22)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

23)     $result = db_query("SELECT id, username, modules FROM system.subusers WHERE uid=?", [$uid]);
24)     $subusers = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

25)     while ($item = $result->fetch()) {
26)         $item['modules'] = explode(',', $item['modules']);
27)         $subusers[] = $item;
28)     }
29)     DEBUG($subusers);
30)     return $subusers;
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

31) }
32) 
33) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

34) function load_subuser($id)
35) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

36)     $args = [":id" => $id, ":uid" => $_SESSION['userinfo']['uid']];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

37) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

38)     $result = db_query("SELECT id, username, modules FROM system.subusers WHERE uid=:uid AND id=:id", $args);
39)     $item = $result->fetch();
40)     $item['modules'] = explode(',', $item['modules']);
41)     return $item;
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

42) }
43) 
44) 
45) function available_modules()
46) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

47)     $modules = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

48)     $allmodules = get_modules_info();
49) 
50)     // Das su-Modul ist hierfuer unwichtig
51)     unset($allmodules['su']);
52) 
53)     foreach ($allmodules as $modname => $modinfo) {
54)         if (isset($modinfo['permission'])) {
55)             $modules[$modname] = $modinfo['permission'];
56)         }
57)     }
58)     return $modules;
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

59) }
60) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

61) function delete_subuser($id)
62) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

63)     $args = [":id" => $id, ":uid" => $_SESSION['userinfo']['uid']];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

64) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

65)     db_query("DELETE FROM system.subusers WHERE id=:id AND uid=:uid", $args);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

66) }
67) 
68) function empty_subuser()
69) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

70)     $subuser = ["id" => null,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

71)         "username" => $_SESSION['userinfo']['username'] . '_',
72)         "modules" => ['index'], ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

73)     return $subuser;
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

74) }
75) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

76) function new_subuser($username, $requested_modules, $password)
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

77) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

78)     $username = filter_input_username($username);
79)     if (strpos($username, $_SESSION['userinfo']['username']) !== 0) {
80)         // Username nicht enthalten (FALSE) oder nicht am Anfang (>0)
81)         system_failure("Ungültiger Benutzername!");
82)     }
83) 
84)     if (!is_array($requested_modules)) {
85)         system_failure("Module nicht als array erhalten!");
86)     }
87)     DEBUG($requested_modules);
88)     $allmods = available_modules();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

89)     $modules = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

90)     foreach ($requested_modules as $mod) {
91)         if (isset($allmods[$mod])) {
92)             $modules[] = $mod;
93)         }
94)     }
95)     DEBUG($modules);
96)     if (count($modules) == 0) {
97)         system_failure("Es sind (nach der Filterung) keine Module mehr übrig!");
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

98)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

99) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

100)     $result = strong_password($password);
101)     if ($result !== true) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

102)         system_failure("Unsicheres Passwort: " . $result);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

103)     }
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

104) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

105)     $args = [":uid" => $_SESSION['userinfo']['uid'],
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

106)         ":username" => $username,
107)         ":password" => gen_pw_hash($password),
108)         ":modules" => implode(',', $modules), ];
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

109) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)     db_query("INSERT INTO system.subusers (uid, username, password, modules) VALUES (:uid, :username, :password, :modules)", $args);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

111) }
112) 
113) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

114) function edit_subuser($id, $username, $requested_modules, $password)
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

115) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

116)     $uid = (int) $_SESSION['userinfo']['uid'];
117) 
118)     $id = (int) $id;
119)     $my_subusers = list_subusers();
120)     $valid = false;
121)     foreach ($my_subusers as $x) {
122)         if ($x['id'] == $id) {
123)             $valid = true;
124)         }
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

125)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

126)     if (!$valid) {
127)         system_failure("Kann diesen Account nicht finden!");
128)     }
129) 
130)     $username = filter_input_username($username);
131)     if (strpos($username, $_SESSION['userinfo']['username']) !== 0) {
132)         // Username nicht enthalten (FALSE) oder nicht am Anfang (>0)
133)         system_failure("Ungültiger Benutzername!");
134)     }
135) 
136) 
137)     if (!is_array($requested_modules)) {
138)         system_failure("Module nicht als array erhalten!");
139)     }
140)     $allmods = available_modules();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

141)     $modules = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

142)     foreach ($requested_modules as $mod) {
143)         if (isset($allmods[$mod])) {
144)             $modules[] = $mod;
145)         }
146)     }
147)     if (count($modules) == 0) {
148)         system_failure("Es sind (nach der Filterung) keine Module mehr übrig!");
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

149)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

150) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

151)     $args = [":uid" => $_SESSION['userinfo']['uid'],
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

152)         ":id" => $id,
153)         ":username" => $username,
154)         ":modules" => implode(',', $modules), ];
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

155) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

156)     $pwchange = '';
157)     if ($password) {
158)         $result = strong_password($password);
159)         if ($result !== true) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

160)             system_failure("Unsicheres Passwort: " . $result);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

161)         }
Hanno Böck use real password hashes fo...

Hanno Böck authored 11 months ago

162)         $args[':password'] = gen_pw_hash($password);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

163)         $pwchange = ", password=:password";
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 13 years ago

164)     }
165) 
166) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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