Project

General

Profile

« Previous | Next » 

Revision 1475

Added by Dietmar over 13 years ago

+ add SecureForm.mtab.php under mantennance by WebsiteBaker Community
! security fixes media, groups, users, sections
  1. change lang variable to remove upgrade-script
    ! reworked add sections in pages
    ! fix set empty href in show_menu2
    ! set show_menu2 version to 4.9.6
    ! reworked Droplet LoginBox, add redirect query
    - remove unneeded folder js
    ! set Droplet to version 1.1.0
    + add checkboxes to change frontend absolute url to relative urls
    ! set output_filter version to 0.2

View differences:

users.php
20 20
require('../../config.php');
21 21
require_once(WB_PATH.'/framework/class.admin.php');
22 22

  
23
// Create new database object
24
// $database = new database();
23
$action = 'cancel';
24
// Set parameter 'action' as alternative to javascript mechanism
25
$action = (isset($_POST['modify']) ? 'modify' : $action );
26
$action = (isset($_POST['delete']) ? 'delete' : $action );
25 27

  
26
if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
27
	header("Location: index.php");
28
	exit(0);
29
}
28
switch ($action):
29
	case 'modify' :
30
			// Print header
31
			$admin = new admin('Access', 'users_modify');
32
			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
33
			// Check if user id is a valid number and doesnt equal 1
34
			if( ($user_id < 2 ) )
35
			{
36
				// if($admin_header) { $admin->print_header(); }
37
				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
38
			}
39
			// Get existing values
40
			$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$user_id."'");
41
			$user = $results->fetchRow();
30 42

  
31
// Set parameter 'action' as alternative to javascript mechanism
32
if(isset($_POST['modify']))
33
	$_POST['action'] = "modify";
34
if(isset($_POST['delete']))
35
	$_POST['action'] = "delete";
43
			// Setup template object
44
			$template = new Template(THEME_PATH.'/templates');
45
			$template->set_file('page', 'users_form.htt');
46
			$template->set_block('page', 'main_block', 'main');
47
			$template->set_var(	array(
48
								'ACTION_URL' => ADMIN_URL.'/users/save.php',
49
								'SUBMIT_TITLE' => $TEXT['SAVE'],
50
								'USER_ID' => $user['user_id'],
51
								'USERNAME' => $user['username'],
52
								'DISPLAY_NAME' => $user['display_name'],
53
								'EMAIL' => $user['email'],
54
								'ADMIN_URL' => ADMIN_URL,
55
								'WB_URL' => WB_URL,
56
								'THEME_URL' => THEME_URL
57
								)
58
						);
36 59

  
37
// Check if user id is a valid number and doesnt equal 1
38
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
39
	header("Location: index.php");
40
	exit(0);
41
}
42

  
43
if($_POST['action'] == 'modify')
44
{
45
	// Print header
46
	$admin = new admin('Access', 'users_modify');
47
	// Get existing values
48
	$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
49
	$user = $results->fetchRow();
50
	
51
	// Setup template object
52
	$template = new Template(THEME_PATH.'/templates');
53
	$template->set_file('page', 'users_form.htt');
54
	$template->set_block('page', 'main_block', 'main');
55
	$template->set_var(	array(
56
							'ACTION_URL' => ADMIN_URL.'/users/save.php',
57
							'SUBMIT_TITLE' => $TEXT['SAVE'],
58
							'USER_ID' => $user['user_id'],
59
							'USERNAME' => $user['username'],
60
							'DISPLAY_NAME' => $user['display_name'],
61
							'EMAIL' => $user['email'],
62
							'ADMIN_URL' => ADMIN_URL,
63
							'WB_URL' => WB_URL,
64
							'THEME_URL' => THEME_URL
65
							)
66
					);
67
	
68
	$template->set_var('FTAN', $admin->getFTAN());
69
	if($user['active'] == 1) {
70
		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
71
	} else {
72
		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
73
	}
74
	// Add groups to list
75
	$template->set_block('main_block', 'group_list_block', 'group_list');
76
	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
77
	if($results->numRows() > 0) {
78
		$template->set_var('ID', '');
79
		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
80
		$template->set_var('SELECTED', '');
81
		$template->parse('group_list', 'group_list_block', true);
82
		while($group = $results->fetchRow()) {
83
			$template->set_var('ID', $group['group_id']);
84
			$template->set_var('NAME', $group['name']);
85
			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
86
				$template->set_var('SELECTED', ' selected="selected"');
60
			$template->set_var('FTAN', $admin->getFTAN());
61
			if($user['active'] == 1) {
62
				$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
87 63
			} else {
64
				$template->set_var('DISABLED_CHECKED', ' checked="checked"');
65
			}
66
			// Add groups to list
67
			$template->set_block('main_block', 'group_list_block', 'group_list');
68
			$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
69
			if($results->numRows() > 0) {
70
				$template->set_var('ID', '');
71
				$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
88 72
				$template->set_var('SELECTED', '');
73
				$template->parse('group_list', 'group_list_block', true);
74
				while($group = $results->fetchRow()) {
75
					$template->set_var('ID', $group['group_id']);
76
					$template->set_var('NAME', $group['name']);
77
					if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
78
						$template->set_var('SELECTED', ' selected="selected"');
79
					} else {
80
						$template->set_var('SELECTED', '');
81
					}
82
					$template->parse('group_list', 'group_list_block', true);
83
				}
89 84
			}
90
			$template->parse('group_list', 'group_list_block', true);
91
		}
92
	}
