cyberneticos Posted October 29, 2007 Share Posted October 29, 2007 Hi guys, The default IP manager is a good start, but a bit useless. I am going to post my modifications and hope everyone else can benefit from my work too. <?php # Set the admin level required to access the addon - 1 for support, 2 for sales & 3 for full admin $adminlevel = "3"; if(!mysql_num_rows( mysql_query("SHOW TABLES LIKE 'mod_ipmanager'"))) { if (!$_GET["install"]) { echo ' Not Yet Installed</p> This addon module allows you to record IP addresses and what they are being used for.</p> To install it, click on the button below.</p> <input type="button" value="Install IP Manager" onclick="window.location=\''.$modulelink.'&install=true\'"></p> '; } else { $query = "CREATE TABLE `mod_ipmanager` (`id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`ipaddress` VARCHAR( 16 ) NOT NULL ,`note` TEXT NOT NULL )"; $result=mysql_query($query); header("Location: $modulelink"); exit; } } else { if ($_POST["ip"]) { foreach ($_POST["ip"] AS $id=>$ip) { $id = sanitize($id); $ip = sanitize($ip); $note = sanitize($_POST["note"][$id]); update_query("mod_ipmanager",array("ipaddress"=>$ip,"note"=>$note),"id='$id'"); } } if ($_POST["newip"]) { $newip = sanitize($_POST["newip"]); $newnote = sanitize($_POST["newnote"]); insert_query("mod_ipmanager",array("ipaddress"=>$newip,"note"=>$newnote)); } if ($_GET["delete"]) { $id = sanitize($_GET["id"]); delete_query("mod_ipmanager","id='$id'"); } $filterfield = sanitize($_POST["filterfield"]); $filtertype = sanitize($_POST["filtertype"]); $filtervalue = sanitize($_POST["filtervalue"]); echo ' <script language="JavaScript"> function doDelete(id) { if (confirm("Are you sure you want to delete this IP?")) { window.location="'.$modulelink.'&delete=true&id="+id; }} </script> <form method="post" action="'.$modulelink.'"> <p align="center">Search for <select name="filterfield"> <option value="ipaddress"'; if ($filterfield=="ipaddress") { echo ' selected'; } echo '>IP Address</option> <option value="note"'; if ($filterfield=="note") { echo ' selected'; } echo '>Note</option> <select> that <select name="filtertype"> <option'; if ($filtertype=="starts with") { echo ' selected'; } echo '>starts with</option> <option'; if ($filtertype=="ends with") { echo ' selected'; } echo '>ends with</option> <option'; if ($filtertype=="contains") { echo ' selected'; } echo '>contains</option> </select> <input type="text" name="filtervalue" size="30" value="'.$filtervalue.'"> <input type="submit" value="Filter"><input type="button" value="Show all" onclick="window.location=\'addonmodules.php?module=ip_manager\'"></p> <table width="100%" cellspacing="1" bgcolor="#cccccc"><tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="120">IP Address</td><td>Note</td><td width="20"></td></tr> '; $id=""; $query = "SELECT * FROM mod_ipmanager"; if ($filterfield) { $query.= " WHERE $filterfield"; if ($filtertype=="starts with") { $query.= " LIKE '$filtervalue%'"; } elseif ($filtertype=="ends with") { $query.= " LIKE '%$filtervalue'"; } else { $query.= " LIKE '%$filtervalue%'"; } } $query.= " ORDER BY ipaddress ASC"; $result=mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $ipaddress = $data["ipaddress"]; $note = $data["note"]; echo ' <tr bgcolor="#ffffff"> <td><textarea name="ip['.$id.']" style="width:100%" rows=6>'.$ipaddress.'</textarea></td> <td><textarea name="note['.$id.']" style="width:100%" rows=6>'.$note.'</textarea></td> <td align="center"></td> </tr>'; } if (!$id) { echo '<tr bgcolor="#ffffff"><td colspan="3" align="center">No Data Found</td></tr>'; } echo ' </table> <p align="center"><input type="submit" value="Save Changes"></p> <p align="center">Add New IP IP Address: <input type="text" name="newip" size="20"> Note: <input type="text" name="newnote" size="75"> <input type="submit" value="Add IP"></p> </form> '; } ?> This version basically turns the text inputs into textareas. You need to modifiy the mod_ipmanager table's ipaddress field and set it to TEXT and leave the length value empty or 255 at least. I have made the textarea rows length a value of 6 to be able to see at least 4 ips without having to scroll. I have also added a "Show All" button. This was obviously needed Most likely I will be creating extra fields like "Hostname" "Username" etc,... any improvements are very welcome. 0 Quote Link to comment Share on other sites More sharing options...
Chrisw Posted October 29, 2007 Share Posted October 29, 2007 I'm glad to see someone working on this Thanks 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted November 4, 2007 Share Posted November 4, 2007 ost likely I will be creating extra fields like "Hostname" "Username" etc,... any improvements are very welcome. Sounds like the start of a DNS management module Just what I was beginning to work on .. 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted November 4, 2007 Author Share Posted November 4, 2007 Yeah,. I need a way to keep track of what ip has been assigned to when machine (vps,ded server,etc..) and also to know what the machines hostname is so I can search for it in whmcs.(actually that's what I'm going to call "internal" and the hostname will be the actual machine's hostname (the one the user picked. See, we classify vps in a sequence "vps1, vps2,3,4,5,6,7 etc.." 0 Quote Link to comment Share on other sites More sharing options...
Chrisw Posted November 7, 2007 Share Posted November 7, 2007 I already added a domain field with a few minor cosmetic edits. It does the job for now 0 Quote Link to comment Share on other sites More sharing options...
netswitch Posted November 8, 2007 Share Posted November 8, 2007 Hello, Can you be more specific on "how to install" ? Regards 0 Quote Link to comment Share on other sites More sharing options...
Chrisw Posted November 8, 2007 Share Posted November 8, 2007 Copy and paste (replace the entire code) the code to the ip_manager.php files in the module directory. Then you can install it as your normally would 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted November 8, 2007 Author Share Posted November 8, 2007 I already added a domain field with a few minor cosmetic edits.It does the job for now Are you going to share your code ? Or is this something you did to the original code ? 0 Quote Link to comment Share on other sites More sharing options...
Chrisw Posted November 8, 2007 Share Posted November 8, 2007 Yeah, here ya go. I've added a "print page" link with an added CSS to strip out most of the extra stuff that is not needed for printing. It simply saves a bunch of ink. The search was edited as well to allow to search by domain. I will post the CSS in another reply. Here is the code and should install fine: <link rel="stylesheet" media="print" href="printipstyle.css" type="text/css" /> <?php # Set the admin level required to access the addon - 1 for support, 2 for sales & 3 for full admin $adminlevel = "3"; if(!mysql_num_rows( mysql_query("SHOW TABLES LIKE 'mod_ipmanager'"))) { if (!$_GET["install"]) { echo ' [b]Not Yet Installed[/b]</p> This addon module allows you to record IP addresses and what they are being used for.</p> To install it, click on the button below.</p> <input type="button" value="Install IP Manager" onclick="window.location=\''.$modulelink.'&install=true\'"></p> '; } else { $query = "CREATE TABLE `mod_ipmanager` (`id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`ipaddress` VARCHAR( 16 ) NOT NULL ,`note` TEXT NOT NULL , `domain` TEXT NOT NULL )"; $result=mysql_query($query); header("Location: $modulelink"); exit; } } else { if ($_POST["ip"]) { foreach ($_POST["ip"] AS $id=>$ip) { $id = sanitize($id); $ip = sanitize($ip); $note = sanitize($_POST["note"] [$id]); $domain = sanitize($_POST["domain"][$id]); update_query("mod_ipmanager",array("ipaddress"=>$ip,"note"=>$note,"domain"=>$domain),"id='$id'"); } } if ($_POST["newip"]) { $newip = sanitize($_POST["newip"]); $newnote = sanitize($_POST["newnote"]); $newdomain = sanitize($_POST["newdomain"]); insert_query("mod_ipmanager",array("ipaddress"=>$newip,"note"=>$newnote,"domain"=>$newdomain)); } if ($_GET["delete"]) { $id = sanitize($_GET["id"]); delete_query("mod_ipmanager","id='$id'"); } $filterfield = sanitize($_POST["filterfield"]); $filtertype = sanitize($_POST["filtertype"]); $filtervalue = sanitize($_POST["filtervalue"]); echo ' <script language="JavaScript"> function doDelete(id) { if (confirm("Are you sure you want to delete this IP?")) { window.location="'.$modulelink.'&delete=true&id="+id; }} </script> <form method="post" action="'.$modulelink.'"> <p align="center">Search for <select name="filterfield"> <option value="ipaddress"'; if ($filterfield=="ipaddress") { echo ' selected'; } echo '>IP Address</option> <option value="note"'; if ($filterfield=="note") { echo ' selected'; } echo '>Notes/Justification</option> <option value="domain"'; if ($filterfield=="domain") { echo ' selected'; } echo '>Domain</option> <select> that <select name="filtertype"> <option'; if ($filtertype=="starts with") { echo ' selected'; } echo '>starts with</option> <option'; if ($filtertype=="ends with") { echo ' selected'; } echo '>ends with</option> <option'; if ($filtertype=="contains") { echo ' selected'; } echo '>contains</option> </select> <input type="text" name="filtervalue" size="30" value="'.$filtervalue.'"> <input type="submit" value="Filter"></p> <table width="100%" cellspacing="1" bgcolor="#cccccc"><tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="15%">IP Address</td> <td>Notes/Justification</td> <td width="25%">Domain</td><td width="20"></td></tr> '; $id=""; $query = "SELECT * FROM mod_ipmanager"; if ($filterfield) { $query.= " WHERE $filterfield"; if ($filtertype=="starts with") { $query.= " LIKE '$filtervalue%'"; } elseif ($filtertype=="ends with") { $query.= " LIKE '%$filtervalue'"; } else { $query.= " LIKE '%$filtervalue%'"; } } $query.= " ORDER BY ipaddress ASC"; $result=mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $ipaddress = $data["ipaddress"]; $note = $data["note"]; $domain = $data["domain"]; echo '<tr bgcolor="#ffffff"><td><input type="text" name="ip['.$id.']" style="width:100%" value="'.$ipaddress.'"></td> <td><input type="text" name="note['.$id.']" style="width:100%" value="'.$note.'"></td> <td><input type="text" name="domain['.$id.']" style="width:100%" value="'.$domain.'"></td> <td align="center">[url="#"][img=images/delete.gif][/url]</td></tr>'; } if (!$id) { echo '<tr bgcolor="#ffffff"><td colspan="3" align="center">No Data Found</td></tr>'; } echo ' </table> [url="#"]Print this page[/url] <p align="center"><input type="submit" value="Save Changes"></p> <p align="left">[b]Add New IP[/b] IP Address: <input type="text" name="newip" size="20"> Notes/Justification <input type="text" name="newnote" size="75"> Domain: <input type="text" name="newdomain" size="30"> <input type="submit" value="Add IP"></p> </form> '; } ?> 0 Quote Link to comment Share on other sites More sharing options...
Chrisw Posted November 8, 2007 Share Posted November 8, 2007 Go to admin/styles and create a new file called printipstyle.css. Then paste this in it. This will strip most the webpage from the IP list during printing. .pageheaderrow { display: none } .navheading { display: none } .navbaroff { display: none } .navbutton { display: none } body { background-color: #ffffff; margin:0px; } .navbar { background-color: #ffffff; padding:15px; font-size: 10px; } 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted November 8, 2007 Author Share Posted November 8, 2007 nice Chris, I will test this out 0 Quote Link to comment Share on other sites More sharing options...
Chad Posted January 10, 2008 Share Posted January 10, 2008 There is no folder called "styles" inside the admin directory. Also, " Print this page" is not hyperlinked when I applied your mod. Please let me know how to correct this. Also, can we add a range of IP's instead of one at a time? Screenshot is what it looks like now. 0 Quote Link to comment Share on other sites More sharing options...
Ekras Posted August 15, 2008 Share Posted August 15, 2008 Parse error: parse error, unexpected T_STRING, expecting ')' in /home/content/p/p/i/ppiadmin/html/whmcs/modules/ip_monitor.php on line 34 I get this when trying to run the page. 0 Quote Link to comment Share on other sites More sharing options...
mobile Posted August 19, 2008 Share Posted August 19, 2008 Parse error: parse error, unexpected T_STRING, expecting ')' in /home/content/p/p/i/ppiadmin/html/whmcs/modules/ip_monitor.php on line 34 I get this when trying to run the page. Here is the code as I had the same error. I fixed a couple of lines giving errors I believe they were lines 34 & 40. Also made it all fit in one line. <link rel="stylesheet" media="print" href="printipstyle.css" type="text/css" /> <?php # Set the admin level required to access the addon - 1 for support, 2 for sales & 3 for full admin $adminlevel = "3"; if(!mysql_num_rows( mysql_query("SHOW TABLES LIKE 'mod_ipmanager'"))) { if (!$_GET["install"]) { echo ' Not Yet Installed</p> This addon module allows you to record IP addresses and what they are being used for.</p> To install it, click on the button below.</p> <input type="button" value="Install IP Manager" onclick="window.location=\''.$modulelink.'&install=true\'"></p> '; } else { $query = "CREATE TABLE `mod_ipmanager` (`id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`ipaddress` VARCHAR( 16 ) NOT NULL ,`note` TEXT NOT NULL , `domain` TEXT NOT NULL )"; $result=mysql_query($query); header("Location: $modulelink"); exit; } } else { if ($_POST["ip"]) { foreach ($_POST["ip"] AS $id=>$ip) { $id = sanitize($id); $ip = sanitize($ip); $note = sanitize($_POST["note"] [$id]); $domain = sanitize($_POST["domain"][$id]); update_query("mod_ipmanager",array("ipaddress"=>$ip,"note"=>$note,"domain"=>$domain),"id='$id'"); } } if ($_POST["newip"]) { $newip = sanitize($_POST["newip"]); $newnote = sanitize($_POST["newnote"]); $newdomain = sanitize($_POST["newdomain"]); insert_query("mod_ipmanager",array("ipaddress"=>$newip,"note"=>$newnote,"domain"=>$newdomain)); } if ($_GET["delete"]) { $id = sanitize($_GET["id"]); delete_query("mod_ipmanager","id='$id'"); } $filterfield = sanitize($_POST["filterfield"]); $filtertype = sanitize($_POST["filtertype"]); $filtervalue = sanitize($_POST["filtervalue"]); echo ' <script language="JavaScript"> function doDelete(id) { if (confirm("Are you sure you want to delete this IP?")) { window.location="'.$modulelink.'&delete=true&id="+id; }} </script> <form method="post" action="'.$modulelink.'"> <p align="center">Search for <select name="filterfield"> <option value="ipaddress"'; if ($filterfield=="ipaddress") { echo ' selected'; } echo '>IP Address</option> <option value="note"'; if ($filterfield=="note") { echo ' selected'; } echo '>Notes/Justification</option> <option value="domain"'; if ($filterfield=="domain") { echo ' selected'; } echo '>Domain</option> <select> that <select name="filtertype"> <option'; if ($filtertype=="starts with") { echo ' selected'; } echo '>starts with</option> <option'; if ($filtertype=="ends with") { echo ' selected'; } echo '>ends with</option> <option'; if ($filtertype=="contains") { echo ' selected'; } echo '>contains</option> </select> <input type="text" name="filtervalue" size="30" value="'.$filtervalue.'"> <input type="submit" value="Filter"></p> <table width="100%" cellspacing="1" bgcolor="#cccccc"><tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="15%">IP Address</td> <td>Notes/Justification</td> <td width="25%">Domain</td><td width="20"></td></tr> '; $id=""; $query = "SELECT * FROM mod_ipmanager"; if ($filterfield) { $query.= " WHERE $filterfield"; if ($filtertype=="starts with") { $query.= " LIKE '$filtervalue%'"; } elseif ($filtertype=="ends with") { $query.= " LIKE '%$filtervalue'"; } else { $query.= " LIKE '%$filtervalue%'"; } } $query.= " ORDER BY ipaddress ASC"; $result=mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $ipaddress = $data["ipaddress"]; $note = $data["note"]; $domain = $data["domain"]; echo '<tr bgcolor="#ffffff"><td><input type="text" name="ip['.$id.']" style="width:100%" value="'.$ipaddress.'"></td> <td><input type="text" name="note['.$id.']" style="width:100%" value="'.$note.'"></td> <td><input type="text" name="domain['.$id.']" style="width:100%" value="'.$domain.'"></td> <td align="center">[img=images/delete.gif]</td></tr>'; } if (!$id) { echo '<tr bgcolor="#ffffff"><td colspan="3" align="center">No Data Found</td></tr>'; } echo ' </table> Print this page <p align="center"><input type="submit" value="Save Changes"></p> <p align="left">Add New IP IP Address: <input type="text" name="newip" size="20"> Notes/Justification <input type="text" name="newnote" size="30"> Domain: <input type="text" name="newdomain" size="30"> <input type="submit" value="Add IP"></p> </form> '; } ?> 0 Quote Link to comment Share on other sites More sharing options...
nugenhost Posted August 20, 2008 Share Posted August 20, 2008 Here is the code as I had the same error. I fixed a couple of lines giving errors I believe they were lines 34 & 40. Also made it all fit in one line. <link rel="stylesheet" media="print" href="printipstyle.css" type="text/css" /> <?php [b] **shortened to save space.[/b] I installed this version of the code and while it shows up and looks great and it's all on one line, I cannot get it to 'add' anything. nor does the 'print page' link work. I haven't looked at the code yet myself, but thought I'd let you know. 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted August 20, 2008 Share Posted August 20, 2008 I installed this version of the code and while it shows up and looks great and it's all on one line, I cannot get it to 'add' anything. nor does the 'print page' link work. I haven't looked at the code yet myself, but thought I'd let you know. Use phpMyadmin to drop (delete) the mod_ipmanager table then run ip manager and re-install. (BE CAREFULL... BACKUP THE DATABASE FIRST) To fix the missing delete image Find Replace it with<img src="../../../admin/images/delete.gif">And a little cosmetic thingFind <p align="left">Add New IP IP Address: <input type="text" name="newip" size="20">Replace it with<p align="left"><strong>Add New IP</strong><br />IP Address: <input type="text" name="newip" size="20"> 0 Quote Link to comment Share on other sites More sharing options...
nugenhost Posted August 23, 2008 Share Posted August 23, 2008 Thank you sparky, I did the changes and now it will add the IP's but the delete button still isn't there. I've changed the url to the direct url and it still isn't pulling it up. I've checked and yes it's there. So it isn't allowing me to delete anything. The print feature still isnt' working either. 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted August 24, 2008 Share Posted August 24, 2008 I've checked and yes it's there. So it isn't allowing me to delete anything right click on the missing image take "view properties" and check the url fix your typo 0 Quote Link to comment Share on other sites More sharing options...
mhx Posted September 30, 2010 Share Posted September 30, 2010 any chance someone has come up with a way to add gateways, netmasks, and assign the ips to a client? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.