function buildServerConfig($serial_no) { global $fmdb, $__FM_CONFIG, $fm_name; /** Check serial number */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', sanitize($serial_no), 'server_', 'server_serial_no'); if (!$fmdb->num_rows) { return sprintf('<p class="error">%s</p>', __('This server is not found.')); } $server_details = $fmdb->last_result; extract(get_object_vars($server_details[0]), EXTR_SKIP); $response = null; switch ($server_update_method) { case 'cron': if ($action == 'buildconf') { /* set the server_update_config flag */ setBuildUpdateConfigFlag($serial_no, 'conf', 'update'); $response = sprintf('<p>%s</p>' . "\n", __('This server will be updated on the next cron run.')); } else { $response = sprintf('<p>%s</p>' . "\n", __('This server receives updates via cron - please manage the server manually.')); } break; case 'http': case 'https': /** Test the port first */ if (!socketTest($server_name, $server_update_port, 10)) { return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port)); } /** Remote URL to use */ $url = $server_update_method . '://' . $server_name . ':' . $server_update_port . '/' . $_SESSION['module'] . '/reload.php'; /** Data to post to $url */ $post_data = array('action' => 'buildconf', 'serial_no' => $server_serial_no); $post_result = @unserialize(getPostData($url, $post_data)); if (!is_array($post_result)) { /** Something went wrong */ if (empty($post_result)) { return sprintf('<p class="error">%s</p>', sprintf(__('It appears %s does not have php configured properly within httpd or httpd is not running.'), $server_name)); } return $response . '<p class="error">' . $post_result . '</p>' . "\n"; } else { if (count($post_result) > 1) { $response .= '<textarea rows="7" cols="100">'; /** Loop through and format the output */ foreach ($post_result as $line) { $response .= "[{$server_name}] {$line}\n"; } $response .= "</textarea>\n"; } else { $response .= "<p>[{$server_name}] " . $post_result[0] . '</p>'; } } break; case 'ssh': /** Test the port first */ if (!socketTest($server_name, $server_update_port, 10)) { return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not access %s using %s (tcp/%d).'), $server_name, $server_update_method, $server_update_port)); } /** Get SSH key */ $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']); if (!$ssh_key) { return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: SSH key is not <a href="%s">defined</a>.'), getMenuURL(_('General')))); } $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa'; if (file_exists($temp_ssh_key)) { @unlink($temp_ssh_key); } if (@file_put_contents($temp_ssh_key, $ssh_key) === false) { return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: could not load SSH key into %s.'), $temp_ssh_key)); } @chmod($temp_ssh_key, 0400); $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']); if (!$ssh_user) { return sprintf('<p class="error">%s</p>' . "\n", sprintf(__('Failed: SSH user is not <a href="%s">defined</a>.'), getMenuURL(_('General')))); } /** Test SSH authentication */ exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$server_update_port} -l {$ssh_user} {$server_name} 'ls /usr/local/{$fm_name}/{$_SESSION['module']}/fw.php'", $post_result, $retval); if ($retval) { /** Something went wrong */ @unlink($temp_ssh_key); return sprintf('<p class="error">%s</p>' . "\n", __('Could not login via SSH.')); } unset($post_result); /** Run build */ exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$server_update_port} -l {$ssh_user} {$server_name} 'sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/fw.php {$action} " . implode(' ', $options) . "'", $post_result, $retval); @unlink($temp_ssh_key); if ($retval) { /** Something went wrong */ return '<p class="error">' . ucfirst($friendly_action) . ' failed.</p>' . "\n"; } else { if (!count($post_result)) { $post_result[] = ucfirst($friendly_action) . ' was successful.'; } if (count($post_result) > 1) { $response .= '<textarea rows="4" cols="100">'; /** Loop through and format the output */ foreach ($post_result as $line) { $response .= "[{$server_name}] {$line}\n"; } $response .= "</textarea>\n"; } else { $response .= "<p>[{$server_name}] " . $post_result[0] . '</p>'; } } break; } /* reset the server_build_config flag */ if (!strpos($response, strtolower('failed'))) { setBuildUpdateConfigFlag($serial_no, 'no', 'build'); } $tmp_name = getNameFromID($serial_no, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_name'); addLogEntry(ucfirst($friendly_action) . " was performed on server '{$tmp_name}'."); return $response; }
/** * Updates tables to reset flags * * @since 1.0 * @package fmDNS */ function updateReloadFlags($post_data) { global $fmdb, $__FM_CONFIG; $server_serial_no = sanitize($post_data['SERIALNO']); extract($post_data); basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', $server_serial_no, 'server_', 'server_serial_no'); if ($fmdb->num_rows) { $result = $fmdb->last_result; $data = $result[0]; extract(get_object_vars($data), EXTR_SKIP); $msg = !setBuildUpdateConfigFlag($server_serial_no, 'no', 'build') || !setBuildUpdateConfigFlag($server_serial_no, 'no', 'update') ? "Could not update the backend database.\n" : "Success.\n"; $msg = "Success.\n"; if (isset($built_domain_ids)) { $this->setBuiltDomainIDs($server_serial_no, $built_domain_ids); } if (isset($reload_domain_ids)) { $query = "DELETE FROM `fm_" . $__FM_CONFIG['fmDNS']['prefix'] . "track_reloads` WHERE `server_serial_no`='" . sanitize($server_serial_no) . "' AND domain_id IN (" . implode(',', array_unique($reload_domain_ids)) . ')'; $fmdb->query($query); } } else { $msg = "DNS server is not found.\n"; } if ($compress) { echo gzcompress(serialize($msg)); } else { echo serialize($msg); } }
/** * Sets server build config flag * * @since 1.0 * @package facileManager * * @param integer $serial_no Server serial number * @param string $flag Flag to set (yes or no) * @param string $build_update Are we building or updating * @param integer $domain_id Domain ID to update DNS servers for * @return boolean */ function setBuildUpdateConfigFlag($serial_no = null, $flag, $build_update, $__FM_CONFIG = null) { global $fmdb, $fm_dns_zones; if (!$__FM_CONFIG) { global $__FM_CONFIG; } $serial_no = sanitize($serial_no); /** Process server group */ if ($serial_no[0] == 'g') { global $fm_shared_module_servers; $group_servers = $fm_shared_module_servers->getGroupServers(substr($serial_no, 2)); if (!is_array($group_servers)) { return false; } setBuildUpdateConfigFlag(implode(',', $group_servers), $flag, $build_update, $__FM_CONFIG); return true; } if ($serial_no) { $query = "UPDATE `fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}servers` SET `server_" . $build_update . "_config`='" . $flag . "' WHERE `server_serial_no` IN (" . $serial_no . ") AND `server_installed`='yes'"; } else { $query = "UPDATE `fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}servers` SET `server_" . $build_update . "_config`='" . $flag . "' WHERE `server_installed`='yes' AND `server_status`='active'"; } $result = $fmdb->query($query); if ($fmdb->result) { return true; } return false; }
/** * Deletes the selected option */ function delete($id, $server_serial_no = 0) { global $fmdb, $__FM_CONFIG; $tmp_name = getNameFromID($id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'cfg_id', 'cfg_name'); $tmp_server_name = $server_serial_no ? getNameFromID($server_serial_no, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_name') : 'All Servers'; if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', $id, 'cfg_', 'deleted', 'cfg_id') === false) { return __('This option could not be deleted because a database error occurred.'); } else { setBuildUpdateConfigFlag($server_serial_no, 'yes', 'build'); addLogEntry(sprintf(__("Option '%s' for %s was deleted."), $tmp_name, $tmp_server_name)); return true; } }
/** * Deletes the selected policy */ function delete($policy_id, $server_serial_no) { global $fmdb, $__FM_CONFIG; /** Does the policy_id exist for this account? */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'policies', $policy_id, 'policy_', 'policy_id'); if ($fmdb->num_rows) { /** Delete service */ if (updateStatus('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'policies', $policy_id, 'policy_', 'deleted', 'policy_id')) { setBuildUpdateConfigFlag($_REQUEST['server_serial_no'], 'yes', 'build'); addLogEntry('Deleted policy from ' . getNameFromID($server_serial_no, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_name') . '.'); return true; } } return __('This policy could not be deleted.'); }
/** 1.2-beta1 */ function upgradefmDNS_1201($__FM_CONFIG, $running_version) { global $fmdb, $module_name; $success = version_compare($running_version, '1.1', '<') ? upgradefmDNS_111($__FM_CONFIG, $running_version) : true; if (!$success) { return false; } $table[] = "ALTER TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` CHANGE `record_type` `record_type` ENUM( 'A', 'AAAA', 'CERT', 'CNAME', 'DNAME', 'DNSKEY', 'KEY', 'KX', 'MX', 'NS', 'PTR', 'RP', 'SRV', 'TXT', 'HINFO' ) NOT NULL DEFAULT 'A'"; $table[] = "ALTER TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` CHANGE `record_class` `record_class` ENUM( 'IN', 'CH', 'HS' ) NOT NULL DEFAULT 'IN'"; $table[] = "ALTER TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` ADD `record_os` VARCHAR( 255 ) NULL AFTER `record_port`,\nADD `record_cert_type` TINYINT NULL AFTER `record_os` ,\nADD `record_key_tag` INT NULL AFTER `record_cert_type` ,\nADD `record_algorithm` TINYINT NULL AFTER `record_key_tag`,\nADD `record_flags` ENUM( '0', '256', '257' ) NULL AFTER `record_algorithm`,\nADD `record_text` VARCHAR( 255 ) NULL AFTER `record_flags` "; $table[] = "ALTER TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` CHANGE `record_value` `record_value` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL "; $table[] = <<<TABLE CREATE TABLE IF NOT EXISTS `fm_{$__FM_CONFIG['fmDNS']['prefix']}records_skipped` ( `account_id` int(11) NOT NULL, `domain_id` int(11) NOT NULL, `record_id` int(11) NOT NULL, `record_status` enum('active','deleted') NOT NULL DEFAULT 'active', PRIMARY KEY (`record_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; TABLE; $inserts = $updates = null; /** Create table schema */ if (count($table) && $table[0]) { foreach ($table as $schema) { $fmdb->query($schema); if (!$fmdb->result || $fmdb->sql_errors) { return false; } } } if (count($inserts) && $inserts[0]) { foreach ($inserts as $schema) { $fmdb->query($schema); if (!$fmdb->result || $fmdb->sql_errors) { return false; } } } if (count($updates) && $updates[0]) { foreach ($updates as $schema) { $fmdb->query($schema); if (!$fmdb->result || $fmdb->sql_errors) { return false; } } } /** Force rebuild of server configs for Issue #75 */ $current_module = $_SESSION['module']; $_SESSION['module'] = 'fmDNS'; setBuildUpdateConfigFlag(null, 'yes', 'build', $__FM_CONFIG); $_SESSION['module'] = $current_module; unset($current_module); /** Move module options */ $fmdb->get_results("SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}options`"); if ($fmdb->num_rows) { $count = $fmdb->num_rows; $result = $fmdb->last_result; for ($i = 0; $i < $count; $i++) { if (!setOption($result[$i]->option_name, $result[$i]->option_value, 'auto', true, $result[$i]->account_id, 'fmDNS')) { return false; } } } $fmdb->query("DROP TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}options`"); if (!$fmdb->result || $fmdb->sql_errors) { return false; } $fm_user_caps = getOption('fm_user_caps'); /** Update user capabilities */ $fm_user_caps['fmDNS'] = array('read_only' => '<b>Read Only</b>', 'manage_servers' => 'Server Management', 'build_server_configs' => 'Build Server Configs', 'manage_zones' => 'Zone Management', 'manage_records' => 'Record Management', 'reload_zones' => 'Reload Zones', 'manage_settings' => 'Manage Settings'); if (!setOption('fm_user_caps', $fm_user_caps)) { return false; } $fmdb->get_results("SELECT * FROM `fm_users`"); if ($fmdb->num_rows) { $count = $fmdb->num_rows; $result = $fmdb->last_result; for ($i = 0; $i < $count; $i++) { $user_caps = null; /** Update user capabilities */ $j = 1; $temp_caps = null; foreach ($fm_user_caps['fmDNS'] as $slug => $trash) { $user_caps = isSerialized($result[$i]->user_caps) ? unserialize($result[$i]->user_caps) : $result[$i]->user_caps; if (@array_key_exists('fmDNS', $user_caps)) { if ($user_caps['fmDNS']['imported_perms'] == 0) { $temp_caps['fmDNS']['read_only'] = 1; } else { if ($j & $user_caps['fmDNS']['imported_perms'] && $j > 1) { $temp_caps['fmDNS'][$slug] = 1; } $j = $j * 2; } } else { $temp_caps['fmDNS']['read_only'] = $user_caps['fmDNS']['read_only'] = 1; } } if (@array_key_exists('fmDNS', $temp_caps)) { $user_caps['fmDNS'] = array_merge($temp_caps['fmDNS'], $user_caps['fmDNS']); } if (@array_key_exists('zone_access', $user_caps['fmDNS'])) { $user_caps['fmDNS']['access_specific_zones'] = $user_caps['fmDNS']['zone_access']; } unset($user_caps['fmDNS']['imported_perms'], $user_caps['fmDNS']['zone_access']); $fmdb->query("UPDATE fm_users SET user_caps = '" . serialize($user_caps) . "' WHERE user_id=" . $result[$i]->user_id); if (!$fmdb->result) { return false; } } } setOption('client_version', $__FM_CONFIG['fmDNS']['client_version'], 'auto', false, 0, 'fmDNS'); setOption('version', '1.2-beta1', 'auto', false, 0, $module_name); return true; }
$response = $result; $form_data = $_POST; } else { setBuildUpdateConfigFlag($server_serial_no, 'yes', 'build'); header('Location: ' . $GLOBALS['basename'] . $server_serial_no_uri); } } break; case 'edit': if (!empty($_POST)) { $result = $fm_dns_controls->update($_POST); if ($result !== true) { $response = $result; $form_data = $_POST; } else { setBuildUpdateConfigFlag($server_serial_no, 'yes', 'build'); header('Location: ' . $GLOBALS['basename'] . $server_serial_no_uri); } } } } printHeader(); @printMenu(); $avail_servers = buildServerSubMenu($server_serial_no); echo printPageHeader($response, null, currentUserCan('manage_servers', $_SESSION['module'])); echo <<<HTML <div id="pagination_container" class="submenus"> \t<div> \t<div class="stretch"></div> \t{$avail_servers} \t</div>
/** * Updates tables to reset flags * * @since 1.0 * @package fmFirewall */ function updateReloadFlags($post_data) { global $fmdb, $__FM_CONFIG; $server_serial_no = sanitize($post_data['SERIALNO']); extract($post_data); basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', $server_serial_no, 'server_', 'server_serial_no'); if ($fmdb->num_rows) { $result = $fmdb->last_result; $data = $result[0]; extract(get_object_vars($data), EXTR_SKIP); $reset_build = setBuildUpdateConfigFlag($server_serial_no, 'no', 'build'); $reset_update = setBuildUpdateConfigFlag($server_serial_no, 'no', 'update'); // $msg = (!setBuildUpdateConfigFlag($server_serial_no, 'no', 'build') && !setBuildUpdateConfigFlag($server_serial_no, 'no', 'update')) ? "Could not update the backend database.\n" : "Success.\n"; $msg = "Success.\n"; } else { $msg = "Server is not found.\n"; } if ($compress) { echo gzcompress(serialize($msg)); } else { echo serialize($msg); } }
/** * Deletes the selected logging channel/category */ function delete($id, $server_serial_no = 0, $type) { global $fmdb, $__FM_CONFIG; /** Check if channel is currently associated with category */ if ($type == 'channel' && is_array($this->getAssocCategories($id))) { return sprintf(__('This %s could not be deleted because it is associated with one or more categories.'), $type); } $tmp_name = getNameFromID($id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'cfg_id', 'cfg_data'); /** Delete associated children */ $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}config` SET `cfg_status`='deleted' WHERE `cfg_parent`={$id}"; $fmdb->query($query); /** Delete item */ if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', $id, 'cfg_', 'deleted', 'cfg_id') === false) { return sprintf(__('This %s could not be deleted because a database error occurred.'), $type); } else { setBuildUpdateConfigFlag($server_serial_no, 'yes', 'build'); addLogEntry(sprintf(__("Logging %s '%s' was deleted."), $type, $tmp_name)); return true; } }
function buildZoneConfig($domain_id) { global $fmdb, $__FM_CONFIG, $fm_name; /** Check domain_id and soa */ $parent_domain_ids = getZoneParentID($domain_id); if (!isset($parent_domain_ids[2])) { $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}domains d, fm_{$__FM_CONFIG['fmDNS']['prefix']}soa s WHERE domain_status='active' AND d.account_id='{$_SESSION['user']['account_id']}' AND s.soa_id=d.soa_id AND d.domain_id IN (" . join(',', $parent_domain_ids) . ")"; } else { $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}domains d, fm_{$__FM_CONFIG['fmDNS']['prefix']}soa s WHERE domain_status='active' AND d.account_id='{$_SESSION['user']['account_id']}' AND\n\t\t\t\ts.soa_id=(SELECT soa_id FROM fm_dns_domains WHERE domain_id={$parent_domain_ids[2]})"; } $result = $fmdb->query($query); if (!$fmdb->num_rows) { return sprintf('<p class="error">%s</p>' . "\n", __('Failed: There was no SOA record found for this zone.')); } $domain_details = $fmdb->last_result; extract(get_object_vars($domain_details[0]), EXTR_SKIP); $name_servers = $this->getNameServers($domain_name_servers, array('masters')); /** No name servers so return */ if (!$name_servers) { return sprintf('<p class="error">%s</p>' . "\n", __('There are no DNS servers hosting this zone.')); } /** Loop through name servers */ $name_server_count = $fmdb->num_rows; $response = '<textarea rows="12" cols="85">'; $failures = false; for ($i = 0; $i < $name_server_count; $i++) { switch ($name_servers[$i]->server_update_method) { case 'cron': /** Add records to fm_{$__FM_CONFIG['fmDNS']['prefix']}track_reloads */ foreach ($this->getZoneCloneChildren($domain_id) as $child_id) { $this->addZoneReload($name_servers[$i]->server_serial_no, $child_id); } /** Set the server_update_config flag */ setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update'); $response .= '[' . $name_servers[$i]->server_name . '] ' . __('This zone will be updated on the next cron run.') . "\n"; break; case 'http': case 'https': /** Test the port first */ if (!socketTest($name_servers[$i]->server_name, $name_servers[$i]->server_update_port, 10)) { $response .= '[' . $name_servers[$i]->server_name . '] ' . sprintf(__('Failed: could not access %s (tcp/%d).'), $name_servers[$i]->server_update_method, $name_servers[$i]->server_update_port) . "\n"; $failures = true; break; } /** Remote URL to use */ $url = $name_servers[$i]->server_update_method . '://' . $name_servers[$i]->server_name . ':' . $name_servers[$i]->server_update_port . '/' . $_SESSION['module'] . '/reload.php'; /** Data to post to $url */ $post_data = array('action' => 'reload', 'serial_no' => $name_servers[$i]->server_serial_no, 'domain_id' => $domain_id); $post_result = unserialize(getPostData($url, $post_data)); if (!is_array($post_result)) { /** Something went wrong */ return '<div class="error"><p>' . $post_result . '</p></div>' . "\n"; } else { if (count($post_result) > 1) { /** Loop through and format the output */ foreach ($post_result as $line) { $response .= '[' . $name_servers[$i]->server_name . "] {$line}\n"; if (strpos(strtolower($line), 'fail')) { $failures = true; } } } else { $response .= "[{$name_servers[$i]->server_name}] " . $post_result[0] . "\n"; if (strpos(strtolower($post_result[0]), 'fail')) { $failures = true; } } } /** Set the server_update_config flag */ setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update'); break; case 'ssh': /** Test the port first */ if (!socketTest($name_servers[$i]->server_name, $name_servers[$i]->server_update_port, 10)) { $response .= '[' . $name_servers[$i]->server_name . '] ' . sprintf(__('Failed: could not access %s (tcp/%d).'), $name_servers[$i]->server_update_method, $name_servers[$i]->server_update_port) . "\n"; $failures = true; break; } /** Get SSH key */ $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']); if (!$ssh_key) { return '<p class="error">' . sprintf(__('Failed: SSH key is not <a href="%s">defined</a>.'), getMenuURL(_('Settings'))) . '</p>' . "\n"; } $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa'; if (file_exists($temp_ssh_key)) { @unlink($temp_ssh_key); } if (@file_put_contents($temp_ssh_key, $ssh_key) === false) { return '<p class="error">' . sprintf(__('Failed: could not load SSH key into %s.'), $temp_ssh_key) . '</p>' . "\n"; } @chmod($temp_ssh_key, 0400); $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']); if (!$ssh_user) { return '<p class="error">' . sprintf(__('Failed: SSH user is not <a href="%s">defined</a>.'), getMenuURL(_('Settings'))) . '</p>' . "\n"; } unset($post_result); exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$name_servers[$i]->server_update_port} -l {$ssh_user} {$name_servers[$i]->server_name} 'sudo php /usr/local/{$fm_name}/{$_SESSION['module']}/dns.php zones id={$domain_id}'", $post_result, $retval); @unlink($temp_ssh_key); if (!is_array($post_result)) { /** Something went wrong */ return sprintf('<p class="error">%s</p>' . "\n", $post_result); } else { if (!count($post_result)) { $post_result[] = __('Zone reload was successful.'); } if (count($post_result) > 1) { /** Loop through and format the output */ foreach ($post_result as $line) { $response .= '[' . $name_servers[$i]->server_name . "] {$line}\n"; if (strpos(strtolower($line), 'fail')) { $failures = true; } } } else { $response .= "[{$name_servers[$i]->server_name}] " . $post_result[0] . "\n"; if (strpos(strtolower($post_result[0]), 'fail')) { $failures = true; } } } /** Set the server_update_config flag */ setBuildUpdateConfigFlag($name_servers[$i]->server_serial_no, 'yes', 'update'); break; } } $response .= "</textarea>\n"; /** Reset the domain_reload flag */ if (!$failures) { global $fm_dns_records; if (!isset($fm_dns_records)) { include ABSPATH . 'fm-modules/fmDNS/classes/class_records.php'; } $fm_dns_records->updateSOAReload($domain_id, 'no'); } addLogEntry(sprintf(__("Reloaded zone '%s'."), displayFriendlyDomainName($domain_name))); return $response; }
/** * Adds the new record */ function add($domain_id, $record_type, $new_array, $operation = 'insert') { global $fmdb, $__FM_CONFIG, $fm_dns_zones; $domain_name = displayFriendlyDomainName(getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name')); $log_message = "Added a record with the following details:\nDomain: {$domain_name}\nType: {$record_type}\n"; $table = $record_type == 'SOA' ? 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'soa' : 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records'; /** Check if record already exists */ if ($record_type != 'SOA') { $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}records WHERE domain_id={$domain_id} AND record_name='{$new_array['record_name']}'\n\t\t\t\t\tAND record_value='{$new_array['record_value']}' AND record_type='{$record_type}' AND record_status != 'deleted'"; $result = $fmdb->get_results($query); if ($fmdb->num_rows) { return; } } $new_array['account_id'] = $_SESSION['user']['account_id']; /** Replacing? */ if ($operation == 'replace' && $record_type == 'PTR') { $query = "UPDATE fm_{$__FM_CONFIG['fmDNS']['prefix']}records SET record_status='deleted' WHERE account_id='{$_SESSION['user']['account_id']}'\n\t\t\t\tAND domain_id={$domain_id} AND record_name='{$new_array['record_name']}' AND record_status!='deleted' LIMIT 1"; $fmdb->query($query); } $sql_insert = "INSERT INTO `{$table}`"; $sql_fields = '('; if ($record_type != 'SOA' && $record_type) { $sql_fields .= 'domain_id,record_type,'; $sql_values .= "{$domain_id},'{$record_type}',"; } /** Process default integers */ if (array_key_exists('record_priority', $new_array) && !is_numeric($new_array['record_priority'])) { $new_array['record_priority'] = 0; } if (array_key_exists('record_weight', $new_array) && !is_numeric($new_array['record_weight'])) { $new_array['record_weight'] = 0; } if (array_key_exists('record_port', $new_array) && !is_numeric($new_array['record_port'])) { $new_array['record_port'] = 0; } if (array_key_exists('record_ttl', $new_array) && !is_numeric($new_array['record_ttl'])) { $new_array['record_ttl'] = null; } foreach ($new_array as $key => $data) { if ($key == 'PTR') { continue; } if ($key == 'record_type') { continue; } if ($record_type == 'SOA' && in_array($key, array('record_type', 'record_comment'))) { continue; } $sql_fields .= $key . ','; $sql_values .= "'" . mysql_real_escape_string($data) . "',"; if ($key != 'account_id') { $log_message .= $data ? formatLogKeyData('record_', $key, $data) : null; } if ($key == 'soa_default' && $data == 'yes') { $query = "UPDATE `{$table}` SET {$key} = 'no' WHERE `account_id`='{$_SESSION['user']['account_id']}'"; $result = $fmdb->query($query); } } $sql_fields = rtrim($sql_fields, ',') . ')'; $sql_values = rtrim($sql_values, ','); $query = "{$sql_insert} {$sql_fields} VALUES ({$sql_values})"; $result = $fmdb->query($query); if (!$fmdb->result) { return false; } /** Update domain with SOA ID */ if ($record_type == 'SOA') { $this->assignSOA($fmdb->insert_id, $domain_id); } if (!$fm_dns_zones) { include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php'; } /** Update the SOA serial number */ foreach ($fm_dns_zones->getZoneTemplateChildren($domain_id) as $child_id) { $domain_id = getParentDomainID($child_id); $soa_count = getSOACount($domain_id); $ns_count = getNSCount($domain_id); if (reloadAllowed($domain_id) && $soa_count && $ns_count) { $this->updateSOAReload($child_id, 'yes'); } if (in_array($record_type, array('SOA', 'NS')) && $soa_count && $ns_count) { /** Update all associated DNS servers */ setBuildUpdateConfigFlag(getZoneServers($child_id), 'yes', 'build'); } } addLogEntry($log_message); return true; }
/** * Sets SOA serials and reload flags per domain_id * * @since 2.1 * @package facileManager * @subpackage fmDNS * * @param id $domain_id domain_id to set * @param id $record_type Record type to check * @param id $action Add or update * @return null */ function processSOAUpdates($domain_id, $record_type, $action) { global $fm_dns_zones; if (!$fm_dns_zones) { include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php'; } foreach ($fm_dns_zones->getZoneTemplateChildren($domain_id) as $child_id) { $domain_id = getParentDomainID($child_id); $soa_count = getSOACount($domain_id); $ns_count = getNSCount($domain_id); if (reloadAllowed($domain_id) && $soa_count && $ns_count) { $this->updateSOAReload($child_id, 'yes'); } if ($action == 'add') { if (in_array($record_type, array('SOA', 'NS')) && $soa_count && $ns_count) { /** Update all associated DNS servers */ setBuildUpdateConfigFlag(getZoneServers($child_id), 'yes', 'build'); } } } }
/** * Deletes the selected key */ function delete($id, $server_serial_no = 0) { global $fmdb, $__FM_CONFIG; $tmp_name = getNameFromID($id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_', 'key_id', 'key_name'); if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', $id, 'key_', 'deleted', 'key_id') === false) { return __('This key could not be deleted because a database error occurred.'); } else { setBuildUpdateConfigFlag($server_serial_no, 'yes', 'build'); addLogEntry(sprintf(__("Key '%s' was deleted."), $tmp_name)); return true; } }
function moduleCompleteClientInstallation() { /** Install default config option overrides based on OS distro */ setDefaultOverrideOptions(); setBuildUpdateConfigFlag($_POST['SERIALNO'], 'yes', 'build'); }