dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
bernd Verwaltung von FTP-Accounts...

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

bernd authored 15 years ago

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

Bernd Wurst authored 5 years ago

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

bernd authored 15 years ago

16) 
17) function list_ftpusers()
18) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

19)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

20)     $result = db_query("SELECT id, username, homedir, active, forcessl FROM system.ftpusers WHERE uid=?", [$uid]);
21)     $ftpusers = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

22)     while ($u = $result->fetch()) {
23)         $ftpusers[] = $u;
24)     }
25)     return $ftpusers;
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

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

Hanno authored 6 years ago

30)     $myserver = my_server_id();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

31)     return ["id" => "0", "username" => "", "password" => "", "homedir" => "", "active" => "1", "forcessl" => "1", "server" => $myserver];
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

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

Hanno authored 6 years ago

36)     if ($id == 0) {
37)         return empty_ftpuser();
38)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

39)     $args = [":id" => $id, ":uid" => $_SESSION['userinfo']['uid']];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

52)     verify_input_username($data['username']);
53)     if ($data['username'] == '') {
54)         system_failure('Bitte geben Sie eine Erweiterung für den Benutzernamen an!');
55)     }
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 5 years ago

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

Hanno authored 6 years ago

57)     if (substr($homedir, 0, 1) == '/') {
58)         $homedir = substr($homedir, 1);
bernd Auch FTP-User-Passwörter mi...

bernd authored 14 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 5 years ago

75)         $result = strong_password($data['password']);
76)         if ($result !== true) {
77)             system_failure("Unsicheres Passwort: ".$result);
78)         }
Hanno Böck Simplify crypt() calls, alw...

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

80)         $set_password = true;
81)     } elseif (! $data['id']) {
82)         system_failure('Wenn Sie einen neuen Zugang anlegen, müssen Sie ein Passwort setzen');
bernd Auch FTP-User-Passwörter mi...

bernd authored 14 years ago

83)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 10 years ago

86)                 ":homedir" => $homedir,
87)                 ":active" => ($data['active'] == 1 ? 1 : 0),
88)                 ":forcessl" => ($data['forcessl'] == 0 ? 0 : 1),
89)                 ":server" => $server,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

90)                 ":uid" => $_SESSION['userinfo']['uid'], ];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

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

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

bernd authored 15 years ago

104) }
105) 
106) 
107) function delete_ftpuser($id)
108) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

109)     $args = [":id" => $id, ":uid" => $_SESSION['userinfo']['uid']];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)     db_query("DELETE FROM system.ftpusers WHERE id=:id AND uid=:uid", $args);
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

111) }
112) 
113) 
114) function get_gid($groupname)
115) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

116)     $result = db_query("SELECT gid FROM system.gruppen WHERE name=?", [$groupname]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

117)     if ($result->rowCount() != 1) {
118)         system_failure('cannot determine gid of ftpusers group');
119)     }
120)     $a = $result->fetch();
121)     $gid = (int) $a['gid'];
122)     if ($gid == 0) {
123)         system_failure('error on determining gid of ftpusers group');
124)     }
125)     return $gid;
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

126) }
127) 
128) 
129) function have_regular_ftp()
130) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

131)     $args = [":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

132)     $result = db_query("SELECT * FROM system.gruppenzugehoerigkeit WHERE gid=:gid AND uid=:uid", $args);
133)     return ($result->rowCount() > 0);
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

134) }
135) 
136) 
137) function enable_regular_ftp()
138) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

139)     require_role(ROLE_SYSTEMUSER);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

140)     $args = [":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

141)     db_query("REPLACE INTO system.gruppenzugehoerigkeit (gid, uid) VALUES (:gid, :uid)", $args);
bernd Verwaltung von FTP-Accounts...

bernd authored 15 years ago

142) }
143) 
144) function disable_regular_ftp()
145) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

146)     $args = [":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

147)     db_query("DELETE FROM system.gruppenzugehoerigkeit WHERE gid=:gid AND uid=:uid", $args);