Enable Maintenance Mode

Nathan Paton edited this page Feb 15, 2016 · 2 revisions

Sometimes it's important to keep users off the site, such as for upgrades or server moves. Because users messing around + changing data = bad times.

Rather than leave things to chance, we can switch Dolphin into maintenance mode so only admin users can access the site. No, there's no hidden maitnenance option, but it's easy enough to make our own with a little bit of PHP and an HTML file.

Let's make a HTML file

First things first, we'll make the actual maintenance page. Create a maintenance.html file with these contents:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charsetf="utf-8">
        <title>Site Maintenance</title>

        <style>
            body {
                margin: 0;
                padding: 20px;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
                font-size: 14px;
                line-height: 20px;
                color: #333;
                background-color: #f4f4f4;
            }

            .container {
                width: 640px;
                padding: 20px;
                background-color: #fff;
                border: 1px solid #eaeaea;
                -webkit-border-radius: 3px;
                   -moz-border-radius: 3px;
                    -ms-border-radius: 3px;
                     -o-border-radius: 3px;
                        border-radius: 3px;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <h2>Site Maintenance</h2>

            <p>The site is currently unavailable for maintenance. Please try again later.</p>
        </div>
    </body>
</html>

Feel free to customize the text and CSS as needed.

Switch on maintenance mode

Now it's time to switch on maintenace mode. To do this, we'll add some code to /inc/design.inc.php to check if the user is an admin, and if not, redirect them to maintenance.html. Edit /inc/design.inc.php and look for (around line 97):

if(empty($oTemplate))
    $oTemplate = $oSysTemplate;

Add immeditely under this:

if(!isAdmin((int)$_COOKIE['memberID'])) {
    header('Location: ' . BX_DOL_URL_ROOT . 'maintenance.html');
}

That's it. Loading the site while logged out (or logged in as a normal user) should redirect you to maintenance.html.

Mobile Apps

The mobile apps don't really have a graceful way to handle maintenance mode like the desktop site, so for now we'll have to disable them. To do this, edit the /xmlrpc/BxDolXMLRPCUtil.php file and look for (around line 233):

function checkLogin ($sUser, $sPwd)
{

Add directly under the opening bracket ({) this bit of code:

if(!isAdmin((int)$_COOKIE['memberID'])) {
    exit;
}

So that it looks like this:

function checkLogin ($sUser, $sPwd)
{
    if(!isAdmin((int)$_COOKIE['memberID'])) {
        exit;
    }

This will cause a connection error if the user is not an admin. It's not possible to pass custom errors to the mobile apps, so for now this will have to do.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.