Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2007, 11:41 AM
n3o n3o is offline
Junior Member
 
Join Date: Oct 2007
Posts: 2
Question escaping from MVC control flow in plugin

Hello.

I have the following problem. I'm trying to create plugin, that enforces certain ip access policy (you can call it banlist if you want) to the site. IP check takes place in routeStartup() function, when I already have recieved the request from client with $_SERVER['REMOTE_ADDR'] set. Then my plugin checks that remote ip address against some list and so on ..., and then if it matches some of those I want to immediately stop processing the request and exit.

So my current solution if something like this

PHP Code:
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
    
$ip $request->getServer('REMOTE_ADDR');
    ...
    if ( 
$this->_isBlackListed($ip) )
    {
        
$view = new Zend_View();
        
$response $this->getResponse();
        
$response->append('errormsg',$view->render('banned.phtml');
        
$response->sendResponse();
        die;
    }

, and it seems very ugly to me (but it works at least). And something tells me that there should be some cleaner solution how to solve this with internal ZF structures, anyway is there any cleaner solution to this ? So any help or suggestions will be appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-09-2007, 08:44 PM
n3o n3o is offline
Junior Member
 
Join Date: Oct 2007
Posts: 2
Default

Well, after some experiments, i found out that simply moving IPcheck into plugins postDispatch() function does the trick, simply check for match, and if its true then use
$request->setControllerName() and $request->setActionName() functions. For example I`m using something like this

$request->setControllerName('error');
$request->setActionName('banned');

And this doesn't break MVC flow with some ugly die or similar.

Yes, i know maybe it seems obvious to do like that, but it didn`t seemed for me back then. Of course now it does .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-10-2007, 02:17 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 122
Default

if you implemented acl's it's easier to write an assert ip policy in combination with a plugin
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:06 PM.