More ui-libification of users and groups module, plus generic 'are you sure' function
authorJamie Cameron <jcameron@webmin.com>
Mon, 25 Aug 2008 21:44:00 +0000 (21:44 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 25 Aug 2008 21:44:00 +0000 (21:44 +0000)
ui-lib.pl
useradmin/delete_group.cgi
useradmin/delete_user.cgi
useradmin/edit_user.cgi
useradmin/help/forcechange.html [new file with mode: 0644]
useradmin/lang/en
useradmin/mass_delete_group.cgi
useradmin/mass_delete_user.cgi

index 258b944..1307da7 100644 (file)
--- a/ui-lib.pl
+++ b/ui-lib.pl
@@ -550,7 +550,6 @@ return $rv;
 # Returns HTML for selecting many of many from a list. By default, this is
 # implemented using two <select> lists and Javascript buttons to move elements
 # between them. The resulting input value is \n separated.
-# XXX IE testing
 sub ui_multi_select
 {
 return &theme_ui_multi_select(@_) if (defined(&theme_ui_multi_select));
@@ -1444,9 +1443,13 @@ return "" if (!@$rows);
 local $rv = "<table>\n";
 foreach my $r (@$rows) {
        $rv .= "<tr>\n";
-       $rv .= "<td valign=top><b>".&ui_oneradio($name, $r->[0], $r->[1],
-                                  $r->[0] eq $sel)."</b></td>\n";
-       $rv .= "<td valign=top>".$r->[2]."</td>\n";
+       $rv .= "<td valign=top".(defined($r->[2]) ? "" : " colspan=2").
+              "><b>".
+              &ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel).
+              "</b></td>\n";
+       if (defined($r->[2])) {
+               $rv .= "<td valign=top>".$r->[2]."</td>\n";
+               }
        $rv .= "</tr>\n";
        }
 $rv .= "</table>\n";
@@ -1486,6 +1489,31 @@ return &theme_ui_hr() if (defined(&theme_ui_hr));
 return "<hr>\n";
 }
 
+# ui_confirmation_form(cgi, message, &hiddens, [&buttons], [&otherinputs],
+#                      [extra-warning])
+# Returns HTML for a form asking for confirmation before performing some
+# action, such as deleting a user.
+sub ui_confirmation_form
+{
+local ($cgi, $message, $hiddens, $buttons, $others, $warning) = @_;
+local $rv;
+$rv .= "<center class=ui_confirmation>\n";
+$rv .= &ui_form_start($cgi, "post");
+foreach my $h (@$hiddens) {
+       $rv .= &ui_hidden(@$h);
+       }
+$rv .= "<b>$message</b><p>\n";
+if ($warning) {
+       $rv .= "<b><font color=#ff0000>$warning</font></b><p>\n";
+       }
+if ($others) {
+       $rv .= $others."<p>\n";
+       }
+$rv .= &ui_form_end($buttons);
+$rv .= "</center>\n";
+return $rv;
+}
+
 ####################### javascript functions
 
 # js_disable_input(&disable-inputs, &enable-inputs, [tag])
index 967f6f7..cce49ac 100755 (executable)
@@ -15,7 +15,7 @@ $access{'gdelete'} || &error($text{'gdel_egroup'});
 &ui_print_header(undef, $text{'gdel_title'}, "");
 
 if (!$config{'delete_root'} && $group->{'gid'} <= 10) {
-       print "<p> <b>$text{'gdel_eroot'}</b> <p>\n";
+       print "<b>$text{'gdel_eroot'}</b> <p>\n";
        &ui_print_footer("", $text{'index_return'});
        exit;
        }
