/** */ function DeleteRecord(&$vars) { parent::__construct($vars, _("Are you sure you want to delete this record?")); $rectype = $vars->get('rectype'); $types = Beatnik::getRecTypes(); $this->addHidden('', 'id', 'text', $vars->get('id')); $this->addHidden('', 'curdomain', 'text', $vars->get('curdomain')); $this->addHidden('', 'rectype', 'text', $vars->get('rectype')); $this->addVariable(_("Type"), 'rectype', 'text', false, true); $recset = Beatnik::getRecFields($rectype); foreach ($recset as $field => $fdata) { if ($fdata['type'] != 'hidden' && ($fdata['infoset'] == 'basic' || $_SESSION['beatnik']['expertmode'])) { $this->addVariable(_($fdata['description']), $field, $fdata['type'], false, true); } } $this->setButtons(array(_("Delete"), _("Cancel"))); return true; }
/** */ function EditRecord(&$vars) { $isnew = !$vars->exists('id'); $rectype = $vars->get('rectype'); $recset = Beatnik::getRecFields($rectype); if ($isnew) { // Pre-load the field defaults on a new record foreach ($recset as $field => $fdata) { if (isset($fdata['default'])) { $vars->set($field, $fdata['default']); } } } parent::__construct($vars, $isnew ? _("Add DNS Record") : _("Edit DNS Record")); $types = Beatnik::getRecTypes(); if (empty($_SESSION['beatnik']['curdomain'])) { // Without an active domain, limit the form to creating a new zone. $types = array('soa' => _('SOA (Start of Authority)')); } $action =& Horde_Form_Action::factory('reload'); $select =& $this->addVariable(_("Record Type"), 'rectype', 'enum', true, false, null, array($types, true)); $select->setAction($action); $select->setOption('trackchange', true); // Do not show record-specific fields until a record type is chosen if (!$rectype) { return true; } foreach ($recset as $field => $fdata) { if ($fdata['type'] == 'hidden' || $fdata['infoset'] != 'basic' && !$_SESSION['beatnik']['expertmode']) { $this->addHidden(_($fdata['description']), $field, 'text', $fdata['required']); } else { $this->addVariable(_($fdata['description']), $field, $fdata['type'], $fdata['required']); } } return true; }
/** * Saves a new or edited record to the DNS backend * * @access private * * @param array $info Array from Horde_Form with record data * * @return mixed The new or modified record ID on success; */ function _saveRecord($info) { // Make sure we have a valid record type $rectype = strtolower($info['rectype']); $rdata = false; foreach (Beatnik::getRecTypes() as $rtype => $rdata) { if ($rectype == $rtype) { break; } $rdata = false; } if (!$rdata) { throw new Beatnik_Exception(_("Invalid record type specified.")); } $recfields = Beatnik::getRecFields($rectype); $entry = array(); if ($rectype == 'a+ptr') { // Special case for A+PTR Records $entry['dnstype'] = 'a'; } else { $entry['dnstype'] = $rectype; } $id = strtoupper($rectype); // Apply each piece of submitted data to the new/updated object foreach ($recfields as $field => $fdata) { // Translate the key to an LDAP attribute $key = $this->_getAttrByField($field); if ($key === null || $key == 'dn') { // Skip the DN or any other key we don't care about continue; } if (!isset($info[$field]) && isset($fdata['default'])) { // No value specified. Use the default $val = $fdata['default']; } else { // Only populate the field if there is actual data if (isset($info[$field]) && strlen($info[$field])) { $entry[$key] = $info[$field]; } else { // $info[$field] was possibly unset $info[$field] = ''; // If the record previously had data, we have to send an // empty array to remove the attribute. However, always // sending an empty attribute causes PHP to return with // "Protocol Error". Hence this somewhat expensive check: if (isset($info['id'])) { list($type, $record) = $this->getRecord($info['id']); if ($record && isset($record[$field])) { $entry[$key] = array(); } } } } if (!isset($entry[$key]) && $fdata['required']) { // No value available but required field throw new Beatnik_Exception(sprintf(_("Missing required field %s to save record."), $fdata['name'])); } // Construct an ID for this object as a tuple of its data. // This guarantees uniqueness. $id .= '-' . $this->cleanDNString($info[$field]); } // Create and populate the DN $key = $this->_params['dn']; $dn = ''; // Special case for SOA records. if ($rectype == 'soa') { $domain = $this->cleanDNString($info['zonename']); $entry[$key] = $domain; $id = $domain; $dn = $key . '=' . $domain; $suffix = $this->_params['basedn']; } else { // Everything else gets full id for DN $id = $this->cleanDNString($id); $entry[$key] = $id; $dn = $key . '=' . $id; // The domain is held in the session $domain = $this->cleanDNString($_SESSION['beatnik']['curdomain']['zonename']); // Prepare the DN suffix $suffix = $key . '=' . $domain . ',' . $this->_params['basedn']; } // Check to see if this is a modification if (isset($info['id'])) { // Get the base name of the old object $oldRDN = $key . '=' . $this->cleanDNString($info['id']); if ($dn != $oldRDN) { // We have an old DN but it doesn't match the new DN. // Need to rename the old object if ($rectype == 'soa') { throw new Beatnik_Exception(_("Unsupported operation: cannot rename a domain.")); } $res = @ldap_rename($this->_LDAP, $oldRDN . ',' . $suffix, $dn, $suffix, true); if ($res === false) { throw new Beatnik_Exception(sprintf(_("Unable to rename old object. Reason: %s"), @ldap_error($this->_LDAP))); } } // Finish appending the DN suffix information $dn .= ',' . $suffix; // Modify the existing record $res = @ldap_mod_replace($this->_LDAP, $dn, $entry); if ($res === false) { throw new Beatnik_Exception(sprintf(_("Unable to modify record. Reason: %s"), @ldap_error($this->_LDAP))); } } else { // Must be a new record // Append the suffix to the DN to make it fully qualified $dn .= ',' . $suffix; // Create the necessary objectClass definitions $entry['objectclass'] = array(); $entry['objectclass'][] = 'top'; $entry['objectclass'][] = 'dnszone'; if ($rectype != 'soa') { // An objectclass to hold the non-SOA record information $entry['objectclass'][] = 'dnsrrset'; } $res = @ldap_add($this->_LDAP, $dn, $entry); if ($res === false) { throw new Beatnik_Exception(sprintf(_("Unable to add record to LDAP. Reason: %s"), @ldap_error($this->_LDAP))); } } return $id; }
/** * Delete record from backend * * @access private * * @param array $data Reference to array of record data to be deleted * * @return boolean true on success, PEAR::Error on error */ function _deleteRecord($data) { // delete just one record if ($data['rectype'] != 'soa') { return $this->_write_db->query('DELETE FROM beatnik_' . $data['rectype'] . ' WHERE id = ?', array($data['id'])); } // delete all subrecords $params = array($data['curdomain']); foreach (array_keys(Beatnik::getRecTypes()) as $type) { if ($type == 'soa') { continue; } $result = $this->_write_db->query('DELETE FROM beatnik_' . $type . ' WHERE zonename = ?', $params); if (is_a($result, 'PEAR_Error')) { return $result; } } // we are cuccesfull so, delete even soa return $this->_write_db->query('DELETE FROM beatnik_soa WHERE zonename = ?', $params); }
Horde::url('listzones.php')->redirect(); } $page_output->addScriptFile('beatnik.js'); $page_output->addScriptFile('stripe.js', 'horde'); Beatnik::notifyCommits(); $page_output->header(array('title' => $_SESSION['beatnik']['curdomain']['zonename'])); require BEATNIK_TEMPLATES . '/menu.inc'; // Get a list of all the fields for all record typess we'll be processing $fields = array(); foreach ($zonedata as $type => $data) { $fields = array_merge($fields, Beatnik::getRecFields($type)); } // Remove fields that should not be shown foreach ($fields as $field_id => $field) { if ($field['type'] == 'hidden' || $field['infoset'] != 'basic' && !$_SESSION['beatnik']['expertmode']) { unset($field[$field_id]); } } $delete = Horde::url('delete.php')->add('curdomain', $_SESSION['beatnik']['curdomain']['zonename']); $edit = Horde::url('editrec.php')->add('curdomain', $_SESSION['beatnik']['curdomain']['zonename']); $autogen = Horde::url('autogenerate.php')->add('curdomain', $_SESSION['beatnik']['curdomain']['zonename']); $rectypes = Beatnik::getRecTypes(); require BEATNIK_TEMPLATES . '/view/header.inc'; foreach ($rectypes as $type => $typedescr) { if (!isset($zonedata[$type])) { continue; } require BEATNIK_TEMPLATES . '/view/record.inc'; } require BEATNIK_TEMPLATES . '/view/footer.inc'; $page_output->footer();