WordPress.org

Ready to get started?Download WordPress

Forums

ecSTATic
Support for IPv6 IP Addresses (18 posts)

  1. bhagwad
    Member
    Posted 1 year ago #

    I've noticed a few visitors coming to my site with IPv6 addresses looking like: 2001:0db8:85a3:0042:1000:8a2e:0370:7334 and getting blocked by ecSTATic with a "Bad IP" message.

    Could you perhaps include support for IPv6 addresses in the next patch?

    Thanks for an awesome plugin!

    http://wordpress.org/extend/plugins/ecstatic/

  2. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    I haven't seen any of those, yet, but I knew it would happen eventually, so it's been in the back of my mind.

    It all depends on what the PHP people have come it with as to functions to deal with IPv6. I'm afraid I haven't looked for a while, but will see what's what.

    Just storing those buggers will mean a modification to the database, but maybe in the meantime I can find a test for validity and at least not block them.

    Stay tuned.

  3. bhagwad
    Member
    Posted 1 year ago #

    @Mike

    Thanks Mike - yeah you'll definitely need to modify the database which could be a pain in the butt. Temporarily allowing them through will at least take the urgency off.

    Found this - might help: http://jbhannah.net/blog/2011/05/18/simple-php-ipv6-detection-script.html

  4. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    IPv6 support is "enabled" on my host's server, so I will be able to test functions.

  5. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for the link.

  6. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    Re the link: It might do in a pinch, but apparently there is no simple regexp that can validate an IPv6 address.

    I'm looking here...

    http://crisp.tweakblogs.net/blog/2031

    ... and his follow up link at the bottom of that.

    As to my little plugin, at this point, I wonder how much "validation" is needed. All I do for IPv4 is check for a blank IP, and then do the long2ip(ip2long($ip)) thing. I don't manage the busiest blogs, but I've never seen a blank IP or one that didn't pass the arithmetic test.

    So, if I pass on validating IPv6 addresses for the time being, the question is what to do with them in the database. Well, I currently store IPs in TINYTEXT fields, which leaves room for the longer format. I have no idea what the repercussions might be in parsing and sorting, or blocking, etc., but the program might well handle it. The reverse IP lookups will undoubtedly kick.

    Do you want to test it? I can create a branch with changes, after I make 'em. I don't know how easy it is to roll back a version, but it should be possible if you have problems. Just copy the old ecstatic.php back, I think.

    Just rambling, but any thoughts appreciated.

  7. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    Dang. Outside any other problems down range, if you find line 350 in ecstatic.php and change...

    if ($this->ip != long2ip(ip2long($this->ip))) {

    ... to ...

    if (!filter_var($this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) {

    ... you may be in business. That's the pipe character between flags.

    Requires PHP 5.2 and above.

    http://us3.php.net/manual/en/function.filter-var.php

    I really can't say if it covers all possibilities, or what will happen when an IPv6 address gets shoved into the ecSTATic database, but the more I look around at that latter eventuality, it looks like trouble will only crop up if one tries to block an IPv6 address range in the WNKS table. As long as you don't try to block an IPv6 address with an IP token, things should work. I make no promises.

    I'm running it now on my own blog, and it's working for IPv4, but I don't get IPv6 visitors, so...

    Alternately, you can just delete the small block of code at line 350.

    Let me know.

  8. bhagwad
    Member
    Posted 1 year ago #

    @Mike

    Thanks Mike. I don't have much experience with PHP programming, but I get the gist. I'd be willing to test out a different version with IPv6 support. Never mind reverse IP lookups for now...

  9. bhagwad
    Member
    Posted 1 year ago #

    I replaced the line and it broke my site :). It triggered the "Bad IP" flag for every request. I wasn't able to access anything. Obviously I'd kept a backup of the old file so I just FTP'd in and replaced it with the old file and I'm back up and working now...

  10. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    That's bad news. I was just liking it more and more in the light of the morning. You got the ! (exclamation point) in front of filter_var, right? Gotta ask.

  11. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    This guy...

    http://coding-journal.com/validating-ip-addresses-in-php/

    ... says that using both flags together, like I suggested, always returns false, but leaving off the flags defaults to validating both IPv4 and IPv6, and returns correctly.

    Which turns line 350 into...

    if (!filter_var($this->ip, FILTER_VALIDATE_IP)) {

    Want to try that?

  12. bhagwad
    Member
    Posted 1 year ago #

    I'll test it once I finish my tournaments on guild wars 2 and let you know :)

  13. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    You go.

    If it works, IPv6 addresses break the Details pages, for now. The whois function chokes. Working on it.

    Or, I should say, it breaks the Details page for that particular IP. IPv4 visitors will still show full Details pages.

    I have a fix, but until I upload a new version, any IPv6 addresses you take in will not have Details pages available.

    But I would like to know if the filter_var() function works, in that it validates your IPv6 addresses. If it does, I've rewritten the initial IP validation for people who might not be running PHP 5.2 and above (and maybe that's your case, I don't know.) If the filter_var() function doesn't work for you, you'll have to comment out a section of code.

  14. bhagwad
    Member
    Posted 1 year ago #

    Tested and working. Simulated an IPv6 visit and it allowed through. The details pane is blank of course. But it's a good work around.

  15. bhagwad
    Member
    Posted 1 year ago #

    Working in the real world as well. Just got an IPv6 visit referred by Google searching for "Chinese women with black woman's ass"! Lol. People find my humble blog in the strangest ways!

  16. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    Yay. That simplifies things. And besides, native PHP functions generally should work.

    To get your Details page working, comment out lines 192 and 193 in ecstatic_whosis.php.

    //if ((strlen($ip) < 1) OR (strlen($ip) > 16))
    // exit("Expected Parameter Not Found.");

    The whois box won't display meaningful information, but the rest of it should work.

    I've got some more playing around with it to do before I release a new version.

    Thanks!

  17. MikeSoja
    Member
    Plugin Author

    Posted 1 year ago #

    New version is up. Let me know if you have any problems.

  18. bhagwad
    Member
    Posted 1 year ago #

    Sweet, thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags