Completed ui-lib conversion

This commit is contained in:
Jamie Cameron
2008-01-02 00:13:14 +00:00
parent 4ea9101640
commit 4074850ffa
5 changed files with 118 additions and 170 deletions

View File

@@ -15,3 +15,6 @@ Added a Module Config parameter to change the number of columns used to display
The contents of uploaded files are no longer logged.
---- Changes since 1.340 ----
Removed the Module Config option to control if a shell is used when executing a command as a user, since we can now work this out automatically.
---- Changes since 1.390 ----
Re-designed the user interface somewhat, and converted all code to use the new Webmin UI library.
When commands are shown in a table and no parameters are needed, the names now link directly to run the command.

View File

@@ -294,41 +294,33 @@ return @rv;
sub show_params_inputs
{
local ($cmd, $noquote, $editor) = @_;
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'edit_params'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print "<tr> <td><b>$text{'edit_name'}</b></td> ",
"<td><b>$text{'edit_desc'}</b></td> <td><b>$text{'edit_type'}</b></td> ";
if (!$noquote) {
print "<td><b>$text{'edit_quote'}</b></td> ";
}
print "</tr>\n";
local $ptable = &ui_columns_start([
$text{'edit_name'}, $text{'edit_desc'}, $text{'edit_type'},
$noquote ? ( ) : ( $text{'edit_quote'} ),
], 100, 0, undef, undef);
local @a = (@{$cmd->{'args'}}, { });
for(my $i=0; $i<@a; $i++) {
print "<tr>\n";
printf "<td><input name=name_$i size=10 value='%s'></td>\n",
$a[$i]->{'name'};
printf "<td><input name=desc_$i size=40 value='%s'></td>\n",
&html_escape($a[$i]->{'desc'});
print "<td><select name=type_$i>\n";
local @cols;
push(@cols, &ui_textbox("name_$i", $a[$i]->{'name'}, 10));
push(@cols, &ui_textbox("desc_$i", $a[$i]->{'desc'}, 40));
local @opts;
for(my $j=0; $text{"edit_type$j"}; $j++) {
next if ($editor &&
($j == 7 || $j == 8 || $j == 10 || $j == 11));
printf "<option value=%d %s>%s\n",
$j, $a[$i]->{'type'} == $j ? "selected" : "",
$text{"edit_type$j"};
push(@opts, [ $j, $text{"edit_type$j"} ]);
}
print "</select>\n";
print &ui_textbox("opts_$i", $a[$i]->{'opts'}, 20),"</td>\n";
push(@cols, &ui_select("type_$i", $a[$i]->{'type'}, \@opts)." ".
&ui_textbox("opts_$i", $a[$i]->{'opts'}, 20));
if (!$noquote) {
print "<td>",&ui_yesno_radio("quote_$i",
int($a[$i]->{'quote'})),"</td>\n";
push(@cols, &ui_yesno_radio("quote_$i",
int($a[$i]->{'quote'})));
}
print "</tr>\n";
$ptable .= &ui_columns_row(\@cols);
}
print "</table></td></tr></table>\n";
$ptable .= &ui_columns_end();
print $ptable;
}
# parse_params_inputs(&command)

View File

