UI-lib conversion

This commit is contained in:
Jamie Cameron
2020-11-01 17:12:51 -08:00
parent 2a104b43c9
commit 21f7dc9971
6 changed files with 116 additions and 186 deletions

View File

@ -54,7 +54,7 @@ if (-d "$hdir/$host->{'id'}") {
closedir(DIR);
}
else {
mkdir("$hdir/$hist->{'id'}", 0700);
mkdir("$hdir/$host->{'id'}", 0700);
}
foreach my $u (@{$host->{'users'}}) {
&write_file("$hdir/$host->{'id'}/$u->{'user'}.user", $u);

View File

@ -1,7 +1,7 @@
line1=Display Options,11
sort_mode=Sort hosts by,1,1-Hostname,0-Order added,2-Description
table_mode=Show hosts as,1,1-Table,0-Icons
conf_host_links=Provide a link to modify host,1,1-Yes,0-No
conf_host_links=Provide a link to modify hosts?,1,1-Yes,0-No
line2=Users and Groups Options,11
conf_add_user=Allow user add,1,1-Yes,0-No
conf_add_group=Allow group add,1,1-Yes,0-No

View File

@ -12,83 +12,63 @@ $server = &foreign_call("servers", "get_server", $in{'id'});
@packages = @{$host->{'packages'}};
# Show host details
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'host_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print &ui_table_start($text{'host_header'}, undef, 4);
print "<tr> <td><b>$text{'host_name'}</b></td>\n";
my $hmsg;
if ($server->{'id'}) {
print "<td>";
printf &ui_link("/servers/link.cgi/%s/","%s"),
$server->{'id'},
$hmsg = &ui_link("/servers/link.cgi/$server->{'id'}/",
$server->{'desc'} ?
"$server->{'desc'} ($server->{'host'}:$server->{'port'})" :
"$server->{'host'}:$server->{'port'}";
print "</td>";
"$server->{'desc'} ($server->{'host'}:$server->{'port'})" :
"$server->{'host'}:$server->{'port'}");
}
else {
print "<td colspan=3><a href=/>$text{'this_server'}</a></td>\n";
$hmsg = &ui_link("/", $text{'this_server'});
}
print &ui_table_row($text{'host_name'}, $hmsg, 3);
if ($server->{'id'}) {
print "<td><b>$text{'host_type'}</b></td> <td>\n";
foreach $t (@servers::server_types) {
print $t->[1] if ($t->[0] eq $server->{'type'});
}
print "</td>\n";
my ($t) = grep { $_->[0] eq $server->{'type'} } @servers::server_types;
print &ui_table_row($text{'host_type'}, $t ? $t->[1] : "");
}
print "</tr>\n";
print "<tr> <td><b>$text{'host_users'}</b></td>\n";
printf "<td>%d</td>\n", scalar(@{$host->{'users'}});
print &ui_table_row($text{'host_users'},
scalar(@{$host->{'users'}}));
print "<td><b>$text{'host_groups'}</b></td>\n";
printf "<td>%d</td> </tr>\n", scalar(@{$host->{'groups'}});
print &ui_table_row($text{'host_groups'},
scalar(@{$host->{'groups'}}));
print "</table></td></tr></table>\n";
print &ui_table_end();
# Show delete and refresh buttons
print "<p><table width=100%><tr>\n";
print &ui_buttons_start();
print "<td><form action=delete_host.cgi>\n";
print "<input type=hidden name=id value=$in{'id'}>\n";
print "<input type=submit value='$text{'host_delete'}'>\n";
print "</form></td>\n";
print &ui_buttons_row("delete_host.cgi", $text{'host_delete'}, undef,
[ [ "id", $in{'id'} ] ]);
print "<td align=right><form action=refresh.cgi>\n";
print "<input type=hidden name=id value=$in{'id'}>\n";
print "<input type=submit value='$text{'host_refresh'}'>\n";
print "</form></td>\n";
print &ui_buttons_row("refresh.cgi", $text{'host_refresh'}, undef,
[ [ "id", $in{'id'} ] ]);
print "</tr></table>\n";
print &ui_buttons_end();
# Show users and groups
print &ui_hr();
print &ui_subheading($text{'host_ulist'});
print "<table width=100% border>\n";
print "<tr $tb> <td><b>$text{'index_users'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
foreach $u (@{$host->{'users'}}) {
if ($i%4 == 0) { print "<tr>\n"; }
print "<td><a href=\"edit_user.cgi?user=$u->{'user'}&",
"host=$server->{'id'}\">$u->{'user'}</a></td>\n";
if ($i%4 == 3) { print "</tr>\n"; }
$i++;
print &ui_table_start($text{'index_users'}, undef, 2);
my @ugrid;
foreach my $u (@{$host->{'users'}}) {
push(@ugrid, &ui_link("edit_user.cgi?user=".&urlize($u->{'user'}).
"&host=".&urlize($server->{'id'}), $u->{'user'}));
}
print "</table></td> </tr></table>\n";
print &ui_table_row(undef, &ui_grid_table(\@ugrid, 4), 2);
print &ui_table_end();
print &ui_subheading($text{'host_glist'});
print "<table width=100% border>\n";
print "<tr $tb> <td><b>$text{'index_groups'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print &ui_table_start($text{'index_groups'}, undef, 2);
my @ggrid;
foreach $g (@{$host->{'groups'}}) {
if ($j%4 == 0) { print "<tr>\n"; }
print "<td><a href=\"edit_group.cgi?group=$g->{'group'}&",
"host=$server->{'id'}\">$g->{'group'}</a></td>\n";
if ($j%4 == 3) { print "</tr>\n"; }
$j++;
push(@ggrid, &ui_link("edit_group.cgi?group=".&urlize($g->{'group'}).
"&host=".&urlize($server->{'id'}), $g->{'group'}));
}
print "</table></td> </tr></table>\n";
print &ui_table_row(undef, &ui_grid_table(\@ggrid, 4), 2);
print &ui_table_end();
&ui_print_footer("", $text{'index_return'});

View File

@ -27,9 +27,8 @@ foreach $h (@hosts) {
push(@titles, $s->{'desc'} ? $s->{'desc'}
: "$s->{'host'}:$s->{'port'}");
push(@links, $link);
push(@icons, $gconfig{'webprefix'} ?
($gconfig{'webprefix'}."/servers/images/".$s->{'type'}.".gif") :
("../servers/images/".$s->{'type'}.".gif"));
push(@icons, $gconfig{'webprefix'}."/servers/images/".
$s->{'type'}.".gif");
push(@installed, @{$h->{'packages'}});
$gothost{$h->{'id'}}++;
}
@ -47,7 +46,8 @@ if (@links) {
local ($type) = grep { $_->[0] eq $s->{'type'} }
@servers::server_types;
local ($link) = $config{'conf_host_links'} ?
&ui_link("edit_host.cgi?id=$h->{'id'}",($s->{'host'} || &get_system_hostname())) :
&ui_link("edit_host.cgi?id=$h->{'id'}",
($s->{'host'} || &get_system_hostname())) :
($s->{'host'} || &get_system_hostname());
print &ui_columns_row([
$link,

View File

@ -29,15 +29,13 @@ add_egft=Server $1 does not use the same group file format as this host
add_ok=Added $1 with $2 users and $3 groups.
host_title=Managed Server
host_header=Software managed server details
host_header=Users and groups managed server details
host_name=Host name
host_type=Server type
host_delete=Remove From Managed List
host_refresh=Refresh Users and Groups
host_users=Number of users
host_groups=Number of groups
host_ulist=Users on Server
host_glist=Groups on Server
host_return=server details
refresh_title=Refresh Users and Groups

View File

@ -29,93 +29,70 @@ while(<SHELLS>) {
}
close(SHELLS);
print "<form action=create_user.cgi method=post>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'uedit_details'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print &ui_form_start("save_user.cgi", "post");
print &ui_table_start($text{'uedit_details'}, "width=100%", 2);
print "<tr> <td><b>$text{'user'}</b></td>\n";
print "<td><input name=user size=10></td>\n";
# Username
print &ui_table_row($text{'user'},
&ui_textbox("user", undef, 40));
# Find the first free UID above the base
print "<td><b>$text{'uid'}</b></td>\n";
$newuid = int($uconfig{'base_uid'});
while($used{$newuid}) {
$newuid++;
}
print "<td><input name=uid size=10 value='$newuid'></td> </tr>\n";
print &ui_table_row($text{'uid'},
&ui_textbox("uid", $newuid, 10));
# Real name and possibly other fields
if ($uconfig{'extra_real'}) {
print "<tr> <td><b>$text{'real'}</b></td>\n";
print "<td><input name=real size=20></td>\n";
print &ui_table_row($text{'real'},
&ui_textbox("real", undef, 40));
print "<td><b>$text{'office'}</b></td>\n";
print "<td><input name=office size=20 value=\"$real[1]\"></td> </tr>\n";
print &ui_table_row($text{'office'},
&ui_textbox("office", undef, 20));
print "<tr> <td><b>$text{'workph'}</b></td>\n";
print "<td><input name=workph size=20></td>\n";
print &ui_table_row($text{'workph'},
&ui_textbox("workph", undef, 20));
print "<td><b>$text{'homeph'}</b></td>\n";
print "<td><input name=homeph size=20></td> </tr>\n";
print &ui_table_row($text{'homeph'},
&ui_textbox("homeph", undef, 20));
print "<tr> <td><b>$text{'extra'}</b></td>\n";
print "<td><input name=extra size=20></td>\n";
print &ui_table_row($text{'extra'},
&ui_textbox("extra", undef, 20));
}
else {
print "<tr> <td><b>$text{'real'}</b></td>\n";
print "<td><input name=real size=20></td>\n";
print &ui_table_row($text{'real'},
&ui_textbox("real", undef, 40));
}
print "<td><b>$text{'home'}</b></td>\n";
print "<td>\n";
if ($uconfig{'home_base'}) {
printf "<input type=radio name=home_base value=1 checked> %s\n",
$text{'uedit_auto'};
printf "<input type=radio name=home_base value=0>\n";
printf "<input name=home size=25> %s\n",
&file_chooser_button("home", 1);
}
else {
print "<input name=home size=25>\n",
&file_chooser_button("home", 1);
}
print "</td> </tr>\n";
# Home directory
print &ui_table_row($text{'home'},
$uconfig{'home_base'} ?
&ui_radio("home_base", 1,
[ [ 1, $text{'uedit_auto'} ],
[ 0, &ui_filebox("home", "", 40) ] ]) :
&ui_filebox("home", "", 40));
print "<tr> <td valign=top><b>$text{'shell'}</b></td>\n";
print "<td valign=top><select name=shell>\n";
# Login shell
@shlist = &unique(@shlist);
foreach $s (@shlist) {
printf "<option value='%s'>%s</option>\n", $s,
$s eq "" ? "&lt;None&gt;" : $s;
}
print "<option value=*>$text{'uedit_other'}</option>\n";
print "</select></td>\n";
push(@shlist, [ "*", $text{'uedit_other'} ]);
print &ui_table_row($text{'shell'},
&ui_select("shell", undef, \@shlist)." ".
&ui_filebox("othersh", undef, 25));
&seed_random();
foreach (1 .. 15) {
$random_password .= $random_password_chars[
rand(scalar(@random_password_chars))];
}
print "<td valign=top rowspan=3><b>$text{'pass'}</b>",
"</td> <td rowspan=3 valign=top>\n";
printf "<input type=radio name=passmode value=0> %s<br>\n",
$uconfig{'empty_mode'} ? $text{'none1'} : $text{'none2'};
printf "<input type=radio name=passmode value=1 checked> %s<br>\n",
$text{'nologin'};
printf "<input type=radio name=passmode value=3> %s\n",
$text{'clear'};
printf "<input %s name=pass size=15 value='%s'><br>\n",
$uconfig{'passwd_stars'} ? "type=password" : "",
$uconfig{'random_password'} ? $random_password : "";
printf "<input type=radio name=passmode value=2> $text{'encrypted'}\n";
printf "<input name=encpass size=13>\n";
print "</td> </tr>\n";
# Password or locked account
$rp = $uconfig{'random_password'} ? &useradmin::generate_random_password() : "";
$pfield = $uconfig{'passwd_stars'} ? &ui_password("pass", $rp, 40)
: &ui_textbox("pass", $rp, 40);
print &ui_table_row($text{'pass'},
&ui_radio_table("passmode", 1,
[ [ 0, $uconfig{'empty_mode'} ? $text{'none1'} : $text{'none2'} ],
[ 1, $text{'nologin'} ],
[ 3, $text{'clear'}, $pfield ],
[ 2, &ui_textbox("encpass", undef, 40) ] ]));
print "<tr> <td valign=top>$text{'uedit_other'}</td>\n";
print "<td valign=top><input size=25 name=othersh>\n";
print &file_chooser_button("othersh", 0),"</td> </tr>\n";
print "<tr> <td colspan=2><br></td> </tr>\n";
print "</table></td></tr></table><p>\n";
print &ui_table_end();
$pft = &foreign_call("useradmin", "passfiles_type");
if ($pft == 1 || $pft == 6) {
@ -125,13 +102,13 @@ if ($pft == 1 || $pft == 6) {
print "<tr $cb> <td><table width=100%>\n";
print "<tr> <td><b>$text{'change2'}</b></td>\n";
print "<td>";
&date_input("", "", "", 'change');
&useradmin::date_input("", "", "", 'change');
print " &nbsp; <input name=changeh size=3>";
print ":<input name=changemi size=3></td>\n";
print "<td colspan=1><b>$text{'expire2'}</b></td>\n";
print "<td colspan=3>";
&date_input("", "", "", 'expire');
&useradmin::date_input("", "", "", 'expire');
print " &nbsp; <input name=expireh size=3>";
print ":<input name=expiremi size=3></td> </tr>\n";
@ -149,7 +126,7 @@ elsif ($pft == 2) {
print "<td colspan=1><b>$text{'expire'}</b></td>\n";
print "<td colspan=3>";
&date_input($eday, $emon, $eyear, 'expire');
&useradmin::date_input($eday, $emon, $eyear, 'expire');
print "</td> </tr>\n";
print "<tr> <td><b>$text{'min'}</b></td>\n";
@ -174,7 +151,7 @@ elsif ($pft == 4) {
print "<tr> <td><b>$text{'expire'}</b></td>\n";
print "<td>";
&date_input("", "", "", 'expire');
&useradmin::date_input("", "", "", 'expire');
print " &nbsp; <input name=expireh size=3>";
print "<b>:</b><input name=expiremi size=3></td> </tr>\n";
@ -199,74 +176,49 @@ elsif ($pft == 4) {
print "</table></td></tr></table><p>\n";
}
# Output group memberships
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'uedit_gmem'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print "<tr> <td valign=top><b>$text{'group'}</b></td> <td valign=top>\n";
printf "<input name=gid size=15 value=\"%s\">\n",
$uconfig{'default_group'};
print "<input type=button onClick='ifield = document.forms[0].gid; chooser = window.open(\"/useradmin/my_group_chooser.cgi?multi=0&group=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=300,height=200\"); chooser.ifield = ifield' value=\"...\"></td>\n";
print &ui_table_start($text{'uedit_gmem'}, "width=100%", 2);
print "<td valign=top><b>$text{'uedit_2nd'}</b></td>\n";
print "<td><select name=sgid multiple size=5>\n";
# Primary group
print &ui_table_row($text{'group'},
&ui_groupbox("gid", $uconfig{'default_group'}));
# Secondary groups
@glist = sort { $a->{'group'} cmp $b->{'group'} } @glist
if ($uconfig{'sort_mode'});
foreach $g (@glist) {
@mems = split(/,/ , $g->{'members'});
print "<option value=\"$g->{'gid'}\">$g->{'group'} ($g->{'gid'})</option>\n";
}
print "</select></td> </tr>\n";
print "</table></td></tr></table><p>\n";
print &ui_table_row($text{'uedit_2nd'},
&ui_select("sgid", undef,
[ map { [ $_->{'gid'}, $_->{'group'} ] } @glist ],
5, 1));
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'uedit_oncreate'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_table_end();
print "<tr> <td><b>$text{'uedit_makehome'}</b></td>\n";
print "<td><input type=radio name=makehome value=1 checked> $text{'yes'}</td>\n";
print "<td><input type=radio name=makehome value=0> $text{'no'}</td> </tr>\n";
print &ui_table_start($text{'uedit_oncreate'}, "width=100%", 2);
# Create home dir?
print &ui_table_row($text{'uedit_makehome'},
&ui_yesno_radio("makehome", 1));
# Copy home dir files?
if ($uconfig{'user_files'} =~ /\S/) {
print "<tr> <td><b>$text{'uedit_copy'}<b></td>\n";
print "<td><input type=radio name=copy_files ",
"value=1 checked> $text{'yes'}</td>\n";
print "<td><input type=radio name=copy_files ",
"value=0> $text{'no'}</td> </tr>\n";
print &ui_table_row($text{'uedit_copy'},
&ui_yesno_radio("copy_files", 1));
}
# Show make home on all servers option
print "<tr> <td><b>$text{'uedit_servs'}</b></td>\n";
print "<td><input type=radio name=servs value=1> $text{'uedit_mall'}</td>\n";
print "<td><input type=radio name=servs value=0 checked> $text{'uedit_mthis'}</td> </tr>\n";
# Create home dir on all servers?
print &ui_table_row($text{'uedit_servs'},
&ui_radio("servs", 0, [ [ 1, $text{'uedit_mall'} ],
[ 0, $text{'uedit_mthis'} ] ]));
# Show other modules option
print "<tr> <td><b>$text{'uedit_others'}</b></td>\n";
print "<td><input type=radio name=others value=1 checked> $text{'yes'}</td>\n";
print "<td><input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
print &ui_table_row($text{'uedit_others'},
&ui_yesno_radio("others", 1));
# Show selector for hosts to create on
print "<tr> <td><b>$text{'uedit_servers'}</b></td> ",
"<td>",&create_on_input(),"</td> </tr>\n";
print &ui_table_row($text{'uedit_servers'},
&create_on_input());
print "</table></td> </tr></table><p></p><p></p>\n";
print "<input type=submit value=\"$text{'create'}\"></form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'create'} ] ]);
&ui_print_footer("", $text{'index_return'});
# date_input(day, month, year, prefix)
sub date_input
{
print "<input name=$_[3]d size=3 value='$_[0]'>";
print "/<select name=$_[3]m>\n";
local $m;
foreach $m (1..12) {
printf "<option value=%d %s>%s</option>\n",
$m, $_[1] eq $m ? 'selected' : '', $text{"smonth_$m"};
}
print "</select>";
print "/<input name=$_[3]y size=5 value='$_[2]'>";
print &date_chooser_button("$_[3]d", "$_[3]m", "$_[3]y");
}