Yii Toggle Maintenance Mode On/off

I am trying to make a maintenance mode in my website, I want to put a button that only the admin can see to toggle the maintenance mode ON/OFF.

This allow to admin continue seeing the web but the rest of the visitors not.

I have read about catchAllRequest, creating a file and renaming it when is necessary, but I cant make it work.

I have tried underconstruct extension, but I dont know how to toggle ON/OFF.

This is what I have at the moment.

CONTROLLER:


public function actionIndex()

    {

        $location = Yii::app()->request->baseUrl.'/protected/config/maintenanceON.txt';

        $new = Yii::app()->request->baseUrl.'/protected/config/maintenanceOFF.txt';

        Yii::app()->session['secret'] = "password";

        rename($location,$new);

        $this->renderPartial("index");

    }

CONFIG/MAIN.PHP :


'catchAllRequest'=>file_exists(

        dirname(__FILE__).'/maintenanceON.txt') && 

            !(Yii::app()->user->checkAccess('admin') ?

                array('maintenance/index') : null,

Thanks!

Any solutions :) ?

Maybe https://www.google.de/search?q=yii+maintenance+mode