Howdy !
PhpIP is great, and I'm happy to use it !
I'd love to see two improvements, however :
# IP ordering
- It's a shame that the IP's are not correctly ordered.
I guess this is due to mysql being a bit shite at handling them specifically, and that the ip fields are varchar.
- Would it be possible to split the IP's into 4 different fields, so that an order-by would work properly (or save them to an 'int' using ip2long, etc.). OAt the moment, I see that IP's varchar for holding the IP addresses... or use postgres :)
# IP Threading
- It'd be really *great* to be able to have threading !
(what i mean is : in the menu on the left, to be able to have a /16, splitable into multiple subnets (e.g. lotsa /24's) which would then branch into smaller subnets (e.g. /28's), etc. I hope I'm being clear on what would be nice to see !
My apologies in advance if this replicates previous support requests or mailing-list posts : i trawled through them quickly, but i'm fallible ! :)
Many thanks,
Tom
Logged In: YES
user_id=2164141
Originator: NO
IP Ordering in left hand menu:
boxes/box_CidrMenu.php, about line 30, change to
if ($_SESSION['access_level'] != "Administrator") {
$sql = mysql_query("SELECT * FROM `NetMenu` WHERE `groupid` = '$_SESSION[groupid]' ORDER BY INET_ATON(LEFT(NetMenuCidr, LOCATE('/',NetMenuCidr)-1))");
} else {
$sql = mysql_query("SELECT * FROM `NetMenu` ORDER BY INET_ATON(LEFT(NetMenuCidr, LOCATE('/',NetMenuCidr)-1)) ASC");
}
mysql ordering of cidr by:
ORDER BY INET_ATON(LEFT(NetMenuCidr, LOCATE('/',NetMenuCidr)-1)) ASC
Created and tested following solution with PHP 5.2.6 and MySQL 5.0.63. Works same as the other code, just a bit "tidier"?
Edit cidr_desc.php, cidr_remove.php, group_update.php, prefix_add.php, boxes/box_CidrMenu.php
Search for ORDER BY `NetMenuCidr` + 0
Replace with ORDER BY INET_ATON(SUBSTRING_INDEX(`NetMenuCidr`, '/', 1))
This will update in all the places the CIDR range is used.
To explain what this does; phpIP stores the CIDR in the database like this 10.0.0.0/8. INET_ATON is a MySQL function to convert the IP address into binary, which is a reliable way of sorting correctly all the way through. SUBSTRING_INDEX splits a string field based on a delimiting character, in this case the / present at the end, and then the 1 denotes that it should use the 1 left most entry. In summary, it SUBSTRING_INDEX(`NetMenuCidr`, '/', 1) would return 10.0.0.0 when the database entry was 10.0.0.0/8, and then INET_ATON will convert this into binary, and sort it.