index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 = strtolower(trim(substr(filter_input(INPUT_GET, "url", FILTER_SANITIZE_STRING), 0, 300), "/"));
  33. switch ($url) {
  34. case "action":
  35. $scriptPath = APP_AJAX_PATH;
  36. define("SCRIPT_NAME", "action");
  37. define("SCRIPT_FILENAME", "action.php");
  38. break;
  39. case "":
  40. case "home":
  41. define("SCRIPT_NAME", "home");
  42. define("SCRIPT_FILENAME", "home.php");
  43. $pattern = APP_DATA_PATH . DIRECTORY_SEPARATOR . "*";
  44. $aAvatarPaths = glob($pattern, GLOB_ONLYDIR);
  45. if (empty($aAvatarPaths)) {
  46. 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.");
  47. } else {
  48. define("AVATAR_NAME", basename($aAvatarPaths[0]));
  49. }
  50. break;
  51. case "doc":
  52. $avatar = filter_input(INPUT_GET, "av", FILTER_SANITIZE_STRING);
  53. $AVATAR_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  54. $repo = filter_input(INPUT_GET, "re", FILTER_SANITIZE_STRING);
  55. switch ($repo) {
  56. case "cv":
  57. $REPO_PATH = $AVATAR_PATH . DIRECTORY_SEPARATOR . "cv";
  58. break;
  59. default:
  60. die("unknown parma value:".$repo);
  61. }
  62. $doc = filter_input(INPUT_GET, "doc", FILTER_SANITIZE_STRING);
  63. $originalFilename = pathinfo($doc, PATHINFO_FILENAME);
  64. $destFilename = explode("|",$originalFilename)[1];
  65. $originalFileExt = pathinfo($doc, PATHINFO_EXTENSION);
  66. $fileExt = strtolower(pathinfo($doc, PATHINFO_EXTENSION));
  67. $docPath = $REPO_PATH . DIRECTORY_SEPARATOR . $doc;
  68. if (filesize($docPath) <= APP_FILE_MAX_SIZE) {
  69. switch ($fileExt) {
  70. case "doc":
  71. header("Content-Type: application/msword");
  72. header('Content-Disposition: attachment; filename=' . $destFilename . '.doc');
  73. break;
  74. case "pdf":
  75. header("Content-Type: application/pdf");
  76. header('Content-Disposition: attachment; filename=' . $destFilename . '.pdf');
  77. break;
  78. default:
  79. die("unknown file extension.");
  80. }
  81. echo(file_get_contents($docPath));
  82. exit(0);
  83. } else {
  84. die("doc size over app limits.");
  85. }
  86. break;
  87. case "img":
  88. $avatar = filter_input(INPUT_GET, "av", FILTER_SANITIZE_STRING);
  89. $AVATAR_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  90. $GALLERY_PATH = $AVATAR_PATH . DIRECTORY_SEPARATOR . "gallery";
  91. $pic = filter_input(INPUT_GET, "pic", FILTER_SANITIZE_STRING);
  92. $originalFilename = pathinfo($pic, PATHINFO_FILENAME);
  93. $originalFileExt = pathinfo($pic, PATHINFO_EXTENSION);
  94. $fileExt = strtolower(pathinfo($pic, PATHINFO_EXTENSION));
  95. if ($pic === APP_DEF_PROFILE_PIC) {
  96. $picPath = APP_PATH . DIRECTORY_SEPARATOR . "static" . $pic;
  97. } else {
  98. $picPath = $GALLERY_PATH . DIRECTORY_SEPARATOR . $pic;
  99. }
  100. if (filesize($picPath) <= APP_FILE_MAX_SIZE) {
  101. if ($fileExt = "jpg") {
  102. header("Content-Type: image/jpeg");
  103. } else {
  104. header("Content-Type: image/" . $fileExt);
  105. }
  106. echo(file_get_contents($picPath));
  107. exit(0);
  108. } else {
  109. die("picture size over app limits.");
  110. }
  111. break;
  112. case "imgj":
  113. $avatar = filter_input(INPUT_GET, "av", FILTER_SANITIZE_STRING);
  114. $jar = (int)substr(filter_input(INPUT_GET, "jar", FILTER_SANITIZE_STRING),0,1);
  115. if ($jar >= 1 && $jar <= 3) {
  116. } else {
  117. die("jar parameter error.");
  118. }
  119. $AVATAR_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  120. $JAR_PATH = $AVATAR_PATH . DIRECTORY_SEPARATOR . "magicjar" . $jar;
  121. $fileName = filter_input(INPUT_GET, "fn", FILTER_SANITIZE_STRING);
  122. $originalFilename = pathinfo($fileName, PATHINFO_FILENAME);
  123. $orioriFilename = explode("|", $originalFilename)[1];
  124. $originalFileExt = pathinfo($fileName, PATHINFO_EXTENSION);
  125. $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  126. $filePath = $JAR_PATH . DIRECTORY_SEPARATOR . $fileName;
  127. if (filesize($filePath) <= APP_FILE_MAX_SIZE) {
  128. if ($fileExt = "jpg") {
  129. header("Content-Type: image/jpeg");
  130. } else {
  131. header("Content-Type: image/" . $fileExt);
  132. }
  133. //header("Content-Disposition: attachment; filename=" . $orioriFilename . ".$fileExt");
  134. echo(file_get_contents($filePath));
  135. exit(0);
  136. } else {
  137. die("file size over app limits.");
  138. }
  139. break;
  140. case "file":
  141. $avatar = filter_input(INPUT_GET, "av", FILTER_SANITIZE_STRING);
  142. $jar = (int)substr(filter_input(INPUT_GET, "jar", FILTER_SANITIZE_STRING),0,1);
  143. if ($jar >= 1 && $jar <= 3) {
  144. } else {
  145. die("jar parameter error.");
  146. }
  147. $AVATAR_PATH = APP_DATA_PATH . DIRECTORY_SEPARATOR . $avatar;
  148. $JAR_PATH = $AVATAR_PATH . DIRECTORY_SEPARATOR . "magicjar" . $jar;
  149. $fileName = filter_input(INPUT_GET, "fn", FILTER_SANITIZE_STRING);
  150. $originalFilename = pathinfo($fileName, PATHINFO_FILENAME);
  151. $orioriFilename = explode("|", $originalFilename)[1];
  152. $originalFileExt = pathinfo($fileName, PATHINFO_EXTENSION);
  153. $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  154. $filePath = $JAR_PATH . DIRECTORY_SEPARATOR . $fileName;
  155. if (filesize($filePath) <= APP_FILE_MAX_SIZE) {
  156. header("Content-Type: avatarfree/bin");
  157. header("Content-Disposition: attachment; filename=" . $orioriFilename . ".$fileExt");
  158. echo(file_get_contents($filePath));
  159. exit(0);
  160. } else {
  161. die("file size over app limits.");
  162. }
  163. break;
  164. default:
  165. define("SCRIPT_NAME", "home");
  166. define("SCRIPT_FILENAME", "home.php");
  167. define("AVATAR_NAME", $url);
  168. break;
  169. }
  170. if (SCRIPT_NAME==="err-404") {
  171. header("HTTP/1.1 404 Not Found");
  172. }
  173. require $scriptPath . "/" . SCRIPT_FILENAME;