diff --git a/src/www/system_groupmanager.php b/src/www/system_groupmanager.php index d036da849..a44883f24 100644 --- a/src/www/system_groupmanager.php +++ b/src/www/system_groupmanager.php @@ -31,516 +31,513 @@ require_once("guiconfig.inc"); -$pgtitle = array(gettext('System'), gettext('Groups')); - if (!isset($config['system']['group'])) { $config['system']['group'] = array(); } - $a_group = &$config['system']['group']; -unset($id); -if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) { - $id = $_POST['groupid']; -} - -$act = (isset($_POST['act']) ? $_POST['act'] : ''); - -if ($act == "delgroup") { - if (!isset($id) || !isset($_POST['groupname']) || !isset($a_group[$id]) || ($_POST['groupname'] != $a_group[$id]['name'])) { - redirectHeader("system_groupmanager.php"); - exit; +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($a_group[$_GET['groupid']])) { + $id = $_GET['groupid']; } - - local_group_del($a_group[$id]); - $groupdeleted = $a_group[$id]['name']; - unset($a_group[$id]); - write_config(); - $savemsg = gettext("Group")." {$groupdeleted} ". - gettext("successfully deleted")."
"; -} - -if ($act == "delpriv") { - if (!isset($id) || !isset($a_group[$id])) { - redirectHeader("system_groupmanager.php"); - exit; + if (isset($_GET['act']) && ($_GET['act'] == 'edit' || $_GET['act'] == 'new')) { + $act = $_GET['act']; + } else { + $act = null; } - - $privdeleted = $priv_list[$a_group[$id]['priv'][$_POST['privid']]]['name']; - unset($a_group[$id]['priv'][$_POST['privid']]); - - if (is_array($a_group[$id]['member'])) { - foreach ($a_group[$id]['member'] as $uid) { - $user = getUserEntryByUID($uid); - if ($user) { - local_user_set($user); - } - } - } - - write_config(); - $act = "edit"; - $savemsg = gettext("Privilege")." {$privdeleted} ". - gettext("successfully deleted")."
"; -} - -if ($act == "edit") { - if (isset($id) && isset($a_group[$id])) { + $pconfig = array(); + if ($act == "edit" && isset($id)) { + // read config $pconfig['name'] = $a_group[$id]['name']; $pconfig['gid'] = $a_group[$id]['gid']; - $pconfig['gtype'] = $a_group[$id]['scope']; + $pconfig['scope'] = $a_group[$id]['scope']; $pconfig['description'] = $a_group[$id]['description']; - $pconfig['members'] = $a_group[$id]['member']; - $pconfig['priv'] = $a_group[$id]['priv']; + $pconfig['members'] = isset($a_group[$id]['member']) ? $a_group[$id]['member'] : array(); + $pconfig['priv'] = isset($a_group[$id]['priv']) ? $a_group[$id]['priv'] : array(); + } elseif ($act != null) { + // init defaults + $pconfig['name'] = null; + $pconfig['gid'] = null; + $pconfig['scope'] = null; + $pconfig['description'] = null; + $pconfig['members'] = array(); + $pconfig['priv'] = array(); + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($a_group[$_POST['groupid']])) { + $id = $_POST['groupid']; } -} - -if (isset($_POST['save'])) { - unset($input_errors); $pconfig = $_POST; - - /* input validation */ - $reqdfields = explode(" ", "groupname"); - $reqdfieldsn = array(gettext("Group Name")); - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname'])) { - $input_errors[] = gettext("The group name contains invalid characters."); - } - - if (strlen($_POST['groupname']) > 16) { - $input_errors[] = gettext("The group name is longer than 16 characters."); - } - - if (!$input_errors && !(isset($id) && $a_group[$id])) { - /* make sure there are no dupes */ - foreach ($a_group as $group) { - if ($group['name'] == $_POST['groupname']) { - $input_errors[] = gettext("Another entry with the same group name already exists."); - break; + $act = (isset($pconfig['act']) ? $pconfig['act'] : ''); + if (isset($id) && $act == "delgroup" && isset($pconfig['groupname']) && $pconfig['groupname'] == $a_group[$id]['name']) { + // remove group + local_group_del($a_group[$id]); + $groupdeleted = $a_group[$id]['name']; + unset($a_group[$id]); + write_config(); + // reload page + redirectHeader("system_groupmanager.php"); + exit; + } elseif (isset($id) && $act == "delpriv" && isset($a_group[$id]['priv']) && is_array($a_group[$id]['priv'])) { + // remove by privid + foreach ($a_group[$id]['priv'] as $key => $value) { + if ($value == $pconfig['privid']) { + unset($a_group[$id]['priv'][$key]); } } - - $sys_groups = file_get_contents('/etc/group'); - foreach (explode("\n", $sys_groups) as $line) { - if (explode(":", $line)[0] == $_POST['groupname']) { - $input_errors[] = gettext("That groupname is reserved by the system."); - } - } - } - - if (!$input_errors) { - $group = array(); - if (isset($id) && $a_group[$id]) { - $group = $a_group[$id]; - } - - $group['name'] = $_POST['groupname']; - $group['description'] = $_POST['description']; - - if (empty($_POST['members'])) { - unset($group['member']); - } else { - $group['member'] = $_POST['members']; - } - - if (isset($id) && $a_group[$id]) { - $a_group[$id] = $group; - } else { - $group['gid'] = $config['system']['nextgid']++; - $a_group[] = $group; - } - - local_group_set($group); - - /* Refresh users in this group since their privileges may have changed. */ - if (is_array($group['member'])) { - $a_user = &$config['system']['user']; - foreach ($a_user as & $user) { - if (in_array($user['uid'], $group['member'])) { + if (isset($a_group[$id]['member']) && is_array($a_group[$id]['member'])) { + foreach ($a_group[$id]['member'] as $uid) { + $user = getUserEntryByUID($uid); + if ($user) { local_user_set($user); } } } - write_config(); + // reload page + redirectHeader("system_groupmanager.php?act=edit&groupid={$id}"); + exit; + } elseif (isset($pconfig['save'])) { + $input_errors = array(); - header("Location: system_groupmanager.php"); + /* input validation */ + $reqdfields = explode(" ", "name"); + $reqdfieldsn = array(gettext("Group Name")); + + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + + if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $pconfig['name'])) { + $input_errors[] = gettext("The group name contains invalid characters."); + } + + if (strlen($pconfig['name']) > 16) { + $input_errors[] = gettext("The group name is longer than 16 characters."); + } + + if (count($input_errors) == 0 && !isset($id)) { + /* make sure there are no dupes */ + foreach ($a_group as $group) { + if ($group['name'] == $pconfig['name']) { + $input_errors[] = gettext("Another entry with the same group name already exists."); + break; + } + } + + $sys_groups = file_get_contents('/etc/group'); + foreach (explode("\n", $sys_groups) as $line) { + if (explode(":", $line)[0] == $pconfig['name']) { + $input_errors[] = gettext("That groupname is reserved by the system."); + } + } + } + if (count($input_errors) == 0) { + $group = array(); + if (isset($id) && $a_group[$id]) { + $group = $a_group[$id]; + } + + $group['name'] = $pconfig['name']; + $group['description'] = $pconfig['description']; + + if (empty($pconfig['members'])) { + unset($group['member']); + } else { + $group['member'] = $pconfig['members']; + } + + if (isset($id) && $a_group[$id]) { + $a_group[$id] = $group; + } else { + $group['gid'] = $config['system']['nextgid']++; + $a_group[] = $group; + } + local_group_set($group); + + /* Refresh users in this group since their privileges may have changed. */ + if (is_array($group['member'])) { + $a_user = &$config['system']['user']; + foreach ($a_user as & $user) { + if (in_array($user['uid'], $group['member'])) { + local_user_set($user); + } + } + } + write_config(); + header("Location: system_groupmanager.php"); + exit; + } else { + // input errors, load page in edit mode + $act = 'edit'; + } + } else { + // POST without a valid action, redirect to overview + redirectHeader("system_groupmanager.php"); exit; } } -include("head.inc"); +$pgtitle = array(gettext('System'), gettext('Groups')); +legacy_html_escape_form_data($pconfig); +legacy_html_escape_form_data($a_group); + +include("head.inc"); ?> -
-
-
- - 0) { - print_input_errors($input_errors); - } - if (isset($savemsg)) { - print_info_box($savemsg); - } - ?> - -
-
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - + - '; - document.getElementById('groupid').value=''; - document.iform2.submit();"> - - - - + + + + + + + + + + + + + + + + + +
- - -
- /> -
- -
- -
- - - - - - -
-
-
- -
-
-
- - - -

- - - -
-
-
- -
-
- -
- - - - - - - 0) { + print_input_errors($input_errors); + } +?> +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + - - - - - - -
+ + +
+ /> +
+ + +
+ + + + + + + + + + + + + + +
 
+ + +
+ "> + + +

+ "> + + +
+ +
+ +
+ + + + + + + - - - - - - + + + + + - - - - - -
- - - - - -
+ +
- - - - -
-
  - " /> - " onclick="window.location.href='/system_groupmanager.php'" /> - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - + endif;?> + + + + +
- -
-

- -

-
+ + + +
+
- - - - - + endif;?> + + + +
- - -   -
+ " /> + " onclick="window.location.href='/system_groupmanager.php'" /> + + + + +
-
-   - - - - -   + - + else :?> +
+ + " /> + + + + + + + + + + + - - - - -
-
+ $i = 0; + foreach ($a_group as $group) :?> +
+ "> +   + + + + + "> + + - - - - - - + if ($group['scope'] != "system") :?> + + +
+ " data-toggle="tooltip" data-placement="left"> + + +
+ + +
+
+
+
+