Guest User

Untitled

a guest
Apr 11th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.80 KB | None | 0 0
  1. *//this is the class.core
  2. <?php
  3. // start functions
  4.  
  5. function customError($errno, $errstr) {
  6.     global $target, $core;
  7.     $core->msg($target, "[$errno] $errstr");
  8. }
  9.  
  10. //stop functions
  11.  
  12. class irc {
  13.  
  14.     var $botnick;
  15.     var $fp;
  16.  
  17.     function ConnectServer() {
  18.         global $fp, $botnick, $server, $port;
  19.         $fp = fsockopen($server, $port);
  20.         socket_set_blocking($fp, 0);
  21.         $this->command("USER $botnick $botnick $botnick $botnick :$botnick\n");
  22.         $this->command("NICK $botnick\n");
  23.     }
  24.  
  25.     function botReload($msg = "Normal Reload") {
  26.         exit(10);
  27.     }
  28.  
  29.     function check_module() {
  30.         return trim(shell_exec("php -l input.php"));
  31.     }
  32.  
  33.     function JoinChan($chan) {
  34.         $this->command("JOIN $chan\n");
  35.     }
  36.  
  37.     function term($term) {
  38.         echo date ("G:i:s")."\033[31m << \033[37m$term\n";
  39.     }
  40.  
  41.     function isCmd($string) {
  42.         global $fc, $command;
  43.         return ("$fc$string" == "$command");
  44.     }
  45.  
  46.     function isChanCmd($string) {
  47.         global $cfc, $command;
  48.         return ("$cfc$string" == "$command");
  49.     }
  50.  
  51.     function newPass() {
  52.         $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  53.         srand((double)microtime()*1000000);
  54.         $i = 0;
  55.         $pass = '' ;
  56.         while ($i <= 7) {
  57.             $num = rand() % 33;
  58.             $tmp = substr($chars, $num, 1);
  59.             $pass = $pass . $tmp;
  60.             $i++;
  61.         }
  62.         return $pass;
  63.     }
  64.  
  65.     function command($cmd) {
  66.         global $fp;
  67.         fwrite($fp, $cmd);
  68.         echo date ("G:i:s")."\033[31m << \033[37m$cmd";
  69.     }
  70.  
  71.     function access($nick) {
  72.         global $access;
  73.         $keys = array_keys($access);
  74.         if(in_array($nick, $keys)) {
  75.             return $access["$nick"];
  76.         }
  77.     }
  78.  
  79.     function msg($who = null, $msg = "") {
  80.         if (is_array($msg)){
  81.             foreach ($msg as $message){
  82.                     $message = str_replace("\n","",$message);
  83.                     $this->command("PRIVMSG $who :$message\n");
  84.             }
  85.         }
  86.         else {
  87.                 $msg = str_replace("\n","",$msg);
  88.                 $this->command("PRIVMSG $who :$msg\n");
  89.         }
  90.     }
  91.     function notice($who = null, $msg = "") {
  92.         if (is_array($msg)){
  93.             foreach ($msg as $message) {
  94.                     $message = str_replace("\n","",$message);
  95.                     $this->command("NOTICE $who :$message\n");
  96.             }
  97.         }
  98.         else {
  99.             $msg = str_replace("\n","",$msg);
  100.             $this->command("NOTICE $who :$msg\n");
  101.         }
  102.     }  
  103.  
  104.     function isCtcp() {
  105.         global $command;
  106.         $ctcparr = array("\x01VERSION\x01","\x01PING","\x01USERINFO\x01","\x01DCC");
  107.         return (in_array($command,$ctcparr));
  108.     }
  109.  
  110.     function nick($newnick) {
  111.         $this->command("NICK $newnick\n");
  112.         $botnick = $newnick;
  113.     }
  114.  
  115.     function cping($args) {
  116.         global $rarr, $nick, $fp, $target, $botnick;
  117.         $new = 0;
  118.         $who = $rarr[0] ? $rarr[0] : $nick;
  119.         if ($who == $botnick) {
  120.             $this->msg($target, "Ping reply from $who in fuck.you seconds.");
  121.             return;
  122.         }
  123.         $msg = implode(" ",$args);
  124.         $beg = explode(" ",microtime());
  125.         $this->msg($who, "\x01PING $msg\x01");
  126.         $recv = 'lol';
  127.         while(!stristr($recv, "$msg\x01") && $new != 5) {
  128.             $recv = str_replace(array("\r","\n"),array("",""),fgets($fp));
  129.             if($recv != "") echo date ("G:i:s")."\033[32m >> \033[37m$recv\n";
  130.             if(strstr($recv, ":No such nick/channel")) {
  131.                     $this->msg($target, "$who was not found.");
  132.                     return;
  133.             }
  134.             $test = explode(" ",microtime());
  135.             $new = (int) $test[1] - (int) $beg[1];
  136.         }
  137.         if ($new == 5 && $recv == "") {
  138.             $this->msg($target, "$who did not respond.");
  139.             return;
  140.         }
  141.         else if ($new == 5) {
  142.             $this->msg($target, "$who gave an invalid response.");
  143.             return;
  144.         }    
  145.         else {
  146.             echo date ("G:i:s")."\033[32m >> \033[37m$recv\n";
  147.             $end = explode(" ",microtime());
  148.             $ptime = ($end[1] - $beg[1]).strstr(($end[0] - $beg[0]),".");
  149.             //$this->msg($owner, "$ptime Begin:{$beg[1]} {$beg[0]} End:{$end[1]} {$end[0]}");
  150.             $this->msg($target, "Ping reply from $who in $ptime seconds.");
  151.         }
  152.     }
  153. }
  154. ?>
  155.  
  156.  
  157. *//this is the runtime
  158. <?php
  159. error_reporting(E_ALL & ~E_NOTICE);
  160. include("config.php");
  161. $core = new irc;
  162. $core->ConnectServer();
  163. $core->JoinChan($chan);
  164.  
  165. //$dbconnect = mysql_connect($dbhost, $dbuser, $dbpass);
  166. //if (!$dbconnect) die("mysql failed somewhere when connecting...");
  167. //mysql_select_db($dbname, $dbconnect);
  168.  
  169. while(!feof($fp)) {
  170.     $data = explode("\r\n", trim(fread($fp, 4096)));
  171.     if($data[0] != "") {
  172.         foreach($data as $line) {
  173.             $w = explode(" ", $line);
  174.             echo date ("G:i:s")."\033[32m >> \033[37m$line\n";
  175.             $command = false;
  176.                         $ismsg = 0;
  177.                         $hostident = false;
  178.                         $nick = false;
  179.                         $user = false;
  180.                         $host = false;
  181.                         $txtcmd = false;
  182.                         $target = false;
  183.                         $txt = false;
  184.                         $txt1 = false;
  185.                         $rest = false;
  186.                         $rarr = false;
  187.                         if(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s(.*?)\s:?((.*?\s)?(?(1)(.*?)$|$))/", $line, $greps)) {
  188.                                 $ismsg = 1;
  189.                                 $hostident = $greps[1];
  190.                                 $nick = htmlentities($greps[2]);
  191.                                 $user = $greps[3];
  192.                                 $host = $greps[4];
  193.                                 $txtcmd = $greps[5];
  194.                                 $target = $greps[6];
  195.                                 $txt = $greps[7];
  196.                                 $txt1 = trim($greps[8] != "" ? $greps[8] : $greps[9]);
  197.                                 $rest = trim($greps[8] != "" ? $greps[9] : $greps[8]);
  198.                                 $rarr = stristr($rest, " ") ? explode(" ",$rest) : array($rest);
  199.                         }
  200.                         elseif(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s:?(.*?)$/", $line, $greps)) {
  201.                                 $hostident = $greps[1];
  202.                                 $nick = $greps[2];
  203.                                 $user = $greps[3];
  204.                                 $host = $greps[4];
  205.                                 $txtcmd = $greps[5];
  206.                                 $txt = $greps[6];
  207.                                 $target = $botnick;
  208.                                 $ismsg = 0;
  209.                         }
  210.                         elseif(preg_match("/:?(.*?)\s(.*?)\s(.*?)\s:?(.*?)$/",$line,$infos)) {
  211.                                 $hostident = $infos[1];
  212.                                 $txtcmd = $infos[2];
  213.                                 $target = $infos[3];
  214.                                 $txt = $infos[4];
  215.                                 $rarr = explode(" ", $txt);
  216.                         }
  217.                         elseif(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s:?(.*?)$/", $line, $greps)) {
  218.                                 $hostident = $greps[1];
  219.                                 $nick = $greps[2];
  220.                                 $user = $greps[3];
  221.                                 $host = $greps[4];
  222.                                 $txtcmd = $greps[5];
  223.                                 $txt = $greps[6];
  224.                                 $target = $botnick;
  225.                                 $ismsg = 0;
  226.                         }
  227.                         elseif(preg_match("/:?(.*?)\s(.*?)\s(.*?)\s:?(.*?)$/",$line,$infos)) {
  228.                                 $hostident = $infos[1];
  229.                                 $txtcmd = $infos[2];
  230.                                 $target = $infos[3];
  231.                                 $txt = $infos[4];
  232.                                 $rarr = explode(" ", $txt);
  233.                         }
  234.                         if(preg_match("/:?(.*?)\s(\d{3})\s(.*?)\s:?(.*?)$/",$line,$infos)) {
  235.                                 $hostident = $infos[1];
  236.                                 $txtcmd = "SRVMSG";
  237.                                 $code = $infos[2];
  238.                                 $target = $infos[3];
  239.                                 $txt = $infos[4];
  240.                         }
  241.                         if(preg_match("/^(\w+)\s:(.*?)$/",$line,$infos)) {
  242.                                 $hostident = "SERVER";
  243.                                 $target = $botnick;
  244.                                 $txtcmd = $infos[1];
  245.                                 $txt = $infos[2];
  246.                         }
  247.             $command = htmlentities(trim($txt1),ENT_QUOTES);
  248.             $target = $target == $botnick ? $nick : $target;
  249.             $input = $core->check_module();
  250.             if(!preg_match("/syntax error, unexpected/i", $input)) {
  251.                 $error=0;
  252.                 include("input.php");
  253.             }
  254.             if(preg_match("/syntax error, unexpected/i", $input) && $error != 1) {
  255.                 $core->msg($chan, "An exception was thrown, please check the logs. Now running in safe mode.");
  256.                 $core->term($input);
  257.                 $error=1;
  258.             }
  259.             if ($txtcmd == "PING") $core->command("PONG $txt\n");
  260.            
  261.         }
  262.     }
  263. }
  264. ?>
Add Comment
Please, Sign In to add comment