<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Admin\Middleware; use Closure; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\View; use Illuminate\Support\Str; use ModStart\Admin\Auth\Admin; use ModStart\Admin\Auth\AdminPermission; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; class AuthMiddleware { protected $authIgnores = array('\\ModStart\\Admin\\Controller\\AuthController'); public function handle($kn_5b, Closure $BuCHd) { goto BYJj0; zxUyL: if (!$this->isAuthIgnore($clsTY, $TFjGK)) { goto aMq6j; ROx3g: if (empty($Zmfkp)) { return Response::redirect(action('\\ModStart\\Admin\\Controller\\AuthController@login', array('redirect' => Request::currentPageUrl()))); } goto inedU; yilZN: if (AdminPermission::isFounder($yq1bP)) { foreach ($PhCiy as $U9AsU => $ohYVl) { $PhCiy[$U9AsU] = true; } } else { goto aD6Vx; Fxd6O: foreach ($lT6n5 as $KpdQH => $ohYVl) { $PhCiy[$KpdQH] = true; } goto om_Jn; om_Jn: Session::put('_adminRules', $PhCiy); goto r6oxp; J9v79: if (true || empty($lT6n5) && $Zmfkp['id'] > 0 || $Zmfkp['ruleChanged']) { goto dUoPj; cLSGV: $lT6n5 = array(); goto awgps; GS4og: foreach ($uotzZ['data'] as $FYbMR) { foreach ($FYbMR['rules'] as $KpdQH) { $lT6n5[$KpdQH['rule']] = true; } } goto UM1eL; UM1eL: Session::put('_adminHasRules', $lT6n5); goto gSeJi; dUoPj: if ($Zmfkp['ruleChanged']) { Admin::ruleChanged($Zmfkp['id'], false); } goto cLSGV; awgps: $uotzZ = Admin::listRolesByUserId($Zmfkp['id']); goto GS4og; gSeJi: } goto Fxd6O; aD6Vx: $lT6n5 = Session::get('_adminHasRules', array()); goto J9v79; r6oxp: } goto G0CAn; aMq6j: if ($yq1bP && !$Zmfkp) { Session::forget('_adminUserId'); return Response::redirect(action('\\ModStart\\Admin\\Controller\\AuthController@login', array('redirect' => Request::currentPageUrl()))); } goto ROx3g; G0CAn: if (isset($PhCiy[$UPLu0]) && !$PhCiy[$UPLu0]) { return Response::send(-1, L('Permission Denied')); } goto kmWUs; inedU: $PhCiy = array_build(AdminPermission::rules(), function ($U9AsU, $ohYVl) { return array($ohYVl, false); }); goto yilZN; kmWUs: } goto vmx9o; V2b2S: View::share('_controllerMethod', $UPLu0); goto Iiq7r; qui5u: Session::flash('_adminUser', $Zmfkp); goto LOJ8n; sf04G: if ($yq1bP) { if (empty($Zmfkp)) { $Zmfkp = Admin::get($yq1bP); } } goto XQ2UG; LOJ8n: View::share('_adminUser', $Zmfkp); goto Bmr4r; Bmr4r: View::share('_adminUserId', $yq1bP); goto V2b2S; iTfuG: if (empty($yq1bP)) { goto bT1nm; bT1nm: $m0v7v = intval(Request::headerGet('auth-admin-user-id')); goto At740; At740: $t5kWp = intval(Request::headerGet('auth-admin-timestamp')); goto mua5s; mua5s: $PoFq9 = trim(Request::headerGet('auth-admin-sign')); goto hZqlY; hZqlY: if ($m0v7v > 0) { goto Fx7de; q316V: if (empty($kZoGJ['password']) || empty($kZoGJ['passwordSalt'])) { return Response::send(-1, 'admin user forbidden'); } goto P_BCa; Nu_GI: $yq1bP = $kZoGJ['id']; goto s3CqN; spwZc: $kZoGJ = Admin::get($m0v7v); goto ih2gw; Fx7de: if ($t5kWp < time() - 1800 || $t5kWp > time() + 1800) { return Response::send(-1, 'auth-admin-timestamp error'); } goto spwZc; T9exJ: if ($mNLRy != $PoFq9) { return Response::send(-1, 'admin user sign error'); } goto Nu_GI; s3CqN: $Zmfkp = $kZoGJ; goto UTFZ9; P_BCa: $mNLRy = md5("{$m0v7v}:{$t5kWp}:{$kZoGJ['password']}{$kZoGJ['passwordSalt']}"); goto T9exJ; ih2gw: if (empty($kZoGJ)) { return Response::send(-1, 'admin user not exists'); } goto q316V; UTFZ9: } goto FBOyL; FBOyL: } goto sf04G; EjR2c: $HGZG4 = explode('@', $COAft); goto Y8lLs; Y8lLs: if (isset($HGZG4[0])) { $clsTY = $HGZG4[0]; } else { $clsTY = null; } goto Uypi6; Uypi6: if (isset($HGZG4[1])) { $TFjGK = $HGZG4[1]; } else { $TFjGK = null; } goto jlNBo; WqLv8: $Zmfkp = null; goto iTfuG; Iiq7r: return $BuCHd($kn_5b); goto Fk4Ef; XQ2UG: $UPLu0 = $clsTY . '@' . $TFjGK; goto zxUyL; MJ2L3: $yq1bP = intval(Session::get('_adminUserId', null)); goto WqLv8; BYJj0: $COAft = Route::currentRouteAction(); goto EjR2c; vmx9o: Session::put('_adminUserId', $yq1bP); goto qui5u; jlNBo: if (!Str::startsWith($clsTY, '\\')) { $clsTY = '\\' . $clsTY; } goto MJ2L3; Fk4Ef: } private function isAuthIgnore($clsTY, $TFjGK) { foreach ($this->authIgnores as $Nrp0b) { if (Str::contains($Nrp0b, '@')) { if ($clsTY . '@' . $TFjGK == $Nrp0b) { return true; } } else { if ($clsTY == $Nrp0b) { return true; } } } return false; } }