#!/usr/bin/perl # Execute create/modify/delete group commands in a batch file require './user-lib.pl'; $access{'batch'} || &error($text{'gbatch_ecannot'}); if ($ENV{'REQUEST_METHOD'} eq 'GET') { &ReadParse(); } else { &ReadParseMime(); } if ($in{'source'} == 0) { $data = $in{'file'}; $data =~ /\S/ || &error($text{'batch_efile'}); } elsif ($in{'source'} == 1) { open(LOCAL, "<$in{'local'}") || &error($text{'batch_elocal'}); while(<LOCAL>) { $data .= $_; } close(LOCAL); } elsif ($in{'source'} == 2) { $data = $in{'text'}; $data =~ /\S/ || &error($text{'batch_etext'}); } &ui_print_unbuffered_header(undef, $text{'gbatch_title'}, ""); # Force defaults for save options $in{'chgid'} = 1 if (!$access{'chgid'}); # Work out a good base GID for new groups &build_group_used(\%gused, \%gtaken); $newgid = int($config{'base_gid'} > $access{'lowgid'} ? $config{'base_gid'} : $access{'lowgid'}); # Process the file &batch_start() if ($in{'batch'}); &lock_user_files(); $lnum = $created = $modified = $deleted = 0; print "<pre>\n"; $pft = &passfiles_type(); foreach $line (split(/[\r\n]+/, $data)) { $lnum++; $line =~ s/^\s*#.*$//; next if ($line !~ /\S/); local @line = split(/:/, $line, -1); local %group; if ($line[0] eq 'create') { # Creating a new group # Validate line if (!$line[1]) { print &text('batch_eline', $lnum),"\n"; next; } if (@line != 5) { print &text('batch_elen', $lnum, 5),"\n"; next; } if ($line[1] !~ /^[^:\t]+$/) { print &text('gbatch_egroupname', $lnum),"\n"; next; } $group{'group'} = $line[1]; if ($gtaken{$group{'group'}}) { print &text('gbatch_egroup', $lnum, $group{'group'}),"\n"; next; } if ($line[3] !~ /^\d+$/) { # make up a GID while($gused{$newgid}) { $newgid++; } $group{'gid'} = $newgid; } else { # use the given UID if ($gused{$line[3]} && !$access{'gmultiple'}) { print &text('gbatch_ecaccess', $lnum, $text{'gsave_egidused2'}),"\n"; next; } $group{'gid'} = $line[3]; } $gused{$group{'gid'}}++; $group{'members'} = $line[4]; # Check access control restrictions if (!$access{'gcreate'}) { print &text('gbatch_ecaccess', $lnum, $text{'gsave_ecreate'}); next; } local $ch = &check_group(\%group); if ($ch) { print &text('gbatch_ecaccess', $lnum, $ch),"\n"; next; } if ($line[2] eq '') { # No password needed $group{'pass'} = ''; $group{'passmode'} = 0; } else { # Normal password $group{'pass'} = &encrypt_password($line[2]); $group{'passmode'} = 3; $group{'plainpass'} = $line[2]; } # Run the before command &set_user_envs(\%group, 'CREATE_GROUP'); $merr = &making_changes(); &error(&text('gsave_emaking', "<tt>$merr</tt>")) if (defined($merr)); # Create the group! &create_group(\%group); # All done &made_changes(); # Call other modules, ignoring any failures $error_must_die = 1; eval { &other_modules("useradmin_create_group", \%group) if ($access{'cothers'} == 1 && $in{'others'} || $access{'cothers'} == 0); }; $other_err = $@; $error_must_die = 0; print "<b>",&text('gbatch_created', $group{'group'}),"</b>\n"; print "<b><i>",&text('batch_eother', $other_err),"</i></b>\n" if ($other_err); $created++; } elsif ($line[0] eq 'delete') { # Deleting an existing group if (@line != 2) { print &text('batch_elen', $lnum, 2),"\n"; next; } local @glist = &list_groups(); local ($group) = grep { $_->{'group'} eq $line[1] } @glist; if (!$group) { print &text('gbatch_enogroup', $lnum, $line[1]),"\n"; next; } # Check if deletion is allowed if (!&can_edit_group(\%access, $group)) { print &text('gbatch_edaccess', $lnum, $text{'gdel_egroup'}),"\n"; next; } if (!$config{'delete_root'} && $group->{'gid'} <= 10) { print &text('gbatch_edaccess', $lnum, $text{'gdel_egroup'}),"\n"; next; } # Check if has primary members local $prim; foreach $u (&list_users()) { if ($u->{'gid'} == $group->{'gid'}) { $prim = $u; last; } } if ($prim) { print &text('gbatch_eprimary', $lnum, $prim->{'user'}),"\n"; next; } # Run the before command &set_user_envs($group, 'DELETE_GROUP'); $merr = &making_changes(); &error(&text('usave_emaking', "<tt>$merr</tt>")) if (defined($merr)); # Delete from other modules, ignoring errors $error_must_die = 1; eval { &other_modules("useradmin_delete_group", $group) if ($access{'dothers'} == 1 && $in{'others'} || $access{'dothers'} == 0); }; $other_err = $@; $error_must_die = 0; # Delete the user entry &delete_group($group); &made_changes(); print "<b>",&text('gbatch_deleted',$group->{'group'}),"</b>\n"; print "<b><i>",&text('batch_eother', $other_err),"</i></b>\n" if ($other_err); $deleted++; } elsif ($line[0] eq 'modify') { # Modifying an existing group if (@line != 6) { print &text('batch_elen', $lnum, 6),"\n"; next; } local @glist = &list_groups(); local ($group) = grep { $_->{'group'} eq $line[1] } @glist; if (!$group) { print &text('gbatch_enogroup', $lnum, $line[1]),"\n"; next; } %oldgroup = %group = %$group; $user{'olduser'} = $user->{'user'}; if (!&can_edit_group(\%access, \%group)) { print &text('gbatch_emaccess', $lnum, $text{'gsave_eedit'}),"\n"; next; } # Update supplied fields if ($line[2] ne '') { if (!$access{'grename'}) { print &text('gbatch_erename', $lnum, $line[1]),"\n"; } $group{'group'} = $line[2]; } if ($line[3] ne '') { # New normal password $group{'pass'} = &encrypt_password($line[3]); $group{'passmode'} = 3; $group{'plainpass'} = $line[3]; } else { # No change $group{'passmode'} = 4; } $group{'gid'} = $line[4] if ($line[4] ne ''); if ($line[5] =~ /^\s+$/ || $line[5] eq 'NONE') { # No members $group{'members'} = ''; } elsif ($line[5]) { $group{'members'} = $line[5]; } # Check access control restrictions local $ch = &check_group(\%group, \%oldgroup); if ($ch) { print &text('gbatch_emaccess', $lnum, $ch),"\n"; next; } # Run the before command &set_user_envs(\%group, 'MODIFY_GROUP'); $merr = &making_changes(); &error(&text('usave_emaking', "<tt>$merr</tt>")) if (defined($merr)); # Change GIDs if ($oldgroup{'gid'} != $group{'gid'} && $in{'chgid'}) { if ($in{'chgid'} == 1) { # Do all the home directories of members &change_all_home_groups( $oldgroup{'gid'}, $group{'gid'}, [ split(/,/, $group{'members'}) ]); } else { # Do all files in this group from the root dir &recursive_change("/", -1, $oldgroup{'gid'}, -1, $group{'gid'}); } } # Actually modify the group &modify_group(\%oldgroup, \%group); &made_changes(); # Modify in other modules, ignoring errors $error_must_die = 1; eval { &other_modules("groupadmin_modify_group", \%group, \%oldgroup) if ($access{'mothers'} == 1 && $in{'others'} || $access{'mothers'} == 0); }; $error_must_die = 0; $other_err = $@; print "<b>",&text('batch_modified',$oldgroup{'group'}),"</b>\n"; print "<b><i>",&text('batch_eother', $other_err),"</i></b>\n" if ($other_err); $modified++; } else { print &text('batch_eaction', $lnum, $line[0]),"\n"; next; } } print "</pre>\n"; &batch_end() if ($in{'batch'}); &unlock_user_files(); &webmin_log("gbatch", undef, $in{'source'} == 1 ? $in{'local'} : undef, { 'created' => $created, 'modified' => $modified, 'deleted' => $deleted, 'lnum' => $lnum } ); &ui_print_footer("gbatch_form.cgi", $text{'batch_return'}, "index.cgi?mode=groups", $text{'index_return'}); # check_group(\%group, [\%oldgroup]) # Check access control restrictions for a group sub check_group { # check if gid is within range if ($access{'lowgid'} && $_[0]->{'gid'} < $access{'lowgid'}) { return &text('usave_elowgid', $access{'lowuid'}); } if ($access{'hiuid'} && $_[0]->{'uid'} > $access{'hiuid'}) { return &text('usave_ehiuid', $access{'hiuid'}); } if ($_[1] && !$access{'ggid'} && $_[1]->{'gid'} != $_[0]->{'gid'}) { return $text{'gsave_eggid'}; } return undef; }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
help | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 5.66 KB | 0644 |
|
acl_security.pl | File | 13.74 KB | 0755 |
|
aix-lib.pl | File | 1.17 KB | 0755 |
|
backup_config.pl | File | 749 B | 0755 |
|
batch_exec.cgi | File | 17.21 KB | 0755 |
|
batch_form.cgi | File | 2.42 KB | 0755 |
|
cgi_args.pl | File | 477 B | 0755 |
|
config-aix | File | 703 B | 0644 |
|
config-cobalt-linux | File | 710 B | 0644 |
|
config-coherent-linux | File | 657 B | 0644 |
|
config-corel-linux | File | 665 B | 0644 |
|
config-debian-linux | File | 665 B | 0644 |
|
config-freebsd | File | 684 B | 0644 |
|
config-generic-linux | File | 677 B | 0644 |
|
config-gentoo-linux | File | 637 B | 0644 |
|
config-hpux | File | 579 B | 0644 |
|
config-irix | File | 757 B | 0644 |
|
config-macos | File | 581 B | 0644 |
|
config-mandrake-linux | File | 662 B | 0644 |
|
config-msc-linux | File | 657 B | 0644 |
|
config-netbsd | File | 623 B | 0644 |
|
config-open-linux | File | 687 B | 0644 |
|
config-openSUSE-Linux-15.0-ALL | File | 715 B | 0644 |
|
config-openbsd | File | 636 B | 0644 |
|
config-openmamba-linux | File | 657 B | 0644 |
|
config-openserver | File | 841 B | 0644 |
|
config-osf1 | File | 579 B | 0644 |
|
config-pardus-linux | File | 665 B | 0644 |
|
config-redhat-linux-15.0-ALL | File | 659 B | 0644 |
|
config-redhat-linux-ALL-14.9 | File | 657 B | 0644 |
|
config-slackware-linux | File | 663 B | 0644 |
|
config-sol-linux | File | 657 B | 0644 |
|
config-solaris | File | 631 B | 0644 |
|
config-suse-linux | File | 677 B | 0644 |
|
config-suse-linux-9.0-ALL | File | 715 B | 0644 |
|
config-trustix-linux | File | 657 B | 0644 |
|
config-turbo-linux | File | 677 B | 0644 |
|
config-united-linux | File | 677 B | 0644 |
|
config-unixware | File | 595 B | 0644 |
|
config.info | File | 4.05 KB | 0644 |
|
config.info.bg | File | 7.87 KB | 0644 |
|
config.info.ca | File | 4.82 KB | 0644 |
|
config.info.cs | File | 4.21 KB | 0644 |
|
config.info.da | File | 3.7 KB | 0644 |
|
config.info.de | File | 4.65 KB | 0644 |
|
config.info.es | File | 4.34 KB | 0644 |
|
config.info.fa | File | 6.04 KB | 0644 |
|
config.info.fr | File | 2.77 KB | 0644 |
|
config.info.hu | File | 0 B | 0644 |
|
config.info.ja | File | 4.96 KB | 0644 |
|
config.info.nl | File | 4.61 KB | 0644 |
|
config.info.no | File | 4.12 KB | 0644 |
|
config.info.pl | File | 3.01 KB | 0644 |
|
config.info.pt_BR | File | 4.36 KB | 0644 |
|
config.info.ru | File | 4.61 KB | 0644 |
|
config.info.sv | File | 1.06 KB | 0644 |
|
config.info.tr | File | 3.69 KB | 0644 |
|
config.info.uk | File | 4.58 KB | 0644 |
|
config.info.zh | File | 961 B | 0644 |
|
config.info.zh_TW | File | 909 B | 0644 |
|
cpan_modules.pl | File | 256 B | 0755 |
|
defaultacl | File | 358 B | 0644 |
|
delete_group.cgi | File | 2.18 KB | 0755 |
|
delete_user.cgi | File | 4.67 KB | 0755 |
|
edit_group.cgi | File | 4.97 KB | 0755 |
|
edit_user.cgi | File | 18.46 KB | 0755 |
|
export_exec.cgi | File | 2.9 KB | 0755 |
|
export_form.cgi | File | 1.77 KB | 0755 |
|
freebsd-lib.pl | File | 1.74 KB | 0755 |
|
gbatch_exec.cgi | File | 8.1 KB | 0755 |
|
gbatch_form.cgi | File | 1.59 KB | 0755 |
|
gexport_exec.cgi | File | 1.73 KB | 0755 |
|
gexport_form.cgi | File | 1.26 KB | 0755 |
|
help.html | File | 6.79 KB | 0644 |
|
hpux-lib.pl | File | 1.02 KB | 0755 |
|
index.cgi | File | 7.38 KB | 0755 |
|
irix-lib.pl | File | 1.09 KB | 0755 |
|
linux-lib.pl | File | 4.75 KB | 0755 |
|
list_logins.cgi | File | 1.55 KB | 0755 |
|
list_who.cgi | File | 945 B | 0755 |
|
log_parser.pl | File | 1.68 KB | 0755 |
|
macos-lib.pl | File | 3.15 KB | 0755 |
|
mass_delete_group.cgi | File | 2.41 KB | 0755 |
|
mass_delete_user.cgi | File | 7.65 KB | 0755 |
|
md5-lib.pl | File | 7.58 KB | 0755 |
|
module.info | File | 544 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 155 B | 0644 |
|
module.info.ar | File | 173 B | 0644 |
|
module.info.ar.auto | File | 34 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 247 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 228 B | 0644 |
|
module.info.ca | File | 117 B | 0644 |
|
module.info.ca.auto | File | 27 B | 0644 |
|
module.info.cs | File | 30 B | 0644 |
|
module.info.cs.auto | File | 134 B | 0644 |
|
module.info.da | File | 27 B | 0644 |
|
module.info.da.auto | File | 116 B | 0644 |
|
module.info.de | File | 133 B | 0644 |
|
module.info.de.auto | File | 25 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 258 B | 0644 |
|
module.info.es | File | 26 B | 0644 |
|
module.info.es.auto | File | 136 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 175 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 220 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 156 B | 0644 |
|
module.info.fr | File | 32 B | 0644 |
|
module.info.fr.auto | File | 154 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 182 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 147 B | 0644 |
|
module.info.hu | File | 37 B | 0644 |
|
module.info.hu.auto | File | 156 B | 0644 |
|
module.info.it | File | 0 B | 0644 |
|
module.info.it.auto | File | 129 B | 0644 |
|
module.info.ja | File | 39 B | 0644 |
|
module.info.ja.auto | File | 175 B | 0644 |
|
module.info.ko | File | 29 B | 0644 |
|
module.info.ko.auto | File | 142 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 166 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 167 B | 0644 |
|
module.info.ms | File | 124 B | 0644 |
|
module.info.ms.auto | File | 26 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 133 B | 0644 |
|
module.info.nl | File | 30 B | 0644 |
|
module.info.nl.auto | File | 123 B | 0644 |
|
module.info.no | File | 27 B | 0644 |
|
module.info.no.auto | File | 116 B | 0644 |
|
module.info.pl | File | 122 B | 0644 |
|
module.info.pl.auto | File | 31 B | 0644 |
|
module.info.pt | File | 30 B | 0644 |
|
module.info.pt.auto | File | 124 B | 0644 |
|
module.info.pt_BR | File | 30 B | 0644 |
|
module.info.pt_BR.auto | File | 130 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 167 B | 0644 |
|
module.info.ru | File | 49 B | 0644 |
|
module.info.ru.auto | File | 208 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 177 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 163 B | 0644 |
|
module.info.sv | File | 31 B | 0644 |
|
module.info.sv.auto | File | 128 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 260 B | 0644 |
|
module.info.tr | File | 31 B | 0644 |
|
module.info.tr.auto | File | 147 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 247 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 232 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 177 B | 0644 |
|
module.info.zh | File | 24 B | 0644 |
|
module.info.zh.auto | File | 103 B | 0644 |
|
module.info.zh_TW | File | 30 B | 0644 |
|
module.info.zh_TW.auto | File | 109 B | 0644 |
|
my_group_chooser.cgi | File | 6.9 KB | 0755 |
|
my_user_chooser.cgi | File | 6.56 KB | 0755 |
|
netbsd-lib.pl | File | 1.74 KB | 0755 |
|
openbsd-lib.pl | File | 1.74 KB | 0755 |
|
openserver-lib.pl | File | 1.18 KB | 0755 |
|
osf1-lib.pl | File | 1.01 KB | 0755 |
|
prefs.info | File | 134 B | 0644 |
|
rbac-mapping | File | 190 B | 0644 |
|
save_group.cgi | File | 4.86 KB | 0755 |
|
save_user.cgi | File | 20.39 KB | 0755 |
|
search_group.cgi | File | 991 B | 0755 |
|
search_user.cgi | File | 1.33 KB | 0755 |
|
solaris-lib.pl | File | 1.78 KB | 0755 |
|
unixware-lib.pl | File | 1.13 KB | 0755 |
|
user-lib.pl | File | 71.71 KB | 0755 |
|