<?php
class lib_auth
{
function lib_auth( )
{
}
function auth( $login, $pass )
{
$CI =& get_instance( );
if ( $login == config_item( "om_admin_login" ) && md5( $pass."omspass" ) == config_item( "om_admin_pass" ) )
{
$mdstr = md5( config_item( "om_admin_pass" ).$CI->agent->browser( ).$_SERVER['REMOTE_ADDR'] );
$CI->session->set_userdata( array(
"om_admin" => "logged",
"om_admin_hash" => $mdstr
) );
return TRUE;
}
if ( config_item( "om_staff_on" ) != 1 )
{
return FALSE;
}
if ( $login == config_item( "om_staff_login" ) && $pass == config_item( "om_staff_pass" ) )
{
$mdstr = md5( config_item( "om_staff_pass" ).$CI->agent->browser( ).$_SERVER['REMOTE_ADDR'] );
$CI->session->set_userdata( array(
"om_staff" => "logged",
"om_staff_hash" => $mdstr
) );
return TRUE;
}
return FALSE;
}
function check( $staff = FALSE )
{
$CI =& get_instance( );
if ( !defined( "OM_LIC" ) )
{
$CI->mdl_set->_lc( );
}
if ( $CI->session->userdata( "om_admin" ) == "logged" )
{
$mdstr = md5( config_item( "om_admin_pass" ).$CI->agent->browser( ).$_SERVER['REMOTE_ADDR'] );
if ( $CI->session->userdata( "om_admin_hash" ) == $mdstr )
{
return TRUE;
}
if ( $this->_staff( $staff ) )
{
return TRUE;
}
redirect( "ap/login" );
}
else if ( $this->_staff( $staff ) )
{
return TRUE;
}
else
{
redirect( "ap/login" );
}
}
function _staff( $staff )
{
if ( $staff == FALSE )
{
return FALSE;
}
if ( config_item( "om_staff_on" ) != 1 )
{
return FALSE;
}
$ex = explode( ",", config_item( "om_staff_allowed" ) );
if ( !in_array( $staff, $ex ) )
{
return FALSE;
}
$CI =& get_instance( );
if ( $CI->session->userdata( "om_staff" ) == "logged" )
{
$mdstr = md5( config_item( "om_staff_pass" ).$CI->agent->browser( ).$_SERVER['REMOTE_ADDR'] );
if ( $CI->session->userdata( "om_staff_hash" ) == $mdstr )
{
return TRUE;
}
}
return FALSE;
}
function logout( )
{
$CI =& get_instance( );
$CI->session->unset_userdata( array( "om_admin" => "", "om_admin_hash" => "", "om_staff" => "", "om_staff_hash" => "" ) );
redirect( "ap/login" );
}
function auth_aff( $login, $pass, $oklogin, $okpass )
{
$CI =& get_instance( );
if ( $login == $oklogin && $okpass == $pass )
{
$affstr = md5( $pass."afflogged" );
$CI->session->set_userdata( array(
"om_affrefid" => $login,
"om_aff_hash" => $affstr
) );
return TRUE;
}
return FALSE;
}
function logout_aff( )
{
$CI =& get_instance( );
$CI->session->unset_userdata( array( "om_affrefid" => "", "om_aff_hash" => "" ) );
redirect( "aff/login" );
}
function check_aff( )
{
$CI =& get_instance( );
$refid = $CI->session->userdata( "om_affrefid" );
if ( !empty( $refid ) )
{
$CI->load->model( "mdl_partners" );
$p = $CI->mdl_partners->get( $refid );
if ( empty( $p ) )
{
redirect( "aff/login" );
}
$affstr = md5( $p['password']."afflogged" );
if ( $CI->session->userdata( "om_aff_hash" ) == $affstr )
{
return $refid;
}
redirect( "aff/login" );
}
else
{
redirect( "aff/login" );
}
}
}
if ( !defined( "BASEPATH" ) )
{
exit( "No direct script access allowed" );
}
?>