summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/draksec
blob: 89478dbe816e9f70952fba67c029482adae1e969 (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
#!/usr/bin/perl
#*****************************************************************************
#
# Copyright (c) 2002-2008 Christian Belisle
#                         Thierry Vignaud <tvignaud@mandriva.com>
#			  Eugeni Dodonov <eugeni@mandriva.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 interactive;
use mygtk2 qw(gtknew gtkset);
use ugtk2 qw(:helpers :wrappers :ask :create);
use run_program;
use security::level;
use security::msec;
use security::help;
use security::l10n;

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

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


my $in = 'interactive'->vnew('su');

$ugtk2::wm_icon = "/usr/share/mcc/themes/default/draksec-mdk.png";
my ($w, %fields);

############################    I18N     ###################################

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] }
sub resize { gtkset($_[0], width => 50) }

%fields = security::l10n::fields();
my %inv_fields = reverse %fields;

# factorize this with rpmdrake and harddrake2
sub wait_msg {
    my $mainw = ugtk2->new(N("Please wait"), (modal => 1, transient => $w->{real_window}));
    $mainw->{window}->add(gtknew('WrappedLabel', text => $_[0]));
    $mainw->{rwindow}->show_all;
    gtkset_mousecursor_wait($mainw->{rwindow}->window);
    # ugly workaround for gtk+ not displaying subdialog contents:
    Glib::Timeout->add(300, sub { Gtk2->main_quit; 0 });
    Gtk2->main;
    $mainw;
}

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

sub new_nonedit_combo {
    my ($string_list, $o_default_value) = @_;
    gtknew('ComboBox', text => to_i18n($o_default_value), list => [ to_i18n(@$string_list) ]);
}

my $msec = new security::msec;
$w = ugtk2->new(N("Security Level and Checks"));
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(gtknew('VBox')));

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

######################## AUTH ###################################
my %progs;

my $auth_string = N("Configure authentication required to access Mandriva tools");

my %auth = (
      no_passwd => N("No password"),
      root_passwd => N("Root password"),
      user_passwd => N("User password"),
);

sub default_auth_value {
    my ($prog) = @_;
    my $link = readlink("/etc/pam.d/$prog");
    if ($link =~ /mandriva-console-auth/) {
        return $auth{no_passwd};
    } elsif ($link =~ /mandriva-simple-auth/) {
        my ($user) = cat_("/etc/security/console.apps/$prog") =~ /USER=(.*)/;
        return $auth{root_passwd} if $user eq 'root';
        return $auth{user_passwd} if $user eq '<user>';
    }
}

sub set_auth_value {
    my ($prog, $auth) = @_;
    if ($auth eq 'no_passwd') {
        symlinkf('../../etc/pam.d/mandriva-console-auth', "/etc/pam.d/$prog");
    } else {
        symlinkf('../../etc/pam.d/mandriva-simple-auth', "/etc/pam.d/$prog");
        my $value = $auth eq 'user_passwd' ? '<user>' : 'root';
        substInFile {
            s/^USER=.*/USER=$value/;
        } "/etc/security/console.apps/$prog";
    }
}

my %descr = (
    
    rpmdrake => N("Software Management"),
    mandrivaupdate => N("Mandriva Update"),
    'drakrpm-edit-media' => N("Software Media Manager"),
    drak3d => N("Configure 3D Desktop effects"),
    xfdrake => N("Graphical Server Configuration"),
    drakmouse => N("Mouse Configuration"),
    drakkeyboard => N("Keyboard Configuration"),
    drakups => N("UPS Configuration"),
    drakconnect => N("Network Configuration"),
    drakhosts => N("Hosts definitions"),
    draknetcenter => N("Network Center"),
    drakvpn => N("VPN"),
    drakproxy => N("Proxy Configuration"),
    drakgw => N("Connection Sharing"),
    drakauth => N("Authentication"),
    drakbackup => N("Backups"),
    drakfont => N("Import fonts"),
    draklog => N("Logs"),
    drakxservices => N("Services"),
    userdrake => N("Users"),
    drakclock => N("Date, Clock & Time Zone Settings"),
    drakboot => N("Boot Configuration"),
);





####################### OK CANCEL BUTTONS ##################################
gtkpack_($vbox,
	 0, gtkshow(gtknew('VBox', spacing => 5, children => [
			if_(!$::isEmbedded, 0, Gtk2::Banner->new('/usr/share/mcc/themes/default/drakperm-mdk.png', N("Permissions"))),
			0, gtknew('Label', text => $auth_string, alignment => [ 0.5, 0])
		])),
         1, gtkshow(create_scrolled_window(
			gtknew('VBox', children => [
			    1, create_packtable(
				$common_opts,
			    map {
				my ($title, $progs) = @$_;
				([ gtknew('Title2', label => $title), '' ],
				     map {
					 [
					     gtkshow(gtknew('Label_Left', line_wrap => 1, text => $descr{$_} || $_)),
						 $progs{$_} = new_nonedit_combo([
						     @auth{qw(user_passwd root_passwd no_passwd)}
						 ],
										default_auth_value($_)
										#$msec->get_check_value($opt)
									    )
					 ];
				     } split(' ', $progs)
				);
			    } (
				[ N("Software Management"), 'rpmdrake mandrivaupdate drakrpm-edit-media' ],
				[ N("Hardware"), 'drak3d xfdrake drakmouse drakkeyboard drakups' ],
				[ N("Network"), 'drakconnect drakhosts draknetcenter drakvpn drakproxy drakgw' ],
				[ N("System"), 'drakauth drakbackup drakfont draklog drakxservices userdrake drakclock' ],
				[ N("Boot"), 'drakboot' ],
			    )
			)
			]))),

         0, create_okcancel(my $oc =
                            {
                             cancel_clicked => sub { ugtk2->exit(0) },
                             ok_clicked => sub {
                                log::explanations("Setting up right delegation");
                                my %rev_auth = reverse %auth;
                                foreach my $key (keys %progs) {
                                    my $value = $progs{$key}->get_text;
                                    set_auth_value($key, $rev_auth{$value});
                                }

                                remove_wait_msg($w);
                                ugtk2->exit(0);
                            }
                            },
                            undef, undef, ''
                           ),
        );

$oc->{cancel}->can_default(1);
$oc->{cancel}->grab_default;

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