surf.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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")??"";
  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. $file = fopen($url, "r");
  53. if (!$file) {
  54. echo "<p>404 LightOff url doesn't exist.</p>\n";
  55. exit;
  56. }
  57. $w = "";
  58. while (!feof($file)) {
  59. $w .= fgets($file, 20000);
  60. }
  61. fclose($file);
  62. $ipos = stripos($w, "</head>");
  63. $head = substr($w, 0, $ipos + 7);
  64. $body = substr($w, $ipos + 7);
  65. $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);
  66. if (mb_stripos($head, "<base") === false ) {
  67. $head = str_ireplace("</head>", "<base href='$domain/'>\n</head>", $head);
  68. }
  69. $head = str_ireplace('src="//', 'src="https://', $head);
  70. $head = str_ireplace('src="/', 'src="'.$domain.'/', $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 = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $head);
  74. //$head = str_ireplace('src="js/', 'src="'.$domain.'/js/', $head);
  75. //$head = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $head);
  76. $head = str_ireplace('href="//', 'href="https://', $head);
  77. $head = str_ireplace('href="/', 'href="'.$domain.'/', $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. //$head = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $head);
  81. //$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);
  82. //$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);
  83. $body = str_ireplace("</body>", "\n\n<script src='".APP_HOST."/js/surf.js' type='text/javascript'></script>\n\n</body>", $body);
  84. $body = str_ireplace('src="//', 'src="https://', $body);
  85. $body = str_ireplace('src="/', 'src="'.$domain.'/', $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 = preg_replace("/src=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "src='".$domain."/$1'", $body);
  89. //$body = str_ireplace('src="js/', 'src="'.$domain.'/js/', $body);
  90. //$body = str_ireplace('src="/js/', 'src="'.$domain.'/js/', $body);
  91. $body = str_ireplace('href="//', 'href="https://', $body);
  92. $body = str_ireplace('href="/', 'href="'.$domain.'/', $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 = preg_replace("/href=(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)/iU", "href='".$domain."/$1'", $body);
  96. $body = str_ireplace('action="//', 'action="'.APP_HOST.'/surf.php?url=https://', $body);
  97. $body = str_ireplace('action="/', 'action="'.APP_HOST.'/surf.php?url='.$domain.'/', $body);
  98. $body = preg_replace('/action="(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)"/iU', "action=\"".APP_HOST."/surf.php?url=".$domain."/$1\"", $body);
  99. $body = preg_replace("/action='(.{6}(?<!http:\/)(?<!https:)(?<!ftp:\/\/).+)'/iU", "action='".APP_HOST."/surf.php?url=".$domain."/$1'", $body);
  100. $body = preg_replace('/href="(.+)"/iU', "href=\"".APP_HOST."/surf.php?url=$1\"", $body);
  101. $w = $head . $body;
  102. echo($w);
  103. ?>