Hi All,

My client needed more flexibility than this module currently has - specifically 2 distinct ranges for a single user - so attached is a modified version of the current 6.x-dev module that allows the following:

  • Single IP matches like "123.123.123.123"
  • Wildcards in any quadrant except the first one - for example "123.123.123.*" or "100.*.*.100"
  • Ranges in any quadrant except the first one - for example "123.123.123.100-200"
  • Any combination of the above with comma separated multiple values like "10.11.12.13, 123.123.123.100-200, 123.123.124.*"

It's inspired by #726242: patch to support 123.123.*.*, 123.*.*.* and other todo's for ip_login and #352102: Support for multiple ips or ranges. (thanks those who worked on them) but a bit cleaner in my opinion and extensible should there be another way to describe IP ranges that is required. I didn't use the multiple profile fields approach as this is a bit ugly and unnecessary with the addition of comma separated values.

I've updated the admin settings page to have new help mirroring the above, plus done a fair amount of testing so please do dive in and have a play.

Hope this helps!

Jim

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jim Kirkpatrick’s picture

EDIT: The version I posted had a bug I didn't spot which, though it matched the IPs fine, failed to log in!

Please use the version in the next comment, not the one directly below...

Jim Kirkpatrick’s picture

Here's the working version...

EDIT: Please use the version in the next comment, as it's loads better!

Jim Kirkpatrick’s picture

Hello again...

In addition to the above, my client needed the ability to have auto IP logged-in users be able to log in as another user. So, based on the great work in #698758: Need a way to switch users or log out (thanks guys!) I have integrated their approach into my improved version that can handle IP ranges etc.

This new version (attached) adds a menu item 'Login as a different user' plus a nice link on the 'auto-login complete' message that, when clicked, clears the session and goes to the login screen.

It uses hook_form_alter to change the login block and page to add a 'Log in automatically' link at the top for users that have already PASSED the IP login check. I've tried also to avoid the overheads of checking too much, but this needs further testing.

The main issues with this version are: a) the code now needs a gentle re-factor & tidy up to hit Drupal coding standards; b) the Drupal-standard 'logout' links clash with the 'Login as a different user' - anyone know how to override the normal 'logout' behaviour/menu item?; and c) needs Drupal community testing/fixing!

It's a little unpolished but seems to work. The attached code represents a much changed/improved version of this module (so much has changed that a patch is pointless!) - please do let me know how you get on...

----

Note that this version is supported by me because it is live on a busy site requiring these features. Any bug fixes or enhancements will be posted to this thread and once this attached version has been tested properly I'll contact the module maintainer to get this - or a version that is similar - released.

EDIT: There's another, better version a bit lower down, use that one instead.

generalelektrix’s picture

Title: New version supports comma separated values, IP ranges and wildcards » Improved: now supports logging in as alternate user plus comma separated values, IP ranges and wildcards

Thanks Jim! I will try this new version on my test site. I wish the maintainer would give us a feedback about all this contributed work or simply pass the torch if he's too busy since this is a very useful module.

generalelektrix’s picture

Just installed it. I have a user with IP range 132.203.*.* (our class B network) in its profile_ip variable, when I'm logged in as a normal user, I can use the "Login as a different user" link and it works. However, when I try to login back by IP, it does nothing, i.e. when I click on the Log in automatically, it fails to log me in by IP, leaving me unconnected.

Some suggestions. I would prefer to see the "Log in automatically" link appear in the Navigation Menu instead of in the login page, or at least let the admin be able to configure where he wants to see it. It would also be great to be able to configure the text of the link. "Log in automatically" is a good generic label, but here I use it to login users that plays the role of institutions. So in my case, I'd like the label to be "Log in by my institution IP", or something like that. Last, but not least, when the user clicks on "Login as a different user", he is taken to /user. I'd prefer to be able to send him to the website's home page, or be able to configure the destination.

Jim Kirkpatrick’s picture

I think it's a caching issue as it works fine with Drupal's caching disabled but on 'normal' the login as a different user error happens. I'll take a look.

And I was thinking about adding some admin options and your suggestions are good ideas, so I'll try to add some of them too.

I'm a bit busy for the next week but will try to get an improved/fixed version done soon.

generalelektrix’s picture

Hi Jim,

Thanks for quick response. No caching here, I disabled it long ago because of the problem you mentionned with login as a different user. My server is performant enough and most requests to it are from connected users, making the cache almost useless.

As soon as I have time I will review your code and post my comments. I hope this can be done by the end of next week.

Just to let you know the context, the site I'm working on is a research university library site dedicated to bilingual (english/french) controlled vocabulary in document indexing. I could say it's the french version of the Library of Congress Subject Headings (LCSH). I also have a whole LOT of issues concerning localization I must address at the same time!

Thank you for your work on this.

Jim Kirkpatrick’s picture

FYI I'm working updating this code right now to use hook_boot and the caching issue outlined in #5... Once it's tested I'll post back here.

More soon!

Jim Kirkpatrick’s picture

Ok, a fixed/improved version is attached.

