0
|
1 |
<?php
|
|
2 |
|
|
3 |
function redirect($url)
|
|
4 |
{
|
|
5 |
header('HTTP/1.1 302 Found');
|
|
6 |
header("Location: $url");
|
|
7 |
exit;
|
|
8 |
}
|
|
9 |
|
|
10 |
/**
|
|
11 |
* Queue a message that will be displayed in a box on the next page load
|
|
12 |
* @param int Message type (E_NOTICE, E_WARNING, E_ERROR)
|
|
13 |
* @param string Message string
|
|
14 |
*/
|
|
15 |
|
|
16 |
function queue_message($code, $message)
|
|
17 |
{
|
|
18 |
$_SESSION['messages'][] = array(
|
|
19 |
'code' => $code
|
|
20 |
, 'message' => $message
|
|
21 |
);
|
|
22 |
}
|
|
23 |
|
|
24 |
function smarty_function_get_next_uid()
|
|
25 |
{
|
|
26 |
return get_next_available_uid();
|
|
27 |
}
|
|
28 |
|
|
29 |
function load_credentials()
|
|
30 |
{
|
|
31 |
$config = yaml_parse_file("/usr/local/etc/ssoinabox/webcreds.yml");
|
3
|
32 |
$keys = array('LDAP_BASEDN', 'UID_MIN', 'GID_MIN', 'ldap_server', 'ldap_manager', 'ldap_user_basedn', 'ldap_group_basedn', 'kerberos_admin', 'PHONE_EXT_MIN', 'hmac_secret');
|
0
|
33 |
|
|
34 |
foreach ( $keys as $key )
|
|
35 |
{
|
|
36 |
if ( !isset($config[$key]) )
|
|
37 |
die("Config key $key is not set");
|
|
38 |
|
|
39 |
if ( preg_match('/^[A-Z_]+$/', $key) )
|
|
40 |
define($key, $config[$key]);
|
|
41 |
else
|
|
42 |
$GLOBALS[$key] = $config[$key];
|
|
43 |
}
|
|
44 |
}
|
3
|
45 |
|
|
46 |
/**
|
|
47 |
* Test a password's policy compliance
|
|
48 |
* @param string password
|
|
49 |
* @return mixed true if compliant, otherwise a string describing why it isn't
|
|
50 |
*/
|
|
51 |
|
|
52 |
function test_password($str)
|
|
53 |
{
|
|
54 |
if ( strlen($str) < 8 )
|
|
55 |
return 'must be at least 8 characters in length';
|
|
56 |
|
|
57 |
if ( countUniqueChars($str) < 6 )
|
|
58 |
return 'must have at least 6 unique characters';
|
|
59 |
|
|
60 |
if ( strlen($str) <= 16 )
|
|
61 |
{
|
|
62 |
if ( !preg_match('/[a-z]/', $str) )
|
|
63 |
return 'must contain at least one lowercase letter';
|
|
64 |
|
|
65 |
if ( !preg_match('/[A-Z]/', $str) )
|
|
66 |
return 'must contain at least one lowercase letter';
|
|
67 |
|
|
68 |
if ( !preg_match('/[0-9]/', $str) )
|
|
69 |
return 'must contain at least one lowercase letter';
|
|
70 |
|
|
71 |
if ( !preg_match('/[^A-Za-z0-9]/', $str) )
|
|
72 |
return 'must contain at least one lowercase letter';
|
|
73 |
}
|
|
74 |
|
|
75 |
return true;
|
|
76 |
}
|
|
77 |
|
|
78 |
function countUniqueChars($str)
|
|
79 |
{
|
|
80 |
$count = 0;
|
|
81 |
$uniq = '';
|
|
82 |
for ( $i = 0; $i < strlen($str); $i++ )
|
|
83 |
{
|
|
84 |
if ( strpos($uniq, $str{$i}) === false )
|
|
85 |
$uniq .= $str{$i};
|
|
86 |
}
|
|
87 |
|
|
88 |
return strlen($uniq);
|
|
89 |
}
|