... | ... |
@@ -2,14 +2,11 @@ |
2 | 2 |
/* |
3 | 3 |
This file belongs to the Webinterface of schokokeks.org Hosting |
4 | 4 |
|
5 |
-Written 2008-2018 by schokokeks.org Hosting, namely |
|
5 |
+Written by schokokeks.org Hosting, namely |
|
6 | 6 |
Bernd Wurst <bernd@schokokeks.org> |
7 | 7 |
Hanno Böck <hanno@schokokeks.org> |
8 | 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/ |
|
9 |
+This code is published under a 0BSD license. |
|
13 | 10 |
|
14 | 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. |
15 | 12 |
*/ |
... | ... |
@@ -32,7 +32,6 @@ function strong_password($password, $user = array()) |
32 | 32 |
curl_setopt($req, CURLOPT_TIMEOUT, 5); |
33 | 33 |
curl_setopt($req, CURLOPT_FOLLOWLOCATION, 0); |
34 | 34 |
curl_setopt($req, CURLOPT_POST, 1); |
35 |
- curl_setopt($req, CURLOPT_SAFE_UPLOAD, 1); |
|
36 | 35 |
curl_setopt($req, CURLOPT_POSTFIELDS, "password=".urlencode($password)); |
37 | 36 |
$result = chop(curl_exec($req)); |
38 | 37 |
DEBUG($result); |
... | ... |
@@ -33,7 +33,7 @@ function strong_password($password, $user = array()) |
33 | 33 |
curl_setopt($req, CURLOPT_FOLLOWLOCATION, 0); |
34 | 34 |
curl_setopt($req, CURLOPT_POST, 1); |
35 | 35 |
curl_setopt($req, CURLOPT_SAFE_UPLOAD, 1); |
36 |
- curl_setopt($req, CURLOPT_POSTFIELDS, array("password" => $password)); |
|
36 |
+ curl_setopt($req, CURLOPT_POSTFIELDS, "password=".urlencode($password)); |
|
37 | 37 |
$result = chop(curl_exec($req)); |
38 | 38 |
DEBUG($result); |
39 | 39 |
} |
... | ... |
@@ -243,7 +243,7 @@ function filter_ssh_key($key) |
243 | 243 |
system_failure("Ungültiger SSH-Key!"); |
244 | 244 |
} |
245 | 245 |
|
246 |
- if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@.-_]+$/", $keyparts[2]) === 0)) { |
|
246 |
+ if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@._-]+$/", $keyparts[2]) === 0)) { |
|
247 | 247 |
system_failure("Ungültige Zeichen im Kommentar des SSH-Keys!"); |
248 | 248 |
} |
249 | 249 |
|
... | ... |
@@ -45,7 +45,11 @@ function strong_password($password, $user = array()) |
45 | 45 |
// Kein Online-Check eingerichtet oder der request war nicht erfolgreich |
46 | 46 |
DEBUG('using Zxcvbn for password check!'); |
47 | 47 |
$passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
48 |
- $strength = $passwordchecker->passwordStrength($password, $user); |
|
48 |
+ if ($user) { |
|
49 |
+ $strength = $passwordchecker->passwordStrength($password, $user); |
|
50 |
+ } else { |
|
51 |
+ $strength = $passwordchecker->passwordStrength($password); |
|
52 |
+ } |
|
49 | 53 |
DEBUG('password strength: '.$strength['score']); |
50 | 54 |
if ($strength['score'] < 2) { |
51 | 55 |
return "Das Passwort ist zu einfach!"; |
... | ... |
@@ -306,3 +306,24 @@ function check_domain($input) |
306 | 306 |
{ |
307 | 307 |
return (bool) preg_match("/^[a-z0-9\.\-]+\.[a-z\-]{2,63}$/i", $input); |
308 | 308 |
} |
309 |
+ |
|
310 |
+function check_input_types($input, $types) |
|
311 |
+{ |
|
312 |
+ foreach ($types as $key => $type) { |
|
313 |
+ if (!array_key_exists($key, $input)) { |
|
314 |
+ system_failure("Interner Fehler bei Eingabevariablen"); |
|
315 |
+ } |
|
316 |
+ if ($type === 'int') { |
|
317 |
+ if ($input[$key] !== (string)(int)$input[$key]) { |
|
318 |
+ system_failure("Interner Fehler bei Eingabevariablen"); |
|
319 |
+ } |
|
320 |
+ continue; |
|
321 |
+ } elseif ($type === 'string') { |
|
322 |
+ if (!is_string($input[$key])) { |
|
323 |
+ system_failure("Interner Fehler bei Eingabevariablen"); |
|
324 |
+ } |
|
325 |
+ } else { |
|
326 |
+ system_failure("Interner Fehler: Ungültier Typ"); |
|
327 |
+ } |
|
328 |
+ } |
|
329 |
+} |
... | ... |
@@ -111,7 +111,6 @@ function verify_input_identifier($data) |
111 | 111 |
if ($filtered !== $data) { |
112 | 112 |
logger(LOG_WARNING, 'inc/security', 'verify_input_identifier', 'Ungültige Daten: '.$data); |
113 | 113 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
114 |
- |
|
115 | 114 |
} |
116 | 115 |
return $filtered; |
117 | 116 |
} |
... | ... |
@@ -59,6 +59,7 @@ function filter_input_general($input) |
59 | 59 |
if ($input === null) { |
60 | 60 |
return null; |
61 | 61 |
} |
62 |
+ $input = (string) $input; |
|
62 | 63 |
$filtered = preg_replace('/[\x00-\x09\x0b-\x0c\x0e-\x1f]/', '', $input); |
63 | 64 |
if ($filtered !== $input) { |
64 | 65 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
... | ... |
@@ -72,10 +73,11 @@ function filter_input_oneline($input) |
72 | 73 |
if ($input === null) { |
73 | 74 |
return null; |
74 | 75 |
} |
76 |
+ $input = (string) $input; |
|
75 | 77 |
$filtered = preg_replace('/[\x00-\x1f]/', '', $input); |
76 | 78 |
if ($filtered !== $input) { |
77 | 79 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
78 |
- logger(LOG_WARNING, 'inc/security', 'filter_input_general', 'Ungültige Daten!'); |
|
80 |
+ logger(LOG_WARNING, 'inc/security', 'filter_input_oneline', 'Ungültige Daten!'); |
|
79 | 81 |
} |
80 | 82 |
return $filtered; |
81 | 83 |
} |
... | ... |
@@ -89,6 +91,7 @@ function filter_output_html($data) |
89 | 91 |
|
90 | 92 |
function verify_input_ascii($data) |
91 | 93 |
{ |
94 |
+ $data = (string) $data; |
|
92 | 95 |
$filtered = filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); |
93 | 96 |
if ($filtered != $data) { |
94 | 97 |
logger(LOG_WARNING, 'inc/security', 'verify_input_ascii', 'Ungültige Daten: '.$data); |
... | ... |
@@ -100,6 +103,7 @@ function verify_input_ascii($data) |
100 | 103 |
|
101 | 104 |
function verify_input_identifier($data) |
102 | 105 |
{ |
106 |
+ $data = (string) $data; |
|
103 | 107 |
if ($data === "") { |
104 | 108 |
system_failure("Leerer Bezeichner"); |
105 | 109 |
} |
... | ... |
@@ -59,18 +59,25 @@ function filter_input_general($input) |
59 | 59 |
if ($input === null) { |
60 | 60 |
return null; |
61 | 61 |
} |
62 |
- return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8'); |
|
62 |
+ $filtered = preg_replace('/[\x00-\x09\x0b-\x0c\x0e-\x1f]/', '', $input); |
|
63 |
+ if ($filtered !== $input) { |
|
64 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
65 |
+ logger(LOG_WARNING, 'inc/security', 'filter_input_general', 'Ungültige Daten!'); |
|
66 |
+ } |
|
67 |
+ return $filtered; |
|
63 | 68 |
} |
64 | 69 |
|
65 |
- |
|
66 |
-function verify_input_general($input) |
|
70 |
+function filter_input_oneline($input) |
|
67 | 71 |
{ |
68 |
- if (filter_input_general($input) !== $input) { |
|
72 |
+ if ($input === null) { |
|
73 |
+ return null; |
|
74 |
+ } |
|
75 |
+ $filtered = preg_replace('/[\x00-\x1f]/', '', $input); |
|
76 |
+ if ($filtered !== $input) { |
|
69 | 77 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
70 |
- logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input); |
|
71 |
- } else { |
|
72 |
- return $input; |
|
78 |
+ logger(LOG_WARNING, 'inc/security', 'filter_input_general', 'Ungültige Daten!'); |
|
73 | 79 |
} |
80 |
+ return $filtered; |
|
74 | 81 |
} |
75 | 82 |
|
76 | 83 |
|
... | ... |
@@ -80,10 +87,35 @@ function filter_output_html($data) |
80 | 87 |
} |
81 | 88 |
|
82 | 89 |
|
90 |
+function verify_input_ascii($data) |
|
91 |
+{ |
|
92 |
+ $filtered = filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); |
|
93 |
+ if ($filtered != $data) { |
|
94 |
+ logger(LOG_WARNING, 'inc/security', 'verify_input_ascii', 'Ungültige Daten: '.$data); |
|
95 |
+ system_failure("Ihre Eingabe enthielt ungültige Zeichen"); |
|
96 |
+ } |
|
97 |
+ return $filtered; |
|
98 |
+} |
|
99 |
+ |
|
100 |
+ |
|
101 |
+function verify_input_identifier($data) |
|
102 |
+{ |
|
103 |
+ if ($data === "") { |
|
104 |
+ system_failure("Leerer Bezeichner"); |
|
105 |
+ } |
|
106 |
+ $filtered = preg_replace("/[^[:alnum:]\_\.\-]/", "", $data); |
|
107 |
+ if ($filtered !== $data) { |
|
108 |
+ logger(LOG_WARNING, 'inc/security', 'verify_input_identifier', 'Ungültige Daten: '.$data); |
|
109 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
110 |
+ |
|
111 |
+ } |
|
112 |
+ return $filtered; |
|
113 |
+} |
|
114 |
+ |
|
83 | 115 |
|
84 | 116 |
function filter_input_username($input) |
85 | 117 |
{ |
86 |
- $username=preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
|
118 |
+ $username = preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
|
87 | 119 |
if ($username === "") { |
88 | 120 |
system_failure("Leerer Benutzername!"); |
89 | 121 |
} |
... | ... |
@@ -102,12 +134,9 @@ function verify_input_username($input) |
102 | 134 |
|
103 | 135 |
function filter_input_hostname($input, $wildcard=false) |
104 | 136 |
{ |
105 |
- // FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern. |
|
106 |
- |
|
107 | 137 |
DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')'); |
108 | 138 |
$input = strtolower($input); |
109 |
- $input = rtrim($input, "\t\n\r\x00 ."); |
|
110 |
- $input = ltrim($input, "\t\n\r\x00 ."); |
|
139 |
+ $input = trim($input, "\t\n\r\x00 ."); |
|
111 | 140 |
if (preg_replace("/[^.]_/", "", $input) != $input) { |
112 | 141 |
system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt."); |
113 | 142 |
} |
... | ... |
@@ -142,7 +171,7 @@ function verify_input_hostname_utf8($input) |
142 | 171 |
system_failure("Ungültiger Hostname! idn ".$input); |
143 | 172 |
} |
144 | 173 |
$filter = filter_var($puny, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME); |
145 |
- if ($filter === false) { |
|
174 |
+ if ($filter !== $puny) { |
|
146 | 175 |
system_failure("Ungültiger Hostname! filter ".$input); |
147 | 176 |
} |
148 | 177 |
} |
... | ... |
@@ -74,6 +74,13 @@ function verify_input_general($input) |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
|
77 |
+function filter_output_html($data) |
|
78 |
+{ |
|
79 |
+ return htmlspecialchars($data, ENT_QUOTES); |
|
80 |
+} |
|
81 |
+ |
|
82 |
+ |
|
83 |
+ |
|
77 | 84 |
function filter_input_username($input) |
78 | 85 |
{ |
79 | 86 |
$username=preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
... | ... |
@@ -215,7 +222,7 @@ function filter_ssh_key($key) |
215 | 222 |
function check_path($input) |
216 | 223 |
{ |
217 | 224 |
DEBUG("checking {$input} for valid path name"); |
218 |
- if ($input != filter_input_general($input)) { |
|
225 |
+ if ($input != filter_output_html($input)) { |
|
219 | 226 |
logger(LOG_WARNING, 'inc/security', 'check_path', 'HTML-Krams im Pfad: '.$input); |
220 | 227 |
DEBUG("HTML-Krams im Pfad"); |
221 | 228 |
return false; |
... | ... |
@@ -40,7 +40,7 @@ function strong_password($password, $user = array()) |
40 | 40 |
if ($result === 'good') { |
41 | 41 |
return true; |
42 | 42 |
} elseif ($result === 'bad') { |
43 |
- return "Das ist kein gutes Passwort!"; |
|
43 |
+ return "Unsere Überprüfung hat ergeben, dass dieses Passwort in bisher veröffentlichten Passwortlisten enthalten ist. Es wird daher nicht akzeptiert."; |
|
44 | 44 |
} |
45 | 45 |
// Kein Online-Check eingerichtet oder der request war nicht erfolgreich |
46 | 46 |
DEBUG('using Zxcvbn for password check!'); |
... | ... |
@@ -50,7 +50,6 @@ function strong_password($password, $user = array()) |
50 | 50 |
if ($strength['score'] < 2) { |
51 | 51 |
return "Das Passwort ist zu einfach!"; |
52 | 52 |
} |
53 |
- |
|
54 | 53 |
return true; |
55 | 54 |
} |
56 | 55 |
|
... | ... |
@@ -24,13 +24,16 @@ function strong_password($password, $user = array()) |
24 | 24 |
$result = null; |
25 | 25 |
if ($pwcheck) { |
26 | 26 |
DEBUG($pwcheck); |
27 |
- $req = curl_init($pwcheck.$password); |
|
27 |
+ $req = curl_init($pwcheck); |
|
28 | 28 |
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1); |
29 | 29 |
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, 1); |
30 | 30 |
curl_setopt($req, CURLOPT_SSL_VERIFYSTATUS, 1); |
31 | 31 |
curl_setopt($req, CURLOPT_CONNECTTIMEOUT, 5); |
32 | 32 |
curl_setopt($req, CURLOPT_TIMEOUT, 5); |
33 | 33 |
curl_setopt($req, CURLOPT_FOLLOWLOCATION, 0); |
34 |
+ curl_setopt($req, CURLOPT_POST, 1); |
|
35 |
+ curl_setopt($req, CURLOPT_SAFE_UPLOAD, 1); |
|
36 |
+ curl_setopt($req, CURLOPT_POSTFIELDS, array("password" => $password)); |
|
34 | 37 |
$result = chop(curl_exec($req)); |
35 | 38 |
DEBUG($result); |
36 | 39 |
} |
... | ... |
@@ -39,14 +39,13 @@ function strong_password($password, $user = array()) |
39 | 39 |
} elseif ($result === 'bad') { |
40 | 40 |
return "Das ist kein gutes Passwort!"; |
41 | 41 |
} |
42 |
- if ($result === null || $result === false) { |
|
43 |
- // Kein Online-Check eingerichtet oder der request war nicht erfolgreich |
|
44 |
- $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
45 |
- $strength = $passwordchecker->passwordStrength($password, $user); |
|
46 |
- |
|
47 |
- if ($strength['score'] < 2) { |
|
48 |
- return "Das Passwort ist zu einfach!"; |
|
49 |
- } |
|
42 |
+ // Kein Online-Check eingerichtet oder der request war nicht erfolgreich |
|
43 |
+ DEBUG('using Zxcvbn for password check!'); |
|
44 |
+ $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
45 |
+ $strength = $passwordchecker->passwordStrength($password, $user); |
|
46 |
+ DEBUG('password strength: '.$strength['score']); |
|
47 |
+ if ($strength['score'] < 2) { |
|
48 |
+ return "Das Passwort ist zu einfach!"; |
|
50 | 49 |
} |
51 | 50 |
|
52 | 51 |
return true; |
... | ... |
@@ -20,11 +20,33 @@ require_once('vendor/autoload.php'); |
20 | 20 |
|
21 | 21 |
function strong_password($password, $user = array()) |
22 | 22 |
{ |
23 |
- $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
24 |
- $strength = $passwordchecker->passwordStrength($password, $user); |
|
25 |
- |
|
26 |
- if ($strength['score'] < 2) { |
|
27 |
- return "Das Passwort ist zu einfach!"; |
|
23 |
+ $pwcheck = config('pwcheck'); |
|
24 |
+ $result = null; |
|
25 |
+ if ($pwcheck) { |
|
26 |
+ DEBUG($pwcheck); |
|
27 |
+ $req = curl_init($pwcheck.$password); |
|
28 |
+ curl_setopt($req, CURLOPT_RETURNTRANSFER, 1); |
|
29 |
+ curl_setopt($req, CURLOPT_SSL_VERIFYPEER, 1); |
|
30 |
+ curl_setopt($req, CURLOPT_SSL_VERIFYSTATUS, 1); |
|
31 |
+ curl_setopt($req, CURLOPT_CONNECTTIMEOUT, 5); |
|
32 |
+ curl_setopt($req, CURLOPT_TIMEOUT, 5); |
|
33 |
+ curl_setopt($req, CURLOPT_FOLLOWLOCATION, 0); |
|
34 |
+ $result = chop(curl_exec($req)); |
|
35 |
+ DEBUG($result); |
|
36 |
+ } |
|
37 |
+ if ($result === 'good') { |
|
38 |
+ return true; |
|
39 |
+ } elseif ($result === 'bad') { |
|
40 |
+ return "Das ist kein gutes Passwort!"; |
|
41 |
+ } |
|
42 |
+ if ($result === null || $result === false) { |
|
43 |
+ // Kein Online-Check eingerichtet oder der request war nicht erfolgreich |
|
44 |
+ $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
45 |
+ $strength = $passwordchecker->passwordStrength($password, $user); |
|
46 |
+ |
|
47 |
+ if ($strength['score'] < 2) { |
|
48 |
+ return "Das Passwort ist zu einfach!"; |
|
49 |
+ } |
|
28 | 50 |
} |
29 | 51 |
|
30 | 52 |
return true; |
... | ... |
@@ -204,6 +204,12 @@ function check_path($input) |
204 | 204 |
DEBUG("»..« im Pfad"); |
205 | 205 |
return false; |
206 | 206 |
} |
207 |
+ if (strlen($item) > 255) { |
|
208 |
+ return false; |
|
209 |
+ } |
|
210 |
+ } |
|
211 |
+ if (strlen($input) > 2048) { |
|
212 |
+ return false; |
|
207 | 213 |
} |
208 | 214 |
return (preg_match('/^[ A-Za-z0-9.@\/_-]*$/', $input) == 1); |
209 | 215 |
} |
... | ... |
@@ -105,6 +105,19 @@ function verify_input_hostname($input, $wildcard=false) |
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
|
108 |
+function verify_input_hostname_utf8($input) |
|
109 |
+{ |
|
110 |
+ $puny = idn_to_ascii($input, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
|
111 |
+ if ($puny === false) { |
|
112 |
+ system_failure("Ungültiger Hostname! idn ".$input); |
|
113 |
+ } |
|
114 |
+ $filter = filter_var($puny, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME); |
|
115 |
+ if ($filter === false) { |
|
116 |
+ system_failure("Ungültiger Hostname! filter ".$input); |
|
117 |
+ } |
|
118 |
+} |
|
119 |
+ |
|
120 |
+ |
|
108 | 121 |
function verify_input_ipv4($input) |
109 | 122 |
{ |
110 | 123 |
if (! preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $input)) { |
... | ... |
@@ -75,13 +75,13 @@ function filter_input_hostname($input, $wildcard=false) |
75 | 75 |
// FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern. |
76 | 76 |
|
77 | 77 |
DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')'); |
78 |
- $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input)); |
|
78 |
+ $input = strtolower($input); |
|
79 | 79 |
$input = rtrim($input, "\t\n\r\x00 ."); |
80 | 80 |
$input = ltrim($input, "\t\n\r\x00 ."); |
81 | 81 |
if (preg_replace("/[^.]_/", "", $input) != $input) { |
82 | 82 |
system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt."); |
83 | 83 |
} |
84 |
- if (preg_replace("/[^[:alnum:]äöü_*\.\-]/", "", $input) != $input) { |
|
84 |
+ if (preg_replace("/[^[:alnum:]_*\.\-]/u", "", $input) != $input) { |
|
85 | 85 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
86 | 86 |
} |
87 | 87 |
if (preg_match("/^.+\*/", $input)) { |
... | ... |
@@ -207,7 +207,7 @@ function in_homedir($path) |
207 | 207 |
DEBUG("Kann homedir nicht ermitteln"); |
208 | 208 |
return false; |
209 | 209 |
} |
210 |
- return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0; |
|
210 |
+ return strncmp($_SESSION['userinfo']['homedir'], $path, strlen($_SESSION['userinfo']['homedir'])) == 0; |
|
211 | 211 |
} |
212 | 212 |
|
213 | 213 |
function check_date($input) |
... | ... |
@@ -73,7 +73,7 @@ function verify_input_username($input) |
73 | 73 |
function filter_input_hostname($input, $wildcard=false) |
74 | 74 |
{ |
75 | 75 |
// FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern. |
76 |
- |
|
76 |
+ |
|
77 | 77 |
DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')'); |
78 | 78 |
$input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input)); |
79 | 79 |
$input = rtrim($input, "\t\n\r\x00 ."); |
... | ... |
@@ -8,7 +8,7 @@ Written 2008-2018 by schokokeks.org Hosting, namely |
8 | 8 |
|
9 | 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 | 10 |
|
11 |
-You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see |
|
11 |
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see |
|
12 | 12 |
http://creativecommons.org/publicdomain/zero/1.0/ |
13 | 13 |
|
14 | 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. |
... | ... |
@@ -20,205 +20,208 @@ require_once('vendor/autoload.php'); |
20 | 20 |
|
21 | 21 |
function strong_password($password, $user = array()) |
22 | 22 |
{ |
23 |
- $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
24 |
- $strength = $passwordchecker->passwordStrength($password, $user); |
|
23 |
+ $passwordchecker = new ZxcvbnPhp\Zxcvbn(); |
|
24 |
+ $strength = $passwordchecker->passwordStrength($password, $user); |
|
25 | 25 |
|
26 |
- if ($strength['score'] < 2) { |
|
27 |
- return "Das Passwort ist zu einfach!"; |
|
28 |
- } |
|
26 |
+ if ($strength['score'] < 2) { |
|
27 |
+ return "Das Passwort ist zu einfach!"; |
|
28 |
+ } |
|
29 | 29 |
|
30 |
- return true; |
|
30 |
+ return true; |
|
31 | 31 |
} |
32 | 32 |
|
33 | 33 |
|
34 |
-function filter_input_general( $input ) |
|
34 |
+function filter_input_general($input) |
|
35 | 35 |
{ |
36 |
- if ($input === NULL) { |
|
37 |
- return NULL; |
|
38 |
- } |
|
39 |
- return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8'); |
|
36 |
+ if ($input === null) { |
|
37 |
+ return null; |
|
38 |
+ } |
|
39 |
+ return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8'); |
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
|
43 |
-function verify_input_general( $input ) |
|
43 |
+function verify_input_general($input) |
|
44 | 44 |
{ |
45 |
- if (filter_input_general($input) !== $input) { |
|
46 |
- system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
47 |
- logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input); |
|
48 |
- } else { |
|
49 |
- return $input; |
|
50 |
- } |
|
45 |
+ if (filter_input_general($input) !== $input) { |
|
46 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
47 |
+ logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input); |
|
48 |
+ } else { |
|
49 |
+ return $input; |
|
50 |
+ } |
|
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
|
54 |
-function filter_input_username( $input ) |
|
54 |
+function filter_input_username($input) |
|
55 | 55 |
{ |
56 |
- $username=preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
|
57 |
- if ($username === "") { |
|
58 |
- system_failure("Leerer Benutzername!"); |
|
59 |
- } |
|
60 |
- return $username; |
|
56 |
+ $username=preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
|
57 |
+ if ($username === "") { |
|
58 |
+ system_failure("Leerer Benutzername!"); |
|
59 |
+ } |
|
60 |
+ return $username; |
|
61 | 61 |
} |
62 | 62 |
|
63 |
-function verify_input_username( $input ) |
|
63 |
+function verify_input_username($input) |
|
64 | 64 |
{ |
65 |
- if (filter_input_username( $input ) != $input) { |
|
66 |
- logger(LOG_WARNING, 'inc/security', 'verify_input_username', 'Ungültige Daten: '.$input); |
|
67 |
- system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
68 |
- } |
|
65 |
+ if (filter_input_username($input) != $input) { |
|
66 |
+ logger(LOG_WARNING, 'inc/security', 'verify_input_username', 'Ungültige Daten: '.$input); |
|
67 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
68 |
+ } |
|
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
|
72 | 72 |
|
73 |
-function filter_input_hostname( $input, $wildcard=false ) |
|
73 |
+function filter_input_hostname($input, $wildcard=false) |
|
74 | 74 |
{ |
75 |
- // FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern. |
|
75 |
+ // FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern. |
|
76 | 76 |
|
77 |
- DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')'); |
|
78 |
- $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input)); |
|
79 |
- $input = rtrim($input, "\t\n\r\x00 ."); |
|
80 |
- $input = ltrim($input, "\t\n\r\x00 ."); |
|
81 |
- if (preg_replace("/[^.]_/", "", $input) != $input) { |
|
82 |
- system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt."); |
|
83 |
- } |
|
84 |
- if (preg_replace("/[^[:alnum:]äöü_*\.\-]/", "", $input ) != $input) |
|
85 |
- system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
86 |
- if (preg_match("/^.+\*/", $input )) |
|
87 |
- system_failure("Ihre Daten enthielten ungültige Zeichen (Wildcard-Stern muss ganz vorne stehen)!"); |
|
88 |
- if (! $wildcard && preg_replace("/^\*/", "", $input ) != $input) |
|
89 |
- system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!"); |
|
90 |
- if (strstr($input, '..')) |
|
91 |
- system_failure("Ungültiger Hostname"); |
|
92 |
- return $input; |
|
77 |
+ DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')'); |
|
78 |
+ $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input)); |
|
79 |
+ $input = rtrim($input, "\t\n\r\x00 ."); |
|
80 |
+ $input = ltrim($input, "\t\n\r\x00 ."); |
|
81 |
+ if (preg_replace("/[^.]_/", "", $input) != $input) { |
|
82 |
+ system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt."); |
|
83 |
+ } |
|
84 |
+ if (preg_replace("/[^[:alnum:]äöü_*\.\-]/", "", $input) != $input) { |
|
85 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
86 |
+ } |
|
87 |
+ if (preg_match("/^.+\*/", $input)) { |
|
88 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen (Wildcard-Stern muss ganz vorne stehen)!"); |
|
89 |
+ } |
|
90 |
+ if (! $wildcard && preg_replace("/^\*/", "", $input) != $input) { |
|
91 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!"); |
|
92 |
+ } |
|
93 |
+ if (strstr($input, '..')) { |
|
94 |
+ system_failure("Ungültiger Hostname"); |
|
95 |
+ } |
|
96 |
+ return $input; |
|
93 | 97 |
} |
94 | 98 |
|
95 |
-function verify_input_hostname( $input, $wildcard=false ) |
|
99 |
+function verify_input_hostname($input, $wildcard=false) |
|
96 | 100 |
{ |
97 |
- if (filter_input_hostname( $input, $wildcard ) != $input) { |
|
98 |
- logger(LOG_WARNING, 'inc/security', 'verify_input_hostname', 'Ungültige Daten: '.$input); |
|
99 |
- system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
100 |
- } |
|
101 |
+ if (filter_input_hostname($input, $wildcard) != $input) { |
|
102 |
+ logger(LOG_WARNING, 'inc/security', 'verify_input_hostname', 'Ungültige Daten: '.$input); |
|
103 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
104 |
+ } |
|
101 | 105 |
} |
102 | 106 |
|
103 | 107 |
|
104 |
-function verify_input_ipv4( $input ) |
|
108 |
+function verify_input_ipv4($input) |
|
105 | 109 |
{ |
106 |
- if (! preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $input)) |
|
107 |
- system_failure('Keine IP-Adresse'); |
|
110 |
+ if (! preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $input)) { |
|
111 |
+ system_failure('Keine IP-Adresse'); |
|
112 |
+ } |
|
108 | 113 |
} |
109 | 114 |
|
110 | 115 |
|
111 |
-function verify_input_ipv6( $input ) |
|
116 |
+function verify_input_ipv6($input) |
|
112 | 117 |
{ |
113 |
- // ripped from Perl module Net-IPv6Addr v0.2 |
|
114 |
- if (! preg_match("/^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|[0-9a-f]{0,4}::|:(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){1,6}:|(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}|(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}|(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}|(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}|(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4}))$/i", $input)) |
|
115 |
- system_failure("Ungültige IPv6-Adresse"); |
|
118 |
+ // ripped from Perl module Net-IPv6Addr v0.2 |
|
119 |
+ if (! preg_match("/^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|[0-9a-f]{0,4}::|:(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){1,6}:|(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}|(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}|(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}|(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}|(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4}))$/i", $input)) { |
|
120 |
+ system_failure("Ungültige IPv6-Adresse"); |
|
121 |
+ } |
|
116 | 122 |
} |
117 | 123 |
|
118 |
-function verify_input_recorddata( $input ) |
|
124 |
+function verify_input_recorddata($input) |
|
119 | 125 |
{ |
120 |
- if (strstr($input, "\\") || strstr($input, '"')) |
|
121 |
- system_failure("Ungültige Zeichen"); |
|
126 |
+ if (strstr($input, "\\") || strstr($input, '"')) { |
|
127 |
+ system_failure("Ungültige Zeichen"); |
|
128 |
+ } |
|
122 | 129 |
} |
123 | 130 |
|
124 |
-function filter_quotes( $input ) |
|
131 |
+function filter_quotes($input) |
|
125 | 132 |
{ |
126 |
- return preg_replace('/["\'`]/', '', $input ); |
|
133 |
+ return preg_replace('/["\'`]/', '', $input); |
|
127 | 134 |
} |
128 | 135 |
|
129 | 136 |
|
130 | 137 |
|
131 |
-function filter_shell( $input ) |
|
138 |
+function filter_shell($input) |
|
132 | 139 |
{ |
133 |
- return preg_replace('/[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]/', '', $input ); |
|
140 |
+ return preg_replace('/[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]/', '', $input); |
|
134 | 141 |
} |
135 | 142 |
|
136 |
-function verify_shell( $input ) |
|
143 |
+function verify_shell($input) |
|
137 | 144 |
{ |
138 |
- if (filter_shell($input) != $input) |
|
139 |
- system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
145 |
+ if (filter_shell($input) != $input) { |
|
146 |
+ system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
|
147 |
+ } |
|
140 | 148 |
} |
141 | 149 |
|
142 | 150 |
|
143 | 151 |
function filter_ssh_key($key) |
144 | 152 |
{ |
145 |
- $keyparts = explode(" ", trim($key)); |
|
153 |
+ $keyparts = explode(" ", trim($key)); |
|
146 | 154 |
|
147 |
- if ((count($keyparts) > 3) || (count($keyparts) < 2)) { |
|
148 |
- system_failure("Ungültiger SSH-Key!"); |
|
149 |
- } |
|
155 |
+ if ((count($keyparts) > 3) || (count($keyparts) < 2)) { |
|
156 |
+ system_failure("Ungültiger SSH-Key!"); |
|
157 |
+ } |
|
150 | 158 |
|
151 |
- if (preg_match("/^[a-z0-9]+-[a-z0-9-]+$/", $keyparts[0]) === 0) { |
|
152 |
- system_failure("Ungültiger SSH-Key!"); |
|
153 |
- } |
|
159 |
+ if (preg_match("/^[a-z0-9]+-[a-z0-9-]+$/", $keyparts[0]) === 0) { |
|
160 |
+ system_failure("Ungültiger SSH-Key!"); |
|
161 |
+ } |
|
154 | 162 |
|
155 |
- if (base64_decode($keyparts[1], 1) == false) { |
|
156 |
- system_failure("Ungültiger SSH-Key!"); |
|
157 |
- } |
|
163 |
+ if (base64_decode($keyparts[1], 1) == false) { |
|
164 |
+ system_failure("Ungültiger SSH-Key!"); |
|
165 |
+ } |
|
158 | 166 |
|
159 |
- if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@.-_]+$/", $keyparts[2]) === 0)) { |
|
160 |
- system_failure("Ungültige Zeichen im Kommentar des SSH-Keys!"); |
|
161 |
- } |
|
167 |
+ if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@.-_]+$/", $keyparts[2]) === 0)) { |
|
168 |
+ system_failure("Ungültige Zeichen im Kommentar des SSH-Keys!"); |
|
169 |
+ } |
|
162 | 170 |
|
163 |
- if (count($keyparts) === 2) { |
|
164 |
- return $keyparts[0]." ".$keyparts[1]; |
|
165 |
- } else { |
|
166 |
- return $keyparts[0]." ".$keyparts[1]." ".$keyparts[2]; |
|
167 |
- } |
|
171 |
+ if (count($keyparts) === 2) { |
|
172 |
+ return $keyparts[0]." ".$keyparts[1]; |
|
173 |
+ } else { |
|
174 |
+ return $keyparts[0]." ".$keyparts[1]." ".$keyparts[2]; |
|
175 |
+ } |
|
168 | 176 |
} |
169 | 177 |
|
170 | 178 |
|
171 |
-function check_path( $input ) |
|
179 |
+function check_path($input) |
|
172 | 180 |
{ |
173 |
- DEBUG("checking {$input} for valid path name"); |
|
174 |
- if ($input != filter_input_general($input)) |
|
175 |
- { |
|
176 |
- logger(LOG_WARNING, 'inc/security', 'check_path', 'HTML-Krams im Pfad: '.$input); |
|
177 |
- DEBUG("HTML-Krams im Pfad"); |
|
178 |
- return False; |
|
179 |
- } |
|
180 |
- $components = explode("/", $input); |
|
181 |
- foreach ($components AS $item) |
|
182 |
- { |
|
183 |
- if ($item == '..') |
|
184 |
- { |
|
185 |
- logger(LOG_WARNING, 'inc/security', 'check_path', '»..« im Pfad: '.$input); |
|
186 |
- DEBUG("»..« im Pfad"); |
|
187 |
- return False; |
|
181 |
+ DEBUG("checking {$input} for valid path name"); |
|
182 |
+ if ($input != filter_input_general($input)) { |
|
183 |
+ logger(LOG_WARNING, 'inc/security', 'check_path', 'HTML-Krams im Pfad: '.$input); |
|
184 |
+ DEBUG("HTML-Krams im Pfad"); |
|
185 |
+ return false; |
|
186 |
+ } |
|
187 |
+ $components = explode("/", $input); |
|
188 |
+ foreach ($components as $item) { |
|
189 |
+ if ($item == '..') { |
|
190 |
+ logger(LOG_WARNING, 'inc/security', 'check_path', '»..« im Pfad: '.$input); |
|
191 |
+ DEBUG("»..« im Pfad"); |
|
192 |
+ return false; |
|
193 |
+ } |
|
188 | 194 |
} |
189 |
- } |
|
190 |
- return (preg_match('/^[ A-Za-z0-9.@\/_-]*$/',$input) == 1); |
|
195 |
+ return (preg_match('/^[ A-Za-z0-9.@\/_-]*$/', $input) == 1); |
|
191 | 196 |
} |
192 | 197 |
|
193 | 198 |
|
194 | 199 |
function in_homedir($path) |
195 | 200 |
{ |
196 |
- DEBUG("Prüfe »{$path}«"); |
|
197 |
- if (! check_path($path)) |
|
198 |
- { |
|
199 |
- DEBUG('Kein Pfad'); |
|
200 |
- return False; |
|
201 |
- } |
|
202 |
- if (! isset($_SESSION['userinfo']['homedir'])) |
|
203 |
- { |
|
204 |
- DEBUG("Kann homedir nicht ermitteln"); |
|
205 |
- return False; |
|
206 |
- } |
|
207 |
- return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0; |
|
201 |
+ DEBUG("Prüfe »{$path}«"); |
|
202 |
+ if (! check_path($path)) { |
|
203 |
+ DEBUG('Kein Pfad'); |
|
204 |
+ return false; |
|
205 |
+ } |
|
206 |
+ if (! isset($_SESSION['userinfo']['homedir'])) { |
|
207 |
+ DEBUG("Kann homedir nicht ermitteln"); |
|
208 |
+ return false; |
|
209 |
+ } |
|
210 |
+ return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0; |
|
208 | 211 |
} |
209 | 212 |
|
210 |
-function check_date( $input ) |
|
213 |
+function check_date($input) |
|
211 | 214 |
{ |
212 |
- return (bool) preg_match("/[0-9]{4}-(0?[1-9]|10|11|12)-([012]?[0-9]|30|31)/", $input); |
|
215 |
+ return (bool) preg_match("/[0-9]{4}-(0?[1-9]|10|11|12)-([012]?[0-9]|30|31)/", $input); |
|
213 | 216 |
} |
214 | 217 |
|
215 | 218 |
|
216 |
-function check_emailaddr( $input ) |
|
219 |
+function check_emailaddr($input) |
|
217 | 220 |
{ |
218 |
- return (bool) filter_var($input, FILTER_VALIDATE_EMAIL) == $input; |
|
221 |
+ return (bool) filter_var($input, FILTER_VALIDATE_EMAIL) == $input; |
|
219 | 222 |
} |
220 | 223 |
|
221 |
-function check_domain( $input ) |
|
224 |
+function check_domain($input) |
|
222 | 225 |
{ |
223 |
- return (bool) preg_match("/^[a-z0-9\.\-]+\.[a-z\-]{2,63}$/i", $input ); |
|
226 |
+ return (bool) preg_match("/^[a-z0-9\.\-]+\.[a-z\-]{2,63}$/i", $input); |
|
224 | 227 |
} |
... | ... |
@@ -42,9 +42,11 @@ function filter_input_general( $input ) |
42 | 42 |
|
43 | 43 |
function verify_input_general( $input ) |
44 | 44 |
{ |
45 |
- if (filter_input_general($input) != $input) { |
|
45 |
+ if (filter_input_general($input) !== $input) { |
|
46 | 46 |
system_failure("Ihre Daten enthielten ungültige Zeichen!"); |
47 | 47 |
logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input); |
48 |
+ } else { |
|
49 |
+ return $input; |
|
48 | 50 |
} |
49 | 51 |
} |
50 | 52 |
|
... | ... |
@@ -154,8 +154,8 @@ function filter_ssh_key($key) |
154 | 154 |
system_failure("Ungültiger SSH-Key!"); |
155 | 155 |
} |
156 | 156 |
|
157 |
- if ((count($keyparts) === 3) && (preg_match("/^[a-z0-9@]+$/", $keyparts[2]) === 0)) { |
|
158 |
- system_failure("Ungültiger SSH-Key!"); |
|
157 |
+ if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@.-_]+$/", $keyparts[2]) === 0)) { |
|
158 |
+ system_failure("Ungültige Zeichen im Kommentar des SSH-Keys!"); |
|
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
if (count($keyparts) === 2) { |
... | ... |
@@ -51,7 +51,11 @@ function verify_input_general( $input ) |
51 | 51 |
|
52 | 52 |
function filter_input_username( $input ) |
53 | 53 |
{ |
54 |
- return preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input ); |
|
54 |
+ $username=preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input); |
|
55 |
+ if ($username === "") { |
|
56 |
+ system_failure("Leerer Benutzername!"); |
|
57 |
+ } |
|
58 |
+ return $username; |
|
55 | 59 |
} |
56 | 60 |
|
57 | 61 |
function verify_input_username( $input ) |
... | ... |
@@ -134,6 +134,33 @@ function verify_shell( $input ) |
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
|
137 |
+function filter_ssh_key($key) |
|
138 |
+{ |
|
139 |
+ $keyparts = explode(" ", trim($key)); |
|
140 |
+ |
|
141 |
+ if ((count($keyparts) > 3) || (count($keyparts) < 2)) { |
|
142 |
+ system_failure("Ungültiger SSH-Key!"); |
|
143 |
+ } |
|
144 |
+ |
|
145 |
+ if (preg_match("/^[a-z0-9]+-[a-z0-9-]+$/", $keyparts[0]) === 0) { |
|
146 |
+ system_failure("Ungültiger SSH-Key!"); |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ if (base64_decode($keyparts[1], 1) == false) { |
|
150 |
+ system_failure("Ungültiger SSH-Key!"); |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ if ((count($keyparts) === 3) && (preg_match("/^[a-z0-9@]+$/", $keyparts[2]) === 0)) { |
|
154 |
+ system_failure("Ungültiger SSH-Key!"); |
|
155 |
+ } |
|
156 |
+ |
|
157 |
+ if (count($keyparts) === 2) { |
|
158 |
+ return $keyparts[0]." ".$keyparts[1]; |
|
159 |
+ } else { |
|
160 |
+ return $keyparts[0]." ".$keyparts[1]." ".$keyparts[2]; |
|
161 |
+ } |
|
162 |
+} |
|
163 |
+ |
|
137 | 164 |
|
138 | 165 |
function check_path( $input ) |
139 | 166 |
{ |
... | ... |
@@ -109,6 +109,11 @@ function verify_input_ipv6( $input ) |
109 | 109 |
system_failure("Ungültige IPv6-Adresse"); |
110 | 110 |
} |
111 | 111 |
|
112 |
+function verify_input_recorddata( $input ) |
|
113 |
+{ |
|
114 |
+ if (strstr($input, "\\") || strstr($input, '"')) |
|
115 |
+ system_failure("Ungültige Zeichen"); |
|
116 |
+} |
|
112 | 117 |
|
113 | 118 |
function filter_quotes( $input ) |
114 | 119 |
{ |