/** * @return mixed */ public function onBeforeInit() { $access = new IpAccess($this->owner->getRequest()->getIP()); if (!$access->hasAccess()) { $access->respondNoAccess($this->owner); } }
function onBeforeInit() { if (Config::inst()->get('IpAccess', 'enabled')) { $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips')); if (!$ipAccess->hasAccess()) { if (class_exists('ErrorPage', true)) { $response = ErrorPage::response_for(403); } $response = $response ? $response : 'The requested page could not be found.'; return $this->owner->httpError(403, $response); } } }
/** * @return void */ public function init() { parent::init(); $access = new IpAccess($this->getRequest()->getIP()); if (!$access->hasAccess()) { $access->respondNoAccess($this); } if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) { // this prevents loading frontend css and javscript files Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller'); Requirements::css('adminlogin/css/style.css'); } Object::useCustomClass('MemberLoginForm', 'AdminLoginForm'); }
public function init() { parent::init(); if (Config::inst()->get('IpAccess', 'enabled')) { $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips')); if (!$ipAccess->hasAccess()) { $reponse = ''; if (class_exists('ErrorPage', true)) { $response = ErrorPage::response_for(404); } return $this->owner->httpError(404, $response ? $response : 'The requested page could not be found.'); } } // this prevents loading frontend css and javscript files Requirements::clear(); Requirements::css('adminlogin/css/style.css'); }
public function init() { parent::init(); if (Config::inst()->get('IpAccess', 'enabled')) { $ipAccess = new IpAccess($this->owner->getRequest()->getIP(), Config::inst()->get('IpAccess', 'allowed_ips')); if (!$ipAccess->hasAccess()) { $reponse = ''; if (class_exists('ErrorPage', true)) { $response = ErrorPage::response_for(404); } return $this->owner->httpError(404, $response ? $response : 'The requested page could not be found.'); } } if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) { // this prevents loading frontend css and javscript files Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller'); Requirements::css('adminlogin/css/style.css'); } Object::useCustomClass('MemberLoginForm', 'AdminLoginForm'); }
function testHasAccess() { $obj = new IpAccess('192.168.1.101'); $obj->allowedIps = array(); $this->assertEquals($obj->hasAccess(), 'allowed'); $obj->allowedIps = $this->allowedIps; $obj->setIp('192.168.1.101'); $this->assertEquals($obj->hasAccess(), '192.168.1.101'); $obj->setIp('192.168.1.102'); $this->assertEquals($obj->hasAccess(), '192.168.1.100-200'); $obj->setIp('192.168.1.201'); $this->assertEquals($obj->hasAccess(), '192.168.1.0/24'); $obj->setIp('192.168.1.257'); $this->assertEquals($obj->hasAccess(), '192.168.1.*'); $obj->setIp('192.168.2.101'); $this->assertEmpty($obj->hasAccess()); }