PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/server/ping_server.inc.php

http://lansuite.googlecode.com/
PHP | 130 lines | 93 code | 15 blank | 22 comment | 46 complexity | 5bd2d5d7c5fadf7589201401d919dcc7 MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. function ping_server($host, $port) {
  3. global $db, $func;
  4. $cfg["server_ping_refresh"] = (int) $cfg["server_ping_refresh"];
  5. $server_daten = $db->qry_first("SELECT UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(lastscan) AS idle, type, available, special_info
  6. FROM %prefix%server
  7. WHERE (ip = %string%) AND (port = %string%)
  8. HAVING (idle > %int%)
  9. ", $host, $port, $cfg["server_ping_refresh"]);
  10. if (rand(0, 2) == 0){
  11. // Erreichbarkeit testen
  12. $success = 0;
  13. if($func->ping($host)) $success = 1;
  14. $available = $success;
  15. $special_info = "";
  16. // Weitere Daten für FTPs herrausfinden
  17. if (($success) && ($server_daten["type"] == "ftp")) if ($fp = @fsockopen ($host, $port, $errno, $errstr, 1))
  18. {
  19. socket_set_blocking($fp, false);
  20. socket_set_timeout($fp, 1, 500);
  21. //Benutzernamen senden
  22. fputs ($fp, "USER anonymous\r\n");
  23. //Passwort senden
  24. fputs ($fp, "PASS erreichbarkeitstest@lansuite.de\r\n");
  25. //In Pasivmode wechseln
  26. fputs ($fp, "PASV\r\n");
  27. //System abfragen
  28. fputs ($fp, "SYST\r\n");
  29. //Verzeichnis auflisten
  30. fputs ($fp, "LIST\r\n");
  31. //Quit senden
  32. fputs ($fp, "QUIT\r\n");
  33. $res = fread($fp, 1000);
  34. //Antwort auswerten
  35. if ((strpos($res, "logged in") != 0) && (strpos($res, "230") != 0))
  36. {
  37. $special_info .= "<div class=\"tbl_green\">".t('Login als Anonymous erfolgreich')."</div>";
  38. } else {
  39. $special_info .= "<div class=\"tbl_error\">".t('Login als Anonymous fehlgeschlagen')."</div>";
  40. }
  41. if ((strpos($res, "Ratio") != 0) && (strpos($res, "426") != 0))
  42. {
  43. $special_info .= "<div class=\"tbl_error\">".t('Ratio-FTP (Es muss zuerst etwas hochgeladen werden)')."</div>";
  44. }
  45. if ((strpos($res, "Quota") != 0) && (strpos($res, "426") != 0))
  46. {
  47. $special_info .= "<div class=\"tbl_error\">".t('Quota-FTP (Es darf nur eine gewisse Menge gezogen werden)')."</div>";
  48. }
  49. if ((strpos($res, "Too many") != 0) && (strpos($res, "21") != 0))
  50. {
  51. $special_info .= "<div class=\"tbl_error\">".t('<u>Hinweis</u>: Zu viele User momentan')."</div>";
  52. }
  53. if ((strpos($res, "home directory") != 0) && (strpos($res, "530") != 0))
  54. {
  55. $special_info .= "<div class=\"tbl_error\">".t('<u>Fehler</u>: Server hat kein Home-Directory gesetzt')."</div>";
  56. }
  57. if ((strpos($res, "220") === 0))
  58. {
  59. $special_info .= "<div class=\"tbl_black\">: ".substr($res, 4, strpos($res, "\r\n")-2)."</div>";
  60. }
  61. if ((strpos($res, "215") != 0))
  62. {
  63. $special_info .= "<div class=\"tbl_black\">".t('System').": ".substr(substr($res, strpos($res, "215"), 99), 4, strpos(substr($res, strpos($res, "215"), 99), "\r\n")-2) ."</div>";
  64. }
  65. $error_stri=$res;
  66. for ($error_stri_num=0; $error_stri_num<10; $error_stri_num++) if (strpos($error_stri, "530 ") != 0)
  67. {
  68. if ($error_stri_num == 0) { $special_info .= HTML_NEWLINE . "<div class=\"tbl_black\"><u>".t('Fehlermeldungen').":</u></div>"; }
  69. $error_stri=substr($error_stri, strpos($error_stri, "530 ")+4, 9999);
  70. $special_info .= "<div class=\"tbl_black\">". substr($error_stri, 0, strpos($error_stri, "\r\n")) ."</div>";
  71. }
  72. fclose($fp);
  73. // Wenn Socketverbindung fehlgeschlagen
  74. } else {
  75. $available=2;
  76. $success=0;
  77. // echo "$errstr ($errno)<br>\n";
  78. } // END: If Type=FTP
  79. // Weitere Daten für IRCs herrausfinden
  80. if (($success) && ($server_daten["type"] == "irc")) if ($fp = @fsockopen ($host, $port, $errno, $errstr, 1))
  81. {
  82. socket_set_blocking($fp, false);
  83. socket_set_timeout($fp, 1, 500);
  84. //Ident senden
  85. #fputs ($fp, "identify lansuite\r\n");
  86. //Nick setzen
  87. #fputs ($fp, "nick ls_script\r\n");
  88. //Liste anfordern
  89. fputs ($fp, "list\r\n");
  90. //Verabschieden
  91. fputs ($fp, "quit done\r\n");
  92. $channel_num=0;
  93. $res = fread($fp, 1000);
  94. // Channel ausgeben
  95. $special_info .= "<div class=\"tbl_black\"><u>".t('Channels').":</u></div>";
  96. $channel=$res;
  97. for ($channel_num=0;$channel_num<10;$channel_num++) if (strpos($channel, "322 ") != 0)
  98. {
  99. $channel=substr($channel, strpos($channel, "322 ")+5, 9999);
  100. $special_info .= "<div class=\"tbl_black\">". substr($channel, 0, strpos($channel, ":")-1) ."</div>";
  101. }
  102. fclose($fp);
  103. // Wenn Socketverbindung fehlgeschlagen
  104. } else {
  105. $available=2;
  106. $success=0;
  107. //echo "$errstr ($errno)<br>\n";
  108. } // END: If Type=IRC
  109. // Ergebins speichern
  110. if ($special_info =="") { $special_info=$server_daten["special_info"]; }
  111. $special_info = $special_info;
  112. $db->qry('UPDATE %prefix%server SET special_info=%string%, available=%string%, scans=scans+1, success=success+%int%, lastscan=NOW() WHERE ((ip = %string%) AND (port=%int%));', $special_info, $available, $success, $host, $port);
  113. }
  114. }
  115. ?>