Exemplo n.º 1
0
 /**
  * Updates the selected server
  */
 function update($post)
 {
     global $fmdb, $__FM_CONFIG;
     /** Validate entries */
     $post = $this->validatePost($post);
     if (!is_array($post)) {
         return $post;
     }
     $exclude = array('submit', 'action', 'server_id', 'compress', 'AUTHKEY', 'module_name', 'module_type', 'config', 'SERIALNO');
     $sql_edit = null;
     foreach ($post as $key => $data) {
         if (!in_array($key, $exclude)) {
             $sql_edit .= $key . "='" . sanitize($data) . "',";
         }
     }
     $sql = rtrim($sql_edit, ',');
     // Update the server
     $old_name = getNameFromID($post['server_id'], 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_id', 'server_name');
     $query = "UPDATE `fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}servers` SET {$sql} WHERE `server_id`={$post['server_id']} AND `account_id`='{$_SESSION['user']['account_id']}'";
     $result = $fmdb->query($query);
     if (!$fmdb->result) {
         return __('Could not update the server because a database error occurred.');
     }
     /** Return if there are no changes */
     if (!$fmdb->rows_affected) {
         return true;
     }
     setBuildUpdateConfigFlag(getServerSerial($post['server_id'], $_SESSION['module']), 'yes', 'build');
     addLogEntry("Updated server '{$old_name}' to:\nName: {$post['server_name']}\nType: {$post['server_type']}\n" . "Update Method: {$post['server_update_method']}\nConfig File: {$post['server_config_file']}");
     return true;
 }
Exemplo n.º 2
0
 /**
  * Updates the selected server
  */
 function updateServer($post)
 {
     global $fmdb, $__FM_CONFIG;
     if (empty($post['server_name'])) {
         return __('No server name defined.');
     }
     if (empty($post['server_root_dir'])) {
         $post['server_root_dir'] = $__FM_CONFIG['ns']['named_root_dir'];
     }
     if (empty($post['server_zones_dir'])) {
         $post['server_zones_dir'] = $__FM_CONFIG['ns']['named_zones_dir'];
     }
     if (empty($post['server_config_file'])) {
         $post['server_config_file'] = $__FM_CONFIG['ns']['named_config_file'];
     }
     if (empty($post['server_update_method'])) {
         $post['server_update_method'] = 'cron';
     }
     $post['server_root_dir'] = rtrim($post['server_root_dir'], '/');
     $post['server_chroot_dir'] = rtrim($post['server_chroot_dir'], '/');
     $post['server_zones_dir'] = rtrim($post['server_zones_dir'], '/');
     /** Check name field length */
     $field_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_name');
     if ($field_length !== false && strlen($post['server_name']) > $field_length) {
         return sprintf(dngettext($_SESSION['module'], 'Server name is too long (maximum %d character).', 'Server 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'] . 'servers', sanitize($post['server_name']), 'server_', 'server_name', "AND server_id!='{$post['server_id']}'");
     if ($fmdb->num_rows) {
         return __('This server name already exists.');
     }
     /** Process server_key */
     if (!isset($post['server_key']) || !is_numeric($post['server_key'])) {
         $post['server_key'] = 0;
     }
     /** Set default ports */
     if ($post['server_update_method'] == 'cron') {
         $post['server_update_port'] = 0;
     }
     if (!empty($post['server_update_port']) && !verifyNumber($post['server_update_port'], 1, 65535, false)) {
         return __('Server update port must be a valid TCP port.');
     }
     if (empty($post['server_update_port'])) {
         if ($post['server_update_method'] == 'http') {
             $post['server_update_port'] = 80;
         } elseif ($post['server_update_method'] == 'https') {
             $post['server_update_port'] = 443;
         } elseif ($post['server_update_method'] == 'ssh') {
             $post['server_update_port'] = 22;
         }
     }
     $exclude = array('submit', 'action', 'server_id', 'compress', 'AUTHKEY', 'module_name', 'module_type', 'config', 'SERIALNO', 'sub_type');
     $post['server_run_as'] = $post['server_run_as_predefined'] == 'as defined:' ? $post['server_run_as'] : null;
     if (!in_array($post['server_run_as_predefined'], enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_run_as_predefined'))) {
         $post['server_run_as'] = $post['server_run_as_predefined'];
         $post['server_run_as_predefined'] = 'as defined:';
     }
     $sql_edit = null;
     foreach ($post as $key => $data) {
         if (!in_array($key, $exclude)) {
             $sql_edit .= $key . "='" . sanitize($data) . "',";
         }
     }
     $sql = rtrim($sql_edit, ',');
     /** Update the server */
     $old_name = getNameFromID($post['server_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_id', 'server_name');
     $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}servers` SET {$sql} WHERE `server_id`={$post['server_id']} AND `account_id`='{$_SESSION['user']['account_id']}'";
     $result = $fmdb->query($query);
     if ($fmdb->sql_errors) {
         return __('Could not update the server because a database error occurred.');
     }
     /** Return if there are no changes */
     if (!$fmdb->rows_affected) {
         return true;
     }
     setBuildUpdateConfigFlag(getServerSerial($post['server_id'], $_SESSION['module']), 'yes', 'build');
     $tmp_key = $post['server_key'] ? getNameFromID($post['server_key'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_', 'key_id', 'key_name') : 'None';
     $tmp_runas = $post['server_run_as_predefined'] == 'as defined:' ? $post['server_run_as'] : $post['server_run_as_predefined'];
     addLogEntry("Updated server '{$old_name}' to:\nName: {$post['server_name']}\nKey: {$tmp_key}\nType: {$post['server_type']}\n" . "Run-as: {$tmp_runas}\nUpdate Method: {$post['server_update_method']}\nConfig File: {$post['server_config_file']}\n" . "Server Root: {$post['server_root_dir']}\nServer Chroot: {$post['server_chroot_dir']}\n" . "Zone file directory: {$post['server_zones_dir']}");
     return true;
 }