@@ -15,123 +15,92 @@ else {
$cmd = $cmds[$in{'idx'}];
}
print "<form action=save_cmd.cgi method=post>\n";
print "<input type=hidden name=new value='$in{'new'}'>\n";
print "<input type=hidden name=idx value='$in{'idx'}'>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'edit_details'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
# Form header
print &ui_form_start("save_cmd.cgi", "post");
print &ui_hidden("new", $in{'new'});
print &ui_hidden("idx", $in{'idx'});
print &ui_table_start($text{'edit_details'}, "width=100%", 4);
# Command ID
if (!$in{'new'}) {
print "<tr> <td valign=top><b>",&hlink($text{'edit_id'}, "id"),
"</b></td>\n";
print "<td><tt>$cmd->{'id'}</tt></td> </tr>\n";
print &ui_table_row(&hlink($text{'edit_id'}, "id"),
"<tt>$cmd->{'id'}</tt>", 3);
}
print "<tr> <td valign=top><b>",&hlink($text{'edit_desc'}, "desc"),
"</b></td>\n";
print "<td colspan=3><input name=desc size=50 value='",
&html_escape($cmd->{'desc'}),"'><br>\n";
print "<textarea name=html rows=2 cols=50>",$cmd->{'html'},
"</textarea></td> </tr>\n";
# Description, text and HTML
print &ui_table_row(&hlink($text{'edit_desc'}, "desc"),
&ui_textbox("desc", $cmd->{'desc'}, 60)."<br>".
&ui_textarea("html", $cmd->{'html'}, 2, 60), 3);
# Command to run
if ($cmd->{'cmd'} =~ s/^\s*cd\s+(\S+)\s*;\s*//) {
$dir = $1;
}
print "<tr> <td><b>",&hlink($text{'edit_cmd'},"command"),"</b></td>\n";
print "<td colspan=3><input name=cmd size=50 value=\"".
&html_escape($cmd->{'cmd'})."\"></td> </tr>\n";
print &ui_table_row(&hlink($text{'edit_cmd'},"command"),
&ui_textbox("cmd", $cmd->{'cmd'}, 60), 3);
print "<tr> <td><b>",&hlink($text{'edit_dir'},"dir"),"</b></td>\n";
$dir =~ s/"/&quot;/g;
printf "<td colspan=3><input type=radio name=dir_def value=1 %s> %s\n",
$dir ? "" : "checked", $text{'default'};
printf "<input type=radio name=dir_def value=0 %s>\n",
$dir ? "checked" : "";
printf "<input name=dir size=40 value=\"%s\"> %s</td> </tr>\n",
$dir, &file_chooser_button("dir", 1);
# Directory to run in
print &ui_table_row(&hlink($text{'edit_dir'},"dir"),
&ui_opt_textbox("dir", $dir, 40, $text{'default'})." ".
&file_chooser_button("dir", 1), 3);
# User to run as
if (&supports_users()) {
print "<tr> <td><b>",&hlink($text{'edit_user'},"user"),"</b></td>\n";
print "<td colspan=3>\n";
printf "<input type=radio name=user_def value=1 %s> %s\n",
$cmd->{'user'} eq '*' && !$in{'new'} ? "checked" : "",
$text{'edit_user_def'};
printf "<input type=radio name=user_def value=0 %s>\n",
$cmd->{'user'} eq '*' && !$in{'new'} ? "" : "checked";
printf "<input name=user size=8 value='%s'> %s\n",
$cmd->{'user'} eq '*' ? '' : $cmd->{'user'},
&user_chooser_button("user", 0);
printf "<input type=checkbox name=su value=1 %s> %s</td> </tr>\n",
$cmd->{'su'} ? 'checked' : '', $text{'edit_su'};
print &ui_table_row(&hlink($text{'edit_user'},"user"),
&ui_opt_textbox("user", $cmd->{'user'} eq '*' ? undef
: $cmd->{'user'}, 13, $text{'edit_user_def'})." ".
&user_chooser_button("user", 0)." ".
&ui_checkbox("su", 1, $text{'edit_su'}, $cmd->{'su'}), 3);
}
print "<tr> <td><b>",&hlink($text{'edit_raw'},"raw"),"</b></td>\n";
printf "<td><input type=radio name=raw value=1 %s> %s\n",
$cmd->{'raw'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=raw value=0 %s> %s</td>\n",
$cmd->{'raw'} ? "" : "checked", $text{'no'};
# Show raw output
print &ui_table_row(&hlink($text{'edit_raw'},"raw"),
&ui_yesno_radio("raw", $cmd->{'raw'} ? 1 : 0));
print "<td><b>",&hlink($text{'edit_order'},"order"),"</b></td>\n";
printf "<td><input type=radio name=order_def value=1 %s> %s\n",
$cmd->{'order'} ? "" : "checked", $text{'default'};
printf "<input type=radio name=order_def value=0 %s>\n",
$cmd->{'order'} ? "checked" : "";
printf "<input name=order size=6 value='%s'></td> </tr>\n",
$cmd->{'order'} ? $cmd->{'order'} : '';
# Command ordering on main page
print &ui_table_row(&hlink($text{'edit_order'},"order"),
&ui_opt_textbox("order", $cmd->{'order'} || "", 6, $text{'default'}));
print "<tr> <td><b>",&hlink($text{'edit_noshow'},"noshow"),"</b></td>\n";
printf "<td><input type=radio name=noshow value=1 %s> %s\n",
$cmd->{'noshow'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=noshow value=0 %s> %s</td>\n",
$cmd->{'noshow'} ? "" : "checked", $text{'no'};
# Hide from main page?
print &ui_table_row(&hlink($text{'edit_noshow'},"noshow"),
&ui_yesno_radio("noshow", $cmd->{'noshow'}));
print "<td><b>",&hlink($text{'edit_usermin'},"usermin"),"</b></td>\n";
printf "<td><input type=radio name=usermin value=1 %s> %s\n",
$cmd->{'usermin'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=usermin value=0 %s> %s</td> </tr>\n",
$cmd->{'usermin'} ? "" : "checked", $text{'no'};
# Visible in Usermin?
print &ui_table_row(&hlink($text{'edit_usermin'},"usermin"),
&ui_yesno_radio("usermin", $cmd->{'usermin'}));
print "<tr> <td><b>",&hlink($text{'edit_timeout'},"timeout"),"</b></td>\n";
printf "<td><input type=radio name=timeout_def value=1 %s> %s\n",
$cmd->{'timeout'} ? "" : "checked", $text{'edit_timeoutdef'};
printf "<input type=radio name=timeout_def value=0 %s>\n",
$cmd->{'timeout'} ? "checked" : "";
printf "<input name=timeout size=6 value='%s'> %s</td>\n",
$cmd->{'timeout'} ? $cmd->{'timeout'} : '', $text{'edit_secs'};
# Command timeout
print &ui_table_row(&hlink($text{'edit_timeout'},"timeout"),
&ui_opt_textbox("timeout", $cmd->{'timeout'}, 6, $text{'default'}).
" ".$text{'edit_secs'});
print "<td><b>",&hlink($text{'edit_clear'},"clear"),"</b></td>\n";
printf "<td><input type=radio name=clear value=1 %s> %s\n",
$cmd->{'clear'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=clear value=0 %s> %s</td> </tr>\n",
$cmd->{'clear'} ? "" : "checked", $text{'no'};
# Clear environment?
print &ui_table_row(&hlink($text{'edit_clear'},"clear"),
&ui_yesno_radio("clear", $cmd->{'clear'}));
# Show Webmin servers to run on
@servers = &list_servers();
if (@servers > 1) {
print "<tr> <td valign=top><b>",
&hlink($text{'edit_servers'}, "servers"),"</b></td>\n";
print "<td colspan=3>";
@hosts = @{$cmd->{'hosts'}};
@hosts = ( 0 ) if (!@hosts);
print &ui_select("hosts", \@hosts,
print &ui_table_row(&hlink($text{'edit_servers'}, "servers"),
&ui_select("hosts", \@hosts,
[ map { [ $_->{'id'}, ($_->{'desc'} || $_->{'host'}) ] } @servers ],
5, 1);
print "</td> </tr>\n";
5, 1), 3);
}
print "</table></td></tr></table><p>\n";
print &ui_table_end();
# Show parameters
&show_params_inputs($cmd);
print "<table width=100%><tr>\n";
print "<td><input type=submit value=\"$text{'save'}\"></td>\n";
if (!$in{'new'}) {
print "<td align=right><input type=submit name=delete ",
"value=\"$text{'delete'}\"></td>\n";
if ($in{'new'}) {
print &ui_form_end([ [ undef, $text{'create'} ] ]);
}
else {
print &ui_form_end([ [ undef, $text{'save'} ],
[ 'delete', $text{'delete'} ] ]);
}
print "</tr></table></form>\n";
&ui_print_footer("", $text{'index_return'});

View File

@@ -18,80 +18,64 @@ else {
print &ui_form_start("save_file.cgi", "post");
print &ui_hidden("new", $in{'new'});
print &ui_hidden("idx", $in{'idx'});
print &ui_table_start($text{'file_details'}, "width=100%", 4);
print &ui_table_start($text{'file_details'}, "width=100%", 2);
if (!$in{'new'}) {
print "<tr> <td valign=top><b>",&hlink($text{'file_id'}, "fileid"),
"</b></td>\n";
print "<td><tt>$edit->{'id'}</tt></td> </tr>\n";
print &ui_table_row(&hlink($text{'file_id'}, "fileid"),
"<tt>$edit->{'id'}</tt>");
}
print "<tr> <td valign=top><b>",&hlink($text{'file_desc'}, "fdesc"),
"</b></td>\n";
print "<td><input name=desc size=50 value='",
&html_escape($edit->{'desc'}),"'><br>\n";
print "<textarea name=html rows=2 cols=50>",$edit->{'html'},
"</textarea></td> </tr>\n";
# Description, text and HTML
print &ui_table_row(&hlink($text{'edit_desc'}, "desc"),
&ui_textbox("desc", $edit->{'desc'}, 60)."<br>".
&ui_textarea("html", $edit->{'html'}, 2, 60));
print "<tr> <td><b>",&hlink($text{'file_edit'}, "file"),"</b></td>\n";
print "<td><input name=edit size=50 value='$edit->{'edit'}'> ",
&file_chooser_button("edit", 0),"</td> </tr>\n";
# File to edit, and environment checkbox
print &ui_table_row(&hlink($text{'file_edit'}, "file"),
&ui_textbox("edit", $edit->{'edit'}, 60)." ".
&file_chooser_button("edit", 0)."<br>".
&ui_checkbox("envs", 1, $text{'file_envs'}, $edit->{'envs'}));
print "<tr> <td></td>\n";
printf "<td><input type=checkbox name=envs value=1 %s> %s</td> </tr>\n",
$edit->{'envs'} ? "checked" : "", $text{'file_envs'};
# File owner and group
print &ui_table_row(&hlink($text{'file_owner'}, "owner"),
&ui_radio("owner_def", $edit->{'user'} ? 0 : 1,
[ [ 1, $text{'file_leave'} ],
[ 0, $text{'file_user'}." ".
&ui_textbox("user", $edit->{'user'}, 13)." ".
$text{'file_group'}." ".
&ui_textbox("group", $edit->{'group'}, 13) ] ]));
print "<tr> <td><b>",&hlink($text{'file_owner'}, "owner"),"</b></td>\n";
printf "<td><input type=radio name=owner_def value=1 %s> %s\n",
$edit->{'user'} ? '' : 'checked', $text{'file_leave'};
printf "<input type=radio name=owner_def value=0 %s> %s\n",
$edit->{'user'} ? 'checked' : '', $text{'file_user'};
printf "<input name=user size=8 value='%s'> %s\n",
$edit->{'user'}, $text{'file_group'};
printf "<input name=group size=8 value='%s'></td> </tr>\n",
$edit->{'group'};
# File permissions
print &ui_table_row(&hlink($text{'file_perms'}, "perms"),
&ui_opt_textbox("perms", $edit->{'perms'}, 3, $text{'file_leave'},
$text{'file_set'}));
print "<tr> <td><b>",&hlink($text{'file_perms'}, "perms"),"</b></td>\n";
printf "<td><input type=radio name=perms_def value=1 %s> %s\n",
$edit->{'perms'} ? '' : 'checked', $text{'file_leave'};
printf "<input type=radio name=perms_def value=0 %s> %s\n",
$edit->{'perms'} ? 'checked' : '', $text{'file_set'};
printf "<input name=perms size=3 value='%s'></td> </tr>\n",
$edit->{'perms'};
# Commands to run before and after
print &ui_table_row(&hlink($text{'file_before'}, "before"),
&ui_textbox("before", $edit->{'before'}, 60));
print &ui_table_row(&hlink($text{'file_after'}, "after"),
&ui_textbox("after", $edit->{'after'}, 60));
print "<tr> <td><b>",&hlink($text{'file_before'}, "before"),"</b></td>\n";
print "<td><input name=before size=60 value='",
&html_escape($edit->{'before'}),"'></td> </tr>\n";
# Command ordering on main page
print &ui_table_row(&hlink($text{'edit_order'},"order"),
&ui_opt_textbox("order", $edit->{'order'} || "", 6, $text{'default'}));
print "<tr> <td><b>",&hlink($text{'file_after'}, "after"),"</b></td>\n";
print "<td><input name=after size=60 value='",
&html_escape($edit->{'after'}),"'></td> </tr>\n";
# Visible in Usermin?
print &ui_table_row(&hlink($text{'edit_usermin'},"usermin"),
&ui_yesno_radio("usermin", $edit->{'usermin'}));
print "<tr> <td><b>",&hlink($text{'edit_order'}, "order"),"</b></td>\n";
printf "<td><input type=radio name=order_def value=1 %s> %s\n",
$edit->{'order'} ? "" : "checked", $text{'default'};
printf "<input type=radio name=order_def value=0 %s>\n",
$edit->{'order'} ? "checked" : "";
printf "<input name=order size=6 value='%s'></td> </tr>\n",
$edit->{'order'} ? $edit->{'order'} : '';
print "<tr> <td><b>",&hlink($text{'edit_usermin'},"usermin"),"</b></td>\n";
printf "<td><input type=radio name=usermin value=1 %s> %s\n",
$edit->{'usermin'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=usermin value=0 %s> %s</td> </tr>\n",
$edit->{'usermin'} ? "" : "checked", $text{'no'};
print "</table></td></tr></table><p>\n";
print &ui_table_end();
# Show parameters
&show_params_inputs($edit, 1, 1);
print "<table width=100%><tr>\n";
print "<td><input type=submit value=\"$text{'save'}\"></td>\n";
if (!$in{'new'}) {
print "<td align=right><input type=submit name=delete ",
"value=\"$text{'delete'}\"></td>\n";
if ($in{'new'}) {
print &ui_form_end([ [ undef, $text{'create'} ] ]);
}
else {
print &ui_form_end([ [ undef, $text{'save'} ],
[ 'delete', $text{'delete'} ] ]);
}
print "</tr></table></form>\n";
&ui_print_footer("", $text{'index_return'});

View File

@@ -30,9 +30,9 @@ edit_raw=Command outputs HTML?
edit_su=Use user's environment?
edit_order=Ordering on main page
edit_params=Command parameters
edit_name=Name
edit_name=Parameter name
edit_type=Type
edit_quote=Quote parameter?
edit_quote=Quote?
edit_type0=Text
edit_type1=User
edit_type2=UID