PHP ban removal Script, uses Solarstats

These are old archives. They are kept for historic purposes only.
Post Reply
Matridom
Posts: 296
Joined: Fri Jan 07, 2005 3:28 am

PHP ban removal Script, uses Solarstats

Post by Matridom »

There are two pages involved in this script. A display page and a removal page, Im sure the code for the removal page can be cleaned up.

page 1, display page

Code: Select all

<?php 

   // This page is to show the current bans inplace on the server

   //Remote function to allow an SQL connection
   require ('/some/offline/folder/sql_connect.inc');

   sql_connect('stats'); //Connecting to SQL and sending the database name
   //define the query
   $query = "SELECT * FROM stats_bans WHERE (type='G') ORDER BY 'setat'DESC";

   //This runs the query to view
   define ('FONT_SIZE', 'size="2"');
   If ($r = mysql_query ($query)) { //Creates the diplay table
      echo "<table align=\"center\" border=\"0\" width=\"80%\">\n";
      echo "<tr><td colspan=\"2\"><b><center><font size=\"6\">Server Bans</font></b></center></b></td>\n";
      echo "</table><br />";
      While ($row = mysql_fetch_array($r)) { //inputs the data into the table
             //Formats various variables
             $mask = $row['mask'];
             $setby = $row['setby'];
             $reason = trim ($row['reason']);
             $set_at = date ('F j g:i A', $row['setat']);
             $expires_at = $row['expiresat'];

             //Checks for permanent ban
             if ($expires_at == 0) {
                 $expires_at = "Permanent";
             } else {
                 $expires_at = date ('F j g:i A', $row['expiresat']);
             }
             //creates the tables
             ?>

             <font size="1"><table border="1" align="center" width="80%"><td>
             <table border="0" align="center" width="100%">
                    <tr>
                        <td>
                            <font size="2"><i>Banned Mask</i>: <b><?php echo $mask; ?></b></font>
                        </td>
                        <td width="110">
                            <font size="2"><i>Set By</i>: <b><?php echo $setby; ?></b></font>
                        </td>
                        <td width="180">
                            <font size="2"><i>Set On</i>: <b><?php echo $set_at; ?></b></font>
                        </td>
                        <td width="170">
                            <font size="2"><i>Expires on</i>: <b><?php echo $expires_at; ?></b></font>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <font size="2"><i>Reason For ban</i>: <b><?php echo $reason; ?></b></font>
                        </td>

                        <form action="ban_removal.php" method="POST">
                        <input type="hidden" name="ban" value="<?php echo $mask; ?>" />

                        <td align="right">
                            <input type="submit" value="Remove" />
                        </td>
                        </form>
                    </tr>
             </table>
             </td></table>
             <br /></font>
             <?php
             }

   } else { //query did not run.
        die ("<p>Could not run query because : <b>" . mysql_error() . "</b></p>\n");
        }

     mysql_close();
?>
page 2, removal script

Code: Select all

<?php

$ban=$_POST['ban'];

//Configuration Variables.
$server = 'server address';
$port = 'port number';
$OperName = 'ircop name';
$OperPasswd = 'ircop passwd';


//When a ban is removed, i wan't to know who.. so i snag their dns/ip
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);


$irc = fsockopen($server, $port);  //connects to the IRC server

if ($irc) {
  $line = fgets($irc, 1024);//Get's back a successfull logon

  fputs($irc, "user WebBot localhost localhost :Dont bother\n");
  $line = fgets($irc, 1024); // get's back the confirmation of method

  fputs($irc, "nick WebBot\n"); //sends the nickname
  $line = fgets($irc, 1024);

  $pong = explode( ' ', $line);

  $line = fgets($irc, 1024);

  fputs($irc, "PONG $pong[18]\n"); //sends the pong response

  $count = 1;
  while ($count <= 18){
     $line = fgets($irc, 1024);
     $count ++;
  }

  fputs($irc, "oper " . $OperName . " " . $OperPasswd . "\r\n");  //Opers Up
  $count = 1;
  while ($count <= 2){
     $line = fgets($irc, 1024);
     $count ++;
  }

  fputs($irc, "gline -" . $ban . "\n"); //This removes the ban
  $line = fgets($irc, 1024);

  $line = fgets($irc, 1024);


  $pos = strpos($line, 'removed G:Line'); //This checks for a removal or not
  if ($pos) {
     echo "<center>Ban Removal Successfull. <b>" . $ban . "</b> is no longer longer banned.</center>\n";
     echo "<center>Please be aware that ban removal display may take several minutes to update.</center>\n";
  } else {
     echo "<center>Could not remove the ban <b>". $ban . "</b> </center>\n";
  }

  fputs($irc, "quit " . $host . "\n"); //sends the disconnect message with the captured host
  $line = fgets($irc, 1024);
}
 ?>
<br />
<center>
<form action="bans.php" method="POST">
<input type="submit" value="Return" />
</form>
</center>
Never argue with an idiot. They will bring you down to their level, then beat you with experience.
Post Reply