From 2a4d0e3e898f1ee2395b5e83198d68a5e646a640 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 10 Dec 2010 15:34:52 -0500 Subject: Allow getting users opertype from XMLRPC requests --- modules/extra/m_xmlrpc.cpp | 2 ++ modules/extra/m_xmlrpc_main.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'modules') diff --git a/modules/extra/m_xmlrpc.cpp b/modules/extra/m_xmlrpc.cpp index 4b15499b8..b345ce183 100644 --- a/modules/extra/m_xmlrpc.cpp +++ b/modules/extra/m_xmlrpc.cpp @@ -18,6 +18,7 @@ class MyXMLRPCClientSocket : public XMLRPCClientSocket if (message.find("") != Anope::string::npos) { + Log(LOG_DEBUG) << "m_xmlrpc: Processing message"; this->HandleMessage(); this->query.clear(); } @@ -254,6 +255,7 @@ void MyXMLRPCClientSocket::HandleMessage() while (this->GetData(name, data)) { + Log(LOG_DEBUG) << "m_xmlrpc: Tag name: " << name << ", data: " << data; if (name == "methodName") request.name = data; else if (name == "name" && data == "id") diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp index 59088792f..8d4cdf56e 100644 --- a/modules/extra/m_xmlrpc_main.cpp +++ b/modules/extra/m_xmlrpc_main.cpp @@ -1,6 +1,7 @@ #include "module.h" #include "xmlrpc.h" +// XXX We no longer need this, we need to modify CommandSource to allow commands to go back here class XMLRPCUser : public User { Anope::string out; @@ -56,6 +57,8 @@ class MyXMLRPCEvent : public XMLRPCEvent this->DoChannel(iface, source, request); else if (request->name == "user") this->DoUser(iface, source, request); + else if (request->name == "opers") + this->DoOperType(iface, source, request); } void DoCommand(XMLRPCServiceInterface *iface, XMLRPCClientSocket *source, XMLRPCRequest *request) @@ -108,9 +111,15 @@ class MyXMLRPCEvent : public XMLRPCEvent XMLRPCListenSocket *ls = static_cast(source->LS); if (ls->username.empty() && ls->password.empty()) + { request->reply("result", "Logged in"); + source->logged_in = true; + } else if (request->data.size() > 1 && request->data[0] == ls->username && request->data[1] == ls->password) + { request->reply("result", "Logged in"); + source->logged_in = true; + } else request->reply("error", "Invalid credentials"); } @@ -237,7 +246,11 @@ class MyXMLRPCEvent : public XMLRPCEvent request->reply("timestamp", stringify(u->timestamp)); request->reply("signon", stringify(u->my_signon)); if (u->Account()) + { request->reply("account", iface->Sanitize(u->Account()->display)); + if (u->Account()->ot) + request->reply("opertype", iface->Sanitize(u->Account()->ot->GetName())); + } Anope::string channels; for (UChannelList::const_iterator it = u->chans.begin(); it != u->chans.end(); ++it) @@ -252,6 +265,19 @@ class MyXMLRPCEvent : public XMLRPCEvent } } } + + void DoOperType(XMLRPCServiceInterface *iface, XMLRPCClientSocket *source, XMLRPCRequest *request) + { + for (std::list::const_iterator it = Config->MyOperTypes.begin(), it_end = Config->MyOperTypes.end(); it != it_end; ++it) + { + Anope::string perms; + for (std::list::const_iterator it2 = (*it)->GetPrivs().begin(), it2_end = (*it)->GetPrivs().end(); it2 != it2_end; ++it2) + perms += " " + *it2; + for (std::list::const_iterator it2 = (*it)->GetCommands().begin(), it2_end = (*it)->GetCommands().end(); it2 != it2_end; ++it2) + perms += " " + *it2; + request->reply((*it)->GetName(), perms); + } + } }; class ModuleXMLRPCMain : public Module -- cgit