PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/settings.php

http://github.com/sjparkinson/isitup
PHP | 169 lines | 109 code | 25 blank | 35 comment | 12 complexity | c8034825092de6f24c8dcb1345eca730 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. ############# Configuration #############
  3. // Set to false to bring the site offline.
  4. $setting["live"] = true;
  5. // Set to true to see PHP errors, warnings and notices.
  6. $setting["errors"] = false;
  7. // Server time zone, for database records. (use: http://www.php.net/manual/en/timezones.php)
  8. $setting["time_zone"] = "Europe/London";
  9. // The default input value
  10. $setting["default"] = "duckduckgo.com";
  11. // The max time to check if a site is working for, in seconds.
  12. $setting["timeout"] = 3;
  13. // Static content override. No trailing slash.
  14. // For example:
  15. // $setting["static"] = "http://my.cdn.com/static/";
  16. $setting["static"] = "/static"; // Local folder
  17. // Folder of script, no trailing slash.
  18. $setting["folder"] = "";
  19. // A list of banned user agents.
  20. $setting["banned_ua"] = array
  21. (
  22. "Mozilla/4.0 (compatible; ICS)",
  23. "Rackspace Monitoring/1.1 (https://monitoring.api.rackspacecloud.com)",
  24. "Python-urllib/1.17",
  25. "Xenu Link Sleuth/1.3.8"
  26. );
  27. // A list of banned referrers, can include wildcards.
  28. $setting["banned_referrers"] = array
  29. (
  30. "http://*.xnrg.net/*",
  31. "http://banjia.yulewangzhan.cn/*",
  32. "http://gang.yulewangzhan.cn/*",
  33. "http://hao.dangqian.com/hao/*",
  34. "http://tlapple.com/*",
  35. "http://www.010bjanmo.com/*",
  36. "http://www.36963.com/*",
  37. "http://www.510532.com/*",
  38. "http://www.51qqq.net/*",
  39. "http://www.62idc.com/*",
  40. "http://www.72tui.com/*",
  41. "http://www.110.gd*",
  42. "http://www.278cc.com/*",
  43. "http://www.598yingxiao.com/*",
  44. "http://www.680.com/*",
  45. "http://www.41418.net/*",
  46. "http://www.668108.com/",
  47. "http://www.747474.net/*",
  48. "http://www.2011522.com/*",
  49. "http://www.babaw.com/*",
  50. "http://www.bjnanmo.com/*",
  51. "http://www.craneceo.com/*",
  52. "http://www.dangqian.com/*",
  53. "http://www.dt-qz.com*",
  54. "http://www.ej158.com/*",
  55. "http://www.gpxz.com/*",
  56. "http://www.hexiushou.com/*",
  57. "http://www.hitsaati.com/backlinky.php",
  58. "http://www.itunion.cn/*",
  59. "http://www.junminqing.com/*",
  60. "http://www.ku58.com/*",
  61. "http://maskr.in/*",
  62. "http://www.ndhjd.com/*",
  63. "http://niulangdian.com/*",
  64. "http://www.pinyouge.com/*",
  65. "http://www.shihuifanli.com*",
  66. "http://www.ufukart.com/backlink/index.html",
  67. "http://www.wanshida518.cn/*",
  68. "http://www.yuehaiwang.com/*",
  69. "http://www.yuzhouzhiwang.com/*",
  70. "http://www.zjgdesign.com/*",
  71. "http://seo.dadadihao.com/*",
  72. "http://www.90kis.com/*",
  73. "http://www.zyruide.com/*",
  74. "http://www.bmizg.com/*",
  75. "http://www.ydjyjg.net/*"
  76. );
  77. #########################################
  78. // Sets the error level.
  79. if ($setting["errors"] == true)
  80. {
  81. error_reporting(E_ALL);
  82. }
  83. else
  84. {
  85. error_reporting(0);
  86. }
  87. // Sets the time zone.
  88. date_default_timezone_set($setting["time_zone"]);
  89. // Sets the timeout.
  90. ini_set("default_socket_timeout", $setting["timeout"]);
  91. // Sets the host domain.
  92. $setting["host"] = $_SERVER["SERVER_NAME"];
  93. if ($setting["folder"] != "")
  94. {
  95. $setting["host"] = $setting["host"] . $setting["folder"];
  96. }
  97. /**
  98. * Checks the given request headers against the lists of banned items.
  99. *
  100. * @return bool
  101. */
  102. function is_bad_request()
  103. {
  104. global $setting;
  105. // Check the referer is not banned.
  106. if (is_banned_referrer($setting["banned_referrers"])) return true;
  107. // Check the user-agent is not empty and not in the banned list.
  108. if (strlen(trim($_SERVER["HTTP_USER_AGENT"])) == 0
  109. || in_array($_SERVER["HTTP_USER_AGENT"], $setting["banned_ua"])) return true;
  110. return false;
  111. }
  112. /**
  113. * Checks the given referrer against the list of banned referrers and return true if there is a match.
  114. *
  115. * @return bool
  116. */
  117. function is_banned_referrer($patterns)
  118. {
  119. // Check the supplied referrer isn't banned.
  120. if ( isset($_SERVER["HTTP_REFERER"]) )
  121. {
  122. foreach ($patterns as $pattern)
  123. {
  124. if ( fnmatch($pattern, $_SERVER["HTTP_REFERER"]) ) return true;
  125. }
  126. }
  127. return false;
  128. }
  129. // Forbid banned ips or user agents.
  130. if ( is_bad_request() )
  131. {
  132. header("HTTP/1.1 403 Forbidden");
  133. exit();
  134. };
  135. // Check if we should send people to the offline page.
  136. if ($setting["live"] === false)
  137. {
  138. header("Location: /offline.html", true, 503);
  139. exit();
  140. };
  141. /**
  142. * Set the headers.
  143. */
  144. header("X-XSS-Protection: 1; mode=block");