CodeIgniter Forums
How can I lock down my entire site? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How can I lock down my entire site? (/showthread.php?tid=10150)



How can I lock down my entire site? - El Forum - 07-20-2008

[eluser]Aquillyne[/eluser]
My site has an admin area accessible by logging in. Inside the admin area I want a button that reads "Lock". If the admin clicks on this, every page request on the site delivers a "Site is locked down" message rather than loading (apart from the pages in the admin area, obviously). This continues until the admin clicks "Unlock".

What would be the simplest way of achieving this behaviour? I prefigure some Router extensions? Or maybe a simple hook?


How can I lock down my entire site? - El Forum - 07-20-2008

[eluser]Colin Williams[/eluser]
Sounds like if you had a pre-controller hook, you could check a variable stored in a database table or even flat-text file and then serve up the "LOCKED!!" (don't forget the exclamation marks) page accordingly.


How can I lock down my entire site? - El Forum - 07-20-2008

[eluser]Michael Wales[/eluser]
A hook, or extending the Controller class, would be the simplest.


How can I lock down my entire site? - El Forum - 07-20-2008

[eluser]Aquillyne[/eluser]
This works:

post-controller-constructor

Code:
class Lock
{
    
    var $locked = TRUE;
    var $CI;
    
    function check()
    {
        $this->CI =& get_instance();
        
        if ($this->locked)
        {
            $data["PageTitle"] = "LOCKED!!";
            $data["Content"] = "LOCKED!!";

            $this->CI->load->view("locked", $data);
            $this->CI->output->_display();
            die();
        }
    }
    
}

Can anyone say if I'm doing anything a little clumsily here? Or is this fine?

The problem remains: how to alter whether the site is locked via the button in the admin area...


How can I lock down my entire site? - El Forum - 07-20-2008

[eluser]Colin Williams[/eluser]
Hook looks alright. Nice and simple.

Quote:The problem remains: how to alter whether the site is locked via the button in the admin area…

Again, save a var in a database table or in a flat text file that you check in your hook. Are you familiar with using databases or manipulating files?


How can I lock down my entire site? - El Forum - 07-21-2008

[eluser]Aquillyne[/eluser]
[quote author="Colin Williams" date="1216637729"]Hook looks alright. Nice and simple.

Quote:The problem remains: how to alter whether the site is locked via the button in the admin area…

Again, save a var in a database table or in a flat text file that you check in your hook. Are you familiar with using databases or manipulating files?[/quote]

Yes. I think I'll go for a text file, otherwise every page on my site will initiate a database connection which may slow things down. Thanks for the help!


How can I lock down my entire site? - El Forum - 07-21-2008

[eluser]Colin Williams[/eluser]
You don't even need to write data to a file, just check for the existence of one. Then, all your admin function does is create/destroy the file as needed.