Project

General

Profile

1 4 ryan
<?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 4 ryan
19
// Print admin header
20
require('../../config.php');
21 1041 Ruebenwurz
include_once('resize_img.php');
22
include_once('parameters.php');
23
24 4 ryan
require_once(WB_PATH.'/framework/class.admin.php');
25 1023 Ruebenwurz
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');	// Required to unzip file.
26 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
27
$admin = new admin('Media', 'media_upload', false);
28 4 ryan
29 1457 Luisehahne
if( !$admin->checkFTAN() )
30 1400 FrankH
{
31 1457 Luisehahne
	$admin->print_header();
32
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
33 1400 FrankH
}
34 1457 Luisehahne
// After check print the header
35
$admin->print_header();
36 1400 FrankH
37 1457 Luisehahne
// Target location
38
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
39
$target = (isset(${$requestMethod}['target'])) ? ${$requestMethod}['target'] : '';
40
41 4 ryan
// Include the WB functions file
42
require_once(WB_PATH.'/framework/functions.php');
43
44
// Check to see if target contains ../
45 1425 Luisehahne
if (!check_media_path($target, false))
46
{
47 1457 Luisehahne
	$admin->print_error($MESSAGE['MEDIA']['TARGET_DOT_DOT_SLASH'] );
48 4 ryan
}
49
50
// Create relative path of the target location for the file
51
$relative = WB_PATH.$target.'/';
52 1102 ruud
$resizepath = str_replace(array('/',' '),'_',$target);
53 4 ryan
54
// Find out whether we should replace files or give an error
55
if($admin->get_post('overwrite') != '') {
56
	$overwrite = true;
57
} else {
58
	$overwrite = false;
59
}
60
61 61 stefan
// Get list of file types to which we're supposed to append 'txt'
62
$get_result=$database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name='rename_files_on_upload' LIMIT 1");
63
$file_extension_string='';
64
if ($get_result->numRows()>0) {
65
	$fetch_result=$get_result->fetchRow();
66
	$file_extension_string=$fetch_result['value'];
67
}
68
$file_extensions=explode(",",$file_extension_string);
69
70 4 ryan
// Loop through the files
71
$good_uploads = 0;
72
for($count = 1; $count <= 10; $count++) {
73
	// If file was upload to tmp
74
	if(isset($_FILES["file$count"]['name'])) {
75
		// Remove bad characters
76
		$filename = media_filename($_FILES["file$count"]['name']);
77
		// Check if there is still a filename left
78
		if($filename != '') {
79 61 stefan
			// Check for potentially malicious files and append 'txt' to their name
80
			foreach($file_extensions as $file_ext) {
81
				$file_ext_len=strlen($file_ext);
82
				if (substr($filename,-$file_ext_len)==$file_ext) {
83
					$filename.='.txt';
84
				}
85
			}
86 4 ryan
			// Move to relative path (in media folder)
87
			if(file_exists($relative.$filename) AND $overwrite == true) {
88
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
89
					$good_uploads++;
90
					// Chmod the uploaded file
91
					change_mode($relative.$filename, 'file');
92
				}
93
			} elseif(!file_exists($relative.$filename)) {
94
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
95
					$good_uploads++;
96
					// Chmod the uploaded file
97
					change_mode($relative.$filename);
98
				}
99
			}
100 1041 Ruebenwurz
101
			if(file_exists($relative.$filename)) {
102
				if ($pathsettings[$resizepath]['width'] || $pathsettings[$resizepath]['height'] ) {
103
					$rimg=new RESIZEIMAGE($relative.$filename);
104
					$rimg->resize_limitwh($pathsettings[$resizepath]['width'],$pathsettings[$resizepath]['height'],$relative.$filename);
105
					$rimg->close();
106
				}
107
			}
108
109 1023 Ruebenwurz
			// store file name of first file for possible unzip action
110
			if ($count == 1) {
111
				$filename1 = $relative . $filename;
112
			}
113 4 ryan
		}
114
	}
115
}
116
117 1023 Ruebenwurz
// If the user chose to unzip the first file, unzip into the current folder
118
if (isset($_POST['unzip']) && isset($filename1) && file_exists($filename1) ) {
119
	$archive = new PclZip($filename1);
120
	$list = $archive->extract(PCLZIP_OPT_PATH, $relative);
121
	if($list == 0) {
122
		// error while trying to extract the archive (most likely wrong format)
123
		$admin->print_error('UNABLE TO UNZIP FILE' . $archive -> errorInfo(true));
124
	}
125 1407 FrankH
126
	// rename executable files!
127
	foreach ($list as $val) {
128
		$fn = $val['filename'];
129
		$fnp = pathinfo($fn);
130
		if (isset($fnp['extension'])) {
131
			$fext = $fnp['extension'];
132
			if (in_array($fext, $file_extensions)) {
133
				rename($fn, $fn.".txt");
134
			}
135
		}
136
	}
137 1023 Ruebenwurz
}
138
139 4 ryan
if($good_uploads == 1) {
140 1457 Luisehahne
	$admin->print_success($good_uploads.' '.$MESSAGE['MEDIA']['SINGLE_UPLOADED'] );
141 1023 Ruebenwurz
	if (isset($_POST['delzip'])) {
142
		unlink($filename1);
143
	}
144 4 ryan
} else {
145 1457 Luisehahne
	$admin->print_success($good_uploads.' '.$MESSAGE['MEDIA']['UPLOADED'] );
146 4 ryan
}
147
148
// Print admin
149
$admin->print_footer();