bernd commited on 2009-12-08 16:22:42
Zeige 5 geänderte Dateien mit 309 Einfügungen und 0 Löschungen.
git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@1533 87cf0b9e-d624-0410-a070-f6ee81989793
... | ... |
@@ -0,0 +1,42 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+require_once('inc/base.php'); |
|
4 |
+require_once('inc/icons.php'); |
|
5 |
+ |
|
6 |
+include("ftpusers.php"); |
|
7 |
+ |
|
8 |
+$ftpusers = list_ftpusers(); |
|
9 |
+$regular_ftp = have_regular_ftp(); |
|
10 |
+ |
|
11 |
+ |
|
12 |
+output('<h3>FTP-Zugänge</h3> |
|
13 |
+<p>Mit Ihrem SSH- bzw. SFTP-Zugriff können Sie sämtliche Ihrer Dateien bearbeiten und alle Funktionen nutzen, die wir Ihnen bereitstellen. Wenn sie möchten, können Sie sich mit diesen Zugangsdaten auch über das FTP-Protokoll verbinden.</p> |
|
14 |
+'); |
|
15 |
+ |
|
16 |
+if ($regular_ftp) |
|
17 |
+{ |
|
18 |
+ output('<p>'.icon_enabled().' Momentan ist der Zugriff über FTP aktiviert. Wenn Sie diesen nicht benötigen sollten Sie ihn aus Sicherheitsgründen ausschalten.<br /><a href="edit?regular_ftp=no">FTP-Zugriff sperren</a></p>'); |
|
19 |
+} |
|
20 |
+else |
|
21 |
+{ |
|
22 |
+ output('<p>'.icon_error().' Der Zugriff über FTP ist momentan gesperrt. Aktivieren Sie diesen nur wenn Sie ihn auch nutzen möchten.<br /><a href="edit?regular_ftp=yes">FTP-Zugriff freischalten</a></p>'); |
|
23 |
+} |
|
24 |
+ |
|
25 |
+output(' |
|
26 |
+<h3>Zusätzliche FTP-Benutzer</h3> |
|
27 |
+<p>Als Zusatzleistung bieten wir Ihnen die Möglichkeit, weitere FTP-Benutzerzugänge anzulegen. Diese Zugänge sind auf das angegebene Verzeichnis beschränkt und es kann nur mit dem FTP-Protokoll verwendet werden. Ein Login mittels SSH ist für diese Benutzerkonten nicht möglich.</p>'); |
|
28 |
+ |
|
29 |
+ |
|
30 |
+output(' |
|
31 |
+<table><tr><th>Benutzername</th><th>Verzeichnis</th><th>aktiv</th><th> </th></tr> |
|
32 |
+'); |
|
33 |
+ |
|
34 |
+foreach ($ftpusers AS $f) |
|
35 |
+{ |
|
36 |
+ $active = ($f['active'] == 1 ? icon_enabled('Ja') : '-'); |
|
37 |
+ output("<tr><td>".internal_link("edit?id={$f['id']}", $f['username'])."</td><td>{$f['homedir']}</td><td style=\"text-align: center;\">{$active}</td><td>".internal_link("save?delete={$f['id']}", icon_delete("{$f['username']} löschen"))."</td></tr>"); |
|
38 |
+} |
|
39 |
+output('</table>'); |
|
40 |
+ |
|
41 |
+addnew('edit', 'Neuen FTP-Benutzer anlegen'); |
|
42 |
+ |
... | ... |
@@ -0,0 +1,78 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+include('ftpusers.php'); |
|
4 |
+ |
|
5 |
+require_once('inc/base.php'); |
|
6 |
+ |
|
7 |
+$title="FTP-Benutzer einrichten"; |
|
8 |
+$section='ftpusers_accounts'; |
|
9 |
+ |
|
10 |
+if (isset($_GET['regular_ftp'])) |
|
11 |
+{ |
|
12 |
+ if ($_GET['regular_ftp'] == 'yes') |
|
13 |
+ enable_regular_ftp(); |
|
14 |
+ else |
|
15 |
+ disable_regular_ftp(); |
|
16 |
+ redirect('accounts'); |
|
17 |
+} |
|
18 |
+ |
|
19 |
+ |
|
20 |
+$ftpuser = empty_ftpuser(); |
|
21 |
+ |
|
22 |
+if (isset($_GET['id'])) |
|
23 |
+ $ftpuser = load_ftpuser($_GET['id']); |
|
24 |
+ |
|
25 |
+if ($ftpuser['username']) |
|
26 |
+ output('<h3>Ändern des FTP-Benutzers</h3>'); |
|
27 |
+else |
|
28 |
+ output('<h3>Neuer FTP-Zugang</h3>'); |
|
29 |
+ |
|
30 |
+$username = substr($ftpuser['username'], strlen($_SESSION['userinfo']['username'])+1); |
|
31 |
+ |
|
32 |
+$user_home = $_SESSION['userinfo']['homedir']; |
|
33 |
+$homedir = substr($ftpuser['homedir'], strlen($user_home)+1); |
|
34 |
+DEBUG($user_home.' / '.$homedir.' / '.$ftpuser['homedir']); |
|
35 |
+ |
|
36 |
+$checked = ($ftpuser['active'] == 1 ? 'checked="checked" ' : ''); |
|
37 |
+ |
|
38 |
+$servers = server_names(); |
|
39 |
+$available_servers = array_merge(array(my_server_id()), additional_servers()); |
|
40 |
+ |
|
41 |
+$whichserver = '<strong>'.$servers[my_server_id()].'</strong>'; |
|
42 |
+if (count($available_servers) > 1) |
|
43 |
+{ |
|
44 |
+ $serverselect = array(); |
|
45 |
+ foreach ($available_servers AS $s) |
|
46 |
+ $serverselect[$s] = $servers[$s]; |
|
47 |
+ $whichserver = html_select('server', $serverselect, $ftpuser['server']); |
|
48 |
+} |
|
49 |
+ |
|
50 |
+ |
|
51 |
+ |
|
52 |
+output(html_form('ftpusers_edit', 'save', 'id='.$ftpuser['id'], ' |
|
53 |
+ <table style="margin-bottom: 1em;"> |
|
54 |
+ <tr> |
|
55 |
+ <td>Benutzername:</td> |
|
56 |
+ <td><strong>'.$_SESSION['userinfo']['username'].'-</strong><input type="text" name="ftpusername" id="ftpusername" value="'.$username.'" /></td> |
|
57 |
+ </tr> |
|
58 |
+ <tr> |
|
59 |
+ <td>Verzeichnis:</td> |
|
60 |
+ <td><strong>'.$user_home.'/</strong><input type="text" id="homedir" name="homedir" value="'.$homedir.'" /></td> |
|
61 |
+ </tr> |
|
62 |
+ <tr> |
|
63 |
+ <td>Passwort:</td> |
|
64 |
+ <td><input type="password" id="password" name="password" value="" /></td> |
|
65 |
+ </tr> |
|
66 |
+ <tr> |
|
67 |
+ <td>Zugang aktivieren:</td> |
|
68 |
+ <td><input type="checkbox" id="active" name="active" value="1" '.$checked.'/> auf Server '.$whichserver.'</td> |
|
69 |
+ </tr> |
|
70 |
+ </table> |
|
71 |
+ <p><input type="submit" name="save" value="Speichern" /></p> |
|
72 |
+ ')); |
|
73 |
+ |
|
74 |
+ |
|
75 |
+ |
|
76 |
+ |
|
77 |
+ |
|
78 |
+ |
... | ... |
@@ -0,0 +1,131 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+require_once('inc/base.php'); |
|
4 |
+ |
|
5 |
+function list_ftpusers() |
|
6 |
+{ |
|
7 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
8 |
+ $result = db_query("SELECT id, username, homedir, active FROM system.ftpusers WHERE uid=$uid"); |
|
9 |
+ $ftpusers = array(); |
|
10 |
+ while ($u = mysql_fetch_assoc($result)) { |
|
11 |
+ $ftpusers[] = $u; |
|
12 |
+ } |
|
13 |
+ return $ftpusers; |
|
14 |
+} |
|
15 |
+ |
|
16 |
+function empty_ftpuser() |
|
17 |
+{ |
|
18 |
+ $myserver = my_server_id(); |
|
19 |
+ return array("id" => "0", "username" => "", "password" => "", "homedir" => "", "active" => "1", "server" => $myserver); |
|
20 |
+} |
|
21 |
+ |
|
22 |
+function load_ftpuser($id) |
|
23 |
+{ |
|
24 |
+ if ($id == 0) |
|
25 |
+ return empty_ftpuser(); |
|
26 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
27 |
+ $id = (int) $id; |
|
28 |
+ $result = db_query("SELECT id, username, password, homedir, active, server FROM system.ftpusers WHERE uid={$uid} AND id='{$id}' LIMIT 1"); |
|
29 |
+ if (mysql_num_rows($result) != 1) |
|
30 |
+ system_failure("Fehler beim auslesen des Accounts"); |
|
31 |
+ $account = mysql_fetch_assoc($result); |
|
32 |
+ DEBUG($account); |
|
33 |
+ return $account; |
|
34 |
+} |
|
35 |
+ |
|
36 |
+ |
|
37 |
+function save_ftpuser($data) |
|
38 |
+{ |
|
39 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
40 |
+ $id = (int) $data['id']; |
|
41 |
+ verify_input_username($data['username']); |
|
42 |
+ if ($data['username'] == '') |
|
43 |
+ system_failure('Bitte geben Sie eine Erweiterung für den Benutzernamen an!'); |
|
44 |
+ $username = $_SESSION['userinfo']['username'].'-'.$data['username']; |
|
45 |
+ $homedir = filter_input_general($data['homedir']); |
|
46 |
+ if (substr($homedir, 0, 1) == '/') |
|
47 |
+ $homedir = substr($homedir, 1); |
|
48 |
+ $homedir = $_SESSION['userinfo']['homedir'].'/'.$homedir; |
|
49 |
+ if (! in_homedir($homedir)) |
|
50 |
+ system_failure('Pfad scheint nicht in Ihrem Home zu sein oder enthielt ungültige Zeichen.'); |
|
51 |
+ $active = ($data['active'] == 1 ? '1' : '0'); |
|
52 |
+ |
|
53 |
+ $server = NULL; |
|
54 |
+ if ($data['server'] == my_server_id()) |
|
55 |
+ { |
|
56 |
+ $server = NULL; |
|
57 |
+ } |
|
58 |
+ elseif (in_array($data['server'], additional_servers())) |
|
59 |
+ { |
|
60 |
+ $server = (int) $data['server']; |
|
61 |
+ } |
|
62 |
+ $server = maybe_null($server); |
|
63 |
+ |
|
64 |
+ $password_query = ''; |
|
65 |
+ $password_hash = ''; |
|
66 |
+ if ($data['password'] != '') |
|
67 |
+ { |
|
68 |
+ $salt = random_string(8); |
|
69 |
+ $password_hash = crypt($data['password'], "\$1\${$salt}\$"); |
|
70 |
+ $password_query = "password='{$password_hash}', "; |
|
71 |
+ } |
|
72 |
+ elseif (! $id) |
|
73 |
+ { |
|
74 |
+ system_failure('Wenn Sie einen neuen Zugang anlegen, müssen Sie ein Passwort setzen'); |
|
75 |
+ } |
|
76 |
+ |
|
77 |
+ |
|
78 |
+ if ($id) |
|
79 |
+ db_query("UPDATE system.ftpusers SET username='{$username}', {$password_query} homedir='{$homedir}', active='{$active}', server={$server} WHERE id={$id} AND uid={$uid} LIMIT 1"); |
|
80 |
+ else |
|
81 |
+ db_query("INSERT INTO system.ftpusers (username, password, homedir, uid, active, server) VALUES ('{$username}', '{$password_hash}', '{$homedir}', '{$uid}', '{$active}', {$server})"); |
|
82 |
+} |
|
83 |
+ |
|
84 |
+ |
|
85 |
+function delete_ftpuser($id) |
|
86 |
+{ |
|
87 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
88 |
+ $id = (int) $id; |
|
89 |
+ db_query("DELETE FROM system.ftpusers WHERE id='{$id}' AND uid={$uid} LIMIT 1"); |
|
90 |
+} |
|
91 |
+ |
|
92 |
+ |
|
93 |
+function get_gid($groupname) |
|
94 |
+{ |
|
95 |
+ $groupname = mysql_real_escape_string($groupname); |
|
96 |
+ $result = db_query("SELECT gid FROM system.gruppen WHERE name='{$groupname}' LIMIT 1"); |
|
97 |
+ if (mysql_num_rows($result) != 1) |
|
98 |
+ system_failure('cannot determine gid of ftpusers group'); |
|
99 |
+ $a = mysql_fetch_assoc($result); |
|
100 |
+ $gid = (int) $a['gid']; |
|
101 |
+ if ($gid == 0) |
|
102 |
+ system_failure('error on determining gid of ftpusers group'); |
|
103 |
+ return $gid; |
|
104 |
+} |
|
105 |
+ |
|
106 |
+ |
|
107 |
+function have_regular_ftp() |
|
108 |
+{ |
|
109 |
+ $gid = get_gid('ftpusers'); |
|
110 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
111 |
+ $result = db_query("SELECT * FROM system.gruppenzugehoerigkeit WHERE gid='$gid' AND uid='$uid'"); |
|
112 |
+ return (mysql_num_rows($result) > 0); |
|
113 |
+} |
|
114 |
+ |
|
115 |
+ |
|
116 |
+function enable_regular_ftp() |
|
117 |
+{ |
|
118 |
+ $gid = get_gid('ftpusers'); |
|
119 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
120 |
+ db_query("REPLACE INTO system.gruppenzugehoerigkeit (gid, uid) VALUES ('$gid', '$uid')"); |
|
121 |
+} |
|
122 |
+ |
|
123 |
+function disable_regular_ftp() |
|
124 |
+{ |
|
125 |
+ $gid = get_gid('ftpusers'); |
|
126 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
127 |
+ db_query("DELETE FROM system.gruppenzugehoerigkeit WHERE gid='$gid' AND uid='$uid'"); |
|
128 |
+} |
|
129 |
+ |
|
130 |
+ |
|
131 |
+ |
... | ... |
@@ -0,0 +1,48 @@ |
1 |
+<?php |
|
2 |
+include('ftpusers.php'); |
|
3 |
+ |
|
4 |
+require_role(ROLE_SYSTEMUSER); |
|
5 |
+ |
|
6 |
+if (isset($_GET['delete'])) |
|
7 |
+{ |
|
8 |
+ $ftpuser = load_ftpuser($_GET['delete']); |
|
9 |
+ |
|
10 |
+ $sure = user_is_sure(); |
|
11 |
+ if ($sure === NULL) |
|
12 |
+ { |
|
13 |
+ are_you_sure("delete={$ftpuser['id']}", "Möchten Sie den FTP-Zugang »{$ftpuser['username']}« wirklich löschen?"); |
|
14 |
+ return; |
|
15 |
+ } |
|
16 |
+ elseif ($sure === true) |
|
17 |
+ { |
|
18 |
+ delete_ftpuser($ftpuser['id']); |
|
19 |
+ } |
|
20 |
+ redirect('accounts'); |
|
21 |
+} |
|
22 |
+ |
|
23 |
+$ftpuser = empty_ftpuser(); |
|
24 |
+ |
|
25 |
+if (isset($_GET['id'])) |
|
26 |
+{ |
|
27 |
+ check_form_token('ftpusers_edit'); |
|
28 |
+ $ftpuser = load_ftpuser($_GET['id']); |
|
29 |
+} |
|
30 |
+ |
|
31 |
+ |
|
32 |
+$ftpuser['username'] = $_REQUEST['ftpusername']; |
|
33 |
+$ftpuser['password'] = $_REQUEST['password']; |
|
34 |
+$ftpuser['homedir'] = $_REQUEST['homedir']; |
|
35 |
+if (isset($_REQUEST['active'])) |
|
36 |
+ $ftpuser['active'] = $_REQUEST['active']; |
|
37 |
+else |
|
38 |
+ $ftpuser['active'] = 0; |
|
39 |
+ |
|
40 |
+if (isset($_REQUEST['server'])) |
|
41 |
+ $ftpuser['server'] = $_REQUEST['server']; |
|
42 |
+ |
|
43 |
+ |
|
44 |
+save_ftpuser($ftpuser); |
|
45 |
+ |
|
46 |
+redirect('accounts'); |
|
47 |
+ |
|
48 |
+ |
|
0 | 49 |