I'm am working on a site for a customer. The site owner wants to restrict the editors of the site content only to login from the office.
I have looked for a standard drupal option or contributed module to arrange this. I also searched the forum without result.
I have started working on an own module to restrict certain roles to login only from a know ip/hostname. I have it kind of working but am not happy with the result.
In my editor_access.module I have a hook user. When $op is 'login' I check if the if the visitors ip is on the save list. If not I log them out with user_logout();
Is there a better method than hook_user to restrict user access on ip/hostname?
function editor_access_user($op) {
global $user;
if ($op == "login") {
$safelist = editor_access_safelist(variable_get('editor_access', ''));
$ip = $_SERVER['REMOTE_ADDR'];
if (in_array('editor', user_roles()) && !in_array($ip, $safelist) && $user->uid != 1) {
watchdog('user', t('Session closed for %name using un allowed remote address %ip.',
array('%name' => theme('placeholder', $user->name), '%ip' => $_SERVER['REMOTE_ADDR'])),
WATCHDOG_ERROR);
// message is not showing because session gets destroyed by user_logout()
//drupal_set_message(t('It is not allowed to login from outside the office'))
user_logout();
}
}