f1f231f5e074dfa038e70a67d39849e80f2b4b4d
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 Erlaube unverschlüsselte FT...

bernd authored 12 years ago

22)   $result = db_query("SELECT id, username, homedir, active, forcessl FROM system.ftpusers WHERE uid=$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();
40)   $uid = (int) $_SESSION['userinfo']['uid'];
41)   $id = (int) $id;
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

42)   $result = db_query("SELECT id, username, password, homedir, active, forcessl, server FROM system.ftpusers WHERE uid={$uid} AND id='{$id}' LIMIT 1");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

46)   DEBUG($account);
47)   return $account;
48) }
49) 
50) 
51) function save_ftpuser($data)
52) {
53)   $uid = (int) $_SESSION['userinfo']['uid'];
54)   $id = (int) $data['id'];
55)   verify_input_username($data['username']);
56)   if ($data['username'] == '')
57)     system_failure('Bitte geben Sie eine Erweiterung für den Benutzernamen an!');
58)   $username = $_SESSION['userinfo']['username'].'-'.$data['username'];
59)   $homedir = filter_input_general($data['homedir']);
60)   if (substr($homedir, 0, 1) == '/')
61)     $homedir = substr($homedir, 1);
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)   $active = ($data['active'] == 1 ? '1' : '0');
66) 
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

67)   $forcessl = ($data['forcessl'] == 0 ? '0' : '1');
68) 
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

69)   $server = NULL;
70)   if ($data['server'] == my_server_id())
71)   {
72)     $server = NULL;
73)   }
74)   elseif (in_array($data['server'], additional_servers()))
75)   {
76)     $server = (int) $data['server'];
77)   }
78)   $server = maybe_null($server);
79) 
80)   $password_query = '';
81)   $password_hash = '';
82)   if ($data['password'] != '')
83)   {
bernd Auch FTP-User-Passwörter mi...

bernd authored 13 years ago

84)     if (defined("CRYPT_SHA512") && CRYPT_SHA512 == 1)
85)     {
86)       $rounds = rand(1000, 5000);
87)       $salt = "rounds=".$rounds."$".random_string(8);
88)       $password_hash = crypt($data['password'], "\$6\${$salt}\$");
89)     }
90)     else
91)     {
92)       $salt = random_string(8);
93)       $password_hash = crypt($data['password'], "\$1\${$salt}\$");
94)     }
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

95)     $password_query = "password='{$password_hash}', ";
96)   }
97)   elseif (! $id)
98)   {
99)     system_failure('Wenn Sie einen neuen Zugang anlegen, müssen Sie ein Passwort setzen');
100)   }
101)     
102)   
103)   if ($id)
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

104)     db_query("UPDATE system.ftpusers SET username='{$username}', {$password_query} homedir='{$homedir}', active='{$active}', forcessl='{$forcessl}', server={$server} WHERE id={$id} AND uid={$uid} LIMIT 1");
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

105)   else
bernd Erlaube unverschlüsselte FT...

bernd authored 12 years ago

106)     db_query("INSERT INTO system.ftpusers (username, password, homedir, uid, active, forcessl, server) VALUES ('{$username}', '{$password_hash}', '{$homedir}', '{$uid}', '{$active}', '{$forcessl}', {$server})");
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

107) }
108) 
109) 
110) function delete_ftpuser($id)
111) {
112)   $uid = (int) $_SESSION['userinfo']['uid'];
113)   $id = (int) $id;
114)   db_query("DELETE FROM system.ftpusers WHERE id='{$id}' AND uid={$uid} LIMIT 1");
115) }
116) 
117) 
118) function get_gid($groupname)
119) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

120)   $groupname = db_escape_string($groupname);
bernd Verwaltung von FTP-Accounts...

bernd authored 14 years ago

121)   $result = db_query("SELECT gid FROM system.gruppen WHERE name='{$groupname}' LIMIT 1");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

125)   $gid = (int) $a['gid'];
126)   if ($gid == 0)
127)     system_failure('error on determining gid of ftpusers group');
128)   return $gid;
129) }
130) 
131) 
132) function have_regular_ftp()
133) {
134)   $gid = get_gid('ftpusers');
135)   $uid = (int) $_SESSION['userinfo']['uid'];
136)   $result = db_query("SELECT * FROM system.gruppenzugehoerigkeit WHERE gid='$gid' AND uid='$uid'");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

138) }
139) 
140) 
141) function enable_regular_ftp()
142) {
bernd Security-enhancements und a...

bernd authored 14 years ago

143)   require_role(ROLE_SYSTEMUSER);