This is a mild refactor of the code to tidy up some definitions in introduced and use hook_boot instead of hook_init (See #509028: doesn't log in until after second page load) to avoid caching and (hopefully) improve performance. It also appears in my first batch of testing that it's stopped the caching problem noted in #5. I also ran it through Coder module and fixed a few things.

The 'log in as another user' has been fixed, with its menu item being ditched in favour of hook_user method, so I've managed to get the standard Drupal logout mechanism calling my code which logs out and sets session flag to avoid automatically logging back in. It seems to work much better than before, though there's a chance this module could stop other modules' hook_user($op == logout) from being called... Probably depends on module weights and may not even be an issue - or at least a rare corner case.

I'm now going to add some admin settings based on suggestions by generalelektrix in #5. I have also contacted the module's maintainer, davidwhthomas, to get his input as I hadn't yet done so (my bad, just very busy) - hopefully he/I/we can begin the process of getting these improvements folded into a new DEV release.

Please test and let me know it goes... Any suggestions or issues post here please!!!

Jim Kirkpatrick’s picture

Thought I'd post these here...

Settings I'm suggest adding to the module's admin screen

  1. [x] (checkbox) "Allow users who are logged in by IP to log out and choose another user." -- this would ideally disable the logout menu option, or failing that override the 'log in as another user' feature to force users to log back in immediately, essentially preventing logging out.
  2. Log in by IP automatically links & text:
    • [x] Show IP Login link in Navigation block

      Text to use for link [ text box, currently "Log in automatically" ]
    • [x] Show IP Login link on User Login block

      Text to use for link [ text box, currently "Log in automatically" ]
    • [x] Show IP Login link on User Login page

      Text to use for link [ text box, currently "Log in automatically" ]

      Explanatory help text underneath link [ text box, currently "Your computer's IP address has been matched and validated." ]
  3. Destination (Drupal path) of after login [ text box, normally "user" ]

Other To Dos on my list:

  • (DONE in my next version) #818022: replace $_SERVER['REMOTE_ADDR'] with ip_address() to handle proxy servers better
  • Check usage of $GLOBALS['conf']['cache'] in ip_login_attempt_login() - not sure it's needed, or if it even does what I think! must test...
  • Possibly integrate with Content Profile as source of IP addresses for users?

If anyone has any comments or other simple admin screen settings, please post them.

generalelektrix’s picture

Ok, tried the new version. Here are my comments.

The only serious glitch it that when I'm not connected and click on "Log in automatically", I get redirected to /ip_login_as_different_user. That's weird. I get the message "Welcome Institution. You have been automatically logged into My Test Site. You can also log in as another user.", but Drupal also gives me a page not found error.

However, I'm now really connected as "Institution". So, I go back to the website home page and I can logout without being automatically logged in back by IP. This works exactly as expected.

The "Log in automatically" link is there, in the user login form. I wonder if we could put it below the username/password input fields instead of above. I'd also like to see this link appear in the navigation menu.

Thank you, it's a great improvement over previous versions.

generalelektrix’s picture

Again, very useful explanation of what you are going to add in the admin interface.

My only suggestion would be to make the Explanatory help text underneath link [ text box, currently "Your computer's IP address has been matched and validated." ] optionnal by adding a checkbox.

Indeed, one might want to avoid giving technical details to some category of users. :-)

Everything else is in line with what I asked earlier. Thanks.

Jim Kirkpatrick’s picture

Did you flush the caches and rebuild the menu first? I changed some menu entries so that might explain why you're seeing links for /ip_login_as_different_user (which is no longer in the code) instead of just using the existing /logout page... Let me know - that page you mention should not exist.

All your points regarding admin options are taken on board, including a weight option for "Log in automatically" link on the login page/block. Thinking about it, I'll probably just make the system hide text/links if the admin field is left empty to save messing around with a load of extraneous check boxes.

More soon,

Jim

Jim Kirkpatrick’s picture

Ok, yet another version - and this one is good! I have:

  • Implemented hook_perm and added two permissions: "administer ip login" self explanatory; "can log in as another user" which allows users who are logged in by IP to log out and choose another user. Users who don't have this permission are simply logged straight back in again, which is what the current release version of this module does. I'm not able to hide 'logout' via hook_menu_alter, so will perhaps later inject some CSS to hide the 'Log out' menu link... Not sure, seems brittle - ideas?
  • Fixed the improper (D5) use of url() I cut/pasted from ipAuthenticator (oops!)
  • Implemented #818022: replace $_SERVER['REMOTE_ADDR'] with ip_address() to handle proxies properly
  • Tried to ensure security where possible using filter_xss_admin() and adding an admin screen warning if the chosen profile field's visibililty isn't "Hidden".
  • Tried to ensure the interface is completely translatable.
  • Updated admin settings:
    • Moved admin menu settings code to ip_login.admin.inc file for performance and clarity.
    • Implemented hook_help
    • Added options for link text and visibility for Navigation menu item, and login page and block.
    • Added option for different destination after IP login to override the user's original requested page
    • Added weight options for auto-login links so they can be placed anywhere within the login page/block's form

I haven't yet added the option to log in automatically to the menu as I'm still not sure the best way to do this for now.

Jim Kirkpatrick’s picture

Just added a failsafe so that people can still override the auto login if running from their own computer (i.e. their IP is 127.0.0.1)... Caught myself out and couldn't break out of a test account without hacking the code!! At least the permission checks work! ;-)

I guess the code should also check the server's IP too, and allow requests from that machine to log in, though that's slightly less important because servers will be 127.0.0.1 to themselves anyway.

So the _ip_login_can_use_alternate_account should have this extra line before the return line:
if (ip_address() == '127.0.0.1') return TRUE;

Jim Kirkpatrick’s picture

Oh and PLEASE REMEMBER to clear your caches and rebuild the menus to avoid weird errors...

msamavi’s picture

The recent version does not work properly in Google Chrome for Mac!

[Fixed]

msamavi’s picture

Another problem in the recent version:
If you leave the option "Destination after IP successful login" blank, the user is always sent to the frontpage after automatic logging in, while 'send user back to their originally requested page' is expected.
Thanks

Jim Kirkpatrick’s picture

@msamavi:

#17 - This module is not client side or browser dependent, there can be no issue with it under Chrome. I use Chrome under Linux and have seen no browser-related issues at all.

#18 - Works great for me - if a request comes in from an IP-match user wanting, say, http://www.example.com/somepage they get logged in and sent back to http://www.example.com/somepage?ip_login_no_cache=b8fe4285c0c0de2b03af76... (or some other md5 hash). Are you sure the field in the admin screen is completely blank? All the code is doing is getting the original request and sending it though Drupal's url() function. It works as far as I can see, and I can't see a way for it not to...

