summaryrefslogtreecommitdiffstats
path: root/kolab_wizard/Kolab.pm
blob: 512d14c086706732e9d3dbd52cd1c38ff21861dd (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
#!/usr/bin/perl
#
# Drakwizard
# Copyright (C) 2003 Florent Villard <warly@mandrakesoft.com>
# Copyright (C) 2004 Antoine Ginies <aginies -ateu_ 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::Kolab;
use strict;
use common;
use MDK::Wizard::IFCFG;
use MDK::Wizard::Wizcommon;
use MDK::Wizard::Wizcommon_gtk2;


my $wiz = new MDK::Wizard::Wizcommon;

my $HOSTNAME = chomp_(`hostname`);
my $IPSERVER = $wiz->{net}->itf_get("IPADDR");
if (!$IPSERVER) {
  my $interface = 'eth0';
  ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
}
my $DOMAINNAME = chomp_(`dnsdomainname`);
#my $kolab_config = "/etc/kolab/kolab.conf";
my $CAYESORNO;

my $o = {
	 name => N("Kolab configuration wizard"),
	 init => sub {
	   test_host_domain($HOSTNAME, $DOMAINNAME);
	 },
	 var => {
		 hostname => $HOSTNAME,
		 ip1 => $IPSERVER,
		 domain => $DOMAINNAME,
		 password => '',
		 capasswd => '',
		 keypasswd => '',
		},
	 needed_rpm => [ 'proftpd', 'openldap-servers', 'kolab' ],
	 #	 defaultimage => /usr/share/wizards/,
	};
$::Wizard_pix_up = "/usr/share/mcc/themes/default/kolab-mdk.png";

my %type = (
	    1 => N("Master kolab server"),
#	    2 => N("Slave kolab server"),
	   );

$o->{pages} = {
	       welcome => {
			   name => N("Welcome to the Kolab Groupware server configuration Wizard.") . "\n\n" . N("Kolab is a secure, scalable and reliable groupware server. Some of the major features include: a web administration interface, a shared address book with provision for mailbox users as well as contacts and a POP3 as well as IMAP4(rev1) access to mail") . "\n\n" . N("Warning: Kolab needs to configure many other services: Proftpd, LDAP, Cyrus, Postfix, Imap, Saslauth. Wizard will make a backup of all your previous configuration files for these services."),
			   no_back => 1,
			   next => 'masterslave',
			  },
	        masterslave => {
				name => N("Master or slave Kolab server"),
				post => sub {
				  if ($o->{var}{wiz_type} == 1) {
				    $o->{var}{masterslave} = "1";
				    return 'slaveserver';
				  } else {
				    $o->{var}{masterslave} = "2";
				    return 'domain';
				  }
				},
                           data => [
				    { label => "", val => \$o->{var}{wiz_type}, type => 'list', list => [ sort keys %type ], format => sub { $type{$_[0]} } },
                                   ],
			  },
	        master => {
			   name => N("You choose a Master Kolab server"),
			   next => 'slaveserver',
			  },
	       slaveserver => {
			       name => N("You choose to configure a master Kolab server.") . "\n\n" . N("Enter fully qualified hostname of slave kolab server e.g. thishost.domain.tld (leave empty if none)."),
			       data => [
					{ label => N("Slave kolab server:"), val => \$o->{var}{slaveserver} },
				       ],
			       next => 'domain',
			       no_back => 1,
			      },
	       domain => {
			  name => N("Kolab Domain") . "\n\n" . N("Please enter your Maildomain - if you do not know your mail domain use the FQDN from above. Kolab primary email addresses will be of the type user\@yourdomain"),
			  pre => sub {
			    $o->{var}{domain} = $DOMAINNAME;
			  },
			  data => [
				   { label => N("Domain:"), val => \$o->{var}{domain} },
				  ],
			  next => 'password',
			  complete => sub {
			    if (!$o->{var}{domain}) {
			      $::in->ask_warn(N("Error"), N("You need a Kolab domain"));
			      return 1;
			    } else { return 0 }
			  },
			 },
	       password => {
			    name => N("Enter password for the 'manager' account of Kolab server."),
			    pre => sub {
			      $o->{var}{password} = "dfgdfg";
			      $o->{var}{password2} = "dfgdfg";
			    },
			    complete => sub {
			      if ($o->{var}{password} ne $o->{var}{password2} || $o->{var}{password} eq "") {
				$::in->ask_warn(N("Error:"), N("Password mismatch, or null password, please correct."));
				return 1;
			      }
			    },
			    data => [
				     { label => N("Password:"), val => \$o->{var}{password}, hidden => 1 },
				     { label => N("Password again:"), val => \$o->{var}{password2}, hidden => 1 },
				    ],
			    next => 'organame',
			   },
	       organame => {
			    name => N("Enter organisation name and organisational unit"),
			    pre => sub {
			      $o->{var}{wiz_organame} = "kolab";
			      $o->{var}{wiz_orgaunit} = "Test_CA";
			    },
			    data => [
				     { label => N("Organisation name:"), val => \$o->{var}{wiz_organame} },
				     { label => N("Organisational unit:"), val => \$o->{var}{wiz_orgaunit} },
				    ],
			    complete => sub { 
			      if (!$o->{var}{wiz_orgaunit} || !$o->{var}{wiz_organame}) {
				$::in->ask_warn(N("Error"), N("You need to enter an Organisation name and an organisational unit"));
				return 1;
			      } else { return 0 }
			    },
			    next => 'summary',
			   },
	       cayesorno => {
			      name => N("Kolab can create and manage a certificate authority that can be used to create SSL certificates for use within the Kolab environment.") . "\n\n" . N("You can choose to skip this section if you already have certificates for the Kolab server.CA and certificate"),
			      post => sub {
				if ($o->{var}{cayesorno}) {
				  $CAYESORNO = "y";
				  return 'capassword';
				} else {
				  $CAYESORNO = "n";
				  return 'summary_noca';
				}
			      },
			     pre => sub {
			       $o->{var}{cayesorno} = 1;
			     },
			      data => [
				       { label => "Do you want to create CA and certificates:", type => 'bool', val => \$o->{var}{cayesorno} },
				      ],
			     },
	       capassword => {
			      name => N("Kolab can create and manage a certificate authority that can be used to create SSL certificates for use within the \Kolab environment. Enter the passphrase for CA, and the passphrase for the RSA key."),
			      complete => sub {
				if ($o->{var}{capasswd} ne $o->{var}{capasswd2} || $o->{var}{capasswd} eq "") {
				  $::in->ask_warn(N("Error:"), N("Password mismatch, or null password, please correct."));
				  return 1;
				}
				if ($o->{var}{keycapasswd} ne $o->{var}{keycapasswd2} || $o->{var}{keycapasswd} eq "") {
				  $::in->ask_warn(N("Error:"), N("Password mismatch, or null password, please correct."));
				  return 1;
				}
			      },
			      pre => sub {
				      foreach ($o->{var}{capasswd}, $o->{var}{capasswd2}, $o->{var}{keycapasswd}, $o->{var}{keycapasswd2}) {
					$_ = "rrrrrrrrrr";
				      }
				     },
			      data => [
				       { label => N("CA passphrase:"), val => \$o->{var}{capasswd}, hidden => 1 },
				       { label => N("CA passphrase again:"), val => \$o->{var}{capasswd2}, hidden => 1 },
				       { label => ' ', },
				       { label => N("RSA key passphrase:"), val => \$o->{var}{keycapasswd}, hidden => 1 },
				       { label => N("RSA key passphrase:"), val => \$o->{var}{keycapasswd2}, hidden => 1 },
				      ],
			      next => 'summary',
			     },
	       summary => {
			   name =>  N("The wizard will now configure Kolab server with these parameters"),
			   data => [
				    { label => N("Hostname:"), fixed_val => \$o->{var}{hostname} },
				    { label => N("Domain:"), fixed_val => \$o->{var}{domain} },
				    { label => "" },
				    { label => N("Organisation name:"), fixed_val => \$o->{var}{wiz_organame} },
				    { label => N("Organisationnal unit:"), fixed_val => \$o->{var}{wiz_orgaunit} },
				    { label => N("With CA") },
				   ],
			   post => \&do_it_master,
			   next => 'end',
			  },
	       summary_noca => {
			   name =>  N("The wizard will now configure Kolab server with these parameters"),
			   data => [
				    { label => N("Hostname:"), fixed_val => \$o->{var}{hostname} },
				    { label => N("Domain:"), fixed_val => \$o->{var}{domain} },
				    { label => "" },
				    { label => N("Organisation name:"), fixed_val => \$o->{var}{wiz_organame} },
				    { label => N("Organisationnal unit:"), fixed_val => \$o->{var}{wiz_orgaunit} },
				   ],
			   post => \&do_it_master_withoutca,
			   next => 'end',
			       },
	       end => {
		       name => N("Done") . "\n\n" . N("The kolab server is now configured. Log in as 'manager' with the password you entered at https://127.0.0.1/kolab/admin/"),
		       end => 1,
		       next => 0,
		      },
	      };


sub new {
  my ($class) = @_;
  bless {
	 o   => $o,
	}, $class;
}

sub do_it_master_withoutca {
  return if $::testing;
  my $in = 'interactive'->vnew('su', 'Kolab server');
  my $w = $in->wait_message(N("Kolab server"), N("Configuring Kolab server on your system..."));
}

sub do_it_master {
  return if $::testing;
  !-f "/etc/kolab/.kolab2_configured" and system("touch /etc/kolab/.kolab2_configured");
  MDK::Wizard::Wizcommon_gtk2::gtk_log("service kolab stop", "");
  my $in = 'interactive'->vnew('su', 'Kolab server');
  my $w = $in->wait_message(N("Kolab server"), N("Configuring Kolab server on your system..."));

  system("rm -rf /etc/kolab/*.pem");
  system("rm -rf /etc/kolab/*.kolabtmp");
  system("rm -rf /etc/kolab/ca/*");

  substInFile {
      s|\$REQ -new -x509 -keyout \${CATOP}/private/\$CAKEY.*|\$REQ -new -x509 -keyout \${CATOP}/private/\$CAKEY -passout pass\:\$PASSKOLAB \\|;
      s|\$CA -policy policy_anything.*|\$CA -policy policy_anything -batch -out \${outfile} -passin pass\:\$PASSKOLAB -infiles \${infile}|;
  } "/etc/kolab/kolab_ca.sh";

  $ENV{PASSKOLAB} = $o->{var}{password};

  my $F;
  open($F, "|/usr/sbin/kolab_bootstrap -b\n");
  print $F "y
$o->{var}{hostname}
$o->{var}{masterslave}
$o->{var}{domain}
$o->{var}{password}
$o->{var}{slaveserver}
$CAYESORNO
$o->{var}{wiz_organame}
$o->{var}{wiz_orgaunit}

y
";
  close $F;
  undef $w;
  MDK::Wizard::Wizcommon_gtk2::gtk_log("service kolab start", "");
}

1;