From: Christian Hofstaedtler Date: Fri, 7 Feb 2014 01:53:05 +0000 (+0100) Subject: Recursor: Add api-config-dir config setting X-Git-Tag: rec-3.6.0-rc1~189^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c348c0c84831169316ea44024e44f26b36cc4dcf;p=thirdparty%2Fpdns.git Recursor: Add api-config-dir config setting Prefixed experimental- for now. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index c89a5174a7..c30a5eada5 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2065,6 +2065,7 @@ int main(int argc, char **argv) ::arg().set("experimental-webserver-address", "IP Address of webserver to listen on") = "127.0.0.1"; ::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("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 256c1bcdc5..e5b857dc2f 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -44,6 +44,22 @@ void productServerStatisticsFetch(map& out) out.swap(stats); } +static void apiWriteConfigFile(const string& filebasename, const string& content) +{ + if (::arg()["experimental-api-config-dir"].empty()) { + throw ApiException("Config Option \"experimental-api-config-dir\" must be set"); + } + + string filename = ::arg()["experimental-api-config-dir"] + "/" + filebasename + ".conf"; + ofstream ofconf(filename.c_str()); + if (!ofconf) { + throw ApiException("Could not open config fragment file '"+filename+"' for writing: "+stringerror()); + } + ofconf << "# Generated by pdns-recursor REST API, DO NOT EDIT" << endl; + ofconf << content << endl; + ofconf.close(); +} + RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm) { RecursorControlParser rcp; // inits