lgsl_feed.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. include("lgsl_protocol.php");
  3. function lgsl_string_html($string, $xml_feed = FALSE, $word_wrap = 0)
  4. {
  5. if ($word_wrap) { $string = lgsl_word_wrap($string, $word_wrap); }
  6. if ($xml_feed != FALSE)
  7. {
  8. $string = htmlspecialchars($string, ENT_QUOTES);
  9. }
  10. elseif (function_exists("mb_convert_encoding"))
  11. {
  12. $string = htmlspecialchars($string, ENT_QUOTES);
  13. $string = @mb_convert_encoding($string, "HTML-ENTITIES", "UTF-8");
  14. }
  15. else
  16. {
  17. $string = htmlentities($string, ENT_QUOTES, "UTF-8");
  18. }
  19. if ($word_wrap) { $string = lgsl_word_wrap($string); }
  20. return $string;
  21. }
  22. //------------------------------------------------------------------------------------------------------------+
  23. function lgsl_word_wrap($string, $length_limit = 0)
  24. {
  25. if (!$length_limit)
  26. {
  27. // http://www.quirksmode.org/oddsandends/wbr.html
  28. // return str_replace("\x05\x06", " ", $string); // VISIBLE
  29. // return str_replace("\x05\x06", "&shy;", $string); // FF2 VISIBLE AND DIV NEEDED
  30. return str_replace("\x05\x06", "&#8203;", $string); // IE6 VISIBLE
  31. }
  32. $word_list = explode(" ", $string);
  33. foreach ($word_list as $key => $word)
  34. {
  35. $word_length = function_exists("mb_strlen") ? mb_strlen($word, "UTF-8") : strlen($word);
  36. if ($word_length < $length_limit) { continue; }
  37. $word_new = "";
  38. for ($i=0; $i<$word_length; $i+=$length_limit)
  39. {
  40. $word_new .= function_exists("mb_substr") ? mb_substr($word, $i, $length_limit, "UTF-8") : substr($word, $i, $length_limit);
  41. $word_new .= "\x05\x06";
  42. }
  43. $word_list[$key] = $word_new;
  44. }
  45. return implode(" ", $word_list);
  46. }
  47. //------------------------------------------------------------------------------------------------------------+
  48. $type = isset($_GET['lgsl_type'])? lgsl_string_html($_GET['lgsl_type']): "";
  49. $ip = isset($_GET['ip']) ? lgsl_string_html($_GET['ip']) : "";
  50. $c_port = isset($_GET['c_port']) ? intval($_GET['c_port']) : 0;
  51. $q_port = isset($_GET['q_port']) ? intval($_GET['q_port']) : 0;
  52. $s_port = isset($_GET['s_port']) ? intval($_GET['s_port']) : 0;
  53. $request = isset($_GET['request']) ? lgsl_string_html($_GET['request']) : "";
  54. //------------------------------------------------------------------------------------------------------------+
  55. // VALIDATE REQUEST
  56. if (!$type || !$ip || !$c_port || !$q_port || !$request)
  57. {
  58. echo "FAILURE"; return;
  59. }
  60. if ($q_port > 99999 || $q_port < 1024)
  61. {
  62. echo "FAILURE"; return;
  63. }
  64. if (preg_match("/[^0-9a-z\.\-\[\]\:]/i", $ip))
  65. {
  66. echo "FAILURE"; return;
  67. }
  68. if (preg_match("/[^a-z]/", $request))
  69. {
  70. echo "FAILURE"; return;
  71. }
  72. if ($type == "test")
  73. {
  74. echo "FAILURE"; return;
  75. }
  76. $lgsl_protocol_list = lgsl_protocol_list();
  77. if (!isset($lgsl_protocol_list[$type]))
  78. {
  79. echo "FAILURE"; return;
  80. }
  81. //------------------------------------------------------------------------------------------------------------+
  82. // FILTER HOSTNAME AND IP FORMATS THAT PHP ACCEPTS BUT ARE NOT WANTED
  83. if (preg_match("/(\[[0-9a-z\:]+\])/iU", $ip, $match)) { $ip = $match[1]; }
  84. elseif (preg_match("/([0-9a-z\.\-]+)/i", $ip, $match)) { $ip = $match[1]; }
  85. //------------------------------------------------------------------------------------------------------------+
  86. // QUERY SERVER
  87. $server = lgsl_query_live($type, $ip, $c_port, $q_port, $s_port, $request);
  88. //------------------------------------------------------------------------------------------------------------+
  89. // SERIALIZED OUTPUT
  90. echo "_SLGSLF_".serialize($server)."_SLGSLF_";
  91. return;