Locking and logging support.

Ability to move boot options.
This commit is contained in:
Jamie Cameron 2010-10-15 16:48:34 -07:00
parent d254023b26
commit c96720215e
10 changed files with 95 additions and 4 deletions

View 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.

14
grub/down.cgi Executable file
View File

@ -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("");

View File

@ -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
{

View File

@ -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";

View File

@ -69,5 +69,6 @@ else {
print "$text{'install_ok'}<p>\n";
}
&webmin_log("install");
&ui_print_footer("", $text{'index_return'});

View 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

19
grub/log_parser.pl Executable file
View File

@ -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};
}
}

View File

@ -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("");

View File

@ -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("");

14
grub/up.cgi Executable file
View File

@ -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("");