93 85

  
94
	// Only allow the user to add a user to the Administrators group if they belong to it
95
	if(in_array(1, $admin->get_groups_id()))
96
    {
97
		$template->set_var('ID', '1');
98
		$users_groups = $admin->get_groups_name();
99
		$template->set_var('NAME', $users_groups[1]);
86
			// Only allow the user to add a user to the Administrators group if they belong to it
87
			if(in_array(1, $admin->get_groups_id()))
88
		    {
89
				$template->set_var('ID', '1');
90
				$users_groups = $admin->get_groups_name();
91
				$template->set_var('NAME', $users_groups[1]);
100 92

  
101
		$in_group = FALSE;
102
		foreach($admin->get_groups_id() as $cur_gid){
103
		    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
104
		        $in_group = TRUE;
105
		    }
106
		}
93
				$in_group = FALSE;
94
				foreach($admin->get_groups_id() as $cur_gid){
95
				    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
96
				        $in_group = TRUE;
97
				    }
98
				}
107 99

  
108
		if($in_group) {
109
			$template->set_var('SELECTED', ' selected="selected"');
110
		} else {
111
			$template->set_var('SELECTED', '');
112
		}
113
		$template->parse('group_list', 'group_list_block', true);
114
	} else {
115
		if($results->numRows() == 0) {
116
			$template->set_var('ID', '');
117
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
118
			$template->set_var('SELECTED', ' selected="selected"');
119
			$template->parse('group_list', 'group_list_block', true);
120
		}
121
	}
100
				if($in_group) {
101
					$template->set_var('SELECTED', ' selected="selected"');
102
				} else {
103
					$template->set_var('SELECTED', '');
104
				}
105
				$template->parse('group_list', 'group_list_block', true);
106
			} else {
107
				if($results->numRows() == 0) {
108
					$template->set_var('ID', '');
109
					$template->set_var('NAME', $TEXT['NONE_FOUND']);
110
					$template->set_var('SELECTED', ' selected="selected"');
111
					$template->parse('group_list', 'group_list_block', true);
112
				}
113
			}
122 114

  
123
	// Generate username field name
124
	$username_fieldname = 'username_';
125
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
126
	srand((double)microtime()*1000000);
127
	$i = 0;
128
	while ($i <= 7) {
129
		$num = rand() % 33;
130
		$tmp = substr($salt, $num, 1);
131
		$username_fieldname = $username_fieldname . $tmp;
132
		$i++;
133
	}
134
	
135
	// Work-out if home folder should be shown
136
	if(!HOME_FOLDERS) {
137
		$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
138
	}
139
	
140
	// Include the WB functions file
141
	require_once(WB_PATH.'/framework/functions.php');
142
	
143
	// Add media folders to home folder list
144
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
145
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
146
    {
147
		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
148
		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
149
		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
150
			$template->set_var('SELECTED', ' selected="selected"');
151
		} else {
152
			$template->set_var('SELECTED', ' ');
153
		}
