8a4acb54b452ad801825c59cc7aa542eae0f9f3f
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 Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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 Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

27)   $subusers = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

28)   while ($item = $result->fetch())
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) {
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

39)   $args = array(":id" => $id, ":uid" => $_SESSION['userinfo']['uid']);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

40)   
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

41)   $result = db_query("SELECT id, username, modules FROM system.subusers WHERE uid=:uid AND id=:id", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

42)   $item = $result->fetch();
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

60)   }
61)   return $modules;
62) }
63) 
64) function delete_subuser($id) {
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

65)   $args = array(":id" => $id, ":uid" => $_SESSION['userinfo']['uid']);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

66)   
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

68) }
69) 
70) function empty_subuser()
71) {
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

72)   $subuser = array("id" => NULL, 
73)                    "username" => $_SESSION['userinfo']['username'].'_', 
74)                    "modules" => array('index'));
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

75)   return $subuser;
76) }
77) 
78) function new_subuser($username, $requested_modules, $password) 
79) {
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 6 years ago

104)     system_failure("Unsicheres Passwort: ".$result);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

105)   }
106) 
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

107)   $args = array(":uid" => $_SESSION['userinfo']['uid'],
108)                 ":username" => $username,
109)                 ":password" => hash("sha256", $password),
110)                 ":modules" => implode(',', $modules));
111) 
112)   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 12 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 10 years ago

153)   $args = array(":uid" => $_SESSION['userinfo']['uid'],
154)                 ":id" => $id,
155)                 ":username" => $username,
156)                 ":modules" => implode(',', $modules));
157) 
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

158)   $pwchange = '';
159)   if ($password) {
160)     $result = strong_password($password);
161)     if ($result !== true) {
Bernd Wurst Referenzen auf cracklib ent...

Bernd Wurst authored 6 years ago

162)       system_failure("Unsicheres Passwort: ".$result);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

163)     }
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

164)     $args[':password'] = hash("sha256", $password);
165)     $pwchange = ", password=:password";
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

166)   }
167) 
168) 
Bernd Wurst Modul subusers auf prepared...

Bernd Wurst authored 10 years ago

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