Use ui-lib.pl functions
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 00:41:01 +0000 (00:41 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 00:41:01 +0000 (00:41 +0000)
passwd/CHANGELOG
passwd/edit_passwd.cgi
passwd/index.cgi

index 5c89664..85a5308 100644 (file)
@@ -2,3 +2,5 @@
 If a user exists in the LDAP database instead of the local password file, he will be updated there instead.
 ---- Changes since 1.280 ----
 Added an access control option to exclude users from the list of those whose passwords can be changed, if allowing by group membership.
+---- Changes since 1.390 ----
+Re-wrote the user interface code to use the new Webmin UI library, for a more consistent look.
index ba5f065..7680e21 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/local/bin/perl
-# edit_passwd.cgi
+# Show password change form
 
 require './passwd-lib.pl';
 &ReadParse();
@@ -8,59 +8,57 @@ require './passwd-lib.pl';
 @user = getpwnam($in{'user'});
 @user || &error($text{'passwd_euser'});
 &can_edit_passwd(\@user) || &error($text{'passwd_ecannot'});
-
-# Show password change form
 &ui_print_header(undef, $text{'passwd_title'}, "");
-print "<form action=save_passwd.cgi method=post>\n";
-print "<input type=hidden name=user value='$user[0]'>\n";
-print "<input type=hidden name=one value='$in{'one'}'>\n";
-print "<table border>\n";
-print "<tr $tb> <td><b>$text{'passwd_header'}</b></td> </tr>\n";
-print "<tr $cb> <td><table>\n";
 
+print &ui_form_start("save_passwd.cgi", "post");
+print &ui_hidden("user", $user[0]);
+print &ui_hidden("one", $in{'one'});
+print &ui_table_start($text{'passwd_header'}, undef, 2);
+
+# Login and real name
 %uconfig = &foreign_config("useradmin");
-print "<tr> <td><b>$text{'passwd_for'}</b></td>\n";
 $user[6] =~ s/,.*$// if ($uconfig{'extra_real'});
-print "<td>$user[0]",( $user[6] ? " ($user[6])" : "" ),
-      "</td> </tr>\n";
+print &ui_table_row($text{'passwd_for'},
+       $user[0].( $user[6] ? " ($user[6])" : "" ));
 
+# Old password field
 if ($access{'old'} == 1 ||
     $access{'old'} == 2 && $user[0] ne $remote_user) {
-       print "<tr> <td><b>$text{'passwd_old'}</b></td>\n";
-       print "<td><input name=old size=25 type=password></td> </tr>\n";
+       print &ui_table_row($text{'passwd_old'},
+               &ui_password("old", undef, 30));
        }
 
-print "<tr> <td><b>$text{'passwd_new'}</b></td>\n";
-print "<td><input name=new size=25 type=password></td> </tr>\n";
+# New password
+print &ui_table_row($text{'passwd_new'},
+       &ui_password("new", undef, 30));
 
+# New password again
 if ($access{'repeat'}) {
-       print "<tr> <td><b>$text{'passwd_repeat'}</b></td>\n";
-       print "<td><input name=repeat size=25 type=password></td> </tr>\n";
+       print &ui_table_row($text{'passwd_repeat'},
+               &ui_password("repeat", undef, 30));
        }
 
+# Force change at next login
 if (!$config{'passwd_cmd'} && $access{'expire'}) {
        &foreign_require("useradmin", "user-lib.pl");
        $pft = &useradmin::passfiles_type();
        ($uuser) = grep { $_->{'user'} eq $in{'user'} }
                        &useradmin::list_users();
        if ($uuser->{'max'} && ($pft == 2 || $pft == 5)) {
-               print "<tr> <td colspan=2>\n";
-               print "<input type=checkbox name=expire value=1> ",
-                     "$text{'passwd_expire'}</td> </tr>\n";
+               print &ui_table_row(" ",
+                       &ui_checkbox("expire", 1, $text{'passwd_expire'}, 0));
                }
        }
 
+# Change in other modules
 if ($access{'others'} == 2) {
-       print "<tr> <td colspan=2>\n";
-       print "<input type=checkbox name=others value=1 checked> ",
-             "$text{'passwd_others'}</td> </tr>\n";
+       print &ui_table_row(" ",
+               &ui_checkbox("others", 1, $text{'passwd_others'}, 1));
        }
 
-print "<tr> <td colspan=2>\n";
-print "<input type=submit value='$text{'passwd_change'}'>\n";
-print "<input type=reset value='$text{'passwd_reset'}'></td> </tr>\n";
+print &ui_table_end();
+print &ui_form_end([ [ undef, $text{'passwd_change'} ] ]);
 
-print "</table></td></tr></table></form>\n";
 &ui_print_footer($in{'one'} ? ( "/", $text{'index'} ) :
                              ( "", $text{'index_return'} ));
 
index a9ff632..c8c1c4c 100755 (executable)
@@ -2,6 +2,8 @@
 # Display a list of users whose passwords can be changed
 
 require './passwd-lib.pl';
+
+# Show an error if we don't know how to change passwords
 if (!$config{'passwd_cmd'} && !&foreign_check("useradmin")) {
        &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
        print "<p>$text{'index_euseradmin'}<p>\n";
@@ -67,35 +69,28 @@ if ($config{'sort_mode'}) {
 if ($config{'max_users'} && @ulist > $config{'max_users'}) {
        # Show as form for entering a username
        print "$text{'index_toomany'}<br>\n";
-       print "<form action=edit_passwd.cgi>\n";
-       print "<input type=submit value='$text{'index_user'}'>\n";
+       print &ui_form_start("edit_passwd.cgi");
+       print &ui_submit($text{'index_user'});
        if ($config{'input_type'}) {
-               print "<select name=user>\n";
-               foreach $u (@ulist) {
-                       print "<option>$u->[0]\n";
-                       }
-               print "</select>\n";
+               print &ui_select("user", undef,
+                                [ map { $_->[0] } @ulist ]);
                }
        else {
-               print "<input name=user size=13> ",
-                     &user_chooser_button("user",0);
+               print &ui_user_textbox("user");
                }
-       print "</form>\n";
+       print &ui_form_end();
        }
 elsif (@ulist) {
        # Show as table of users
-       print "<table border width=100%>\n";
-       print "<tr $tb> <td><b>$text{'index_header'}</b></td> </tr>\n";
-       print "<tr $cb> <td><table width=100%>\n";
+       @grid = ( );
        for($i=0; $i<@ulist; $i++) {
                if ($i%4 == 0) { print "<tr>\n"; }
-               print "<td width=25%><a href=\"edit_passwd.cgi?",
-                     "user=$ulist[$i]->[0]\">",
-                     &html_escape($ulist[$i]->[0])."</a></td>\n";
-               if ($i%4 == 3) { print "</tr>\n"; }
+               push(@grid, "<a href=\"edit_passwd.cgi?".
+                           "user=$ulist[$i]->[0]\">".
+                           &html_escape($ulist[$i]->[0])."</a>");
                }
-       while($i++ % 4) { print "<td width=25%></td>\n"; }
-       print "</table></td> </tr></table><p>\n";
+       print &ui_grid_table(\@grid, 4, 100, undef, undef,
+                            $text{'index_header'});
        }
 else {
        # No users available