surf.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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, "miourl")??"";
  30. $url = strip_tags($url);
  31. //echo($url."<br>");
  32. if ($url == "") {
  33. echo "<p>404 LightOff url doesn't exist.</p>\n";
  34. exit;
  35. }
  36. if (substr($url, 0, 4) === "http") {
  37. $ipos = stripos($url, "/", 8);
  38. if ($ipos) {
  39. $domain = substr($url, 0, $ipos);
  40. } else {
  41. $domain = $url;
  42. }
  43. } else {
  44. $domain = stripos($url, "/");
  45. if ($ipos) {
  46. $domain = "http://" . substr($url, 0, $ipos);
  47. } else {
  48. $domain = "http://" . $url;
  49. }
  50. }
  51. //echo($domain."<br>");
  52. // xxx
  53. if (mb_stripos($url, "?") === false) {
  54. $url = $url . "?miot=t";
  55. }
  56. foreach($_GET as $key=>$val) {
  57. if ($key !== "miourl") {
  58. $url = $url . "&$key=" . urlencode($val);
  59. }
  60. }
  61. // end xxx
  62. $file = fopen($url, "r");
  63. if (!$file) {
  64. echo "<p>404 LightOff url doesn't exist.</p>\n";
  65. exit;
  66. }
  67. $w = "";
  68. while (!feof($file)) {
  69. $w .= fgets($file, 20000);
  70. }
  71. fclose($file);
  72. $ipos = stripos($w, "</head>");
  73. $head = substr($w, 0, $ipos + 7);
  74. $body = substr($w, $ipos + 7);
  75. $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);
  76. if (mb_stripos($head, "<base") === false ) {
  77. $head = str_ireplace("</head>", "<base href='$domain/'>\n</head>", $head);
  78. }
  79. $head = str_ireplace('src="//', 'src="https://', $head);
  80. $head = str_ireplace('src="/', 'src="'.$domain.'/', $head);
  81. $head = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $head);
  82. $head = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $head);
  83. //$head = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $head);
  84. //$head = str_ireplace('src="js/', 'src="'.$domain.'/js/', $head);
  85. //$head = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $head);
  86. $head = str_ireplace('href="//', 'href="https://', $head);
  87. $head = str_ireplace('href="/', 'href="'.$domain.'/', $head);
  88. $head = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $head);
  89. $head = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $head);
  90. //$head = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $head);
  91. //$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);
  92. //$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);
  93. $body = str_ireplace("</body>", "\n\n<script src='".APP_HOST."/js/surf.js' type='text/javascript'></script>\n\n</body>", $body);
  94. $body = str_ireplace('src="//', 'src="https://', $body);
  95. $body = str_ireplace('src="/', 'src="'.$domain.'/', $body);
  96. $body = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $body);
  97. $body = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $body);
  98. //$body = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $body);
  99. //$body = str_ireplace('src="js/', 'src="'.$domain.'/js/', $body);
  100. //$body = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $body);
  101. $body = str_ireplace('href="//', 'href="https://', $body);
  102. $body = str_ireplace('href="/', 'href="'.$domain.'/', $body);
  103. $body = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $body);
  104. $body = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $body);
  105. //$body = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $body);
  106. //$body = str_ireplace('action="//', 'action="'.APP_HOST.'/surf.php?url=https://', $body);
  107. //$body = str_ireplace('action="/', 'action="'.APP_HOST.'/surf.php?url='.$domain.'/', $body);
  108. //$body = str_ireplace('action="//', 'action="https://', $body);
  109. //$body = str_ireplace('action="/', 'action="'.$domain.'/', $body);
  110. $body = str_ireplace('action="https://', 'action="'.APP_HOST.'/post.php?miourl=https://', $body);
  111. $body = str_ireplace('action="//', 'action="'.APP_HOST.'/post.php?miourl=https://', $body);
  112. $body = str_ireplace('action="/', 'action="'.APP_HOST.'/post.php?miourl='.$domain.'/', $body);
  113. $body = preg_replace('/action="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "action=\"".APP_HOST."/post.php?miourl=".$domain."/$1\"", $body);
  114. $body = preg_replace("/action='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "action='".APP_HOST."/post.php?miourl=".$domain."/$1'", $body);
  115. $body = str_ireplace('<form', '<form method="POST"', $body);
  116. $body = str_ireplace('method="GET', 'method="POST', $body);
  117. //$body = str_ireplace('</form>', "<input name=\"miourl\" type=\"hidden\"></form>", $body);
  118. //YAHOO
  119. if ((mb_stripos($url, "yahoo.it")!==false) || (mb_stripos($url, "yahoo.com")!==false)) {
  120. $ipos = mb_stripos($body, '<div id="doc"');
  121. if ($ipos !== false) {
  122. $body = substr($body,$ipos);
  123. }
  124. }
  125. $body = preg_replace('/href="(.+)"/iU', "href=\"".APP_HOST."/surf.php?miourl=$1\"", $body);
  126. $w = $head . $body;
  127. echo($w);
  128. //YAHOO
  129. if (mb_stripos($miourl, "yahoo.it")!==false) {
  130. // echo("<div style='clear:both'>&nbsp;</div><br><br><br><br><br><br><br><br><br>");
  131. }
  132. ?>