Locking and logging support.
authorJamie Cameron <jcameron@webmin.com>
Fri, 15 Oct 2010 23:48:34 +0000 (16:48 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 15 Oct 2010 23:48:34 +0000 (16:48 -0700)
Ability to move boot options.

grub/CHANGELOG
grub/down.cgi [new file with mode: 0755]
grub/grub-lib.pl
grub/index.cgi
grub/install.cgi
grub/lang/en
grub/log_parser.pl [new file with mode: 0755]
grub/save_global.cgi
grub/save_title.cgi
grub/up.cgi [new file with mode: 0755]

index 967da3b..84851aa 100644 (file)
@@ -2,3 +2,6 @@
 Converted all code to use the new Webmin user interface library.
 ---- Changes since 1.400 ----
 Multiple module lines in menu.lst are now preserved and editable. This prevents breakage sometimes seen on kernels using Xen.
+---- Changes since 1.520 ----
+Added arrows to move boot options up or down in the list of those available.
+Added locking and logging, so that changes can be viewed in the Webmin Actions Log module.
diff --git a/grub/down.cgi b/grub/down.cgi
new file mode 100755 (executable)
index 0000000..cf2efb4
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/local/bin/perl
+# Move a title down
+
+require './grub-lib.pl';
+&ReadParse();
+&lock_file($config{'menu_file'});
+$conf = &get_menu_config();
+@t = &find("title", $conf);
+&swap_directives($t[$in{'idx'}], $t[$in{'idx'}+1]);
+&flush_file_lines($config{'menu_file'});
+&unlock_file($config{'menu_file'});
+&webmin_log("down", "title", undef, $t[$in{'idx'}]);
+&redirect("");
+
index c522c62..36fbaf2 100755 (executable)
@@ -100,6 +100,23 @@ else {
        }
 }
 
