- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
<?php
set_time_limit(600);
//error_reporting (E_ALL);
#############################################################
## Проверка: запущен или нет фтп сервер. Зпускаю nnCron'ом ##
#############################################################
$proxy = "172.16.0.2";
$port = "2121";
$timeout = 10;
$sleep = 0;
require_once('set.php');
$link = mysql_connect($servername, $username, $password) or die("Could not connect : ".mysql_error());
mysql_query("SET CHARACTER SET cp1251;");
mysql_select_db("ftp");
$online=mysql_query("SELECT * FROM `online_sial`;");
$offline=mysql_query("SELECT * FROM `offline_sial`;");
$this_time = time();
while ($row = mysql_fetch_array($online)) {
$url = "ftp://".$row['ipaddr']."/";
if($fp = fsockopen($proxy, $port, $errno, $errstr, $timeout)){
fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy\r\n\r\n");
stream_set_timeout($fp, 10);
$res = fread($fp, 100);
$info = stream_get_meta_data($fp);
fclose($fp);
if (!$info['timed_out']){
$del="DELETE FROM `online_sial` WHERE ipaddr=\"".$row['ipaddr']."\";";
$ins="INSERT INTO `online_sial` values (\"".$row['hostname']."\", \"".$row['ipaddr']."\", \"".$this_time."\", \"".$row['comment']."\");";
mysql_query($del);
mysql_query($ins);
echo $row['hostname']."<br />";
}else{
$del="DELETE FROM `online_sial` WHERE ipaddr=\"".$row['ipaddr']."\";";
$ins="INSERT INTO `offline_sial` values (\"".$row['hostname']."\", \"".$row['ipaddr']."\", \"".$this_time."\", \"".$row['comment']."\");";
mysql_query($del);
mysql_query($ins);
echo $row['hostname']."<br />";
}
sleep($sleep);
}else echo "Proxy упал<br />";
}
while ($row = mysql_fetch_array($offline)) {
$url = "ftp://".$row['ipaddr']."/";
if($fp = fsockopen($proxy, $port, $errno, $errstr, $timeout)){
fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy\r\n\r\n");
stream_set_timeout($fp, 10);
$res = fread($fp, 100);
$info = stream_get_meta_data($fp);
fclose($fp);
if (!$info['timed_out']){
$del="DELETE FROM `offline_sial` WHERE ipaddr=\"".$row['ipaddr']."\";";
$ins="INSERT INTO `online_sial` values (\"".$row['hostname']."\", \"".$row['ipaddr']."\", \"".$this_time."\", \"".$row['comment']."\");";
mysql_query($del);
mysql_query($ins);
echo $row['hostname']."<br />";
}
sleep($sleep);
} echo "Proxy упал<br />";
}
mysql_query("ALTER TABLE `ftp`.`online_sial` ORDER BY `hostname`;");
mysql_query("ALTER TABLE `ftp`.`offline_sial` ORDER BY `hostname`;");
mysql_close($link);
?>
Пять лет назад. Этим можно пугать детей.