generalelektrix’s picture

I installed v5, emptied cache, rebuilt menus. Bad link and page not found error solved. However, something weird happens. When I'm connected as a normal user and then logout, the module connects me by IP, but I get these 2 messages:

This account does not not have permission to log out once logged in automatically.

* Welcome Université Laval. You have been automatically logged into RVMWeb *** TEST ***.
* You may also log in as another user if required.

Huh? Funny cause I'm sure I gave this account the access right to ip login as a different user.

And when I try to logout again by clicking on "log in as another user" I still get the same messages. I'm stuck there, can't log back a normal user without reverting to v4.

Jim Kirkpatrick’s picture

There are permissions to be set to allow users to log in as another user... Please check them and use v5 if possible as it's generally better. Full instructions on the top of the admin screen.

Jim Kirkpatrick’s picture

As for the contradictory messages, I think it's just that the security on logging out needs a little tweak since I made some last minute changes. By default users, except Administrators and those coming from 127.0.0.1 CANNOT log out without being logged back in - this is what the current LIVE version of the module does. Once you've set the permissions for the roles that can log out and log in as another user, these issues will go away.

I'm working on v6 now, mainly tweaks and bug fixes - more in a few days.

generalelektrix’s picture

Ok, I found out why I always had the can't login as another user message.

In order to have my user log in as another user, I had to enable one of its roles (it has 3) and also the Anonymous user role to "administer ip login" and "can log in as another user".

Is this normal? I thought that enabling those permissions to only one role would be sufficient. I never thought I would have to enable it to anonymous user too.

Thanks.

Jim Kirkpatrick’s picture

Hi generalelektrix, no that's not normal - it's a bug I literally just fixed the minute before I saw your message!

v6 attached, should fix a couple of weird issues like the ones you mentioned, plus tidy things up a little and use Drupal's t() function more appropriately.

generalelektrix’s picture

Outstanding.

Been able to translate most of the strings, but I can't find a way to translate the "Log in automatically" link from the user's login page and block. I'm able to find the string in i18n, enter a french version, but still get the english version displayed when I switch to french.

Outside of that, everything works as expected.

Jim Kirkpatrick’s picture

That should be an admin screen option? In the 'Login page link' and 'Login block link' sections at www.example.com/admin/settings/iplogin...

I've checked the code and all occurrences of "Log in automatically" are wrapped in t() and therefore - apart from the admin screen settings above - should be translatable. Maybe also try flushing the caches again if you're still not seeing it.

There are a couple of minor issues with v6 so v7 will be along sometime this week. If you have any suggestions for other improvements, let me know.

generalelektrix’s picture

Gotcha!

At line 148 of ip_login.module, Change:

$link_text = variable_get('ip_login_link_login_page', t('Log in automatically'));

To:

$link_text = t(variable_get('ip_login_link_login_page', 'Log in automatically'));

Same thing with line 163. Translated string will now appear in both user login page and user login block.

Problem was it only translated default text, now it also translates what's stored in the database.

Jim Kirkpatrick’s picture

Thanks generalelektrix, but after a bit of research, that approach is not recommended; from http://api.drupal.org/api/function/t/6 :

However tempting it is, custom data from user input or other non-code sources should not be passed through t(). Doing so leads to the following problems and errors:

    The t() system doesn't support updates to existing strings. When user data is updated, the next time it's passed through t() a new record is created instead of an update. The database bloats over time and any existing translations are orphaned with each update.
    The t() system assumes any data it receives is in English. User data may be in another language, producing translation errors.
    The "Built-in interface" text group in the locale system is used to produce translations for storage in .po files. When non-code strings are passed through t(), they are added to this text group, which is rendered inaccurate since it is a mix of actual interface strings and various user input strings of uncertain origin.

