/** * Create a new DNS zone, or insert records into an existing DNS zone. * * If no identifier is specified, a new DNS zone is created. * * ### Request: ### * * ~~~ * { * "name": <string>, * "type": MASTER|SLAVE|NATIVE, * "master": <ipv4 optional>, * "templates": [ { * "identifier": <string> * },0..n ] * "records": [ { * "name": <string>, * "type": <string>, * "content": <string>, * "ttl": <int optional>, * "priority": <int optional> * },0..n ] * } * ~~~ * * ### Response: ### * * ~~~ * true * ~~~ * * If an identifier is specified, records will be inserted into an existing DNS zone. * * ### Request: ### * * ~~~ * { * "records": [ { * "name": <string>, * "type": <string>, * "content": <string>, * "ttl": <int optional>, * "priority": <int optional> * },0..n ] * } * ~~~ * * ### Response: ### * * ~~~ * true * ~~~ * * ### Errors (request without identifier): ### * * * 508 - Invalid request, missing required parameters or input validation failed. * * 500 - Failed to connect to database or query execution error. * * 409 - Zone already exists, or trying to insert records into a SLAVE zone. * * ### Errors (request with identifier): ### * * * 508 - Invalid request, missing required parameters or input validation failed. * * 500 - Failed to connect to database or query execution error. * * 409 - Cannot insert records into a SLAVE zone. * * 404 - Could not find zone. * * @access public * @param mixed $request Request parameters * @param string $identifier Zone identifier * @return Response True if request was successful, error message otherwise. */ public function put($request, $identifier = null) { $response = new FormattedResponse($request); $data = $request->parseData(); if ($data == null) { $response->code = Response::BADREQUEST; $response->error = "Request body was malformed. Ensure the body is in valid format."; $response->error_detail = "BODY_MALFORMED"; return $response; } if ((!isset($data->name) || !isset($data->type)) && empty($identifier)) { $response->code = Response::BADREQUEST; $response->error = "Identifier and/or entries were missing or invalid. Ensure that the body is in valid format and all required parameters are present."; $response->error_detail = "MISSING_REQUIRED_PARAMETERS"; return $response; } $validator = new ZoneValidator($data); $validator->mode_override = "add"; if (!empty($identifier)) { $validator->identifier = $identifier; } if (!$validator->validates()) { $response->code = Response::BADREQUEST; $response->error = $validator->getFormattedErrors(); $response->error_detail = $validator->getErrorDetails(); return $response; } if (!empty($identifier)) { return ZoneFunctions::create_records($response, $identifier, $data); } else { return ZoneFunctions::create_zone($response, $data); } }