function formAction($get) { // create a new Updater object $u = new Net_DNS2_Updater($get['domain'], array('nameservers' => array(NS1))); try { switch ($get['todo']) { case 'recordAdd': $record = Net_DNS2_RR::fromString($get['rr']); // add the record $u->add($record); break; case 'recordAddWizard': $cmd = formatRR($get); $record = Net_DNS2_RR::fromString($cmd); // add the record $u->add($record); break; case 'recordDel': $record = Net_DNS2_RR::fromString($get['rr']); // add the record $u->delete($record); break; } // add a TSIG / SIGO to authenticate the request if (AUTH_SIGO != NULL) { $u->signSIG0(AUTH_SIGO_NAME, AUTH_SIGO); } else { if (AUTH_TSIG != NULL) { $u->signTSIG(AUTH_TSIG_NAME, AUTH_TSIG); } } // execute the request $u->update(); echo '<p class="success">Update Result: Dynamic update is successful.</p>'; } catch (Net_DNS2_Exception $e) { echo '<p class="error">Failed: ' . $e->getMessage() . '</p>'; } if (isset($get['rr'])) { echo '<p><pre>' . $get['rr'] . '</pre></p>'; } else { echo '<p><pre>' . $cmd . '</pre></p>'; } }
function add_record($args) { foreach (array("zone", "key-name", "key-type", "key", "server", "record") as $val) { if (empty($args[$val])) { output_error('Invalid request, "' . $val . '" field is mandatory.', 400); } } $record = $args['record']; foreach (array("name", "ttl", "type", "data") as $val) { if (empty($record[$val])) { output_error('Invalid request, "' . $val . '" field is mandatory.', 400); } } $type_name = $record['type']; if (empty(Net_DNS2_Lookups::$rr_types_by_name[$type_name])) { output_error('Resource record type "' . $type_name . '" is not supported.'); } $type_id = Net_DNS2_Lookups::$rr_types_by_name[$type_name]; if (empty(Net_DNS2_Lookups::$rr_types_id_to_class[$type_id])) { output_error('Resource record type "' . $type_name . '" is not supported.'); } $type_class = Net_DNS2_Lookups::$rr_types_id_to_class[$type_id]; $u = new Net_DNS2_Updater($args['zone'], array('nameservers' => array($args['server']))); try { $u->signTSIG($args['key-name'], $args['key'], $args['key-type']); $u->add($type_class::fromString($record['name'] . ' ' . $record['ttl'] . ' IN ' . $record['type'] . ' ' . $record['data'])); $u->update(); } catch (Net_DNS2_Exception $e) { return $e->getMessage(); } return true; }
public function saveRecord($data, \App\Zone $zone) { $updater = new \Net_DNS2_Updater($zone->name, array('nameservers' => $this->servers, 'cache_type' => 'none', 'recurse' => false)); //TODO check if record type is authorized ? try { $rname = isset($data["name"]) && $data["name"] != "" ? $data["name"] . '.' . $zone->name : $zone->name; $rvalue = $data["rdata"]; if ($data["type"] == "TXT") { if (substr($rvalue, 0, 1) != '"') { $rvalue = '"' . $rvalue; } if (substr($rvalue, -1) != '"') { $rvalue = $rvalue . '"'; } } //dd($rvalue); //if record update, we delete the previous one if (array_key_exists("ori", $data)) { $ori = $data["ori"]; $orirecord = \Net_DNS2_RR::fromString($rname . ' ' . $ori["ttl"] . ' ' . $ori["type"] . ' ' . $ori["rdata"]); $updater->delete($orirecord); if ($this->loggingenable()) { \Log::info(\Auth::user()->username . ' DELETE ' . $orirecord); } // if reverse record(s) exists delete it if ($ori["type"] == "A" && $this->managereverse()) { $revarr = $this->getPTR($zone, $ori["rdata"]); if ($revarr["zone"] != null) { $zonerev = $revarr["zone"]; $updaterrev = new \Net_DNS2_Updater($zonerev->name, array('nameservers' => $this->servers, 'cache_type' => 'none', 'recurse' => false)); foreach ($revarr["records"] as $rr) { $updaterrev->delete($rr); if ($this->loggingenable()) { \Log::info(\Auth::user()->username . ' DELETE ' . $rr); } } $updaterrev->signTSIG(\Crypt::decrypt($zonerev->tsigname), \Crypt::decrypt($zonerev->tsigkey)); $updaterrev->update(); } } } $record = \Net_DNS2_RR::fromString($rname . ' ' . $data["ttl"] . ' ' . $data["type"] . ' ' . $rvalue); $updater->add($record); $updater->signTSIG(\Crypt::decrypt($zone->tsigname), \Crypt::decrypt($zone->tsigkey)); $updater->update(); if ($this->loggingenable()) { \Log::info(\Auth::user()->username . ' CREATE ' . $record); } // create reverse record if authoritative if ($data["type"] == "A" && $this->managereverse()) { $zonerev = $this->canAddPTR($zone, $rvalue); if ($zonerev != null) { $revrecord = \Net_DNS2_RR::fromString($this->getReverseIP($rvalue) . '.in-addr.arpa ' . $data["ttl"] . ' PTR ' . $rname); $updaterrev = new \Net_DNS2_Updater($zonerev->name, array('nameservers' => $this->servers, 'cache_type' => 'none', 'recurse' => false)); $updaterrev->add($revrecord); $updaterrev->signTSIG(\Crypt::decrypt($zonerev->tsigname), \Crypt::decrypt($zonerev->tsigkey)); $updaterrev->update(); if ($this->loggingenable()) { \Log::info(\Auth::user()->username . ' CREATE ' . $revrecord); } } } } catch (\Net_DNS2_Exception $e) { echo "::update() failed: ", $e->getMessage(), "\n"; } }
/** * function to test the compression logic * * @return void * @access public * */ public function testCompression() { // // this list of RR's uses name compression // $rrs = array('NS' => 'example.com. 300 IN NS ns1.mrdns.com.', 'CNAME' => 'example.com. 300 IN CNAME www.example.com.', 'SOA' => 'example.com. 300 IN SOA ns1.mrdns.com. help.mrhost.ca. 1278700841 900 1800 86400 21400', 'MX' => 'example.com. 300 IN MX 10 mx1.mrhost.ca.', 'RP' => 'example.com. 300 IN RP louie.trantor.umd.edu. lam1.people.test.com.', 'AFSDB' => 'example.com. 300 IN AFSDB 3 afsdb.example.com.', 'RT' => 'example.com. 300 IN RT 2 relay.prime.com.', 'PX' => 'example.com. 300 IN PX 10 ab.net2.it. o-ab.prmd-net2.admdb.c-it.', 'SRV' => 'example.com. 300 IN SRV 20 0 5269 xmpp-server2.l.google.com.', 'NAPTR' => 'example.com. 300 IN NAPTR 100 10 S SIP+D2U !^.*$!sip:customer-service@example.com! _sip._udp.example.com.', 'DNAME' => 'example.com. 300 IN DNAME frobozz-division.acme.example.', 'HIP' => 'example.com. 300 IN HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs.example.com. another.example.com. test.domain.org.'); // // create a new updater object // $u = new Net_DNS2_Updater("example.com", array('nameservers' => array('10.10.0.1'))); // // add each RR to the same object, so we can build a build compressed name list // foreach ($rrs as $rr => $line) { $class_name = 'Net_DNS2_RR_' . $rr; // // parse the line // $a = Net_DNS2_RR::fromString($line); // // check that the object is right // $this->assertTrue($a instanceof $class_name); // // set it on the packet // $u->add($a); } // // get the request packet // $request = $u->packet(); // // get the authority section of the request // $request_authority = $request->authority; // // parse the binary // $data = $request->get(); $response = new Net_DNS2_Packet_Response($data, strlen($data)); // // get the authority section of the response, and clean up the // rdata so everything will match. // // the request packet doesn't have the rdlength and rdata fields // built yet, so it will throw off the hash // $response_authority = $response->authority; foreach ($response_authority as $id => $object) { $response_authority[$id]->rdlength = ''; $response_authority[$id]->rdata = ''; } // // build the hashes // $a = md5(print_r($request_authority, 1)); $b = md5(print_r($response_authority, 1)); // // the new hashes should match. // $this->assertSame($a, $b); }