]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: add api-readonly to Recursor 1350/head
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 1 Apr 2014 12:40:19 +0000 (14:40 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 1 Apr 2014 13:42:10 +0000 (15:42 +0200)
pdns/pdns_recursor.cc
pdns/ws-recursor.cc

index f02b37a6e64b250d2bdfc7504ac8ce129198bade..3c4f96be58852693e04c6fbbe748689c4fafbbbf 100644 (file)
@@ -2091,6 +2091,7 @@ int main(int argc, char **argv)
     ::arg().set("experimental-webserver-port", "Port of webserver to listen on") = "8082";
     ::arg().set("experimental-webserver-password", "Password required for accessing the webserver") = "";
     ::arg().set("experimental-api-config-dir", "Directory where REST API stores config and zones") = "";
+    ::arg().set("experimental-api-readonly", "If the JSON API should disallow data modification") = "no";
     ::arg().set("quiet","Suppress logging of questions and answers")="";
     ::arg().set("logging-facility","Facility to log messages as. 0 corresponds to local0")="";
     ::arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR;
index e62a210b49840f7c8f674a59eca646922a258500..240f6af452b2474c98b5bfbb71077960b68cf4a4 100644 (file)
@@ -65,7 +65,7 @@ static void apiWriteConfigFile(const string& filebasename, const string& content
 
 static void apiServerConfigAllowFrom(HttpRequest* req, HttpResponse* resp)
 {
-  if (req->method == "PUT") {
+  if (req->method == "PUT" && !::arg().mustDo("experimental-api-readonly")) {
     Document document;
     req->json(document);
     const Value &jlist = document["value"];
@@ -258,7 +258,7 @@ static bool doDeleteZone(const string& zonename)
 
 static void apiServerZones(HttpRequest* req, HttpResponse* resp)
 {
-  if (req->method == "POST") {
+  if (req->method == "POST" && !::arg().mustDo("experimental-api-readonly")) {
     if (::arg()["experimental-api-config-dir"].empty()) {
       throw ApiException("Config Option \"experimental-api-config-dir\" must be set");
     }
@@ -323,7 +323,7 @@ static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp)
   if (iter == t_sstorage->domainmap->end())
     throw ApiException("Could not find domain '"+zonename+"'");
 
-  if(req->method == "PUT") {
+  if(req->method == "PUT" && !::arg().mustDo("experimental-api-readonly")) {
     Document document;
     req->json(document);
 
@@ -332,7 +332,7 @@ static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp)
     reloadAuthAndForwards();
     fillZone(stringFromJson(document, "name"), resp);
   }
-  else if(req->method == "DELETE") {
+  else if(req->method == "DELETE" && !::arg().mustDo("experimental-api-readonly")) {
     if (!doDeleteZone(zonename)) {
       throw ApiException("Deleting domain failed");
     }