1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package media
|
6
|
* @author Ryan Djurovich (2004-2009), WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: rename2.php 2098 2014-02-11 01:37:03Z darkviper $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/rename2.php $
|
14
|
* @lastmodified $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
if(!defined('WB_URL'))
|
19
|
{
|
20
|
$config_file = realpath('../../config.php');
|
21
|
if(file_exists($config_file) && !defined('WB_URL'))
|
22
|
{
|
23
|
require($config_file);
|
24
|
}
|
25
|
}
|
26
|
//if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
27
|
$oTrans = Translate::getInstance();
|
28
|
$oTrans->enableAddon('admin\\media');
|
29
|
|
30
|
$admin = new admin('Media', 'media', false);
|
31
|
|
32
|
// Include the WB functions file
|
33
|
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
|
34
|
|
35
|
// Get the current dir
|
36
|
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
37
|
$directory = (isset(${$requestMethod}['dir'])) ? ${$requestMethod}['dir'] : '';
|
38
|
$directory = ($directory == '/') ? '' : $directory;
|
39
|
|
40
|
$dirlink = 'browse.php?dir='.$directory;
|
41
|
$rootlink = 'browse.php?dir=';
|
42
|
// $file_id = intval($admin->get_post('id'));
|
43
|
|
44
|
// Get the current dir
|
45
|
$currentHome = $admin->get_home_folder();
|
46
|
// check for correct directory
|
47
|
if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$rootlink,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
|
48
|
$rootlink = $currentHome;
|
49
|
}
|
50
|
|
51
|
// first Check to see if it contains ..
|
52
|
if (!check_media_path($directory)) {
|
53
|
$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_DOT_DOT_SLASH, $rootlink, false);
|
54
|
}
|
55
|
|
56
|
// Get the temp id
|
57
|
$file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']));
|
58
|
if (!$file_id) {
|
59
|
$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS, $dirlink, false);
|
60
|
}
|
61
|
|
62
|
// Check for potentially malicious files
|
63
|
$forbidden_file_types = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
|
64
|
// Get home folder not to show
|
65
|
$home_folders = get_home_folders();
|
66
|
|
67
|
// Figure out what folder name the temp id is
|
68
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
|
69
|
// Loop through the files and dirs an add to list
|
70
|
while (false !== ($file = readdir($handle))) {
|
71
|
$info = pathinfo($file);
|
72
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
73
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
74
|
if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
|
75
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
76
|
if(!isset($home_folders[$directory.'/'.$file])) {
|
77
|
$DIR[] = $file;
|
78
|
}
|
79
|
} else {
|
80
|
$FILE[] = $file;
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
$temp_id = 0;
|
86
|
if(isset($DIR)) {
|
87
|
sort($DIR);
|
88
|
foreach($DIR AS $name) {
|
89
|
$temp_id++;
|
90
|
if($file_id == $temp_id) {
|
91
|
$rename_file = $name;
|
92
|
$type = 'folder';
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
if(isset($FILE)) {
|
97
|
sort($FILE);
|
98
|
foreach($FILE AS $name) {
|
99
|
$temp_id++;
|
100
|
if($file_id == $temp_id) {
|
101
|
$rename_file = $name;
|
102
|
$type = 'file';
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
}
|
107
|
|
108
|
$file_id = $admin->getIDKEY($file_id);
|
109
|
|
110
|
if(!isset($rename_file)) {
|
111
|
$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_NOT_FOUND, $dirlink, false);
|
112
|
}
|
113
|
|
114
|
// Check if they entered a new name
|
115
|
if(media_filename($admin->get_post('name')) == "") {
|
116
|
$admin->print_error($oTrans->MESSAGE_MEDIA_BLANK_NAME, "rename.php?dir=$directory&id=$file_id", false);
|
117
|
} else {
|
118
|
$old_name = $admin->get_post('old_name');
|
119
|
$new_name = media_filename($admin->get_post('name'));
|
120
|
}
|
121
|
|
122
|
// Check if they entered an extension
|
123
|
if($type == 'file') {
|
124
|
if(media_filename($admin->get_post('extension')) == "") {
|
125
|
$admin->print_error($oTrans->MESSAGE_MEDIA_BLANK_EXTENSION, "rename.php?dir=$directory&id=$file_id", false);
|
126
|
} else {
|
127
|
$extension = media_filename($admin->get_post('extension'));
|
128
|
}
|
129
|
} else {
|
130
|
$extension = '';
|
131
|
}
|
132
|
|
133
|
// Join new name and extension
|
134
|
$name = $new_name.$extension;
|
135
|
|
136
|
$info = pathinfo(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name);
|
137
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
138
|
$dots = (substr($info['basename'], 0, 1) == '.') || (substr($info['basename'], -1, 1) == '.');
|
139
|
|
140
|
if( preg_match('/'.$forbidden_file_types.'$/i', $ext) || $dots == '.' ) {
|
141
|
$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_RENAME, "rename.php?dir=$directory&id=$file_id", false);
|
142
|
}
|
143
|
|
144
|
// Check if the name contains ..
|
145
|
if(strstr($name, '..')) {
|
146
|
$admin->print_error($oTrans->MESSAGE_MEDIA_NAME_DOT_DOT_SLASH, "rename.php?dir=$directory&id=$file_id", false);
|
147
|
}
|
148
|
|
149
|
// Check if the name is index.php
|
150
|
if($name == 'index.php') {
|
151
|
$admin->print_error($oTrans->MESSAGE_MEDIA_NAME_INDEX_PHP, "rename.php?dir=$directory&id=$file_id", false);
|
152
|
}
|
153
|
|
154
|
// Check that the name still has a value
|
155
|
if($name == '') {
|
156
|
$admin->print_error($oTrans->MESSAGE_MEDIA_BLANK_NAME, "rename.php?dir=$directory&id=$file_id", false);
|
157
|
}
|
158
|
|
159
|
$info = pathinfo(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file);
|
160
|
$ext = isset($info['extension']) ? $info['extension'] : '';
|
161
|
$dots = (substr($info['basename'], 0, 1) == '.') || (substr($info['basename'], -1, 1) == '.');
|
162
|
|
163
|
if( preg_match('/'.$forbidden_file_types.'$/i', $ext) || $dots == '.' ) {
|
164
|
$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_RENAME, "rename.php?dir=$directory&id=$file_id", false);
|
165
|
}
|
166
|
|
167
|
// Check if we should overwrite or not
|
168
|
if($admin->get_post('overwrite') != 'yes' AND file_exists(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name) == true) {
|
169
|
if($type == 'folder') {
|
170
|
$admin->print_error($oTrans->MESSAGE_MEDIA_DIR_EXISTS, "rename.php?dir=$directory&id=$file_id", false);
|
171
|
} else {
|
172
|
$admin->print_error($oTrans->MESSAGE_MEDIA_FILE_EXISTS, "rename.php?dir=$directory&id=$file_id", false);
|
173
|
}
|
174
|
}
|
175
|
|
176
|
// Try and rename the file/folder
|
177
|
if(rename(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file, WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)) {
|
178
|
$usedFiles = array();
|
179
|
// feature freeze
|
180
|
// require_once(ADMIN_PATH.'/media/dse.php');
|
181
|
|
182
|
$admin->print_success($oTrans->MESSAGE_MEDIA_RENAMED, $dirlink);
|
183
|
} else {
|
184
|
$admin->print_error($oTrans->MESSAGE_MEDIA_CANNOT_RENAME, "rename.php?dir=$directory&id=$file_id", false);
|
185
|
}
|