index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Copyright (c) 2016, 2024, 5 Mode
  4. *
  5. * This file is part of FoatingBuds.
  6. *
  7. * FoatingBuds 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. * FoatingBuds 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 FoatingBuds. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * index.php
  21. *
  22. * FoatingBuds index file.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. require "../Private/core/init.inc";
  28. // FUNCTION AND VARIABLE DECLARATIONS
  29. $scriptPath = APP_SCRIPT_PATH;
  30. // PARAMETERS VALIDATION
  31. $url = filter_input(INPUT_GET, "url")??"";
  32. $url = strip_tags($url);
  33. $url = strtolower(trim(substr($url, 0, 300), "/"));
  34. switch ($url) {
  35. case "action":
  36. $scriptPath = APP_AJAX_PATH;
  37. define("SCRIPT_NAME", "action");
  38. define("SCRIPT_FILENAME", "action.php");
  39. break;
  40. case "":
  41. case "home":
  42. if (defined("APP_HOME_PATH") && (APP_HOME_PATH !== PHP_STR) && is_readable(APP_HOME_PATH)) {
  43. define("SCRIPT_NAME", "homeproxy");
  44. define("SCRIPT_FILENAME", "homeproxy.php");
  45. } else {
  46. # define("SCRIPT_NAME", "home");
  47. # define("SCRIPT_FILENAME", "home.php");
  48. #
  49. # $pattern = APP_DATA_PATH . DIRECTORY_SEPARATOR . "*";
  50. # $aAvatarPaths = glob($pattern, GLOB_ONLYDIR);
  51. # if (empty($aAvatarPaths)) {
  52. # die("<br>&nbsp;No chat exists yet: type in the url with your chat uri like http://" . $_SERVER['HTTP_HOST']. "/&lt;your chat&gt;.<br>&nbsp;");
  53. # } else {
  54. # define("BUD_NAME", basename($aAvatarPaths[0]));
  55. # }
  56. die("<br>&nbsp;You have to define an homepage.<br>&nbsp;");
  57. }
  58. break;
  59. case "doc":
  60. $avatar = filter_input(INPUT_GET, "av")??"";
  61. $avatar = strip_tags($avatar);
  62. $BUD_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  63. $repo = filter_input(INPUT_GET, "re")??"";
  64. $repo = strip_tags($repo);
  65. switch ($repo) {
  66. case "cv":
  67. $REPO_PATH = $BUD_PATH . DIRECTORY_SEPARATOR . "cv";
  68. break;
  69. default:
  70. die("unknown parma value:".$repo);
  71. }
  72. $doc = filter_input(INPUT_GET, "doc")??"";
  73. $doc = strip_tags($doc);
  74. $originalFilename = pathinfo($doc, PATHINFO_FILENAME);
  75. $destFilename = explode("|",$originalFilename)[1];
  76. $originalFileExt = pathinfo($doc, PATHINFO_EXTENSION);
  77. $fileExt = strtolower(pathinfo($doc, PATHINFO_EXTENSION));
  78. $docPath = $REPO_PATH . DIRECTORY_SEPARATOR . $doc;
  79. if (filesize($docPath) <= APP_FILE_MAX_SIZE) {
  80. switch ($fileExt) {
  81. case "doc":
  82. header("Content-Type: application/msword");
  83. header('Content-Disposition: attachment; filename=' . $destFilename . '.doc');
  84. break;
  85. case "pdf":
  86. header("Content-Type: application/pdf");
  87. header('Content-Disposition: attachment; filename=' . $destFilename . '.pdf');
  88. break;
  89. default:
  90. die("unknown file extension.");
  91. }
  92. echo(file_get_contents($docPath));
  93. exit(0);
  94. } else {
  95. die("doc size over app limits.");
  96. }
  97. break;
  98. case "img":
  99. $avatar = filter_input(INPUT_GET, "av")??"";
  100. $avatar = strip_tags($avatar);
  101. $BUD_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  102. $GALLERY_PATH = $BUD_PATH . DIRECTORY_SEPARATOR . "gallery";
  103. $pic = filter_input(INPUT_GET, "pic")??"";
  104. $pic = strip_tags($pic);
  105. $originalFilename = pathinfo($pic, PATHINFO_FILENAME);
  106. $originalFileExt = pathinfo($pic, PATHINFO_EXTENSION);
  107. $fileExt = strtolower(pathinfo($pic, PATHINFO_EXTENSION));
  108. if ($pic === APP_DEF_PROFILE_PIC) {
  109. $picPath = APP_PATH . DIRECTORY_SEPARATOR . "static" . $pic;
  110. } else {
  111. $picPath = $GALLERY_PATH . DIRECTORY_SEPARATOR . $pic;
  112. }
  113. if (filesize($picPath) <= APP_FILE_MAX_SIZE) {
  114. if ($fileExt === "jpg") {
  115. header("Content-Type: image/jpeg");
  116. } else {
  117. header("Content-Type: image/" . $fileExt);
  118. }
  119. echo(file_get_contents($picPath));
  120. exit(0);
  121. } else {
  122. die("picture size over app limits.");
  123. }
  124. break;
  125. case "imgj":
  126. $avatar = filter_input(INPUT_GET, "av")??"";
  127. $avatar = strip_tags($avatar);
  128. $jar = (int)substr(strip_tags(filter_input(INPUT_GET, "jar")??""),0,1);
  129. if ($jar >= 1 && $jar <= 3) {
  130. } else {
  131. die("jar parameter error.");
  132. }
  133. $BUD_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  134. $JAR_PATH = $BUD_PATH . DIRECTORY_SEPARATOR . "magicjar" . $jar;
  135. $fileName = filter_input(INPUT_GET, "fn")??"";
  136. $fileName = strip_tags($fileName);
  137. $originalFilename = pathinfo($fileName, PATHINFO_FILENAME);
  138. $orioriFilename = explode("|", $originalFilename)[1];
  139. $originalFileExt = pathinfo($fileName, PATHINFO_EXTENSION);
  140. $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  141. $filePath = $JAR_PATH . DIRECTORY_SEPARATOR . $fileName;
  142. if (filesize($filePath) <= APP_FILE_MAX_SIZE) {
  143. if ($fileExt === "jpg") {
  144. header("Content-Type: image/jpeg");
  145. } else {
  146. header("Content-Type: image/" . $fileExt);
  147. }
  148. //header("Content-Disposition: attachment; filename=" . $orioriFilename . ".$fileExt");
  149. echo(file_get_contents($filePath));
  150. exit(0);
  151. } else {
  152. die("file size over app limits.");
  153. }
  154. break;
  155. case "file":
  156. $avatar = filter_input(INPUT_GET, "av")??"";
  157. $avatar = strip_tags($avatar);
  158. $jar = (int)substr(strip_tags(filter_input(INPUT_GET, "jar")??""),0,1);
  159. if ($jar >= 1 && $jar <= 3) {
  160. } else {
  161. die("jar parameter error.");
  162. }
  163. $BUD_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  164. $JAR_PATH = $BUD_PATH . DIRECTORY_SEPARATOR . "magicjar" . $jar;
  165. $fileName = filter_input(INPUT_GET, "fn")??"";
  166. $fileName = strip_tags($fileName);
  167. $originalFilename = pathinfo($fileName, PATHINFO_FILENAME);
  168. $orioriFilename = explode("|", $originalFilename)[1];
  169. $originalFileExt = pathinfo($fileName, PATHINFO_EXTENSION);
  170. $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  171. $filePath = $JAR_PATH . DIRECTORY_SEPARATOR . $fileName;
  172. if (filesize($filePath) <= APP_FILE_MAX_SIZE) {
  173. header("Content-Type: avatarfree/bin");
  174. header("Content-Disposition: attachment; filename=" . $orioriFilename . ".$fileExt");
  175. echo(file_get_contents($filePath));
  176. exit(0);
  177. } else {
  178. die("file size over app limits.");
  179. }
  180. break;
  181. default:
  182. define("SCRIPT_NAME", "home");
  183. define("SCRIPT_FILENAME", "home.php");
  184. define("BUD_NAME", $url);
  185. break;
  186. }
  187. if (SCRIPT_NAME==="err-404") {
  188. header("HTTP/1.1 404 Not Found");
  189. }
  190. require $scriptPath . "/" . SCRIPT_FILENAME;