mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 00:25:06 +02:00
Fix coding style part 2
This commit is contained in:
@@ -1,104 +1,99 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION['username']))
|
||||
{
|
||||
$_SESSION['username'] = '';
|
||||
if (!isset($_SESSION['username'])) {
|
||||
$_SESSION['username'] = '';
|
||||
}
|
||||
|
||||
function authenticate($username,$password)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (isset($_SERVER['REMOTE_USER']))
|
||||
{
|
||||
$_SESSION['username'] = mres($_SERVER['REMOTE_USER']);
|
||||
function authenticate($username, $password) {
|
||||
global $config;
|
||||
|
||||
$row = @dbFetchRow("SELECT username FROM `users` WHERE `username`=?", array($_SESSION['username']));
|
||||
if (isset($row['username']) && $row['username'] == $_SESSION['username'])
|
||||
{
|
||||
return 1;
|
||||
if (isset($_SERVER['REMOTE_USER'])) {
|
||||
$_SESSION['username'] = mres($_SERVER['REMOTE_USER']);
|
||||
|
||||
$row = @dbFetchRow('SELECT username FROM `users` WHERE `username`=?', array($_SESSION['username']));
|
||||
if (isset($row['username']) && $row['username'] == $_SESSION['username']) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
$_SESSION['username'] = $config['http_auth_guest'];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION['username'] = $config['http_auth_guest'];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reauthenticate($sess_id = "",$token = "")
|
||||
{
|
||||
return 0;
|
||||
|
||||
function reauthenticate($sess_id='', $token='') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function passwordscanchange($username = "")
|
||||
{
|
||||
return 0;
|
||||
|
||||
function passwordscanchange($username='') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function changepassword($username,$newpassword)
|
||||
{
|
||||
# Not supported
|
||||
|
||||
function changepassword($username, $newpassword) {
|
||||
// Not supported
|
||||
}
|
||||
|
||||
function auth_usermanagement()
|
||||
{
|
||||
return 1;
|
||||
|
||||
function auth_usermanagement() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1')
|
||||
{
|
||||
|
||||
function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd='1') {
|
||||
if (!user_exists($username)) {
|
||||
$hasher = new PasswordHash(8, FALSE);
|
||||
$hasher = new PasswordHash(8, false);
|
||||
$encrypted = $hasher->HashPassword($password);
|
||||
return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname), 'users');
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function user_exists($username)
|
||||
{
|
||||
// FIXME this doesn't seem right? (adama)
|
||||
return dbFetchCell("SELECT * FROM `users` WHERE `username` = ?", array($username));
|
||||
|
||||
function user_exists($username) {
|
||||
// FIXME this doesn't seem right? (adama)
|
||||
return dbFetchCell('SELECT * FROM `users` WHERE `username` = ?', array($username));
|
||||
}
|
||||
|
||||
function get_userlevel($username)
|
||||
{
|
||||
return dbFetchCell("SELECT `level` FROM `users` WHERE `username`= ?", array($username));
|
||||
|
||||
function get_userlevel($username) {
|
||||
return dbFetchCell('SELECT `level` FROM `users` WHERE `username`= ?', array($username));
|
||||
}
|
||||
|
||||
function get_userid($username)
|
||||
{
|
||||
return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username`= ?", array($username));
|
||||
|
||||
function get_userid($username) {
|
||||
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username`= ?', array($username));
|
||||
}
|
||||
|
||||
function deluser($username)
|
||||
{
|
||||
# Not supported
|
||||
return 0;
|
||||
|
||||
function deluser($username) {
|
||||
// Not supported
|
||||
return 0;
|
||||
}
|
||||
|
||||
function get_userlist()
|
||||
{
|
||||
return dbFetchRows("SELECT * FROM `users`");
|
||||
|
||||
function get_userlist() {
|
||||
return dbFetchRows('SELECT * FROM `users`');
|
||||
}
|
||||
|
||||
function can_update_users()
|
||||
{
|
||||
# supported so return 1
|
||||
return 1;
|
||||
|
||||
function can_update_users() {
|
||||
// supported so return 1
|
||||
return 1;
|
||||
}
|
||||
|
||||
function get_user($user_id)
|
||||
{
|
||||
return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id));
|
||||
|
||||
function get_user($user_id) {
|
||||
return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id));
|
||||
}
|
||||
|
||||
function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
|
||||
{
|
||||
dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
|
||||
}
|
||||
|
||||
?>
|
||||
function update_user($user_id, $realname, $level, $can_modify_passwd, $email) {
|
||||
dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
|
||||
}
|
||||
|
||||
@@ -1,228 +1,237 @@
|
||||
<?php
|
||||
|
||||
$ds = @ldap_connect($config['auth_ldap_server'],$config['auth_ldap_port']);
|
||||
$ds = @ldap_connect($config['auth_ldap_server'], $config['auth_ldap_port']);
|
||||
|
||||
if ($config['auth_ldap_starttls'] && ($config['auth_ldap_starttls'] == 'optional' || $config['auth_ldap_starttls'] == 'require'))
|
||||
{
|
||||
$tls = ldap_start_tls($ds);
|
||||
if ($config['auth_ldap_starttls'] == 'require' && $tls == FALSE)
|
||||
{
|
||||
echo("<h2>Fatal error: LDAP TLS required but not successfully negotiated:" . ldap_error($ds) . "</h2>");
|
||||
exit;
|
||||
}
|
||||
if ($config['auth_ldap_starttls'] && ($config['auth_ldap_starttls'] == 'optional' || $config['auth_ldap_starttls'] == 'require')) {
|
||||
$tls = ldap_start_tls($ds);
|
||||
if ($config['auth_ldap_starttls'] == 'require' && $tls == false) {
|
||||
echo '<h2>Fatal error: LDAP TLS required but not successfully negotiated:'.ldap_error($ds).'</h2>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function authenticate($username,$password)
|
||||
{
|
||||
global $config, $ds;
|
||||
|
||||
if ($username && $ds)
|
||||
{
|
||||
if ($config['auth_ldap_version'])
|
||||
{
|
||||
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
|
||||
|
||||
function authenticate($username, $password) {
|
||||
global $config, $ds;
|
||||
|
||||
if ($username && $ds) {
|
||||
if ($config['auth_ldap_version']) {
|
||||
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
|
||||
}
|
||||
|
||||
if (ldap_bind($ds, $config['auth_ldap_prefix'].$username.$config['auth_ldap_suffix'], $password)) {
|
||||
if (!$config['auth_ldap_group']) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
$ldap_groups = get_group_list();
|
||||
foreach ($ldap_groups as $ldap_group) {
|
||||
$ldap_comparison = ldap_compare(
|
||||
$ds,
|
||||
$ldap_group,
|
||||
$config['auth_ldap_groupmemberattr'],
|
||||
get_membername($username)
|
||||
);
|
||||
if ($ldap_comparison === true) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo ldap_error($ds);
|
||||
}
|
||||
}
|
||||
if (ldap_bind($ds, $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'], $password))
|
||||
{
|
||||
if (!$config['auth_ldap_group'])
|
||||
{
|
||||
else {
|
||||
// FIXME return a warning that LDAP couldn't connect?
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function reauthenticate($sess_id, $token) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function passwordscanchange($username='') {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function changepassword($username, $newpassword) {
|
||||
// Not supported (for now)
|
||||
|
||||
}
|
||||
|
||||
|
||||
function auth_usermanagement() {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd='1') {
|
||||
// Not supported
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function user_exists($username) {
|
||||
global $config, $ds;
|
||||
|
||||
$filter = '('.$config['auth_ldap_prefix'].$username.')';
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
if ($entries['count']) {
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ldap_groups = get_group_list();
|
||||
foreach($ldap_groups as $ldap_group) {
|
||||
$ldap_comparison = ldap_compare($ds,
|
||||
$ldap_group,
|
||||
$config['auth_ldap_groupmemberattr'],
|
||||
get_membername($username));
|
||||
if($ldap_comparison === true) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_userlevel($username) {
|
||||
global $config, $ds;
|
||||
|
||||
$userlevel = 0;
|
||||
|
||||
// Find all defined groups $username is in
|
||||
$filter = '(&(|(cn='.join(')(cn=', array_keys($config['auth_ldap_groups'])).'))('.$config['auth_ldap_groupmemberattr'].'='.get_membername($username).'))';
|
||||
$search = ldap_search($ds, $config['auth_ldap_groupbase'], $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
// Loop the list and find the highest level
|
||||
foreach ($entries as $entry) {
|
||||
$groupname = $entry['cn'][0];
|
||||
if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel) {
|
||||
$userlevel = $config['auth_ldap_groups'][$groupname]['level'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(ldap_error($ds));
|
||||
|
||||
return $userlevel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_userid($username) {
|
||||
global $config, $ds;
|
||||
|
||||
$filter = '('.$config['auth_ldap_prefix'].$username.')';
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
if ($entries['count']) {
|
||||
return $entries[0]['uidnumber'][0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME return a warning that LDAP couldn't connect?
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
function reauthenticate($sess_id,$token)
|
||||
{
|
||||
return 0;
|
||||
|
||||
function deluser($username) {
|
||||
// Not supported
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
function passwordscanchange($username = "")
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
function changepassword($username,$newpassword)
|
||||
{
|
||||
# Not supported (for now)
|
||||
}
|
||||
function get_userlist() {
|
||||
global $config, $ds;
|
||||
$userlist = array();
|
||||
|
||||
function auth_usermanagement()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$filter = '('.$config['auth_ldap_prefix'].'*)';
|
||||
|
||||
function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1')
|
||||
{
|
||||
# Not supported
|
||||
return 0;
|
||||
}
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
function user_exists($username)
|
||||
{
|
||||
global $config, $ds;
|
||||
|
||||
$filter = "(" . $config['auth_ldap_prefix'] . $username . ")";
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
if ($entries['count'])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function get_userlevel($username)
|
||||
{
|
||||
global $config, $ds;
|
||||
|
||||
$userlevel = 0;
|
||||
|
||||
# Find all defined groups $username is in
|
||||
$filter = "(&(|(cn=" . join(")(cn=", array_keys($config['auth_ldap_groups'])) . "))(". $config['auth_ldap_groupmemberattr']. "=" . get_membername($username) . "))";
|
||||
$search = ldap_search($ds, $config['auth_ldap_groupbase'], $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
# Loop the list and find the highest level
|
||||
foreach ($entries as $entry)
|
||||
{
|
||||
$groupname = $entry['cn'][0];
|
||||
if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel)
|
||||
{
|
||||
$userlevel = $config['auth_ldap_groups'][$groupname]['level'];
|
||||
}
|
||||
}
|
||||
|
||||
return $userlevel;
|
||||
}
|
||||
|
||||
function get_userid($username)
|
||||
{
|
||||
global $config, $ds;
|
||||
|
||||
$filter = "(" . $config['auth_ldap_prefix'] . $username . ")";
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
if ($entries['count'])
|
||||
{
|
||||
return $entries[0]['uidnumber'][0];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function deluser($username)
|
||||
{
|
||||
# Not supported
|
||||
return 0;
|
||||
}
|
||||
|
||||
function get_userlist()
|
||||
{
|
||||
global $config, $ds;
|
||||
$userlist = array();
|
||||
|
||||
$filter = '(' . $config['auth_ldap_prefix'] . '*)';
|
||||
|
||||
$search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter);
|
||||
$entries = ldap_get_entries($ds, $search);
|
||||
|
||||
if ($entries['count'])
|
||||
{
|
||||
foreach ($entries as $entry)
|
||||
{
|
||||
$username = $entry['uid'][0];
|
||||
$realname = $entry['cn'][0];
|
||||
$user_id = $entry['uidnumber'][0];
|
||||
$email = $entry[$config['auth_ldap_emailattr']][0];
|
||||
$ldap_groups = get_group_list();
|
||||
foreach($ldap_groups as $ldap_group) {
|
||||
$ldap_comparison = ldap_compare($ds,
|
||||
$ldap_group,
|
||||
$config['auth_ldap_groupmemberattr'],
|
||||
get_membername($username));
|
||||
if (!isset($config['auth_ldap_group']) || $ldap_comparison === true) {
|
||||
$userlist[] = array('username' => $username, 'realname' => $realname, 'user_id' => $user_id, 'email' => $email);
|
||||
if ($entries['count']) {
|
||||
foreach ($entries as $entry) {
|
||||
$username = $entry['uid'][0];
|
||||
$realname = $entry['cn'][0];
|
||||
$user_id = $entry['uidnumber'][0];
|
||||
$email = $entry[$config['auth_ldap_emailattr']][0];
|
||||
$ldap_groups = get_group_list();
|
||||
foreach ($ldap_groups as $ldap_group) {
|
||||
$ldap_comparison = ldap_compare(
|
||||
$ds,
|
||||
$ldap_group,
|
||||
$config['auth_ldap_groupmemberattr'],
|
||||
get_membername($username)
|
||||
);
|
||||
if (!isset($config['auth_ldap_group']) || $ldap_comparison === true) {
|
||||
$userlist[] = array(
|
||||
'username' => $username,
|
||||
'realname' => $realname,
|
||||
'user_id' => $user_id,
|
||||
'email' => $email,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $userlist;
|
||||
return $userlist;
|
||||
}
|
||||
|
||||
function can_update_users()
|
||||
{
|
||||
# not supported so return 0
|
||||
return 0;
|
||||
|
||||
function can_update_users() {
|
||||
// not supported so return 0
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
function get_user($user_id)
|
||||
{
|
||||
# not supported
|
||||
return 0;
|
||||
|
||||
function get_user($user_id) {
|
||||
// not supported
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
|
||||
{
|
||||
# not supported
|
||||
return 0;
|
||||
|
||||
function update_user($user_id, $realname, $level, $can_modify_passwd, $email) {
|
||||
// not supported
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
function get_membername ($username)
|
||||
{
|
||||
global $config;
|
||||
if ($config['auth_ldap_groupmembertype'] == "fulldn")
|
||||
{
|
||||
$membername = $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$membername = $username;
|
||||
}
|
||||
return $membername;
|
||||
|
||||
function get_membername($username) {
|
||||
global $config;
|
||||
if ($config['auth_ldap_groupmembertype'] == 'fulldn') {
|
||||
$membername = $config['auth_ldap_prefix'].$username.$config['auth_ldap_suffix'];
|
||||
}
|
||||
else {
|
||||
$membername = $username;
|
||||
}
|
||||
|
||||
return $membername;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_group_list() {
|
||||
global $config;
|
||||
global $config;
|
||||
|
||||
$ldap_groups = array();
|
||||
$default_group = 'cn=groupname,ou=groups,dc=example,dc=com';
|
||||
if(isset($config['auth_ldap_group'])) {
|
||||
if($config['auth_ldap_group'] !== $default_group) {
|
||||
$ldap_groups[] = $config['auth_ldap_group'];
|
||||
$ldap_groups = array();
|
||||
$default_group = 'cn=groupname,ou=groups,dc=example,dc=com';
|
||||
if (isset($config['auth_ldap_group'])) {
|
||||
if ($config['auth_ldap_group'] !== $default_group) {
|
||||
$ldap_groups[] = $config['auth_ldap_group'];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($config['auth_ldap_groups'] as $key => $value) {
|
||||
$dn = "cn=$key," . $config['auth_ldap_groupbase'];
|
||||
$ldap_groups[] = $dn;
|
||||
}
|
||||
return $ldap_groups;
|
||||
}
|
||||
|
||||
?>
|
||||
foreach ($config['auth_ldap_groups'] as $key => $value) {
|
||||
$dn = "cn=$key,".$config['auth_ldap_groupbase'];
|
||||
$ldap_groups[] = $dn;
|
||||
}
|
||||
|
||||
return $ldap_groups;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,71 +1,69 @@
|
||||
<?php
|
||||
|
||||
function authenticate($username,$password)
|
||||
{
|
||||
$encrypted_old = md5($password);
|
||||
$row = dbFetchRow("SELECT username,password FROM `users` WHERE `username`= ?", array($username));
|
||||
if ($row['username'] && $row['username'] == $username)
|
||||
{
|
||||
// Migrate from old, unhashed password
|
||||
if ($row['password'] == $encrypted_old)
|
||||
{
|
||||
$row_type = dbFetchRow("DESCRIBE users password");
|
||||
if ($row_type['Type'] == 'varchar(34)')
|
||||
{
|
||||
changepassword($username,$password);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
elseif(substr($row['password'],0,3) == '$1$')
|
||||
{
|
||||
$row_type = dbFetchRow("DESCRIBE users password");
|
||||
if ($row_type['Type'] == 'varchar(60)')
|
||||
{
|
||||
if ($row['password'] == crypt($password,$row['password']))
|
||||
{
|
||||
changepassword($username,$password);
|
||||
|
||||
function authenticate($username, $password) {
|
||||
$encrypted_old = md5($password);
|
||||
$row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username));
|
||||
if ($row['username'] && $row['username'] == $username) {
|
||||
// Migrate from old, unhashed password
|
||||
if ($row['password'] == $encrypted_old) {
|
||||
$row_type = dbFetchRow('DESCRIBE users password');
|
||||
if ($row_type['Type'] == 'varchar(34)') {
|
||||
changepassword($username, $password);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (substr($row['password'], 0, 3) == '$1$') {
|
||||
$row_type = dbFetchRow('DESCRIBE users password');
|
||||
if ($row_type['Type'] == 'varchar(60)') {
|
||||
if ($row['password'] == crypt($password, $row['password'])) {
|
||||
changepassword($username, $password);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hasher = new PasswordHash(8, FALSE);
|
||||
if($hasher->CheckPassword($password, $row['password']))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reauthenticate($sess_id,$token)
|
||||
{
|
||||
list($uname,$hash) = explode("|",$token);
|
||||
$session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'");
|
||||
$hasher = new PasswordHash(8, FALSE);
|
||||
if($hasher->CheckPassword($uname.$session['session_token'],$hash))
|
||||
{
|
||||
$_SESSION['username'] = $uname;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hasher = new PasswordHash(8, false);
|
||||
if ($hasher->CheckPassword($password, $row['password'])) {
|
||||
return 1;
|
||||
}
|
||||
}//end if
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function passwordscanchange($username = "")
|
||||
{
|
||||
/*
|
||||
* By default allow the password to be modified, unless the existing
|
||||
* user is explicitly prohibited to do so.
|
||||
*/
|
||||
}//end authenticate()
|
||||
|
||||
|
||||
function reauthenticate($sess_id, $token) {
|
||||
list($uname,$hash) = explode('|', $token);
|
||||
$session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'");
|
||||
$hasher = new PasswordHash(8, false);
|
||||
if ($hasher->CheckPassword($uname.$session['session_token'], $hash)) {
|
||||
$_SESSION['username'] = $uname;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}//end reauthenticate()
|
||||
|
||||
|
||||
function passwordscanchange($username='') {
|
||||
/*
|
||||
* By default allow the password to be modified, unless the existing
|
||||
* user is explicitly prohibited to do so.
|
||||
*/
|
||||
|
||||
if (empty($username) || !user_exists($username)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username));
|
||||
}
|
||||
|
||||
}//end passwordscanchange()
|
||||
|
||||
if (empty($username) || !user_exists($username))
|
||||
{
|
||||
return 1;
|
||||
} else {
|
||||
return dbFetchCell("SELECT can_modify_passwd FROM users WHERE username = ?", array($username));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* From: http://code.activestate.com/recipes/576894-generate-a-salt/
|
||||
@@ -74,92 +72,98 @@ function passwordscanchange($username = "")
|
||||
* @param $max integer The number of characters in the string
|
||||
* @author AfroSoft <scripts@afrosoft.co.cc>
|
||||
*/
|
||||
function generateSalt($max = 15)
|
||||
{
|
||||
$characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
$i = 0;
|
||||
$salt = "";
|
||||
do
|
||||
{
|
||||
$salt .= $characterList{mt_rand(0,strlen($characterList))};
|
||||
$i++;
|
||||
} while ($i <= $max);
|
||||
function generateSalt($max=15) {
|
||||
$characterList = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
$i = 0;
|
||||
$salt = '';
|
||||
do {
|
||||
$salt .= $characterList{mt_rand(0, strlen($characterList))};
|
||||
$i++;
|
||||
} while ($i <= $max);
|
||||
|
||||
return $salt;
|
||||
}
|
||||
return $salt;
|
||||
|
||||
function changepassword($username,$password)
|
||||
{
|
||||
$hasher = new PasswordHash(8, FALSE);
|
||||
$encrypted = $hasher->HashPassword($password);
|
||||
return dbUpdate(array('password' => $encrypted), 'users', '`username` = ?', array($username));
|
||||
}
|
||||
}//end generateSalt()
|
||||
|
||||
function auth_usermanagement()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd=1, $description ="", $twofactor=0)
|
||||
{
|
||||
if (!user_exists($username))
|
||||
{
|
||||
$hasher = new PasswordHash(8, FALSE);
|
||||
function changepassword($username, $password) {
|
||||
$hasher = new PasswordHash(8, false);
|
||||
$encrypted = $hasher->HashPassword($password);
|
||||
return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users');
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return dbUpdate(array('password' => $encrypted), 'users', '`username` = ?', array($username));
|
||||
|
||||
function user_exists($username)
|
||||
{
|
||||
$return = @dbFetchCell("SELECT COUNT(*) FROM users WHERE username = ?", array($username));
|
||||
return $return;
|
||||
}
|
||||
}//end changepassword()
|
||||
|
||||
function get_userlevel($username)
|
||||
{
|
||||
return dbFetchCell("SELECT `level` FROM `users` WHERE `username` = ?", array($username));
|
||||
}
|
||||
|
||||
function get_userid($username)
|
||||
{
|
||||
return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username` = ?", array($username));
|
||||
}
|
||||
function auth_usermanagement() {
|
||||
return 1;
|
||||
|
||||
function deluser($username)
|
||||
{
|
||||
}//end auth_usermanagement()
|
||||
|
||||
dbDelete('bill_perms', "`user_name` = ?", array($username));
|
||||
dbDelete('devices_perms', "`user_name` = ?", array($username));
|
||||
dbDelete('ports_perms', "`user_name` = ?", array($username));
|
||||
dbDelete('users_prefs', "`user_name` = ?", array($username));
|
||||
dbDelete('users', "`user_name` = ?", array($username));
|
||||
|
||||
return dbDelete('users', "`username` = ?", array($username));
|
||||
function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd=1, $description='', $twofactor=0) {
|
||||
if (!user_exists($username)) {
|
||||
$hasher = new PasswordHash(8, false);
|
||||
$encrypted = $hasher->HashPassword($password);
|
||||
return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users');
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}//end adduser()
|
||||
|
||||
function get_userlist()
|
||||
{
|
||||
return dbFetchRows("SELECT * FROM `users`");
|
||||
}
|
||||
|
||||
function can_update_users()
|
||||
{
|
||||
# supported so return 1
|
||||
return 1;
|
||||
}
|
||||
function user_exists($username) {
|
||||
$return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username));
|
||||
return $return;
|
||||
|
||||
function get_user($user_id)
|
||||
{
|
||||
return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id));
|
||||
}
|
||||
}//end user_exists()
|
||||
|
||||
function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
|
||||
{
|
||||
dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
|
||||
}
|
||||
|
||||
?>
|
||||
function get_userlevel($username) {
|
||||
return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username));
|
||||
|
||||
}//end get_userlevel()
|
||||
|
||||
|
||||
function get_userid($username) {
|
||||
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username));
|
||||
|
||||
}//end get_userid()
|
||||
|
||||
|
||||
function deluser($username) {
|
||||
dbDelete('bill_perms', '`user_name` = ?', array($username));
|
||||
dbDelete('devices_perms', '`user_name` = ?', array($username));
|
||||
dbDelete('ports_perms', '`user_name` = ?', array($username));
|
||||
dbDelete('users_prefs', '`user_name` = ?', array($username));
|
||||
dbDelete('users', '`user_name` = ?', array($username));
|
||||
|
||||
return dbDelete('users', '`username` = ?', array($username));
|
||||
|
||||
}//end deluser()
|
||||
|
||||
|
||||
function get_userlist() {
|
||||
return dbFetchRows('SELECT * FROM `users`');
|
||||
|
||||
}//end get_userlist()
|
||||
|
||||
|
||||
function can_update_users() {
|
||||
// supported so return 1
|
||||
return 1;
|
||||
|
||||
}//end can_update_users()
|
||||
|
||||
|
||||
function get_user($user_id) {
|
||||
return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id));
|
||||
|
||||
}//end get_user()
|
||||
|
||||
|
||||
function update_user($user_id, $realname, $level, $can_modify_passwd, $email) {
|
||||
dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
|
||||
|
||||
}//end update_user()
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Two-Factor Authentication Library
|
||||
@@ -44,14 +45,14 @@ const otpWindow = 4;
|
||||
* Base32 Decoding dictionary
|
||||
*/
|
||||
$base32 = array(
|
||||
"A" => 0, "B" => 1, "C" => 2, "D" => 3,
|
||||
"E" => 4, "F" => 5, "G" => 6, "H" => 7,
|
||||
"I" => 8, "J" => 9, "K" => 10, "L" => 11,
|
||||
"M" => 12, "N" => 13, "O" => 14, "P" => 15,
|
||||
"Q" => 16, "R" => 17, "S" => 18, "T" => 19,
|
||||
"U" => 20, "V" => 21, "W" => 22, "X" => 23,
|
||||
"Y" => 24, "Z" => 25, "2" => 26, "3" => 27,
|
||||
"4" => 28, "5" => 29, "6" => 30, "7" => 31
|
||||
"A" => 0, "B" => 1, "C" => 2, "D" => 3,
|
||||
"E" => 4, "F" => 5, "G" => 6, "H" => 7,
|
||||
"I" => 8, "J" => 9, "K" => 10, "L" => 11,
|
||||
"M" => 12, "N" => 13, "O" => 14, "P" => 15,
|
||||
"Q" => 16, "R" => 17, "S" => 18, "T" => 19,
|
||||
"U" => 20, "V" => 21, "W" => 22, "X" => 23,
|
||||
"Y" => 24, "Z" => 25, "2" => 26, "3" => 27,
|
||||
"4" => 28, "5" => 29, "6" => 30, "7" => 31
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -128,14 +129,16 @@ function oath_hotp($key, $counter=false) {
|
||||
function verify_hotp($key,$otp,$counter=false) {
|
||||
if( oath_hotp($key,$counter) == $otp ) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if( $counter === false ) {
|
||||
//TimeBased HOTP requires lookbehind and lookahead.
|
||||
$counter = floor(microtime(true)/keyInterval);
|
||||
$initcount = $counter-((otpWindow+1)*keyInterval);
|
||||
$endcount = $counter+(otpWindow*keyInterval);
|
||||
$totp = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//Counter based HOTP only has lookahead, not lookbehind.
|
||||
$initcount = $counter-1;
|
||||
$endcount = $counter+otpWindow;
|
||||
@@ -145,7 +148,8 @@ function verify_hotp($key,$otp,$counter=false) {
|
||||
if( oath_hotp($key,$initcount) == $otp ) {
|
||||
if( !$totp ) {
|
||||
return $initcount;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -200,23 +204,28 @@ function twofactor_auth() {
|
||||
$twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username']));
|
||||
if( empty($twofactor['twofactor']) ) {
|
||||
$_SESSION['twofactor'] = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$twofactor = json_decode($twofactor['twofactor'],true);
|
||||
if( $twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time()-$twofactor['last']) < $config['twofactor_lock']) ) {
|
||||
$auth_message = "Too many failures, please ".($config['twofactor_lock'] ? "wait ".$config['twofactor_lock']." seconds" : "contact administrator").".";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if( !$_POST['twofactor'] ) {
|
||||
$twofactorform = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if( ($server_c = verify_hotp($twofactor['key'],$_POST['twofactor'],$twofactor['counter'])) === false ) {
|
||||
$twofactor['fails']++;
|
||||
$twofactor['last'] = time();
|
||||
$auth_message = "Wrong Two-Factor Token.";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if( $twofactor['counter'] !== false ) {
|
||||
if( $server_c !== true && $server_c !== $twofactor['counter'] ) {
|
||||
$twofactor['counter'] = $server_c+1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$twofactor['counter']++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user