d15336e63638b00f19db8cef0a9908472aef82f3
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 Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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) {
21)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

22)   $result = db_query("SELECT id, username, homedir, active, forcessl FROM system.ftpusers WHERE uid=?", array($uid));
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

23)   $ftpusers = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

24)   while ($u = $result->fetch()) {
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

25)     $ftpusers[] = $u;
26)   }
27)   return $ftpusers;
28) }
29) 
30) function empty_ftpuser()
31) {
32)   $myserver = my_server_id();
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

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) {
38)   if ($id == 0)
39)     return empty_ftpuser();
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

40)   $args = array(":id" => $id, ":uid" => $_SESSION['userinfo']['uid']);
41)   $result = db_query("SELECT id, username, password, homedir, active, forcessl, server FROM system.ftpusers WHERE uid=:uid AND id=:id", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

42)   if ($result->rowCount() != 1)
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

43)     system_failure("Fehler beim auslesen des Accounts");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

44)   $account = $result->fetch();
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

45)   DEBUG($account);
46)   return $account;
47) }
48) 
49) 
50) function save_ftpuser($data)
51) {
52)   verify_input_username($data['username']);
53)   if ($data['username'] == '')
54)     system_failure('Bitte geben Sie eine Erweiterung für den Benutzernamen an!');
55)   $homedir = filter_input_general($data['homedir']);
56)   if (substr($homedir, 0, 1) == '/')
57)     $homedir = substr($homedir, 1);
58)   $homedir = $_SESSION['userinfo']['homedir'].'/'.$homedir;
59)   if (! in_homedir($homedir))
60)     system_failure('Pfad scheint nicht in Ihrem Home zu sein oder enthielt ungültige Zeichen.');
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

61) 
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

62)   $server = NULL;
63)   if ($data['server'] == my_server_id())
64)   {
65)     $server = NULL;
66)   }
67)   elseif (in_array($data['server'], additional_servers()))
68)   {
69)     $server = (int) $data['server'];
70)   }
71) 
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

72)   $set_password = false;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

73)   $password_hash = '';
74)   if ($data['password'] != '')
75)   {
bernd Auch FTP-User-Passwörter mi...

bernd authored 13 years ago

76)     if (defined("CRYPT_SHA512") && CRYPT_SHA512 == 1)
77)     {
78)       $rounds = rand(1000, 5000);
79)       $salt = "rounds=".$rounds."$".random_string(8);
80)       $password_hash = crypt($data['password'], "\$6\${$salt}\$");
81)     }
82)     else
83)     {
84)       $salt = random_string(8);
85)       $password_hash = crypt($data['password'], "\$1\${$salt}\$");
86)     }
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

87)     $set_pasword = true;
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

88)     $password_query = "password='{$password_hash}', ";
89)   }
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

90)   elseif (! $data['id'])
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

91)   {
92)     system_failure('Wenn Sie einen neuen Zugang anlegen, müssen Sie ein Passwort setzen');
93)   }
94)     
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

95)   $args = array(":username" => $_SESSION['userinfo']['username'].'-'.$data['username'],
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']);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

101)   
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 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)     }
110)   }  else {
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);
113)   }
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

114) }
115) 
116) 
117) function delete_ftpuser($id)
118) {
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 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) {
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

126)   $result = db_query("SELECT gid FROM system.gruppen WHERE name=?", array($groupname));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

127)   if ($result->rowCount() != 1)
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

128)     system_failure('cannot determine gid of ftpusers group');
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

129)   $a = $result->fetch();
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

130)   $gid = (int) $a['gid'];
131)   if ($gid == 0)
132)     system_failure('error on determining gid of ftpusers group');
133)   return $gid;
134) }
135) 
136) 
137) function have_regular_ftp()
138) {
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

139)   $args = array(":gid" => get_gid('ftpusers'), ":uid" => $_SESSION['userinfo']['uid']);
140)   $result = db_query("SELECT * FROM system.gruppenzugehoerigkeit WHERE gid=:gid AND uid=:uid", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

141)   return ($result->rowCount() > 0);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

142) }
143) 
144) 
145) function enable_regular_ftp()
146) {
bernd Security-enhancements und a...

bernd authored 14 years ago

147)   require_role(ROLE_SYSTEMUSER);
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

150) }
151) 
152) function disable_regular_ftp()
153) {
Bernd Wurst Modul ftpusers auf prepared...

Bernd Wurst authored 10 years ago

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