This means strings users enter through the interface should not be translated... As is the case in Drupal core (e.g. http://api.drupal.org/api/function/system_site_information_settings/6). So the current approach is correct, and users must manually override these strings in the admin interface because the defaults are translatable from English automatically - IF the correct .pot file exists (e.g. fr.pot). Does that make sense? I've never done translations...

However, if you felt like contributing to help this module it would be amazing if you fancied making an actual translation of its interface to French using Drupal's inbuilt methods - See http://drupal.org/translators and http://drupal.org/node/220341... It's a big ask, I know, so no pressure whatsoever, but that would really improve things for other French speakers. If you're interested, shout, and I'll post v7 which includes some grammatical improvements.

generalelektrix’s picture

Thanks for the reference. I will look at how to translate this later. Now, I started working on a french translation for the module. While doing so, Drupal gave me those cute messages:

  • The first two watchdog() parameters should be literal strings. There should be no variables, concatenation, constants or even a t() call there. At watchdog('user',$message) in ip_login.module on line 256. Read more at http://drupal.org/node/323101
  • Invalid menu 'title' definition found in ip_login_menu(). Title and description keys of the menu array should be literal strings. In ip_login.module on line 98. Read more at http://drupal.org/node/323101
  • Invalid menu 'description' definition found in ip_login_menu(). Title and description keys of the menu array should be literal strings. In ip_login.module on line 99. Read more at http://drupal.org/node/323101

They will probably help you making this module i18n ready. Coming soon with a .po file.

generalelektrix’s picture

FileSize
7.09 KB

First draft for french translation.

generalelektrix’s picture

So the current approach is correct, and users must manually override these strings in the admin interface because the defaults are translatable from English automatically - IF the correct .pot file exists (e.g. fr.pot). Does that make sense?

What do you mean by the correct .pot file exists? Where is this .pot fils supposed to be located in my Drupal file system?

My site is multilingual, the default language being French. I used POTX to extract a .po file ready for translation and added all the translations using the latest version of POEdit, then loaded the .po file back in. It worked like a charm, the interface being translated, except the introduction paragraph in the admin interface, which you will probably be able to solve in an upcoming version. That's the ip_login.fr.po file I made available yesterday.

However, when I want to give a french equivalent to the "Log in automaticaly" links in the admin interface, it doesn't work. If I enter the french version of the string in the french admin interface, it remains in french when I switch to the english admin interface. And vice-versa. That's where I'm stuck. Hope you can help with that.

Thought I had found the solution earlier by tweaking the position of the t() function, but it seems it's not good practice. FWIW, this is the source from where I took inspiration for this hack: Translating or internationalizing an Ubercart store: Common problems & solutions.

On an unrelated note, I had a new request today from users. They need to be able to get automatically connected to the site by IP address using our wireless network. The fact is that when connected thru our wireless lan, they can be anywhere in the IP range 10.*.*.*. So, I will need to be able to authenticate people in a class A range. Would you be able to add that functionnality too? Thanks.

Jim Kirkpatrick’s picture

Hi generalelektrix, thanks for all that... I'm just tweaking the module and will post v7 shortly.

Having thought and looked about more, I think your original solution in #27 is the right one. I mean, it's not the 'correct' way to do it, but then that means Drupal's translation methods don't support user entered strings without your method, so I will move the t() outside the variable_get() method.

I'll also look into getting that .pot file you posted into the module - thanks so much for that! More later.

And on your last point: 10.*.*.* is already supported - wildcards and ranges can be in any quadrant of the IP address except the first. Can you confirm it works please (does at home when I use 127.*.*.*)

generalelektrix’s picture

Ho great, yes 10.*.*.* works, sorry for bothering you about that.

I suppose I will have to re-work a new .po file for the v7 version. There shouldn't be much differences and will not take long to do, so don't waste time trying to add the actuel .po in your new version. Once you publish the v7 version, I will publish a .po for v7.

I think we can now begin to wonder what's going on with the maintainer of this module. Haven't heard for him since the beginning of this thread. I sent him a private message a couple of weeks ago and got no response. Do you have an idea?

Jim Kirkpatrick’s picture

v7 attached!... Thanks for all the .po work! A only a few strings have changed since the last version, just for clarity and grammar, and I've also wrapped the help text in t(), too. I also fixed those translation issues you raised in #29.

I've spoken to David (the maintainer) via email and he said he was happy to see the module evolve and thanked me for the work I've done. He had reservations about the security of allowing wildcards and ranges in IPs, and suggested using Regular Expressions instead. I said many use-cases for this module (intranets or large institutional clients) need an IP range/wildcard and most web admins do not know regexp and so that would represent a serious barrier to use for many people. I suggested that RegExp should be an option, not a replacement for more human-readable IP matching. As a result of that I also suggested (then added) the code to warn users about having the IP address profile field set to anything other than 'hidden', plus I re-checked my IP matching code and cannot see a way to corrupt it really since any strings that don't contain numbers will be thrown out.

I also offered to become a co-maintainer of the module since I have a paying client who needs this module and am keen and getting pretty experienced at Drupal coding... No response to that or any of the points above as yet. I'm sure he's busy and will get back to us when he has a moment - I know he's got his eye on the issues list so hopefully he'll weigh in shortly... Hello David?!

Anyway, I feel this version of the module is a huge improvement in many ways from the 'official' version - I really hope it can become a 6.x DEV even a v2 alpha/beta release at some point soon. I'm also happy to help updated the module page's documentation if needed.

generalelektrix’s picture

FileSize
9.61 KB

Here's the v7 .po file for french translation. I added all missing strings and corrected typos.

Only issue I see with v7 version is in the file ip_login.admin.inc at lines 74, 80 and 99. Just apply the t() function as you did for ip_login.module so translated values can be displayed in the french admin interface.

We are very close to a beta version now.

Jim Kirkpatrick’s picture

v8, with changes you requested in #35 and the French translation, thank you... I think the module is pretty much done - hidden bugs aside - isn't it?

davidwhthomas’s picture

Thanks again Jim,

I'll have a good look through this shortly with the aim to commit to dev.

cheers,

David

davidwhthomas’s picture

Jim, a question re: the drupal_bootstrap full in ip_login_login, is that neccessary or would drupal_bootstrap session suffice?

hook_boot seems like a good option to get around cache issues.

The module is certainly a lot longer than the original, I wonder if these features are all needed for the general user...

Nevertheless, at the moment looking good, will possibly commit as a new 6.x-2.0 branch

DT

derrynairn’s picture

Category: feature » task

Hi there

First of all, thank you for doing such useful work on a promising but limited module. I need to implement complex IP Access for some educational institutions on a test site, and it sounds like the changes you have made will do the trick.

I'm just wondering about the contents of the update. Is it a full, improved version of the IP Login module, or an add-on? ie. Do I need to leave the original module in the system when I install it?

I ask because I presumed that I needed to delete the original version, and then commit your version in full instead. But it's not showing up in my modules admin area when I refresh. I think I'm missing something very simple in the installation process...

Apologies for such a newbie question, but this is the first time I have experimented with a test update of a module.

Thanks
Derry

Jim Kirkpatrick’s picture

Category: task » feature

Hi David, (#38)

Great that you're thinking about committing this soon - I'm really glad to have been able to contribute.

hook_boot solved the caching issue nicely, yes, but as you say it meant I had to manually boostrap Drupal to get access to all the relevant functions. The reason I added the full bootstrap was because of the call to url() in ip_login_login - I tried lower levels of bootstrap but it didn't work. I realise it's not the ideal choice - indeed, I did start by trying to include_once the right files, but each needed ever more dependencies so in the end I just boostrapped the whole lot as it felt less hacky, if perhaps not as efficient. If anyone has better suggestions or ideas, I'm all ears...

The module is definitely longer... However, the code that does the hard work of IP checking is very small (smaller than before, tidier definitely). After the 'core' there's a function for logging in as another user and some hooks for overriding the login blocks/page and providing better help. After that, the rest of the code lives in the .admin.inc which is only called for the admin page. I certainly don't think it's at all bloated as it sticks to the core purpose of the module but fixes a couple of omissions from the original while adding administrative flexibility so people don't need to override basic theme methods. The 'general user' is, given the types of users with known, fixed IPs: intranet users, home developers, institutional users/clients etc. I feel the new features help all categories of user - indeed, everything I added except a few admin screen options was needed by my client and others on this issue tracker. Is there anything specific you feel doesn't belong?

Jim Kirkpatrick’s picture

Category: task » feature

@Derry (#39): I'd just install the current version of IP login (as it sounds like you already have), then extract the improved v8 zip file over the top of it... Or just install v8 directly - in either case the ip_login folder with the files inside should live in /sites/all/modules. In other words, using a test/dev version of a module is exactly the same as using a release version as far as installation is concerned. Good luck.

derrynairn’s picture

Category: feature » task

Thanks for the swift response, Jim.

The error my SVN tool (Tortoise SVN on Windows) is giving me is on v8 is: Error: containing working copy admin area is missing

I tried to install v7. Unlike v8, it uploads OK via SVN, but then is still not visible on the Module admin page.

The IP Login Settings page (admin/settings/iplogin) is still available in my Site Configuration admin menu, but records the following error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'ip_login_admin_settings' was given in /mnt/www/html/historytoday/docroot/includes/form.inc on line 372.

EDIT: OK I cleared the cache and it seems to have worked. Thanks for your help above.

generalelektrix’s picture

Category: feature » task

v8, with changes you requested in #35 and the French translation, thank you... I think the module is pretty much done - hidden bugs aside - isn't it?

Yep, all done. It's installed on my test site. I will keep it there for a while and proceed in production after a complete testing of all functionnalities. The version I have actually in production does the same thing, but it's hackish and does not have an admin interface as complete as v8.

You have done some great work in a short time. We now have a valuable module that fits a large range of IP login needs. Even those with dynamic addressing could benefit of it since it allows all kinds of IP ranges to be defined.

For those interested, here's the use case for us:

Our web site is a bilingual (french/english) site designed to serve institutional clients. It serves many purposes: a search engine (specific to a subject thesaurus for libraries cataloging, kindof like LCSH but in french), an automatic english-french subjects translator, a blog, a forum, headings suggestion forms, etc.

Users are recognized by their IP address and then logged (using this module) on to their institutionnal account (example: Library and Archives Canada), which gives them access to a restricted set of functionnalities. They can then, for example, search the thesaurus, but they cannot use the translation engine. Once they create themselves a personnal account, they can use it to unlock access to other privileges they are registered to like translation, forums, new headings suggestions, comments, personal preferences, etc.

So IP recognition is a way to give institutional users intermediate privileges. They can do a quick search without having to log in each time.

davidbessler’s picture

Is there a way to have it actually automatically log in if the ip address is matched instead of bringing me to the login screen where I can click on the "automatically log me in" link? Am I doing something wrong?

ip_login used to behave like that, I think. I would suggest, that there be a checkbox under the ip address in each user that allows you to "log in automatically" vs "ask before logging me in automatically".

This way for my institutions I can use "log me in automatically" but for anybody else, they can leave it as is.

**Update**
For the time being I have found a temporary solution that works for me. I have my server set up with drupal installed in its own directory and an index.html file with the following code:

<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://mydomainname.com/drupal/user/login_by_ip'>

which forwards to drupal. It used to forward to the frontpage, but I changed it to forward to /user/login_by_ip instead so now, when you go to mydomain.com you get logged in by ip if you match, and sent to the login screen if you don't. perfect, since nobody in my company is saavy enough to link directly to pages, and all my terminals have their browser homepage set to mydomain.com

cheers

msamavi’s picture

I need auto login just for some specific pages/paths or nodes, not the whole site. Can you please implement the Activity settings for the module (a feature like Visibility settings available for blocks and nodes)? So, browsing the specific paths/pages/nodes the auto login works, and out of those pages, only normal username/pass login would be applicable. I mean options like following:

"
PAGE SPECIFIC ACITIVITY SETTINGS
Show block on specific pages:
Show on every page except the listed pages.
Show on only the listed pages.
Show if the following PHP code returns TRUE (PHP-mode, experts only).
"

Jim Kirkpatrick’s picture

@msamavi - Interesting, but that's a pretty big feature request that takes the module in a new direction. Please open a new 'feature request' on the IP Login issue tracker so it can be discussed separately and perhaps integrated if the community thinks it's a goer.

Jim Kirkpatrick’s picture

@davidbessler: "Is there a way to have it actually automatically log in if the ip address is matched instead of bringing me to the login screen where I can click on the "automatically log me in" link? Am I doing something wrong?"

It's working as designed, and behaves _exactly_ like the old module EXCEPT: if you've logged out a flag is set in the session to allow you choose another account rather than be logged in automatically... This only happens for users with the correct permission AND/OR visitors from 127.0.0.1 to avoid being locked out of the admin section of your own site (as happened to me)! When I try it on my machine (using an incognito window on Chrome) I'm automatically logged directly as expected.

I would: clear your caches to be sure then open the site in a clean session (using incognito mode or equivalent for Firefox etc) and it'll work fine - UNTIL you log out, in which case the 127.0.0.1 test will set a flag so you get the option to choose another account rather than auto-logging in.

It's a deliberate safety feature to avoid users with 'administer' permissions or home developers being locked out of the site. Your temporary solution is simply bypassing these checks I added and logging in directly.

Please confirm...

davidbessler’s picture

You're right. Seems to working as expected. I am still going to use my workaround because it avoids any situations involving cache-clearing for my employees. Thanks for all your hard work!

davidbessler’s picture

We are having all sorts of trouble with this. When a user logs out, it frequently takes us back to a page with no "login automatically" option.

The behavior that would work for us would be a timeout function for logging in as a different user, so you logout and have 1 minute or so to log in as a user, otherwise it goes back to logging in by IP.

For the meantime, we are going back the old version. Do you have patch for just the multiple ip address changes only? That part is working great!

Jim Kirkpatrick’s picture

Hi David, could you explain exactly the process, your settings and what isn't working for you? Are you still using your 'hack' from #44? I'd remove it if so as it could short-circuit the process... Have you set up the ip_login permissions correctly? Have you disabled Block Caching (perhaps the cause of the missing option)?

Version 8 is working fine for me and, I believe, generalelektrix so without being able to reproduce your problem(s) I currently don't understand what's going on. I will certainly try to look into this as soon as you reply with more steps/details though.

The 'log in as another user' feature is required by me and several others and I think v2 above is the last updated version that has multiple IPs/ranges/wildcards but not that feature, however it's buggy and had a problem with caching.

Let me know, keen to get to the bottom of this.

Jim Kirkpatrick’s picture

@David: actually about 10 minutes after posting the above my client said one of their users is having an issue similar to what you describe. Please do post any/all information you have to help me track this little bugger down! Thanks.

davidbessler’s picture

Block caching was disabled

I reinstalled your update ... we don't have a test site and we have about 500 users who all know me (and my family ;) so this means I will start getting all those emails again.

I am trying to reproduce the problem. I did not re add the hack #44 in order to rule out that as the cause. We discovered the problem intermittently, and it may be hard to reproduce.

In the meantime, can you figure out a working way to replace my 'hack' #44? I think this feature would be very useful. "Log in by IP after X seconds on the login screen".

generalelektrix’s picture

If you come up with a procedure to reproduce the problem, I will try it on my test site.

Jim Kirkpatrick’s picture

A little update: My client's issue does not appear related to IP login at this stage, but we're still investigating that one and will keep you posted.

I've now tested and re-tested the various code paths around auto login, logout and registration etc on my DEV machine but am yet to see this issue. As soon as I get more information I'll certainly be on this like a fat kid on a tasty tasty cake...

---------------

@David/#52 - your idea is a good one, but it's a new feature - I saw nothing in the original code that could do what you're asking. Anyway, it's a nice idea and could be implemented in one (or probably both) of these ways:

  1. A timestamp in the session that, once expired, will auto-login on the next page request.
  2. Additionally/alternatively some client-side JavaScript/jQuery that puts a little I'm thinking a little countdown timer in the login block/page that then sends the to the user/login_by_ip page when it gets to 0. It might be annoying for users to be pulled away from what their doing though, so perhaps that's either an admin option or just a timer telling the user that they will be auto-logged in as per (1) above?

There would need to be a new admin screen field to configure the timeout variable too... Has anyone got any further thoughts on this?

generalelektrix’s picture

I prefer idea #1. I don't like the idea of scripting that client side with a redirect, sounds irritating. A timestamp that resets ip login status seems an easy and convenient way to solve this matter.

I would probably use it to ensure my client's institutions get recognized by IP after a while if they didn't login with their personal account.

This would need to be an option disabled by default and a default timeout of 300 seconds (5 minutes) seems fine.

Jim Kirkpatrick’s picture

OK, there are too many issues in this thread now and I don't have time to look at any of them for at least the next week due to other commitments.

So I propose:

  1. Version 8 is moved into the 6.x-2.x-dev branch and continues along side the current version 1 until it's proven and can go to beta, rc or 2.0 full release. This allows other people to submit patches again, too.
  2. The 3 related related issues (auto-login timer, specific pages login occurs, possible intermittent bug) raised in this issue ticket are split out into separate ones, then this issue is closed so the issue tracker works properly again for the new branch.
  3. I think it would be good if were made co-maintainer of this module since I've largely rewritten it, have a paying client needing my rewritten verison, have 3 years Drupal and 12 years web development experience, am keen and am offering my help. Plus I'm on Drupal.org and developing most days, too.

What do you think David? Anyone?

generalelektrix’s picture

I perfectly agree with all of that, and especially the part where you suggest becoming co-maintainer!

davidbessler’s picture

I agree as well. Got my vote.

Anonymous’s picture

Getting this error with your v8 in my site report shown after I log out (I logged in normally, not through IP Login if it matters):

session_destroy() [<a href='function.session-destroy'>function.session-destroy</a>]: Trying to destroy uninitialized session in /home/web/actonweb/v4.acton.org/sites/all/modules/ip_login/ip_login.module on line 312.

Any way you could get this fixed?

Jim Kirkpatrick’s picture

Hi vilepickle... That line is a belt-and-braces- approach to ensure a session is completely destroyed before logging an account in and redirecting them. ipAuthtenticator (where I believe that snippet of code got copied from) had it, and it makes sense in a paranoid way. The code is:

// Destroy the current session, if we have one
if (session_name() <> '') session_destroy();

And there are two solutions:

  1. Remove/Comment out the line - which will remove this extra safety but probably cause little or no side effects in the real world.
  2. Make sure the IF statement actually properly detects the case where the session is not initialised, and therefore doesn't try to destroy it unless it's actually there.

So you can certainly remove that line in the mean time if you don't want to have the logged errors. I'd rather we did 2) though. I'm going to roll version 9 in the couple of next weeks. It will have a couple of very minor tweaks and some extra diagnostics in place.

The nebulous bug mentioned earlier in this thread (#49) has not materialised for my client at all, nor for me during my testing, and since no one else has complained or provided any information and the processes used by this version are mostly the same as the original module, I'm now of the opinion no such issues exists. But then having a proper issue tracker would be NICE so others could get involved!

It would be really great if David Thomas (davidwhthomas, the module maintainer) could let us all know his plans and answer the points in #56 soon. Hello, David? There's at least 5 (probably more) people using this version of the module, when can we move this to the 6.2.x branch so we can all contribute quickly and clearly please?

Anonymous’s picture

Jim,
Thanks for the response. I will leave it in there now and wait for your next version that properly checks if the session is destroyed. I guess it's better to have the check there and give an error for now (it's extra assurance that the session will be destroyed) and in your next version it won't pass the check when it shouldn't.

It would indeed be nice to have your version folded into the module itself... the wildcard functionality is essential for the site I administer.

generalelektrix’s picture

Hi Jim,

I've been on holidays for 3 weeks, back to work now. I have not seen bug #49 here and I've been testing for several weeks now. I would love to see version 6.2.x go out soon cause I'm waiting for such an official version to put your version of the module in production. I will for sure test v9 when it comes out.

johnv’s picture

Jim,
very nice add-on to the module, you can add 1 to #60! (ofcourse, all credits to David)

However, I have the following case:
If an anonymous user (with known login_IP-address) visits my site, he would be redirected from the root to www.example.com/homepage, where he must click the button 'log in automatically'. This is one click too many... Can you avoid this step?

I have the following workaround, which works fine:
- admin/settings/site-information: default front page = from 'homepage' to 'user/login_by_ip'
- admin/settings/iplogin: Destination after successful login by IP = 'homepage'
- admin/user/permissions#module-ip_login: can log in as another user = Yes (for authenticated user) and No (for anonymous user)

So now, if a user with matching login_ip visits my site (he is not logged in yet, hence anonymous), her gets redirected, logged in and redirected again to homepage. That's fine :-)

However,
if the anonymous user visits my site from another PC, or his login_ip is not maintained, he gets bounced to root page, and not homepage.
root page is not maintained (since redirected to homepage) and now shows only "Access denied - You are not authorized to access this page. "
This wouldnt be a problem if the block 'user login' shows, but is isn't.
The workaround for this scenario is : provide the (frequent) user with the correct URL, which is www.example.com/homepage

So, can you create a really automatic login?
An option for my workaround would be: add to setting the following: "Destination after UNSUCCESSFUL login by IP"

But I feel that this module should not mess around with the 'default front page'.

Jim Kirkpatrick’s picture

Hi All, just a quickie to say I've just finished a bunch of hectic work and am about to move house... I will try to get v9 up and answer any recent questions later this week. Sorry for the delay, Jim

johnv’s picture

update on #63,
I wrote: "(user gets a 404-page) This wouldn't be a problem if the block 'user login' shows, but is isn't."
I solved this by installing the following module: http://drupal.org/project/blocks404
Regards, John

generalelektrix’s picture

FileSize
104.9 KB

Hi Jim,

I don't know why, but I've been unable to make v8 work on my Prod server. When I installed the files (and emptied caches) and installed the new version of the modules, I tried to logout and login back by IP, but the link to do so was not available in the login page. So I tried to login back by IP using the URL (user/login_by_ip) and the result can be seen in the attached jpeg. I don't undertsand why as I have set all the correct permissions (also see attached jpeg). I also attach IP login configuration in the same jpeg. I might be missing something very obvious, as usual!

I had to revert to my old version temporarily in order to find a solution.

Thank you,

Sébastien

johnv’s picture

Sébastien,
is this the same problem I described in #65 ?
Groeten, John

Jim Kirkpatrick’s picture

Hi guys.. Am moving house for the next couple of days but afterwards the workload is much lighter - will get on this ASAP. Jim

generalelektrix’s picture

Seriously, I have trouble understanding all that you explained in #63 and #65, so I couldn't say. Actually I have the following problems when I install v8:

1- The login page and Login block links do not show when I'm logged out (they should cause that's the only way can log by IP after a logout).

2- When I try to go to http://example.com/user/login_by_ip manually to login by IP, I get an access denied message.

There's something stuck somewhere, might it be another module that prevents IP Login from working, I don't know. I will try to disable them one by one and see if it makes a difference.

To Jim: I hope you enjoy your new house. Congrats!

UPDATE: I disabled all other non-core modules except IP Login, emptied caches, rebuilt permissions and I still have the problem.

dabblela’s picture

Thanks for all your work on this, Jim. Have you contacted the maintainer of ip_login to become a co-maintainer or take over maintainer-ship? I have some improvements I'd like to share, but it'd be great if we could make it 'official.'

On a separate note, this module seems to break Drush - don't know if it's the original or the modified version, but I'm looking into it.

Anonymous’s picture

My drush has been working with the modified version.

TDobrowolski’s picture

Thanks for the great patch! It helped me a lot.
My opinion still is, that this module should have an ability to assign a role to certain IP-numbers, like the module IP Authentication used to do earlier. I´ll try to describe my needs.

Basically i have three user profiles, which are maintained by roles:

1. Anonymous visitors (Have right to some of the materials of the site)
2. Personal users (have right to all the materials of the site). The log in via their account.
3. Institutional users, ie schools, univercities, etc (have right to all the materials of the site). They must be automatically logged in by IP-number.

When institutional user is loggen in, they unfortunatelly do not have a possibility to create their own account. This way they cant subscribe to the simplenews newsletters or do anything else, that the users with the personal account can do.

Jim Kirkpatrick’s picture

@All: Feel like I'm perpetually putting this off, really sorry guys. I'm still somewhat 'homeless' and my broadband in my temporary office is, frankly, shit. If anyone wants to debug in the mean time, go for it! A comparison of the differences between v6, v7 and v8 might show the cause of issue... Otherwise I hope to be more settled and ready on this for next week. Thanks for your patience.

@TDobrowolski: This module doesn't really work like that. It associates an IP address (or range etc) with a user account. Since the account must already exist, it will already have roles assigned. It's beyond the remit of this module to assign another role, though there are modules that could do this. (Perhaps this module could use Rules integration or something? Hmmm...) In any case, fine control over roles based on IP isn't what this module does, sorry.

Best,

Jim

scotwith1t’s picture

subscribe. i'm particularly interested in at least being able to assign a range of IPs to a user that goes deeper than the first octet. i'm dealing with universities whose ranges can be like xx.xxx.26.* - xx.xxx.94.* and I just can not feasibly use this module as is without creating dozens of users (.26.*, .27.*, .28.*, .......yuk!) That said, I certainly couldn't have ever written even the basics of this module and I thank you! Thanks to Jim for all the changes proposed and made available. I will be trying some of them soon...I also contacted the maintainer to see if he would kindly chime in and maybe even start a new branch using one of the versions...who knows.

scotwith1t’s picture

Status: Needs review » Reviewed & tested by the community

granted i'm just one tester, but i've got a site using this improved module (v8 from #35) works great with multiple university subscribers with multiple, comma-separated ranges of IPs assigned to one login, using a combination of wildcards, ranges and individual IPs (within the space allowed).

the site's still in dev, but had 2 of the institutional subscribers confirm it's working, i've tried it at work and get good results on multiple comps.

+1 for a new 2.x branch and not just adding this to the current dev as this is a vast improvement over the original module. Jim, has your CVS access been approved yet? i saw where you and David had gotten that 'official' in another issue...

Jim Kirkpatrick’s picture

Hi Guys, I've finally moved house and got broadband... I'm plugged back into the matrix!

@phrancescot: Great, glad it's working for you. I've still never had a reported problem from my client either and haven't seen an issue with v8 myself...

And I've got the co-maintainer say-so from David who maintains the module presently - http://drupal.org/node/943480 - so it's definitely on my list of things to do to very soon to ask for a CVS account and submit this either a new 1.x version or a new 2.x.dev branch...

Jim Kirkpatrick’s picture

FYI I've now applied for a Drupal CVS account here: http://drupal.org/node/999254

Note the latest v9 is now attached here: http://drupal.org/node/999254#comment-3832358 - only minor tweaks and typos really, plus implementation of hook_uninstall().

justin.cherniak’s picture

It seems that you call drupal_goto at the end of ip_login_as_different_user. This causes problems with other hook_user implementations and as such, I'd recommend removing it. The worst case is that the user is redirected to the home page instead of the login page, but presumably they can figure out how to get back.

Alternatively, if you set $_REQUEST['destination'] instead of directly calling drupal_goto, other hook_user('logout') implementation could run and you would still achieve the same result.

justin.cherniak’s picture

Also, if you don't mind me asking, since it seems you have your Git account, any idea when we might see a release with this new version?

Jim Kirkpatrick’s picture

Hi Justin,

#78: thanks for the input - I'll amend on my next pass.

#79: I've had an uber-busy few months and really want to get back to this... Should have chance soon...

My dilemma is basically revolving around how to move forward; do I go for a 2.x branch which includes the work in this issue or removes the dependency on the core Profile module, thus easing a D7 version, or do I just commit v9 from here as 6.x-DEV knowing that branch will be abandoned later this year...

It's not that I can't do both, it's that I have less time than I want. #1087822: IP Login incompatible with SecurePages Hijack Prevention module is a concern too. If you have a preference shout now! I haven't had the headspace to think too much about it.

In either case, I should hopefully be free to commit something late this month/early next.

scotwith1t’s picture

i'd say go for a new version 2.x that's not dependent on profile module and start working on D7 from that. Moving forward for the future is the idea to me.

justin.cherniak’s picture

Jim, trust me, I know all about lack of time. Thanks for all your hard work on this module. It is always great to see once (almost) abandoned projects get new life with new maintainers.

I'd say just do a 2.x branch as we don't want to lose the work you've done here. That said, it is imperative that we retain Drupal 6 support (at least for my company's purposes).

justin.cherniak’s picture

FileSize
613 bytes

Jim,

I'm seeing another bug popup here. If the user logs out of an account which does not have an auto-login IP assigned to it, they still get the "This account does not have permission to log out once logged in automatically. You have been logged back in." warning message, even though they have not in fact been logged back in.

I've attached a patch which I think fixes the issue.

Thanks,
Justin Cherniak

Jim Kirkpatrick’s picture

FileSize
15.96 KB

Thanks for the catch Justin! Latest version of DEV attached.

FYI the roadmap is roughly:

  1. Remove reliance on Profile module,
  2. Submit 6.2.x-DEV branch,
  3. Get feedback, fix, tweak
  4. Submit 7.2x-DEV branch,
  5. Wait a bit, fix bugs, go for proper 2.0 release

I hope to do 1) and 2) before the end of the month.

