Example #1
0
 function validatePost($post)
 {
     global $fmdb, $__FM_CONFIG;
     if (!$post['domain_id']) {
         unset($post['domain_id']);
     }
     /** Empty domain names are not allowed */
     if (empty($post['domain_name'])) {
         return __('No zone name defined.');
     }
     if ($post['domain_template'] != 'yes') {
         $post['domain_name'] = rtrim(strtolower($post['domain_name']), '.');
         /** Perform domain name validation */
         if (!isset($post['domain_mapping'])) {
             global $map;
             $post['domain_mapping'] = $map;
         }
         if ($post['domain_mapping'] == 'reverse') {
             $post['domain_name'] = $this->fixDomainTypos($post['domain_name']);
         } else {
             $post['domain_name'] = function_exists('idn_to_ascii') ? idn_to_ascii($post['domain_name']) : $post['domain_name'];
         }
         if (!$this->validateDomainName($post['domain_name'], $post['domain_mapping'])) {
             return __('Invalid zone name.');
         }
     }
     /** Is this based on a template? */
     if ($post['domain_template_id']) {
         $include = array('action', 'domain_template_id', 'domain_name', 'domain_template', 'domain_mapping');
         foreach ($include as $key) {
             $new_post[$key] = $post[$key];
         }
         $post = $new_post;
         unset($new_post, $post['domain_template']);
         $post['domain_type'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_type');
         $post['domain_view'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_view');
         return $post;
     } else {
         $post['domain_template_id'] = 0;
     }
     /** Format domain_clone_domain_id */
     if (!$post['domain_clone_domain_id'] && $post['action'] == 'add') {
         $post['domain_clone_domain_id'] = 0;
     }
     /** domain_clone_dname override */
     if (!$post['domain_clone_dname_override']) {
         $post['domain_clone_dname'] = null;
     } else {
         unset($post['domain_clone_dname_override']);
     }
     /** Ensure domain_view is set */
     if (!array_key_exists('domain_view', $post)) {
         $post['domain_view'] = $post['domain_clone_domain_id'] ? -1 : 0;
     }
     /** Reverse zones should have form of x.x.x.in-addr.arpa */
     if ($post['domain_mapping'] == 'reverse') {
         $post['domain_name'] = $this->setReverseZoneName($post['domain_name']);
     }
     /** Does the record already exist for this account? */
     $domain_id_sql = isset($post['domain_id']) ? 'AND domain_id!=' . sanitize($post['domain_id']) : null;
     basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', $_SESSION['user']['account_id'], 'view_', 'account_id');
     if (!$fmdb->num_rows) {
         /** No views defined - all zones must be unique */
         basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql);
         if ($fmdb->num_rows) {
             return __('Zone already exists.');
         }
     } else {
         /** All zones must be unique per view */
         $defined_views = $fmdb->last_result;
         /** Format domain_view */
         if (!$post['domain_view'] || in_array(0, $post['domain_view'])) {
             basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql);
             if ($fmdb->num_rows) {
                 /** Zone exists for views, but what about on the same server? */
                 if (!$post['domain_name_servers'] || in_array('0', $post['domain_name_servers'])) {
                     return __('Zone already exists for all views.');
                 }
             }
         }
         if (is_array($post['domain_view'])) {
             $domain_view = null;
             foreach ($post['domain_view'] as $val) {
                 if ($val == 0 || $val == '') {
                     $domain_view = 0;
                     break;
                 }
                 $domain_view .= $val . ';';
                 basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', "AND (domain_view='{$val}' OR domain_view=0 OR domain_view LIKE '{$val};%' OR domain_view LIKE '%;{$val};%' OR domain_view LIKE '%;{$val}') {$domain_id_sql}");
                 if ($fmdb->num_rows) {
                     $view_name = getNameFromID($val, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', 'view_', 'view_id', 'view_name');
                     return sprintf(__("Zone already exists for the '%s' view."), $view_name);
                 }
             }
             $post['domain_view'] = rtrim($domain_view, ';');
         }
     }
     /** Check name field length */
     $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', 'domain_name');
     if ($field_length !== false && strlen($post['domain_name']) > $field_length) {
         return sprintf(dngettext($_SESSION['module'], 'Zone name is too long (maximum %d character).', 'Zone name is too long (maximum %d characters).', $field_length), $field_length);
     }
     /** No need to process more if zone is cloned */
     if ($post['domain_clone_domain_id']) {
         return $post;
     }
     /** Cleans up acl_addresses for future parsing **/
     $clean_fields = array('forwarders', 'masters');
     foreach ($clean_fields as $val) {
         $post['domain_required_servers'][$val] = verifyAndCleanAddresses($post['domain_required_servers'][$val], 'no-subnets-allowed');
         if (strpos($post['domain_required_servers'][$val], 'not valid') !== false) {
             return $post['domain_required_servers'][$val];
         }
     }
     /** Forward zones require forward servers */
     if ($post['domain_type'] == 'forward') {
         if (empty($post['domain_required_servers']['forwarders'])) {
             return __('No forward servers defined.');
         }
         $post['domain_required_servers'] = $post['domain_required_servers']['forwarders'];
     }
     /** Slave and stub zones require master servers */
     if (in_array($post['domain_type'], array('slave', 'stub'))) {
         if (empty($post['domain_required_servers']['masters'])) {
             return __('No master servers defined.');
         }
         $post['domain_required_servers'] = $post['domain_required_servers']['masters'];
     }
     return $post;
 }
Example #2
0
 /**
  * Updates the selected acl
  */
 function update($post)
 {
     global $fmdb, $__FM_CONFIG;
     /** Check name field length */
     $field_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_name');
     if ($field_length !== false && strlen($post['acl_name']) > $field_length) {
         return sprintf(dngettext($_SESSION['module'], 'ACL name is too long (maximum %d character).', 'ACL name is too long (maximum %d characters).', $field_length), $field_length);
     }
     /** Does the record already exist for this account? */
     basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', sanitize($post['acl_name']), 'acl_', 'acl_name');
     if ($fmdb->num_rows) {
         $result = $fmdb->last_result;
         if ($result[0]->acl_id != $post['acl_id']) {
             return __('This ACL already exists.');
         }
     }
     if (empty($post['acl_name'])) {
         return __('No ACL name defined.');
     }
     /** Cleans up acl_addresses for future parsing **/
     $post['acl_addresses'] = verifyAndCleanAddresses($post['acl_addresses']);
     if (strpos($post['acl_addresses'], 'not valid') !== false) {
         return $post['acl_addresses'];
     }
     if ($post['acl_predefined'] != 'as defined:') {
         $post['acl_addresses'] = null;
     }
     $post['acl_comment'] = trim($post['acl_comment']);
     $post['account_id'] = $_SESSION['user']['account_id'];
     $exclude = array('submit', 'action', 'server_id');
     $sql_edit = null;
     foreach ($post as $key => $data) {
         if (!in_array($key, $exclude)) {
             $sql_edit .= $key . "='" . sanitize($data) . "',";
         }
     }
     $sql = rtrim($sql_edit, ',');
     // Update the acl
     $old_name = getNameFromID($post['acl_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_', 'acl_id', 'acl_name');
     $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}acls` SET {$sql} WHERE `acl_id`={$post['acl_id']}";
     $result = $fmdb->query($query);
     if (!$fmdb->result) {
         return __('Could not update the ACL because a database error occurred.');
     }
     /** Return if there are no changes */
     if (!$fmdb->rows_affected) {
         return true;
     }
     $acl_addresses = $post['acl_predefined'] == 'as defined:' ? $post['acl_addresses'] : $post['acl_predefined'];
     addLogEntry("Updated ACL '{$old_name}' to the following:\nName: {$post['acl_name']}\nAddresses: {$acl_addresses}\nComment: {$post['acl_comment']}");
     return true;
 }