surf.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?PHP
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of LightOff.
  6. *
  7. * LightOff is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * LightOff is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with LightOff. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * surf.php
  21. *
  22. * The surfing page.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. require("config.inc");
  28. echo("<div style='top:5px;font-weight:900;background-color:#FFFFFF;'>&nbsp;LIGHTOFF&nbsp;&nbsp;(<a href='http://github.com/par7133/LightOff' target='_blank'>on github</a>)</div><br><br>");
  29. $url = filter_input(INPUT_GET, "url", FILTER_SANITIZE_STRING);
  30. //echo($url."<br>");
  31. if (substr($url, 0, 4) === "http") {
  32. $ipos = stripos($url, "/", 8);
  33. if ($ipos) {
  34. $domain = substr($url, 0, $ipos);
  35. } else {
  36. $domain = $url;
  37. }
  38. } else {
  39. $domain = stripos($url, "/");
  40. if ($ipos) {
  41. $domain = "http://" . substr($url, 0, $ipos);
  42. } else {
  43. $domain = "http://" . $url;
  44. }
  45. }
  46. //echo($domain."<br>");
  47. $file = fopen($url, "r");
  48. if (!$file) {
  49. echo "<p>404 LightOff url doesn't exist.</p>\n";
  50. exit;
  51. }
  52. $w = "";
  53. while (!feof($file)) {
  54. $w .= fgets($file, 20000);
  55. }
  56. fclose($file);
  57. $ipos = stripos($w, "</head>");
  58. $head = substr($w, 0, $ipos + 7);
  59. $body = substr($w, $ipos + 7);
  60. $head = str_ireplace("</head>", "<script src='".APP_HOST."/js/jquery-3.6.0.min.js' type='text/javascript'></script>\n<script src='".APP_HOST."/js/common.js' type='text/javascript'></script>\n<link href='".APP_HOST."/css/style.css' type='text/css' rel='stylesheet'>\n<link href='".APP_HOST."/css/bootstrap.min.css' type='text/css' rel='stylesheet'>\n</head>", $head);
  61. if (mb_stripos($head, "<base") === false ) {
  62. $head = str_ireplace("</head>", "<base href='$domain/'>\n</head>", $head);
  63. }
  64. $head = str_ireplace('src="//', 'src="https://', $head);
  65. $head = str_ireplace('src="/', 'src="'.$domain.'/', $head);
  66. $head = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $head);
  67. $head = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $head);
  68. //$head = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $head);
  69. //$head = str_ireplace('src="js/', 'src="'.$domain.'/js/', $head);
  70. //$head = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $head);
  71. $head = str_ireplace('href="//', 'href="https://', $head);
  72. $head = str_ireplace('href="/', 'href="'.$domain.'/', $head);
  73. $head = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $head);
  74. $head = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $head);
  75. //$head = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $head);
  76. //$body = preg_replace("/<body .+>/iU", "$0\n<form id='LIGHTOFFfrmUpload' role='form' method='get' action='/surf2.php' target='_self' enctype='multipart/form-data'>\n<div id='LIGHTOFFcontent'><div id='LIGHTOFFheader-surf'><br>&nbsp;&nbsp;<span style='font-weight:900;'>LIGHTOFF</span><br></div>", $body);
  77. //$body = str_ireplace("</body>", "<input type='url' id='LIGHTOFFurl' name='LIGHTOFFurl' value='https://5mode.com' style='display: none;'>&nbsp;<input id='LIGHTOFFSubmit' name='LIGHTOFFSubmit' type='submit' style='display: none;'><br>\n\n</div>\n\n</form>\n\n<script src='http://lightoff.doggy/js/surf.js' type='text/javascript'></script>\n\n</body>", $body);
  78. $body = str_ireplace("</body>", "\n\n<script src='".APP_HOST."/js/surf.js' type='text/javascript'></script>\n\n</body>", $body);
  79. $body = str_ireplace('src="//', 'src="https://', $body);
  80. $body = str_ireplace('src="/', 'src="'.$domain.'/', $body);
  81. $body = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $body);
  82. $body = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $body);
  83. //$body = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $body);
  84. //$body = str_ireplace('src="js/', 'src="'.$domain.'/js/', $body);
  85. //$body = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $body);
  86. $body = str_ireplace('href="//', 'href="https://', $body);
  87. $body = str_ireplace('href="/', 'href="'.$domain.'/', $body);
  88. $body = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $body);
  89. $body = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $body);
  90. //$body = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $body);
  91. $body = preg_replace('/href="(.+)"/iU', "href=\"".APP_HOST."/surf.php?url=$1\"", $body);
  92. $w = $head . $body;
  93. echo($w);
  94. ?>