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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
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 (similar to finger)."),
saned => N_("SANE (Scanner Access Now Easy) enables to access scanners, video cameras, ..."),
smb => N_("The SMB/CIFS protocol enables to share access to files & printers and also integrates with a Windows Server domain"),
sound => N_("Launch the sound system on your machine"),
sshd => N_("Secure Shell is a network protocol that allows data to be exchanged over a secure channel between two computers"),
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."),
xinetd => N_("Starts other deamons on demand."),
);
my ($name) = @_;
my $s = $services{$name};
if ($s) {
$s = translate($s);
} else {
my $file = find { -e $_ } map { "$::prefix$_/$name" } '/etc/rc.d/init.d', '/etc/init.d', '/etc/xinetd.d';
$s = cat_($file);
$s =~ s/\\\s*\n#\s*//mg;
$s =
$s =~ /^#\s+(?:Short-)?[dD]escription:\s+(.*?)^(?:[^#]|# {0,2}\S)/sm ? $1 :
$s =~ /^#\s*(.*?)^[^#]/sm ? $1 : '';
$s =~ s/#\s*//mg;
}
$s =~ s/\n/ /gm; $s =~ s/\s+$//;
$s;
}
sub ask_ {
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 ip6tables ipvsadm isdn4linux ibod jabber jabber-icq adsl squid
portsentry prelude nessusd junkbuster radvd cddbp ippl iptoip jail.init) ],
N("File sharing") => [ qw(nfs-common nfs-server 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 rpcbind 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(N("Services"), 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 => sub {
interactive::gtk::display_help($in,
{ interactive_help_id =>
'misc-params#drakxid-configureServices' }, $::main_window) },
}) or return $l, $on_services; #- no change on cancel.
[ grep { $services{$_} } @$l ];
}
sub ask_standalone_gtk {
my ($_in) = @_;
my ($l, $on_services) = services();
my @xinetd_services = map { $_->[0] } @{(services_raw())[1]};
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 {
my ($text) = @_;
$nopop->();
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($text), 'left'))),
button_press_event => sub { $nopop->() }
)))->move($x, $y) if $text;
};
my $update_service = sub {
my ($service, $label) = @_;
my $started = -e "/var/lock/subsys/$service";
$label->set_label($started ? N("running") : N("stopped"));
};
my $b = Gtk2::EventBox->new;
$b->set_events('pointer_motion_mask');
gtkadd($W->{window}, gtkadd($b, gtkpack_($W->create_box_with_title,
0, mygtk2::gtknew('Title1', label => N("Services and daemons")),
1, gtkset_size_request(create_scrolled_window(create_packtable({ col_spacings => 10, row_spacings => 3 },
map {
my $service = $_;
my $is_xinetd_service = member($service, @xinetd_services);
my $infos = warp_text(description($_), 40);
$infos ||= N("No additional information\nabout this service, sorry.");
my $label = gtkset_justify(Gtk2::Label->new, 'left');
$update_service->($service, $label) if !$is_xinetd_service;
[ gtkpack__(Gtk2::HBox->new(0,0), $_),
gtkpack__(Gtk2::HBox->new(0,0), $label),
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($is_xinetd_service ? N("Start when requested") : N("On boot")),
clicked => sub { if ($_[0]->get_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 $action = $a eq "Start" ? 'restart' : 'stop';
log::explanations(qq(GP_LANG="UTF-8" service $service $action));
# as we need the output in UTF-8, force it
local $_ = `GP_LANG="UTF-8" service $service $action 2>&1`; s/\033\[[^mG]*[mG]//g;
c::set_tagged_utf8($_);
$update_service->($service, $label);
$display->($_);
})) if !$is_xinetd_service;
} (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_;
}
sub _set_service {
my ($service, $enable) = @_;
my $script = "/etc/rc.d/init.d/$service";
run_program::rooted($::prefix, "chkconfig", $enable ? "--add" : "--del", $service);
#- FIXME: handle services with no chkconfig line and with no Default-Start levels in LSB header
if ($enable && cat_("$::prefix$script") =~ /^#\s+chkconfig:\s+-/m) {
run_program::rooted($::prefix, "chkconfig", "--level", "35", $service, "on");
}
}
sub _run_action {
my ($service, $action) = @_;
run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", $action);
}
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) {
_set_service($_, $after);
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_action($_, "stop");
}
}
}
}
sub services_raw() {
local $ENV{LANGUAGE} = 'C';
my (@services, @xinetd_services);
foreach (run_program::rooted_get_stdout($::prefix, '/sbin/chkconfig', '--list')) {
if (my ($xinetd_name, $on_off) = m!^\t(\S+):\s*(on|off)!) {
push @xinetd_services, [ $xinetd_name, $on_off eq 'on' ];
} elsif (my ($name, $l) = m!^(\S+)\s+(0:(on|off).*)!) {
push @services, [ $name, [ $l =~ /(\d+):on/g ] ];
}
}
\@services, \@xinetd_services;
}
#- returns:
#--- the listref of installed services
#--- the listref of "on" services
sub services() {
my ($services, $xinetd_services) = services_raw();
my @l = @$xinetd_services;
if ($::isInstall) {
push @l, map { [ $_->[0], @{$_->[1]} > 0 ] } @$services;
} else {
my $runlevel = (split " ", `/sbin/runlevel`)[1];
push @l, map { [ $_->[0], member($runlevel, @{$_->[1]}) ] } @$services;
}
@l = sort { $a->[0] cmp $b->[0] } @l;
[ map { $_->[0] } @l ], [ map { $_->[0] } grep { $_->[1] } @l ];
}
sub service_exists {
my ($service) = @_;
-x "$::prefix/etc/rc.d/init.d/$service";
}
sub restart ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
_run_action($service, "restart");
}
sub restart_or_start ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
_run_action($service, is_service_running($service) ? "restart" : "start");
}
sub start ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
_run_action($service, "start");
}
sub start_not_running_service ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
is_service_running($service) || _run_action($service, "start");
}
sub stop ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
_run_action($service, "stop");
}
sub is_service_running ($) {
my ($service) = @_;
# Exit silently if the service is not installed
service_exists($service) or return 1;
run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", '>', '/dev/null', '2>', '/dev/null', "status");
}
sub starts_on_boot {
my ($service) = @_;
my (undef, $on_services) = services();
member($service, @$on_services);
}
sub start_service_on_boot ($) {
my ($service) = @_;
_set_service($service, 1);
}
sub do_not_start_service_on_boot ($) {
my ($service) = @_;
_set_service($service, 0);
}
sub enable {
my ($service, $o_dont_apply) = @_;
start_service_on_boot($service);
restart_or_start($service) unless $o_dont_apply;
}
sub disable {
my ($service, $o_dont_apply) = @_;
do_not_start_service_on_boot($service);
stop($service) unless $o_dont_apply;
}
sub set_status {
my ($service, $enable, $o_dont_apply) = @_;
if ($enable) {
enable($service, $o_dont_apply);
} else {
disable($service, $o_dont_apply);
}
}
1;
|