]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add experimental json interface bridge to all pdns_control commands (command=pdns...
authorBert Hubert <bert.hubert@netherlabs.nl>
Tue, 4 Dec 2012 12:07:55 +0000 (12:07 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Tue, 4 Dec 2012 12:07:55 +0000 (12:07 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2964 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dynlistener.hh
pdns/ws.cc

index 3dbea2fb7311abd4c66c115c5cf642e83d3260a2..769aa470d74989e9087fd1cb68c3f9f881c18f4e 100644 (file)
@@ -55,6 +55,7 @@ public:
   
   static void registerFunc(const string &name, g_funk_t *gf, const string &usage="", const string &args="");
   static void registerRestFunc(g_funk_t *gf);
+  static g_funk_t* getFunc(const string& fname) { return s_funcdb[fname].func; } 
 private:
   void sendLine(const string &line);
   string getHelp();
index a848e9c1adcdf137797bd74e73254b6378585c55..ee5d38d40bbca4e3d57022da47e2dcadf2aac0d9 100644 (file)
@@ -15,6 +15,7 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 #include "utility.hh"
+#include "dynlistener.hh"
 #include "ws.hh"
 #include "json.hh"
 #include "webserver.hh"
@@ -327,7 +328,7 @@ string StatWebServer::jsonstat(const string& method, const string& post, const m
       
     map<string, string> object;
     object["number"]=lexical_cast<string>(number);
-    cerr<<"Flushed cache for '"<<ourvarmap["domain"]<<"', cleaned "<<number<<" records"<<endl;
+    //cerr<<"Flushed cache for '"<<ourvarmap["domain"]<<"', cleaned "<<number<<" records"<<endl;
     ret += returnJSONObject(object);
   }
   if(command=="get-zone") {
@@ -358,6 +359,34 @@ string StatWebServer::jsonstat(const string& method, const string& post, const m
 
     ret += "]";
   }
+  if(command == "pdns-control") {
+    if(method!="POST") {
+      map<string, string> m;
+      m["error"]="pdns-control requires a POST";
+      return ret + returnJSONObject(m);
+    }
+    // cout<<"post: "<<post<<endl;
+    rapidjson::Document document;
+    if(document.Parse<0>(post.c_str()).HasParseError()) {
+      return ret+"{\"error\": \"Unable to parse JSON\"";
+    }
+    // cout<<"Parameters: '"<<document["parameters"].GetString()<<"'\n";
+    vector<string> parameters;
+    stringtok(parameters, document["parameters"].GetString(), " \t");
+    
+    DynListener::g_funk_t* ptr=0;
+    if(!parameters.empty())
+      ptr = DynListener::getFunc(toUpper(parameters[0]));
+    map<string, string> m;
+    
+    if(ptr) {
+      m["result"] = (*ptr)(parameters, 0);
+    } else {
+      m["error"]="No such function "+toUpper(parameters[0]);
+    }
+    ret+= returnJSONObject(m);
+      
+  }
   if(command == "zone-rest") { // http://jsonstat?command=zone-rest&rest=/powerdns.nl/www.powerdns.nl/a
     vector<string> parts;
     stringtok(parts, ourvarmap["rest"], "/");
@@ -410,7 +439,6 @@ string StatWebServer::jsonstat(const string& method, const string& post, const m
         return ret+"{\"error\": \"Unable to parse JSON\"";
       }
       
-    
       DNSResourceRecord rr;
       vector<DNSResourceRecord> rrset;
       const rapidjson::Value &records= document["records"];