1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package settings
|
6
|
* @author 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: save.php 1840 2012-12-23 15:35:25Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
|
14
|
* @lastmodified $Date: 2012-12-23 16:35:25 +0100 (Sun, 23 Dec 2012) $
|
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
|
//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
|
require_once(WB_PATH.'/framework/functions.php');
|
38
|
|
39
|
// suppress to print the header, so no new FTAN will be set
|
40
|
if($advanced == '')
|
41
|
{
|
42
|
$admin = new admin('Settings', 'settings_basic',false);
|
43
|
} else {
|
44
|
$admin = new admin('Settings', 'settings_advanced',false);
|
45
|
}
|
46
|
|
47
|
// Create a javascript back link
|
48
|
$js_back = ADMIN_URL.'/settings/index.php'.$advanced;
|
49
|
if( !$admin->checkFTAN() )
|
50
|
{
|
51
|
$admin->print_header();
|
52
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back );
|
53
|
}
|
54
|
// After check print the header
|
55
|
$admin->print_header();
|
56
|
|
57
|
// 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
|
// // $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
|
{
|
66
|
$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'].
|
67
|
'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
if($admin->StripCodeFromText($admin->get_post('wbmailer_routine'))=='smtp') {
|
72
|
|
73
|
$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
|
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
|
// Work-out file mode
|
88
|
if($advanced == '')
|
89
|
{
|
90
|
$file_mode = STRING_FILE_MODE;
|
91
|
$dir_mode = STRING_DIR_MODE;
|
92
|
// Check if should be set to 777 or left alone
|
93
|
// 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
|
} else {
|
102
|
$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
|
}
|
171
|
}
|
172
|
|
173
|
$allow_tags_in_fields = array(
|
174
|
'website_header',
|
175
|
'website_footer',
|
176
|
'website_signature'
|
177
|
);
|
178
|
$allow_empty_values = array(
|
179
|
'website_header',
|
180
|
'website_footer',
|
181
|
'website_signature',
|
182
|
'wysiwyg_style',
|
183
|
'pages_directory',
|
184
|
'page_icon_dir',
|
185
|
'rename_files_on_upload',
|
186
|
'page_spacer',
|
187
|
'page_icon_dir',
|
188
|
'modules_upgrade_list'
|
189
|
);
|
190
|
$disallow_in_fields = array(
|
191
|
'pages_directory',
|
192
|
'media_directory',
|
193
|
'wb_version'
|
194
|
);
|
195
|
$StripCodeFromInput = array(
|
196
|
'website_title',
|
197
|
'website_description',
|
198
|
'website_keywords',
|
199
|
'website_signature',
|
200
|
'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
|
'modules_upgrade_list'
|
209
|
);
|
210
|
|
211
|
$bRebuildAccessFiles = ( (isset( $_POST['rebuild_access_files']) && ( $_POST['rebuild_access_files'] == true )) ? true : false ) ;
|
212
|
|
213
|
// Query current settings in the db, then loop through them and update the db with the new value
|
214
|
$settings = array();
|
215
|
$old_settings = array();
|
216
|
// Query current settings in the db, then loop through them to get old values
|
217
|
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
|
218
|
$sql .= 'ORDER BY `name`';
|
219
|
|
220
|
if($res_settings = $database->query($sql)) {
|
221
|
$passed = false;
|
222
|
while($setting = $res_settings->fetchRow(MYSQL_ASSOC))
|
223
|
{
|
224
|
$setting_name = $setting['name'];
|
225
|
$old_settings[$setting_name] = $setting['value'];
|
226
|
$value = $admin->get_post($setting_name);
|
227
|
$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
|
228
|
switch ($setting_name) {
|
229
|
case 'default_timezone':
|
230
|
$value=$value*60*60;
|
231
|
$passed = true;
|
232
|
break;
|
233
|
case 'string_dir_mode':
|
234
|
$value=$dir_mode;
|
235
|
$passed = true;
|
236
|
break;
|
237
|
case 'string_file_mode':
|
238
|
$value=$file_mode;
|
239
|
$passed = true;
|
240
|
break;
|
241
|
case 'sec_anchor':
|
242
|
$value = $admin->StripCodeFromText($value);
|
243
|
$value=(($value=='') ? 'section_' : $value);
|
244
|
$passed = true;
|
245
|
break;
|
246
|
case 'pages_directory':
|
247
|
$value = $admin->StripCodeFromText($value);
|
248
|
$bNewPageFile = ( ( $value!= $old_settings['pages_directory'] ) ? true : false );
|
249
|
$passed = $bNewPageFile;
|
250
|
$sGetId = '&id='.$bNewPageFile;
|
251
|
// if(!is_dir(WB_PATH.$value) && is_writable(WB_PATH)) {
|
252
|
// $passed = make_dir(WB_PATH.$value);
|
253
|
// }
|
254
|
$value = (($passed == true) ? $value : $old_settings['pages_directory']);
|
255
|
$sPageDirectory = $value;
|
256
|
break;
|
257
|
case 'wbmailer_smtp_auth':
|
258
|
// $value = isset($_POST[$setting_name]) ? $_POST[$setting_name] : '' ;
|
259
|
$value = true ;
|
260
|
$passed = true;
|
261
|
break;
|
262
|
default :
|
263
|
$passed = in_array($setting_name, $allow_empty_values);
|
264
|
if(in_array($setting_name, $StripCodeFromInput) ) {
|
265
|
$value = $admin->StripCodeFromText($value);
|
266
|
}
|
267
|
break;
|
268
|
}
|
269
|
|
270
|
if (!in_array($setting_name, $allow_tags_in_fields))
|
271
|
{
|
272
|
$value = strip_tags($value);
|
273
|
}
|
274
|
|
275
|
if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
|
276
|
{
|
277
|
$value = trim($admin->add_slashes($value));
|
278
|
$sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
|
279
|
$sql .= 'SET `value` = \''.($value).'\' '; // mysql_escape_string
|
280
|
$sql .= 'WHERE `name` != \'wb_version\' ';
|
281
|
$sql .= 'AND `name` = \''.$setting_name.'\' ';
|
282
|
if (!$database->query($sql))
|
283
|
{
|
284
|
if($database->is_error()) {
|
285
|
$admin->print_error($database->get_error, $js_back );
|
286
|
}
|
287
|
}
|
288
|
}
|
289
|
}
|
290
|
|
291
|
if(($bRebuildAccessFiles==true) && ($_POST['modules_upgrade_list']!='') && ($sPageDirectory==$old_settings['pages_directory']) ) {
|
292
|
rebuild_all_accessfiles();
|
293
|
$aModuleList = ( explode(',', $_POST['modules_upgrade_list']));
|
294
|
upgrade_modules($aModuleList);
|
295
|
}
|
296
|
|
297
|
}
|
298
|
/**
|
299
|
* now save search settings
|
300
|
*/
|
301
|
$StripCodeFromISearch = array(
|
302
|
'search_header',
|
303
|
'search_results_header',
|
304
|
'search_results_loop',
|
305
|
'search_results_footer',
|
306
|
'search_footer',
|
307
|
'search_module_order',
|
308
|
'search_max_excerpt',
|
309
|
'search_no_results',
|
310
|
'search_time_limit',
|
311
|
'search_max_excerpt',
|
312
|
);
|
313
|
$allow_empty_values = array(
|
314
|
'header',
|
315
|
'results_header',
|
316
|
'results_loop',
|
317
|
'results_footer',
|
318
|
'footer',
|
319
|
'module_order',
|
320
|
'no_results',
|
321
|
);
|
322
|
$allow_tags_in_fields = array(
|
323
|
'header',
|
324
|
'results_header',
|
325
|
'results_loop',
|
326
|
'results_footer',
|
327
|
'no_results',
|
328
|
'footer',
|
329
|
);
|
330
|
|
331
|
// Query current search settings in the db, then loop through them and update the db with the new value
|
332
|
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
|
333
|
$sql .= 'WHERE `extra` = \'\' ';
|
334
|
if( !($oSearch = $database->query($sql)) ) {
|
335
|
if($database->is_error()) {
|
336
|
$admin->print_error(explode(';',$database->get_error()), $js_back );
|
337
|
}
|
338
|
}
|
339
|
|
340
|
while($aSearch = $oSearch->fetchRow(MYSQL_ASSOC))
|
341
|
{
|
342
|
$passed = false;
|
343
|
$old_value = $aSearch['value'];
|
344
|
$sSearchName = $aSearch['name'];
|
345
|
$sPostName = 'search_'.$sSearchName;
|
346
|
|
347
|
$value = $admin->get_post($sPostName);
|
348
|
$value = isset($value) ? $value : $old_value;
|
349
|
if(in_array($sPostName, $StripCodeFromISearch) ) {
|
350
|
$value = $admin->StripCodeFromText($value);
|
351
|
}
|
352
|
|
353
|
/**
|
354
|
* hold old value if post is empty
|
355
|
* check search template
|
356
|
*/
|
357
|
switch ($sSearchName) {
|
358
|
case 'template':
|
359
|
$passed = true;
|
360
|
$value = ( !($admin->get_post($sPostName)) || ($value == DEFAULT_TEMPLATE ) ) ? '' : $admin->get_post($sPostName);
|
361
|
break;
|
362
|
case 'max_excerpt':
|
363
|
$passed = true;
|
364
|
if(preg_match('/[^0-9]+/i', $value)) {
|
365
|
$value = $old_value;
|
366
|
}
|
367
|
break;
|
368
|
case 'time_limit':
|
369
|
$passed = true;
|
370
|
if(preg_match('/[^0-9]+/i', $value)) {
|
371
|
$value = $old_value;
|
372
|
}
|
373
|
break;
|
374
|
default :
|
375
|
$passed = ($admin->get_post($sPostName) || in_array($sSearchName, $allow_empty_values));
|
376
|
|
377
|
if (!in_array($sSearchName, $allow_tags_in_fields))
|
378
|
{
|
379
|
$value = strip_tags($value);
|
380
|
}
|
381
|
break;
|
382
|
}
|
383
|
|
384
|
if ( ($passed == true) )
|
385
|
{
|
386
|
$value = $admin->add_slashes($value);
|
387
|
$sql = 'UPDATE `'.TABLE_PREFIX.'search` ';
|
388
|
$sql .= 'SET `value` = \''.$value.'\' ';
|
389
|
$sql .= 'WHERE `name` = \''.$sSearchName.'\' ';
|
390
|
$sql .= 'AND `extra` = \'\' ';
|
391
|
if($database->query($sql)) {
|
392
|
|
393
|
}
|
394
|
$sql_info = mysql_info($database->db_handle);
|
395
|
}
|
396
|
}
|
397
|
|
398
|
// Check if there was an error updating the db
|
399
|
if($database->is_error()) {
|
400
|
$admin->print_error($database->get_error, $js_back );
|
401
|
} else {
|
402
|
$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
|
403
|
}
|
404
|
$admin->print_footer();
|