-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFirewall.php
More file actions
56 lines (45 loc) · 1.55 KB
/
Copy pathFirewall.php
File metadata and controls
56 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require_once __DIR__ . "/UserManager.php";
require_once __DIR__ . "/EncryptionInterface.php";
require_once __DIR__ . "/EncryptionCrypt.php";
require_once __DIR__ . "/EncryptionMd5.php";
require_once __DIR__ . "/EncryptionPlainText.php";
class Firewall {
/**
* @return bool
*/
public function isAutenticated() {
global $userManager, $config;
// If the Server-variables do not exist, the user cannot be validated.
if (!array_key_exists('PHP_AUTH_USER', $_SERVER) || !array_key_exists('PHP_AUTH_PW', $_SERVER))
return false;
$username = $_SERVER['PHP_AUTH_USER'];
// Check if the user exists
if (!$userManager->userExists($username))
return false;
// Check if the password can be validated by any enabled encryption class
foreach ($config['firewall']['acceptEncryptionClasses'] as $encryptionClass) {
/** @var $encryption EncryptionInterface */
$encryption = new $encryptionClass;
if (!($encryption instanceof EncryptionInterface))
throw new Exception('The registered encryption-class <' . get_class($encryption) . '> does not implement the EncryptionInterface');
$result = $encryption->validateEncryptedString($_SERVER['PHP_AUTH_PW'],
$userManager->getUserByName($username)->getPassword());
if ($result === true)
return true;
elseif ($result === false)
return false;
}
return false;
}
/**
* @return bool
*/
public function hasUserAccess() {
global $userManager, $config;
if ($userManager->getCurrentUser()->getUsername() === $config['firewall']['admin'])
return true;
else
return false;
}
}