Completed group export feature
authorJamie Cameron <jcameron@webmin.com>
Sat, 13 Dec 2008 22:37:34 +0000 (22:37 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 13 Dec 2008 22:37:34 +0000 (22:37 +0000)
useradmin/CHANGELOG
useradmin/export_exec.cgi
useradmin/gexport_exec.cgi [new file with mode: 0755]
useradmin/gexport_form.cgi [new file with mode: 0755]
useradmin/index.cgi
useradmin/lang/en
useradmin/user-lib.pl

index fe543b4..08a0278 100644 (file)
@@ -52,3 +52,4 @@ Improved support for default password changing options on AIX.
 ---- Changes since 1.440 ----
 Added a non-editable list of users who have this group as their primary to the Edit Group page.
 Added a Module Config option to use a text box for entering secondary group members, rather than the left/right user chooser.
+Created a page for exporting groups to a batch file, for importing on other systems.
index 3a614c9..dd89ea9 100755 (executable)
@@ -3,6 +3,7 @@
 # Actually output a user creation batch file
 
 require './user-lib.pl';
+&error_setup($text{'export_err'});
 $access{'export'} || &error($text{'export_ecannot'});
 &ReadParse();
 
diff --git a/useradmin/gexport_exec.cgi b/useradmin/gexport_exec.cgi
new file mode 100755 (executable)
index 0000000..7bcb34f
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/local/bin/perl
+# Actually output a group creation batch file
+
+require './user-lib.pl';
+&error_setup($text{'gexport_err'});
+$access{'export'} || &error($text{'gexport_ecannot'});
+&ReadParse();
+
+# Validate inputs
+if ($in{'to'}) {
+       $access{'export'} == 2 || &error($text{'export_ecannot'});
+       $in{'file'} =~ /^\/.+$/ || &error($text{'export_efile'});
+       &is_under_directory($access{'home'}, $in{'file'}) ||
+               &error($text{'export_efile2'});
+       }
+if ($in{'mode'} == 4) {
+       $in{'gid'} =~ /^\d*$/ || &error($text{'gexport_egid'});
+       $in{'gid2'} =~ /^\d*$/ || &error($text{'gexport_egid2'});
+       }
+
+# Open the output file
+if ($in{'to'}) {
+       &open_tempfile(OUT, ">$in{'file'}", 1) ||
+               &error(&text('export_eopen', $!));
+       $fh = "OUT";
+       &ui_print_header(undef, $text{'gexport_title'}, "");
+       }
+else {
+       print "Content-type: text/plain\n\n";
+       $fh = "STDOUT";
+       }
+
+# Work out which groups are allowed and selected
+@glist = &list_groups();
+@glist = &list_allowed_groups(\%access, \@glist);
+$faccess{'gedit_mode'} = $in{'mode'};
+$faccess{'gedit'} = $in{'mode'} == 2 ? $in{'can'} :
+                  $in{'mode'} == 3 ? $in{'cannot'} :
+                  $in{'mode'} == 4 ? $in{'gid'} : "";
+$faccess{'gedit2'} = $in{'mode'} == 4 ? $in{'gid2'} : "";
+@glist = &list_allowed_groups(\%faccess, \@glist);
+
+# Go through all allowed users
+$count = 0;
+foreach $g (@glist) {
+       @line = ( $g->{'group'}, $g->{'pass'}, $g->{'gid'},
+                 $g->{'members'} );
+       if ($fh eq "STDOUT") {
+               print $fh join(":", "create", @line),"\n";
+               }
+       else {
+               &print_tempfile($fh, join(":", "create", @line),"\n");
+               }
+       $count++;
+       }
+
+if ($in{'to'}) {
+       # All done
+       &close_tempfile($fh);
+       @st = stat($in{'file'});
+       print "<p>",&text('export_done',
+                 $count, "<tt>$in{'file'}</tt>", &nice_size($st[7])),"<p>\n";
+
+       &ui_print_footer("", $text{'index_return'});
+       }
+
diff --git a/useradmin/gexport_form.cgi b/useradmin/gexport_form.cgi
new file mode 100755 (executable)
index 0000000..1f65ba8
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/local/bin/perl
+# Display a form for exporting a batch file of groups
+
+require './user-lib.pl';
+$access{'export'} || &error($text{'gexport_ecannot'});
+&ui_print_header(undef, $text{'gexport_title'}, "", "gexport");
+
+print "$text{'export_desc'}<p>\n";
+print &ui_form_start("gexport_exec.cgi");
+print &ui_table_start($text{'gexport_header'}, undef, 2);
+
+# Destination
+if ($access{'export'} == 2) {
+       # Can be to a file
+       print &ui_table_row($text{'export_to'},
+               &ui_radio_table("to", 0,
+                       [ [ 0, $text{'export_show'} ],
+                         [ 1, $text{'export_file'},
+                               &ui_filebox("file", undef, 30) ] ]));
+       }
+else {
+       # Always in browser
+       print &ui_table_row($text{'export_to'}, $text{'export_show'});
+       }
+
+# Groups to include
+print &ui_table_row($text{'gexport_who'},
+    &ui_radio_table("mode", 0,
+       [ [ 0, $text{'acl_gedit_all'} ],
+         [ 2, $text{'acl_gedit_only'},
+           &ui_textbox("can", undef, 40)." ".
+           &group_chooser_button("can", 1) ],
+         [ 3, $text{'acl_gedit_except'},
+           &ui_textbox("cannot", undef, 40)." ".
+           &group_chooser_button("cannot", 1) ],
+         [ 4, $text{'acl_gedit_gid'},
+           &ui_textbox("gid", undef, 6)." - ".
+           &ui_textbox("gid2", undef, 6) ] ]));
+
+print &ui_table_end();
+print &ui_form_end([ [ undef, $text{'export_ok'} ] ]);
+
+&ui_print_footer("", $text{'index_return'});
+
index b0aa449..5c6f33e 100755 (executable)
@@ -144,7 +144,10 @@ elsif (@glist) {
        @glist = &sort_groups(\@glist, $config{'sort_mode'});
        if ($config{'display_mode'} == 1) {
                # Display group name, ID and members
-               &groups_table(\@glist, $formno++, 0, [ &get_group_buttons() ]);
+               @b = &get_group_buttons();
+               @left = grep { !/gbatch_form|gexport_form/ } @b;
+               @right = grep { /gbatch_form|gexport_form/ } @b;
+               &groups_table(\@glist, $formno++, 0, \@left, \@right);
                $no_group_buttons = 1;
                }
        else {
@@ -261,12 +264,19 @@ if ($access{'gcreate'} == 1) {
                push(@rv, $text{'index_nomoregroups'});
                }
        }
+push(@rv, "<a href=\"gbatch_form.cgi\">$text{'index_batch'}</a>")
+       if ($access{'batch'});
+push(@rv, "<a href=\"gexport_form.cgi\">$text{'index_export'}</a>")
+       if ($access{'export'});
 return @rv;
 }
 
 sub show_group_buttons
 {
 local @b = &get_group_buttons();
-print &ui_links_row(\@b);
+local @left = grep { !/gbatch_form|gexport_form/ } @b;
+local @right = grep { /gbatch_form|gexport_form/ } @b;
+local @grid = ( &ui_links_row(\@left), &ui_links_row(\@right) );
+print &ui_grid_table(\@grid, 2, 100, [ "align=left", "align=right" ]);
 }
 
index abdd7ad..8d8c25d 100644 (file)
@@ -425,7 +425,7 @@ who_from=Logged in from
 who_none=No users are currently logged in.
 
 export_title=Export Batch File
-export_desc=This form allows you to create a batch file containing some or all of the available users on the system. The file can be used on the Export Batch File page on another system to re-create the exported users, assuming that it uses the selected batch file format.
+export_desc=This form allows you to create a batch file containing some or all of the available users on the system. The file can be used on the Execute Batch File page on another system to re-create the exported users, assuming that it uses the selected batch file format.
 export_header=Batch user export options
 export_to=Batch file destination
 export_show=Display in browser
@@ -443,6 +443,16 @@ export_egid2=Invalid second GID in range
 export_done=Successfully exported $1 users to the file $2 ($3).
 export_pft=Batch file format
 export_who=Users to export
+export_ecannot=You are not allowed to export users
+
+gexport_title=Export Groups Batch File
+gexport_desc=This form allows you to create a batch file containing some or all of the available groups on the system. The file can be used on the Execute Group Batch File page on another system to re-create the exported groups.
+gexport_header=Batch group export options
+gexport_who=Groups to export
+gexport_ecannot=You are not allowed to export groups
+gexport_err=Failed to export group batch file
+gexport_egid=Invalid first GID in range
+gexport_egid2=Invalid second GID in range
 
 pft_0=Classic <tt>passwd</tt> file only
 pft_1=BSD <tt>master.passwd</tt> file
index a8a661d..0817930 100644 (file)
@@ -1996,11 +1996,11 @@ if ($anyedit) {
        }
 }
 
-# groups_table(&groups, [form], [no-buttons], [&otherlinks])
+# groups_table(&groups, [form], [no-buttons], [&otherlinks], [&rightlinks])
 # Prints a table of groups, possibly with checkboxes and a delete button
 sub groups_table
 {
-local ($groups, $formno, $noboxes, $links) = @_;
+local ($groups, $formno, $noboxes, $links, $rightlinks) = @_;
 
 # Work out if any groups can be edited
 local $anyedit;
@@ -2019,7 +2019,8 @@ if ($anyedit && $access{'gdelete'}) {
                        &select_invert_link("gd", $formno) );
        }
 push(@linksrow, @$links);
-print &ui_links_row(\@linksrow);
+local @grid = ( &ui_links_row(\@linksrow), &ui_links_row($rightlinks) );
+print &ui_grid_table(\@grid, 2, 100, [ "align=left", "align=right" ]);
 
 local @tds = $anyedit ? ( "width=5" ) : ( );
 push(@tds, "width=15%", "width=10%");