anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
xmlrpc.php (3649B)
1 <?php 2 3 /** 4 * XMLRPC Functions 5 * 6 * (C) 2003-2022 Anope Team 7 * Contact us at team@anope.org 8 */ 9 10 class AnopeXMLRPC 11 { 12 /** 13 * The XMLRPC host 14 * 15 * @var string 16 */ 17 private $host; 18 19 /** 20 * Initiate a new AnopeXMLRPC instance 21 * 22 * @param $host 23 */ 24 public function __construct($host) 25 { 26 $this->host = $host; 27 } 28 29 /** 30 * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: 31 * $this->raw("checkAuthentication", ["adam", "qwerty"]); 32 * If successful returns back an array of useful information. 33 * 34 * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. 35 * If you do, the same ID will be passed back with the reply from Anope. 36 * 37 * @param $name 38 * @param $params 39 * @return array|null 40 */ 41 public function run($name, $params) 42 { 43 $xmlquery = xmlrpc_encode_request($name, $params); 44 $context = stream_context_create(["http" => [ 45 "method" => "POST", 46 "header" => "Content-Type: text/xml", 47 "content" => $xmlquery]]); 48 49 $inbuf = file_get_contents($this->host, false, $context); 50 $response = xmlrpc_decode($inbuf); 51 52 if ($response) { 53 return $response; 54 } 55 56 return null; 57 } 58 59 /** 60 * Do Command on Service as User, eg: 61 * $anope->command("ChanServ", "Adam", "REGISTER #adam"); 62 * Returns an array of information regarding the command execution, if 63 * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. 64 * If 'online' is set to no, then the reply to the command is in the array member 'return' 65 * 66 * @param $service 67 * @param $user 68 * @param $command 69 * @return array|null 70 */ 71 public function command($service, $user, $command) 72 { 73 return $this->run("command", [$service, $user, $command]); 74 } 75 76 /** 77 * Check an account/nick name and password to see if they are valid 78 * Returns the account display name if valid 79 * 80 * @param $account 81 * @param $pass 82 * @return string|null 83 */ 84 public function auth($account, $pass) 85 { 86 $ret = $this->run("checkAuthentication", [$account, $pass]); 87 88 if ($ret && $ret["result"] == "Success") { 89 return $ret["account"]; 90 } 91 92 return null; 93 } 94 95 /** 96 * Returns an array of misc stats regarding Anope 97 * 98 * @return array|null 99 */ 100 public function stats() 101 { 102 return $this->run("stats", null); 103 } 104 105 /** 106 * Look up data for a channel 107 * Returns an array containing channel information, or an array of size one 108 * (just containing the name) if the channel does not exist 109 * 110 * @param $channel 111 * @return array|null 112 */ 113 public function channel($channel) 114 { 115 return $this->run("channel", [$channel]); 116 } 117 118 /** 119 * Sent a notice to a user. 120 * Returns an array containing channel information, or an array of size one 121 * (just containing the name) if the channel does not exist 122 * 123 * @param $source 124 * @param $target 125 * @param $message 126 * @return array|null 127 */ 128 public function notice($source, $target, $message) 129 { 130 return $this->run("notice", [$source, $target, $message]); 131 } 132 133 /** 134 * Like channel(), but different. 135 * 136 * @param $user 137 * @return array|null 138 */ 139 public function user($user) 140 { 141 return $this->run("user", [$user]); 142 } 143 } 144 145 $anope = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc");