summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-12-10 15:34:52 -0500
committerAdam <Adam@anope.org>2010-12-12 19:37:04 -0500
commit2a4d0e3e898f1ee2395b5e83198d68a5e646a640 (patch)
tree3c2b4cc157c04e97e5db2b136bac4b81e55d3978
parent9f7a2e4da2c9917ae7a0fb2729609ef03093a312 (diff)
Allow getting users opertype from XMLRPC requests
-rw-r--r--docs/XMLRPC/xmlrpc.php10
-rw-r--r--include/opertype.h10
-rw-r--r--modules/extra/m_xmlrpc.cpp2
-rw-r--r--modules/extra/m_xmlrpc_main.cpp26
-rw-r--r--src/opertype.cpp11
5 files changed, 53 insertions, 6 deletions
diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php
index 768fcd449..31f174172 100644
--- a/docs/XMLRPC/xmlrpc.php
+++ b/docs/XMLRPC/xmlrpc.php
@@ -30,9 +30,7 @@ class AnopeXMLRPC
if ($Username && $Pass)
{
/* Login to XMLRPC, if required */
- $query = array("login", array($Username, $Pass));
- $xmlquery = xmlrpc_encode_request($query);
- socket_write($this->Socket, $xmlquery);
+ $this->RunXMLRPC("login", array($Username, $Pass));
}
}
@@ -48,7 +46,7 @@ class AnopeXMLRPC
* 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.
*/
- private function RunXMLRPC($name, $params)
+ function RunXMLRPC($name, $params)
{
$xmlquery = xmlrpc_encode_request($name, $params);
socket_write($this->Socket, $xmlquery);
@@ -97,14 +95,14 @@ class AnopeXMLRPC
*/
function DoChannel($Channel)
{
- return $this->RunXMLRPC("channel");
+ return $this->RunXMLRPC("channel", NULL);
}
/* Like DoChannel(), but different.
*/
function DoUser($User)
{
- return $this->RunXMLRPC("channel", array($User));
+ return $this->RunXMLRPC("user", array($User));
}
}
diff --git a/include/opertype.h b/include/opertype.h
index 40607b39f..b08e7643d 100644
--- a/include/opertype.h
+++ b/include/opertype.h
@@ -71,6 +71,16 @@ class CoreExport OperType
* @param ot The opertype to inherit from
*/
void Inherits(OperType *ot);
+
+ /** Gets the icommands for this opertype
+ * @return A list of commands
+ */
+ const std::list<Anope::string> &GetCommands() const;
+
+ /** Gets the privileges for this opertype
+ * @return A list of privileges
+ */
+ const std::list<Anope::string> &GetPrivs() const;
};
#endif // OPERTYPE_H
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("</methodCall>") != 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<XMLRPCListenSocket *>(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<OperType *>::const_iterator it = Config->MyOperTypes.begin(), it_end = Config->MyOperTypes.end(); it != it_end; ++it)
+ {
+ Anope::string perms;
+ for (std::list<Anope::string>::const_iterator it2 = (*it)->GetPrivs().begin(), it2_end = (*it)->GetPrivs().end(); it2 != it2_end; ++it2)
+ perms += " " + *it2;
+ for (std::list<Anope::string>::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
diff --git a/src/opertype.cpp b/src/opertype.cpp
index a4ea94dd3..dd4ec7307 100644
--- a/src/opertype.cpp
+++ b/src/opertype.cpp
@@ -66,3 +66,14 @@ void OperType::Inherits(OperType *ot)
{
this->inheritances.insert(ot);
}
+
+const std::list<Anope::string> &OperType::GetCommands() const
+{
+ return this->commands;
+}
+
+const std::list<Anope::string> &OperType::GetPrivs() const
+{
+ return this->privs;
+}
+