Ability to move boot options.
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.
--- /dev/null
+#!/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("");
+
}
}
+# 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
{
@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 ? "<< | " :
+ "<a href='up.cgi?idx=$i'>".
+ "<<</a> | ");
+ push(@afters, $i == @t-1 ? " | >>" :
+ " | <a href='down.cgi?idx=$i'>".
+ ">></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";
print "$text{'install_ok'}<p>\n";
}
+&webmin_log("install");
&ui_print_footer("", $text{'index_return'});
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
--- /dev/null
+# log_parser.pl
+# Functions for parsing this module's logs
+
+do 'grub-lib.pl';
+
+# parse_webmin_log(user, script, action, type, object, ¶ms)
+# 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};
+ }
+}
+
require './grub-lib.pl';
&ReadParse();
&error_setup($text{'global_err'});
+&lock_file($config{'menu_file'});
$conf = &get_menu_config();
&error_setup($text{'global_err'});
$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("");
require './grub-lib.pl';
&ReadParse();
+&lock_file($config{'menu_file'});
$conf = &get_menu_config();
if (!$in{'new'}) {
$old = $title = $conf->[$in{'idx'}];
&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("");
--- /dev/null
+#!/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("");
+