+# swap_directives(&dir1, &dir2)
+# Swaps two blocks in the config file
+sub swap_directives
+{
+my ($dir1, $dir2) = @_;
+local $lref = &read_file_lines($config{'menu_file'});
+if ($dir1->{'line'} > $dir2->{'line'}) {
+       ($dir1, $dir2) = ($dir2, $dir1);
+       }
+my @lines1 = @$lref[$dir1->{'line'} .. $dir1->{'eline'}];
+my @lines2 = @$lref[$dir2->{'line'} .. $dir2->{'eline'}];
+my $len1 = $dir1->{'eline'} - $dir1->{'line'} + 1;
+my $len2 = $dir2->{'eline'} - $dir2->{'line'} + 1;
+splice(@$lref, $dir2->{'line'}, $len2, @lines1);
+splice(@$lref, $dir1->{'line'}, $len1, @lines2);
+}
+
 # find(name, &config)
 sub find
 {
index 5fe1080..d67a530 100755 (executable)
@@ -24,17 +24,26 @@ if (!&has_command($config{'grub_path'})) {
 @crlinks = ( "<a href='edit_title.cgi?new=1'>$text{'index_add'}</a>" );
 $conf = &get_menu_config();
 $def = &find_value("default", $conf);
-foreach $t (&find("title", $conf)) {
+@t = &find("title", $conf);
+$i = 0;
+foreach $t (@t) {
        push(@icons, $t->{'chainloader'} ? "images/chain.gif"
                                         : "images/kernel.gif");
        local $tt = &html_escape($t->{'value'});
        push(@titles, $def == $i ? "<b>$tt</b>" : $tt);
        push(@links, "edit_title.cgi?idx=$t->{'index'}");
+       push(@befores, $i == 0 ? "&lt;&lt;&nbsp;|&nbsp;" :
+               "<a href='up.cgi?idx=$i'>".
+               "&lt;&lt;</a>&nbsp;|&nbsp;");
+       push(@afters, $i == @t-1 ? "&nbsp;|&nbsp;&gt;&gt;" :
+               "&nbsp;|&nbsp;<a href='down.cgi?idx=$i'>".
+               "&gt;&gt;</a>");
        $i++;
        }
 if (@links) {
        print &ui_links_row(\@crlinks);
-       &icons_table(\@links, \@titles, \@icons, 4);
+       &icons_table(\@links, \@titles, \@icons, 4, undef, undef, undef,
+                    \@befores, \@afters);
        }
 else {
        print "<b>$text{'index_none'}</b><p>\n";
index eb0c501..33e3eda 100755 (executable)
@@ -69,5 +69,6 @@ else {
        print "$text{'install_ok'}<p>\n";
        }
 
+&webmin_log("install");
 &ui_print_footer("", $text{'index_return'});
 
index 544d073..5df715f 100644 (file)
@@ -67,3 +67,10 @@ install_desc=Installing GRUB on $1 with commands $2 and $3 ..
 install_ok=.. install complete.
 install_failed=.. install failed!
 
+log_create_title=Created boot option $1
+log_delete_title=Deleted boot option $1
+log_modify_title=Modified boot option $1
+log_up_title=Moved up boot option $1
+log_down_title=Moved down  boot option $1
+log_global=Changed global options
+log_install=Installed GRUB
diff --git a/grub/log_parser.pl b/grub/log_parser.pl
new file mode 100755 (executable)
index 0000000..0907554
--- /dev/null
@@ -0,0 +1,19 @@
+# log_parser.pl
+# Functions for parsing this module's logs
+
+do 'grub-lib.pl';
+
+# parse_webmin_log(user, script, action, type, object, &params)
+# Converts logged information from this module into human-readable form
+sub parse_webmin_log
+{
+my ($user, $script, $action, $type, $object, $p) = @_;
+if ($type eq 'title') {
+       return &text('log_'.$action.'_title',
+                    "<i>".&html_escape($p->{'value'})."</i>");
+       }
+else {
+       return $text{'log_'.$action};
+       }
+}
+
index bdc1f59..be56bd1 100755 (executable)
@@ -5,6 +5,7 @@
 require './grub-lib.pl';
 &ReadParse();
 &error_setup($text{'global_err'});
+&lock_file($config{'menu_file'});
 $conf = &get_menu_config();
 &error_setup($text{'global_err'});
 
@@ -57,6 +58,8 @@ else {
        $config{'install'} = $in{'other'};
        }
 &write_file("$module_config_directory/config", \%config);
-&flush_file_lines();
+&flush_file_lines($config{'menu_file'});
+&unlock_file($config{'menu_file'});
+&webmin_log("global");
 &redirect("");
 
index 513d2e2..d534c15 100755 (executable)
@@ -4,6 +4,7 @@
 
 require './grub-lib.pl';
 &ReadParse();
+&lock_file($config{'menu_file'});
 $conf = &get_menu_config();
 if (!$in{'new'}) {
        $old = $title = $conf->[$in{'idx'}];
@@ -74,6 +75,9 @@ else {
        &save_directive($conf, $old, $title);
        }
 
-&flush_file_lines();
+&flush_file_lines($config{'menu_file'});
+&unlock_file($config{'menu_file'});
+&webmin_log($in{'new'} ? 'create' : $in{'delete'} ? 'delete' : 'modify',
+            'title', undef, $title);
 &redirect("");
 
diff --git a/grub/up.cgi b/grub/up.cgi
new file mode 100755 (executable)
index 0000000..141c814
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/local/bin/perl
+# Move a title up
+
+require './grub-lib.pl';
+&ReadParse();
+&lock_file($config{'menu_file'});
+$conf = &get_menu_config();
+@t = &find("title", $conf);
+&swap_directives($t[$in{'idx'}], $t[$in{'idx-1'}]);
+&flush_file_lines($config{'menu_file'});
+&unlock_file($config{'menu_file'});
+&webmin_log("up", "title", undef, $t[$in{'idx'}]);
+&redirect("");
+