Mostly converted all pages to use ui-lib

This commit is contained in:
Jamie Cameron
2007-12-29 00:47:08 +00:00
parent 70de08c0f7
commit 8b34eeeadc
39 changed files with 190 additions and 146 deletions

View File

@ -21,3 +21,6 @@ When a user's home directory is changed in the Users and Groups module, any Cron
Added a button on the Edit Job page for cloning an existing job.
---- Changes since 1.370 ----
Added a Module Config option to limit Cron jobs to hourly at most, thanks to Filip Hajny.
---- Changes since 1.390 ----
If there are more than 100 jobs (by default), a search form is shown on the main page instead of a list of all jobs.
Re-wrote all user interface code to use the new Webmin UI library.

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -19,3 +19,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -22,3 +22,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -19,3 +19,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -19,3 +19,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -19,3 +19,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -22,3 +22,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -19,3 +19,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -21,3 +21,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -20,3 +20,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -18,3 +18,4 @@ match_user=1
kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -10,3 +10,4 @@ kill_subs=0
single_file=c:/cronw/crontab.txt
show_comment=0
hourly_only=0
max_jobs=100

View File

@ -1,5 +1,6 @@
line1=Configurable options,11
max_len=Maximum command length to display,3,Unlimited
max_jobs=Maximum Cron jobs to show,3,Unlimited
show_time=Show job schedules?,1,1-Yes,0-No
show_comment=Show job comments?,1,1-Yes,0-No
show_run=Display running status of jobs?,1,2-Yes, and allow starting and stopping,1-Yes,0-No

View File

@ -6,30 +6,27 @@ require './cron-lib.pl';
$access{'allow'} || &error($text{'allow_ecannot'});
&ui_print_header(undef, $text{'allow_title'}, "");
print "<form action=save_allow.cgi>\n";
print &ui_form_start("save_allow.cgi");
print "$text{'allow_desc'} <p>\n";
$allowfile = (-r $config{cron_allow_file});
$denyfile = (-r $config{cron_deny_file});
$nofile = $config{cron_deny_all};
printf "<input type=radio name=mode value=0 %s> %s<br>\n",
!$allowfile && !$denyfile ? "checked" : "",
$nofile==0 ? $text{'allow_all1'} :
$nofile==1 ? $text{'allow_all2'} :
$text{'allow_all3'};
printf "<input type=radio name=mode value=1 %s> $text{'allow_allow'}\n",
$allowfile ? "checked" : "";
printf "<input name=allow size=30 value=\"%s\"> %s<br>\n",
($allowfile ? join(' ', &list_allowed()) : ""),
&user_chooser_button("allow", 1);
printf "<input type=radio name=mode value=2 %s> $text{'allow_deny'}&nbsp;\n",
$denyfile && !$allowfile ? "checked" : "";
printf "<input name=deny size=30 value=\"%s\"> %s<br>\n",
($denyfile ? join(' ', &list_denied()) : ""),
&user_chooser_button("deny", 1);
print "<input type=submit value=\"$text{'save'}\">\n";
print "</form>\n";
$mode = !$allowfile && !$denyfile ? 0 :
$allowfile ? 1 : 2;
print &ui_radio_table("mode", $mode,
[ [ 0, $nofile==0 ? $text{'allow_all1'} :
$nofile==1 ? $text{'allow_all2'} :
$text{'allow_all3'} ],
[ 1, $text{'allow_allow'},
&ui_textbox("allow",
$allowfile ? join(' ', &list_allowed()) : "", 50).
" ".&user_chooser_button("allow", 1) ],
[ 2, $text{'allow_deny'},
&ui_textbox("deny",
$denyfile ? join(' ', &list_denied()) : "", 50).
" ".&user_chooser_button("deny", 1) ] ]);
print &ui_form_end([ [ undef, $text{'save'} ] ]);
&ui_print_footer("", $text{'index_return'});

View File

