ui-lib conversion, full command link
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 19:36:23 +0000 (19:36 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 19:36:23 +0000 (19:36 +0000)
at/CHANGELOG
at/at-lib.pl
at/create_job.cgi
at/delete_jobs.cgi
at/edit_job.cgi
at/index.cgi
at/lang/en
at/save_allow.cgi

index 30aa093..003b8fb 100644 (file)
@@ -4,3 +4,6 @@ Added the ability to run a scheduled command.
 Allowed and denied At users can now be managed, on Linux systems.
 ---- Changes since 1.300 ----
 Added checkboxes and a button for deleting multiple scheduled commands at once.
+---- Changes since 1.390 ----
+Converted all user interface code to use the new Webmin UI library.
+When editing a job, only the actual command entered is shown by default - the full command can be displayed using a new link.
index 541852d..2a69d07 100644 (file)
@@ -4,6 +4,7 @@
 do '../web-lib.pl';
 &init_config();
 do '../ui-lib.pl';
+%access = &get_module_acl();
 
 do "$config{'at_style'}-lib.pl";
 
index 46e2e2a..9b7008d 100755 (executable)
@@ -7,7 +7,6 @@ require 'timelocal.pl';
 require './at-lib.pl';
 &ReadParse();
 &error_setup($text{'create_err'});
-%access = &get_module_acl();
 
 # Validate inputs
 &can_edit_user(\%access, $in{'user'}) || &error($text{'create_ecannot'});
index d51af94..05c8ae1 100755 (executable)
@@ -9,7 +9,6 @@ require './at-lib.pl';
 
 # Delete each one
 @jobs = &list_atjobs();
-%access = &get_module_acl();
 foreach $d (@d) {
        ($job) = grep { $_->{'id'} eq $d } @jobs;
        $job || &error($text{'delete_egone'});
index 20202f3..e8a9a3e 100755 (executable)
@@ -7,40 +7,45 @@ require './at-lib.pl';
 @jobs = &list_atjobs();
 ($job) = grep { $_->{'id'} eq $in{'id'} } @jobs;
 $job || &error($text{'edit_ejob'});
-%access = &get_module_acl();
 &can_edit_user(\%access, $job->{'user'}) || &error($text{'edit_ecannot'});
 
 &ui_print_header(undef, $text{'edit_title'}, "");
 
-print "<form action=delete_job.cgi>\n";
-print "<input type=hidden name=id value='$in{'id'}'>\n";
-print "<table border width=100%>\n";
-print "<tr $tb> <td><b>$text{'edit_header'}</b></td> </tr>\n";
-print "<tr $cb> <td><table width=100%>\n";
+print &ui_form_start("delete_job.cgi");
+print &ui_hidden("id", $in{'id'});
+print &ui_table_start($text{'edit_header'}, "width=100%", 4);
 
-print "<tr> <td><b>$text{'index_user'}</b></td>\n";
-print "<td colspan=3>",&html_escape($job->{'user'}),"\n";
+# Run as user
 @uinfo = getpwnam($job->{'user'});
 $uinfo[6] =~ s/,.*$//g;
-print " (",&html_escape($uinfo[6]),")\n" if ($uinfo[6]);
-print "</td> </tr>\n";
-
-$date = localtime($job->{'date'});
-print "<tr> <td><b>$text{'index_exec'}</b></td>\n";
-print "<td>$date</td>\n";
-
-$created = localtime($job->{'created'});
-print "<td><b>$text{'index_created'}</b></td>\n";
-print "<td>$created</td> </tr>\n";
-
-print "<tr> <td valign=top><b>$text{'edit_cmd'}</b></td>\n";
-print "<td colspan=3><font size=-1><pre>",
-      &html_escape(join("\n", &wrap_lines($job->{'cmd'}, 80))),
-      "</pre></font></td> </tr>\n";
-
-print "<tr> <td colspan=4 align=right>",
-      "<input type=submit name=run value='$text{'edit_run'}'> ",
-      "<input type=submit value='$text{'edit_delete'}'></td> </tr>\n";
+print &ui_table_row($text{'index_user'},
+       &html_escape($job->{'user'}).
+       ($uinfo[6] ? " (".&html_escape($uinfo[6]).")" : ""), 3);
+
+# When to run
+print &ui_table_row($text{'index_exec'}, &make_date($job->{'date'}));
+
+# When created
+print &ui_table_row($text{'index_created'}, &make_date($job->{'created'}));
+
+if ($in{'full'}) {
+       # Full command
+       print &ui_table_row($text{'edit_cmd'},
+               "<pre>".&html_escape(
+                   join("\n", &wrap_lines($job->{'cmd'}, 80)))."</pre>", 3);
+       }
+else {
+       # Just the short command
+       print &ui_table_row($text{'edit_shortcmd'},
+               "<pre>".&html_escape(
+                   join("\n", &wrap_lines($job->{'realcmd'}, 80)))."</pre>".
+               "<a href='edit_job.cgi?full=1&id=".&urlize($in{'id'})."'>".
+               $text{'edit_showfull'}."</a>", 3);
+       }
+
+print &ui_table_end();
+print &ui_form_end([ [ "run", $text{'edit_run'} ],
+                    [ undef, $text{'edit_delete'} ] ]);
 
 print "</table></td></tr></table></form>\n";
 &ui_print_footer("", $text{'index_return'});
index d90cdab..b5c6340 100755 (executable)
@@ -9,7 +9,6 @@
 require './at-lib.pl';
 use POSIX;
 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
-%access = &get_module_acl();
 ReadParse();
 
 # Show list of existing jobs
@@ -18,7 +17,7 @@ ReadParse();
 if (@jobs) {
        print &ui_form_start("delete_jobs.cgi", "post");
        @jobs = sort { $a->{'id'} <=> $b->{'id'} } @jobs;
-       @tds = ( "width=5" );
+       @tds = ( "width=5", "nowrap" );
        @links = ( &select_all_link("d"), &select_invert_link("d") );
        print &ui_links_row(\@links);
        print &ui_columns_start([
@@ -49,64 +48,54 @@ if (@jobs) {
 
 
 # Show form for creating a new At job
-print "<form action=create_job.cgi>\n";
-print "<table border>\n";
-print "<tr $tb> <td><b>$text{'index_header'}</b></td> </tr>\n";
-print "<tr $cb> <td><table>\n";
+print &ui_form_start("create_job.cgi");
+print &ui_table_start($text{'index_header'}, undef, 2);
 
-print "<tr> <td><b>$text{'index_user'}</b></td>\n";
+# User to run as
 $dir = "/";
 if ($access{'mode'} == 1) {
-       print "<td><select name=user>\n";
-       foreach $u (split(/\s+/, $access{'users'})) {
-               print "<option>$u\n";
-               }
-       print "</select></td>\n";
+       $usel = &ui_select("user", undef,
+                          [ 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);
        @uinfo = getpwnam($remote_user);
        $dir = $uinfo[7];
        }
 else {
-       print "<td><input name=user value=\"$in{ext_user}\" size=8>",
-               &user_chooser_button("user", 0),"</td>\n";
+       $usel = &ui_user_textbox("user", $in{ext_user});
        }
+print &ui_table_row($text{'index_user'}, $usel);
 
+# Run date
 @now = localtime(time());
-print "<tr> <td><b>$text{'index_date'}</b></td>\n";
-printf "<td><input name=day size=2 value='%d'>/", $now[3];
-print "<select name=month>\n";
-for($i=0; $i<12; $i++) {
-       printf "<option value=%s %s>%s\n",
-               $i, $now[4] == $i ? 'selected' : '', $text{"smonth_".($i+1)};
-       }
-print "</select>/";
-printf "<input name=year size=4 value='%d'>\n", $now[5] + 1900;
-print &date_chooser_button("day", "month", "year"),"</td>\n";
-
-print "<td><b>$text{'index_time'}</b></td>\n";
-print "<td><input name=hour size=2>:<input name=min size=2 value='00'></td> </tr>\n";
-
+print &ui_table_row($text{'index_date'},
+       &ui_textbox("day", $now[3], 2)."/".
+       &ui_select("month", $now[4],
+                  [ map { [ $_, $text{"smonth_".($_+1)} ] } ( 0 .. 11 ) ])."/".
+       &ui_textbox("year", $now[5]+1900, 4).
+       &date_chooser_button("day", "month", "year"));
+
+# Run time
+print &ui_table_row($text{'index_time'},
+       &ui_textbox("hour", undef, 2).":".&ui_textbox("min", "00", 2));
+
+# Current date and time
 ($date, $time) = split(/\s+/, &make_date(time()));
+print &ui_table_row($text{'index_cdate'}, $date);
+print &ui_table_row($text{'index_ctime'}, $time);
 
-print "<tr> <td><b>$text{'index_cdate'}</b></td>\n";
-print "<td>$date</td>\n";
-
-print "<td><b>$text{'index_ctime'}</b></td>\n";
-print "<td>$time</td> </tr>\n";
-
-print "<tr> <td><b>$text{'index_dir'}</b></td>\n";
-print "<td colspan=3><input name=dir size=40 value='$dir'></td> </tr>\n";
-
-print "<tr> <td valign=top><b>$text{'index_cmd'}</b></td>\n";
-print "<td colspan=3><textarea rows=5 cols=40 name=cmd>$in{ext_cmd}</textarea></td></tr>\n";
+# Run in directory
+print &ui_table_row($text{'index_dir'},
+                   &ui_textbox("dir", $dir, 50));
 
-print "<tr> <td colspan=4 align=right>",
-      "<input type=submit value='$text{'create'}'></td> </tr>\n";
+# Commands to run
+print &ui_table_row($text{'index_cmd'},
+                   &ui_textarea("cmd", $in{ext_cmd}, 5, 50));
 
-print "</table></td></tr></table></form>\n";
+print &ui_table_end();
+print &ui_form_end([ [ undef, $text{'create'} ] ]);
 
 if ($access{'allow'} && $config{'allow_file'}) {
        # Show form to manage allowed and denied users
index d55c89c..ca5694b 100644 (file)
@@ -20,11 +20,13 @@ index_delete=Cancel Selected Commands
 
 edit_title=Scheduled Command
 edit_cmd=Full script to execute
+edit_shortcmd=Command to execute
 edit_header=Scheduled command details
 edit_delete=Cancel this command
 edit_run=Run Now
 edit_ejob=Scheduled command no longer exists!
 edit_ecannot=You are not allowed to edit this scheduled command
+edit_showfull=Show full script.
 
 create_err=Failed to created schedule command
 create_euser=Missing or invalid username
index 19e051f..7880aaa 100755 (executable)
@@ -2,7 +2,6 @@
 # Update allowed or denied At users
 
 require './at-lib.pl';
-%access = &get_module_acl();
 ReadParse();
 &error_setup($text{'allow_err'});
 $access{'allow'} || &error($text{'allow_ecannot'});