Project

General

Profile

« Previous | Next » 

Revision 01a0385e

Added by Phil Davis about 9 years ago

Do not allow deleting your own user name

Currently if you delete your own user name, then the config ends up with a blank user tag in it. Rather than fix that up, it seems dangerous to be able to delete yourself anyway, because if you are the last user with admin privs for which you know the password (i.e. if you have not recorded the password for "admin" somewhere), then you can lock yourself out. That would require console access to fix, which for some people is a pain.
It seems reasonable to me to make the person login as some other user with admin privs to delete "themselves".
Bit of boots and braces done here:
1) Don't show the trash bin icon for "yourself", and also disable the delete_check checkbox. So you can't opt to delete yourself from the ordinary front-end GUI.
2) Enhance the back-end validation to prevent deleting yourself, just in case someone mucks about in the front-end code.
3) Put error messages to tell people when something is not deleted, and why.
4) In the success message for multi-deletion, tell which user names have actually been deleted.
(cherry picked from commit d6b79c398d16ade9ccd3d21c9574c7a263fc6383)

View differences:

src/usr/local/www/system_usermanager.php
110 110
		exit;
111 111
	}
112 112

  
113
	conf_mount_rw();
114
	local_user_del($a_user[$id]);
115
	conf_mount_ro();
116
	$userdeleted = $a_user[$id]['name'];
117
	unset($a_user[$id]);
118
	write_config();
119
	$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
113
	if ($_GET['username'] == $_SESSION['Username']) {
114
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_GET['username']);
115
	} else {
116
		conf_mount_rw();
117
		local_user_del($a_user[$id]);
118
		conf_mount_ro();
119
		$userdeleted = $a_user[$id]['name'];
120
		unset($a_user[$id]);
121
		write_config();
122
		$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
123
	}
120 124
} else if ($act == "new") {
121 125
	/*
122 126
	 * set this value cause the text field is read only
......
130 134
if (isset($_POST['dellall'])) {
131 135

  
132 136
	$del_users = $_POST['delete_check'];
137
	$deleted_users = "";
138
	$deleted_count = 0;
139
	$comma = "";
133 140

  
134 141
	if (!empty($del_users)) {
135 142
		foreach ($del_users as $userid) {
136 143
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
137
				conf_mount_rw();
138
				local_user_del($a_user[$userid]);
139
 			    conf_mount_ro();
140
				unset($a_user[$userid]);
144
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
145
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
146
				} else {
147
					conf_mount_rw();
148
					$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
149
					$comma = ", ";
150
					$deleted_count++;
151
					local_user_del($a_user[$userid]);
152
					conf_mount_ro();
153
					unset($a_user[$userid]);
154
				}
155
			} else {
156
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
141 157
			}
142 158
		}
143
		$savemsg = gettext("Selected users removed successfully.");
144
		write_config($savemsg);
159

  
160
		if ($deleted_count > 0) {
161
			if ($deleted_count == 1) {
162
				$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
163
			} else {
164
				$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
165
			}
166
			write_config($savemsg);
167
		}
145 168
	}
146 169
}
147 170

  
......
479 502
}
480 503
include("head.inc");
481 504

  
505
if ($delete_errors) {
506
	print_input_errors($delete_errors);
507
}
508

  
482 509
if ($input_errors) {
483 510
	print_input_errors($input_errors);
484 511
}
......
518 545
	?>
519 546
					<tr>
520 547
						<td>
521
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=($userent['scope'] == "system" ? 'disabled' : '')?>/>
548
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
522 549
						</td>
523 550
						<td>
524 551
<?php
......
536 563
						<td><?=implode(",", local_user_get_groups($userent))?></td>
537 564
						<td>
538 565
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
539
<?php if ($userent['scope'] != "system"): ?>
566
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
540 567
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>"></a>
541 568
<?php endif; ?>
542 569
						</td>
......
912 939
</script>
913 940
<?php
914 941
include('foot.inc');
915
?>
942
?>

Also available in: Unified diff