surf.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 ($url == "") {
  32. echo "<p>404 LightOff url doesn't exist.</p>\n";
  33. exit;
  34. }
  35. if (substr($url, 0, 4) === "http") {
  36. $ipos = stripos($url, "/", 8);
  37. if ($ipos) {
  38. $domain = substr($url, 0, $ipos);
  39. } else {
  40. $domain = $url;
  41. }
  42. } else {
  43. $domain = stripos($url, "/");
  44. if ($ipos) {
  45. $domain = "http://" . substr($url, 0, $ipos);
  46. } else {
  47. $domain = "http://" . $url;
  48. }
  49. }
  50. //echo($domain."<br>");
  51. $file = fopen($url, "r");
  52. if (!$file) {
  53. echo "<p>404 LightOff url doesn't exist.</p>\n";
  54. exit;
  55. }
  56. $w = "";
  57. while (!feof($file)) {
  58. $w .= fgets($file, 20000);
  59. }
  60. fclose($file);
  61. $ipos = stripos($w, "</head>");
  62. $head = substr($w, 0, $ipos + 7);
  63. $body = substr($w, $ipos + 7);
  64. $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);
  65. if (mb_stripos($head, "<base") === false ) {
  66. $head = str_ireplace("</head>", "<base href='$domain/'>\n</head>", $head);
  67. }
  68. $head = str_ireplace('src="//', 'src="https://', $head);
  69. $head = str_ireplace('src="/', 'src="'.$domain.'/', $head);
  70. $head = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $head);
  71. $head = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $head);
  72. //$head = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $head);
  73. //$head = str_ireplace('src="js/', 'src="'.$domain.'/js/', $head);
  74. //$head = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $head);
  75. $head = str_ireplace('href="//', 'href="https://', $head);
  76. $head = str_ireplace('href="/', 'href="'.$domain.'/', $head);
  77. $head = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $head);
  78. $head = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $head);
  79. //$head = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $head);
  80. //$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);
  81. //$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);
  82. $body = str_ireplace("</body>", "\n\n<script src='".APP_HOST."/js/surf.js' type='text/javascript'></script>\n\n</body>", $body);
  83. $body = str_ireplace('src="//', 'src="https://', $body);
  84. $body = str_ireplace('src="/', 'src="'.$domain.'/', $body);
  85. $body = preg_replace('/src="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "src=\"".$domain."/$1\"", $body);
  86. $body = preg_replace("/src='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "src='".$domain."/$1'", $body);
  87. //$body = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $body);
  88. //$body = str_ireplace('src="js/', 'src="'.$domain.'/js/', $body);
  89. //$body = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $body);
  90. $body = str_ireplace('href="//', 'href="https://', $body);
  91. $body = str_ireplace('href="/', 'href="'.$domain.'/', $body);
  92. $body = preg_replace('/href="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "href=\"".$domain."/$1\"", $body);
  93. $body = preg_replace("/href='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "href='".$domain."/$1'", $body);
  94. //$body = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $body);
  95. $body = str_ireplace('action="//', 'action="'.APP_HOST.'/surf.php?url=https://', $body);
  96. $body = str_ireplace('action="/', 'action="'.APP_HOST.'/surf.php?url='.$domain.'/', $body);
  97. $body = preg_replace('/action="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "action=\"".APP_HOST."/surf.php?url=".$domain."/$1\"", $body);
  98. $body = preg_replace("/action='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "action='".APP_HOST."/surf.php?url=".$domain."/$1'", $body);
  99. $body = preg_replace('/href="(.+)"/iU', "href=\"".APP_HOST."/surf.php?url=$1\"", $body);
  100. $w = $head . $body;
  101. echo($w);
  102. ?>