whoami7 - Manager
:
/
home
/
snapify
/
public_html
/
clients
/
kyte-baby-dev
/
inc
/
Upload File:
files >> /home/snapify/public_html/clients/kyte-baby-dev/inc/handle.php
<?php class handler{ private $userid; private $usertype; private $link; private $db; private $headers; public $data; public $view; public $metadata; public $authdata; public $redirectpath; public $redirectstatus; public $template; public $status; public $messages; function __construct($db,$template){ $this->userid = 0; $this->usertype = 0; $this->db = $db; $template->registerFunction('js', function ($path,$js) { foreach ($js as $key => $value) {echo '<script type="text/javascript" src="'.THEME.'/'.$path.$value.'.js?v='.VERSION.'" ></script>';}}); $template->registerFunction('css', function ($path,$css) { foreach ($css as $key => $value) {echo ' <link rel="stylesheet" type="text/css" href="'.THEME.'/'.$path.$value.'.css?v='.VERSION.'" >';}}); $template->registerFunction('menu', function ($menu1,$menu2) {if($menu1 == $menu2){return 'class ="active"';}}); $this->template = $template; $this->headers = getallheaders(); } private function serve(){ if($this->link){ $this->data = $this->link->getdata(); $this->status = $this->link->getstatus(); if(!$this->view){ $this->view = $this->link->getview(); } $this->metadata = $this->link->getmeta(); $this->authdata = $this->link->getAuth(); $this->redirectpath = $this->link->getredirectpath(); $this->redirectstatus = $this->link->getredirectstatus(); $this->userid = $this->authdata['id'] ?? '0'; if(!$this->redirectstatus){ $this->data['flash'] = $this->setupflashtemplate(); } else{ $this->data['flash'] = []; } } } private function setupflashtemplate(){ $this->messages = []; if(isset($_COOKIE['flash'])){ $flash = json_decode($_COOKIE['flash'],true); $expiry = time() + (30 * 60); setcookie("flash",json_encode([]), $expiry,'/' ); $all = []; foreach ($flash as $key => $value) { $all[$value['type']][$value['keyname']] = $value['value']; } } else{ $all = []; } foreach ($all as $type => $messages) { switch ($type) { case 'error': $this->error_message($messages); break; case 'success': $this->success_message($messages); break; default: break; } } return $this->messages; } public function error_message($messages){ $return = []; foreach ($messages as $key => $message) { $this->messages[$key] = '<div class=" alert alert-danger alert-dismissible fade show mt-2" role="alert"> <div class="alert-content"> <p>'.$message.'</p> <button type="button" class="btn-close text-capitalize" data-bs-dismiss="alert" aria-label="Close"> <img src="hexadash/images/x.svg" alt="x" class="svg" aria-hidden="true"> </button> </div> </div>'; } } public function success_message($messages){ $return = []; foreach ($messages as $key => $message) { $this->messages[$key] = '<div class=" alert alert-success alert-dismissible fade show mt-2" role="alert"> <div class="alert-content"> <p>'.$message.'</p> <button type="button" class="btn-close text-capitalize" data-bs-dismiss="alert" aria-label="Close"> <img src="hexadash/images/x.svg" alt="x" class="svg" aria-hidden="true"> </button> </div> </div>'; } } public function auth($type){ if(isset($_COOKIE['token']) OR isset($_COOKIE['admintoken'])){ if(isset($_COOKIE['admintoken'])){ $authtoken = $_COOKIE['admintoken']; } if(isset($_COOKIE['token'])){ $authtoken = $_COOKIE['token']; } if(in_array(1,$type)){ $user_type[] = 'admin'; } if(in_array(2,$type)){ $user_type[] = 'user'; } if(in_array(4,$type)){ $user_type[] = 'order_level'; } $user = $this->db->from('login_tokens')->select(null)->select('user_id,user_type')->where('token',$authtoken)->where('user_type',$user_type)->where('status','1')->fetch(); if($user){ $values = ['last_seen'=>date('Y-m-d H:i:s')]; $this->db->update('login_tokens')->set($values)->where('token',$authtoken)->execute(); $user['name'] = $this->db->from('users')->where('id',$user['user_id'])->fetch('name'); if(isset($_COOKIE['token']) && isset($_COOKIE['admintoken'])){ $user['backtoadmin'] = true; } else{ $user['backtoadmin'] = false; } $expiry = time() + (30 * 60); if($user['user_type'] == 'admin'){ setcookie("admintoken",$authtoken, $expiry,'/' ); } elseif($user['user_type'] == 'user'){ setcookie("token",$authtoken, $expiry,'/' ); } elseif($user['user_type'] == 'order_level'){ setcookie("token",$authtoken, $expiry,'/' ); } if(isset($_COOKIE['remember']) && $_COOKIE['remember'] == 'true'){ $expiry = time() + (10 * 365 * 24 * 60 * 60); if($user['user_type'] == 'admin'){ setcookie("admintoken",$authtoken, $expiry,'/' ); } elseif($user['user_type'] == 'user'){ setcookie("token",$authtoken, $expiry,'/' ); } setcookie("remember",$_COOKIE['remember'], $expiry,'/' ); } return $user; } else{ $this->data = []; $this->status = 200; $this->view = 'login'; return false; } } $this->data = []; $this->status = 401; $this->view = 'login'; setcookie("token", "", time() - 3600,'/'); setcookie("admintoken", "", time() - 3600,'/'); return false; } public function noauth(){ return ['user_id'=>0]; } public function notfount(){ $this->data = []; $this->status = 200; $this->view = '404'; return false; } public function route404(){ $this->data = []; $this->status = 200; $this->view = '404'; return $this; } public function setdata($link,$args,$auth=[]){ $src = explode('#', $link); $class = $src[0]; $method = $src[1]; if(!empty($auth)){ $user = $this->auth($auth); if($user){ $this->userid = $user['user_id']; $args['auth_user_id'] = $user['user_id']; $args['auth_user_name'] = $user['name']; $args['auth_user_type'] = $user['user_type']; $args['backtoadmin'] = $user['backtoadmin']; $rank = new $class($args); $this->link = $rank->$method(); return $this; } else{ $rank = new $class($args); $this->link = $rank->noauth(); return $this; } } else{ $user = $this->noauth(); $args['auth_user_id'] = $user['user_id']; $rank = new $class($args); $this->link = $rank->$method(); return $this; } } public function getdata(){ return $this->data ?? []; } public function getmeta(){ return $this->metadata ?? []; } public function getAuth(){ return $this->authdata ?? []; } public function getview(){ return $this->view ?? 'login'; } public function getstatus() { return $this->status ?? 200; } public function __call($method,$args) { $auth = $this->get_authetication(); if(isset($auth[$method])){ $class = $this->setdata($method,$args[0],$auth[$method]); } else{ $class = $this->setdata($method,$args[0]); } $this->serve(); return $class; } public function getuserid() { return $this->userid; } public function get_authetication(){ $auths = parse_ini_file("authentication.ini"); $admin = array_fill_keys(preg_filter('/^/','admin#',explode(',', $auths['admin'])),[1,2,4]); $logs = array_fill_keys(preg_filter('/^/','logs#',explode(',', $auths['logs'])),[1,2,4]); $users = array_fill_keys(preg_filter('/^/','users#',explode(',', $auths['users'])),[1,2,4]); $ajax = array_fill_keys(preg_filter('/^/','ajax#',explode(',', $auths['ajax'])),[1,2,4]); $client = array_fill_keys(preg_filter('/^/','client#',explode(',', $auths['client'])),[1,2,4]); $app = array_fill_keys(preg_filter('/^/','app#',explode(',', $auths['app'])),[1,2,4]); $execptions = []; $execptions['users#home']=[1,2,4]; $execptions['users#settings']=[1,2,4]; $execptions['users#profile']=[1,2,4]; return array_merge($admin,$logs,$users,$ajax,$client,$app,$execptions); } public function isredirect() { return $this->redirectstatus; } public function getredirect() { return $this->redirectpath; } }
Copyright ©2021 || Defacer Indonesia