154
		$template->parse('folder_list', 'folder_list_block', true);
155
	}
156
	
157
	// Insert language text and messages
158
	$template->set_var(array(
159
									'TEXT_RESET' => $TEXT['RESET'],
160
									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
161
									'TEXT_DISABLED' => $TEXT['DISABLED'],
162
									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
163
									'TEXT_USERNAME' => $TEXT['USERNAME'],
164
									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
165
									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
166
									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
167
									'TEXT_EMAIL' => $TEXT['EMAIL'],
168
									'TEXT_GROUP' => $TEXT['GROUP'],
169
									'TEXT_NONE' => $TEXT['NONE'],
170
									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
171
									'USERNAME_FIELDNAME' => $username_fieldname,
172
									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
173
									'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
174
									)
175
							);
176
	
177
	// Parse template object
178
	$template->parse('main', 'main_block', false);
179
	$template->pparse('output', 'page');
180
} elseif($_POST['action'] == 'delete') {
181
	// Print header
182
	$admin = new admin('Access', 'users_delete');
183
	// Delete the user
184
	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
185
	if($database->is_error()) {
186
		$admin->print_error($database->get_error());
187
	} else {
188
		$admin->print_success($MESSAGE['USERS']['DELETED']);
189
	}
190
}
115
			// Generate username field name
116
			$username_fieldname = 'username_';
117
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
118
			srand((double)microtime()*1000000);
119
			$i = 0;
120
			while ($i <= 7) {
121
				$num = rand() % 33;
122
				$tmp = substr($salt, $num, 1);
123
				$username_fieldname = $username_fieldname . $tmp;
124
				$i++;
125
			}
191 126

  
127
			// Work-out if home folder should be shown
128
			if(!HOME_FOLDERS) {
129
				$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
130
			}
131

  
132
			// Include the WB functions file
133
			require_once(WB_PATH.'/framework/functions.php');
134

  
135
			// Add media folders to home folder list
136
			$template->set_block('main_block', 'folder_list_block', 'folder_list');
137
			foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
138
		    {
139
				$template->set_var('NAME', str_replace(WB_PATH, '', $name));
140
				$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
141
				if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
142
					$template->set_var('SELECTED', ' selected="selected"');
143
				} else {
144
					$template->set_var('SELECTED', ' ');
145
				}
146
				$template->parse('folder_list', 'folder_list_block', true);
147
			}
148

  
149
			// Insert language text and messages
150
			$template->set_var(array(
151
								'TEXT_RESET' => $TEXT['RESET'],
152
								'TEXT_ACTIVE' => $TEXT['ACTIVE'],
153
								'TEXT_DISABLED' => $TEXT['DISABLED'],
154
								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
155
								'TEXT_USERNAME' => $TEXT['USERNAME'],
156
								'TEXT_PASSWORD' => $TEXT['PASSWORD'],
157
								'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
158
								'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
159
								'TEXT_EMAIL' => $TEXT['EMAIL'],
160
								'TEXT_GROUP' => $TEXT['GROUP'],
161
								'TEXT_NONE' => $TEXT['NONE'],
162
								'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
163
								'USERNAME_FIELDNAME' => $username_fieldname,
164
								'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
165
								'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
166
								)
167
						);
168

  
169
			// Parse template object
170
			$template->parse('main', 'main_block', false);
171
			$template->pparse('output', 'page');
172
			break;
173
		case 'delete' :
174
			// Print header
175
			$admin = new admin('Access', 'users_delete');
176
			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
177
			// Check if user id is a valid number and doesnt equal 1
178
			if( ($user_id < 2 ) )
179
			{
180
				// if($admin_header) { $admin->print_header(); }
181
				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
182
			}
183
			// Delete the user
184
			$database->query("UPDATE `".TABLE_PREFIX."users` SET `active` = 0 WHERE `user_id` = '".$user_id."' ");
185
			if($database->is_error()) {
186
				$admin->print_error($database->get_error());
187
			} else {
188
				$admin->print_success($MESSAGE['USERS']['DELETED']);
189
			}
190
			break;
191
	default:
192
			break;
193
endswitch;
194

  
192 195
// Print admin footer
193 196
$admin->print_footer();
194

  
195
?>

Also available in: Unified diff