7f4ef736f78f3f6810693e2ed6ca86afa9680110
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 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) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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) */
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

16) 
17) require_once("inc/debug.php");
bernd input-filtering

bernd authored 16 years ago

18) require_once("inc/security.php");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

19) 
bernd Parse Error, hatte ich gar...

bernd authored 16 years ago

20) require_once('class/domain.php');
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

Hanno authored 5 years ago

22) function get_jabber_accounts()
23) {
24)     require_role(ROLE_CUSTOMER);
25)     $customerno = (int) $_SESSION['customerinfo']['customerno'];
26)     $result = db_query("SELECT id, `create`, created, lastactivity, local, domain FROM jabber.accounts WHERE customerno=? AND `delete`=0", array($customerno));
27)     $accounts = array();
28)     if (@$result->rowCount() > 0) {
29)         while ($acc = @$result->fetch()) {
30)             array_push($accounts, $acc);
31)         }
32)     }
33)     return $accounts;
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

34) }
35) 
36) 
37) 
38) function get_jabberaccount_details($id)
39) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

40)     require_role(ROLE_CUSTOMER);
41)     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
Bernd Wurst Weitere Umstellungen auf pr...

Bernd Wurst authored 10 years ago

42)                 ":id" => $id);
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

Hanno authored 5 years ago

44)     $result = db_query("SELECT id, local, domain FROM jabber.accounts WHERE customerno=:customerno AND id=:id", $args);
45)     if ($result->rowCount() != 1) {
46)         system_failure("Invalid account");
47)     }
48)     $data = $result->fetch();
49)     if ($data['domain'] == null) {
50)         $data['domain'] = config('masterdomain');
51)     } else {
52)         $dom = new Domain((int) $data['domain']);
53)         $dom->ensure_customerdomain();
54)         $data['domain'] = $dom->fqdn;
55)     }
56)     return $data;
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

57) }
58) 
59) 
bernd erlaube Jabber-Passwörter m...

bernd authored 16 years ago

60) function valid_jabber_password($pass)
61) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

62)     // Hier könnten erweiterte Checks stehen wenn nötig.
63)     /*$foo = ereg_replace('["\']', '', $pass);
64)     DEBUG("\$foo = {$foo} / \$pass = {$pass}");
65)     return ($foo == $pass);
66)     */
67)     return true;
bernd erlaube Jabber-Passwörter m...

bernd authored 16 years ago

68) }
69) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

70) 
71) function create_jabber_account($local, $domain, $password)
72) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

73)     require_role(ROLE_CUSTOMER);
74)     $data = array(":customerno" => $_SESSION['customerinfo']['customerno'],
Bernd Wurst Jabber-accounts immer lower...

Bernd Wurst authored 5 years ago

75)                 ":local" => filter_input_username(strtolower($local)),
Bernd Wurst Weitere Umstellungen auf pr...

Bernd Wurst authored 10 years ago

76)                 ":domain" => $domain);
Bernd Wurst add password strength check...

Bernd Wurst authored 5 years ago

77)     if (!valid_jabber_password($password)) {
78)         system_failure('Das Passwort enthält Zeichen, die aufgrund technischer Beschränkungen momentan nicht benutzt werden können.');
79)     }
80)     $check = strong_password($password);
81)     if ($check !== true) {
82)         system_failure('Das Passwort ist nicht sicher genug.');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

83)     }
84)     $data[':password'] = $password;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

86)     if ($domain > 0) {
87)         $args = array(":domain" => $data[":domain"], ":customerno" => $data[":customerno"]);
88)         $result = db_query("SELECT id FROM kundendaten.domains WHERE kunde=:customerno AND jabber=1 AND id=:domain", $args);
89)         if ($result->rowCount() == 0) {
90)             logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create account for invalid domain »{$domain}«");
91)             system_failure("Invalid domain!");
92)         }
93)     }
94) 
95)     $args = array(":domain" => $data[":domain"], ":local" => $data[":local"]);
96)     $domainquery = "domain=:domain";
97)     if ($domain == 0) {
98)         unset($args[":domain"]);
99)         $data[":domain"] = null;
100)         $domainquery = 'domain IS NULL';
101)     }
102)     $result = db_query("SELECT id FROM jabber.accounts WHERE local=:local AND {$domainquery}", $args);
103)     if ($result->rowCount() > 0) {
104)         logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create already existing account »{$local}@{$domain}«");
105)         system_failure("Diesen Account gibt es bereits!");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

