::arg().set("api-config-dir", "Directory where REST API stores config and zones") = "";
::arg().set("api-key", "Static pre-shared authentication key for access to the REST API") = "";
::arg().set("api-logfile", "Location of the server logfile (used by the REST API)") = "/var/log/pdns.log";
- ::arg().set("api-readonly", "Disallow data modification through the REST API when set") = "no";
::arg().setSwitch("webserver", "Start a webserver (for REST API)") = "no";
::arg().set("webserver-address", "IP Address of webserver to listen on") = "127.0.0.1";
::arg().set("webserver-port", "Port of webserver to listen on") = "8082";
::arg().parse(argc,argv);
- if( !::arg()["chroot"].empty() && !::arg()["api-config-dir"].empty() && !::arg().mustDo("api-readonly") ) {
- g_log<<Logger::Error<<"Using chroot and a writable API is not possible"<<endl;
+ if( !::arg()["chroot"].empty() && !::arg()["api-config-dir"].empty() ) {
+ g_log<<Logger::Error<<"Using chroot and enabling the API is not possible"<<endl;
exit(EXIT_FAILURE);
}
}
resp->setBody(document);
- } else if (req->method == "POST" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "POST") {
auto document = req->json();
string kind;
vector<string> entries;
document["metadata"] = entries;
resp->setBody(document);
- } else if (req->method == "PUT" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "PUT") {
auto document = req->json();
if (!isValidMetadataKind(kind, false))
};
resp->setBody(key);
- } else if (req->method == "DELETE" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "DELETE") {
if (!isValidMetadataKind(kind, false))
throw ApiException("Unsupported metadata kind '" + kind + "'");
if (req->method == "GET") {
apiZoneCryptokeysGET(zonename, inquireKeyId, resp, &dk);
- } else if (req->method == "DELETE" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "DELETE") {
if (inquireKeyId == -1)
throw HttpBadRequestException();
apiZoneCryptokeysDELETE(zonename, inquireKeyId, req, resp, &dk);
- } else if (req->method == "POST" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "POST") {
apiZoneCryptokeysPOST(zonename, req, resp, &dk);
- } else if (req->method == "PUT" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "PUT") {
if (inquireKeyId == -1)
throw HttpBadRequestException();
apiZoneCryptokeysPUT(zonename, inquireKeyId, req, resp, &dk);
static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
UeberBackend B;
DNSSECKeeper dk(&B);
- if (req->method == "POST" && !::arg().mustDo("api-readonly")) {
+ if (req->method == "POST") {
DomainInfo di;
auto document = req->json();
DNSName zonename = apiNameToDNSName(stringFromJson(document, "name"));
throw HttpNotFoundException();
}
- if(req->method == "PUT" && !::arg().mustDo("api-readonly")) {
+ if(req->method == "PUT") {
// update domain settings
updateDomainSettingsFromDocument(B, di, zonename, req->json());
resp->status = 204; // No Content, but indicate success
return;
}
- else if(req->method == "DELETE" && !::arg().mustDo("api-readonly")) {
+ else if(req->method == "DELETE") {
// delete domain
if(!di.backend->deleteDomain(zonename))
throw ApiException("Deleting domain '"+zonename.toString()+"' failed: backend delete failed/unsupported");
resp->body = "";
resp->status = 204; // No Content: declare that the zone is gone now
return;
- } else if (req->method == "PATCH" && !::arg().mustDo("api-readonly")) {
+ } else if (req->method == "PATCH") {
patchZone(req, resp);
return;
} else if (req->method == "GET") {
static void apiServerZoneAxfrRetrieve(HttpRequest* req, HttpResponse* resp) {
DNSName zonename = apiZoneIdToName(req->parameters["id"]);
- if(req->method != "PUT" || ::arg().mustDo("api-readonly"))
+ if(req->method != "PUT")
throw HttpMethodNotAllowedException();
UeberBackend B;
static void apiServerZoneNotify(HttpRequest* req, HttpResponse* resp) {
DNSName zonename = apiZoneIdToName(req->parameters["id"]);
- if(req->method != "PUT" || ::arg().mustDo("api-readonly"))
+ if(req->method != "PUT")
throw HttpMethodNotAllowedException();
UeberBackend B;
}
void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) {
- if(req->method != "PUT" || ::arg().mustDo("api-readonly"))
+ if(req->method != "PUT")
throw HttpMethodNotAllowedException();
DNSName canon = apiNameToDNSName(req->getvars["domain"]);
static void apiServerConfigAllowFrom(HttpRequest* req, HttpResponse* resp)
{
- if (req->method == "PUT" && !::arg().mustDo("api-readonly")) {
+ if (req->method == "PUT") {
Json document = req->json();
auto jlist = document["value"];
static void apiServerZones(HttpRequest* req, HttpResponse* resp)
{
- if (req->method == "POST" && !::arg().mustDo("api-readonly")) {
+ if (req->method == "POST") {
if (::arg()["api-config-dir"].empty()) {
throw ApiException("Config Option \"api-config-dir\" must be set");
}
if (iter == SyncRes::t_sstorage.domainmap->end())
throw ApiException("Could not find domain '"+zonename.toLogString()+"'");
- if(req->method == "PUT" && !::arg().mustDo("api-readonly")) {
+ if(req->method == "PUT") {
Json document = req->json();
doDeleteZone(zonename);
resp->body = "";
resp->status = 204; // No Content, but indicate success
}
- else if(req->method == "DELETE" && !::arg().mustDo("api-readonly")) {
+ else if(req->method == "DELETE") {
if (!doDeleteZone(zonename)) {
throw ApiException("Deleting domain failed");
}