I created a Drupal 6 / Ubercart 2 site for one of my clients and wanted to give them access to add products while the site was in maintenance mode.

So I created a "store manager" role and created a user with that role. I placed the site in maintenance mode and sent my client the "store manager" user name and password, but they just see the maintenance page (as expected).

I read some posts that suggest implementing HTTP Access or giving that role "administer site configuration" permission, but I need the custom maintenance page working (since it has important information) and allowing site configuration would be risky.

I figured out a hack and thought I would share. I posted the HowTo on this page:
http://www.ubercart.org/forum/support/1734/can_multiple_administrators_a...

Basically (in Drupal 6) I edited the /includes/menu.inc file. The function to look for in that file is

_menu_site_is_offline()

function _menu_site_is_offline() {
  // Check if site is set to off-line mode.
  if (variable_get('site_offline', 0)) {
    // Check if the user has administration privileges.
    global $user;
    if (user_access('administer site configuration') || in_array('store manager', $user->roles)) {
      // Ensure that the off-line message is displayed only once [allowing for
      // page redirects], and specifically suppress its display on the site
      // maintenance page.
      if (drupal_get_normal_path($_GET['q']) != 'admin/settings/site-maintenance') {
        drupal_set_message(l(t('Operating in off-line mode.'), 'admin/settings/site-maintenance'), 'status', FALSE);
      }
    }
    else {
      // Anonymous users get a FALSE at the login prompt, TRUE otherwise.
      if (user_is_anonymous()) {
        return $_GET['q'] != 'user' && $_GET['q'] != 'user/login';
      }
      // Logged in users are unprivileged here, so they are logged out.
      require_once drupal_get_path('module', 'user') .'/user.pages.inc';
      user_logout();
    }
  }
  return FALSE;
}

I added / changed these lines:

global $user;
    if (user_access('administer site configuration') || in_array('store manager', $user->roles)) {

I added this post to drupal.org forum (in addition to Ubercart's forum) because it affects the whole drupal system!

Comments

markconroy’s picture

I've tried to edit my menu.inc file and edited 'store manager' to 'staff' (having set up a user role called 'staff' and set permission to 'administer site configuration', but I get an error message on screen and the login will not work for the 'staff' user.

Here's my edited code:

function _menu_site_is_offline() {
  // Check if site is set to off-line mode.
  if (variable_get('site_offline', 0)) {
    // Check if the user has administration privileges.
if (user_access('administer site configuration') || in_array('staff', $user->roles)) {
      // Ensure that the off-line message is displayed only once [allowing for
      // page redirects], and specifically suppress its display on the site
      // maintenance page.

Any hints?

============

Drupal Core Maintainer for "Out of the Box" Initiative.

markconroy’s picture

silly me, I was trying to login as the wrong person. Great little hack this. Thanks.

============

Drupal Core Maintainer for "Out of the Box" Initiative.

hedac’s picture

nice ! thanks

ravenBlue’s picture

This hack is great for us who can't yet use D7, thanks a lot!.

I'd like to know if you experienced the same as me: I used the hack and everything goes ok, but in the login page, i got the primary links displayed(not the access to the pages, just the links being displayed), which i am not supossed to have access (because in that moment i am an anonymous user). Is this supossed to happen?.
I'll try to override the login page with a custom template, so i can get rid of the primary links (using zen subtheme, by the way).

If someone finds out a simpler way to get rid of the links, i'd really like to hear about it!.

Update: I used the "page-user.tlp.php" template (copied from page.tlp.php) to override the login page and get rid of the links. Works as intended, but still have the feeling that there should be something simpler to get the same result.

grendzy’s picture

Here is a small module that offers a permission for 'Use the site in maintenance mode'.

offline_access.info

name = Offline Access
description = "Provides a 'Use the site in maintenance mode' permission"
core = 6.x

offline_access.module


/**
 * Implements hook_perm().
 */
function offline_access_perm() {
  return array('Use the site in maintenance mode');
}

/**
 * Implements hook_init().
 */
function offline_access_init() {
  global $conf;
  if (user_access('Use the site in maintenance mode')) {
    $conf['site_offline'] = FALSE;
  }
}
Cablestein’s picture

I installed and enabled the module but saw no new additional option on the User Permissions page. Should I be looking elsewhere?

Cablestein’s picture

comment deleted by author

summit’s picture

Thanks for making this small, but very handy module!
greetings,
Martijn

krembo’s picture

I don't see any permission too. What can be wrong here?

drupalfever’s picture

Look for the "Use the site in maintenance mode" permission

hedac’s picture

This small module is wonderful.

steveoriol’s picture

Very useful module, bravo !
I have just a "remarque", the message box "Operating in off-line mode." does not appear any more...

Stève

drupalfever’s picture

Here is a little change on Grendzy's module to address your issue regarding the "Operating in off-line mode" message, which is relevant:

offline_access.info

name = Offline Access
description = "Provides a 'Use the site in maintenance mode' permission"
core = 6.x

offline_access.module


/**
* Implements hook_perm().
*/
function offline_access_perm() {
  return array('Use the site in maintenance mode');
}

/**
* Implements hook_init().
*/
function offline_access_init() {
  global $conf;
  if ((user_access('Use the site in maintenance mode'))
  && ($conf['site_offline'])) {
    $conf['site_offline'] = FALSE;
    drupal_set_message(l(t('Operating in off-line mode.'), 'admin/settings/site-maintenance'));
  }
}

Remember that you should not use the PHP closing tag in Drupal.

revol’s picture

Beware to add final ?> to the module file, this throws an error and lot of problems on site's behaviour. Here's the error:
warning: Cannot modify header information - headers already sent by (output started at /home/xxx/domains/xxx.com/public_html/modules/offline_access/offline_access.module:19) in /home/xxx/domains/xxx.com/public_html/includes/common.inc on line 148.
Needs confirmation.

hedac’s picture

it should not be a problem..
be careful maybe you entered a space after the ?>

drupalfever’s picture

PHP does not require a closing tag and it is, actually, advisable not to put the PHP closing tags when in Drupal.

uno’s picture

Just the thing I was looking for, thank you.

--
... I mind

eileen’s picture

Curses, foiled again! This is the error message I get when I went to enable your great little offline_access.module.

Is there an easy fix? I'd really like to use this module.

drupalfever’s picture

Thanks, Grendzy! Excellent module!

Anonymous’s picture

beautifully coded, thumbs up

gawi’s picture

That's a tiny module but it works like a charm. Thanks a lot for this!

altavis’s picture

Super-handy module, thanks.

alexmoreno’s picture

another solution, use a simple theme for your site, with a message in your page.tpl.php like: Site in maintenance...

Then allow user themes, edit each user and make availabe for them the theme in which you are working.

For some cases can be a solution.

Thanks