From b4ae73221e576938b8d3697f28b95479978b3754 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Tue, 1 Apr 2014 14:40:19 +0200 Subject: [PATCH] API: add api-readonly to Recursor --- pdns/pdns_recursor.cc | 1 + pdns/ws-recursor.cc | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f02b37a6e6..3c4f96be58 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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; diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index e62a210b49..240f6af452 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -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"); } -- 2.47.2