Project

General

Profile

« Previous | Next » 

Revision 1348

Added by Dietmar almost 14 years ago

fix save access rights in settings

View differences:

save.php
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, 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 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
20
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
21

  
22
// Find out if the user was view advanced options or not
23
$advanced = ($_POST['advanced'] == 'yes') ? '?advanced=yes' : '';
24

  
25
// Print admin header
26
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28

  
29
if($advanced == '')
30
{
31
	$admin = new admin('Settings', 'settings_basic');
32
	$_POST['database_password'] = DB_PASSWORD;
33
} else {
34
	$admin = new admin('Settings', 'settings_advanced');
35
}
36

  
37
// Create a javascript back link
38
$js_back = "javascript: history.go(-1);";
39

  
40
// Ensure that the specified default email is formally valid
41
if(isset($_POST['server_email']))
42
{
43
	$_POST['server_email'] = strip_tags($_POST['server_email']);
44
    // $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';
45
    $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}))$/';
46
    if(false == preg_match($pattern, $_POST['server_email']))
47
    {
48
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'].
49
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
50
	}
51
}
52

  
53
// Work-out file mode
54
if($advanced == '')
55
{
56
	// Check if should be set to 777 or left alone
57
	if(isset($_POST['world_writeable']) && $_POST['world_writeable'] == 'true')
58
    {
59
		$file_mode = '0777';
60
		$dir_mode = '0777';
61
	} else {
62
		$file_mode = STRING_FILE_MODE;
63
		$dir_mode = STRING_DIR_MODE;
64
	}
65
} else {
66
	// Work-out the octal value for file mode
67
	$u = 0;
68
	if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
69
		$u = $u+4;
70
	}
71
	if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
72
		$u = $u+2;
73
	}
74
	if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
75
		$u = $u+1;
76
	}
77
	$g = 0;
78
	if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
79
		$g = $g+4;
80
	}
81
	if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
82
		$g = $g+2;
83
	}
84
	if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
85
		$g = $g+1;
86
	}
87
	$o = 0;
88
	if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
89
		$o = $o+4;
90
	}
91
	if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
92
		$o = $o+2;
93
	}
94
	if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
95
		$o = $o+1;
96
	}
97
	$file_mode = "0".$u.$g.$o;
98
	// Work-out the octal value for dir mode
99
	$u = 0;
100
	if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
101
		$u = $u+4;
102
	}
103
	if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
104
		$u = $u+2;
105
	}
106
	if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
107
		$u = $u+1;
108
	}
109
	$g = 0;
110
	if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
111
		$g = $g+4;
112
	}
113
	if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
114
		$g = $g+2;
115
	}
116
	if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
117
		$g = $g+1;
118
	}
119
	$o = 0;
120
	if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
121
		$o = $o+4;
122
	}
123
	if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
124
		$o = $o+2;
125
	}
126
	if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
127
		$o = $o+1;
128
	}
129
	$dir_mode = "0".$u.$g.$o;
130
}
131

  
132
// Create new database object
133
/*$database = new database(); */
134

  
135
// Query current settings in the db, then loop through them and update the db with the new value
136
$query = "SELECT name FROM ".TABLE_PREFIX."settings";
137
$results = $database->query($query);
138
while($setting = $results->fetchRow())
139
{
140
	$setting_name = $setting['name'];
141
	$value = $admin->get_post($setting_name);
142
    if(isset($value))
143
	{
144
		if ($setting_name!='wb_version')
145
	    {
146
			$allow_tags_in_fields = array('website_header', 'website_footer','wbmailer_smtp_password');
147
			if(!in_array($setting_name, $allow_tags_in_fields)) {
148
				$value = strip_tags($value);
149
			}
150
			switch ($setting_name) {
151
				case 'default_timezone':
152
					$value=$value*60*60;
153
					break;
154
				case 'string_dir_mode':
155
					$value=$dir_mode;
156
					break;
157
				case 'string_file_mode':
158
					$value=$file_mode;
159
					break;
160
				case 'pages_directory':
161
					if(trim($value)=='/') $value='';
162
					break;
163
			}
164
			$value = $admin->add_slashes($value);
165
			$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
166
		}
167
	}
168
}
169

  
170
// Query current search settings in the db, then loop through them and update the db with the new value
171
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
172
$sql .= 'WHERE `extra` = ""';
173
$res_search = $database->query($sql);
174

  
175
if($database->is_error()) {
176
	$admin->print_error($database->is_error(), ADMIN_URL.'/settings/index.php'.$advanced);
177
}
178

  
179
while($search_setting = $res_search->fetchRow())
180
{
181
	$old_value = $search_setting['value'];
182
	$setting_name = $search_setting['name'];
183
	$post_name = 'search_'.$search_setting['name'];
184

  
185
    // hold old value if post is empty
186
    // check search template
187
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
188
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
189
    if(isset($value))
190
	{
191
		$value = $admin->add_slashes($value);
192
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
193
        $sql .= 'SET `value` = "'.$value.'" ';
194
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
195
        $sql .= 'AND `extra` = ""';
196
		if($database->query($sql)) {
197
		}
198
		$sql_info = mysql_info($database->db_handle);
199
    }
200
}
201

  
202
// Check if there was an error updating the db
203
if($database->is_error()) {
204
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
205
} else {
206
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
207
}
208
$admin->print_footer();
209

  
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, 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 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
20
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
21

  
22
// Find out if the user was view advanced options or not
23
$advanced = ($_POST['advanced'] == 'yes') ? '?advanced=yes' : '';
24

  
25
// Print admin header
26
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28

  
29
if($advanced == '')
30
{
31
	$admin = new admin('Settings', 'settings_basic');
32
	$_POST['database_password'] = DB_PASSWORD;
33
} else {
34
	$admin = new admin('Settings', 'settings_advanced');
35
}
36

  
37
// Create a javascript back link
38
$js_back = "javascript: history.go(-1);";
39

  
40
// Ensure that the specified default email is formally valid
41
if(isset($_POST['server_email']))
42
{
43
	$_POST['server_email'] = strip_tags($_POST['server_email']);
44
    // $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';
45
    $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}))$/';
