From f8c1b8f4f9bcb06242aa7d7360ea610764565c75 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 13 Feb 2025 01:28:28 +0000 Subject: Rework the RPC modules in preparation for the new JSON-RPC module. --- docs/RPC/XMLRPC | 29 ++++++++++ docs/RPC/xmlrpc.php | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/XMLRPC/XMLRPC | 29 ---------- docs/XMLRPC/xmlrpc.php | 145 ------------------------------------------------- 4 files changed, 174 insertions(+), 174 deletions(-) create mode 100644 docs/RPC/XMLRPC create mode 100644 docs/RPC/xmlrpc.php delete mode 100644 docs/XMLRPC/XMLRPC delete mode 100644 docs/XMLRPC/xmlrpc.php (limited to 'docs') diff --git a/docs/RPC/XMLRPC b/docs/RPC/XMLRPC new file mode 100644 index 000000000..ac3f1059b --- /dev/null +++ b/docs/RPC/XMLRPC @@ -0,0 +1,29 @@ +XMLRPC using PHP's xmlrpc_encode_request and xmlrpc_decode functions is supported. +This allows external applications, such as websites, to execute remote procedure calls to Anope in real time. + +Currently there are 5 supported XMLRPC calls, provided by rpc_main: + +checkAuthentication - Takes two parameters, an account name and a password. Checks if the account name is valid and the password + is correct for the account name, useful for making login pages on websites. + +command - Takes three parameters, a service name (BotServ, ChanServ, NickServ), a user name (whether online or not), and the command + to execute. This will execute the given command to Anope using the given service name. If the user given is online, the + command reply will go to them, if not it is returned by XMLRPC. + +stats - Takes no parameters, returns miscellaneous stats that can be found in the /operserv stats command. + +channel - Takes one parameter, a channel name, and returns real time information regarding that channel, such as users, modes + (ban lists and such), topic etc. + +user - Takes one parameter, a user name, and returns real time information regarding that user. + +opers - Takes no parameters, returns opertypes, their privileges and commands. + +notice - Takes three parameters, source user, target user, and message. Sends a message to the user. + +XMLRPC was designed to be used with db_sql, and will not return any information that can be pulled from the SQL +database, such as accounts and registered channel information. It is instead used for pulling realtime data such +as users and channels currently online. For examples on how to use these calls in PHP, see xmlrpc.php in docs/XMLRPC. + +Also note that the parameter named "id" is reserved for query ID. If you pass a query to Anope containing a value for id. it will +be stored by Anope and the same id will be passed back in the result. diff --git a/docs/RPC/xmlrpc.php b/docs/RPC/xmlrpc.php new file mode 100644 index 000000000..90f07a944 --- /dev/null +++ b/docs/RPC/xmlrpc.php @@ -0,0 +1,145 @@ +host = $host; + } + + /** + * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: + * $this->raw("checkAuthentication", ["adam", "qwerty"]); + * If successful returns back an array of useful information. + * + * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. + * If you do, the same ID will be passed back with the reply from Anope. + * + * @param $name + * @param $params + * @return array|null + */ + public function run($name, $params) + { + $xmlquery = xmlrpc_encode_request($name, $params); + $context = stream_context_create(["http" => [ + "method" => "POST", + "header" => "Content-Type: text/xml", + "content" => $xmlquery]]); + + $inbuf = file_get_contents($this->host, false, $context); + $response = xmlrpc_decode($inbuf); + + if ($response) { + return $response; + } + + return null; + } + + /** + * Do Command on Service as User, eg: + * $anope->command("ChanServ", "Adam", "REGISTER #adam"); + * Returns an array of information regarding the command execution, if + * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. + * If 'online' is set to no, then the reply to the command is in the array member 'return' + * + * @param $service + * @param $user + * @param $command + * @return array|null + */ + public function command($service, $user, $command) + { + return $this->run("command", [$service, $user, $command]); + } + + /** + * Check an account/nick name and password to see if they are valid + * Returns the account display name if valid + * + * @param $account + * @param $pass + * @return string|null + */ + public function auth($account, $pass) + { + $ret = $this->run("checkAuthentication", [$account, $pass]); + + if ($ret && $ret["result"] == "Success") { + return $ret["account"]; + } + + return null; + } + + /** + * Returns an array of misc stats regarding Anope + * + * @return array|null + */ + public function stats() + { + return $this->run("stats", null); + } + + /** + * Look up data for a channel + * Returns an array containing channel information, or an array of size one + * (just containing the name) if the channel does not exist + * + * @param $channel + * @return array|null + */ + public function channel($channel) + { + return $this->run("channel", [$channel]); + } + + /** + * Sent a notice to a user. + * Returns an array containing channel information, or an array of size one + * (just containing the name) if the channel does not exist + * + * @param $source + * @param $target + * @param $message + * @return array|null + */ + public function notice($source, $target, $message) + { + return $this->run("notice", [$source, $target, $message]); + } + + /** + * Like channel(), but different. + * + * @param $user + * @return array|null + */ + public function user($user) + { + return $this->run("user", [$user]); + } +} + +$anope = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); diff --git a/docs/XMLRPC/XMLRPC b/docs/XMLRPC/XMLRPC deleted file mode 100644 index 72f81e4b8..000000000 --- a/docs/XMLRPC/XMLRPC +++ /dev/null @@ -1,29 +0,0 @@ -XMLRPC using PHP's xmlrpc_encode_request and xmlrpc_decode functions is supported. -This allows external applications, such as websites, to execute remote procedure calls to Anope in real time. - -Currently there are 5 supported XMLRPC calls, provided by xmlrpc_main: - -checkAuthentication - Takes two parameters, an account name and a password. Checks if the account name is valid and the password - is correct for the account name, useful for making login pages on websites. - -command - Takes three parameters, a service name (BotServ, ChanServ, NickServ), a user name (whether online or not), and the command - to execute. This will execute the given command to Anope using the given service name. If the user given is online, the - command reply will go to them, if not it is returned by XMLRPC. - -stats - Takes no parameters, returns miscellaneous stats that can be found in the /operserv stats command. - -channel - Takes one parameter, a channel name, and returns real time information regarding that channel, such as users, modes - (ban lists and such), topic etc. - -user - Takes one parameter, a user name, and returns real time information regarding that user. - -opers - Takes no parameters, returns opertypes, their privileges and commands. - -notice - Takes three parameters, source user, target user, and message. Sends a message to the user. - -XMLRPC was designed to be used with db_sql, and will not return any information that can be pulled from the SQL -database, such as accounts and registered channel information. It is instead used for pulling realtime data such -as users and channels currently online. For examples on how to use these calls in PHP, see xmlrpc.php in docs/XMLRPC. - -Also note that the parameter named "id" is reserved for query ID. If you pass a query to Anope containing a value for id. it will -be stored by Anope and the same id will be passed back in the result. diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php deleted file mode 100644 index 90f07a944..000000000 --- a/docs/XMLRPC/xmlrpc.php +++ /dev/null @@ -1,145 +0,0 @@ -host = $host; - } - - /** - * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: - * $this->raw("checkAuthentication", ["adam", "qwerty"]); - * If successful returns back an array of useful information. - * - * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. - * If you do, the same ID will be passed back with the reply from Anope. - * - * @param $name - * @param $params - * @return array|null - */ - public function run($name, $params) - { - $xmlquery = xmlrpc_encode_request($name, $params); - $context = stream_context_create(["http" => [ - "method" => "POST", - "header" => "Content-Type: text/xml", - "content" => $xmlquery]]); - - $inbuf = file_get_contents($this->host, false, $context); - $response = xmlrpc_decode($inbuf); - - if ($response) { - return $response; - } - - return null; - } - - /** - * Do Command on Service as User, eg: - * $anope->command("ChanServ", "Adam", "REGISTER #adam"); - * Returns an array of information regarding the command execution, if - * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. - * If 'online' is set to no, then the reply to the command is in the array member 'return' - * - * @param $service - * @param $user - * @param $command - * @return array|null - */ - public function command($service, $user, $command) - { - return $this->run("command", [$service, $user, $command]); - } - - /** - * Check an account/nick name and password to see if they are valid - * Returns the account display name if valid - * - * @param $account - * @param $pass - * @return string|null - */ - public function auth($account, $pass) - { - $ret = $this->run("checkAuthentication", [$account, $pass]); - - if ($ret && $ret["result"] == "Success") { - return $ret["account"]; - } - - return null; - } - - /** - * Returns an array of misc stats regarding Anope - * - * @return array|null - */ - public function stats() - { - return $this->run("stats", null); - } - - /** - * Look up data for a channel - * Returns an array containing channel information, or an array of size one - * (just containing the name) if the channel does not exist - * - * @param $channel - * @return array|null - */ - public function channel($channel) - { - return $this->run("channel", [$channel]); - } - - /** - * Sent a notice to a user. - * Returns an array containing channel information, or an array of size one - * (just containing the name) if the channel does not exist - * - * @param $source - * @param $target - * @param $message - * @return array|null - */ - public function notice($source, $target, $message) - { - return $this->run("notice", [$source, $target, $message]); - } - - /** - * Like channel(), but different. - * - * @param $user - * @return array|null - */ - public function user($user) - { - return $this->run("user", [$user]); - } -} - -$anope = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); -- cgit