| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| session_start(); |
| |
| |
| |
| function check_adminaccess() |
| { |
| |
| if (!isset($_SESSION['employeetype'])) |
| { |
| header('Location: '. BASEURL .'admin/login.php'); |
| } |
| } |
| |
| |
| function check_useraccess() |
| { |
| $timeout = 60 * 30; |
| $fingerprint = md5($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']); |
| $redirect_to = BASEURL . 'admin/login.php?loggedout=true'; |
| |
| |
| if (isset($_SESSION['last_active']) && $_SESSION['last_active'] < (time()-$timeout) |
| || (isset($_SESSION['fingerprint']) && $_SESSION['fingerprint']!=$fingerprint) |
| || isset($_GET['action']) && $_GET['action'] == 'logout') |
| { |
| |
| setcookie(session_name(), '', time()-3600, '/'); |
| session_destroy(); |
| header("Location: $redirect_to"); |
| } |
| |
| |
| session_regenerate_id(); |
| |
| |
| $_SESSION['last_active'] = time(); |
| |
| |
| $_SESSION['fingerprint'] = $fingerprint; |
| |
| } |
| |
| |
| function login() |
| { |
| require_once(ABSPATH . 'admin/includes/classes/ldap.php'); |
| $ldap = new LDAP; |
| |
| |
| $login = array(); |
| $login['username'] = ''; |
| $login['password'] = ''; |
| |
| |
| if (isset($_POST['username'])) |
| { |
| $mail_pattern = '/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/'; |
| if (preg_match( $mail_pattern,$_POST['username'])) |
| { |
| $login['username'] = $_POST['username']; |
| } |
| } |
| |
| |
| if (isset($_POST['password'])) |
| { |
| $login['password'] = $ldap->prepare_userpassword($_POST['password']); |
| } |
| |
| |
| $search = $ldap->get_entries('(&(uid=' . $login['username'] . ')(&(userpassword=' . $login['password'] . ')))'); |
| |
| |
| if ($search['count'] == 1) |
| { |
| |
| $_SESSION['uid'] = $search[0]['uid'][0]; |
| $_SESSION['cn'] = $search[0]['cn'][0]; |
| $_SESSION['employeetype'] = $search[0]['employeetype'][0]; |
| |
| |
| $_SESSION['last_active'] = time(); |
| |
| |
| $fingerprint = md5($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']); |
| $_SESSION['fingerprint'] = $fingerprint; |
| |
| |
| header("Location: " . BASEURL); |
| |
| return 0; |
| } |
| else if ($search['count'] > 1) |
| { |
| |
| return 002; |
| } |
| else |
| { |
| |
| return '001'; |
| } |
| } |
| |
| |
| function get_auth_userlinks() |
| { |
| |
| $html = '<ul>' . "\n"; |
| |
| if (isset($_SESSION['cn'])) |
| { |
| $html .= '<li><strong>' . $_SESSION['cn'] . '</strong> (<a href="?action=logout">' . ucfirst(translate("logout")) . '</a>)</li>' . "\n"; |
| $html .= '<li><a href="admin/index.php">' . ucfirst(translate("admin")) . '</a></li>' . "\n"; |
| } |
| else |
| { |
| $html .= '<li><a href="admin/login.php">' . ucfirst(translate("login")) . '</a></li>' . "\n"; |
| } |
| |
| $html .= '</ul>' . "\n"; |
| |
| return $html; |
| |
| } |
| |
| ?> |