Hanno authored 5 years ago

107) 
108)     db_query("INSERT INTO jabber.accounts (customerno,local,domain,password) VALUES (:customerno, :local, :domain, :password);", $data);
109)     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "created account »{$local}@{$domain}«");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

110) }
111) 
112) 
bernd Jabber-Passwort ändern

bernd authored 16 years ago

113) 
bernd erlaube Jabber-Passwörter m...

bernd authored 16 years ago

114) function change_jabber_password($id, $password)
bernd Jabber-Passwort ändern

bernd authored 16 years ago

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

Hanno authored 5 years ago

116)     require_role(ROLE_CUSTOMER);
Bernd Wurst add password strength check...

Bernd Wurst authored 5 years ago

117)     if (!valid_jabber_password($password)) {
118)         system_failure('Das Passwort enthält Zeichen, die aufgrund technischer Beschränkungen momentan nicht benutzt werden können.');
119)     }
120)     $check = strong_password($password);
121)     if ($check !== true) {
122)         system_failure('Das Passwort ist nicht sicher genug.');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

123)     }
124)     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
Bernd Wurst Weitere Umstellungen auf pr...

Bernd Wurst authored 10 years ago

125)                 ":id" => $id,
126)                 ":password" => $password);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

128)     db_query("UPDATE jabber.accounts SET password=:password WHERE customerno=:customerno AND id=:id", $args);
129)     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "changed password for account  »{$id}«");
bernd Jabber-Passwort ändern

bernd authored 16 years ago

130) }
131) 
132) 
133) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

134) function delete_jabber_account($id)
135) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

136)     require_role(ROLE_CUSTOMER);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

138)     $args = array(":customerno" => $_SESSION['customerinfo']['customerno'],
Bernd Wurst Weitere Umstellungen auf pr...

Bernd Wurst authored 10 years ago

139)                 ":id" => $id);
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

Hanno authored 5 years ago

141)     db_query("UPDATE jabber.accounts SET `delete`=1 WHERE customerno=:customerno AND id=:id", $args);
142)     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "deleted account »{$id}«");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

143) }
144) 
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

145) function domains_without_accounts()
Bernd Wurst implemented deletion of unu...

Bernd Wurst authored 4 years ago

146) {
147)     $domains = get_domain_list((int) $_SESSION['customerinfo']['customerno']);
148)     $accounts = get_jabber_accounts();
149)     $obsolete_domains = array();
150)     foreach ($domains as $d) {
151)         if ($d->jabber != 1) {
152)             continue;
153)         }
154)         $found = false;
155)         foreach ($accounts as $a) {
156)             if ($a['domain'] == $d->id) {
157)                 $found = true;
158)             }
159)         }
160)         if (! $found) {
161)             $obsolete_domains[] = $d;
162)         }
163)     }
164)     return $obsolete_domains;
165) }
166) 
167) 
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

168) function delete_jabber_domain($id)
Bernd Wurst implemented deletion of unu...

Bernd Wurst authored 4 years ago

169) {
170)     $d = new Domain((int) $id);
171)     $d->ensure_customerdomain();
172)     $obsolete_domains = domains_without_accounts();
173)     $found = false;
174)     foreach ($obsolete_domains as $od) {
175)         if ($od->id == $d->id) {
176)             $found = true;
177)         }
178)     }
179)     if (! $found) {
180)         system_failure('Diese Domain ist nicht unbenutzt.');
181)     }
182)     db_query("UPDATE kundendaten.domains SET jabber=0 WHERE jabber=1 AND id=?", array($d->id));
183) }
bernd Neue Jabber-Domains selbst...

bernd authored 14 years ago

184) 
185) function new_jabber_domain($id)
186) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

187)     $d = new Domain((int) $id);
188)     $d->ensure_customerdomain();
189)     db_query("UPDATE kundendaten.domains SET jabber=2 WHERE jabber=0 AND id=?", array($d->id));