1 |
238
|
stefan
|
<?php
|
2 |
1400
|
FrankH
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package admintools
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
|
|
* @requirements PHP 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL: $
|
15 |
|
|
* @lastmodified $Date: $
|
16 |
|
|
*
|
17 |
|
|
*/
|
18 |
238
|
stefan
|
|
19 |
|
|
// Create admin object
|
20 |
|
|
require('../../config.php');
|
21 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
22 |
|
|
$admin = new admin('Media', 'media_rename', false);
|
23 |
|
|
|
24 |
|
|
// Include the WB functions file
|
25 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
26 |
|
|
|
27 |
|
|
// Get the current dir
|
28 |
1457
|
Luisehahne
|
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
29 |
|
|
$directory = (isset(${$requestMethod}['dir'])) ? ${$requestMethod}['dir'] : '';
|
30 |
1475
|
Luisehahne
|
$directory = ($directory == '/') ? '' : $directory;
|
31 |
1400
|
FrankH
|
|
32 |
1475
|
Luisehahne
|
$dirlink = 'browse.php?dir='.$directory;
|
33 |
|
|
$rootlink = 'browse.php?dir=';
|
34 |
|
|
// $file_id = intval($admin->get_post('id'));
|
35 |
|
|
|
36 |
|
|
// first Check to see if it contains ..
|
37 |
1400
|
FrankH
|
if (!check_media_path($directory)) {
|
38 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],$rootlink, false);
|
39 |
238
|
stefan
|
}
|
40 |
|
|
|
41 |
|
|
// Get the temp id
|
42 |
1475
|
Luisehahne
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
43 |
1400
|
FrankH
|
if (!$file_id) {
|
44 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
|
45 |
238
|
stefan
|
}
|
46 |
|
|
|
47 |
1475
|
Luisehahne
|
// Check for potentially malicious files and append 'txt' to their name
|
48 |
|
|
$rename_file_types = str_replace(',','|',RENAME_FILES_ON_UPLOAD);
|
49 |
|
|
// hardcodet forbidden filetypes
|
50 |
|
|
$forbidden_file_types = 'phtml|php5|php4|php|cgi|pl|exe|com|bat|src|'.$rename_file_types;
|
51 |
238
|
stefan
|
// Get home folder not to show
|
52 |
|
|
$home_folders = get_home_folders();
|
53 |
|
|
|
54 |
|
|
// Figure out what folder name the temp id is
|
55 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
56 |
|
|
// Loop through the files and dirs an add to list
|
57 |
|
|
while (false !== ($file = readdir($handle))) {
|
58 |
1475
|
Luisehahne
|
$info = pathinfo($file);
|
59 |
|
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
60 |
238
|
stefan
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
61 |
1475
|
Luisehahne
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
62 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
63 |
|
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
64 |
|
|
$DIR[] = $file;
|
65 |
|
|
}
|
66 |
|
|
} else {
|
67 |
|
|
$FILE[] = $file;
|
68 |
238
|
stefan
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
$temp_id = 0;
|
73 |
|
|
if(isset($DIR)) {
|
74 |
384
|
Ruebenwurz
|
sort($DIR);
|
75 |
238
|
stefan
|
foreach($DIR AS $name) {
|
76 |
|
|
$temp_id++;
|
77 |
|
|
if($file_id == $temp_id) {
|
78 |
|
|
$rename_file = $name;
|
79 |
|
|
$type = 'folder';
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
if(isset($FILE)) {
|
84 |
384
|
Ruebenwurz
|
sort($FILE);
|
85 |
238
|
stefan
|
foreach($FILE AS $name) {
|
86 |
|
|
$temp_id++;
|
87 |
|
|
if($file_id == $temp_id) {
|
88 |
|
|
$rename_file = $name;
|
89 |
|
|
$type = 'file';
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
1475
|
Luisehahne
|
|
95 |
1457
|
Luisehahne
|
$file_id = $admin->getIDKEY($file_id);
|
96 |
1475
|
Luisehahne
|
|
97 |
238
|
stefan
|
if(!isset($rename_file)) {
|
98 |
1475
|
Luisehahne
|
$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], $dirlink, false);
|
99 |
238
|
stefan
|
}
|
100 |
|
|
|
101 |
|
|
// Check if they entered a new name
|
102 |
|
|
if(media_filename($admin->get_post('name')) == "") {
|
103 |
|
|
$admin->print_error($MESSAGE['MEDIA']['BLANK_NAME'], "rename.php?dir=$directory&id=$file_id", false);
|
104 |
|
|
} else {
|
105 |
|
|
$old_name = $admin->get_post('old_name');
|
106 |
|
|
$new_name = media_filename($admin->get_post('name'));
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
// Check if they entered an extension
|
110 |
|
|
if($type == 'file') {
|
111 |
|
|
if(media_filename($admin->get_post('extension')) == "") {
|
112 |
|
|
$admin->print_error($MESSAGE['MEDIA']['BLANK_EXTENSION'], "rename.php?dir=$directory&id=$file_id", false);
|
113 |
|
|
} else {
|
114 |
|
|
$extension = media_filename($admin->get_post('extension'));
|
115 |
|
|
}
|
116 |
|
|
} else {
|
117 |
|
|
$extension = '';
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// Join new name and extension
|
121 |
|
|
$name = $new_name.$extension;
|
122 |
|
|
|
123 |
1475
|
Luisehahne
|
$info = pathinfo(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
124 |
|
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
125 |
|
|
$dots = (substr($info['basename'], 0, 1) == '.') || (substr($info['basename'], -1, 1) == '.');
|
126 |
|
|
|
127 |
|
|
if( preg_match('/'.$forbidden_file_types.'$/i', $ext) || $dots == '.' ) {
|
128 |
|
|
$admin->print_error($MESSAGE['MEDIA']['CANNOT_RENAME'], "rename.php?dir=$directory&id=$file_id", false);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
238
|
stefan
|
// Check if the name contains ..
|
132 |
|
|
if(strstr($name, '..')) {
|
133 |
|
|
$admin->print_error($MESSAGE['MEDIA']['NAME_DOT_DOT_SLASH'], "rename.php?dir=$directory&id=$file_id", false);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
// Check if the name is index.php
|
137 |
|
|
if($name == 'index.php') {
|
138 |
|
|
$admin->print_error($MESSAGE['MEDIA']['NAME_INDEX_PHP'], "rename.php?dir=$directory&id=$file_id", false);
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
// Check that the name still has a value
|
142 |
|
|
if($name == '') {
|
143 |
|
|
$admin->print_error($MESSAGE['MEDIA']['BLANK_NAME'], "rename.php?dir=$directory&id=$file_id", false);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
1475
|
Luisehahne
|
$info = pathinfo(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file);
|
147 |
|
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
148 |
|
|
$dots = (substr($info['basename'], 0, 1) == '.') || (substr($info['basename'], -1, 1) == '.');
|
149 |
238
|
stefan
|
|
150 |
1475
|
Luisehahne
|
if( preg_match('/'.$forbidden_file_types.'$/i', $ext) || $dots == '.' ) {
|
151 |
|
|
$admin->print_error($MESSAGE['MEDIA']['CANNOT_RENAME'], "rename.php?dir=$directory&id=$file_id", false);
|
152 |
|
|
}
|
153 |
238
|
stefan
|
|
154 |
|
|
// Check if we should overwrite or not
|
155 |
|
|
if($admin->get_post('overwrite') != 'yes' AND file_exists(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name) == true) {
|
156 |
|
|
if($type == 'folder') {
|
157 |
|
|
$admin->print_error($MESSAGE['MEDIA']['DIR_EXISTS'], "rename.php?dir=$directory&id=$file_id", false);
|
158 |
|
|
} else {
|
159 |
|
|
$admin->print_error($MESSAGE['MEDIA']['FILE_EXISTS'], "rename.php?dir=$directory&id=$file_id", false);
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
// Try and rename the file/folder
|
164 |
|
|
if(rename(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file, WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)) {
|
165 |
1457
|
Luisehahne
|
$usedFiles = array();
|
166 |
|
|
// feature freeze
|
167 |
|
|
// require_once(ADMIN_PATH.'/media/dse.php');
|
168 |
|
|
|
169 |
1475
|
Luisehahne
|
$admin->print_success($MESSAGE['MEDIA']['RENAMED'], $dirlink);
|
170 |
238
|
stefan
|
} else {
|
171 |
|
|
$admin->print_error($MESSAGE['MEDIA']['CANNOT_RENAME'], "rename.php?dir=$directory&id=$file_id", false);
|
172 |
|
|
}
|