diff options
Diffstat (limited to 'mdkonline')
-rwxr-xr-x | mdkonline | 421 |
1 files changed, 168 insertions, 253 deletions
@@ -1,6 +1,6 @@ #!/usr/bin/perl ################################################################################ -# MandrakeOnline # +# Mandrakeonline Text User Interface # # # # Copyright (C) 2001-2002-2003-2004 Mandrakesoft # # # @@ -22,283 +22,198 @@ use strict; use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime); -use common; use standalone; + +use interactive; +use common; +use wizards; use lang; -BEGIN { unshift @::textdomains, 'mdkonline', 'drakfirstboot' } +use Getopt::Long; -$::no_ugtk_init = 1; -if (check_for_xserver()) { - $::no_ugtk_init = 0; - eval { require ugtk2 }; - die "Can't load ugtk2...\n" if $@; - ugtk2->import(qw(:all)); -} else { - exec("/usr/sbin/mdkonline_tui"); -} +BEGIN { unshift @::textdomains, 'mdkonline', 'drakfirstboot' }; use mdkonline; -use comdialog; use Digest::MD5 qw(md5 md5_hex md5_base64); -my $confdir = '/root/.MdkOnline'; -my $conffile = "$confdir/mdkupdate"; +my $in = interactive->vnew('su'); -add_icon_path("/usr/share/drakfirsttime/pixmaps/"); +my $expert_link = 'http://www.mandrakeexpert.com'; +my $online_link = 'https://www.mandrakeonline.net'; -require_root_capability(); -my $create_account = 0; - -my ($o, $p); +my $confdir = '/root/.MdkOnline'; +my $conffile = "$confdir/mdkupdate"; +my $logfile = '/tmp/mdkonline.log'; #for compatibilities mkdir_p($confdir) if !-d $confdir; -mdkonline::mv_files("/root/.mdkupdate", $conffile); +-e '/root/.mdkupdate' and system("mv", "/root/.mdkupdate", $conffile); -$o->{mw} = ugtk2->new("Mandrakeonline" . " " . $::VERSION, center => 1); -gtkset_size_request($o->{mw}{window}, 600, 500); -$o->{mw}{rwindow}->set_position('center'); -$o->{mw}{window}->signal_connect("delete_event", sub { Gtk2->main_quit }); -$o->{nb} = Gtk2::Notebook->new; -$o->{nb}->set_show_tabs(0); $o->{nb}->set_show_border(0); -$o->{bottomHbox} = Gtk2::HBox->new; -my %stage = ( - 0 => sub { if ($o->{account_cb}->get_active) { subs_online() } else { $o->{nb}->next_page } }, - 1 => sub { $o->{nb}->next_page; set_entry_with_conf() }, - 2 => sub { check_passwd() }, - 3 => sub { log::l("[mdkonline] Sending configuration to remote server"); send_conf_online() }, - 4 => sub { log::l("[mdkonline] Writing local configuration dir"); set_conf() } - ); -$o->{actions} = { - Next => sub { - $p = $o->{nb}->get_current_page; - $stage{$p}->(); - $p <= 0 and $o->{Prev}->set_sensitive(1); - $p == 4 and main_quit() - }, - SkipWiz => sub { - main_quit() - }, - Prev => sub { - $p = $o->{nb}->get_current_page; - $o->{nb}->prev_page; - $p <= 1 and init(0) - } - }; -foreach my $l ([ 'Next', N("Next"), 1 ], [ 'SkipWiz', N("Cancel") ], [ 'Prev', N("Previous"), 1 ]) { - $o->{$l->[0]} = Gtk2::Button->new($l->[1]); - $l->[2] ? $o->{bottomHbox}->pack_end($o->{$l->[0]}, 0, 0, 1) : $o->{bottomHbox}->pack_start($o->{$l->[0]}, 0, 0, 1); - $o->{$l->[0]}->signal_connect(clicked => sub { $o->{actions}{$l->[0]}->() }); -} -gtkadd($o->{mw}{window}, - gtkpack_(Gtk2::VBox->new(0, 2), - 1, $o->{nb}, - 0, Gtk2::HSeparator->new, - 0, gtkpack($o->{bottomHbox}), - ), - ); -gtkappend_page($o->{nb}, - gtkpack_(Gtk2::VBox->new(0, 3), - 0, set_darea(N("Welcome to Mandrakeonline"), 'welcome'), - 0, gtktext_insert(Gtk2::TextView->new, 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")), - 1, gtkadd(gtkset_border_width(Gtk2::Frame->new(N("Create a Mandrakeonline Account")), 5), - gtkpack_(gtkset_border_width(Gtk2::VBox->new(0, 5), 5), - 0, gtksignal_connect(gtkset_active($o->{account_cb} = Gtk2::CheckButton->new(N("I don't have a Mandrakeonline account and I want to subscribe")), $create_account), clicked => sub { $create_account = !$create_account; $o->{vbox_account}->set_sensitive($create_account) }), - 1, gtkpack_($o->{vbox_account} = Gtk2::VBox->new(0, 3), - 1, create_packtable({ homogeneous => 1, col_spacings => 10, row_spacings => 10, mcc => 1 }, - [], - [ N("Login:"), $o->{clogin} = Gtk2::Entry->new ], - [ N("Password:"), $o->{cpasswd} = entry_hidepass() ], - [ N("Confirm Password:"), $o->{cconfirm} = entry_hidepass() ], - [ N("Mail contact:"), $o->{cmail} = Gtk2::Entry->new ] - )) - ) - )) - ); -gtkappend_page($o->{nb}, - gtkpack_(Gtk2::VBox->new(0, 3), - 0, set_darea(N("Mandrakelinux Privacy Policy"), 'privacy'), - 1, create_scrolled_window(gtktext_insert(Gtk2::TextView->new, privacy_text())) - ) - ); -gtkappend_page($o->{nb}, - gtkpack_(Gtk2::VBox->new(0, 3), - 0, set_darea("Mandrakeonline" . " " . N("Authentification"), 'authentification'), - 0, Gtk2::WrappedLabel->new("\n\n" . N("Enter your Mandrakeonline login, password and machine name:")), - 1, create_packtable({ homogeneous => 1, col_spacings => 10, row_spacings => 10, mcc => 1 }, - [], - [ N("Login:"), $o->{login} = Gtk2::Entry->new, "" ], - [ N("Password:"), $o->{passwd} = entry_hidepass(), "" ], - [ N("Machine name:"), $o->{machine} = Gtk2::Entry->new ], - )) - ); -gtkappend_page($o->{nb}, - gtkpack_(Gtk2::VBox->new(0, 3), - 0, set_darea(N("Send Configuration"), 'sendingconf'), - 1, gtktext_insert(Gtk2::TextView->new, N("In order to benefit from Mandrakeonline services,\nwe are about to upload your configuration.\n\nThe Wizard will now send the following information to Mandrakesoft:\n1) the list of packages you have installed on your system,\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.mandrakeexpert.com.")) - ) - ); -gtkappend_page($o->{nb}, - gtkpack_(Gtk2::VBox->new(0, 3), - 0, set_darea(N("Finish"), 'welcome'), - 1, Gtk2::WrappedLabel->new("\n\n" . N("Your upload was successful!") . "\n\n" . N("From now you will receive on security and updates \nannouncements thanks to Mandrakeonline.") . "\n\n" . N("Mandrakeonline offers you the ability to automate the updates.\nA program will run regulary in your system waiting for new updates\n")), - 0, gtkadd(Gtk2::Frame->new(N("automated Upgrades")), - gtkpack_(Gtk2::VBox->new(0, 3), - 0, gtkpack_($o->{vbox_auto} = Gtk2::VBox->new(0, 3), - 0, create_packtable({ homogeneous => 1, col_spacings => 5, row_spacings => 5 }, - [ N("Country:"), $o->{country} = Gtk2::OptionMenu->new ], - [" ", " "], - )) - )))); +$::Wizard_title = N("Mandrakeonline"); -init(1); +my %choices = ( + account => N("I already have an account"), + noaccount => N("I want to subscribe") + ); + +my $choice = $choices{account}; -# Filling country list: -my %countries = map { lang::c2name($_) => $_ } lang::list_countries(); -$o->{country}->set_popdown_strings(sort(keys %countries)); -$o->{country}->set_text(lang::c2name(lang::read('', $>)->{country})); +my ($wiz, $login, $nlogin, $password, $npassword, $boxname, $cfmpassword, $email, $is_success, $key, $r, $createaccount, $sendconfres, $country); -$o->{mw}{rwindow}->show_all; +GetOptions('login=s' => \$login, 'pass=s' => \$password, 'box=s' => \$boxname, 'country:s' => \$country); -Gtk2->main; -ugtk2->exit(0); +my %countries = map { lang::c2name($_) => $_ } lang::list_countries(); +$country = lang::c2name(lang::read('', $>)->{country}); -sub subs_online() { - my $explink = 'http://www.mandrakeexpert.com/online3_CreateAccount.php'; - my $login = $o->{clogin}->get_text; my $despwd = $o->{cpasswd}->get_text; my $despwdcfm = $o->{cconfirm}->get_text; - my $cmail = $o->{cmail}->get_text; - $::error = 0; - check_errors($login, $despwd, $despwdcfm, $o->{cmail}); - # print "Error = $::error"; - if (!$::error) { - my $url = $explink . '?desuserid=' . $login . '&despwd=' . $despwd . '&user_email=' . $cmail; - #print "LOGIN = $login\nPASSWD = $despwd\nMAIL= $cmail\nURL=$url\n"; - my $ret = mdkonline::subscribe_online($url); - if ($ret eq 'OK') { $o->{nb}->next_page } else { raiseError($o->{mw}{window}, N("Error"), $ret) }; - } -} -sub check_errors { - my ($login, $despwd, $despwdcfm, $cmail) = @_; - $login or raiseError($o->{mw}{window}, N("Error"), N("Please provide a login")); - if (!$::error && $despwd ne $despwdcfm) { - raiseError($o->{mw}{window}, N("Error"), N("The passwords do not match\n Please try again\n")) - } elsif (!$::error && check_valid_email($cmail) != 1) { - raiseError($o->{mw}{window}, N("Error"), N("Not a valid mail address!\n")) - } -} -sub set_entry_with_conf() { +sub read_conf() { my $wideconf = '/etc/sysconfig/mdkonline'; my %t = getVarsFromSh($wideconf); my $host = chomp_(`hostname`); $t{MACHINE} ||= $1 if $host =~ /(\w+)(.*)/; - foreach (qw(login machine)) { $o->{$_}->get_text or $o->{$_}->set_text($t{uc($_)}) } -} -sub send_conf_online() { - my ($login, $passwd, $boxname) = get_names(); - my $w = wait_msg(N("Reading configuration\n")); - my $link = 'https://www.mandrakeonline.net/wizard.php'; - mdkonline::report_config("$confdir/$login.$passwd.$boxname.online.log"); - my $tag = { submit => "upload_wizard", wizard => ["$confdir/$login.$passwd.$boxname.online.log.bz2.uue"] }; - remove_wait_msg($w); - my $ww = wait_msg(N("Sending configuration...")); - my ($res, $key) = mdkonline::send_config($link, $tag); - my $pass = $o->{passwd}->get_text; - mdkonline::hw_upload($login, $pass, $boxname); - remove_wait_msg($ww); - if ($res eq 'TRUE' && $key) { - $o->{currentkey} = $key; - $o->{nb}->next_page; $o->{Next}->set_label(N("Finish")); $o->{Prev}->hide - } else { - raiseError($o->{mw}{window}, N("Connection problem"), N("Problem occurs when uploading files, please try again")); - } -} -sub set_conf() { - my ($login, $passwd, $boxname) = get_names(); - my $country = lc($countries{$o->{country}->entry->get_text}); - my $key = $o->{currentkey}; - mdkonline::automated_upgrades($conffile, $login, $passwd, $boxname, $key, $country, 'TRUE'); - mdkonline::write_wide_conf($login, $boxname, $country); -} -sub init { - my $i = shift; - $o->{Prev}->set_sensitive(0); - $o->{Next}->grab_focus; - $i and first_settings(); + $login = $t{LOGIN}; $boxname = $t{MACHINE} } -sub first_settings() { - $o->{vbox_account}->set_sensitive(0); +sub check_login { + my ($log, $pass, $box) = @_; + my ($res, $resp); + my $pp = md5_hex($pass); + $log && $pass && $box or return 0; + my $clink = $expert_link . '/firsttimewizard/validusercheck.php' . '?u=' . $log . '&p=' . $pp; + $resp = mdkonline::get_from_URL($clink, "MdkOnline_tuiAgent/"); + $resp->is_success and $res = $resp->content =~ /TRUE/ ? 1 : 0; + $res } -sub final() { - $o->{Prev}->hide; $o->{SkipWiz}->hide; - $o->{Next}->set_label(N("Finish")) +sub send_conf { + my ($log, $pass, $box) = @_; + my $uplink = $online_link . '/wizard.php'; + my $pp = md5_hex($pass); + my $w = $in->wait_message(N("Please wait"), N("Reading configuration\n")); + mdkonline::report_config("$confdir/$log.$pp.$box.online.log"); + my $tag = { submit => "upload_wizard", wizard => ["$confdir/$log.$pp.$box.online.log.bz2.uue"] }; + undef $w; + my $ww = $in->wait_message(N("Please wait"), N("Sending configuration...")); + ($sendconfres, $key) = mdkonline::send_config($uplink, $tag); + mdkonline::hw_upload($log, $pass, $box); + undef $ww; + ($sendconfres, $key) } -sub get_names() { - my ($login, $passwd, $machine); - $login = $o->{login}->get_text; - $passwd = md5_hex($o->{passwd}->get_text); - $machine = $o->{machine}->get_text; - ($login, $passwd, $machine) +sub create_new_account { + my ($log, $pass, $mail) = @_; + my $url = $expert_link . '/online3_CreateAccount.php' . '?desuserid=' . $log . '&despwd=' . $pass . '&user_email=' . $mail; + my $ca = mdkonline::subscribe_online($url); + $ca } -sub main_quit() { - # remove local files - my ($login, $passwd, $boxname) = get_names(); - if ($login && $passwd && $boxname) { - -f "$confdir/$login.$passwd.$boxname.online.log.bz2.uue" and unlink("$confdir/$login.$passwd.$boxname.online.log.bz2.uue"); - -f "$confdir/$login.$passwd.$boxname.online.log.bz2" and unlink("$confdir/$login.$passwd.$boxname.online.log.bz2"); - } - # quit - print N("Quitting Wizard\n"); - Gtk2->main_quit; -} -sub is_alphanum { - my ($x) = @_; - my $_is_num = sub { $x =~ /^[[:alnum:]]+$/ ? 1 : 0 } -} -sub check_passwd() { - my $link = 'http://www.mandrakeexpert.com/firsttimewizard/validusercheck.php'; - my $result; - my $login = $o->{login}->get_text; my $passwd = md5_hex($o->{passwd}->get_text); my $boxname = $o->{machine}->get_text; - $boxname = is_alphanum($boxname); - if ($login && $passwd && $boxname && $login !~ /\s+/ && $passwd !~ /\s+/) { - my $w = wait_msg("Connecting ...\n"); - $link .= '?u=' . $login . '&p=' . $passwd; - my $response = mdkonline::get_from_URL($link, "MdkOnlineAgent/"); - remove_wait_msg($w); - # Check the outcome of the response - if ($response->is_success) { - $result = $response->content =~ /TRUE/ ? 0 : -1; - } else { - # pb with the connection ? stay on page 2 - raiseError($o->{mw}{window}, N("Connection problem"), N("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) { - $o->{nb}->next_page; - } else { - # if incorrect, clear passwd and stay on page 2 - raiseError($o->{mw}{window}, N("Wrong password"), N("Your login or password was wrong.\n Either you'll have to type it again, or you'll need to create an account on Mandrakeonline.\n In the latter case, go back to the first step to connect to Mandrakeonline.\n Be aware that you must also provide a Machine name \n (only alphabetical characters are admitted)")); - $o->{passwd}->set_text(""); - } -} -sub wait_msg { - my ($msg, %options) = @_; - my $mainw = ugtk2->new('mdkonline', grab => 1, if_(exists $options{transient}, transient => $options{transient})); - $mainw->{rwindow}->set_position($options{transient} ? 'center_on_parent' : 'center_always') if !$::isEmbedded; - my $label = ref($msg) =~ /^Gtk/ ? $msg : Gtk2::Label->new($msg); - gtkadd($mainw->{window}, gtkpack__(gtkadd(Gtk2::VBox->new(0, 5), $label, if_(exists $options{widgets}, @{$options{widgets}})))); - $label->signal_connect(expose_event => sub { $mainw->{displayed} = 1; 0 }); - $mainw->sync until $mainw->{displayed}; - gtkset_mousecursor_wait($mainw->{rwindow}->window); - $mainw->flush; - $mainw; +$wiz = { + name => N("Mandrakeonline"), + pages => { + welcome => { + name => 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, + next => '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 Mandrakeonline login, password and machine name:"), + pre => sub { + read_conf(); + }, + data => sub { + [ + { label => N("Login:"), val => \$login }, + { label => N("Password:"), val => \$password, hidden => 1 }, + { label => N("Machine name:"), val => \$boxname }, + ], + }, + post => sub { + my $_wait = $in->wait_message(N("Please wait"), N("Connecting to Mandrakeonline website...")); + $is_success = check_login($login, $password, $boxname); undef($_wait); + "authenticate" + }, + }, + authenticate => { + name => sub { + if ($is_success) { + N("In order to benefit from Mandrakeonline services,\nwe are about to upload your configuration.\n\nThe Wizard will now send the following information to Mandrakesoft:\n1) the list of packages you have installed on your system,\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.mandrakeexpert.com.") + } else { + N("Connection problem") . " " . N("or") . " " . N("wrong password:") . "\n" . N("Your login or password was wrong.\n Either you'll have to type it again, or you'll need to create an account on Mandrakeonline.\n In the latter case, go back to the first step to connect to Mandrakeonline.\n Be aware that you must also provide a Machine name \n (only alphabetical characters are admitted)") + } + }, + no_back => $is_success ? 1 : 0, + post => sub { + if ($is_success) { + ($sendconfres, $key) = send_conf($login, $password, $boxname); + "upload" + } else { "choices" } + } + }, + noaccount => { + name => N("Create a Mandrakeonline Account"), + data => sub { + [ + { label => N("Login:"), val => \$nlogin }, + { label => N("Password:"), val => \$npassword, hidden => 1 }, + { label => N("Confirm Password:"), val => \$cfmpassword, hidden => 1 }, + { label => N("Mail contact:"), val => \$email }, + ] + }, + post => sub { + $createaccount = $npassword ne $cfmpassword ? N("The passwords do not match\n Please try again\n") : $nlogin eq '' ? N("Please provide a login") : mdkonline::check_valid_email($email) == 0 ? N("Not a valid mail address!\n") : create_new_account($nlogin, $npassword, $email); + "createaccount" + } + }, + createaccount => { + name => sub { + $createaccount eq 'OK' ? "\n\n" . N("Mandrakeonline Account successfully created.\nPlease click \"Next\" to authenticate and upload your configuration\n") : $createaccount; + }, + post => sub { + $createaccount eq 'OK' ? "account" : "noaccount" + } + }, + upload => { + name => sub { + if ($sendconfres eq 'TRUE' && $key) { + "\n\n" . N("Your upload was successful!") . "\n\n" . N("From now you will receive on security and updates \nannouncements thanks to Mandrakeonline.") . "\n\n" . N("Mandrakeonline offers you the ability to automate the updates.\nA program will run regulary in your system waiting for new updates\n"); + } else { + N("Connection problem") . N("Problem occurs when uploading files, please try again") + } + }, + data => sub { + if ($sendconfres eq 'TRUE' && $key) { + [ + { label => N("Country"), val => \$country, type => "combo", list => [ sort keys %countries ], not_edit => 0 } + ] + } + }, + post => sub { + mdkonline::automated_upgrades($conffile, $login, md5_hex($password), $boxname, $key, $country, 'TRUE'); + mdkonline::write_wide_conf($login, $boxname, $country); + "end" + }, + }, + end => { + name => sub { + N("Congratulations") . "\n\n" . N("Your Mandrakeonline account has been successfully configured\n") + }, + end => 1, + no_back => 1, + next => 0, + } + } + }; + +if ($login && $password && $boxname) { + $is_success = check_login($login, $password, $boxname); + if ($is_success) { + ($sendconfres, $key) = send_conf($login, $password, $boxname); + if ($sendconfres eq 'TRUE' && $key) { + mdkonline::automated_upgrades($conffile, $login, md5_hex($password), $boxname, $key, $country, 'TRUE'); + mdkonline::write_wide_conf($login, $boxname, $country); + output($logfile, N("Configuration uploaded successfully")) + } else { output($logfile, N("Problem uploading configuration")) } + } else { output($logfile, N("Cannot connect to mandrakeonline website: wrong login/password or router/firewall bad settings")) } +} else { + wizards->new->safe_process($wiz, $in); } -sub remove_wait_msg { $_[0]->destroy } - - - |