Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.25 KB | None | 0 0
  1. <?php
  2. //If we're running from the command prompt, CLI will be 1. If running through a web server, CLI will be 0.
  3. define("CLI", !isset($_SERVER['HTTP_USER_AGENT']));
  4. define(using_secondary_nick,NULL);
  5. date_default_timezone_set("BST");
  6. error_reporting(E_ALL);
  7. $connect = @mysql_connect("localhost","root","rolex123");
  8. if (!$connect){
  9.      echo("<p>Unable to connect to database server.</p>");
  10.      die('Could not connect: ' . mysql_error());
  11.      exit;
  12. }
  13.  
  14. if (! @mysql_select_db("IRCBot")){
  15.      echo("<p>Unable to connect to the database '");
  16.      echo("IRCBot");
  17.      echo("'</p>");
  18.      exit;
  19. }
  20. $searchfor = array(     "/\\00310(.+?)\\003(10|)/",
  21.                         "/\\00311(.+?)\\003(11|)/",
  22.                         "/\\00312(.+?)\\003(12|)/",
  23.                         "/\\00313(.+?)\\003(13|)/",
  24.                         "/\\00314(.+?)\\003(14|)/",
  25.                         "/\\00315(.+?)\\003(15|)/",
  26.                         "/\\001(.+?)\\001/",
  27.                         "/\\002(.+?)\\002/",
  28.                         "/\\0030(.+?)\\003(0|)/",
  29.                         "/\\0031(.+?)\\003(1|)/",
  30.                         "/\\0032(.+?)\\003(2|)/",
  31.                         "/\\0033(.+?)\\003(3|)/",
  32.                         "/\\0034(.+?)\\003(4|)/",
  33.                         "/\\0035(.+?)\\003(5|)/",
  34.                         "/\\0036(.+?)\\003(6|)/",
  35.                         "/\\0037(.+?)\\003(7|)/",
  36.                         "/\\0038(.+?)\\003(8|)/",
  37.                         "/\\0039(.+?)\\003(9|)/");
  38. $replacewith = array(   "<span style='color: Teal;'>\\1</span>",
  39.                         "<span style='color: blue;'>\\1</span>",
  40.                         "<span style='color: #00fcf7;'>\\1</span>",
  41.                         "<span style='color: Pink;'>\\1</span>",
  42.                         "<span style='color: Grey;'>\\1</span>",
  43.                         "<span style='color: LightGrey;'>\\1</span>",
  44.                         "<u>\\1</u>",
  45.                         "<b>\\1</b>",
  46.                         "<span style='color: White;'>\\1</span>",
  47.                         "<span style='color: Black;'>\\1</span>",
  48.                         "<span style='color: Blue;'>\\1</span>",
  49.                         "<span style='color: Green;'>\\1</span>",
  50.                         "<span style='color: Red;'>\\1</span>",
  51.                         "<span style='color: Brown;'>\\1</span>",
  52.                         "<span style='color: Purple;'>\\1</span>",
  53.                         "<span style='color: Orange;'>\\1</span>",
  54.                         "<span style='color: Yellow;'>\\1</span>",
  55.                         "<span style='color: #00fc00;'>\\1</span>");
  56. set_time_limit(0);
  57. error_reporting(E_ALL);
  58. include("config.php");
  59. include("irc.to.html.php");
  60. foreach($server_chan as $chan => $pass){
  61.     $channels_info[$chan]["users"] = array();
  62.     $channels_info[$chan]["name"] = $chan;
  63. }
  64.  
  65. $plugins = array();
  66. include("plugins/autoload.php");
  67.  
  68. $server = array();
  69. $server['SOCKET'] = fsockopen($server_host, $server_port, $errno, $errstr, 5);
  70. if($server['SOCKET']){
  71.     if($global_vars['type'] == "client"){
  72.         SendCommand("PASS NOPASS\r");
  73.         SendCommand("NICK ".$global_vars['bot_nickname']."\r");
  74.         SendCommand("USER ".$global_vars['bot_nickname']." USING PHP IRC\r");
  75.     }
  76.     else{
  77.         SendCommand("PASS services\r");
  78.         SendCommand("SERVER BBot.alexmonk.co.uk 1 :The one and only\r");
  79.     }
  80.    
  81.     $global_vars['is_fully_connected'] = FALSE;
  82.     $channel_importantpeople = array();
  83.     while(!feof($server['SOCKET'])){
  84.         //$msg_was_encrypted = FALSE;
  85.         $server['READ_BUFFER'] = htmlentities(fgets($server['SOCKET'], 1024));
  86.         if($server['READ_BUFFER'] != ""){
  87.             if(CLI == 0){
  88.                 //echo date("[d/m/Y H:i:s]")."[RECIEVE] ".preg_replace($searchfor,$replacewith,$server['READ_BUFFER'])."<br>\r\n";
  89.                 $output = preg_replace($searchfor,$replacewith,$server['READ_BUFFER']);
  90.                 //echo date("[d/m/Y H:i:s]")."[RECIEVE] ".topic_format_html($a,strlen($a),TRUE)."<br>\r\n";
  91.                 echo date("[d/m/Y H:i:s]")."[RECIEVE] ".$output."<br>\r\n";
  92.             }
  93.             else{
  94.                 echo strip_tags(date("[d/m/Y H:i:s]")."[RECIEVE] ".preg_replace($searchfor,$replacewith,$server['READ_BUFFER'])."<br>\r\n");
  95.             }
  96.             //echo date("[d/m/Y H:i:s]")."[RECIEVE] ".$server['READ_BUFFER']."<br>\n\r"; //display the recived data from the server
  97.         }
  98.        
  99.         foreach($plugins as $plugin => $plugin_main_function_prefix){
  100.             eval("".$plugin_main_function_prefix."Main(\$server,\$global_vars);");
  101.         }
  102.        
  103.         if(substr($server['READ_BUFFER'], 0, 6) == "PING :"){
  104.             SendCommand("PONG :".substr($server['READ_BUFFER'], 6)."\n\r");
  105.         }
  106.         elseif(preg_match("/^:(.+?)!(.+?)@(.+?) PRIVMSG (E-Bot|(&|#)(.+?)) :!loadplugin (.+?)$/",$server['READ_BUFFER'],$matches)){
  107.             if(in_array($matches[1],$global_vars['bot_masters'])){
  108.                 $matches[7] = trim($matches[7]);
  109.                 include("plugins/".$matches[7]);
  110.                 echo date("[d/m/Y H:i:s]")."[INTERNAL MESSAGE] Attempting to load plugin '".$matches[7]."'.<br>\r\n";
  111.             }
  112.         }
  113.         elseif(preg_match("/^:(.+?)!(.+?)@(.+?) PRIVMSG (E-Bot|(&|#)(.+?)) :!unloadplugin (.+?)/",$server['READ_BUFFER'],$matches)){
  114.             if(in_array($matches[1],$global_vars['bot_masters'])){
  115.                 $matches[7] = trim($matches[7]);
  116.                 unset($plugins[$matches[7]]);
  117.             }
  118.         }
  119.         elseif(preg_match("/:(.+?)!(.+?)@(.+?) PRIVMSG (E-Bot|(&|#)(.+?)) :!restart(.+?)$/",$server['READ_BUFFER'],$matches)){
  120.             if(in_array($matches[1],$global_vars['bot_masters'])){
  121.                 if(CLI == 0){
  122.                     $matches[7] = trim($matches[7]);
  123.                     if($matches[7] != ""){
  124.                         foreach($server_chan as $chan => $pass){
  125.                             SendCommand("PART ".$chan." :Restarting...\r");
  126.                         }
  127.                         fclose($server['SOCKET']);
  128.                         echo "Connection closed. Reloading page in ".$matches[7]." seconds.<br>\r\n";
  129.                         echo "<meta http-equiv=\"refresh\" content=\"".$matches[7]."\">";
  130.                         exit;
  131.                     }
  132.                     else{
  133.                         foreach($server_chan as $chan => $pass){
  134.                             SendCommand("PART ".$chan." :Restarting...\r");
  135.                         }
  136.                         fclose($server['SOCKET']);
  137.                         echo "Connection closed. Reloading page.<br>\r\n";
  138.                         echo "<meta http-equiv=\"refresh\" content=\"0\">";
  139.                         exit;
  140.                     }
  141.                 }
  142.                 else{
  143.                     SendCommand("PRIVMSG ".$matches[4]." :Cannot restart bot - running from command line. Please restart the bot manually.");
  144.                 }
  145.             }
  146.         }
  147.         elseif(preg_match("/^:(.+?) (422|376) E-Bot :(MOTD File is missing|End of \/MOTD command|End of message of the day.)/",$server['READ_BUFFER'])){
  148.             if($global_vars['secondary_nick_active'] == TRUE){
  149.                 SendCommand("PRIVMSG NickServ :GHOST E-Bot rolex123\r");
  150.             }
  151.             foreach($server_chan as $chan => $pass){
  152.                 if($pass != ""){
  153.                     SendCommand("JOIN ".$chan." ".$pass."\n\r");
  154.                 }
  155.                 else{
  156.                     SendCommand("JOIN ".$chan."\n\r");
  157.                 }
  158.             }
  159.             $global_vars['is_fully_connected'] = TRUE;
  160.         }
  161.         elseif(preg_match("/^:NickServ!services@azelphur.com (PRIVMSG|NOTICE) E-Bot :please choose a different nick./",$server['READ_BUFFER'])){
  162.             SendCommand("MODE E-Bot +B\r");
  163.             SendCommand($authcommand."\r");
  164.             SendCommand("PRIVMSG NickServ :update\r");
  165.         }
  166.         elseif(preg_match("/^(.+?)!(.+?)@(.+?) INVITE E-Bot :(#|&)(.+?)$/",$server['READ_BUFFER'],$matches)){
  167.             $matches[5] = trim($matches[5]);
  168.             if(in_array($matches[5],$join_chans_on_invite)){
  169.                 SendCommand("JOIN :".$matches[4].$matches[5]."\r");
  170.             }
  171.         }
  172.         elseif(preg_match("/^:irc.azelphur.com 433 \* E-Bot :Nickname is already in use./",$server['READ_BUFFER'])){
  173.             SendCommand("NICK E-Bot_\r");
  174.             $global_vars['secondary_nick_active'] = TRUE;
  175.         }
  176.         elseif(preg_match("/^:(.+?)!(.+?)@(.+?) (NOTICE|PRIVMSG) E-Bot :(E-Bot |!)rehash $/",$server['READ_BUFFER'])){
  177.             include("config.php");
  178.         }
  179.         flush();
  180.     }
  181. }
  182.  
  183. function SendCommand($cmd){
  184.     global $server;
  185.     global $searchfor;
  186.     global $replacewith;
  187.     fwrite($server['SOCKET'], $cmd, strlen($cmd));
  188.     if(CLI == 0){
  189.         echo date("[d/m/Y H:i:s]")."[SEND] ".preg_replace($searchfor,$replacewith,$cmd)." <br>";
  190.     }
  191.     else{
  192.         echo strip_tags(date("[d/m/Y H:i:s]")."[SEND] ".preg_replace($searchfor,$replacewith,$cmd)." <br>");
  193.     }
  194. }
  195.  
  196. // String EnCrypt + DeCrypt function
  197. // Author: halojoy, July 2006
  198. function convert($str, $ky = ''){
  199.     //If the key is nothing, return the string without doing anything to it.
  200.     if($ky == ''){
  201.         return $str;
  202.     }
  203.    
  204.     $ky = str_replace(chr(32), '', $ky); //Replace all spaces in the key with nothing
  205.    
  206.     //Check the key is long enough
  207.     if(strlen($ky) < 8){
  208.         return "Key was too short. Minimum 8 characters.";
  209.     }
  210.    
  211.     //If the key lengh is smaller than 32, $kl will be set to the lengh
  212.     //If not, then it is set to 32.
  213.     if(strlen($ky) < 32){
  214.         $kl = strlen($ky);
  215.     }
  216.     else{
  217.         $kl = 32;
  218.     }
  219.    
  220.     $k = array();
  221.     for($i = 0; $i < $kl; $i++){
  222.         $k[$i] = ord($ky{$i})&0x1F;
  223.     }
  224.    
  225.     $j = 0;
  226.    
  227.     for($i = 0; $i < strlen($str); $i++){
  228.         $e = ord($str{$i});
  229.         if($e&0xE0){
  230.             $str{$i} = chr($e^$k[$j]);
  231.         }
  232.         else{
  233.             $str{$i} = chr($e);
  234.         }
  235.        
  236.         $j++;
  237.        
  238.         if($j == $kl){
  239.             $j = 0;
  240.         }
  241.         else{
  242.             $j = $j;
  243.         }
  244.     }
  245.     return $str;
  246. }
  247. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement