Project

General

Profile

1 1348 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7 1912 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1348 Luisehahne
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1348 Luisehahne
 * @version         $Id$
13 1912 Luisehahne
 * @filesource      $HeadURL$
14 1348 Luisehahne
 * @lastmodified    $Date$
15
 *
16
 */
17
18
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
19
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
20
21
// Find out if the user was view advanced options or not
22
$advanced = ($_POST['advanced'] == 'yes') ? '?advanced=yes' : '';
23
24
// Print admin header
25 1785 Luisehahne
//require('../../config.php');
26
//require_once(WB_PATH.'/framework/class.admin.php');
27
28
// Include config file
29
$config_file = realpath('../../config.php');
30
if(file_exists($config_file) && !defined('WB_URL'))
31
{
32
	require($config_file);
33
}
34
35
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
36
37 1767 Luisehahne
require_once(WB_PATH.'/framework/functions.php');
38 1348 Luisehahne
39 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
40 1348 Luisehahne
if($advanced == '')
41
{
42 1457 Luisehahne
	$admin = new admin('Settings', 'settings_basic',false);
43 1348 Luisehahne
} else {
44 1457 Luisehahne
	$admin = new admin('Settings', 'settings_advanced',false);
45 1348 Luisehahne
}
46
47 1425 Luisehahne
// Create a javascript back link
48
$js_back = ADMIN_URL.'/settings/index.php'.$advanced;
49 1355 FrankH
if( !$admin->checkFTAN() )
50
{
51 1457 Luisehahne
	$admin->print_header();
52 1425 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back );
53 1355 FrankH
}
54 1457 Luisehahne
// After check print the header
55
$admin->print_header();
56 1355 FrankH
57 1348 Luisehahne
// Ensure that the specified default email is formally valid
58
if(isset($_POST['server_email']))
59
{
60
	$_POST['server_email'] = strip_tags($_POST['server_email']);
61 1716 Luisehahne
//    // $pattern = '/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?\r/im';
62
//    $pattern = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,6}))$/';
63
//    if(false == preg_match($pattern, $_POST['server_email']))
64
	if(!$admin->validate_email($_POST['server_email']))
65 1348 Luisehahne
    {
66 1572 Luisehahne
		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'].
67 1348 Luisehahne
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
68
	}
69
}
70
71 1777 Luisehahne
if($admin->StripCodeFromText($admin->get_post('wbmailer_routine'))=='smtp') {
72 1572 Luisehahne
73 1777 Luisehahne
	$checkSmtpHost = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_host'))=='') ? false : true);
74
//	$checkSmtpHost = (isset($_POST['wbmailer_smtp_host']) && ($_POST['wbmailer_smtp_host']=='') ? false : true);
75
	$checkSmtpUser = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_username'))=='') ? false : true);
76
//	$checkSmtpUser = (isset($_POST['wbmailer_smtp_username']) && ($_POST['wbmailer_smtp_username']=='') ? false : true);
77
	$checkSmtpPassword = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_password'))=='') ? false : true);
78
//	$checkSmtpPassword = (isset($_POST['wbmailer_smtp_password']) && ($_POST['wbmailer_smtp_password']=='') ? false : true);
79
80 1572 Luisehahne
	if(!$checkSmtpHost || !$checkSmtpUser || !$checkSmtpPassword) {
81
		$admin->print_error($TEXT['REQUIRED'].' '.$TEXT['WBMAILER_SMTP_AUTH'].
82
			'<br /><strong>'.$MESSAGE['GENERIC_FILL_IN_ALL'].'</strong>', $js_back);
83
	}
84
85
}
86
87 1348 Luisehahne
// Work-out file mode
88
if($advanced == '')
89
{
90 1777 Luisehahne
	$file_mode = STRING_FILE_MODE;
91
	$dir_mode = STRING_DIR_MODE;
92 1348 Luisehahne
	// Check if should be set to 777 or left alone
93 1777 Luisehahne
//	if(isset($_POST['world_writeable']) && $_POST['world_writeable'] == 'true')
94
//    {
95
//		$file_mode = '0777';
96
//		$dir_mode = '0777';
97
//	} else {
98
//		$file_mode = STRING_FILE_MODE;
99
//		$dir_mode = STRING_DIR_MODE;
100
//	}
101 1348 Luisehahne
} else {
102 1577 Luisehahne
	$file_mode = STRING_FILE_MODE;
103
	$dir_mode = STRING_DIR_MODE;
104
	if($admin->get_user_id()=='1')
105
	{
106
		// Work-out the octal value for file mode
107
		$u = 0;
108
		if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
109
			$u = $u+4;
110
		}
111
		if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
112
			$u = $u+2;
113
		}
114
		if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
115
			$u = $u+1;
116
		}
117
		$g = 0;
118
		if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
119
			$g = $g+4;
120
		}
121
		if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
122
			$g = $g+2;
123
		}
124
		if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
125
			$g = $g+1;
126
		}
127
		$o = 0;
128
		if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
129
			$o = $o+4;
130
		}
131
		if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
132
			$o = $o+2;
133
		}
134
		if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
135
			$o = $o+1;
136
		}
137
		$file_mode = "0".$u.$g.$o;
138
		// Work-out the octal value for dir mode
139
		$u = 0;
140
		if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
141
			$u = $u+4;
142
		}
143
		if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
144
			$u = $u+2;
145
		}
146
		if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
147
			$u = $u+1;
148
		}
149
		$g = 0;
150
		if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
151
			$g = $g+4;
152
		}
153
		if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
154
			$g = $g+2;
155
		}
156
		if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
157
			$g = $g+1;
158
		}
159
		$o = 0;
160
		if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
161
			$o = $o+4;
162
		}
163
		if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
164
			$o = $o+2;
165
		}
166
		if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
167
			$o = $o+1;
168
		}
169
		$dir_mode = "0".$u.$g.$o;
170 1348 Luisehahne
	}
171
}
172
173 1777 Luisehahne
$allow_tags_in_fields = array(
174
    'website_header',
175
    'website_footer',
176 1844 Luisehahne
    'wbmail_signature'
177 1777 Luisehahne
    );
178
$allow_empty_values = array(
179
    'website_header',
180
    'website_footer',
181 1844 Luisehahne
    'wbmail_signature',
182 1777 Luisehahne
    'wysiwyg_style',
183
    'pages_directory',
184
    'page_icon_dir',
185
    'rename_files_on_upload',
186
    'page_spacer',
187
    'page_icon_dir',
188
    );
189 1912 Luisehahne
$aPreventFromUpdate = array(
190
    'sp',
191
    'version',
192
//    'page_extension',
193 1777 Luisehahne
    'wb_version'
194
    );
195
$StripCodeFromInput = array(
196
    'website_title',
197
    'website_description',
198
    'website_keywords',
199 1844 Luisehahne
    'wbmail_signature',
200 1777 Luisehahne
    'wysiwyg_style',
201
    'pages_directory',
202
    'page_icon_dir',
203
    'media_directory',
204
    'page_extension',
205
    'rename_files_on_upload',
206
    'page_spacer',
207
    'page_icon_dir',
208
    );
209 1348 Luisehahne
210
// Query current settings in the db, then loop through them and update the db with the new value
211 1912 Luisehahne
//$settings = array();
212
//$old_settings = array();
213 1354 Luisehahne
// Query current settings in the db, then loop through them to get old values
214 1849 Luisehahne
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
215 1354 Luisehahne
$sql .= 'ORDER BY `name`';
216
217 1572 Luisehahne
if($res_settings = $database->query($sql)) {
218 1912 Luisehahne
	$iQueryStart = $database->getQueryCount;
219 1785 Luisehahne
	while($setting = $res_settings->fetchRow(MYSQL_ASSOC))
220 1572 Luisehahne
	{
221 1912 Luisehahne
		$passed = false;
222 1572 Luisehahne
		$setting_name = $setting['name'];
223 1912 Luisehahne
//		$old_settings = $setting['value'];
224
//		$value = $admin->get_post($setting_name);
225
		if(($value = $admin->get_post($setting_name)) === null) { continue; }
226
//		$value = isset($_POST[$setting_name]) ? $value : $old_settings ;
227 1572 Luisehahne
		switch ($setting_name) {
228
			case 'default_timezone':
229 1912 Luisehahne
				$value = intval($value);
230
				$value = ( ($value >= -12 && $value <= 13) ? $value :0 ) * 3600;
231
				$passed = ($value != $setting['value']);
232 1572 Luisehahne
				break;
233
			case 'string_dir_mode':
234
				$value=$dir_mode;
235 1912 Luisehahne
				$passed = ($value != $setting['value']);
236 1572 Luisehahne
				break;
237
			case 'string_file_mode':
238
				$value=$file_mode;
239 1912 Luisehahne
	 			$passed = ($value != $setting['value']);
240
				break;
241
			case 'page_extension':
242
				$value = $admin->StripCodeFromText($value);
243
				if(!preg_match('/^\.[a-z][a-z0-9]+$/siu', $value)) {
244
					$value = '.php';
245
				}
246
				$passed = ($value != $setting['value']);
247
				break;
248 1745 Luisehahne
			case 'sec_anchor':
249 1912 Luisehahne
				$value = $admin->StripCodeFromText($value);
250
				$value=(($value=='') ? 'Sec' : $value);
251
	 			$passed = ($value != $setting['value']);
252 1767 Luisehahne
				break;
253 1843 Luisehahne
			case 'media_directory':
254 1912 Luisehahne
				$value = trim($value,'/');
255
				$value = ( ($value != '')  ? '/'.$value : '/media' );
256
	 			$passed = ($value != $setting['value']);
257 1843 Luisehahne
				break;
258 1912 Luisehahne
			 case 'pages_directory':
259
			 $sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages`';
260
			  if( !($database->get_one($sql)) ) {
261
			   $value = rtrim($admin->StripCodeFromText($value));
262
			   $passed = ($value != $setting['value']);
263
			  }
264
			  $value = trim($value,'/');
265
			  $value = ( ($value != '')  ? '/'.$value : '' );
266
			  break;
267
			default :
268
				 if($value == '')  {
269
					$passed = ((in_array($setting_name, $allow_empty_values)) && ($value != $setting['value']));
270 1843 Luisehahne
				} else {
271 1912 Luisehahne
					if(in_array($setting_name, $StripCodeFromInput) ) {
272
						$value = trim($admin->StripCodeFromText($value));
273
					}
274
					$passed = (($value != '') && ($value != $setting['value']));
275 1843 Luisehahne
				}
276 1572 Luisehahne
				break;
277
		}
278 1348 Luisehahne
279 1572 Luisehahne
	    if (!in_array($setting_name, $allow_tags_in_fields))
280
	    {
281
	        $value = strip_tags($value);
282
	    }
283 1912 Luisehahne
		if( !in_array($setting_name, $aPreventFromUpdate) && $passed )
284
//	    if ( !in_array($setting_name, $aPreventFromUpdate) && (isset($_POST[$setting_name]) || $passed == true) )
285 1572 Luisehahne
	    {
286 1868 Luisehahne
	        $value = trim($database->escapeString($value));
287 1572 Luisehahne
	        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
288 1868 Luisehahne
	        $sql .= 'SET `value` = \''.($value).'\' ';
289 1572 Luisehahne
	        $sql .= 'WHERE `name` != \'wb_version\' ';
290
	        $sql .= 'AND `name` = \''.$setting_name.'\' ';
291
	        if (!$database->query($sql))
292
	        {
293
				if($database->is_error()) {
294
					$admin->print_error($database->get_error, $js_back );
295
				}
296 1912 Luisehahne
	        }
297 1572 Luisehahne
		}
298 1348 Luisehahne
	}
299 1912 Luisehahne
	$iQueriesDone = $database->getQueryCount - $iQueryStart;
300
}
301 1767 Luisehahne
302 1791 Luisehahne
/**
303
 * now save search settings
304
 */
305 1777 Luisehahne
$StripCodeFromISearch = array(
306 1785 Luisehahne
    'search_header',
307
    'search_results_header',
308
    'search_results_loop',
309
    'search_results_footer',
310
    'search_footer',
311 1777 Luisehahne
    'search_module_order',
312
    'search_max_excerpt',
313 1791 Luisehahne
    'search_no_results',
314 1777 Luisehahne
    'search_time_limit',
315 1791 Luisehahne
    'search_max_excerpt',
316 1777 Luisehahne
    );
317 1785 Luisehahne
$allow_empty_values = array(
318 1791 Luisehahne
    'header',
319
    'results_header',
320
    'results_loop',
321
    'results_footer',
322
    'footer',
323
    'module_order',
324
    'no_results',
325 1785 Luisehahne
    );
326 1791 Luisehahne
$allow_tags_in_fields = array(
327
    'header',
328
    'results_header',
329
    'results_loop',
330
    'results_footer',
331
    'no_results',
332
    'footer',
333
    );
334 1348 Luisehahne
335
// Query current search settings in the db, then loop through them and update the db with the new value
336
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
337 1791 Luisehahne
$sql .= 'WHERE `extra` =  \'\' ';
338
if( !($oSearch = $database->query($sql)) ) {
339
    if($database->is_error()) {
340
    	$admin->print_error(explode(';',$database->get_error()), $js_back );
341
    }
342 1348 Luisehahne
}
343
344 1791 Luisehahne
while($aSearch = $oSearch->fetchRow(MYSQL_ASSOC))
345 1348 Luisehahne
{
346 1791 Luisehahne
	$passed = false;
347
	$old_value = $aSearch['value'];
348
	$sSearchName = $aSearch['name'];
349
	$sPostName = 'search_'.$sSearchName;
350 1348 Luisehahne
351 1791 Luisehahne
    $value = $admin->get_post($sPostName);
352
    $value = isset($value) ?  $value : $old_value;
353
    if(in_array($sPostName, $StripCodeFromISearch) ) {
354 1777 Luisehahne
        $value = $admin->StripCodeFromText($value);
355
    }
356 1785 Luisehahne
357 1791 Luisehahne
/**
358
 *  hold old value if post is empty
359
 *  check search template
360
 */
361
	switch ($sSearchName) {
362
		case 'template':
363
 			$passed = true;
364
            $value =  ( !($admin->get_post($sPostName)) || ($value == DEFAULT_TEMPLATE ) ) ? '' : $admin->get_post($sPostName);
365
			break;
366
		case 'max_excerpt':
367
 			$passed = true;
368
        	if(preg_match('/[^0-9]+/i', $value)) {
369
                $value = $old_value;
370
        	}
371
			break;
372
		case 'time_limit':
373
            $passed = true;
374
        	if(preg_match('/[^0-9]+/i', $value)) {
375
                $value = $old_value;
376
        	}
377
			break;
378
		default :
379
        	$passed = ($admin->get_post($sPostName) || in_array($sSearchName, $allow_empty_values));
380 1785 Luisehahne
381 1791 Luisehahne
            if (!in_array($sSearchName, $allow_tags_in_fields))
382
            {
383
                $value = strip_tags($value);
384
            }
385
			break;
386
	}
387 1785 Luisehahne
388 1791 Luisehahne
    if ( ($passed == true) )
389 1348 Luisehahne
	{
390
		$value = $admin->add_slashes($value);
391
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
392 1785 Luisehahne
        $sql .= 'SET `value` = \''.$value.'\' ';
393 1791 Luisehahne
        $sql .= 'WHERE `name` = \''.$sSearchName.'\' ';
394 1785 Luisehahne
        $sql .= 'AND `extra` = \'\' ';
395 1348 Luisehahne
		if($database->query($sql)) {
396 1791 Luisehahne
397 1348 Luisehahne
		}
398
		$sql_info = mysql_info($database->db_handle);
399
    }
400
}
401
402
// Check if there was an error updating the db
403
if($database->is_error()) {
404 1425 Luisehahne
	$admin->print_error($database->get_error, $js_back );
405 1348 Luisehahne
} else {
406 1912 Luisehahne
//	$admin->print_success($iQueriesDone.' Queries '.$MESSAGE['SETTINGS_SAVED'], $js_back );
407 1731 Luisehahne
	$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
408 1348 Luisehahne
}
409
$admin->print_footer();