123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- require_once(dirname(dirname(__FILE__))."/header.php");
- require_once('xmlrpc.php');
- function atheme_login($hostname,$port, $path, $username, $password){
- $message = new xmlrpcmsg("atheme.login");
- $message->addParam(new xmlrpcval($username, "string"));
- $message->addParam(new xmlrpcval($password, "string"));
- $client = new xmlrpc_client($path, $hostname, $port);
- $response = $client->send($message);
- if(!$response->faultCode()){
- $session = explode("<string>", $response->serialize());
- $session = explode("</string", $session[1]);
- $session = $session[0];
- return Array(true,$session);
- }else{
- return Array(
- false,
- '['.$response->faultCode().'] '.$response->faultString()
- );
- }
- }
- function atheme_command($hostname, $port, $path, $sourceip, $username, $password, $service, $command, $params=NULL){
- $message = new xmlrpcmsg("atheme.login");
- $message->addParam(new xmlrpcval($username, "string"));
- $message->addParam(new xmlrpcval($password, "string"));
- $client = new xmlrpc_client($path, $hostname, $port);
- $response = $client->send($message);
- $session = NULL;
- if(!$response->faultCode()){
- $session = explode("<string>", $response->serialize());
- $session = explode("</string", $session[1]);
- $session = $session[0];
- }else{
- switch($response->faultCode()){
- case 1:
- $m = _('Insufficient Parameters to login');
- break;
- case 3:
- $m = _("Account is not registered");
- break;
- case 5:
- $m = _("Invalid Username/Password");
- break;
- case 6:
- $m = _("Account is frozen");
- break;
- default:
- $m = _("Could not log in");
- }
- return Array(false,$m);
- }
- $message = new xmlrpcmsg("atheme.command");
- $message->addParam(new xmlrpcval($session, "string"));
- $message->addParam(new xmlrpcval($username, "string"));
- $message->addParam(new xmlrpcval($sourceip, "string"));
- $message->addParam(new xmlrpcval($service, "string"));
- $message->addParam(new xmlrpcval($command, "string"));
- if($params != NULL){
- if(sizeof($params) < 2){
- foreach($params as $param){
- $message->addParam(new xmlrpcval($param, "string"));
- }
- }else{
- $firstparam = $params[0];
- $secondparam = "";
- for($i = 1; $i < sizeof($params); $i++){
- $secondparam .= $params[$i] . " ";
- }
- $secondparam = rtrim($secondparam);
- $message->addParam(new xmlrpcval($firstparam, "string"));
- $message->addParam(new xmlrpcval($secondparam, "string"));
- }
- }
- $response = $client->send($message);
- if(!$response->faultCode()){
- $response = explode("<string>", $response->serialize());
- $response = explode("</string", $response[1]);
- $response = $response[0];
- return Array(true,$response);
- }else{
- return Array(false,"Command failed: " . $response->faultString());
- }
- }
- $ircret = "";
- function ircputs($line){
- global $msg;
- global $irc;
- $msg .= str_replace(get_conf('rehash-pass','string'),'**********',$line);
- try{
- error_reporting(0);
- $r = fputs($irc,$line);
- error_reporting(E_ALL);
- }catch(Exception $e){
- $r = false;
- ircclose($e->code,$e->message);
- }
- return $r;
- }
- function ircclose($code=0,$message=null){
- global $msg;
- global $irc;
- global $ircret;
- try{
- error_reporting(0);
- $msg .= 'QUIT :'.$message;
- fputs($irc,'QUIT :'.$message);
- error_reporting(E_ALL);
- }catch(Exception $e){}
- while(!feof($irc) && $line = fgets($irc,128)){
- if(is_string($line)){
- $msg .= $line;
- }
- }
- fclose($irc);
- $ircret = '{"code":'.$code.',"message":"'.$message.'","log":'.json_encode($msg).'}';
- return $ircret;
- }
- function isval($src,$prop,$val){
- return isset($src[$prop]) && $src[$prop] == $val;
- }
- function ircrehash(){
- global $msg;
- global $irc;
- global $ircret;
- global $u;
- global $user;
- if(!isset($u)){
- $u = $user;
- }
- $msg = '';
- if(!$irc = fsockopen(get_conf('irc-server'),get_conf('irc-port'))){return ircclose(1,_("Could not connect."));}
- stream_set_timeout($irc,1) or ircclose(2,_("Could not set timeout."));
- while(!feof($irc)&&!$msg = fgets($irc,128)){}
- if(!ircputs("NICK RehashServ\r\n")){return $ircret;}
- if(!ircputs("USER RehashServ omni.irc.omnimaga.org RehashServ :RehashServ\r\n")){return $ircret;}
- while(!feof($irc)){
- $line = fgets($irc,128);
- if(is_string($line)){
- $msg .= $line;
- $data = explode(' ',$line);
- if(isval($data,1,'433')){
- return ircclose(4,_("RehashServ is already running."));
- }elseif(strrpos($line,'ERROR :Closing Link:') !== false){
- return ircclose(3,_("IRC Server refused the connection."));
- }elseif($data[0] == 'PING'){
- if(!ircputs("PONG {$data[1]}")){return $ircret;}
- }elseif(isval($data,1,'001')){
- break;
- }
- }
- }
- if(!ircputs("IDENTIFY ".get_conf('rehash-pass','string')."\r\n")){return $ircret;}
- while(!feof($irc)){
- $line = fgets($irc,128);
- if(is_string($line)){
- $msg .= $line;
- $data = explode(' ',$line);
- if(isval($data,1,'433')){
- return ircclose(4,_("RehashServ is already running."));
- }elseif(strrpos($line,'ERROR :Closing Link:') !== false){
- return ircclose(3,_("IRC Server refused the connection."));
- }elseif(strrpos($line,":You are now identified for") !== false){
- break;
- }elseif(strrpos($line,'Password incorrect.') !== false){
- return ircclose(5,_("Failed to authenticate with NickServ"));
- }
- }
- }
- if(!ircputs("HS ON\r\n")){return $ircret;}
- while(!feof($irc)){
- $line = fgets($irc,128);
- if(is_string($line)){
- $msg .= $line;
- $data = explode(' ',$line);
- if(isval($data,1,'433')){
- return ircclose(4,_("RehashServ is already running."));
- }elseif(strrpos($line,'ERROR :Closing Link:') !== false){
- return ircclose(3,_("IRC Server refused the connection."));
- }elseif(strrpos($line,':Your vhost of') !== false && strrpos($line,'is now activated') !== false){
- break;
- }elseif(strrpos($line,"Please contact an Operator to get a vhost assigned to this nick") !== false){
- return ircclose(6,_("vhost not set."));
- }
- }
- }
- if(!ircputs("OPER RehashServ ".get_conf('rehash-pass','string')."\r\n")){return $ircret;}
- if(!ircputs("REHASH -global\r\n")){return $ircret;}
- if(!ircputs("WALLOPS :{$u['nick']} has rehashed the server\r\n")){return $ircret;}
- try{
- error_reporting(0);
- $msg .= 'QUIT :'.$message;
- fputs($irc,'QUIT :'.$message);
- error_reporting(E_ALL);
- }catch(Exception $e){}
- while(!feof($irc) && $line = fgets($irc,128)){
- if(is_string($line)){
- $msg .= $line;
- }
- }
- fclose($irc);
- if(strrpos($msg,':*** Notice -- Configuration loaded without any problems ..') === false){
- return '{"code":6,"message":"'._('There is an error in the config. See console for output.').'","log":'.json_encode($msg).'}';
- }
- return '{"code":0,"message":"'._('Rehashed. View console for output.').'","log":'.json_encode($msg).'}';
- }
- ?>
|