function AddHostAndIpToDnsServer($hostname, $ip) { $config_manager = MMMConfiguration::getInstance(); $updater = BuildUpdater(); $ttl = $config_manager->item('ttl'); $type = $config_manager->item('type'); print "Executing: nsupdate add {$hostname} {$ttl} {$type} {$ip}'\n"; $add_record = Net_DNS2_RR::fromString("{$hostname} {$ttl} IN {$type} {$ip}"); $updater->add($add_record); return Sendupdate($updater); }
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>'; } }
public function removeRecord($data, \App\Zone $zone) { $updater = new \Net_DNS2_Updater($zone->name, array('nameservers' => $this->servers, 'cache_type' => 'none')); try { $record = \Net_DNS2_RR::fromString($data["name"] . '.' . $zone->name . ' ' . $data["ttl"] . ' ' . $data["type"] . ' ' . $data["rdata"]); $updater->delete($record); $updater->signTSIG(\Crypt::decrypt($zone->tsigname), \Crypt::decrypt($zone->tsigkey)); $updater->update(); if ($this->loggingenable()) { \Log::info(\Auth::user()->username . ' DELETE ' . $record); } //delete reverse record if ($data["type"] == "A" && $this->managereverse()) { $revarr = $this->getPTR($zone, $data["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(); } } } 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); }
/** * adds a TSIG RR object for authentication * * @param string $keyname the key name to use for the TSIG RR * @param string $signature the key to sign the request. * @param string $algorithm the algorithm to use * * @return boolean * @access public * @since function available since release 1.1.0 * */ public function signTSIG($keyname, $signature = '', $algorithm = Net_DNS2_RR_TSIG::HMAC_MD5) { // // if the TSIG was pre-created and passed in, then we can just used // it as provided. // if ($keyname instanceof Net_DNS2_RR_TSIG) { $this->auth_signature = $keyname; } else { // // otherwise create the TSIG RR, but don't add it just yet; TSIG needs // to be added as the last additional entry- so we'll add it just // before we send. // $this->auth_signature = Net_DNS2_RR::fromString(strtolower(trim($keyname)) . ' TSIG ' . $signature); // // set the algorithm to use // $this->auth_signature->algorithm = $algorithm; } return true; }