diff options
Diffstat (limited to 'perl-install/standalone/draksec')
| -rwxr-xr-x | perl-install/standalone/draksec | 139 |
1 files changed, 100 insertions, 39 deletions
diff --git a/perl-install/standalone/draksec b/perl-install/standalone/draksec index d62d5a313..105ab92f0 100755 --- a/perl-install/standalone/draksec +++ b/perl-install/standalone/draksec @@ -38,11 +38,23 @@ use security::l10n; #/^-?-(\S+)$/ and $options{$1} = 1 foreach @ARGV; +$ugtk2::wm_icon = "/usr/share/mcc/themes/default/draksec-mdk.png"; my ($w, %fields); ############################ I18N ################################### -my %inv_translations = map { translate($_) => $_ } N_("ALL"), N_("LOCAL"), N_("NONE"), N_("default"), N_("default"), N_("ignore"), N_("no"), N_("yes"); -my %translations = reverse %inv_translations; + +my @help; + +my %translations = ( + 'ALL' => N("ALL"), + 'LOCAL' => N("LOCAL"), + 'NONE' => N("NONE"), + 'default' => N("Default"), + 'ignore' => N("Ignore"), + 'no' => N("No"), + 'yes' => N("Yes"), +); +my %inv_translations = reverse %translations; sub to_i18n { map { $translations{$_} || $_ } @_ } sub from_i18n { $inv_translations{$_[0]} || $_[0] } @@ -54,8 +66,9 @@ my %inv_fields = reverse %fields; # factorize this with rpmdrake and harddrake2 sub wait_msg { my $mainw = ugtk2->new(N("Please wait"), (modal => 1, if_(!$::isEmbedded, transient => $w->{rwindow}))); - $mainw->{window}->add(new Gtk2::WrappedLabel($_[0])); + $mainw->{window}->add(Gtk2::WrappedLabel->new($_[0])); $mainw->{rwindow}->show_all; + $mainw->{rwindow}->realize; gtkset_mousecursor_wait($mainw->{rwindow}->window); gtkflush(); $mainw; @@ -67,28 +80,35 @@ sub basic_seclevel_explanations() { my $text = Gtk2::TextView->new; use Gtk2::Pango; my %common_opts = ('left-margin' => '10', 'right-margin' => '10'); + # this is a small parser for a Pango Text Attribute Markup Language-like for TextViews widget gtktext_insert($text, [ map { - if (my ($title, $str) = m!<span foreground="royalblue3">(.*)</span>(.*)!) { - if_($title, [ $title, { 'foreground' => 'royalblue3', 'weight' => Gtk2::Pango->PANGO_WEIGHT_BOLD, %common_opts } ]), - if_($str, [ $str . "\n\n", \%common_opts ]); + if (s!^/span>!!) { + [ $_, \%common_opts ]; + } elsif (s!span !!) { + my %tags = %common_opts; + while (s!(\w+?)="(\w+?)"!!) { + $tags{weight} ||= Gtk2::Pango->PANGO_WEIGHT_BOLD if $1 eq 'foreground'; + $tags{$1} = $2 eq "bold" ? Gtk2::Pango->PANGO_WEIGHT_BOLD : $2; + } + s/^>//; + [ $_, \%tags ]; } else { - if_($_, [ "$_\n\n", \%common_opts ]); - } - } split("\n", - - formatAlaTeX( -#-PO: Do not alter the <span ..> and </span> tags -#-PO: Translate the security levels (Poor, Standard, High, Higher and Paranoid) in the same way, you translated these individuals words + [ $_, \%common_opts ]; + } + } split("<", formatAlaTeX( +#-PO: Do not alter the <span ..> and </span> tags. +#-PO: Translate the security levels (Poor, Standard, High, Higher and Paranoid) in the same way, you translated these individuals words. +#-PO: keep the double empty lines between sections, this is formatted a la LaTeX. N("Here, you can setup the security level and administrator of your machine. -The Security Administrator is the one who will receive security alerts if the -'Security Alerts' option is set. It can be a username or an email. +The '<span weight=\"bold\">Security Administrator</span>' is the one who will receive security alerts if the +'<span weight=\"bold\">Security Alerts</span>' option is set. It can be a username or an email. -The Security Level menu allows you to select one of the six preconfigured security levels -provided with msec. These levels range from poor security and ease of use, to -paranoid config, suitable for very sensitive server applications: +The '<span weight=\"bold\">Security Level</span>' menu allows you to select one of the six preconfigured security levels +provided with msec. These levels range from '<span weight=\"bold\">poor</span>' security and ease of use, to +'<span weight=\"bold\">paranoid</span>' config, suitable for very sensitive server applications: <span foreground=\"royalblue3\">Poor</span>: This is a totally unsafe but very @@ -118,16 +138,36 @@ maximum"))) ]); sub new_nonedit_combo { my ($string_list, $o_default_value) = @_; - my $w = Gtk2::ComboBox->new_text ; - $w->set_popdown_strings(to_i18n(@$string_list)) unless is_empty_array_ref $string_list; - $w->entry->set_text(to_i18n($o_default_value)) if $o_default_value; - $w; + Gtk2::ComboBox->new_with_strings([ to_i18n(@$string_list) ], to_i18n($o_default_value)); +} + +sub register_help_page { + my ($domain) = @_; + push @help, + ([ + [ $domain . "\n\n", + { + justification => 'center', + scale => Gtk2::Pango->PANGO_SCALE_LARGE, + weight => Gtk2::Pango->PANGO_WEIGHT_BOLD, + }, + ], + [ N("Description of the fields:\n\n"), ], + ], + ); } -sub set_help_tip { - my ($entry, $default, $opt) = @_; + +sub register_help_entry { + my ($label, $default, $opt) = @_; my $help = $security::help::help{$opt}; - gtkset_tip(new Gtk2::Tooltips, $entry, formatAlaTeX($help) . "\n" . N("(default value: %s)", to_i18n($default))); + push @{$help[-1]}, + ([ + formatAlaTeX($label) . ":\n", + { foreground => "royalblue3" }, + ], + [ join("\n", formatAlaTeX($help), N("(default value: %s)", to_i18n($default)), "\n") ] + ); } my $msec = new security::msec; @@ -147,7 +187,7 @@ unless ($::isEmbedded) { $window->signal_connect('delete_event', sub { $window->destroy }); $window->signal_connect('destroy', sub { ugtk2->exit }); -$window->add(my $vbox = gtkshow(new Gtk2::VBox(0, 0))); +$window->add(my $vbox = gtkshow(Gtk2::VBox->new(0, 0))); # Create the notebook (for bookmarks at the top) my $notebook = create_notebook(); @@ -157,7 +197,7 @@ my $common_opts = { col_spacings => 10, row_spacings => 5, mcc => 1 }; ######################## BASIC OPTIONS PAGE ################################ my ($seclevel_entry, $secadmin_entry); -$notebook->append_page(gtkshow(gtkpack_(new Gtk2::VBox(0, 0), +$notebook->append_page(gtkshow(gtkpack_(Gtk2::VBox->new(0, 0), 1, basic_seclevel_explanations(), 0, create_packtable($common_opts, [ @@ -177,7 +217,7 @@ $notebook->append_page(gtkshow(gtkpack_(new Gtk2::VBox(0, 0), }) ], [ Gtk2::WrappedLabel->new(N("Security Administrator:")), $secadmin_entry = Gtk2::Entry->new_with_text($msec->get_check_value("MAIL_USER")) ]))), - new Gtk2::Label(N("Basic options"))); + Gtk2::Label->new(N("Basic options"))); if ($msec->get_check_value("MAIL_WARN") eq "yes") { $secadmin_check->set_active(1); @@ -190,13 +230,12 @@ my @yesno_choices = qw(yes no default ignore); my @alllocal_choices = qw(ALL LOCAL NONE default); my @all_choices = (@yesno_choices, @alllocal_choices); my %options_values; -my $help_msg = N("The following options can be set to customize your\nsystem security. If you need an explanation, look at the help tooltip.\n"); foreach ([ 'network', N("Network Options") ], [ 'system', N("System Options") ]) { my ($domain, $label) = @$_; + register_help_page($label); my %values; - $notebook->append_page(gtkshow(gtkpack_(Gtk2::VBox->new, - 0, Gtk2::Label->new($help_msg), + gtkappend_page($notebook, gtkshow(gtkpack_(Gtk2::VBox->new, 1, create_scrolled_window(create_packtable($common_opts, map { my $i = $_; @@ -208,11 +247,11 @@ foreach ([ 'network', N("Network Options") ], [ 'system', N("System Options") ]) $values{$i} = new_nonedit_combo(member($default, @yesno_choices) ? \@yesno_choices : if_(member($default, @alllocal_choices), \@alllocal_choices)); $entry = $values{$i}->entry; } else { - $values{$i} = new Gtk2::Entry(); + $values{$i} = Gtk2::Entry->new; $entry = $values{$i}; } $entry->set_text(to_i18n($msec->get_function_value($opt))); - set_help_tip($entry, $default, $opt); + register_help_entry($i, $default, $opt); [ Gtk2::WrappedLabel->new($i), resize($values{$i}) ]; } sort map { $fields{$_} || $_ } $msec->list_functions($domain), ), @@ -227,18 +266,20 @@ foreach ([ 'network', N("Network Options") ], [ 'system', N("System Options") ]) ######################## PERIODIC CHECKS ################################### my %security_checks_value; -$notebook->append_page(gtkshow(gtkpack_(Gtk2::VBox->new, - 0, Gtk2::Label->new($help_msg), +my $check_string = N("Periodic Checks"); + +register_help_page($check_string); +gtkappend_page($notebook, gtkshow(gtkpack_(Gtk2::VBox->new, 1, create_scrolled_window(create_packtable($common_opts, map { my $i = $_; my $opt = $inv_fields{$i} || $i; $security_checks_value{$i} = new_nonedit_combo([ 'yes', 'no', 'default' ], $msec->get_check_value($opt)); my $entry = $security_checks_value{$i}->entry; - set_help_tip($entry, $msec->get_check_default($opt), $opt); + register_help_entry($i, $msec->get_check_default($opt), $opt); [ gtkshow(Gtk2::WrappedLabel->new($i)), resize($security_checks_value{$i}) ]; } sort map { $fields{$_} || $_ } $msec->list_checks)))), - new Gtk2::Label(N("Periodic Checks"))); + Gtk2::Label->new($check_string)); ####################### OK CANCEL BUTTONS ################################## @@ -286,7 +327,7 @@ gtkpack_($vbox, } $msec->apply_functions; log::explanations("Applying msec changes"); - run_program::rooted($::prefix, "/usr/sbin/msec"); + run_program::run("/usr/sbin/msec"); remove_wait_msg($w); @@ -294,9 +335,29 @@ gtkpack_($vbox, } }, undef, undef, '', - [ N("Help"), sub { unless (fork()) { exec("drakhelp --id draksec") } } ], + [ N("Help"), sub { + my $text = Gtk2::TextView->new; + create_dialog(N("Help"), + gtktext_insert($text, + [ + # -1 b/c of main page: + @{$help[$notebook->get_current_page-1]} + ] + ), + { use_markup => 1, + if_(!$::isEmbedded, transient => $w->{window}), + height => 400, + width => 600, + scroll => 1, + }, + ); + } ], ), ); + +$notebook->signal_connect("switch-page" => sub { $oc->{buttons}{N("Help")}->set_sensitive($_[2]) }); + +$oc->{buttons}{N("Help")}->set_sensitive(0); $oc->{cancel}->can_default(1); $oc->{cancel}->grab_default; |