@ -19,72 +19,58 @@ else {
print "$text{'env_order'}<p>\n";
print "<form action=save_env.cgi>\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{'env_details'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_form_start("save_env.cgi", "post");
print &ui_hidden("new", $in{'new'});
print &ui_hidden("idx", $in{'idx'});
print &ui_table_start($text{'env_details'}, "width=100%", 2);
print "<tr> <td><b>$text{'env_user'}</b></td>\n";
# Under user
if ($access{'mode'} == 1) {
print "<td><select name=user>\n";
foreach $u (split(/\s+/, $access{'users'})) {
printf "<option %s>$u\n",
$env->{'user'} eq $u ? "selected" : "";
}
print "</select></td>\n";
$usel = &ui_select("user", $env->{'user'},
[ split(/\s+/, $access{'users'}) ]);
}
elsif ($access{'mode'} == 3) {
print "<td><tt>$remote_user</tt></td>\n";
print "<input type=hidden name=user value='$remote_user'>\n";
$usel = "<tt>$remote_user</tt>";
print &ui_hidden("user", $remote_user);
}
else {
print "<td><input name=user size=8 value=\"$env->{'user'}\"> ",
&user_chooser_button("user", 0),"</td>\n";
$usel = &ui_user_textbox("user", $env->{'user'});
}
print &ui_table_row($text{'env_user'}, $usel);
print "<td> <b>$text{'env_active'}</b></td>\n";
printf "<td><input type=radio name=active value=1 %s> $text{'yes'}\n",
$env->{'active'} ? "checked" : "";
printf "<input type=radio name=active value=0 %s> $text{'no'}</td> </tr>\n",
$env->{'active'} ? "" : "checked";
# Active or now
print &ui_table_row($text{'env_active'},
&ui_yesno_radio("active", $env->{'active'} ? 1 : 0));
print "<td> <b>$text{'env_name'}</b></td>\n";
printf "<td><input name=name size=30 value='%s'></td> </tr>\n",
$env->{'name'};
# Variable name
print &ui_table_row($text{'env_name'},
&ui_textbox("name", $env->{'name'}, 50));
print "<td> <b>$text{'env_value'}</b></td>\n";
printf "<td><input name=value size=60 value='%s'></td> </tr>\n",
$env->{'value'};
# Variable value
print &ui_table_row($text{'env_value'},
&ui_textbox("value", $env->{'value'}, 50));
if ($in{'new'}) {
# Location for new variable
print "<td> <b>$text{'env_where'}</b></td> <td colspan=3>\n";
print &ui_radio("where", 1, [ [ 1, $text{'env_top'} ],
[ 0, $text{'env_bot'} ] ]),"</td></tr>\n";
print &ui_table_row($text{'env_where'},
&ui_radio("where", 1, [ [ 1, $text{'env_top'} ],
[ 0, $text{'env_bot'} ] ]));
}
elsif ($env->{'index'}) {
# Location for existing
print "<td> <b>$text{'env_where2'}</b></td> <td colspan=3>\n";
print &ui_radio("where", 0, [ [ 1, $text{'env_top'} ],
[ 0, $text{'env_leave'} ]]),"</td></tr>\n";
print &ui_table_row($text{'env_where2'},
&ui_radio("where", 0, [ [ 1, $text{'env_top'} ],
[ 0, $text{'env_leave'} ]]));
}
print "</table></td></tr></table>\n";
print "<table width=100%><tr>\n";
print &ui_table_end();
if ($in{'new'}) {
print "<td><input type=submit value='$text{'create'}'></td>\n";
print &ui_form_end([ [ undef, $text{'create'} ] ]);
}
else {
print "<td><input type=submit value='$text{'save'}'></td>\n";
print "</form><form action=delete_env.cgi>\n";
print "<input type=hidden name=idx value=\"$in{'idx'}\">\n";
print "<td align=right><input type=submit name=delete ",
"value='$text{'delete'}'></td>\n";
print &ui_form_end([ [ undef, $text{'save'} ],
[ "delete", $text{'delete'} ] ]);
}
print "</tr></table></form>\n";
&ui_print_footer("", $text{'index_return'});

View File

@ -3,8 +3,9 @@
# Display a list of all cron jobs, with the username and command for each one
require './cron-lib.pl';
&ReadParse();
&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
$max_jobs = $userconfig{'max_jobs'} || $config{'max_jobs'};
# Make sure cron is installed (very likely!)
if ($config{'single_file'} && !-r $config{'single_file'}) {
@ -61,11 +62,12 @@ if ($config{cron_allow_file} && $config{cron_deny_file} && $access{'allow'}) {
push(@crlinks, "<a href=edit_allow.cgi>$text{'index_allow'}</a>");
}
# Show cron jobs by user
$single_file = !&supports_users() || !(@ulist != 1 || $access{'mode'} != 3);
# Build a list of cron job rows to show
$single_user = !&supports_users() || @ulist == 1;
@links = ( &select_all_link("d"),
&select_invert_link("d"),
@crlinks );
@rows = ( );
foreach $u (@ulist) {
if (!$config{'single_file'}) {
# Get the Unix user's real name
@ -90,68 +92,45 @@ foreach $u (@ulist) {
&convert_comment($job);
local @exp = @{$plist[$i]->[1]};
local $idx = $job->{'index'};
if (!$donehead) {
print &ui_form_start("delete_jobs.cgi", "post");
print &ui_links_row(\@links);
print "<table border width=100%> <tr $tb>\n";
if (!$single_file) {
print "<td><b>$text{'index_user'}</b></td>\n";
}
print "<td width=5><br></td>\n";
print "<td><b>$text{'index_active'}</b></td>\n";
if ($access{'command'}) {
print "<td><b>$text{'index_command'}</b></td>\n";
}
if (!$access{'command'} || $config{'show_time'} || $userconfig{'show_time'}) {
print "<td><b>$text{'index_when'}</b></td>\n";
}
if ($config{'show_comment'} || $userconfig{'show_comment'}) {
print "<td><b>$text{'index_comment'}</b></td>\n";
}
if ($config{'show_run'}) {
print "<td width=5%><b>$text{'index_run'}</b></td>\n";
}
if ($access{'move'}) {
print "<td width=5%><b>$text{'index_move'}</b></td>\n";
}
print "</tr>\n";
$donehead = 1;
}
local @cols;
print "<tr $cb>\n";
if ($i == 0 && !$single_file) {
printf "<td valign=top rowspan=%d>", scalar(@plist);
print &html_escape($uname);
print "</td>\n";
push(@cols, $idx);
$useridx = 0;
$cmdidx = 0;
if (!$single_user) {
$useridx = scalar(@cols);
push(@cols, &html_escape($uname));
}
print "<td>",&ui_checkbox("d", $idx),"</td>\n";
printf "<td valign=top>%s</td>\n",
$job->{'active'} ? $text{'yes'}
: "<font color=#ff0000>$text{'no'}</font>";
push(@cols, $job->{'active'} ? $text{'yes'} :
"<font color=#ff0000>$text{'no'}</font>");
$donelink = 0;
if ($job->{'name'}) {
# An environment variable - show the name only
print "<td><a href=\"edit_env.cgi?idx=$idx\">",
"<i>$text{'index_env'}</i> ",
"<tt>$job->{'name'} = $job->{'value'}</tt></td>\n";
$cmdidx = scalar(@cols);
push(@cols, "<a href=\"edit_env.cgi?idx=$idx\">".
"<i>$text{'index_env'}</i> ".
"<tt>$job->{'name'} = $job->{'value'}</tt>");
$donelink = 1;
}
elsif (@exp && $access{'command'}) {
# A multi-part command
$cmdidx = scalar(@cols);
@exp = map { &html_escape($_) } @exp;
print "<td><a href=\"edit_cron.cgi?idx=$idx\">",
join("<br>",@exp),"</a></td>\n";
push(@cols, "<a href=\"edit_cron.cgi?idx=$idx\">".
join("<br>",@exp)."</a>");
$donelink = 1;
}
elsif ($access{'command'}) {
# A simple command
$cmdidx = scalar(@cols);
local $max = $config{'max_len'} || 10000;
local ($cmd, $input) =
&extract_input($job->{'command'});
$cmd =
length($cmd) > $max ?
&html_escape(substr($cmd, 0, $max))." ..." :
$cmd = length($cmd) > $max ?
&html_escape(substr($cmd, 0, $max))." ..." :
$cmd !~ /\S/ ? "BLANK" : &html_escape($cmd);
print "<td><a href=\"edit_cron.cgi?idx=$idx\">$cmd</a></td>\n";
push(@cols,
"<a href=\"edit_cron.cgi?idx=$idx\">$cmd</a>");
$donelink = 1;
}
@ -159,27 +138,27 @@ foreach $u (@ulist) {
if (!$access{'command'} || $config{'show_time'} || $userconfig{'show_time'}) {
$when = &when_text($job, 1);
if ($job->{'name'}) {
print "<td><br></td>\n";
push(@cols, "");
}
elsif ($donelink) {
print "<td>$when</td>\n";
push(@cols, $when);
}
else {
print "<td><a href='edit_cron.cgi?idx=$idx'>$when</a></td>\n";
push(@cols,
"<a href='edit_cron.cgi?idx=$idx'>$when</a>");
}
}
# Show comment
if ($config{'show_comment'} || $userconfig{'show_comment'}) {
print "<td>",($job->{'comment'} || "<br>"),"</td>\n";
push(@cols, $job->{'comment'});
}
# Show running indicator
if ($config{'show_run'}) {
print "<td>";
if ($job->{'name'}) {
# An environment variable
print "<br>\n";
push(@cols, "");
}
else {
# Try to find the process
@ -190,56 +169,91 @@ foreach $u (@ulist) {
if ($config{'show_run'} == 2 &&
($access{'kill'} || !$proc)) {
$lnk = $proc ? "kill_cron.cgi?idx=$idx" : "exec_cron.cgi?idx=$idx&bg=1";
print "<a href='$lnk'>$txt</a>";
push(@cols, "<a href='$lnk'>$txt</a>");
}
else {
print $txt;
push(@cols, $txt);
}
}
print "</td>\n";
}
# Show mover buttons
local $prv = $i > 0 ? $plist[$i-1]->[0] : undef;
local $nxt = $i != $#plist ? $plist[$i+1]->[0] : undef;
if ($access{'move'}) {
print "<td width=5%>";
if ($prv && $prv->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3)) {
print "<a href='move.cgi?idx=$idx&up=1'>",
"<img src=images/up.gif border=0></a>";
}
else {
print "<img src=images/gap.gif>";
}
if ($nxt && $nxt->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3)) {
print "<a href='move.cgi?idx=$idx&down=1'>",
"<img src=images/down.gif border=0></a>";
}
else {
print "<img src=images/gap.gif>";
}
print "</td>\n";
push(@cols, &ui_up_down_arrows(
"move.cgi?idx=$idx&up=1",
"move.cgi?idx=$idx&down=1",
$prv && $prv->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3),
$nxt && $nxt->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3)
));
}
print "</tr>\n";
push(@rows, \@cols);
}
}
if ($donehead) {
print "</table>\n";
print &ui_links_row(\@links);
# Limit to search
if ($in{'search'}) {
@rows = grep { $useridx && $_->[$useridx] =~ /\Q$in{'search'}\E/i ||
$cmdidx && $_->[$cmdidx] =~ /\Q$in{'search'}\E/i }
@rows;
}
else {
print $module_info{'usermin'} ? "<b>$text{'index_none3'}</b> <p>\n" :
$access{'mode'} ? "<b>$text{'index_none2'}</b> <p>\n"
: "<b>$text{'index_none'}</b> <p>\n";
# Check if we are over the display limit
if ($max_jobs && @rows > $max_jobs && !$in{'search'}) {
print &ui_form_start("index.cgi");
print "<b>$text{'index_toomany'}</b>\n";
print &ui_textbox("search", $in{'search'}, 20);
print &ui_submit($text{'index_ok'});
print &ui_form_end();
print &ui_links_row(\@crlinks);
}
if ($donehead) {
elsif (@rows) {
# Show jobs
if ($in{'search'}) {
print "<b>",&text('index_searchres',
"<i>".&html_escape($in{'search'})."</i>"),"</b><p>\n";
push(@links, "<a href='index.cgi'>$text{'index_reset'}</a>");
}
print &ui_form_start("delete_jobs.cgi", "post");
print &ui_links_row(\@links);
@tds = ( "width=5" );
print &ui_columns_start([
"",
$single_user ? ( ) : ( $text{'index_user'} ),
$text{'index_active'},
$access{'command'} ? ( $text{'index_command'} ) : ( ),
!$access{'command'} || $config{'show_time'} ||
$userconfig{'show_time'} ? ( $text{'index_when'} ) : ( ),
$config{'show_comment'} || $userconfig{'show_comment'} ?
( $text{'index_comment'} ) : ( ),
$config{'show_run'} ? ( $text{'index_run'} ) : ( ),
$access{'move'} ? ( $text{'index_move'} ) : ( ),
], 100, 0, \@tds);
foreach my $r (@rows) {
print &ui_checked_columns_row([ @$r[1..(@$r-1)] ],
\@tds, "d", $r->[0]);
}
print &ui_columns_end();
print &ui_links_row(\@links);
print &ui_form_end([ [ "delete", $text{'index_delete'} ],
[ "disable", $text{'index_disable'} ],
[ "enable", $text{'index_enable'} ] ]);
}
else {
# Show message
if ($in{'search'}) {
push(@crlinks, "<a href='index.cgi'>$text{'index_reset'}</a>");
}
print $in{'search'} ? "<b>".&text('index_esearch',
"<i>".&html_escape($in{'search'})."</i>")."</b> <p>" :
$module_info{'usermin'} ? "<b>$text{'index_none3'}</b> <p>\n" :
$access{'mode'} ? "<b>$text{'index_none2'}</b> <p>\n"
: "<b>$text{'index_none'}</b> <p>\n";
print &ui_links_row(\@crlinks);
}
&ui_print_footer("/", $text{'index'});

View File

@ -19,6 +19,11 @@ index_esingle=The file $1 listing Cron jobs does not exist. Maybe Cron is not in
index_delete=Delete Selected Jobs
index_disable=Disable Selected Jobs
index_enable=Enable Selected Jobs
index_esearch=No jobs matched your search for $1.
index_toomany=There are too many jobs to show. Find those matching :
index_ok=Search
index_searchres=Cron jobs matching $1 ..
index_reset=Reset search.
edit_title=Edit Cron Job
create_title=Create Cron Job

View File

@ -16,6 +16,12 @@ else {
$job->{'line'} = $oldjob->{'line'};
}
if ($in{'delete'}) {
# Just re-direct to delete CGI
&redirect("delete_env.cgi?idx=$in{'idx'}");
exit;
}
@files = &unique((map { $_->{'file'} } @jobs),
"$config{'cron_dir'}/$in{'user'}");
foreach $f (@files) { &lock_file($f); }