summaryrefslogtreecommitdiffstats
path: root/perl-install/services.pm
blob: 7e5850d6a28d4621c10cf5c1654d36aea6db3fd7 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package services; # $Id$




#-######################################################################################
#- misc imports
#-######################################################################################

use strict;
use common;
use run_program;

use common;
use run_program;

sub description {
    my %services = (
alsa => N_("Launch the ALSA (Advanced Linux Sound Architecture) sound system"),
anacron => N_("Anacron is a periodic command scheduler."),
apmd => N_("apmd is used for monitoring battery status and logging it via syslog.
It can also be used for shutting down the machine when the battery is low."),
atd => N_("Runs commands scheduled by the at command at the time specified when
at was run, and runs batch commands when the load average is low enough."),
crond => N_("cron is a standard UNIX program that runs user-specified programs
at periodic scheduled times. vixie cron adds a number of features to the basic
UNIX cron, including better security and more powerful configuration options."),
gpm => N_("GPM adds mouse support to text-based Linux applications such the
Midnight Commander. It also allows mouse-based console cut-and-paste operations,
and includes support for pop-up menus on the console."),
harddrake => N_("HardDrake runs a hardware probe, and optionally configures
new/changed hardware."),
httpd => N_("Apache is a World Wide Web server. It is used to serve HTML files and CGI."),
inet => N_("The internet superserver daemon (commonly called inetd) starts a
variety of other internet services as needed. It is responsible for starting
many services, including telnet, ftp, rsh, and rlogin. Disabling inetd disables
all of the services it is responsible for."),
ipchains => N_("Launch packet filtering for Linux kernel 2.2 series, to set
up a firewall to protect your machine from network attacks."),
keytable => N_("This package loads the selected keyboard map as set in
/etc/sysconfig/keyboard.  This can be selected using the kbdconfig utility.
You should leave this enabled for most machines."),
kheader => N_("Automatic regeneration of kernel header in /boot for
/usr/include/linux/{autoconf,version}.h"),
kudzu => N_("Automatic detection and configuration of hardware at boot."),
linuxconf => N_("Linuxconf will sometimes arrange to perform various tasks
at boot-time to maintain the system configuration."),
lpd => N_("lpd is the print daemon required for lpr to work properly. It is
basically a server that arbitrates print jobs to printer(s)."),
lvs => N_("Linux Virtual Server, used to build a high-performance and highly
available server."),
named => N_("named (BIND) is a Domain Name Server (DNS) that is used to resolve host names to IP addresses."),
netfs => N_("Mounts and unmounts all Network File System (NFS), SMB (Lan
Manager/Windows), and NCP (NetWare) mount points."),
network => N_("Activates/Deactivates all network interfaces configured to start
at boot time."),
nfs => N_("NFS is a popular protocol for file sharing across TCP/IP networks.
This service provides NFS server functionality, which is configured via the
/etc/exports file."),
nfslock => N_("NFS is a popular protocol for file sharing across TCP/IP
networks. This service provides NFS file locking functionality."),
numlock => N_("Automatically switch on numlock key locker under console
and XFree at boot."),
oki4daemon => N_("Support the OKI 4w and compatible winprinters."),
pcmcia => N_("PCMCIA support is usually to support things like ethernet and
modems in laptops.  It won't get started unless configured so it is safe to have
it installed on machines that don't need it."),
portmap => N_("The portmapper manages RPC connections, which are used by
protocols such as NFS and NIS. The portmap server must be running on machines
which act as servers for protocols which make use of the RPC mechanism."),
postfix => N_("Postfix is a Mail Transport Agent, which is the program that moves mail from one machine to another."),
random => N_("Saves and restores system entropy pool for higher quality random
number generation."),
rawdevices => N_("Assign raw devices to block devices (such as hard drive
partitions), for the use of applications such as Oracle or DVD players"),
routed => N_("The routed daemon allows for automatic IP router table updated via
the RIP protocol. While RIP is widely used on small networks, more complex
routing protocols are needed for complex networks."),
rstatd => N_("The rstat protocol allows users on a network to retrieve
performance metrics for any machine on that network."),
rusersd => N_("The rusers protocol allows users on a network to identify who is
logged in on other responding machines."),
rwhod => N_("The rwho protocol lets remote users get a list of all of the users
logged into a machine running the rwho daemon (similiar to finger)."),
sound => N_("Launch the sound system on your machine"),
syslog => N_("Syslog is the facility by which many daemons use to log messages
to various system log files.  It is a good idea to always run syslog."),
usb => N_("Load the drivers for your usb devices."),
xfs => N_("Starts the X Font Server (this is mandatory for XFree to run)."),
    );
    my ($name) = @_;
    my $s = $services{$name};
    if ($s) {
	$s = translate($s);
    } else {
	$s = -e "$::prefix/etc/rc.d/init.d/$name" && cat_("$::prefix/etc/rc.d/init.d/$name");
	$s ||= -e "$::prefix/etc/init.d/$name" && cat_("$::prefix/etc/init.d/$name");
	$s ||= -e "$::prefix/etc/xinetd.d/$name" && cat_("$::prefix/etc/xinetd.d/$name");
	$s =~ s/\\\s*\n#\s*//mg;
	if ($s =~ /^# description:\s+\S/sm) {
	    ($s) = $s =~ /^# description:\s+(.*?)^(?:[^#]|# {0,2}\S)/sm;
	} else {
	    ($s) = $s =~ /^#\s*(.*?)^[^#]/sm;
	}
	$s =~ s/#\s*//mg;
    }
    $s =~ s/\n/ /gm; $s =~ s/\s+$//;
    $s;
}

sub ask_install_simple {
    my ($in) = @_;
    my ($l, $on_services) = services();
    $in->ask_many_from_list("drakxservices",
			    N("Choose which services should be automatically started at boot time"),
			    {
			     list => $l,
			     help => sub { description($_[0]) },
			     values => $on_services,
			     sort => 1,
			    });
}

sub ask_install {
    my ($in) = @_;
    my %root_services = (
			 N("Printing") => [ qw(cups cupslpd lpr lpd oki4daemon hpoj cups-lpd) ],
			 N("Internet") => [ qw(httpd boa tux roxen ftp pftp tftp proftpd wu-ftpd pure-ftpdipsec proftpd-xinetd
                                               ipchains iptables ipvsadm isdn4linux ibod jabber jabber-icq adsl squid
                                               portsentry prelude nessusd junkbuster radvd cddbp ippl iptoip jail.init) ],
			 N("File sharing") => [ qw(nfs nfslock smb nettalk netfs mcserv autofs amd
                                                   venus.init auth2.init codasrv.init update.init swat) ],
			 N("System") => [ qw(usb usbd pcmcia irda xinetd inetd kudzu harddrake apmd sound network xfs
                                             alsa functions halt kheader killall mandrake_everytime mandrake_firstime
                                             random rawdevices single keytable syslog crond medusa-init portmap acon
                                             anacron atd gpm psacct wine acpid numlock jserver sensors mosix bpowerd bpowerfail
                                             fcron powertweak.init ups syslog-ng cvs apcupsd) ],
			 N("Remote Administration") => [ qw(sshd telnetd telnet rsh rlogin rexec webmin cfd heartbeat ldirectord
                                                            iplog mon vncserver netsaint olympusd drakxtools_http) ],
#			 N("Network Client") => [ qw(ypbind nscd arpwatch fetchmail dnrd_rc diald rsync) ],
#			 N("Network Server") => [ qw(named bootparamd ntpd xntpd chronyd postfix sendmail
#                                                     imap imaps ipop2 ipop3 pop3s routed yppasswdd ypserv ldap dhcpd dhcrelay
#                                                     hylafax innd identd rstatd rusersd rwalld rwhod gated
#                                                     kadmin kprop krb524 krb5kdc krb5server hldsld bayonne sockd dhsd gnu-pop3d
#                                                     gdips pptpd.conf vrrpd crossfire bnetd pvmd ircd sympa finger ntalk talk) ],
			 N("Database Server") => [ qw(mysql postgresql) ],
			);
    my %services_root;
    foreach my $root (keys %root_services) {
	$services_root{$_} = $root foreach @{$root_services{$root}};
    }
    my ($l, $on_services) = services();
    my %services;
    $services{$_} = 0 foreach @{$l || []};
    $services{$_} = 1 foreach @{$on_services || []};

    $in->ask_browse_tree_info('drakxservices', N("Choose which services should be automatically started at boot time"),
			      {
			       node_state => sub { $services{$_[0]} ? 'selected' : 'unselected' },
			       build_tree => sub {
				   my ($add_node, $flat) = @_;
				   $add_node->($_, !$flat && ($services_root{$_} || N("Other")))
				     foreach sort keys %services;
			       },
			       grep_unselected => sub { grep { !$services{$_} } @_ },
			       toggle_nodes => sub {
				   my ($set_state, @nodes) = @_;
				   my $new_state = !$services{$nodes[0]};
				   foreach (@nodes) {
				       $set_state->($_, $new_state ? 'selected' : 'unselected');
				       $services{$_} = $new_state;
				   }
			       },
			       get_status => sub {
				   N("Services: %d activated for %d registered", 
				     scalar(grep { $_ } values %services),
				     scalar(values %services));
			       },
			       get_info => sub { formatLines(description($_[0])) },
			       interactive_help_id => 'configureServices',
			      }) or return ($l, $on_services); #- no change on cancel.
    [ grep { $services{$_} } @$l ];
}

sub ask_standalone_gtk {
    my ($_in) = @_;
    my ($l, $on_services) = services();

    require ugtk2;
    ugtk2->import(qw(:wrappers :create));

    my $W = ugtk2->new(N("Services"));
    my ($x, $y, $w_popup);
    my $nopop = sub { $w_popup and $w_popup->destroy; undef $w_popup };
    my $display = sub { $nopop->(); $_[0] and gtkshow(gtkadd($w_popup = Gtk2::Window->new('popup'),
        				       gtksignal_connect(gtkadd(Gtk2::EventBox->new,
        				           gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'etched_out'),
        					   gtkset_justify(Gtk2::Label->new($_[0]), 'left'))),
        					   button_press_event => sub { $nopop->() }
		      )))->move($x, $y) };
    my $update_service = sub {
		my $started = -e "/var/lock/subsys/$_[0]";
                my $action = $started ? "stop" : "start";
                $_[1]->set_label($started ? N("running") : N("stopped"));
                $started, $action;
    };
    my $b = Gtk2::EventBox->new;
    $b->set_events('pointer_motion_mask');
    gtkadd($W->{window}, gtkadd($b, gtkpack_($W->create_box_with_title(N("Services and deamons")),
	1, gtkset_size_request(create_scrolled_window(create_packtable({ col_spacings => 10, row_spacings => 3 },
	    map {
                my $service = $_;
        	my $infos = warp_text(description($_), 40);
                $infos ||= N("No additional information\nabout this service, sorry.");
		my $l = Gtk2::Label->new;
                my ($started, $action) = $update_service->($service, gtkset_justify($l, 'left'));
		[ gtkpack__(Gtk2::HBox->new(0,0), $_),
		  gtkpack__(Gtk2::HBox->new(0,0), $l),
		  gtkpack__(Gtk2::HBox->new(0,0), gtksignal_connect(Gtk2::Button->new(N("Info")), clicked => sub { $display->($infos) })),
                  gtkpack__(Gtk2::HBox->new(0,0), gtkset_active(gtksignal_connect(
                          Gtk2::CheckButton->new(N("On boot")),
                          clicked => sub { if ($_[0]->active) {
                                               push @$on_services, $service if !member($service, @$on_services);
                                           } else {
                                               @$on_services = grep { $_ ne $service } @$on_services;
                                        } }), member($service, @$on_services))),
		  map { my $a = $_;
                      gtkpack__(Gtk2::HBox->new(0,0), gtksignal_connect(Gtk2::Button->new(translate($a)),
                          clicked => sub { my $c = "service $service " . (lc($a) eq "start" ? "restart" : lc($a)) . " 2>&1"; local $_ = `$c`; s/\033\[[^mG]*[mG]//g;
                                           ($started, $action) = $update_service->($service, $l);
                                           $display->($_);
                                         }
                      )) } (N_("Start"), N_("Stop"))
		]
	    }
            @$l), [ $::isEmbedded ? 'automatic' : 'never', 'automatic' ]), -1, $::isEmbedded ? -1 : 400),
            0, gtkpack(gtkset_border_width(Gtk2::HBox->new(0,0),5), $W->create_okcancel)
            ))
	  );
    $b->signal_connect(motion_notify_event => sub { my ($w, $e) = @_;
						    my ($ox, $oy) = $w->window->get_origin;
						    $x = $e->x+$ox; $y = $e->y+$oy });
    $b->signal_connect(button_press_event => sub { $nopop->() });
    $::isEmbedded and gtkflush();
    $W->main or return;
    $on_services;
}

sub ask {    
    my ($in) = @_;
    !$::isInstall && $in->isa('interactive::gtk') ? &ask_standalone_gtk : &ask_install;
}

sub doit {
    my ($in, $on_services) = @_;
    my ($l, $was_on_services) = services();

    foreach (@$l) {
	my $before = member($_, @$was_on_services);
	my $after = member($_, @$on_services);
	if ($before != $after) {
	    my $script = "/etc/rc.d/init.d/$_";
	    run_program::rooted($::prefix, "chkconfig", $after ? "--add" : "--del", $_);
	    if ($after && cat_("$::prefix$script") =~ /^#\s+chkconfig:\s+-/m) {
		run_program::rooted($::prefix, "chkconfig", "--level", "35", $_, "on");
	    }
	    if (!$after && !$::isInstall && !$in->isa('interactive::gtk')) {
		#- only done after install AND when not using the gtk frontend (since it allows one to start/stop services)
		#- this allows to skip stopping service "dm"
		run_program::rooted($::prefix, $script, "stop");
	    }
	}
    }
}

#- returns: 
#--- the listref of installed services
#--- the listref of "on" services
sub services() {
    local $ENV{LANGUAGE} = 'C';
    my @raw_l = map { chomp; $_ } run_program::rooted_get_stdout($::prefix, '/sbin/chkconfig', '--list');
    my @l;
    if ($::isInstall) {
        @l = sort { $a->[0] cmp $b->[0] } map { [ /([^\s:]+)/, /\bon\b/ ] } grep { !/:$/ } @raw_l;
    } else {
        my $runlevel = (split " ", `/sbin/runlevel`)[1];
        @l = sort { $a->[0] cmp $b->[0] } map { [ /([^\s:]+)/, /^\t/ ? /\bon\b/ : /\b$runlevel:on\b/ ] } grep { !/:$/ } @raw_l;
    }
    [ map { $_->[0] } @l ], [ map { $_->[0] } grep { $_->[1] } @l ];
}






# the following functions are mostly by printer related modules


sub restart ($) {
    my ($service) = @_;
    # Exit silently if the service is not installed
    return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
    run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "restart");
}

sub start ($) {
    my ($service) = @_;
    # Exit silently if the service is not installed
    return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
    run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "start");
    return (($? >> 8) != 0) ? 0 : 1;
}

sub start_not_running_service ($) {
    my ($service) = @_;
    # Exit silently if the service is not installed
    return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
    run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "status");
    return (($? >> 8) != 0) ? 0 : 1;
}

sub stop ($) {
    my ($service) = @_;
    # Exit silently if the service is not installed
    return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
    run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "stop");
    return (($? >> 8) != 0) ? 0 : 1;
}

sub is_service_running ($) {
    my ($service) = @_;
    # Exit silently if the service is not installed
    return 0 if !(-x "$::prefix/etc/rc.d/init.d/$service");
    run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "status");
    # The exit status is not zero when the service is not running
    return (($? >> 8) != 0) ? 0 : 1;
}

sub starts_on_boot {
    my ($service) = @_;
    my (undef, $on_services) = services();
    member($service, @$on_services);
}

sub start_service_on_boot ($) {
    my ($service) = @_;
    run_program::rooted($::prefix, "/sbin/chkconfig", "--add", $service) ? 1 : 0;
}

sub do_not_start_service_on_boot ($) {
    my ($service) = @_;
    run_program::rooted($::prefix, "/sbin/chkconfig", "--del", $service) ? 1 : 0;
}

1;
$comment, ]; # update listshare push @listshare, { share_name => $share, path => $test_dir, comment => $comment, }; # update samba conf $samba->{$share}{path} = $test_dir; $samba->{$share}{comment} = $comment; $dialog->destroy; } } ), ), ), ), ); $dialog->show_all; } sub add_printers_entry() { require wizards; my %print = ( 1 => N("pdf-gen - a PDF generator"), 2 => N("printers - all printers available"), ); my $wiz_todo; my $wiz = wizards->new({ name => N("Add Special Printer share"), pages => { welcome => { name => N("Goal of this wizard is to easily create a new special printer Samba share."), data => [ { label => "", type => 'list', val => \$wiz_todo, list => [ keys %print ], format => sub { $print{$_[0]} } } ], next => 'end_add', post => sub { if ($wiz_todo == 1) { exists $samba->{'pdf-gen'} and err_dialog(N("Error"), N("A PDF generator already exists.")) and return 'welcome'; &pdf_section; push @{$printer_list->{data}}, [ $pixbuf_printer, 'pdf-gen', $samba->{'pdf-gen'}{path}, $samba->{'pdf-gen'}{comment}, "", $samba->{'pdf-gen'}{printable}, $samba->{'pdf-gen'}{'print command'}, $samba->{'pdf-gen'}{'lpq command'}, $samba->{'pdf-gen'}{'guest ok'}, "", "", "", $samba->{'pdf-gen'}{printing}, "", "", ]; push @listprinters, { share_name => $samba->{'pdf-gen'}, path => $samba->{'pdf-gen'}{path}, comment => $samba->{'pdf-gen'}{comment}, printebale => $samba->{'pdf-gen'}{printable}, printing => $samba->{'pdf-gen'}{printing}, print_command => $samba->{'pdf-gen'}{'print command'}, lpq_command => $samba->{'pdf-gen'}{'lpq command'}, guest_ok => $samba->{'pdf-gen'}{'guest ok'}, }; } elsif ($wiz_todo == 2) { exists $samba->{'print$'} || exists $samba->{printers} and err_dialog(N("Error"), N("Printers and print\$ already exist.")) and return 'welcome'; &printdollar_section; &printers_section; push @{$printer_list->{data}}, [ $pixbuf_printer, 'print$', $samba->{'print$'}{path}, "", $samba->{'print$'}{browseable}, "", "", "", $samba->{'print$'}{'guest ok'}, "", $samba->{'print$'}{'write list'}, $samba->{'print$'}{'inherit permissions'}, ]; push @{$printer_list->{data}}, [ $pixbuf_printer, 'printers', $samba->{printers}{path}, $samba->{printers}{comment}, $samba->{printers}{browseable}, $samba->{printers}{printable}, $samba->{printers}{'print command'}, "", $samba->{printers}{'guest ok'}, $samba->{printers}{writable}, "", "", "", $samba->{printers}{'create mode'}, $samba->{printers}{'use client driver'}, ]; push @listprinters, { share_name => 'print$', path => $samba->{'print$'}{path}, browseable => $samba->{'print$'}{browseable}, write_list => $samba->{'print$'}{'write list'}, guest_ok => $samba->{'print$'}{'guest ok'}, inherit_permissions => $samba->{'print$'}{'inherit permissions'}, }; push @listprinters, { share_name => "printers", comment => $samba->{printers}{comment}, browseable => $samba->{printers}{browseable}, guest_ok => $samba->{printers}{'guest ok'}, create_mode => $samba->{printers}{'create mode'}, path => $samba->{printers}{path}, writable => $samba->{printers}{writable}, printable => $samba->{printers}{printable}, print_command => $samba->{printers}{'print command'}, use_client_driver => $samba->{printers}{'use client driver'}, }; } return; }, }, end_add => { name => N("Congratulations"), data => [ { label => N("The wizard successfully added the printer Samba share") } ], no_back => 1, end => 1, next => 0, }, } }); $wiz->process($in); $::isWizard = 0; } sub modify_printers_entry { my ($selected) = @_; my ($dir, $comment, $print_command, $guest_ok, $share_name, $browseable, $printable, $write_list, $printing, $lpq_command, $create_mode, $writable, $use_client_driver, $inherit_permissions); $share_name = Gtk2::Label->new; $_ = Gtk2::Entry->new foreach $dir, $comment, $print_command, $write_list, $printing, $lpq_command, $create_mode; $_ = Gtk2::OptionMenu->new foreach $browseable, $printable, $guest_ok, $writable, $use_client_driver, $inherit_permissions; $_->set_popdown_strings(@yesno) foreach $browseable, $printable, $guest_ok, $writable, $use_client_driver, $inherit_permissions; my $s = $printer_list->{data}[$selected][1]; $s or info_dialog(N("Error"), N("Please add or select a Samba printer share to be able to modify it.")) and return; $share_name->set_text($s); $dir->set_text($printer_list->{data}[$selected][2]); $comment->set_text($printer_list->{data}[$selected][3]); $browseable->set_text($printer_list->{data}[$selected][4]); $printable->set_text($printer_list->{data}[$selected][5]); $print_command->set_text($printer_list->{data}[$selected][6]); $lpq_command->set_text($printer_list->{data}[$selected][7]); $guest_ok->set_text($printer_list->{data}[$selected][8]); $writable->set_text($printer_list->{data}[$selected][9]); $write_list->set_text($printer_list->{data}[$selected][10]); $inherit_permissions->set_text($printer_list->{data}[$selected][11]); $printing->set_text($printer_list->{data}[$selected][12]); $create_mode->set_text($printer_list->{data}[$selected][13]); $use_client_driver->set_text($printer_list->{data}[$selected][14]); my $file_dialog = $fdwidget->($dir, ""); my $button = Gtk2::Button->new(N("Open")); $button->signal_connect(clicked => sub { $file_dialog->show }); my $dialog = _create_dialog(N("DrakSamba Printers entry"), { transient_for => $::main_window, modal => 1 }); local $::main_window = $dialog; if ($s eq "printers") { $printable->set_text("yes"); $printing->set_text(""); $_->set_sensitive(0) foreach $printable, $printing; } if ($s eq "pdf-gen") { $printing->set_text("bsd"); $printing->set_sensitive(0); } gtkpack_($dialog->vbox, 0, gtkadd(Gtk2::Frame->new(N("Printer share")), gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3), 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->(N("Printer name:"), $share_name, ""), 0, $label_and_widgets->(N("Comment:"), $comment, ""), 0, $label_and_widgets->(N("Directory:"), $dir, $button), ), 0, Gtk2::VSeparator->new, 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->(N("Writable:"), $writable, ""), 0, $label_and_widgets->(N("Browseable:"), $browseable, ""), 0, $label_and_widgets->(N("Printable"), $printable, ""), ), ), ), 0, gtkadd(Gtk2::Frame->new(N("Advanced options")), gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3), 0, gtkadd(Gtk2::Frame->new(N("Printer access")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->(N("Write list"), $write_list, ""), 0, $label_and_widgets->(N("Inherit permissions"), $inherit_permissions, ""), 0, $label_and_widgets->(N("Guest ok:"), $guest_ok, ""), 0, $label_and_widgets->(N("Create mode:"), $create_mode, ""), ), ), 0, Gtk2::VSeparator->new, 0, gtkadd(Gtk2::Frame->new(N("Printer command")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->(N("Print command:"), $print_command, ""), 0, $label_and_widgets->(N("LPQ command:"), $lpq_command, ""), 0, $label_and_widgets->(N("Printing:"), $printing, ""), ), ), ), ), 0, create_okcancel({ cancel_clicked => sub { $dialog->destroy }, ok_clicked => sub { my $share = $share_name->get_text; my $test_dir = $dir->get_text; $comment->get_text or err_dialog(N("Information"), N("Please enter a Comment for this share.")) and return 1; if (!-d $test_dir) { err_dialog(N("Error!"), N("Please enter a directory to share.")) and return; } foreach ($create_mode->get_text) { if ($_ && !/^\d+$/) { err_dialog(N("Error"), N("create mode should be numeric. ie: 0755.")) and return 1; } } # update gui SimpleList remove_entry($selected, $printer_list); push @{$printer_list->{data}}, [ $pixbuf_printer, $share, $dir->get_text, $comment->get_text, $browseable->get_text, $printable->get_text, $print_command->get_text, $lpq_command->get_text, $guest_ok->get_text, $writable->get_text, $write_list->get_text, $inherit_permissions->get_text, $printing->get_text, $create_mode->get_text, $use_client_driver->get_text, ]; # update $samba $samba->{$share}{path} = $dir->get_text; $samba->{$share}{comment} = $comment->get_text; $browseable->get_text and $samba->{$share}{browseable} = $browseable->get_text || delete $samba->{$share}{browseable}; $printable->get_text and $samba->{$share}{printable} = $printable->get_text || delete $samba->{$share}{printable}; $print_command->get_text and $samba->{$share}{'print command'} = $print_command->get_text || delete $samba->{$share}{'print command'}; $lpq_command->get_text and $samba->{$share}{'lpq command'} = $lpq_command->get_text || delete $samba->{$share}{'lpq command'}; $guest_ok->get_text and $samba->{$share}{'guest ok'} = $guest_ok->get_text || delete $samba->{$share}{'guest ok'}; $writable->get_text and $samba->{$share}{writable} = $writable->get_text || delete $samba->{$share}{writable}; $write_list->get_text and $samba->{$share}{'write list'} = $write_list->get_text || delete $samba->{$share}{'write list'}; $inherit_permissions->get_text and $samba->{$share}{'inherit permissions'} = $inherit_permissions->get_text || delete $samba->{$share}{'inherit permissions'}; $printing->get_text and $samba->{$share}{printing} = $printing->get_text || delete $samba->{$share}{printing}; $create_mode->get_text and $samba->{$share}{'create mode'} = $create_mode->get_text || delete $samba->{$share}{'create mode'}; $use_client_driver->get_text and $samba->{$share}{'use client driver'} = $use_client_driver->get_text || delete $samba->{$share}{'use client driver'}; # $dialog->destroy; } }, ), ); $dialog->show_all; } sub modify_entry { my ($selected) = @_; my ($dir, $comment, $create_mask, $directory_mask, $read_list, $write_list, $admin_users, $valid_users, $force_group, $browseable, $public, $writable, $hide_files, $hide_dot_files, $force_create_mode, $preserve_case, $default_case, $inherit_permissions, $share_name); $share_name = Gtk2::Label->new; $_ = Gtk2::Entry->new foreach $dir, $comment, $create_mask, $directory_mask, $hide_files; $_ = Gtk2::Entry->new foreach $read_list, $write_list, $admin_users, $valid_users, $force_group, $force_create_mode; $_ = Gtk2::OptionMenu->new foreach $browseable, $public, $writable, $default_case, $preserve_case, $hide_dot_files, $inherit_permissions; $default_case->set_popdown_strings(@default_case); $_->set_popdown_strings(@yesno) foreach $browseable, $public, $writable, $hide_dot_files, $preserve_case, $inherit_permissions; my $file_dialog = $fdwidget->($dir, ""); my $button = Gtk2::Button->new(N("Open")); $button->signal_connect(clicked => sub { $file_dialog->show }); my $w = ugtk2->new(N("DrakSamba entry")); $w->{window}->set_modal(1); $w->{window}->set_position('center'); my $s = $share_list->{data}[$selected][1]; $s or info_dialog(N("Error"), N("Please add or select a Samba share to be able to modify it.")) and return; $share_name->set_text($s); $dir->set_text($share_list->{data}[$selected][2]); $comment->set_text($share_list->{data}[$selected][3]); $browseable->set_text($share_list->{data}[$selected][4]); $public->set_text($share_list->{data}[$selected][5]); $writable->set_text($share_list->{data}[$selected][6]); $create_mask->set_text($share_list->{data}[$selected][7]); $directory_mask->set_text($share_list->{data}[$selected][8]); $read_list->set_text($share_list->{data}[$selected][9]); $write_list->set_text($share_list->{data}[$selected][10]); $admin_users->set_text($share_list->{data}[$selected][11]); $valid_users->set_text($share_list->{data}[$selected][12]); $inherit_permissions->set_text($share_list->{data}[$selected][13]); $hide_dot_files->set_text($share_list->{data}[$selected][14]); $hide_files->set_text($share_list->{data}[$selected][15]); $preserve_case->set_text($share_list->{data}[$selected][16]); $force_create_mode->set_text($share_list->{data}[$selected][17]); $force_group->set_text($share_list->{data}[$selected][18]); $default_case->set_text($share_list->{data}[$selected][19]); my $expander_user = Gtk2::Expander->new('User options (user access, mask option, force mode)'); $expander_user->add(gtkpack_(Gtk2::HBox->new, 0, gtkadd(Gtk2::Frame->new(N("Samba user access")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->($adv_options{read_list}, $read_list, ""), 0, $label_and_widgets->($adv_options{write_list}, $write_list, ""), 0, $label_and_widgets->($adv_options{admin_users}, $admin_users, ""), 0, $label_and_widgets->($adv_options{valid_users}, $valid_users, ""), ), ), 0, gtkadd(Gtk2::Frame->new(N("Mask options")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $label_and_widgets->($adv_options{create_mask}, $create_mask, ""), 0, $label_and_widgets->($adv_options{directory_mask}, $directory_mask, ""), 0, $label_and_widgets->($adv_options{force_group}, $force_group, ""), 0, $label_and_widgets->($adv_options{force_create_mode}, $force_create_mode, ""), 0, $label_and_widgets->($adv_options{inherit_permissions}, $inherit_permissions, ""), ), ), ), ); my $expander_file = Gtk2::Expander->new('File options (hide files, case)'); $expander_file->add(gtkpack_(Gtk2::VBox->new, 0, gtkadd(Gtk2::Frame->new(N("Display options")), gtkpack_(gtkset_border_width(Gtk2::HBox->new, 1), 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0), 0, $label_and_widgets->($adv_options{hide_dot_files}, $hide_dot_files, ""), 0, $label_and_widgets->($adv_options{hide_files}, $hide_files, ""), ), 0, Gtk2::VSeparator->new, 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0), 0, $label_and_widgets->($adv_options{default_case}, $default_case, ""), 0, $label_and_widgets->($adv_options{preserve_case}, $preserve_case, ""), ), ), ), ), ); $_->signal_connect(activate => sub { $w->shrink_topwindow; }) foreach $expander_file, $expander_user; gtkadd($w->{window}, gtknew('VBox', spacing => 0, children_loose => [ gtkadd(Gtk2::Frame->new(N("Samba share directory")), gtkpack_(gtkset_border_width(Gtk2::HBox->new, 1), 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0), 0, $label_and_widgets->(N("Share name:"), $share_name), 0, $label_and_widgets->(N("Directory:"), $dir, $button), 0, $label_and_widgets->(N("Comment:"), $comment, ""), ), 0, Gtk2::VSeparator->new, 0, gtkpack_(gtkset_border_width(Gtk2::VBox->new, 0), 0, $label_and_widgets->(N("Public:"), $public, ""), 0, $label_and_widgets->(N("Writable:"), $writable, ""), 0, $label_and_widgets->(N("Browseable:"), $browseable, ""), ), ), ), gtkadd(Gtk2::Frame->new("Advanced options"), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 1), 0, $expander_user, 0, Gtk2::HSeparator->new, 0, $expander_file, ), ), create_okcancel({ cancel_clicked => sub { $w->destroy }, ok_clicked => sub { my $share = $share_name->get_text; my $test_dir = $dir->get_text; $comment->get_text or err_dialog(N("Information"), N("Please enter a Comment for this share.")) and return 1; if ($share ne 'homes' && !-d $test_dir) { err_dialog(N("Error!"), N("Please enter a directory to share.")) and return; } foreach ($create_mask->get_text, $directory_mask->get_text) { if ($_ && !/^\d+$/) { err_dialog(N("Error"), N("Create mask, create mode and directory mask should be numeric. ie: 0755.")) and return 1; } } foreach ($read_list->get_text, $write_list->get_text, $admin_users->get_text, $valid_users->get_text) { my @users = split(" ", $_); foreach my $user (@users) { if (!(any { /^$user:/ } cat_("/etc/samba/smbpasswd")) && !/\@/) { err_dialog(N("Error"), N("Please create this Samba user: %s", $user)) and return; } } } # update gui SimpleList remove_entry($selected, $share_list); push @{$share_list->{data}}, [ $pixbuf_file, $share_name->get_text, $dir->get_text, $comment->get_text, $browseable->get_text, $public->get_text, $writable->get_text, $create_mask->get_text, $directory_mask->get_text, $read_list->get_text, $write_list->get_text, $admin_users->get_text, $valid_users->get_text, $inherit_permissions->get_text, $hide_dot_files->get_text, $hide_files->get_text, $preserve_case->get_text, $force_create_mode->get_text, $force_group->get_text, $default_case->get_text, ]; remove_entry($selected, $display_share); push @{$display_share->{data}}, [ $pixbuf_file, $share_name->get_text, $dir->get_text, $comment->get_text, ]; # update $samba with the new value # $samba->{$share}; $samba->{$share}{path} = $dir->get_text; $samba->{$share}{comment} = $comment->get_text; $browseable->get_text and $samba->{$share}{browseable} = $browseable->get_text || delete $samba->{$share}{browseable}; $public->get_text and $samba->{$share}{public} = $public->get_text || delete $samba->{$share}{public}; $writable->get_text and $samba->{$share}{writable} = $writable->get_text || delete $samba->{$share}{writable}; $create_mask->get_text and $samba->{$share}{'create mask'} = $create_mask->get_text || delete $samba->{$share}{'create mask'}; $directory_mask->get_text and $samba->{$share}{'directory mask'} = $directory_mask->get_text || delete $samba->{$share}{'directory mask'}; $read_list->get_text and $samba->{$share}{'read list'} = $read_list->get_text || delete $samba->{$share}{'read list'}; $write_list->get_text and $samba->{$share}{'write list'} = $write_list->get_text || delete $samba->{$share}{'write list'}; $admin_users->get_text and $samba->{$share}{'admin users'} = $admin_users->get_text || delete $samba->{$share}{'admin users'}; $valid_users->get_text and $samba->{$share}{'valid users'} = $valid_users->get_text || delete $samba->{$share}{'valid users'}; $inherit_permissions->get_text and $samba->{$share}{'inherit permissions'} = $inherit_permissions->get_text || delete $samba->{$share}{'inherit permissions'}; $hide_dot_files->get_text and $samba->{$share}{'hide dot files'} = $hide_dot_files->get_text || delete $samba->{$share}{'hide dot files'}; $hide_files->get_text and $samba->{$share}{'hide files'} = $hide_files->get_text || delete $samba->{$share}{'hide files'}; $preserve_case->get_text and $samba->{$share}{'preserve case'} = $preserve_case->get_text || delete $samba->{$share}{'preserve case'}; $force_create_mode->get_text and $samba->{$share}{'force create mode'} = $force_create_mode->get_text || delete $samba->{$share}{'force create mode'}; $force_group->get_text and $samba->{$share}{'force group'} = $force_group->get_text || delete $samba->{$share}{'force group'}; $default_case->get_text and $samba->{$share}{'default case'} = $default_case->get_text || delete $samba->{$share}{'default case'}; # update listshare push @listshare, { share_name => $share, path => $samba->{$share}{path}, comment => $samba->{$share}{comment}, browseable => $samba->{$share}{browseable}, public => $samba->{$share}{public}, writable => $samba->{$share}{writable}, create_mask => $samba->{$share}{'create mask'}, directory_mask => $samba->{$share}{'directory mask'}, read_list => $samba->{$share}{'read list'}, write_list => $samba->{$share}{'write list'}, admin_users => $samba->{$share}{'admin users'}, valid_users => $samba->{$share}{'valid users'}, inherit_permissions => $samba->{$share}{'inherit permissions'}, hide_dot_files => $samba->{$share}{'hide dot files'}, hide_files => $samba->{$share}{'hide files'}, preserve_case => $samba->{$share}{'preserve case'}, force_create_mode => $samba->{$share}{'force create mode'}, force_group => $samba->{$share}{'force group'}, default_case => $samba->{$share}{'default case'}, }; $w->destroy; }, }, ), ] ), ); $w->{window}->show_all; } sub remove_entry { my ($selected, $list) = @_; my $share_name = $list->{data}[$selected][1]; splice @{$list->{data}}, $selected, 1; delete $samba->{$share_name}; } sub remove_user { my ($user) = @_; system("smbpasswd -x $user"); } sub get_user() { my $conf = "/etc/passwd"; my @data = map { if_(m/^([^#:]+):[^:]+:([^:]+):/ && $2 > 499, $1) } cat_($conf); return sort(@data, " "); } sub modify_user_info { my ($user, $_passwd, $todo) = @_; my ($buser, $bpasswd); my $dialog = new Gtk2::Dialog(); $dialog->set_title(N("Add Samba user")); $dialog->set_modal(1); $dialog->set_position('center'); $dialog->set_resizable(0); if ($todo eq "add") { $buser = Gtk2::ComboBox->new_with_strings([ get_user() ]); $buser->set_wrap_width(3); } else { $buser = Gtk2::Label->new; $buser->set_text($user); } $bpasswd = Gtk2::Entry->new; $bpasswd->set_visibility(0); gtkpack_($dialog->vbox, 0, gtkadd(Gtk2::Frame->new(N("User information")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 5), 0, $label_and_widgets->(N("User name:"), $buser, ""), 0, $label_and_widgets->(N("Password:"), $bpasswd, ""), ), ), 0, create_okcancel({ cancel_clicked => sub { $dialog->destroy }, ok_clicked => sub { my $user_selected = $buser->get_text; if ($todo eq "add") { if (any { /^$user_selected:/ } cat_("/etc/samba/smbpasswd")) { err_dialog(N("Error"), ("Samba User already exist")) and return; } system("smbpasswd -a $user_selected -n"); push @{$user_list->{data}}, [ $pixbuf_user, $user_selected, ]; push @listusers, { user_name => $user_selected, }; } my $passwd_e = $bpasswd->get_text; set_user_passwd($user_selected, $passwd_e); $dialog->destroy; } }, ), ); $dialog->show_all; } sub set_user_passwd { my ($user, $passwd) = @_; my $F; open($F, '|' . qq(smbpasswd $user -s)); print $F "$passwd\n"; print $F "$passwd\n"; close $F; } sub add_data_share_list { my ($share_list) = @_; get_samba_share(); foreach my $data (@listshare) { push @{$share_list->{data}}, [ $pixbuf_file, $data->{share_name}, $data->{path}, $data->{comment}, $data->{browseable}, $data->{public}, $data->{writable}, $data->{create_mask}, $data->{directory_mask}, $data->{read_list}, $data->{write_list}, $data->{admin_users}, $data->{valid_users}, $data->{inherit_permissions}, $data->{hide_dot_files}, $data->{hide_files}, $data->{preserve_case}, $data->{force_create_mode}, $data->{force_group}, $data->{default_case}, ]; push @{$display_share->{data}}, [ $pixbuf_file, $data->{share_name}, $data->{path}, $data->{comment}, ]; } } sub add_data_user_list { my ($user_list) = @_; get_samba_user(); foreach my $data (@listusers) { push @{$user_list->{data}}, [ $pixbuf_user, $data->{user_name}, ]; } } sub add_data_printer_list { my ($printer_list) = @_; get_samba_printers(); foreach my $data (@listprinters) { push @{$printer_list->{data}}, [ $pixbuf_printer, $data->{share_name}, $data->{path}, $data->{comment}, $data->{browseable}, $data->{printable}, $data->{print_command}, $data->{lpq_command}, $data->{guest_ok}, $data->{writable}, $data->{write_list}, $data->{inherit_permissions}, $data->{printing}, $data->{create_mode}, $data->{use_client_driver}, ]; } } sub configure_samba { require wizards; my %type = ( 2 => N("PDC - primary domain controller"), 3 => N("Standalone - standalone server"), ); my @yesorno = qw(yes no); push @yesorno, ""; my @loglevel = qw(0 1 2 3 4 5 6 7 8 9); my @security_list = qw(share user domain); my $wiz = wizards->new({ name => N("Samba Wizard"), pages => { welcome => { name => N("Samba server configuration Wizard") . "\n\n" . N("Samba allows your server to behave as a file and print server for workstations running non-Linux systems."), #no_back => 1, pre => sub { $o->{var}{wiz_type} = "2"; }, post => sub { if ($o->{var}{wiz_type} == 2) { return 'pdc' } elsif ($o->{var}{wiz_type} == 3) { return 'ask_workgroup' } }, data => [ { label => "", val => \$o->{var}{wiz_type}, type => 'list', list => [ sort keys %type ], format => sub { $type{$_[0]} } }, ], }, pdc => { name => N("PDC server: primary domain controller") . "\n\n" . N("Server configured as a PDC is responsible for Windows authentication throughout the domain.") . "\n" . N("Single server installations may use smbpasswd or tdbsam password backends") . "\n" . N("Domain master = yes, causes the server to register the NetBIOS name <pdc name>. This name will be recognized by other servers."), pre => sub { $o->{var}{wiz_domain_master} = "yes"; $o->{var}{wiz_security} = "user"; $o->{var}{wiz_domain_logons} = "yes"; $o->{var}{wiz_wins_support} ||= $samba->{global}{'wins support'}; $o->{var}{wiz_oslevel} = "128"; if (exists $samba->{global}{'passdb backend'}) { $o->{var}{wiz_passdb_backend_yn} = "yes"; } else { $o->{var}{wiz_passdb_backend_yn} = "no"; } }, data => [ #{ label => N("Domain logons:"), val_ref => \$o->{var}{wiz_domain_logons} }, #{ label => N("Domain master:"), val_ref => \$o->{var}{wiz_domain_master} }, { label => N("Wins support:"), val => \$o->{var}{wiz_wins_support}, list => \@yesorno }, { label => N("admin users:"), val => \$o->{var}{wiz_admin_users}, help => N("root \@adm") }, { label => N("Os level:"), val_ref => \$o->{var}{wiz_oslevel}, help => N("The global os level option dictates the operating system level at which Samba will masquerade during a browser election. If you wish to have Samba win an election and become the master browser, you can set the level above that of the operating system on your network with the highest current value. ie: os level = 34") }, ], complete => sub { if (!$o->{var}{wiz_domain_master}) { $in->ask_warn(N("Error"), N("The domain is wrong.")); return 1; } else { return 0 } }, next => 'ask_workgroup', }, ask_workgroup => { name => N("Workgroup") . "\n\n" . N("Samba needs to know the Windows Workgroup it will serve."), pre => sub { $o->{var}{wiz_workgroup} ||= $samba->{global}{workgroup}; $o->{var}{wiz_netbios} ||= $samba->{global}{netbios}; $o->{var}{wiz_netbios_name} ||= $samba->{global}{"netbios name"}; }, data => [ { label => N("Workgroup:"), val => \$o->{var}{wiz_workgroup} }, { label => N("Netbios name:"), val => \$o->{var}{wiz_netbios_name} }, ], complete => sub { if (!$o->{var}{wiz_workgroup}) { $in->ask_warn(N("Error"), N("The Workgroup is wrong.")); return 1; } else { return 0 } }, next => 'ask_security', }, ask_security => { name => N("Security mode") . "\n\n" . N("User level: the client sends a session setup request directly following protocol negotiation. This request provides a username and password.") . "\n" . N("Share level: the client authenticates itself separately for each share") . "\n" . N("Domain level: provides a mechanism for storing all user and group accounts in a central, shared, account repository. The centralized account repository is shared between domain (security) controllers."), pre => sub { $o->{var}{wiz_security} ||= $samba->{global}{security}; $o->{var}{host_allow} ||= $samba->{global}{'hosts allow'}; if ($o->{var}{wiz_type} == 3) { # remove domain security mode for standalone server pop(@security_list); } }, data => [ { label => N("Security mode"), val => \$o->{var}{wiz_security}, list => \@security_list }, { label => N("Hosts allow"), val => \$o->{var}{hosts_allow}, help => "127. 192.168.0. 192.168.1.253" }, ], next => 'ask_banner', }, ask_banner => { name => N("Server Banner.") . "\n\n" . N("The banner is the way this server will be described in the Windows workstations."), pre => sub { $o->{var}{wiz_banner} ||= $samba->{global}{'server string'}; }, data => [ { label => N("Banner:"), val => \$o->{var}{wiz_banner}, help => "Samba Server %v" }, ], complete => sub { if (!$o->{var}{wiz_banner}) { $in->ask_warn(N("Error"), N("The Server Banner is incorrect.")); return 1; } else { return 0 } }, next => 'ask_log', }, ask_log => { name => N("Samba Log") . "\n" . N("Log file: use file.%m to use a separate log file for each machine that connects") . "\n" . N("Log level: set the log (verbosity) level (0 <= log level <= 10)") . "\n" . N("Max Log size: put a capping on the size of the log files (in Kb)."), pre => sub { $o->{var}{wiz_log_file} ||= $samba->{global}{'log file'}; $o->{var}{wiz_log_level} ||= $samba->{global}{'log level'}; $o->{var}{wiz_max_log_size} ||= $samba->{global}{'max log size'}; }, data => [ { label => N("Log file:"), val => \$o->{var}{wiz_log_file}, help => "/var/log/samba/log.%m" }, { label => N("Max log size:"), val => \$o->{var}{wiz_max_log_size}, help => "50" }, { label => N("Log level:"), val => \$o->{var}{wiz_log_level}, list => \@loglevel }, ], next => 'summary', }, summary => { name => N("The wizard collected the following parameters to configure Samba.") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them.") . "\n" . N("If you have previously create some shares, they will appear in this configuration. Run 'drakwizard sambashare' to manage your shares."), pre => sub { $o->{var}{wiz_sambatype} = $type{$o->{var}{wiz_type}}; }, data => [ { label => N("Samba type:"), val_ref => \$o->{var}{wiz_sambatype} }, { label => N("Workgroup:"), val_ref => \$o->{var}{wiz_workgroup} }, { label => N("Server banner:"), val_ref => \$o->{var}{wiz_banner} }, { label => N("Log file:"), val_ref => \$o->{var}{wiz_log_file} }, ], post => sub { $samba->{global}{workgroup} = $o->{var}{wiz_workgroup}; exists $o->{var}{wiz_netbios_name} and $samba->{global}{"netbios name"} = $o->{var}{wiz_netbios_name}; $samba->{global}{'server string'} = $o->{var}{wiz_banner}; $o->{var}{wiz_log_file} and $samba->{global}{'log file'} = $o->{var}{wiz_log_file}; $o->{var}{wiz_log_level} and $samba->{global}{'log level'} = $o->{var}{wiz_log_level}; $o->{var}{wiz_max_log_size} and $samba->{global}{'max log size'} = $o->{var}{wiz_max_log_size}; global_special_options(); }, next => 'endconf', }, endconf => { pre => sub { output($draksambashare, "draksambshare check") }, name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your Samba server."), no_back => 1, end => 1, next => 0 }, }, }); $wiz->process($in); $::isWizard = 0; } sub global_special_options() { # set charset $samba->{global}{'dos charset'} ||= "850"; $samba->{global}{'unix charset'} ||= "ISO8859-1"; $o->{var}{wiz_security} and $samba->{global}{security} = $o->{var}{wiz_security}; $o->{var}{hosts_allow} and $samba->{global}{'hosts allow'} = $o->{var}{hosts_allow}; # $samba->{global}{security} = $o->{var}{wiz_security}; # detect Samba type 3 is standalone if ($o->{var}{wiz_type} == "3") { exists $samba->{global}{domain_master} and delete $samba->{global}{domain_master}; exists $samba->{global}{'domain logons'} and delete $samba->{global}{'domain logons'}; exists $samba->{global}{'wins support'} and delete $samba->{global}{'wins support'}; exists $samba->{global}{'os level'} and delete $samba->{global}{'os level'}; } else { # so pdc $o->{var}{wiz_local_master} and $samba->{global}{'local master'} = $o->{var}{wiz_local_master}; $o->{var}{wiz_preferred_master} and $samba->{global}{'preferred master'} = $o->{var}{wiz_preferred_master}; $o->{var}{wiz_wins_server} and $samba->{global}{'wins server'} = $o->{var}{wiz_wins_server}; $o->{var}{wiz_name_resolve_order} and $samba->{global}{'name resolve order'} = $o->{var}{wiz_name_resolve_order}; $o->{var}{wiz_dns_proxy} and $samba->{global}{'dns proxy'} = $o->{var}{wiz_dns_proxy}; $o->{var}{wiz_domain_master} and $samba->{global}{'domain master'} = $o->{var}{wiz_domain_master}; $o->{var}{wiz_domain_logons} and $samba->{global}{'domain logons'} = $o->{var}{wiz_domain_logons}; $o->{var}{wiz_oslevel} and $samba->{global}{'os level'} = $o->{var}{wiz_oslevel}; $o->{var}{wiz_passdb_backend} and $samba->{global}{'passdb backend'} = $o->{var}{wiz_passdb_backend}; $o->{var}{wiz_wins_support} and $samba->{global}{'wins support'} = $o->{var}{wiz_wins_support}; $o->{var}{wiz_password_server} and $samba->{global}{'password server'} = $o->{var}{wiz_password_server}; $o->{var}{wiz_admin_users} and $samba->{global}{'admin users'} = $o->{var}{wiz_admin_users}; $samba->{global}{'add machine script'} = "/usr/sbin/useradd -d /dev/null -g machines -c 'Machine Account' -s /bin/false -M '%u'"; } my $conf = "/etc/group"; my @groups; foreach (cat_($conf)) { push @groups, $1 if m/^([^#:]+):[^:]+:([^:]+):/ and $2 > 499; } foreach (@groups) { system("net groupmap add unixgroup=$_ ntgroup=$_"); } } sub launch_samba_wizard() { eval { configure_samba() }; my $err = $@; if ($err && $err !~ /wizcancel/) { err_dialog(N("Error"), N("The Samba wizard has unexpectedly failed:") . "\n\n" . $err); } } ############### # Main Program ############### # create model add_data_share_list($share_list); add_data_printer_list($printer_list); add_data_user_list($user_list); $_->set_rules_hint(1) foreach $display_share, $printer_list, $user_list; $ugtk2::wm_icon = $fileshare_icon; $window = ugtk2->new(N("Manage Samba configuration")); $::main_window = $window->{real_window}; $window->{rwindow}->set_size_request(600, 410) unless $::isEmbedded; $window->{rwindow}->set_position('center') if !$::isEmbedded; my $W = $window->{window}; $W->signal_connect(delete_event => sub { ugtk2->exit }); # double clic and popup modify window $display_share->signal_connect(button_press_event => sub { my (undef, $event) = @_; my ($selected) = $display_share->get_selected_indices; $display_share->{data}[$selected][1] and modify_entry($selected) if $event->type eq '2button-press'; }); $printer_list->signal_connect(button_press_event => sub { my (undef, $event) = @_; my ($selected) = $printer_list->get_selected_indices; $printer_list->{data}[$selected][1] and modify_printers_entry($selected) if $event->type eq '2button-press'; }); $user_list->signal_connect(button_press_event => sub { my (undef, $event) = @_; my ($selected) = $user_list->get_selected_indices; $user_list->{data}[$selected][1] and modify_user_info($user_list->{data}[$selected][1], "", "change") if $event->type eq '2button-press'; }); # dont know why "$event->type eq '2button-press'" when starting draksambashare so i can't use mapn :/ #mapn { # $_[0]->signal_connect(button_press_event => sub { # my (undef, $event) = @_; # my ($selected) = $_[0]->get_selected_indices; # return unless $event->type eq '2button-press'; # $_[0]->{data}[$selected][1] and $_[1]($selected); # if $event->type eq '2button-press'; # }); #} [ $share_list, $printer_list, $user_list ], [ modify_entry, modify_printers_entry, modify_user_info ]; # create popup menu my $menupopup = Gtk2::Menu->new; my $menuitem1 = Gtk2::MenuItem->new(N("Modify")); my $menuitem2 = Gtk2::MenuItem->new(N("Remove")); $menuitem1->signal_connect(activate => sub { my ($selected) = $display_share->get_selected_indices; modify_entry($selected); }); $menuitem2->signal_connect(activate => sub { my ($selected) = $display_share->get_selected_indices; ask_okcancel("Remove entry ?", "Remove $display_share->{data}[$selected][1]") or return; remove_entry($selected, $display_share); }); $_->show foreach $menuitem1, $menuitem2; $menupopup->append($_) foreach $menuitem1, $menuitem2; $display_share->signal_connect('button-press-event' => sub { my (undef, $event) = @_; return unless $event->button == 3; $menupopup->popup(undef, undef, undef, undef, $event->button, $event->time); } ); $display_share->signal_connect(key_press_event => sub { my (undef, $event) = @_; return unless $event->keyval == $Gtk2::Gdk::Keysyms{Return}; my ($selected) = $display_share->get_selected_indices; modify_entry($selected); return 1; }); # create menu my @items = get_items(); my $factory = Gtk2::ItemFactory->new('Gtk2::MenuBar', '<main>', undef); $factory->create_items('menu', @items); my $menu = $factory->get_widget('<main>'); my $okcancel = create_okcancel({ cancel_clicked => sub { ugtk2->exit }, ok_clicked => sub { &write_conf; ugtk2->exit }, }, ); gtkappend_page(my $nb = Gtk2::Notebook->new, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0), 1, create_scrolled_window($display_share), 0, gtkpack_(create_vbox('start'), 0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => \&add_entry), 0, Gtk2::HSeparator->new, 0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub { my ($selected) = $display_share->get_selected_indices; eval { modify_entry($selected) }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to Modify Samba share.") . "\n\n" . $err); } }), 0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub { my ($selected) = $display_share->get_selected_indices; ask_okcancel("Remove entry ?", "Remove $display_share->{data}[$selected][1]") or return; eval { remove_entry($selected, $display_share) }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to remove a Samba share.") . "\n\n" . $err); } }), ), ), gtkshow(gtkpack_(Gtk2::HBox->new(0,0), 0, Gtk2::Image->new_from_file($fileshare_icon), 0, Gtk2::Label->new(N("File share")), ), ), ); gtkappend_page($nb, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0), 1, create_scrolled_window($printer_list), 0, gtkpack_(create_vbox('start'), 0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => \&add_printers_entry), 0, Gtk2::HSeparator->new, 0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub { my ($selected) = $printer_list->get_selected_indices; eval { modify_printers_entry($selected) }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to Modify.") . "\n\n" . $err); } }), 0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub { my ($selected) = $printer_list->get_selected_indices; ask_okcancel("Remove entry ?", "Remove $printer_list->{data}[$selected][1]") or return; eval { remove_entry($selected, $printer_list) }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to remove.") . "\n\n" . $err); } }), ), ), gtkshow(gtkpack_(Gtk2::HBox->new(0,0), 0, Gtk2::Image->new_from_file($printershare_icon), 0, Gtk2::Label->new(N("Printers")), ), ), ); gtkappend_page($nb, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 0), 1, create_scrolled_window($user_list), 0, gtkpack_(create_vbox('start'), 0, gtksignal_connect(Gtk2::Button->new(N("Add")), clicked => sub { eval { modify_user_info("", "", "add") }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to add user.") . "\n\n" . $err); } }), 0, Gtk2::HSeparator->new, 0, gtksignal_connect(Gtk2::Button->new(N("Modify")), clicked => sub { my ($selected) = $user_list->get_selected_indices; eval { modify_user_info($user_list->{data}[$selected][1], "", "change") }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to change user password.") . "\n\n" . $err); } }), 0, gtksignal_connect(Gtk2::Button->new(N("Remove")), clicked => sub { my ($selected) = $user_list->get_selected_indices; ask_okcancel("Remove entry ?", "Remove $user_list->{data}[$selected][1]") or return; eval { remove_user($user_list->{data}[$selected][1]); remove_entry($selected, $user_list); }; my $err = $@; if ($err) { err_dialog(N("Error"), N("Failed to delete user.") . "\n\n" . $err); } }), 0, Gtk2::HSeparator->new, # FIXME: Why do we have both an "add" button and a "userdrake" one ??? 0, gtksignal_connect(Gtk2::Button->new(N("Userdrake")), clicked => sub { run_program::raw({ detach => 1 }, 'userdrake'); } ), ), ), gtkshow(gtkpack_(Gtk2::HBox->new(0,0), 0, Gtk2::Image->new_from_file($sambauser_icon), 0, Gtk2::Label->new(N("Samba Users"))), ), ); $nb->set_show_border(0); sub check_first_launch() { if (!-f $draksambashare) { info_dialog(N("Please configure your Samba server"), N("It seems this is the first time you run this tool.\nA wizard will appear to configure a basic Samba server")); launch_samba_wizard(); } } # main interface $W->add(gtkpack_(Gtk2::VBox->new(0,0), 0, $menu, 0, Gtk2::Banner->new('IC-winacces1-48', N("DrakSamba manage Samba shares")), #if_($::isEmbedded, 0, Gtk2::Label->new("Here you can add, remove and alter Samba shares.")), 1, $nb, 0, $okcancel, ), ); check_first_launch; $W->show_all; Gtk2->main;