Jump to content

IP Manager v1.1


Recommended Posts

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">delete.gif</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.

Link to comment
Share on other sites

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.."

Link to comment
Share on other sites

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>
';
}
?>

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

  • 2 months later...

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.

2.jpg

Link to comment
Share on other sites

  • 7 months later...
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>
';
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

delete.gif
Replace it with
<img src="../../../admin/images/delete.gif">
And a little cosmetic thing

Find

<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">
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated