function createBox($serviceName, $serverName, $customName) { include './functions/dbconnect.php'; $sql = 'select * from servers'; $result = mysqli_query($con, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { echo " Name: " . $row["server_custom_name"] . " | " . getIP($row["server_name"]) . ""; echo "Response time (ms): " . pingServer($row["server_name"]); } } else { echo 'There are not data to display for this query.'; } echo "<div class='box'>\n<h2>{$customName} | "; getIP($serverName); echo "</h2>\n\t<hr>\n\t<span class='pingbox'>\n\t<h3>Ping</h3>"; pingServer($serverName); echo "</span>\n\t<span class='servicebox'>\n\t<h3>Service Status</h3>\n\t"; serviceStatus($serviceName, $serverName); echo "</span>\n</div>"; }
<?php function pingServer($host, $port) { $check = false; $waitTimeoutInSeconds = 1; if ($fp = fsockopen($host, $port, $errCode, $errStr, $waitTimeoutInSeconds)) { $check = true; } else { $check = false; } fclose($fp); if ($check) { return 1; } else { return 0; } } $jarr = array('entity' => pingServer("64.25.34.201", 2400), 'entityywo' => pingServer("64.25.35.100", 6600), 'warhound' => pingServer("64.25.35.100", 660), 'warhoundtwo' => pingServer("64.25.34.202", 6600)); echo json_encode($jarr);
function checkForUpdate() { $version = getVersion(); $url = "http://ccms.vahida.ir/update.csv"; $host = 'ccms.vahida.ir'; if (pingServer($host) == 0) { if ($fp = @fopen($url, 'r')) { $read = fgetcsv($fp); fclose($fp); if ($read[0] - $version > 0) { $_SESSION['stat_desc'] = $read[1]; $_SESSION['stat_version'] = $read[0]; $_SESSION['stat_link'] = $read[3]; $_SESSION['stat_date'] = $read[4]; if ($read[2] == 'r') { $_SESSION['update_check'] = 1; // regular update } elseif ($read[2] == 'c') { $_SESSION['update_check'] = 2; // critical update } return $read; // update available } else { $_SESSION['update_check'] = -1; return -1; // no update } } } else { $_SESSION['update_server_down'] = 1; return -1; } }