/** * Tests server connectivity */ function connectTests() { global $fmdb, $__FM_CONFIG; $return = null; /** Get server list */ $result = basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name', 'server_'); if (!$fmdb->num_rows) { return __('There are no servers defined.'); } /** Process server list */ $num_rows = $fmdb->num_rows; $results = $fmdb->last_result; for ($x = 0; $x < $num_rows; $x++) { $return .= sprintf(__("Running tests for %s\n"), $results[$x]->server_name); /** ping tests */ $return .= "\t" . str_pad(__('Ping:'), 15); if (pingTest($results[$x]->server_name)) { $return .= __('success'); } else { $return .= __('failed'); } $return .= "\n"; /** SQL tests */ $return .= "\t" . str_pad($results[$x]->server_type . ':', 15); $port = $results[$x]->server_port ? $results[$x]->server_port : $__FM_CONFIG['fmSQLPass']['default']['ports'][$results[$x]->server_type]; if (socketTest($results[$x]->server_name, $port, 10)) { $return .= __('success') . ' (tcp/' . $port . ')'; } else { $return .= __('failed') . ' (tcp/' . $port . ')'; } $return .= "\n\n"; } return $return; }
/** * Tests server connectivity */ function connectTests() { global $fmdb, $__FM_CONFIG; $return = null; /** Load ssh key for use */ $ssh_key = getOption('ssh_key_priv', $_SESSION['user']['account_id']); $temp_ssh_key = sys_get_temp_dir() . '/fm_id_rsa'; if ($ssh_key) { if (file_exists($temp_ssh_key)) { @unlink($temp_ssh_key); } $ssh_key_loaded = @file_put_contents($temp_ssh_key, $ssh_key); @chmod($temp_ssh_key, 0400); } $ssh_user = getOption('ssh_user', $_SESSION['user']['account_id']); /** Get server list */ $result = basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name', 'server_'); /** Process server list */ $num_rows = $fmdb->num_rows; $results = $fmdb->last_result; for ($x = 0; $x < $num_rows; $x++) { $return .= sprintf(__("Running tests for %s\n"), $results[$x]->server_name); /** ping tests */ $return .= "\t" . str_pad(__('Ping:'), 15); if (pingTest($results[$x]->server_name)) { $return .= __('success'); } else { $return .= __('failed'); } $return .= "\n"; /** remote port tests */ $return .= "\t" . str_pad(__('Remote Port:'), 15); if ($results[$x]->server_update_method != 'cron') { if (socketTest($results[$x]->server_name, $results[$x]->server_update_port, 10)) { $return .= __('success') . ' (tcp/' . $results[$x]->server_update_port . ")\n"; if ($results[$x]->server_update_method == 'ssh') { $return .= "\t" . str_pad(__('SSH Login:'******'no SSH key defined'); } elseif ($ssh_key_loaded === false) { $return .= sprintf(__('could not load SSH key into %s'), $temp_ssh_key); } elseif (!$ssh_user) { $return .= __('no SSH user defined'); } else { exec(findProgram('ssh') . " -t -i {$temp_ssh_key} -o 'StrictHostKeyChecking no' -p {$results[$x]->server_update_port} -l {$ssh_user} {$results[$x]->server_name} uptime", $post_result, $retval); if ($retval) { $return .= __('ssh key login failed'); } else { $return .= __('success'); } } } else { /** php tests */ $return .= "\t" . str_pad(__('http page:'), 15); $php_result = getPostData($results[$x]->server_update_method . '://' . $results[$x]->server_name . '/' . $_SESSION['module'] . '/reload.php', null); if ($php_result == 'Incorrect parameters defined.') { $return .= __('success'); } else { $return .= __('failed'); } } } else { $return .= __('failed') . ' (tcp/' . $results[$x]->server_update_port . ')'; } } else { $return .= __('skipping (host updates via cron)'); } $return .= "\n"; /** dns tests */ $return .= "\t" . str_pad(__('DNS:'), 15); $port = 53; if (socketTest($results[$x]->server_name, $port, 10)) { $return .= __('success') . ' (tcp/' . $port . ')'; } else { $return .= __('failed') . ' (tcp/' . $port . ')'; } $return .= "\n"; $return .= "\n"; } @unlink($temp_ssh_key); return $return; }
} else { return "false"; } } ///////// ///////// ///////// Ping the address list ///////// ///////// echo "{"; echo "\"systems\":["; // if($i=0; $i<count($systemList); $i++){ foreach ($systemList as $system) { echo "{"; echo "\"name\":\"" . $system[1] . "\","; echo "\"addr\":\"" . $system[0] . "\","; echo "\"type\":\"" . $system[2] . "\","; echo "\"x\":\"" . $system[3] . "\","; echo "\"y\":\"" . $system[4] . "\","; echo "\"status\":\"" . pingTest($system[0]) . "\""; echo "}"; if ($system != end($systemList)) { echo ","; } } echo "]"; echo "}"; ?>
<?php ///////// ///////// ///////// Ping Function ///////// ///////// /* function pingTest($_addr){ if( exec("fping $_addr -t100 | grep alive") > "" ){ return "true"; }else{ return "false"; } } */ ///////// ///////// ///////// Ping Google for connection and DNS ///////// ///////// echo "{"; echo "\"network\":{"; echo "\"connected\": \"" . pingTest("74.125.237.176") . "\","; echo "\"dns\": \"" . pingTest("www.google.com") . "\""; echo "}"; echo "}"; ?>