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
|
#!/usr/bin/perl -w
################################################################################
# Mandrake Online #
# #
# Copyright (C) 2001 MandrakeSoft #
# Daouda Lo <daouda@mandrakesoft.com> #
# Renaud Chaillat <rchaillat@mandrakesoft.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 POSIX;
use Gtk;
use lib qw(/usr/lib/libDrakX);
use interactive;
use Config;
init Gtk;
Gtk->set_locale;
#use strict;
use MDK::Common;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $in = 'interactive'->vnew('su', 'default');
#-------------------------------------------------------------
# i18n routines
# IMPORTANT: next two routines have to be redefined here to
# get correct namespace (mdkonline instead of libDrakX)
# (This version is now UTF8 compliant - Sg 2001-08-31)
#-------------------------------------------------------------
sub _ {
my $s = shift @_; my $t = translate($s);
sprintf $t, @_;
}
sub translate {
my ($s) = @_;
$s ? c::dgettext('mdkonline', $s) : '';
}
my $authentication_host = "http://www.mandrakeexpert.com/firsttimewizard/validusercheck.php";
my $nb_pages=6; # 0 to 5
my $page;
my $xpm_path="/usr/share/mdkonline/pixmaps";
my $path_to_welcome="/usr/share/doc/HTML/welcome.html";
my $link_to_mdkonline="http://www.mandrakeexpert.com";
my $check_custid;
my $true=1;
my $false=0;
$::isWizard = "@ARGV" =~ /--wizard/;
$::isWizard=1;
local $_ = join '', @ARGV;
require Gtk;
require Gtk::Gdk::ImlibImage;
#init Gtk;
#Gtk->set_locale;
Gtk::Gdk::ImlibImage->init;
my $Main_Window = new Gtk::Window -toplevel;
$Main_Window->set_policy($false,$false,$true);
$Main_Window->set_position( 1 );
$Main_Window->border_width( 5 );
# For translators : the MandrakeOnline (in one world) should not be translated.
$Main_Window->set_title("MandrakeOnline");
$Main_Window->set_usize(540, 430);
$Main_Window->realize();
$Main_Window->signal_connect( "delete_event", \>k_main_quit);
my $Button_Next= new Gtk::Button(" " . _("Next >") . " ");
my $Button_End= new Gtk::Button(" " . _("Finish") . " ");
my $Button_SkipWiz= new Gtk::Button(" " ._("Quit") . " ");
my $Button_Prev= new Gtk::Button(" " . _("< Back") . " ");
my $notebook_global = new Gtk::Notebook;
$Button_End->show();
$notebook_global->set_show_border($false);
$notebook_global->set_show_tabs($false);
$page=$notebook_global->get_current_page();
my $vbox = new Gtk::VBox(0,0);
$Main_Window->add($vbox);
$vbox->pack_start($notebook_global,1,1,0);
$vbox->pack_start(new Gtk::HSeparator, 0, 0, 1);
my $hbox= new Gtk::HBox(0,5);
$vbox->pack_start($hbox, 0, 0, 1);
$hbox->pack_end($Button_Next, 0, 1, 0);
$hbox->pack_end($Button_Prev, 0, 1, 0);
$Button_SkipWiz->signal_connect( clicked => \&confirm_quit);
$hbox->pack_start($Button_SkipWiz, 0, 1, 0);
my $login_user= new Gtk::Entry();
my $passwd_user= new Gtk::Entry();
my $login = "";
my $passwd = "";
my %actions = (
2 => \&test_passwd,
3 => \&send_config
);
my @no_back_button_pages = (0,3,4,5);
$Button_Prev->set_sensitive(0);
init_ui();
$Main_Window->show_all;
Gtk->main_iteration while Gtk->events_pending;
Gtk->main;
sub init_ui {
step_wizard();
$Button_Next->signal_connect(clicked =>\&on_next_clicked);
$Button_Prev->signal_connect(clicked =>\&on_prev_clicked);
$Button_End->signal_connect(clicked =>\&on_end_clicked);
}
sub on_end_clicked {
gtk_main_quit();
}
sub on_next_clicked {
$page=$notebook_global->get_current_page();
if ( $actions{$page} ) {
$actions{$page}->();
} else {
$notebook_global->next_page();
}
$page=$notebook_global->get_current_page();
# handle the back button state
$Button_Prev->set_sensitive(1);
foreach (@no_back_button_pages) {
/$page/ and $Button_Prev->set_sensitive(0), last;
}
# change "Next" to "Finish" in the last page
if ($page == $nb_pages - 1) {
$hbox->remove($Button_Prev);
$hbox->remove($Button_Next);
$hbox->pack_end($Button_End, 0, 1, 0);
$hbox->pack_end($Button_Prev, 0, 1, 0);
}
}
sub on_prev_clicked {
$page=$notebook_global->get_current_page();
# change "Finish" to "Next" if coming from the last page
if ($page == $nb_pages - 1) {
$hbox->remove($Button_Prev);
$hbox->remove($Button_End);
$hbox->pack_end($Button_Next, 0, 1, 0);
$hbox->pack_end($Button_Prev, 0, 1, 0);
}
if ($page == 4) {
$notebook_global->set_page(2); # Alternatively, don't go back at all since passwd was correct
} elsif ($page == 6) { # Don't go back if informations were correctly sent (button should be deactivated)
} else {
$notebook_global->prev_page();
}
$page=$notebook_global->get_current_page();
# handle the back button state
$Button_Prev->set_sensitive(1);
foreach (@no_back_button_pages) {
/$page/ and $Button_Prev->set_sensitive(0), last;
}
}
sub subscribe_mdkonline() {
my $browser=$ENV{'BROWSER'};
#my $initial_user=$ENV{'INITIAL_USER'};
#my $user_current=$ENV{'USER'};
if (!$browser) {splash_warning( " ". _("Warning: No browser specified") ." "); return;}
# if ($initial_user ne "root" && $initial_user ne undef) {
# system("su -m -l $initial_user -c \"$browser $link_to_mdkonline &\"");
# } else {
system("$browser $link_to_mdkonline &");
}
sub test_passwd () {
my $current_page = shift;
my $result = -1;
$login = $login_user->get_text();
$passwd = $passwd_user->get_text();
if ($login !~ /\s*/ && $passwd !~ /\s*/) {
# OLD METHOD, keep it for next version ?...
# my $ssh_script = "";
# foreach ("/usr/bin/sshlogin.exp","./sshlogin.exp") {
# [ -e "$_" ] and $ssh_script="$_", last;
# }
# print "Exec: $ssh_script $login $authentication_host $passwd \n";
# TODO: beware if the script was not found
# `$ssh_script $login $authentication_host $passwd`;
# NEW METHOD (http)
# first, MD5ify the password
$passwd = md5 ($passwd); # or md5_hex () or md5_base64 ()
require HTTP::Request;
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# TEST URL
print STDERR "Real url should be: $authentication_host?u=$login&p=$passwd \n";
my $request = HTTP::Request->new(GET => 'http://www.mandrakeexpert.com/firsttimewizard/validusercheck.php?u=mark&p=26bdb06eabafac3aea95991149dd8ea9');
# REAL ONE
# my $request = HTTP::Request->new(GET => '$authentication_host?u=$login&p=$passwd');
my $response = $ua->request($request);
# Check the outcome of the response
if ($response->is_success) {
$result = ($response->content =~ /TRUE/) ? 0 : -1;
} else {
# pb with the connection ?
info_popup (_("Connection problem"), _("MandrakeOnline could not be contacted, please try again at a later time"));
return;
}
} else {
$result = -1; # not needed, but this way it's clear
}
# if correct, go to page 4
if (! $result) {
$notebook_global->next_page();
} else {
# if incorrect, clear passwd and stay on page 2
info_popup (_("Wrong password"), _("Your login or password was wrong.\nEither you'll have to type it again, or you'll need to create an account on Mandrake Online.\n In the latter case, go back to the first step to connect to Mandrake Online."));
$passwd_user->set_text("");
}
}
sub send_config {
# When we arrive here, we're sure the login/passwd is correct
# print STDERR "Sending config\n";
`/usr/sbin/drakbug_report > /root/drakbug_report.log`;
my $scp_script = "";
foreach ("/usr/bin/scpcall.exp","./scpcall.exp") {
[ -e "$_" ] and $scp_script="$_", last;
}
# print "Exec: $scp_script /root/drakbug_report.log $login $authentication_host $passwd \n";
# TODO: beware if the script was not found
`$scp_script /root/drakbug_report.log $login $authentication_host $passwd`;
# if informations were sent correctly (exit code: 0 from scp script), go to page 5
if (! $?) {
$notebook_global->set_page(5);
} else {
# if incorrect, go/stay on page 4 to retry sending data
$notebook_global->set_page(4);
}
}
sub step_wizard {
my $vbox_welc= new Gtk::VBox(0,0);
write_on_pixmaps($vbox_welc,"mdkonline.png",_("Welcome to MandrakeOnline"),540,100);
my $label_welc = new Gtk::Label(_("At this step You are supposed to have an account on Mandrake Online [1].\nThis 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"));
$label_welc->set_uposition(20,150);
$vbox_welc->pack_start($label_welc,0,0,1);
my $hbox_subs= new Gtk::HBox(0,0);
$hbox_subs->set_uposition(50,300);
$vbox_welc->pack_start($hbox_subs,0,0,1);
my $check_subs = new Gtk::CheckButton(_("I don't have a Mandrake Online account and I want to "));
$hbox_subs->pack_start($check_subs,0,0,1);
my $button_subs = new Gtk::Button(" " . _("Subscribe") . " ");
$button_subs->set_sensitive(0);
$check_subs->signal_connect (clicked => sub { $test_tog=$check_subs->get_active(); $button_subs->set_sensitive($test_tog);});
$button_subs->signal_connect(clicked => \&subscribe_mdkonline);
$hbox_subs->pack_start($button_subs,0,0,1);
$notebook_global->append_page($vbox_welc,new Gtk::Label("welcome"));
my $vbox_priv = new Gtk::VBox(0,0);
write_on_pixmaps($vbox_priv,"privacy.png",_("Mandrake Privacy Policy"),540,100);
get_on_privacy($vbox_priv);
$notebook_global->append_page($vbox_priv,new Gtk::Label("club"));
my $vbox_ident= new Gtk::VBox(0,0);
write_on_pixmaps($vbox_ident,"identity.png",_("MandrakeOnline Authentification"),540,100);
my $label_log = new Gtk::Label("\n\n" . _("Enter your Mandrake Online login and password:"));
$vbox_ident->pack_start($label_log,$false ,$false,1);
pack_box_identity($vbox_ident,_("Login:"),$login_user,_("Password:"),$passwd_user);
$notebook_global->append_page($vbox_ident,new Gtk::Label("login"));
my $vbox_rev=new Gtk::VBox(0,0);
write_on_pixmaps($vbox_rev,"mailnews.png",_("Sending your Configuration"),540,100);
my $label_rev = new Gtk::Label(_("This is your chance, to help us improving Mandrake Linux.\n\nThe Wizard will now send the following informations to MandrakeSoft:\n1) the packages you have installed on your system,\n2) your hardware configuration.\n\nIf you feel uncomfortable, by that idea, press 'Cancel'.\nBy pressing 'Next', you will grant us the privilege\nto learn more about about you as our customer\nand it gives us the chance to keep you informed\nabout security updates and useful upgrades."));
$label_rev->set_uposition(20,150);
$vbox_rev->pack_start($label_rev,0,0,1);
$notebook_global->append_page($vbox_rev,new Gtk::Label("revision"));
# building the "Error sending data" page
my $vbox_errorsend= new Gtk::VBox(0,0);
write_on_pixmaps($vbox_errorsend,"identity.png",_("Error while sending informations"),540,100);
my $label_errorsend = new Gtk::Label("\n\n" . _("There was an error while sending your personal informations"));
$vbox_errorsend->pack_start($label_errorsend,$false ,$false,1);
$notebook_global->append_page($vbox_errorsend,new Gtk::Label("errorsend"));
# building the "OK data sent" page
my $vbox_oksend= new Gtk::VBox(0,0);
write_on_pixmaps($vbox_oksend,"identity.png",_("Finished"),540,100);
my $label_oksend = new Gtk::Label("\n\n" . _("Your personal informations are now stored at MdkOnline"));
$vbox_oksend->pack_start($label_oksend,$false ,$false,1);
$notebook_global->append_page($vbox_oksend,new Gtk::Label("oksend"));
}
sub info_popup ($$) {
# must have been translated by the caller
my $title = shift;
my $text = shift;
my $popup = new Gtk::Dialog();
$popup->set_position(1);
my $box = new Gtk::HButtonBox;
$popup->action_area->pack_start($box,0,0,0);
my $button_ok = new Gtk::Button(" " . _("OK") . " ");
$button_ok->signal_connect_object("clicked",$popup => 'destroy');
$box->add($button_ok);
my $label = new Gtk::Label($text);
my $style = new Gtk::Style;
$style->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*")));
$label->set_style($style);
$popup->set_title($title);
$popup->vbox->pack_start( $label, 1, 1, 0 );
$popup->show_all();
$popup->set_modal(1);
}
sub confirm_quit {
my $window_about = new Gtk::Dialog();
$window_about->set_position(1);
my $bbox1 = new Gtk::HButtonBox;
$window_about->action_area->pack_start($bbox1,0,0,0);
my $button_cancel = new Gtk::Button(" " . _("Cancel") . " ");
$button_cancel->signal_connect_object("clicked",$window_about => 'destroy');
$bbox1->add($button_cancel);
my $button_quit = new Gtk::Button(" " . _("Quit") . " ");
$button_quit->signal_connect_object("clicked",\>k_main_quit);
$bbox1->add($button_quit);
my $label = new Gtk::Label(
_("Do you really want to abort MandrakeOnline?\nTo return to the Wizard press 'Cancel',\nto really quit it press 'Quit'."));
my $style1 = new Gtk::Style;
$style1->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*")));
$label->set_style($style1);
$window_about->set_title(_("Really abort? - MandrakeOnline"));
$window_about->vbox->pack_start( $label, 1, 1, 0 );
$window_about->show_all();
$window_about->set_modal(1);
}
sub pack_box_identity {
my ($vbox,$label1,$entry1,$label2,$entry2)=@_;
my $table = new Gtk::Table( 2, 2, $true);
my $Label_wg1=new Gtk::Label($label1);
my $Label_wg2=new Gtk::Label($label2);
$table->attach_defaults( $Label_wg1, 0, 1, 0, 1);
$table->attach_defaults( $entry1, 1, 2, 0, 1);
$table->attach_defaults( $Label_wg2, 0, 1, 1, 2);
$table->attach_defaults( $entry2, 1, 2, 1, 2);
$Label_wg1->set_uposition(50,170);
$Label_wg2->set_uposition(40,200);
$entry1->set_uposition(210,170);
$entry2->set_uposition(210,200);
$entry2->set_visibility($false);
$vbox->pack_start($table,$true ,$true ,1);
}
sub load_text {
my $line;
my ($text,$file)=@_;
open( FILE, $file ) or die "load_text: missing file $file";
foreach $line ( <FILE> )
{
$text->insert( $fixed_font, undef, undef, $line );
}
close( FILE );
}
sub get_on_privacy {
my ($vbox)=@_;
my $table=new Gtk::Table( 1, 2, $false );
my $text=new Gtk::Text(undef,undef);
$text->set_editable($false);
$table->attach( $text, 0, 1, 0, 1,
[ 'expand', 'shrink', 'fill' ],
[ 'expand', 'shrink', 'fill' ],
0, 0 );
my $vscrollbar = new Gtk::VScrollbar( $text->vadj );
$table->attach( $vscrollbar, 1, 2, 0, 1, 'fill',
[ 'expand', 'shrink', 'fill' ], 0, 0 );
load_text($text,"/usr/share/mdkonline/privacy.txt");
$vbox->pack_start( $table, $true, $true, 0 );
}
sub gtkpng { new Gtk::Pixmap(gtkcreate_png(@_)) }
sub gtkcreate_png {
my ($f) = @_;
$f =~ m|.png$| or $f="$f.png";
if ( $f !~ /\//) { -e "$_/$f" and $f="$_/$f", last foreach $ENV{SHARE_PATH}, "$pixmaps", "pixmaps" }
my $im = Gtk::Gdk::ImlibImage->load_image($f) or die "gtkcreate_png: missing png file $f";
$im->render($im->rgb_width, $im->rgb_height);
($im->move_image(), $im->move_mask);
}
sub write_on_pixmaps {
my ($vbox, $pix_name, $step_label, $width, $height)=@_;
my $darea= new Gtk::DrawingArea();
$darea->set_usize($width,$height);
$vbox->pack_start($darea,0,0,0);
my ($pix1,$pix_mask1) = gtkcreate_png("$xpm_path/$pix_name");
my ($y1, $x1) = $pix1->get_size;
my $style= new Gtk::Style;
$style->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--17-*-100-100-p-*-iso8859-*,*-r-*")));
my $w = $style->font->string_width(_("Welcome"));
$darea->signal_connect(expose_event => sub {
my $i;
for ($i=0;$i<($width/$y1);$i++) {
$darea->window->draw_pixmap ($darea->style->bg_gc('normal'),
$pix1, 0, 0, 0, $y1*$i,
$x1 , $y1 );
$darea->window->draw_string(
$style->font,
$darea->style->white_gc,
80+(380-$w)/2, 62,
$step_label );
}
});
}
sub splash_warning {
my ($label) = @_;
my $win_about = new Gtk::Dialog();
$win_about->set_position(1);
my $bbox1 = new Gtk::HButtonBox;
$win_about->action_area->pack_start($bbox1,0,0,0);
my $button = new Gtk::Button(" " . _("Close") . " ");
$button->signal_connect_object("clicked",$win_about => 'destroy');
$bbox1->add($button);
my $lab = new Gtk::Label($label);
my $style1 = new Gtk::Style;
$win_about->vbox->pack_start($lab, 1, 1, 0);
$win_about->show_all();
$win_about->set_modal(1);
}
sub gtk_main_quit {
print _("Quitting Wizard\n");
main_quit Gtk;
}
|