46
    if(false == preg_match($pattern, $_POST['server_email']))
47
    {
48
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'].
49
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
50
	}
51
}
52

  
53
// Work-out file mode
54
if($advanced == '')
55
{
56
	// Check if should be set to 777 or left alone
57
	if(isset($_POST['world_writeable']) && $_POST['world_writeable'] == 'true')
58
    {
59
		$file_mode = '0777';
60
		$dir_mode = '0777';
61
	} else {
62
		$file_mode = STRING_FILE_MODE;
63
		$dir_mode = STRING_DIR_MODE;
64
	}
65
} else {
66
	// Work-out the octal value for file mode
67
	$u = 0;
68
	if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
69
		$u = $u+4;
70
	}
71
	if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
72
		$u = $u+2;
73
	}
74
	if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
75
		$u = $u+1;
76
	}
77
	$g = 0;
78
	if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
79
		$g = $g+4;
80
	}
81
	if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
82
		$g = $g+2;
83
	}
84
	if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
85
		$g = $g+1;
86
	}
87
	$o = 0;
88
	if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
89
		$o = $o+4;
90
	}
91
	if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
92
		$o = $o+2;
93
	}
94
	if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
95
		$o = $o+1;
96
	}
97
	$file_mode = "0".$u.$g.$o;
98
	// Work-out the octal value for dir mode
99
	$u = 0;
100
	if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
101
		$u = $u+4;
102
	}
103
	if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
104
		$u = $u+2;
105
	}
106
	if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
107
		$u = $u+1;
108
	}
109
	$g = 0;
110
	if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
111
		$g = $g+4;
112
	}
113
	if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
114
		$g = $g+2;
115
	}
116
	if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
117
		$g = $g+1;
118
	}
119
	$o = 0;
120
	if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
121
		$o = $o+4;
122
	}
123
	if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
124
		$o = $o+2;
125
	}
126
	if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
127
		$o = $o+1;
128
	}
129
	$dir_mode = "0".$u.$g.$o;
130
}
131

  
132
// Create new database object
133
/*$database = new database(); */
134

  
135
// Query current settings in the db, then loop through them and update the db with the new value
136
$query = "SELECT name FROM ".TABLE_PREFIX."settings";
137
$results = $database->query($query);
138
while($setting = $results->fetchRow())
139
{
140
	$setting_name = $setting['name'];
141
	$value = $admin->get_post($setting_name);
142
	if ($setting_name!='wb_version')
143
    {
144
		$allow_tags_in_fields = array('website_header', 'website_footer','wbmailer_smtp_password');
145
		if(!in_array($setting_name, $allow_tags_in_fields)) {
146
			$value = strip_tags($value);
147
		}
148

  
149
		switch ($setting_name) {
150
			case 'default_timezone':
151
				$value=$value*60*60;
152
				break;
153
			case 'string_dir_mode':
154
				$value=$dir_mode;
155
				break;
156
			case 'string_file_mode':
157
				$value=$file_mode;
158
				break;
159
			case 'pages_directory':
160
				if(trim($value)=='/') $value='';
161
				break;
162
			default :
163

  
164
				break;
165
		}
166
		$value = $admin->add_slashes($value);
167
		$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
168
	}
169
}
170

  
171
// Query current search settings in the db, then loop through them and update the db with the new value
172
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
173
$sql .= 'WHERE `extra` = ""';
174
$res_search = $database->query($sql);
175

  
176
if($database->is_error()) {
177
	$admin->print_error($database->is_error(), ADMIN_URL.'/settings/index.php'.$advanced);
178
}
179

  
180
while($search_setting = $res_search->fetchRow())
181
{
182
	$old_value = $search_setting['value'];
183
	$setting_name = $search_setting['name'];
184
	$post_name = 'search_'.$search_setting['name'];
185

  
186
    // hold old value if post is empty
187
    // check search template
188
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
189
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
190
    if(isset($value))
191
	{
192
		$value = $admin->add_slashes($value);
193
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
194
        $sql .= 'SET `value` = "'.$value.'" ';
195
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
196
        $sql .= 'AND `extra` = ""';
197
		if($database->query($sql)) {
198
		}
199
		$sql_info = mysql_info($database->db_handle);
200
    }
201
}
202

  
203
// Check if there was an error updating the db
204
if($database->is_error()) {
205
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
206
} else {
207
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
208
}
209
$admin->print_footer();
210

  
210 211
?>

Also available in: Unified diff