PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/la/admin3120tsmcd/filemanager/execute.php

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