summaryrefslogtreecommitdiffstats
path: root/mdkonline
blob: abe16f40b5b2feb229fc849f7407e3b103681144 (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
#!/usr/bin/perl
################################################################################
# Mandriva Online Text User Interface                                          # 
#                                                                              #
# Copyright (C) 2001, 2002, 2003, 2004, Mandrakesoft SA
#                  2005, 2006 Mandriva                                         #
#                                                                              #
# Daouda Lo                                                                    #
# Thierry Vignaud <tvignaud at mandriva dot 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 /usr/lib/libDrakX/drakfirsttime);
BEGIN { $::no_global_argv_parsing = 1 };
use standalone; # for explanations

use interactive;
use common;
use wizards;
use lang;

use Getopt::Long;

BEGIN { unshift @::textdomains, 'mdkonline', 'drakfirstboot' }

use mdkonline;
use Digest::MD5  qw(md5 md5_hex md5_base64);

$ugtk2::wm_icon = '/usr/share/icons/large/mdkonline.png';

#my $online_link = 'http://online3.mandriva.com/o/soap/';

my $confdir = '/root/.MdkOnline';
my $conffile = "$confdir/mdkupdate";
my $logfile = '/var/tmp/mdkonline.log';

my ($greeting, $firstname, $lastname, $login, $password, $npassword, $boxname, $cfmpassword, $email, $country, $ia, $alias);

my @info;

$ia = 1;


sub usage() {
    print STDERR N("mdonline version %s
Copyright (C) %s Mandriva.
This is free software and may be redistributed under the terms of the GNU GPL.

usage:
", 1, 2006) . N("  --help		- print this help message.
") . N("  --box=			- hostname.
") . N("  --country			- name of country of the user. 
") . N("  --interactive		- use the interactive mode.
") . N("  --nointeractive	- use the non-interactive mode.
") . N("  --login=		     - login name of the user.
") . N("  --pass=			- password  of the user.
");
    exit(0);
}

GetOptions('interactive!' => \$ia, 'login=s' => \$login, 'pass=s' => \$password, 'box=s' => \$boxname, 'country:s' => \$country,
           'embedded=s' => \$::XID,
           'help'  => \&usage,
       );

$::XID and $::isEmbedded = 1;

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

#for compatibilities
mkdir_p($confdir) if !-d $confdir;
-e '/root/.mdkupdate' and system("mv", "/root/.mdkupdate", $conffile);

$::Wizard_title = N("Mandriva Online");

my %choices = (
	       account => N("I already have an account"),
	       noaccount => N("I want to subscribe")
	      );
  
my $choice = $choices{account};

my @greets = (N("Mr."), N("Mrs."), N("Ms."));

my %countries = map { lang::c2name($_) => $_ } lang::list_countries();
my $locale = lang::read('', $>);
$country = lang::c2name($locale->{country});
my $lang = $locale->{lang} || 'en_US';

my $descboxname;

sub get_conf() {
    my $wc = mdkonline::read_conf();
    my $host = chomp_(`hostname`);
    $wc->{HOST_NAME} ||= $1 if $host =~ /(\w+)(.*)/;
    $login = $wc->{USER_EMAIL}; $boxname = $wc->{HOST_NAME}; $descboxname = $wc->{HOST_DESC};
}

sub send_conf_via_soap {
    my ($login, $password, $boxname, $descboxname, $country) = @_;
    my $_w = $in->wait_message(N("Please wait"), N("Reading configuration\n")) if $ia;
    my $reg_host = mdkonline::register_upload_host($login, $password, $boxname, $descboxname, $country);
}

my $wiz = 
  {
   name => N("Mandriva Online"),
      pages => {
		welcome => {
			    name => formatAlaTeX(N("This assistant will help you to upload your configuration\n(packages, hardware configuration) to a centralized database in\norder to keep you informed about security updates and useful upgrades.\n")),
			    no_back => 1,
                   post => sub {
                       $::main_window = $::WizardWindow; # center subdialogs on main window
                       'choices';
                   }
			   },
		choices => {
			    name => N("Account creation or authentication"),
			    data => [ { val => \$choice, type => 'list', list => [ values %choices ] } ],
			    post => sub { +{ reverse %choices }->{$choice} },
			   },
		account => {
			    name => N("Enter your Mandriva Online login, password and machine name:"),
			    pre => sub {
				get_conf();
			    },
			    data => sub {
				[
				 { label => N("Email address:"), val => \$login },
				 { label => N("Password:"), val => \$password, hidden => 1 },
				 { label => N("Machine name:"), val => \$boxname },
				 { label => N("Machine description:"), val => \$descboxname },
				 { label => N("(Ex: My Home Office's Computer)") },
				];
			    },
			    complete => sub {
				if (!mdkonline::check_valid_boxname($boxname)) {
                        $in->ask_warn(N("Error"), N("Machine name must be 1 to 40 alphanumerical characters"));
                        return 1;
				}
				    my $wait = $in->wait_message(N("Please wait"), N("Connecting to Mandriva Online website...")) if $ia;
                    my $err = mdkonline::create_authenticate_account('authenticate', $login, $password);
                    undef $wait;
                    if ($err ne 'OK') {
                        $in->ask_warn(N("Error"), $err);
                        return 1;
                    }
			    },
                   next => 'authenticate',
			   },
		authenticate => {
				 name => 
					 formatAlaTeX(N("In order to benefit from Mandriva Online services,\nwe are about to upload your configuration.\n\nThe Wizard will now send the following information to Mandriva:\n\n1) the list of packages you have installed on your system,\n\n2) your hardware configuration.\n\nIf you feel uncomfortable by that idea, or do not want to benefit from this service,\nplease press 'Cancel'. By pressing 'Next', you allow us to keep you informed\nabout security updates and useful upgrades via personalized email alerts.\nFurthermore, you benefit from discounted paid support services on\nwww.mandrivaexpert.com.")),
                     data => [ { } ],
				 complete => sub { 
                         my $err = send_conf_via_soap($login, $password, $boxname, $descboxname, $country);
                         # if authentication failed with "No host for this id", just transparently register the host again:
                         # (eg: when host was deleted through the web interface)
                        if ($err ne 'OK') {
                            if ($err =~ /No host for this id/) {
                                log::explanations("registring again the host because the id is lost (deleted through the web interface?");
                                substInFile { undef $_ if /HOST_ID|HOST_NAME/ } '/etc/sysconfig/mdkonline';
                                $err = send_conf_via_soap($login, $password, $boxname, $descboxname, $country);
                            }
                            return  $err eq 'OK';
                            $in->ask_warn(N("Error"), N("Connection problem") . "\n\n" . N("Problem occurs when uploading files, please try again") . "\n\n" . $err);
                            return 1;
                        }
				 },
                     next => 'upload',
				},
		noaccount => {
			      name => N("Create a Mandriva Online Account"),
			      data => sub {
				  [
				   { label => 
				   #-PO: that is for things like "Mr", "Ms",...
				   N("Greeting:"), val => \$greeting, list => [ @greets ], type => 'combo' },
				   { label => N("First name:"), val => \$firstname },
				   { label => N("Last name:"), val => \$lastname },
				   { label => N("Email address:"), val => \$email },
				   { label => N("Password:"), val => \$npassword, hidden => 1 },
				   { label => N("Confirm Password:"), val => \$cfmpassword, hidden => 1 },
				  ];
			      },
			      complete => sub {
				  $alias = $firstname . $lastname;
				  @info = ($email, $npassword, $firstname, $lastname, $lang, $greeting, $alias, 'home');
                      if ($npassword ne $cfmpassword) {
                          $in->ask_warn(N("Error"), N("The passwords do not match\n Please try again\n"));
                          return 1;
                      }
                      if (!$email || !$firstname || !$lastname) {
                          $in->ask_warn(N("Error"), N("Please fill in each field"));
                          return 1;
                      }
                      if (mdkonline::check_valid_email($email) == 0) {
                          $in->ask_warn(N("Error"), N("Not a valid mail address!\n") . "\n\n"  . $email);
                          return 1;
                      }
                      my $err = mdkonline::create_authenticate_account('create', @info);
                      if ($err ne 'OK') {
                          $in->ask_warn(N("Error"), N("Creating account failed!") . "\n\n" . $err);
                          return 1;
                      }

			      },
                     next => 'createaccount',
			     },
		createaccount => {
				  name => formatAlaTeX(N("Mandriva Online Account successfully created.\nPlease click \"Next\" to authenticate and upload your configuration\n")),
				  next => 'account',
				 },
		upload => {
			   name => formatAlaTeX(N("Your upload was successful!") . "\n\n" . N("From now you will receive on security and updates \nannouncements thanks to Mandriva Online.") . "\n\n" . N("Mandriva Online offers you the ability to automate the updates.\nA program will run regulary in your system waiting for new updates\n")),
			   data => sub {
				   [
				    { label => N("Country"), val => \$country, type => "combo", list => [ sort keys %countries ], not_edit => 0 }
				   ];
			   },
			   post => sub {
				   mdkonline::automated_upgrades();
				   #mdkonline::clean_confdir();
				   "end";
			       }
			  },
		end => {
			name => sub {
			    N("Congratulations") . "\n\n" . N("Your Mandriva Online account has been successfully configured\n");
			  },
			end => 1,
			no_back => 1,
			next => 0,
		       }
	       }
  };

if (!$ia && $login && $password && $boxname) { 
    my $is_success = mdkonline::create_authenticate_account('authenticate', $login, $password);
    if ($is_success eq 'OK') {
	my $sendconfres = send_conf_via_soap($login, $password, $boxname, $descboxname, $country);
	if ($sendconfres eq 'OK') {
	    mdkonline::automated_upgrades();
	    output_p($logfile, N("Configuration uploaded successfully"));
	} else { output_p($logfile, N("Problem uploading configuration")) }
    } else { 
	output_p($logfile, N("Cannot connect to Mandriva Online website: wrong login/password or router/firewall bad settings"));
    }
} else {
    !$::testing && mdkonline::get_release <= 2006.0 ? wizards->new->safe_process($wiz, $in) : wizards->new($wiz)->safe_process($in);
}