johnv’s picture

Jim, nice to see some action. I'm eager to find a D7-release here. Thanks!

Jim Kirkpatrick’s picture

FileSize
16.06 KB

v11 including proper hook_user calls which fixes #1128382: Does not work with with Rules? attached...

Jim Kirkpatrick’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Reviewed & tested by the community » Fixed

I am pleased to announce a new 6.x-2.x-DEV branch has been committed! Merry xmas!

This committed version is v11 from the above post, but obviously now integrates properly with Drupal's issues and release systems.

As noted, the plan is now to:

  • Remove reliance on core Profile module, replacing with its own small user to IP range table.
  • Release 6.x-2.0-betas, fixing bugs and testing upgrade from 1.x branch
  • Start on a D7 version once D6 version goes to official 2.0 - or someone helps out with some patches!!!
scotwith1t’s picture

You're awesome, Jim. Thanks for all your work on this module. It's been invaluable to a particularly important project for me recently. Can't thank you enough. Works beautifully on all kinds of combinations of ranges, wildcards, individual IPs. Just really solid work. Jim Kirkpatrick++

Jim Kirkpatrick’s picture

Ha! thanks phrancescot... Hope to make some more improvements soon.

Anonymous’s picture

I'll second the great work... this module is basically required if you're doing Drupal with any sort of institutional publications that require automatic access to paywall material.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.