Home
>
Outdated forums
>
Phorum 3 forums (READ ONLY)
>
Finished Mods and Plug-ins (READ ONLY)
>
Topic
[code] mod to add ip/domain name block in the admin panel
Posted by David M
David M
[code] mod to add ip/domain name block in the admin panel July 11, 2004 06:23AM |
Hi,
I was allways looking to be able to block ips/domain name within the admin panel without being obliged to modify the bad_host file, and send it by ftp in the correct folder. Also I wanted to give that possibility to my moderators.
Here is the mod, very easy to add (for MySql only) : 3 files + two images (not mandatory but easy to see what Ip is block yes or not).
I tested in under several 3.4.x releases and it seems to work fine.
Note that it allows to add ipadress (but not to delete them in the database in order to keep a track of ip adresses added). But once you want to release a ip adress, you can say that this ip adress is allowed again (it stays in the database but is not saved into the bad_host file).
Install steps :
- new table to create in the form database (the syntax is in the txt file)
- ipblock.php file to add in the /forumadminfolder/pages/
- a simple line to add in the panels admin in the file /forumadminfolder/pages/main.php for the admin
<a href="<?php echo $myname; ?>?page=ipblock">IP block</a><br />
and/or in the file /forumadminfolder/pages/moderate.php for moderators
<a href="<? echo "$PHP_SELF?"; ?>f=1&page=stats"> Statistiques</a>
Let me know your thoughts
Cheers,
David
I was allways looking to be able to block ips/domain name within the admin panel without being obliged to modify the bad_host file, and send it by ftp in the correct folder. Also I wanted to give that possibility to my moderators.
Here is the mod, very easy to add (for MySql only) : 3 files + two images (not mandatory but easy to see what Ip is block yes or not).
I tested in under several 3.4.x releases and it seems to work fine.
Note that it allows to add ipadress (but not to delete them in the database in order to keep a track of ip adresses added). But once you want to release a ip adress, you can say that this ip adress is allowed again (it stays in the database but is not saved into the bad_host file).
Install steps :
- new table to create in the form database (the syntax is in the txt file)
- ipblock.php file to add in the /forumadminfolder/pages/
- a simple line to add in the panels admin in the file /forumadminfolder/pages/main.php for the admin
<a href="<?php echo $myname; ?>?page=ipblock">IP block</a><br />
and/or in the file /forumadminfolder/pages/moderate.php for moderators
<a href="<? echo "$PHP_SELF?"; ?>f=1&page=stats"> Statistiques</a>
Let me know your thoughts
Cheers,
David
David M
Re: [code] mod to add ip/domain name block in the admin panel : new table July 11, 2004 06:25AM |
David M
Re: [code] mod to add ip/domain name block in the admin panel July 11, 2004 06:26AM |
and the main code :
<?php
if(!defined("PHORUM_ADMIN")) return;
$lFormAdd="Ajouter"; // Add
$lFormMod="Modifier"; // Modify
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bloquer une adresse IP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body
{
color: #000000;
background: #e1e1e1;
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
padding:5px;
margin:0px;
}
th
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
text-align: left;
background-color: #F0F0F0;
border-collapse: collapse;
border-bottom-width : 1px;
border-top-width : 0px;
border-left-width : 0px;
border-right-width : 0px;
border-style : solid;
border-color : Gray;
}
td
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-align: left;
}
a
{
font-weight:bold;
color:Blue;
text-decoration:none;
outline:none;
}
p
{
padding: 0px 0px 0px 0px;
margin: 0px 0px 10px 0px;
}
img
{
border:none;
}
input, select
{
font-size : 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
input.login
{
border-width : 1px;
border-style : solid;
border-color : Gray;
font-family : "Lucida Sans","Lucida Grande",Arial;
font-size : 11px;
}
table.box-table
{
border-width : 1px;
border-style : solid;
border-color : Gray;
background-color: White;
border-collapse: collapse;
}
table.box-table td
{
border-collapse: collapse;
border-bottom-width : 1px;
border-top-width : 0px;
border-left-width : 0px;
border-right-width : 0px;
border-style : solid;
border-color : Gray;
}
td.table-header
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
background-color: Navy;
color: White;
text-align: center;
}
td.table-header a
{
color: White;
}
.nav
{
font-size: 11px;
}
#message
{
width: 300px;
border-width: 1px;
border-style: solid;
padding: 3px;
background-color: White;
}
#title
{
font-size: 14px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
display: inline;
}
</style>
</head>
<body>
<center>
<!-- IP adress to bann form-->
<form name="addform" method="get" action="<?php echo $myname; ?>">
<input type="hidden" name="page" value="ipblock" />
<input type="hidden" name="num" value="1" />
<table width="400" border="0">
<tr>
<td width="150" nowrap valign="middle">Adresse IP à bannir</td>
<td width="50" nowrap valign="middle">
<input name="ipadress" type="text" id="ipadress" size="25" maxlength="200">
</td>
<td width="150" nowrap valign="middle"><input type="submit" name="add" value="<?php echo $lFormAdd; ?>">
</td>
</tr>
</table>
</form>
<hr width="600"/>
<?
$ipadress=strip_tags(trim($ipadress));
if ($add==$lFormAdd && $ipadress!="") {
// simple check if this is a valid domain name, ip adress and avoidspecial caracters
if (!eregi("[^\.\$a-z0-9\-]",$ipadress)) {
$SQL="INSERT INTO iplist VALUES (0,'$ipadress','Y')";
$q->query($DB, $SQL);
echo "<p><font color='green'>Adresse IP ajoutée avec succès ! </font></p>"; // IP adress added with success in the db
} else {
echo "<p><font color='red'>Adresse IP invalide !</font></p>"; // Invalid IP adress
}
}
if ($modif==$lFormMod) {
$query_string = getenv("QUERY_STRING");
$env_array = split("&", $query_string);
while (list($key, $val) = each($env_array)) {
list($id, $state) = split("=", $val);
$id = urldecode($id);
$state = urldecode($state);
if (substr($id,0,2)=="id") {
$id=substr($id,2);
$SQL="UPDATE iplist SET state='$state' where id='$id'";
$q->query($DB, $SQL);
}
}
$SQL="SELECT ip FROM iplist where state='Y'";
$q->query($DB, $SQL);
$data="<?php\n";
$data.="if ( !defined( \"_COMMON_PHP\" ) ) return;\n";
while($row=$q->getrow()) {
$data.="\$hosts[]=\"" . $row['ip'] . "\";\n";
}
$data.="?>";
if(@copy("./include/bad_hosts.php", "./include/bad_hosts_bkp.php")){
QueMessage("Sauvegarde effectuée."); // bad_host file changes saved.
} else {
QueMessage("Sauvegarde effectuée mais backup du fichier bad_host impossible."); // Changes saved but bad_host file could not be backed up
}
$fp=fopen("./include/bad_hosts.php","w");
fputs($fp, $data);
fclose($fp);
echo "<p><font color='green'>Adresses IP mises à jour avec succès ! </font></p>"; // IP Adress updated with success
}
// display all IP adress in the db
$SQL="Select id,ip,state from iplist";
$q->query($DB, $SQL);
$ips_found=$q->numrows();
if ($ips_found>0) {
echo"<form name='modif' method='get' action='$myname'>
<input type='hidden' name='page' value='ipblock' >
<input type='hidden' name='num' value='1' ><table width='400' border='0' class='box-table'>
<tr><td width='150' class='table-header'>IP</td><td width='200' colspan='3' class='table-header'>Etat</td></tr>";
while($row=$q->getrow()) {
$id="id" . $row['id'];
$ip=$row['ip'];
if ($row['state']=="Y") {
$ipsy="checked"; $ipsn="";
} else {
$ipsn="checked"; $ipsy="";
}
echo "<tr><td width='300'> $ip</td><td width='100' colspan='3'><img src='/img/rd_rouge.gif' alt='Interdit' width='11' height='11'><input name='$id' type='radio' value='Y' $ipsy> <img src='/img/rd_vert.gif' alt='Autorisé' width='11' height='11'><input name='$id' type='radio' value='N' $ipsn></td></tr>";
}
echo"<td colspan='3'><p align=center><input type='submit' name='modif' value='$lFormMod'></p></td></tr></table></form>";
} else {
QueMessage("Aucune adresse IP en base"); // no ip adress in the database
}
?>
</center>
</body>
</html>
<?php
if(!defined("PHORUM_ADMIN")) return;
$lFormAdd="Ajouter"; // Add
$lFormMod="Modifier"; // Modify
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bloquer une adresse IP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body
{
color: #000000;
background: #e1e1e1;
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
padding:5px;
margin:0px;
}
th
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
text-align: left;
background-color: #F0F0F0;
border-collapse: collapse;
border-bottom-width : 1px;
border-top-width : 0px;
border-left-width : 0px;
border-right-width : 0px;
border-style : solid;
border-color : Gray;
}
td
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-align: left;
}
a
{
font-weight:bold;
color:Blue;
text-decoration:none;
outline:none;
}
p
{
padding: 0px 0px 0px 0px;
margin: 0px 0px 10px 0px;
}
img
{
border:none;
}
input, select
{
font-size : 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
input.login
{
border-width : 1px;
border-style : solid;
border-color : Gray;
font-family : "Lucida Sans","Lucida Grande",Arial;
font-size : 11px;
}
table.box-table
{
border-width : 1px;
border-style : solid;
border-color : Gray;
background-color: White;
border-collapse: collapse;
}
table.box-table td
{
border-collapse: collapse;
border-bottom-width : 1px;
border-top-width : 0px;
border-left-width : 0px;
border-right-width : 0px;
border-style : solid;
border-color : Gray;
}
td.table-header
{
font-size: 13px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
background-color: Navy;
color: White;
text-align: center;
}
td.table-header a
{
color: White;
}
.nav
{
font-size: 11px;
}
#message
{
width: 300px;
border-width: 1px;
border-style: solid;
padding: 3px;
background-color: White;
}
#title
{
font-size: 14px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
display: inline;
}
</style>
</head>
<body>
<center>
<!-- IP adress to bann form-->
<form name="addform" method="get" action="<?php echo $myname; ?>">
<input type="hidden" name="page" value="ipblock" />
<input type="hidden" name="num" value="1" />
<table width="400" border="0">
<tr>
<td width="150" nowrap valign="middle">Adresse IP à bannir</td>
<td width="50" nowrap valign="middle">
<input name="ipadress" type="text" id="ipadress" size="25" maxlength="200">
</td>
<td width="150" nowrap valign="middle"><input type="submit" name="add" value="<?php echo $lFormAdd; ?>">
</td>
</tr>
</table>
</form>
<hr width="600"/>
<?
$ipadress=strip_tags(trim($ipadress));
if ($add==$lFormAdd && $ipadress!="") {
// simple check if this is a valid domain name, ip adress and avoidspecial caracters
if (!eregi("[^\.\$a-z0-9\-]",$ipadress)) {
$SQL="INSERT INTO iplist VALUES (0,'$ipadress','Y')";
$q->query($DB, $SQL);
echo "<p><font color='green'>Adresse IP ajoutée avec succès ! </font></p>"; // IP adress added with success in the db
} else {
echo "<p><font color='red'>Adresse IP invalide !</font></p>"; // Invalid IP adress
}
}
if ($modif==$lFormMod) {
$query_string = getenv("QUERY_STRING");
$env_array = split("&", $query_string);
while (list($key, $val) = each($env_array)) {
list($id, $state) = split("=", $val);
$id = urldecode($id);
$state = urldecode($state);
if (substr($id,0,2)=="id") {
$id=substr($id,2);
$SQL="UPDATE iplist SET state='$state' where id='$id'";
$q->query($DB, $SQL);
}
}
$SQL="SELECT ip FROM iplist where state='Y'";
$q->query($DB, $SQL);
$data="<?php\n";
$data.="if ( !defined( \"_COMMON_PHP\" ) ) return;\n";
while($row=$q->getrow()) {
$data.="\$hosts[]=\"" . $row['ip'] . "\";\n";
}
$data.="?>";
if(@copy("./include/bad_hosts.php", "./include/bad_hosts_bkp.php")){
QueMessage("Sauvegarde effectuée."); // bad_host file changes saved.
} else {
QueMessage("Sauvegarde effectuée mais backup du fichier bad_host impossible."); // Changes saved but bad_host file could not be backed up
}
$fp=fopen("./include/bad_hosts.php","w");
fputs($fp, $data);
fclose($fp);
echo "<p><font color='green'>Adresses IP mises à jour avec succès ! </font></p>"; // IP Adress updated with success
}
// display all IP adress in the db
$SQL="Select id,ip,state from iplist";
$q->query($DB, $SQL);
$ips_found=$q->numrows();
if ($ips_found>0) {
echo"<form name='modif' method='get' action='$myname'>
<input type='hidden' name='page' value='ipblock' >
<input type='hidden' name='num' value='1' ><table width='400' border='0' class='box-table'>
<tr><td width='150' class='table-header'>IP</td><td width='200' colspan='3' class='table-header'>Etat</td></tr>";
while($row=$q->getrow()) {
$id="id" . $row['id'];
$ip=$row['ip'];
if ($row['state']=="Y") {
$ipsy="checked"; $ipsn="";
} else {
$ipsn="checked"; $ipsy="";
}
echo "<tr><td width='300'> $ip</td><td width='100' colspan='3'><img src='/img/rd_rouge.gif' alt='Interdit' width='11' height='11'><input name='$id' type='radio' value='Y' $ipsy> <img src='/img/rd_vert.gif' alt='Autorisé' width='11' height='11'><input name='$id' type='radio' value='N' $ipsn></td></tr>";
}
echo"<td colspan='3'><p align=center><input type='submit' name='modif' value='$lFormMod'></p></td></tr></table></form>";
} else {
QueMessage("Aucune adresse IP en base"); // no ip adress in the database
}
?>
</center>
</body>
</html>
David M
Re: [code] mod to add ip/domain name block in the admin panel July 14, 2004 03:40PM |
Sorry, you do not have permission to post/reply in this forum.