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>';
    }
}
Example #3
0
 /**
  * we have our own constructor so that we can load our certificate
  * information for parsing.
  *
  * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
  * @param array           $rr      a array with parsed RR values
  *
  * @return
  *
  */
 public function __construct(Net_DNS2_Packet &$packet = null, array $rr = null)
 {
     parent::__construct($packet, $rr);
     //
     // load the lookup values
     //
     $this->cert_format_name_to_id = array_flip($this->cert_format_id_to_name);
 }
Example #4
0
 /**
  * builds a new Net_DNS2_Packet_Response object
  *
  * @param string  $data binary DNS packet
  * @param integer $size the length of the DNS packet
  *
  * @return boolean
  * @throws Net_DNS2_Exception
  * @access public
  *
  */
 public function set($data, $size)
 {
     //
     // store the full packet
     //
     $this->rdata = $data;
     $this->rdlength = $size;
     //
     // parse the header
     //
     // we don't bother checking the size earlier, because the first thing the
     // header class does, is check the size and throw and exception if it's
     // invalid.
     //
     $this->header = new Net_DNS2_Header($this);
     //
     // if the truncation bit is set, then just return right here, because the
     // rest of the packet is probably empty; and there's no point in processing
     // anything else.
     //
     // we also don't need to worry about checking to see if the the header is
     // null or not, since the Net_DNS2_Header() constructor will throw an
     // exception if the packet is invalid.
     //
     if ($this->header->tc == 1) {
         return false;
     }
     //
     // parse the questions
     //
     for ($x = 0; $x < $this->header->qdcount; ++$x) {
         $this->question[$x] = new Net_DNS2_Question($this);
     }
     //
     // parse the answers
     //
     for ($x = 0; $x < $this->header->ancount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->answer[] = $o;
         }
     }
     //
     // parse the authority section
     //
     for ($x = 0; $x < $this->header->nscount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->authority[] = $o;
         }
     }
     //
     // parse the additional section
     //
     for ($x = 0; $x < $this->header->arcount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->additional[] = $o;
         }
     }
     return true;
 }
Example #5
0
 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";
     }
 }
Example #6
0
 /**
  * Constructor - builds a new Net_DNS2_RR_OPT object; normally you wouldn't call
  * this directly, but OPT RR's are a little different
  *
  * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet or null to create
  *                                 an empty object
  * @param array           $rr      an array with RR parse values or null to
  *                                 create an empty object
  *
  * @throws Net_DNS2_Exception
  * @access public
  *
  */
 public function __construct(Net_DNS2_Packet &$packet = null, array $rr = null)
 {
     //
     // this is for when we're manually building an OPT RR object; we aren't
     // passing in binary data to parse, we just want a clean/empty object.
     //
     $this->type = 'OPT';
     $this->rdlength = 0;
     $this->option_length = 0;
     $this->extended_rcode = 0;
     $this->version = 0;
     $this->do = 0;
     $this->z = 0;
     //
     // everthing else gets passed through to the parent.
     //
     if (!is_null($packet) && !is_null($rr)) {
         parent::__construct($packet, $rr);
     }
 }
Example #7
0
 /**
  * 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);
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * builds a new Net_DNS2_Packet_Response object
  *
  * @param string  $data binary DNS packet
  * @param integer $size the length of the DNS packet
  *
  * @return boolean
  * @throws Net_DNS2_Exception
  * @access public
  *
  */
 public function set($data, $size)
 {
     //
     // store the full packet
     //
     $this->rdata = $data;
     $this->rdlength = $size;
     //
     // parse the header
     //
     // we don't bother checking the size earlier, because the first thing the
     // header class does, it check the size and throw and exception if it's
     // invalid.
     //
     $this->header = new Net_DNS2_Header($this);
     //
     // parse the questions
     //
     for ($x = 0; $x < $this->header->qdcount; ++$x) {
         $this->question[$x] = new Net_DNS2_Question($this);
     }
     //
     // parse the answers
     //
     for ($x = 0; $x < $this->header->ancount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->answer[] = $o;
         }
     }
     //
     // parse the authority section
     //
     for ($x = 0; $x < $this->header->nscount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->authority[] = $o;
         }
     }
     //
     // parse the additional section
     //
     for ($x = 0; $x < $this->header->arcount; ++$x) {
         $o = Net_DNS2_RR::parse($this);
         if (!is_null($o)) {
             $this->additional[] = $o;
         }
     }
     return true;
 }