@@ -23,9 +23,8 @@ if (!$config{'delete_root'} && $group->{'gid'} <= 10) {
 if ($in{'confirmed'}) {
        # Check for repeat click
        if ($group->{'group'} ne $in{'group'} || $in{'group'} eq '') {
-               print "<p> <b>$text{'gdel_ealready'}</b> <p>\n";
-               print &ui_hr();
-               &footer("", $text{'index_return'});
+               print "<b>$text{'gdel_ealready'}</b> <p>\n";
+               &ui_print_footer("", $text{'index_return'});
                exit;
                }
 
@@ -64,23 +63,20 @@ else {
                if ($u->{'gid'} == $group->{'gid'}) {
                        print "<b>",&text('gdel_eprimary', $u->{'user'}),
                              "</b> <p>\n";
-                       print &ui_hr();
-                       &footer("", $text{'index_return'});
+                       &ui_print_footer("", $text{'index_return'});
                        exit;
                        }
                }
 
        # Ask if the user is sure
-       print "<center>\n";
-       print &ui_form_start("delete_group.cgi");
-       print &ui_hidden("num", $in{'num'});
-       print &ui_hidden("group", $group->{'group'});
-       print "<b>",&text('gdel_sure', $group->{'group'}),"</b><p>\n";
-       print &ui_submit($text{'gdel_del'}, "confirm"),"<br>\n";
-       print &ui_checkbox("others", 1, $text{'gdel_dothers'},
-                          $config{'default_other'});
-       print &ui_form_end();
-       print "</center>\n";
+       print &ui_confirmation_form("delete_group.cgi",
+               &text('gdel_sure', $group->{'group'}),
+               [ [ "num", $in{'num'} ],
+                 [ "group", $group->{'group'} ] ],
+               [ [ "confirm", $text{'gdel_del'} ] ],
+               ui_checkbox("others", 1, $text{'gdel_dothers'},
+                           $config{'default_other'}),
+               );
 
        &ui_print_footer("", $text{'index_return'});
        }
index 674a4e1..93277eb 100755 (executable)
@@ -109,54 +109,46 @@ done:
 else {
        # Check if something has changed
        if ($user->{'user'} ne $in{'user'}) {
-               print "<p> <b>$text{'udel_echanged'}</b> <p>\n";
+               print "<b>$text{'udel_echanged'}</b> <p>\n";
                &ui_print_footer("", $text{'index_return'});
                exit;
                }
 
        # Ask if the user is sure
-       print "<form action=delete_user.cgi>\n";
-       print "<input type=hidden name=num value=\"$in{'num'}\">\n";
-       print "<input type=hidden name=user value=\"$user->{'user'}\">\n";
-       print "<input type=hidden name=confirmed value=1>\n";
-
-       if ($user->{'home'} ne "/" && -d $user->{'home'} && $access{'delhome'} != 0) {
+       @buts = ( );
+       if ($user->{'home'} ne "/" && -d $user->{'home'} &&
+           $access{'delhome'} != 0) {
                # Has a home directory, so check for files owned by others
                $size = &disk_usage_kb($user->{'home'});
-               print "<center><b>",&text('udel_sure', $user->{'user'},
-                          "<tt>$user->{'home'}</tt>", &nice_size($size*1024)),
-                          "</b><p>\n";
+               $msg = &text('udel_sure', $user->{'user'},
+                           "<tt>$user->{'home'}</tt>", &nice_size($size*1024));
                if ($access{'delhome'} != 1) {
-                       print "<input type=submit value=\"$text{'udel_del1'}\">\n";
+                       push(@buts, [ undef, $text{'udel_del1'} ]);
                        }
-               print "<input name=delhome type=submit ",
-                     "value=\"$text{'udel_del2'}\">\n";
+               push(@buts, [ "delhome", $text{'udel_del2'} ]);
 
                # check for files owned by other users
-               @others = &backquote_command("find ".quotemeta($user->{'home'})." ! -user $user->{'uid'} 2>/dev/null", 1);
-               if (@others) {
-                       print "<br><b><font color=#ff0000>",
-                             &text('udel_others', "<tt>$user->{'home'}</tt>", scalar(@others)),
-                             "</font></b><br>\n";
-                       }
+               @others = &backquote_command("find ".quotemeta($user->{'home'}).
+                       " ! -user $user->{'uid'} 2>/dev/null", 1);
                }
        else {
                # No home directory
-               print "<center><b>",&text('udel_sure2',
-                                          $user->{'user'}),"</b><p>\n";
-               print "<input type=submit value=\"$text{'udel_del1'}\">\n";
-               }
-       print "<br>\n";
-       if ($access{'dothers'} == 1) {
-               printf "<input type=checkbox name=others value=1 %s> %s<br>\n",
-                       $config{'default_other'} ? "checked" : "",
-                       $text{'udel_dothers'};
+               $msg = &text('udel_sure2', $user->{'user'});
+               push(@buts, [ undef, $text{'udel_del1'} ]);
                }
-       if ($user->{'user'} eq 'root') {
-               print "<center><b><font color=#ff0000>$text{'udel_root'}",
-                     "</font></b><p></center>\n";
-               }
-       print "</form></center>\n";
+
+       print &ui_confirmation_form("delete_user.cgi", $msg,
+               [ [ "num", $in{'num'} ],
+                 [ "user", $user->{'user'} ],
+                 [ "confirmed", 1 ] ],
+               \@buts,
+               $access{'dothers'} == 1 ?
+                       &ui_checkbox("others", 1, $text{'udel_dothers'},
+                                     $config{'default_other'}) : "",
+               (@others ? &text('udel_others', "<tt>$user->{'home'}</tt>",
+                                                   scalar(@others))."<p>" : "").
+               ($user->{'user'} eq 'root' ? $text{'udel_root'} : ""),
+               );
 
        &ui_print_footer("", $text{'index_return'});
        }
index 63d46f6..be7a398 100755 (executable)
@@ -34,9 +34,6 @@ if ($shells{'shells'}) {
                }
        close(SHELLS);
        }
-if (%uinfo) {
-       push(@shlist, $uinfo{'shell'});
-       }
 
 # Start of the form
 print &ui_form_start("save_user.cgi", "post");
@@ -50,7 +47,7 @@ if ($n eq "" && $config{'new_user_group'} && $access{'gcreate'}) {
        }
 if ($access{'urename'} || $n eq "") {
        print &ui_table_row(&hlink($text{'user'}, "user"),
-               &ui_textbox("user", $uinfo{'user'}, 20, 0, undef,
+               &ui_textbox("user", $uinfo{'user'}, 40, 0, undef,
                            "onChange='$onch'"));
        }
 else {
@@ -93,7 +90,7 @@ if ($config{'extra_real'}) {
        # Has separate name, office, work and home phone parts
        local @real = split(/,/, $uinfo{'real'}, 5);
        print &ui_table_row(&hlink($text{'real'}, "real"),
-               &ui_textbox("real", $real[0], 20));
+               &ui_textbox("real", $real[0], 40));
 
        print &ui_table_row(&hlink($text{'office'}, "office"),
                &ui_textbox("office", $real[1], 20));
@@ -130,7 +127,7 @@ else {
                        [ [ 1, $text{'uedit_auto'}."<br>" ],
                          [ 0, $text{'uedit_manual'}." ".
                               &ui_filebox("home", $hb ? "" : $uinfo{'home'},
-                                          25, 0, undef, undef, 1) ] ]);
+                                          40, 0, undef, undef, 1) ] ]);
                }
        else {
                # Allow any directory
@@ -142,13 +139,17 @@ print &ui_table_row(&hlink($text{'home'}, "home"),
        $homefield);
 
 # Show shell drop-down
+push(@shlist, $uinfo{'shell'}) if (%uinfo && $uinfo{'shell'});
 if ($access{'shells'} ne "*") {
-       push(@shlist, $uinfo{'shell'} || [ "", "&lt;None&gt;" ]) if (%uinfo);
        push(@shlist, split(/\s+/, $access{'shells'}));
        $shells = 1;
        }
 $shells = 1 if ($access{'noother'});
 @shlist = &unique(@shlist);
+if (%uinfo && !$uinfo{'shell'}) {
+       # No shell!
+       push(@shlist, [ "", "&lt;None&gt;" ]);
+       }
 push(@shlist, [ "*", $text{'uedit_other'} ]) if (!$shells);
 print &ui_table_row(&hlink($text{'shell'}, "shell"),
        &ui_select("shell", $uinfo{'shell'}, \@shlist, 1, 0, 0, 0,
@@ -262,16 +263,13 @@ elsif (($pft == 2 || $pft == 5) && $access{'peopt'}) {
        # password expiry and so on
        print &ui_table_start($text{'uedit_passopts'}, "width=100%", 4, \@tds);
 
-       # Last change date, with checkbox to force change
+       # Last change date
        local $max = $n eq "" ? $config{'default_max'} : $uinfo{'max'};
        print &ui_table_row(&hlink($text{'change'}, "change"),
                ($uinfo{'change'} ? &make_date(timelocal(
-                                       gmtime($uinfo{'change'} * 60*60*24)),1) :
+                                      gmtime($uinfo{'change'} * 60*60*24)),1) :
                 $n eq "" ? $text{'uedit_never'} :
-                           $text{'uedit_unknown'}).
-                (($max || $gconfig{'os_type'} =~ /-linux$/) && $pft == 2 ?
-                   &ui_checkbox("forcechange", 1, $text{'uedit_forcechange'}) :
-                   ""));
+                           $text{'uedit_unknown'}));
 
        if ($pft == 2) {
                # Expiry date
@@ -319,7 +317,13 @@ elsif (($pft == 2 || $pft == 5) && $access{'peopt'}) {
                        &ui_textbox("inactive", $n eq "" ?
                                        $config{'default_inactive'} :
                                        $uinfo{'inactive'}, 5));
+               }
 
