summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/draksec
blob: 6a08e4f8b86a72aec7ae8281a3ca5208f12d4414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/perl
#*****************************************************************************
#
# Copyright (c) 2002 Christian Belisle (cbelisle@mandrakesoft.com)
#
# This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2, as
#  published by the Free Software Foundation.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#*****************************************************************************

use strict;
use lib qw(/usr/lib/libDrakX);
use common;
use standalone;
use vars qw($MODE %options);
use ugtk2 qw(:helpers :wrappers :ask :create);
use run_program;
use security::level;
use security::msec;
use security::help;

#$MODE = 'basic';
#$0 =~ /draksec-firewall$/ and $MODE = 'firewall';
#$0 =~ /draksec-perms$/ and $MODE = 'perms';

#/^-?-(\S+)$/ and $options{$1} = 1 foreach @ARGV;


my $w;

# factorize this with rpmdrake and harddrake2
sub wait_msg {
    my $mainw = ugtk2->new('wait', (modal => 1, if_(!$::isEmbedded, transient => $w->{rwindow})));
    $mainw->{window}->add(new Gtk2::Label($_[0]));
    $mainw->{rwindow}->show_all;
    gtkset_mousecursor_wait($mainw->{rwindow}->window);
    gtkflush();
    $mainw;
}

sub remove_wait_msg { $_[0]->destroy }

sub basic_seclevel_explanations {
    my $text = new Gtk2::TextView;
    $text->set_editable(0);
    gtktext_insert($text,
             formatAlaTeX(N("Standard: This is the standard security recommended for a computer that will be used to connect
               to the Internet as a client.

High:       There are already some restrictions, and more automatic checks are run every night.

Higher:    The security is now high enough to use the system as a server which can accept
              connections from many clients. If your machine is only a client on the Internet, you
           should choose a lower level.

Paranoid:  This is similar to the previous level, but the system is entirely closed and security
                features are at their maximum

Security Administrator:
               If the 'Security Alerts' option is set, security alerts will be sent to this user (username or
            email)")));
    
    gtkpack_(gtkshow(new Gtk2::HBox(0, 0)), 1, $text);
}

sub new_editable_combo {
    my ($string_list, $o_default_value) = @_;
    my $w = new Gtk2::Combo();
    $w->entry->set_editable(0);
    $w->set_popdown_strings(@$string_list) unless is_empty_array_ref $string_list;
    $w->entry->set_text($o_default_value) if $o_default_value;
    $w;
}

sub set_help_tip {
     my ($entry, $default, $opt) = @_;
     my $help = $security::help::help{$opt};
     gtkset_tip(new Gtk2::Tooltips, $entry, formatAlaTeX($help) . "\n" . N("(default value: %s)", $default));
}

my $msec = new security::msec;
$w = ugtk2->new('draksec');
my $window = $w->{window};

############################ MAIN WINDOW ###################################
# Set different options to Gtk2::Window
unless ($::isEmbedded) {
    $w->{rwindow}->set_position('center');
    $w->{rwindow}->set_title("DrakSec");
    $window->set_size_request(598, 520);
}

# Connect the signals
$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)));

# Create the notebook (for bookmarks at the top)
my $notebook = create_notebook();

my $common_opts = { col_spacings => 10, row_spacings => 5 };

######################## BASIC OPTIONS PAGE ################################
my $seclevel_entry;

$notebook->append_page(gtkshow(gtkpack(new Gtk2::VBox(0, 0),
                                       basic_seclevel_explanations($msec),
                                       create_packtable($common_opts,
                                                        [ 
                                                          do {
                                                              my @sec_levels = security::level::get_common_list();
                                                              my $current_level = security::level::get_string();
                                                              
                                                              push(@sec_levels, $current_level) unless member($current_level, @sec_levels);
                                                              $seclevel_entry = new_editable_combo(\@sec_levels, $current_level);
                                                              
                                                              new Gtk2::Label(N("Security Level:")), $seclevel_entry;
                                                          }
                                                          ],
                                                        [ new Gtk2::Label(N("Security Alerts:")), 
                                                          my $secadmin_check = new Gtk2::CheckButton ],
                                                        [ new Gtk2::Label(N("Security Administrator:")),
                                                          my $secadmin_entry = new Gtk2::Entry($msec->get_check_value("MAIL_USER")) ]))),
                               new Gtk2::Label(N("Basic")));
                       
$secadmin_check->set_active(1) if $msec->get_check_value("MAIL_WARN") eq "yes";
                       
