index.php 7.3 KB

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