/admin228c4ef56/filemanager/execute.php

https://gitlab.com/staging06/myproject · PHP · 207 lines · 194 code · 13 blank · 0 comment · 83 complexity · 1234f304fd4e6d80aa64523e48228591 MD5 · raw file

  1. <?php
  2. include('config/config.php');
  3. if ($_SESSION['verify'] != 'RESPONSIVEfilemanager') {
  4. die('forbiden');
  5. }
  6. include('include/utils.php');
  7. $_POST['path_thumb'] = $thumbs_base_path.$_POST['path_thumb'];
  8. if (!isset($_POST['path_thumb']) && trim($_POST['path_thumb']) == '') {
  9. die('wrong path');
  10. }
  11. $thumb_pos = strpos($_POST['path_thumb'], $thumbs_base_path);
  12. if ($thumb_pos === false
  13. || preg_match('/\.{1,2}[\/|\\\]/', $_POST['path_thumb']) !== 0
  14. || preg_match('/\.{1,2}[\/|\\\]/', $_POST['path']) !== 0
  15. ) {
  16. die('wrong path');
  17. }
  18. $language_file = 'lang/en.php';
  19. if (isset($_GET['lang']) && $_GET['lang'] != 'undefined' && $_GET['lang'] != '') {
  20. $path_parts = pathinfo($_GET['lang']);
  21. if (is_readable('lang/'.$path_parts['basename'].'.php')) {
  22. $language_file = 'lang/'.$path_parts['basename'].'.php';
  23. }
  24. }
  25. require_once $language_file;
  26. $base = $current_path;
  27. if (isset($_POST['path'])) {
  28. $path = $current_path.str_replace("\0", "", $_POST['path']);
  29. } else {
  30. $path = $current_path;
  31. }
  32. $cycle = true;
  33. $max_cycles = 50;
  34. $i = 0;
  35. while ($cycle && $i < $max_cycles) {
  36. $i++;
  37. if ($path == $base) {
  38. $cycle = false;
  39. }
  40. if (file_exists($path.'config.php')) {
  41. require_once($path.'config.php');
  42. $cycle = false;
  43. }
  44. $path = fix_dirname($path).'/';
  45. $cycle = false;
  46. }
  47. $path = $current_path.str_replace("\0", "", $_POST['path']);
  48. $path_thumb = $_POST['path_thumb'];
  49. if (isset($_POST['name'])) {
  50. $name = $_POST['name'];
  51. if (preg_match('/\.{1,2}[\/|\\\]/', $name) !== 0) {
  52. die('wrong name');
  53. }
  54. }
  55. $info = pathinfo($path);
  56. if (isset($info['extension']) && !(isset($_GET['action']) && $_GET['action'] == 'delete_folder') && !in_array(strtolower($info['extension']), $ext)) {
  57. die('wrong extension');
  58. }
  59. if (isset($_GET['action'])) {
  60. switch ($_GET['action']) {
  61. case 'delete_file':
  62. if ($delete_files) {
  63. unlink($path);
  64. if (file_exists($path_thumb)) {
  65. unlink($path_thumb);
  66. }
  67. $info = pathinfo($path);
  68. if ($relative_image_creation) {
  69. foreach ($relative_path_from_current_pos as $k => $path) {
  70. if ($path != '' && $path[strlen($path) - 1] != '/') {
  71. $path .= '/';
  72. }
  73. if (file_exists($info['dirname'].'/'.$path.$relative_image_creation_name_to_prepend[$k].$info['filename'].$relative_image_creation_name_to_append[$k].'.'.$info['extension'])) {
  74. unlink($info['dirname'].'/'.$path.$relative_image_creation_name_to_prepend[$k].$info['filename'].$relative_image_creation_name_to_append[$k].'.'.$info['extension']);
  75. }
  76. }
  77. }
  78. if ($fixed_image_creation) {
  79. foreach ($fixed_path_from_filemanager as $k => $path) {
  80. if ($path != '' && $path[strlen($path) - 1] != '/') {
  81. $path .= '/';
  82. }
  83. $base_dir = $path.substr_replace($info['dirname'].'/', '', 0, strlen($current_path));
  84. if (file_exists($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension'])) {
  85. unlink($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension']);
  86. }
  87. }
  88. }
  89. }
  90. break;
  91. case 'delete_folder':
  92. if ($delete_folders) {
  93. if (is_dir($path_thumb)) {
  94. deleteDir($path_thumb);
  95. }
  96. if (is_dir($path)) {
  97. deleteDir($path);
  98. if ($fixed_image_creation) {
  99. foreach ($fixed_path_from_filemanager as $k => $paths) {
  100. if ($paths != '' && $paths[strlen($paths) - 1] != '/') {
  101. $paths .= '/';
  102. }
  103. $base_dir = $paths.substr_replace($path, '', 0, strlen($current_path));
  104. if (is_dir($base_dir)) {
  105. deleteDir($base_dir);
  106. }
  107. }
  108. }
  109. }
  110. }
  111. break;
  112. case 'create_folder':
  113. if ($create_folders) {
  114. create_folder(fix_path($path, $transliteration), fix_path($path_thumb, $transliteration));
  115. }
  116. break;
  117. case 'rename_folder':
  118. if ($rename_folders) {
  119. $name = fix_filename($name, $transliteration);
  120. $name = str_replace('.', '', $name);
  121. if (!empty($name)) {
  122. if (!rename_folder($path, $name, $transliteration)) {
  123. die(lang_Rename_existing_folder);
  124. }
  125. rename_folder($path_thumb, $name, $transliteration);
  126. if ($fixed_image_creation) {
  127. foreach ($fixed_path_from_filemanager as $k => $paths) {
  128. if ($paths != '' && $paths[strlen($paths) - 1] != '/') {
  129. $paths .= '/';
  130. }
  131. $base_dir = $paths.substr_replace($path, '', 0, strlen($current_path));
  132. rename_folder($base_dir, $name, $transliteration);
  133. }
  134. }
  135. } else {
  136. die(lang_Empty_name);
  137. }
  138. }
  139. break;
  140. case 'rename_file':
  141. if ($rename_files) {
  142. $name = fix_filename($name, $transliteration);
  143. if (!empty($name)) {
  144. if (!rename_file($path, $name, $transliteration)) {
  145. die(lang_Rename_existing_file);
  146. }
  147. rename_file($path_thumb, $name, $transliteration);
  148. if ($fixed_image_creation) {
  149. $info = pathinfo($path);
  150. foreach ($fixed_path_from_filemanager as $k => $paths) {
  151. if ($paths != '' && $paths[strlen($paths) - 1] != '/') {
  152. $paths .= '/';
  153. }
  154. $base_dir = $paths.substr_replace($info['dirname'].'/', '', 0, strlen($current_path));
  155. if (file_exists($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension'])) {
  156. rename_file($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension'], $fixed_image_creation_name_to_prepend[$k].$name.$fixed_image_creation_to_append[$k], $transliteration);
  157. }
  158. }
  159. }
  160. } else {
  161. die(lang_Empty_name);
  162. }
  163. }
  164. break;
  165. case 'duplicate_file':
  166. if ($duplicate_files) {
  167. $name = fix_filename($name, $transliteration);
  168. if (!empty($name)) {
  169. if (!duplicate_file($path, $name)) {
  170. die(lang_Rename_existing_file);
  171. }
  172. duplicate_file($path_thumb, $name);
  173. if ($fixed_image_creation) {
  174. $info = pathinfo($path);
  175. foreach ($fixed_path_from_filemanager as $k => $paths) {
  176. if ($paths != '' && $paths[strlen($paths) - 1] != '/') {
  177. $paths .= '/';
  178. }
  179. $base_dir = $paths.substr_replace($info['dirname'].'/', '', 0, strlen($current_path));
  180. if (file_exists($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension'])) {
  181. duplicate_file($base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].'.'.$info['extension'], $fixed_image_creation_name_to_prepend[$k].$name.$fixed_image_creation_to_append[$k]);
  182. }
  183. }
  184. }
  185. } else {
  186. die(lang_Empty_name);
  187. }
  188. }
  189. break;
  190. default:
  191. die('wrong action');
  192. break;
  193. }
  194. }