53483790884f5e09eee79991e3415a4fd2ffc159
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)     }
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

59)     $homedir = $data['homedir'];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Simplify crypt() calls, alw...

Hanno Böck authored 3 years ago

82)         $password_hash = crypt($data['password'], '$6$'.random_string(8).'$');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

83)         $set_password = true;
84)     } elseif (! $data['id']) {
85)         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

86)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

89)                 ":homedir" => $homedir,
90)                 ":active" => ($data['active'] == 1 ? 1 : 0),
91)                 ":forcessl" => ($data['forcessl'] == 0 ? 0 : 1),
92)                 ":server" => $server,
93)                 ":uid" => $_SESSION['userinfo']['uid']);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

95)     if ($data['id']) {
96)         $args[":id"] = $data['id'];
97)         if ($set_password) {
98)             $args[':password'] = $password_hash;
99)             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);
100)         } else {
101)             db_query("UPDATE system.ftpusers SET username=:username, homedir=:homedir, active=:active, forcessl=:forcessl, server=:server WHERE id=:id AND uid=:uid", $args);
102)         }
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

104)         $args[':password'] = $password_hash;
105)         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

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

bernd authored 14 years ago

107) }
108) 
109) 
110) function delete_ftpuser($id)
111) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

119)     $result = db_query("SELECT gid FROM system.gruppen WHERE name=?", array($groupname));
120)     if ($result->rowCount() != 1) {
121)         system_failure('cannot determine gid of ftpusers group');
122)     }
123)     $a = $result->fetch();
124)     $gid = (int) $a['gid'];
125)     if ($gid == 0) {
126)         system_failure('error on determining gid of ftpusers group');
127)     }
128)     return $gid;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

129) }
130) 
131) 
132) function have_regular_ftp()
133) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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