+       # Force change at next login
+       if (($max || $gconfig{'os_type'} =~ /-linux$/) && $pft == 2) {
+               print &ui_table_row(
+                       &hlink($text{'uedit_forcechange'}, 'forcechange'),
+                       &ui_yesno_radio("forcechange", 0));
                }
 
        print &ui_table_end();
diff --git a/useradmin/help/forcechange.html b/useradmin/help/forcechange.html
new file mode 100644 (file)
index 0000000..f1b4e99
--- /dev/null
@@ -0,0 +1,8 @@
+<header>Force change at next login?</header>
+
+If <b>Yes</b> is selected here, the user will be forced to change his password
+at the next login via SSH or Usermin. This is useful for setting a temporary
+password, for just the first login. <p>
+
+<footer>
+
index 13169fc..47b9f76 100644 (file)
@@ -450,6 +450,7 @@ pft_6=MacOS NetInfo database
 umass_title=Delete Users
 umass_err=Failed to delete users
 umass_sure=Are you sure you want to delete the $1 selected users? Their home directories contain $2 of files.
+umass_sure2=Are you sure you want to delete the $1 selected users?
 umass_euser=You are not allowed to delete the user $1
 umass_enone=No users selected
 umass_del1=Delete Users
index ec12fd2..9526301 100755 (executable)
@@ -81,17 +81,14 @@ else {
                }
 
        # Ask if the user is sure