######################### NETWORK & SYSTEM OPTIONS #########################
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) = @$_;
    my %values;
    $notebook->append_page(gtkshow(create_scrolled_window(gtkpack_(new Gtk2::VBox(0, 0),
                                                                   0, new Gtk2::Label($help_msg),
                                                                   1, create_packtable($common_opts,
                                                                                       map {
                                                                                           my $i = $_;
                                                                                           
                                                                                           my $entry;
                                                                                           my $default = $msec->get_function_default($i);
                                                                                           if (member($default, @all_choices)) {
                                                                                               $values{$i} = new_editable_combo(member($default, @yesno_choices) ? \@yesno_choices : if_(member($default, @alllocal_choices), \@alllocal_choices));
                                                                                               $entry = $values{$i}->entry;
                                                                                           } else {
                                                                                               $values{$i} = new Gtk2::Entry();
                                                                                               $entry = $values{$i};
                                                                                           }
                                                                                           $entry->set_text($msec->get_function_value($i));
                                                                                           set_help_tip($entry, $default, $i);
                                                                                           [ new Gtk2::Label($i), $values{$i} ];
                                                                                       } sort $msec->list_functions($domain))))),
                           new Gtk2::Label($label));
    $options_values{$domain} = \%values;
}

######################## PERIODIC CHECKS ###################################
my %security_checks_value;

$notebook->append_page(gtkshow(create_scrolled_window(gtkpack_(new Gtk2::VBox(0, 0),
                                                               0, new Gtk2::Label($help_msg),
                                                               1, create_packtable($common_opts,
                                                                                   map {
                                                                                       my $i = $_;
                                                                                       $security_checks_value{$i} = new_editable_combo([ 'yes', 'no', 'default' ], $msec->get_check_value($i));
                                                                                       my $entry = $security_checks_value{$i}->entry;
                                                                                       set_help_tip($entry, $msec->get_check_default($i), $i);
                                                                                       [ gtkshow(new Gtk2::Label(translate($i))), $security_checks_value{$i} ];
                                                                                   } sort $msec->list_checks)))),
                       new Gtk2::Label(N("Periodic Checks")));


####################### OK CANCEL BUTTONS ##################################
my $bok = gtksignal_connect(new Gtk2::Button(N("Ok")),
                            'clicked' => sub {
                                my $seclevel_value = $seclevel_entry->entry->get_text();
                                my $secadmin_check_value = $secadmin_check->get_active();
                                my $secadmin_value = $secadmin_entry->get_text();
                                my $w;

                                log::explanations("Configuring msec");

                                if ($seclevel_value ne security::level::get_string()) {
                                    $w = wait_msg(N("Please wait, setting security level..."));
                                    log::explanations("Setting security level to $seclevel_value");
                                    security::level::set(security::level::from_string($seclevel_value));
                                    remove_wait_msg($w);
                                }

                                $w = wait_msg(N("Please wait, setting security options..."));
                                log::explanations("Setting security administrator option");
                                $msec->set_check('MAIL_WARN', $secadmin_check_value == 1 ? 'yes' : 'no');

                                if ($secadmin_value ne $msec->get_check_value('MAIL_USER') && $secadmin_check_value) {
                                    log::explanations("Setting security administrator contact");
                                      $msec->set_check('MAIL_USER', $secadmin_value);
                                  }

                                log::explanations("Setting security periodic checks");
                                foreach my $key (keys %security_checks_value) {
                                    $msec->set_check($key, $security_checks_value{$key}->entry->get_text());
                                }
                                $msec->apply_checks;

                                foreach my $domain (keys %options_values) {
                                    log::explanations("Setting msec functions related to $domain");
                                    foreach my $key (keys %{$options_values{$domain}}) {
                                        my $opt = $options_values{$domain}{$key};
                                        $msec->set_function($key, $opt =~ /Combo/ ? $opt->entry->get_text() : $opt->get_text());
                                    }
                                }
                                $msec->apply_functions;
                                log::explanations("Applying msec changes");
                                run_program::rooted($::prefix, "/usr/sbin/msec");

                                remove_wait_msg($w);

                                ugtk2->exit(0);
                            });

my $bcancel = gtksignal_connect(new Gtk2::Button(N("Cancel")),
                                'clicked' => sub { ugtk2->exit(0) });
gtkpack_($vbox,
         1, gtkshow($notebook),
         0, gtkadd(gtkadd(gtkshow(new Gtk2::HBox(0, 0)),
                          $bok),
                   $bcancel));
$bcancel->can_default(1);
$bcancel->grab_default();

$w->main;
ugtk2->exit(0);