class model_common
{
//var $db;
var $_user;
var $_userid;
var $_enc_user;
var $_enc_key;
var $_req_url='';
var $_tpl;
function model_common()
{
//global $db;
//$this->db = $db;
$this->_user = '';
$this->_tpl = 'tpl_no_access';
$this->chkSession();
}
function hexTostring($hS)
{
//var $bA=[];
//echo "
:hS:".$hS;
//echo "
:hS.length:".strlen($hS);
//echo "
:hexdec:".hexdec($hS);
//echo "
:chr:".chr(hexdec($hS));
//if($hS.length%2)return;
if(strlen($hS)%2)return;
// if($hS.indexOf("0x")==0||$hS.indexOf("0X")==0)
// {
// $hS = $hS.substring(2);
// }
$str = '';
//for ($i=0;$i<$hS.length;$i+=2)
for ($i=0;$ichr:".$chr;
$str .= $chr;
}
return $str;
}
function chkSession()
{
global $db;
//echo "
:_SERVER:";print_r($_SERVER);
//echo "
:_REQUEST:";print_r($_REQUEST);
$d = $_REQUEST['d'];
//echo "
_REQUEST['d']:".$d;
$d = $this->hexTostring($d);
//echo "
:d:".$d;
//echo "
:_SESSION:";print_r($_SESSION);
//if(isset($_SESSION['_user']) && $_SESSION['_user']!='')
//if( (isset($_REQUEST['user'])&&$_REQUEST['user']!='') && (isset($_REQUEST['key'])&&$_REQUEST['key']!='') )
if($this->setSessionVars())
{
$this->_tpl = 'tpl_welcome';
return true;
}
//header('location:index.php');
return false;
}
function unsetSession()
{
//unset($_SESSION['_user']);
unset($_SESSION['_userid']);
unset($_SESSION['_enc_user']);
unset($_SESSION['_enc_key']);
return;
}
function setSessionVars()
{
if( (isset($_REQUEST['u'])&&$_REQUEST['u']!='') && (isset($_REQUEST['k'])&&$_REQUEST['k']!='') && (isset($_REQUEST['d'])&&$_REQUEST['d']!='') )
{
$username = $_REQUEST['u'];
$key = $_REQUEST['k'];
$domainname = $_REQUEST['d'];
//echo "
:username:".$username;
//echo "
:password:".$key;
//$_username = $this->decodeDetails($username);
//$_password = $this->decodeDetails($key);
//echo "
:username:".$_username;
//echo "
:password:".$_password;
$this->unsetSession();
//$_userid = $this->chkValidUser($_username,$_password);
$_userid = $this->chkValidUser($username,$key,$domainname,'1');
if($_userid>0)
{
//$this->_user = $_username;
//$this->_domain = $_domainname;
$this->_userid = $_userid;
$this->_enc_user = $username;
$this->_enc_key = $key;
$this->_enc_domain = $domainname;
$this->_req_url = "?u=".$username."&k=".$key."&d=".$domainname;
//$_SESSION['_user'] = $_username;
//echo "
:_req_url:".$this->_req_url;die(':ARI:');
$_SESSION['_userid'] = $_userid;
$_SESSION['_enc_user'] = $username;
$_SESSION['_enc_key'] = $key;
$_SESSION['_enc_domain'] = $domainname;
return true;
}
return false;
}
return false;
}
function setSession()
{
global $db;
//echo "
:_REQUEST:";print_r($_REQUEST);//die(':ARI:');
//echo "
:_SESSION:";print_r($_SESSION);
$this->_tpl = 'tpl_no_access';
if($this->setSessionVars())
//if(isset($_SESSION['_user']) && $_SESSION['_user']!='')
{
$this->_tpl = 'tpl_list_components';
}
//print_r($db);die('ARI');
//echo "
:_req_url:".$this->_req_url;
//echo "
User:".$this->_user;
return;
}
function clean_domainname($domainname)
{
$pos = strrpos($domainname, ":");
if($pos)
{
$domainname = substr($domainname, 0, $pos);
}
return $domainname;
}
function chkValidUser($_username,$_password,$domainname,$chk_encrypted='0')
{
if($chk_encrypted=='1')
{
$domainname = $this->hexTostring($domainname);
$domainname = $this->clean_domainname($domainname);
$where_user_pwd =
"
and md5(user_name) = '".$_username."'
and domain_name like '%$domainname'
";//and md5(password) = '".$_password."'
}
else
{
$domainname = $this->clean_domainname($domainname);
$where_user_pwd =
"
and user_name = '".$_username."'
and domain_name like '%$domainname'
";//and password = '".$_password."'
}
$sql = "
SELECT * FROM
`admin_login`
WHERE
`access_type` = '3'
and `status` = '1'
".$where_user_pwd."
";
//echo "
:sql:".$sql;
$result = mysql_query($sql);
if(mysql_num_rows($result)>0){$row = mysql_fetch_array($result);return $row['user_id'];}
return 0;
}
/* most common functions begins */
function encodetDetails($str)
{
//return base64_encode(base64_encode($str));
return md5($str);
}
function decodeDetails($str)
{
//return base64_decode(base64_decode($str));
return false;
}
function timeDiff($firstTime,$lastTime)
{
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
}
/* most common functions ends */
}
$model_common = new model_common();
?>