dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
bernd Neues Jabber-Modul (noch ni...

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

bernd authored 17 years ago

13) 
14) require_once("inc/debug.php");
bernd input-filtering

bernd authored 17 years ago

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

bernd authored 17 years ago

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

bernd authored 17 years ago

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

bernd authored 17 years ago

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

Hanno authored 6 years ago

19) function get_jabber_accounts()
20) {
21)     require_role(ROLE_CUSTOMER);
22)     $customerno = (int) $_SESSION['customerinfo']['customerno'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

23)     $result = db_query("SELECT id, `create`, created, lastactivity, local, domain FROM jabber.accounts WHERE customerno=? AND `delete`=0", [$customerno]);
24)     $accounts = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

25)     if (@$result->rowCount() > 0) {
26)         while ($acc = @$result->fetch()) {
27)             array_push($accounts, $acc);
28)         }
29)     }
30)     return $accounts;
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

31) }
32) 
33) 
34) 
35) function get_jabberaccount_details($id)
36) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

37)     require_role(ROLE_CUSTOMER);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

38)     $args = [":customerno" => $_SESSION['customerinfo']['customerno'],
39)                 ":id" => $id, ];
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

54) }
55) 
56) 
bernd erlaube Jabber-Passwörter m...

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

65) }
66) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

67) 
68) function create_jabber_account($local, $domain, $password)
69) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

70)     require_role(ROLE_CUSTOMER);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

71)     $data = [":customerno" => $_SESSION['customerinfo']['customerno'],
Bernd Wurst Jabber-accounts immer lower...

Bernd Wurst authored 6 years ago

72)                 ":local" => filter_input_username(strtolower($local)),
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

73)                 ":domain" => $domain, ];
Bernd Wurst add password strength check...

Bernd Wurst authored 5 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

83)     if ($domain > 0) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

84)         $args = [":domain" => $data[":domain"], ":customerno" => $data[":customerno"]];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

85)         $result = db_query("SELECT id FROM kundendaten.domains WHERE kunde=:customerno AND jabber=1 AND id=:domain", $args);
86)         if ($result->rowCount() == 0) {
87)             logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create account for invalid domain »{$domain}«");
88)             system_failure("Invalid domain!");
89)         }
90)     }
91) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

92)     $args = [":domain" => $data[":domain"], ":local" => $data[":local"]];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

93)     $domainquery = "domain=:domain";
94)     if ($domain == 0) {
95)         unset($args[":domain"]);
96)         $data[":domain"] = null;
97)         $domainquery = 'domain IS NULL';
98)     }
99)     $result = db_query("SELECT id FROM jabber.accounts WHERE local=:local AND {$domainquery}", $args);
100)     if ($result->rowCount() > 0) {
101)         logger(LOG_WARNING, "modules/jabber/include/jabberaccounts", "jabber", "attempt to create already existing account »{$local}@{$domain}«");
102)         system_failure("Diesen Account gibt es bereits!");
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

107) }
108) 
109) 
bernd Jabber-Passwort ändern

bernd authored 17 years ago

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

bernd authored 17 years ago

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

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 6 years ago

120)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 10 years ago

122)                 ":id" => $id,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

123)                 ":password" => $password, ];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

127) }
128) 
129) 
130) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

135)     $args = [":customerno" => $_SESSION['customerinfo']['customerno'],
136)                 ":id" => $id, ];
bernd Neues Jabber-Modul (noch ni...

bernd authored 17 years ago

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

Hanno authored 6 years ago

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

bernd authored 17 years ago

140) }
141) 
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 4 years ago

143) {
144)     $domains = get_domain_list((int) $_SESSION['customerinfo']['customerno']);
145)     $accounts = get_jabber_accounts();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

146)     $obsolete_domains = [];
Bernd Wurst implemented deletion of unu...

Bernd Wurst authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 4 years ago

166) {
167)     $d = new Domain((int) $id);
168)     $d->ensure_customerdomain();
169)     $obsolete_domains = domains_without_accounts();
170)     $found = false;
171)     foreach ($obsolete_domains as $od) {
172)         if ($od->id == $d->id) {
173)             $found = true;
174)         }
175)     }
176)     if (! $found) {
177)         system_failure('Diese Domain ist nicht unbenutzt.');
178)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

179)     db_query("UPDATE kundendaten.domains SET jabber=0 WHERE jabber=1 AND id=?", [$d->id]);
Bernd Wurst implemented deletion of unu...

Bernd Wurst authored 4 years ago

180) }
bernd Neue Jabber-Domains selbst...

bernd authored 15 years ago

181) 
182) function new_jabber_domain($id)
183) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

184)     $d = new Domain((int) $id);
185)     $d->ensure_customerdomain();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

186)     db_query("UPDATE kundendaten.domains SET jabber=2 WHERE jabber=0 AND id=?", [$d->id]);