I wanted the option of hiding my yii application from the public, and .htaccess did not 100% serve my needs. Using this component, I can very easily turn my site on and off and add manage allowed IPs from my config file.
I mainly use this as a way of protecting a site from the general public during development/testing/etc, redirecting the user to a 'coming soon' page.
ALSO: i'm a bit of a noob and wasn't sure how this should be categorized/tagged. Please post suggestions if you have them.
Requirements ¶
...requirements of using this extension (e.g. Yii 1.1 or above)...
Homepage ¶
https://github.com/duncanmapes/yii-underconstruction
Usage ¶
...how to use this extension...
- Upload file UnderConstruction.php to components directory
- Load Component in main.php
// preloading 'log' component
'preload'=>array('log','UnderConstruction'),
...
- Configure Component
'components'=>array(
...
'UnderConstruction' => array(
'class' => 'application.components.UnderConstruction',
'allowedIPs'=>array('192.168.1.1','192.168.1.2'), //whatever IPs you want to allow
'locked'=>true,//this is the on off switch
'redirectURL'=>'http://www.yiiframework.com',//put in your desired redirect page.
),
...),
catchAllRequest
Hi,
what are the benefits of this extension against catchAllRequest ?
for me more usefull to toggle construction/normal mode by renaiming empty file in root directory. Otherwise I need to change config and deploy project each time!
It would be nice to have such option in extension.
re:catchAllRequest
@vitalets thanks for the questions.
I have to be honest I was unaware of catchAllRequest prior to building this little component, but from looking it over it doesn't appear that it would have served my purposes anyway, because it locks out the entire site, I want to lockout the site only to the general public but allow myself or other developers/testers/etc to access the site. IP addresses seem like the easiest way to do that.
I'm not sure how renaming a directory would help anything other than prevent access to the entire application, which isn't what I was going for.
I understand this may be a narrow solution to a very specific issue, but it was sort of a pain for me to deal with, and I have benefited greatly from some of the extensions provided by the community here and just wanted to try and contribute.
:)
Hi duncanmapes
it's really good that you are sharing your code for that. I think standart catchAllRequest is not flexible enough and should be extended.
Access by ip is helpfull. (but also I suggest to setup test and production environments and do not make many changes on live site manually. Use version control instead, e.g. git:))
I'll explain what I mean:
I have empty file maintenance.txt in webroot folder.
If I want to toggle site to construction mode, I can do it very fast and easy via renaming file to maintenance123.txt or any other name.
My code in config checks for file and toggles mode:
//maintenance 'catchAllRequest' => (file_exists(dirname(__FILE__).'/../../../maintenance.txt')) ? array('maintenance/index'): null,
But if I change "locked" property straight in code, I need to make extra commit and deploy every time I need maintenance. Not very convenient.
It would be nice to build-in such feature in you component.
imagine user performs Ajax request when you enabled construction mode. What will he get?
He will not be redirected and may be will not understand what happens at all =)
It would be cool to process such case also.
cheers!
re:higherlevelprocess
I appreciate the suggestions and whole heartedly agree with you on the value of testing verses production environments and source control deployments. I also use git (via github.com), but unfortunately I haven't yet gotten the more advanced features figured out, its basically just a online repository/backup for me at this point. I will though.
One of the things I really like about yii is the ability to build out a proof of concept MVP (Minimum Viable Product) very quickly, and prior to that MVP launch, I only would have one environment. Hopefully in the future some of my apps will be successful enough to demand a more professional way of operating.
Regarding the ajax requests...I presume since the site is deactivated everywhere that none of the site built requests would be available, and as such wouldn't be needed. Obviously that is not the case if you're running web service API, but in that case this probably wouldn't be the best idea for you.
Thanks again.
static page
What if I want to send user to static page instead of another website.
Got redirect loop if tried to do so.
Redirection loop solved
Hi,
If someone has issue with redirection loop, this is the simple solution.
Under /components/UnderConstruction.php add one if() statement like following, to detect current URI:
if ($allowed) { /*do some important thing like ... nothing */ } else { if ($_SERVER['SCRIPT_URI'] !== $this->redirectURL) { Yii::app()->request->redirect($this->redirectURL); } }
Simple, and it works.
Regards
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.