bcbfc9f818c6a00449b8d9ee22f89e47245125c9
bernd Verwaltung von FTP-Accounts...

bernd authored 14 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 Verwaltung von FTP-Accounts...

bernd authored 14 years ago

16) 
17) require_once('inc/base.php');
Bernd Wurst add password strength check...

Bernd Wurst authored 5 years ago

18) require_once('inc/security.php');
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

19) 
20) function list_ftpusers()
21) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

22)     $uid = (int) $_SESSION['userinfo']['uid'];
23)     $result = db_query("SELECT id, username, homedir, active, forcessl FROM system.ftpusers WHERE uid=?", array($uid));
24)     $ftpusers = array();
25)     while ($u = $result->fetch()) {
26)         $ftpusers[] = $u;
27)     }
28)     return $ftpusers;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

29) }
30) 
31) function empty_ftpuser()
32) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

33)     $myserver = my_server_id();
34)     return array("id" => "0", "username" => "", "password" => "", "homedir" => "", "active" => "1", "forcessl" => "1", "server" => $myserver);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

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

Hanno authored 5 years ago

39)     if ($id == 0) {
40)         return empty_ftpuser();
41)     }
42)     $args = array(":id" => $id, ":uid" => $_SESSION['userinfo']['uid']);
43)     $result = db_query("SELECT id, username, password, homedir, active, forcessl, server FROM system.ftpusers WHERE uid=:uid AND id=:id", $args);
44)     if ($result->rowCount() != 1) {
45)         system_failure("Fehler beim auslesen des Accounts");
46)     }
47)     $account = $result->fetch();
48)     DEBUG($account);
49)     return $account;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

50) }
51) 
52) 
53) function save_ftpuser($data)
54) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

55)     verify_input_username($data['username']);
56)     if ($data['username'] == '') {
57)         system_failure('Bitte geben Sie eine Erweiterung für den Benutzernamen an!');
58)     }
59)     $homedir = filter_input_general($data['homedir']);
60)     if (substr($homedir, 0, 1) == '/') {
61)         $homedir = substr($homedir, 1);
bernd Auch FTP-User-Passwörter mi...

bernd authored 13 years ago

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

Hanno authored 5 years ago

63)     $homedir = $_SESSION['userinfo']['homedir'].'/'.$homedir;
64)     if (! in_homedir($homedir)) {
65)         system_failure('Pfad scheint nicht in Ihrem Home zu sein oder enthielt ungültige Zeichen.');
66)     }
67) 
68)     $server = null;
69)     if ($data['server'] == my_server_id()) {
70)         $server = null;
71)     } elseif (in_array($data['server'], additional_servers())) {
72)         $server = (int) $data['server'];
73)     }
74) 
75)     $set_password = false;
76)     $password_hash = '';
77)     if ($data['password'] != '') {
Bernd Wurst add password strength check...

Bernd Wurst authored 5 years ago

78)         $result = strong_password($data['password']);
79)         if ($result !== true) {
80)             system_failure("Unsicheres Passwort: ".$result);
81)         }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

82)         if (defined("CRYPT_SHA512") && CRYPT_SHA512 == 1) {
83)             $rounds = rand(1000, 5000);
84)             $salt = "rounds=".$rounds."$".random_string(8);
85)             $password_hash = crypt($data['password'], "\$6\${$salt}\$");
86)         } else {
87)             $salt = random_string(8);
88)             $password_hash = crypt($data['password'], "\$1\${$salt}\$");
89)         }
90)         $set_password = true;
91)     } elseif (! $data['id']) {
92)         system_failure('Wenn Sie einen neuen Zugang anlegen, müssen Sie ein Passwort setzen');
bernd Auch FTP-User-Passwörter mi...

bernd authored 13 years ago

93)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

95)     $args = array(":username" => $_SESSION['userinfo']['username'].'-'.$data['username'],
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

96)                 ":homedir" => $homedir,
97)                 ":active" => ($data['active'] == 1 ? 1 : 0),
98)                 ":forcessl" => ($data['forcessl'] == 0 ? 0 : 1),
99)                 ":server" => $server,
100)                 ":uid" => $_SESSION['userinfo']['uid']);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

102)     if ($data['id']) {
103)         $args[":id"] = $data['id'];
104)         if ($set_password) {
105)             $args[':password'] = $password_hash;
106)             db_query("UPDATE system.ftpusers SET username=:username, password=:password, homedir=:homedir, active=:active, forcessl=:forcessl, server=:server WHERE id=:id AND uid=:uid", $args);
107)         } else {
108)             db_query("UPDATE system.ftpusers SET username=:username, homedir=:homedir, active=:active, forcessl=:forcessl, server=:server WHERE id=:id AND uid=:uid", $args);
109)         }
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

110)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

111)         $args[':password'] = $password_hash;
112)         db_query("INSERT INTO system.ftpusers (username, password, homedir, uid, active, forcessl, server) VALUES (:username, :password, :homedir, :uid, :active, :forcessl, :server)", $args);
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

113)     }
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

114) }
115) 
116) 
117) function delete_ftpuser($id)
118) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

119)     $args = array(":id" => $id, ":uid" => $_SESSION['userinfo']['uid']);
120)     db_query("DELETE FROM system.ftpusers WHERE id=:id AND uid=:uid", $args);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

121) }
122) 
123) 
124) function get_gid($groupname)
125) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

126)     $result = db_query("SELECT gid FROM system.gruppen WHERE name=?", array($groupname));
127)     if ($result->rowCount() != 1) {
128)         system_failure('cannot determine gid of ftpusers group');
129)     }
130)     $a = $result->fetch();
131)     $gid = (int) $a['gid'];
132)     if ($gid == 0) {
133)         system_failure('error on determining gid of ftpusers group');
134)     }
135)     return $gid;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

136) }
137) 
138) 
139) function have_regular_ftp()
140) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

141)     $args = array(":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']);
142)     $result = db_query("SELECT * FROM system.gruppenzugehoerigkeit WHERE gid=:gid AND uid=:uid", $args);
143)     return ($result->rowCount() > 0);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

144) }
145) 
146) 
147) function enable_regular_ftp()
148) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

149)     require_role(ROLE_SYSTEMUSER);
150)     $args = array(":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']);
151)     db_query("REPLACE INTO system.gruppenzugehoerigkeit (gid, uid) VALUES (:gid, :uid)", $args);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

152) }
153) 
154) function disable_regular_ftp()
155) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

156)     $args = array(":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']);
157)     db_query("DELETE FROM system.gruppenzugehoerigkeit WHERE gid=:gid AND uid=:uid", $args);