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
|
#!/usr/bin/perl
# Drakwizard
# Copyright (C) 2003 Mandrakesoft
#
# Author: Florent Villard <warly@mandrakesoft.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# 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.
package MDK::Wizard::Inn;
use strict;
use common;
require MDK::Wizard::Wizcommon;
use MDK::Wizard::Varspaceval;
my $wiz = new MDK::Wizard::Wizcommon;
my $o = {
name => 'News Wizard',
var => {
news_server => '',
news_freq => ''
},
needed_rpm => [ 'inn' ],
defaultimage => "$ENV{__WIZ_HOME__}news_wizard/images/news.png"
};
$o->{pages} = {
welcome => {
name => N("Welcome to the News Wizard") . "\n\n" . N("This wizard will help you configuring the Internet News services for your network."),
no_back => 1,
next => 'ask_news_server'
},
ask_news_server => {
name => N("News Server") . "\n\n" . N("The news server name is the name of the host providing the Internet news to your network; the name is usually provided by your provider.") . "\n\n" . N("Internet host names must be in the form \"host.domain.domaintype\"; for example, if your provider is \"provider.com\", the internet news server is usually \"news.provider.com\"."),
pre => sub {
$o->{var}{news_server} ||= get_server();
},
data => [
{ label => N("News Server Name:"), val => \$o->{var}{news_server} },
],
post => sub { $o->{var}{news_server} or 'error_in_news_server' },
next => 'ask_news_freq'
},
ask_news_freq => {
name => N("Polling Period") . "\n\n" . N("Your server will regularly poll the News Server for obtaning the latest Internet News; the polling period set the interval between two consecutive polling.") . "\n\n" . N("Depending on the kind of internet connection you have, an appropriate polling period can change between 6 and 24 hours."),
pre => sub {
$o->{var}{news_freq} ||= 24;
},
data => [
{ label => N("Polling Period (Hours):"), val => \$o->{var}{news_freq} },
],
post => \&check_valid_hours,
next => 'summary'
},
warning => {
name => N("Warning."),
ignore => 1,
next => 'summary'
},
error_in_news_server => {
name => N("Error.") . "\n\n" . N("The news server name is not correct"),
ignore => 1,
next => 'ask_news_server'
},
error_in_polling_time => {
name => N("Error.") . "\n\n" . N("The polling period is not correct"),
ignore => 1,
next => 'ask_news_freq'
},
summary => {
name => N("Configuring the Internet News") . "\n\n" . N("The wizard collected the following parameters
needed to configure your Internet News Service:") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them."),
data => [
{ label => N("News Server:"), fixed_val => \$o->{var}{news_server} },
{ label => N("Polling Interval:"), fixed_val => \$o->{var}{news_freq} },
],
post => \&do_it,
next => 'end'
},
end => {
name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your Internet News service of your server."),
end => 1,
next => 0
},
};
sub new {
my ($class, $conf) = @_;
bless {
o => $o,
}, $class;
}
sub check_valid_hours {
$o->{var}{news_freq} =~ /^\d+$/ or return 'error_in_polling_time'
}
sub normalize_freq {
my ($freq) = @_;
if ($freq =~ /(\d*)/) {
$freq = $1;
}
if ($freq <= 0) {
$freq = 0;
}
if ($freq >= 24) {
$freq = 24;
}
$freq;
}
sub get_server {
my %mdk = MDK::Wizard::Varspaceval->get("/etc/leafnode/config");
$mdk{server}
}
sub normalize_server {
my ($server) = @_;
$server
}
sub do_it {
$::testing and return;
$o->{var}{news_freq} and my $freq = normalize_freq($o->{var}{news_freq}) or
die "freq not defined: $!";
$o->{var}{news_server} and my $server = normalize_server($o->{var}{news_server}) or
die "server not defined: $!";
my $file = "/etc/leafnode/config";
-d "/etc/leafnode" or mkdir "/etc/leafnode";
output($file, map {
s|__server__|$server|g;
$_;
} cat_("__WIZ_HOME__/news_wizard/scripts/config.default"));
$file = "/var/spool/cron/news";
my $file_c = "/etc/leafnode/crontab";
if (-f $file) {
MDK::Common::cp_af($file, $file_c);
MDK::Common::cp_af($file, $file . ".orig");
}
output($file_c, map {
s|__freq__|$freq|g;
$_;
} cat_("__WIZ_HOME__/news_wizard/scripts/news.cron"));
system("crontab -u news /etc/leafnode/crontab");
}
1;
|