-       print "<form action=mass_delete_group.cgi method=post>\n";
-       foreach $group (@dlist) {
-               print "<input type=hidden name=d value='$group->{'group'}'>\n";
-               }
-       print "<input type=hidden name=confirmed value=1>\n";
-       print "<center><b>",&text('gmass_sure', scalar(@dlist)),"</b><p>\n";
-       print "<input type=submit value=\"$text{'gdel_del'}\">\n";
-       print "<br><input type=checkbox name=others value=1 checked> ",
-             "$text{'gdel_dothers'}<br>\n";
-       print "</center><p>\n";
-       print "</form>\n";
+       print &ui_confirmation_form("mass_delete_group.cgi",
+               &text('gmass_sure', scalar(@dlist)),
+               [ [ "confirmed", 1 ],
+                 map { [ "gd", $_->{'group'} ] } @dlist ],
+               [ [ undef, $text{'gdel_del'} ] ],
+               &ui_checkbox("others", 1, $text{'gdel_dothers'}, 1),
+               );
+
        &ui_print_footer("", $text{'index_return'});
        }
 
index 955afa5..d678df3 100755 (executable)
@@ -65,20 +65,14 @@ if ($in{'disable'}) {
                &ui_print_footer("", $text{'index_return'});
                }
        else {
-               # Ask if the user is sure
-               print "<form action=mass_delete_user.cgi method=post>\n";
-               print "<input type=hidden name=confirmed value=1>\n";
-               print "<input type=hidden name=disable value=1>\n";
-               foreach $user (@dlist) {
-                       print "<input type=hidden name=d value='$user->{'user'}'>\n";
-                       }
-
-               # Show buttons
-               print "<center><b>",&text('dmass_sure',
-                                  scalar(@dlist)),"</b><p>\n";
-               print "<input type=submit value=\"$text{'dmass_dis'}\">\n";
-               print "<br>\n";
-               print "</form></center>\n";
+               # Ask if the user is sure he wants to disable
+               print &ui_confirmation_form("mass_delete_user.cgi",
+                       &text('dmass_sure', scalar(@dlist)),
+                       [ [ "confirmed", 1 ],
+                         [ "disable", 1 ],
+                         map { [ "d", $_->{'user'} ] } @dlist ],
+                       [ [ undef, $text{'dmass_dis'} ] ],
+                       );
 
                &ui_print_footer("", $text{'index_return'});
                }
