summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/modules.example.conf8
-rw-r--r--docs/RPC/RPC21
-rw-r--r--docs/RPC/jsonrpc.php150
-rw-r--r--modules/rpc/rpc_main.cpp189
4 files changed, 0 insertions, 368 deletions
diff --git a/data/modules.example.conf b/data/modules.example.conf
index b6c86871d..90cd0c83a 100644
--- a/data/modules.example.conf
+++ b/data/modules.example.conf
@@ -924,14 +924,6 @@ module
#module { name = "rpc_data" }
/*
- * rpc_main
- *
- * Adds the main RPC core methods.
- * Requires xmlrpc.
- */
-#module { name = "rpc_main" }
-
-/*
* rpc_message
*
* Adds support for the following RPC methods:
diff --git a/docs/RPC/RPC b/docs/RPC/RPC
deleted file mode 100644
index eee81c632..000000000
--- a/docs/RPC/RPC
+++ /dev/null
@@ -1,21 +0,0 @@
-RPC using JSON-RPC and XML-RPC (using PECL'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 RPC 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 RPC.
-
-stats - Takes no parameters, returns miscellaneous stats that can be found in the /operserv stats command.
-
-RPC 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/RPC.
-
-Also note that when using XMLRPC 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/jsonrpc.php b/docs/RPC/jsonrpc.php
deleted file mode 100644
index 4e9b52ba9..000000000
--- a/docs/RPC/jsonrpc.php
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-
-/**
- * JSON-RPC functions
- *
- * (C) 2003-2025 Anope Team
- * Contact us at team@anope.org
- */
-
-class AnopeRPC
-{
- /**
- * The RPC host
- *
- * @var string
- */
- private $host;
-
- /**
- * Initiate a new AnopeRPC instance
- *
- * @param $host
- */
- public function __construct($host)
- {
- $this->host = $host;
- }
-
- /**
- * Run an RPC 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)
- {
- $request = json_encode([
- "jsonrpc" => "2.0",
- "id" => uniqid(),
- "method" => $name,
- "params" => $params,
- ]);
- $context = stream_context_create(["http" => [
- "method" => "POST",
- "header" => "Content-Type: application/json",
- "content" => $request]]);
-
- $inbuf = file_get_contents($this->host, false, $context);
- $response = json_decode($inbuf, true);
-
- 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 && array_key_exists("result", $ret) && array_key_exists("account", $ret["result"])) {
- return $ret["result"]["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("anope.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("anope.messageUser", [$source, $target, $message]);
- }
-
- /**
- * Like channel(), but different.
- *
- * @param $user
- * @return array|null
- */
- public function user($user)
- {
- return $this->run("anope.user", [$user]);
- }
-}
-
-$anope = new AnopeRPC("http://127.0.0.1:8080/jsonrpc");
diff --git a/modules/rpc/rpc_main.cpp b/modules/rpc/rpc_main.cpp
deleted file mode 100644
index 5a9ffaff9..000000000
--- a/modules/rpc/rpc_main.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- *
- * (C) 2010-2025 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-#include "module.h"
-#include "modules/rpc.h"
-
-static Module *me;
-
-class RPCIdentifyRequest final
- : public IdentifyRequest
-{
- RPC::Request request;
- HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it
- we'll copy it here then reset the reference before we use it */
- Reference<HTTPClient> client;
- Reference<RPC::ServiceInterface> xinterface;
-
-public:
- RPCIdentifyRequest(Module *m, RPC::Request &req, HTTPClient *c, RPC::ServiceInterface *iface, const Anope::string &acc, const Anope::string &pass)
- : IdentifyRequest(m, acc, pass, c->GetIP())
- , request(req)
- , repl(request.reply)
- , client(c)
- , xinterface(iface)
- {
- }
-
- void OnSuccess() override
- {
- if (!xinterface || !client)
- return;
-
- request.reply = this->repl;
-
- request.Root().Reply("account", GetAccount());
-
- xinterface->Reply(request);
- client->SendReply(&request.reply);
- }
-
- void OnFail() override
- {
- if (!xinterface || !client)
- return;
-
- request.reply = this->repl;
-
- request.Error(RPC::ERR_CUSTOM_START, "Invalid password");
-
- xinterface->Reply(request);
- client->SendReply(&request.reply);
- }
-};
-
-class CommandRPCEvent final
- : public RPC::Event
-{
-public:
- CommandRPCEvent(Module *o)
- : RPC::Event(o, "command")
- {
- }
-
- bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
- {
- Anope::string service = request.data.size() > 0 ? request.data[0] : "";
- Anope::string user = request.data.size() > 1 ? request.data[1] : "";
- Anope::string command = request.data.size() > 2 ? request.data[2] : "";
-
- if (service.empty() || user.empty() || command.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters");
- return true;
- }
-
- BotInfo *bi = BotInfo::Find(service, true);
- if (!bi)
- {
- request.Error(RPC::ERR_CUSTOM_START, "Invalid service");
- return true;
- }
-
- NickAlias *na = NickAlias::Find(user);
-
- Anope::string out;
-
- struct RPCommandReply final
- : CommandReply
- {
- Anope::string &str;
-
- RPCommandReply(Anope::string &s) : str(s) { }
-
- void SendMessage(BotInfo *source, const Anope::string &msg) override
- {
- str += msg.replace_all_cs("\x1A", "\x20") + "\n";
- };
- }
- reply(out);
-
- User *u = User::Find(user, true);
- CommandSource source(user, u, na ? *na->nc : NULL, &reply, bi);
- Command::Run(source, command);
-
- if (!out.empty())
- request.Root().Reply("return", out);
-
- return true;
- }
-};
-
-class CheckAuthenticationRPCEvent final
- : public RPC::Event
-{
-public:
- CheckAuthenticationRPCEvent(Module *o)
- : RPC::Event(o, "checkAuthentication")
- {
- }
-
- bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
- {
- Anope::string username = request.data.size() > 0 ? request.data[0] : "";
- Anope::string password = request.data.size() > 1 ? request.data[1] : "";
-
- if (username.empty() || password.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters");
- return true;
- }
-
- auto *req = new RPCIdentifyRequest(me, request, client, iface, username, password);
- FOREACH_MOD(OnCheckAuthentication, (NULL, req));
- req->Dispatch();
- return false;
- }
-};
-
-class StatsRPCEvent final
- : public RPC::Event
-{
-public:
- StatsRPCEvent(Module *o)
- : RPC::Event(o, "stats")
- {
- }
-
- bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
- {
- auto &root = request.Root();
- root.Reply("uptime", Anope::CurTime - Anope::StartTime);
- root.Reply("uplinkname", Me->GetLinks().front()->GetName());
- {
- auto &uplinkcapab = root.ReplyArray("uplinkcapab");
- for (const auto &capab : Servers::Capab)
- uplinkcapab.Reply(capab);
- }
- root.Reply("usercount", UserListByNick.size());
- root.Reply("maxusercount", MaxUserCount);
- root.Reply("channelcount", ChannelList.size());
- return true;
- }
-};
-
-class ModuleRPCMain final
- : public Module
-{
-private:
- CommandRPCEvent commandrpcevent;
- CheckAuthenticationRPCEvent checkauthenticationrpcevent;
- StatsRPCEvent statsrpcevent;
-
-public:
- ModuleRPCMain(const Anope::string &modname, const Anope::string &creator)
- : Module(modname, creator, EXTRA | VENDOR)
- , commandrpcevent(this)
- , checkauthenticationrpcevent(this)
- , statsrpcevent(this)
- {
- me = this;
- }
-};
-
-MODULE_INIT(ModuleRPCMain)