/** */ 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; }
* * Copyright 2006-2015 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl * * @author Duck <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; $beatnik = Horde_Registry::appInit('beatnik'); require_once BEATNIK_BASE . '/lib/Forms/Autogenerate.php'; $viewurl = Horde::url('viewzone.php'); $vars = Horde_Variables::getDefaultVariables(); $form = new Autogenerate($vars); if ($form->validate($vars)) { if (Horde_Util::getFormData('submitbutton') == _("Autogenerate")) { try { $result = Beatnik::autogenerate($vars); } catch (Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Horde::url('listzones.php')->redirect(); } } else { $notification->push(_("Autogeneration not performed"), 'horde.warning'); } $viewurl->redirect(); } $page_output->header(array('title' => _("Autogenerate"))); require BEATNIK_BASE . '/templates/menu.inc'; $form->renderActive(null, null, Horde::url('autogenerate.php'), 'post'); $page_output->footer();
// Create the Pager UI $pager_vars = Horde_Variables::getDefaultVariables(); $pager_vars->set('page', $page); $perpage = $prefs->getValue('domains_perpage'); $pager = new Horde_Core_Ui_Pager('page', $pager_vars, array('num' => count($beatnik->domains), 'url' => 'listzones.php', 'page_count' => 10, 'perpage' => $perpage)); // Limit the domain list to the current page $domains = array_slice($beatnik->domains, $page * $perpage, $perpage); // Hide fields that the user does not want to see $fields = Beatnik::getRecFields('soa'); foreach ($fields as $field_id => $field) { if ($field['type'] == 'hidden' || $field['infoset'] != 'basic' && !$_SESSION['beatnik']['expertmode']) { unset($fields[$field_id]); } } // Add javascript navigation and striping $page_output->addScriptFile('beatnik.js'); $page_output->addScriptFile('stripe.js', 'horde'); // Initialization complete. Render the page. Beatnik::notifyCommits(); $page_output->header(); require BEATNIK_TEMPLATES . '/menu.inc'; require BEATNIK_TEMPLATES . '/listzones/header.inc'; foreach ($domains as $domain) { $autourl = Horde::url('autogenerate.php')->add(array('rectype' => 'soa', 'curdomain' => $domain['zonename'])); $deleteurl = Horde::url('delete.php')->add(array('rectype' => 'soa', 'curdomain' => $domain['zonename'])); $viewurl = Horde::url('viewzone.php')->add('curdomain', $domain['zonename']); $editurl = Horde::url('editrec.php')->add(array('curdomain' => $domain['zonename'], 'id' => $domain['id'], 'rectype' => 'soa')); require BEATNIK_TEMPLATES . '/listzones/row.inc'; } require BEATNIK_TEMPLATES . '/listzones/footer.inc'; $page_output->footer();
/** * Delete record from backend * * @access private * * @param array $info Reference to array of record information for deletion * * @return boolean true on success */ function deleteRecord(&$info) { $return = $this->_deleteRecord($info); $oldsoa =& $_SESSION['beatnik']['curdomain']; // No need to commit if the whole zone is gone if ($info['rectype'] != 'soa') { Beatnik::needCommit($oldsoa['zonename'], true); } }
/** */ public function menu($menu) { // We are editing rather than adding if an ID was passed $editing = Horde_Util::getFormData('id'); $editing = !empty($editing); $menu->add(Horde::url('listzones.php'), _("List Domains"), 'website.png'); if (!empty($_SESSION['beatnik']['curdomain'])) { $menu->add(Horde::url('editrec.php')->add('curdomain', $_SESSION['beatnik']['curdomain']['zonename']), $editing ? _("Edit Record") : _("Add Record"), 'edit.png'); } else { $menu->add(Horde::url('editrec.php?rectype=soa'), _("Add Zone"), 'edit.png'); } $url = Horde::selfUrl(true)->add(array('expertmode' => 'toggle')); $menu->add($url, _("Expert Mode"), 'hide_panel.png', null, '', null, $_SESSION['beatnik']['expertmode'] ? 'current' : ''); if (count(Beatnik::needCommit())) { $url = Horde::url('commit.php')->add(array('domain' => 'all')); $menu->add($url, _("Commit All"), 'commit-all.png'); } }
$url = Horde::url('viewzone.php'); $domains[] = $_SESSION['beatnik']['curdomain']; } elseif (Horde_Util::getGet('domain') == 'all') { $url = Horde::url('listzones.php'); foreach (Beatnik::needCommit() as $domain) { $domains[] = $beatnik->driver->getDomain($domain); } } foreach ($domains as $domain) { $_SESSION['beatnik']['curdomain'] = $domain; $vars = new Horde_Variables(); $vars->set('rectype', 'soa'); foreach ($domain as $field => $value) { $vars->set($field, $value); } $vars->set('serial', Beatnik::incrementSerial($domain['serial'])); $form = new EditRecord($vars); $form->useToken(false); $form->setSubmitted(true); if ($form->validate($vars)) { $form->getInfo($vars, $info); try { $result = $beatnik->driver->saveRecord($info); } catch (Exception $e) { $notification->push($e->getMessage(), 'horde.error'); } $notification->push(sprintf(_('Zone serial for %s incremented.'), $domain['zonename']), 'horde.success'); } else { $notification->push(sprintf(_("Unable to construct valid SOA for %s. Not incrementing serial."), $domain['zonename']), 'horde.error'); } }
public static function notifyCommits() { // This check has to come after the page has finished all work in case // the status has changed due to a now-completed edit. if (count(Beatnik::needCommit())) { foreach (Beatnik::needCommit() as $domain) { $GLOBALS['notification']->push(sprintf(_("You have uncommitted changes in %s."), $domain)); } } }
/** * 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); }
/** * 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; }
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();