@@ -225,10 +219,9 @@ else {
                }
        else {
                # Ask if the user is sure
-               print "<form action=mass_delete_user.cgi method=post>\n";
-               print "<input type=hidden name=confirmed value=1>\n";
+               @hids = ( [ "confirmed", 1 ] );
                foreach $user (@dlist) {
-                       print "<input type=hidden name=d value='$user->{'user'}'>\n";
+                       push(@hids, [ "d", $user->{'user'} ]);
                        }
 
                # Sum up home directories
@@ -238,33 +231,34 @@ else {
                                }
                        }
 
-               # Show buttons
-               print "<center><b>",&text('umass_sure',
-                          scalar(@dlist), &nice_size($size*1024)),"</b><p>\n";
-
                if ($access{'delhome'} == 1) {
                        # Force home directory deletion
-                       print &ui_hidden("delhome", 1),"\n";
-                       print &ui_submit($text{'umass_del2'}),"\n";
+                       push(@hids, [ "delhome", 1 ]);
+                       @buts = ( [ undef, $text{'umass_del2'} ] );
                        }
                elsif ($access{'delhome'} == 0) {
                        # Never allow home directory deletion
-                       print &ui_submit($text{'umass_del1'}),"\n";
+                       @buts = ( [ undef, $text{'umass_del1'} ] );
                        }
                else {
-                       print &ui_submit($text{'umass_del1'}),"\n";
-                       print &ui_submit($text{'umass_del2'}, "delhome"),"\n";
+                       # Give user a choice
+                       @buts = ( [ undef, $text{'umass_del1'} ],
+                                 [ "delhome", $text{'umass_del2'} ] );
                        }
 
-               print "<br>\n";
-               printf "<input type=checkbox name=others value=1 %s> %s<br>\n",
-                       $config{'default_other'} ? "checked" : "",
-                       $text{'udel_dothers'};
-               if ($delete_sys && $delete_sys->{'user'} eq 'root') {
-                       print "<center><b><font color=#ff0000>$text{'udel_root'}",
-                             "</font></b><p></center>\n";
-                       }
-               print "</form></center>\n";
+               # Show the warning
+               print &ui_confirmation_form(
+                       "mass_delete_user.cgi",
+                       $size ? &text('umass_sure', scalar(@dlist),
+                                     &nice_size($size*1024)) :
+                               &text('umass_sure2', scalar(@dlist)),
+                       \@hids, \@buts,
+                       &ui_checkbox("others", 1, $text{'udel_dothers'},
+                                    $config{'default_other'}),
+                       $delete_sys && $delete_sys->{'user'} eq 'root' ?
+                          $text{'udel_root'} : "",
+                       );
+                               
 
                &ui_print_footer("", $text{'index_return'});
                }