2626dd47daad110c63a82c0560b134e2364eeac3
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');
18) 
19) function list_ftpusers()
20) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

62)     $homedir = $_SESSION['userinfo']['homedir'].'/'.$homedir;
63)     if (! in_homedir($homedir)) {
64)         system_failure('Pfad scheint nicht in Ihrem Home zu sein oder enthielt ungültige Zeichen.');
65)     }
66) 
67)     $server = null;
68)     if ($data['server'] == my_server_id()) {
69)         $server = null;
70)     } elseif (in_array($data['server'], additional_servers())) {
71)         $server = (int) $data['server'];
72)     }
73) 
74)     $set_password = false;
75)     $password_hash = '';
76)     if ($data['password'] != '') {
77)         if (defined("CRYPT_SHA512") && CRYPT_SHA512 == 1) {
78)             $rounds = rand(1000, 5000);
79)             $salt = "rounds=".$rounds."$".random_string(8);
80)             $password_hash = crypt($data['password'], "\$6\${$salt}\$");
81)         } else {
82)             $salt = random_string(8);
83)             $password_hash = crypt($data['password'], "\$1\${$salt}\$");
84)         }
85)         $set_password = true;
86)         $password_query = "password='{$password_hash}', ";
87)     } elseif (! $data['id']) {
88)         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

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

92)                 ":homedir" => $homedir,
93)                 ":active" => ($data['active'] == 1 ? 1 : 0),
94)                 ":forcessl" => ($data['forcessl'] == 0 ? 0 : 1),
95)                 ":server" => $server,
96)                 ":uid" => $_SESSION['userinfo']['uid']);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

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

bernd authored 14 years ago

110) }
111) 
112) 
113) function delete_ftpuser($id)
114) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

117) }
118) 
119) 
120) function get_gid($groupname)
121) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

132) }
133) 
134) 
135) function have_regular_ftp()
136) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

140) }
141) 
142) 
143) function enable_regular_ftp()
144) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

148) }
149) 
150) function disable_regular_ftp()
151) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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