summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2004-07-09 10:33:56 +0000
committerDaouda Lo <daouda@mandriva.com>2004-07-09 10:33:56 +0000
commit9318ebc5a59e237628457e379d7be3ece5f8d704 (patch)
tree29084b387ed6d3dcf2091e02b95d493d9850d4b1
parent701cbc36ba5feee09e0578c21cdea2c7a0d68a89 (diff)
downloadmgaonline-9318ebc5a59e237628457e379d7be3ece5f8d704.tar
mgaonline-9318ebc5a59e237628457e379d7be3ece5f8d704.tar.gz
mgaonline-9318ebc5a59e237628457e379d7be3ece5f8d704.tar.bz2
mgaonline-9318ebc5a59e237628457e379d7be3ece5f8d704.tar.xz
mgaonline-9318ebc5a59e237628457e379d7be3ece5f8d704.zip
rewrite big chunks of code, added mdkonline.pm
-rw-r--r--Makefile8
-rwxr-xr-xmdkapplet15
-rwxr-xr-xmdkonline302
-rw-r--r--mdkonline.pm132
-rw-r--r--mdkonline.spec28
-rwxr-xr-xmdkupdate190
6 files changed, 292 insertions, 383 deletions
diff --git a/Makefile b/Makefile
index 1f1e0b6b..c4760627 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
PACKAGE = mdkonline
-VERSION:=$(shell rpm -q --qf %{VERSION} --specfile $(PACKAGE).spec)
-RELEASE:=$(shell rpm -q --qf %{RELEASE} --specfile $(PACKAGE).spec)
+VERSION:=$(shell rpm -q --qf '%{VERSION}\n' --specfile $(PACKAGE).spec|head -n 1)
+RELEASE:=$(shell rpm -q --qf '%{RELEASE}\n' --specfile $(PACKAGE).spec|head -n 1)
TAG := $(shell echo "V$(VERSION)_$(RELEASE)" | tr -- '-.' '__')
NAME = mdkonline
@@ -14,6 +14,7 @@ ICONSDIR = $(DATADIR)/icons
PIXDIR = $(DATADIR)/$(NAME)
SBINDIR = $(PREFIX)/usr/sbin
BINDIR = $(PREFIX)/usr/bin
+FBLIBDIR = $(PREFIX)/usr/lib/libDrakX/drakfirsttime
SYSCONFDIR = $(PREFIX)/etc/sysconfig
SBINREL = ../sbin
@@ -32,7 +33,7 @@ clean:
install: all
$(MAKE) -C po $@
- install -d $(PREFIX)/usr/{sbin,bin,share/{$(NAME)/pixmaps,autostart,icons/{mini,large}}}
+ install -d $(PREFIX)/usr/{sbin,bin,share/{$(NAME)/pixmaps,autostart,icons/{mini,large}},lib/libDrakX/drakfirsttime}
install -m755 $(NAME) $(SBINDIR)
install -m755 $(MDKUPDATE) $(SBINDIR)
install -m755 $(MDKAPPLET) $(BINDIR)
@@ -41,6 +42,7 @@ install: all
install -m644 icons/$(NAME)48.png $(ICONSDIR)/large/$(NAME).png
install -m644 pixmaps/*.png $(PIXDIR)/pixmaps
install -m644 mdkapplet.desktop $(PREFIX)/usr/share/autostart/
+ install -m644 mdkonline.pm $(FBLIBDIR)
for d in $(SUBDIRS); do ( cd $$d ; make $@ ) ; done
# rules to build a test rpm
diff --git a/mdkapplet b/mdkapplet
index 7ebd8c2c..fa94a977 100755
--- a/mdkapplet
+++ b/mdkapplet
@@ -21,10 +21,13 @@
################################################################################
use strict;
-use lib qw(/usr/lib/libDrakX);
+use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use common;
+use mdkonline;
+
use Digest::MD5;
+
BEGIN { unshift @::textdomains, 'mdkonline' }
use Gtk2::TrayIcon;
@@ -208,19 +211,11 @@ sub silentCheck {
my $link = "http://www.mandrakeonline.net/online3_RemoteAction.php" . '?action=UpdateList';
my %h = getVarsFromSh($conffile);
my $u;
- require LWP::UserAgent;
- require HTTP::Request::Common;
- require HTTP::Request;
logIt(N("Computing new updates...\n"));
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkAppletAgent/0.1" . $ua->agent);
- $ua->env_proxy;
- # my $request = HTTP::Request->new(GET => $link . '&log=' . "ayomigration" . '&host=' . "online");
- my $request = HTTP::Request->new(GET => $link . '&log=' . $h{LOGIN} . '&host=' . $h{MACHINE});
my $lnk = $link . '&log=' . $h{LOGIN} . '&host=' . $h{MACHINE};
logIt(N("Connecting to") . " $lnk ...\n");
gtkflush(); go2State('busy'); gtkflush();
- my $response = $ua->request($request);
+ my $response = mdkonline::get_from_URL($link, 'MdkAppletAgent/0.1');
my $ct = $response->content;
# print "\nCONTENTS = $ct\n";
# logIt(N("Response from MandrakeOnline server\n") . "$ct");
diff --git a/mdkonline b/mdkonline
index e95dc983..d86a3c21 100755
--- a/mdkonline
+++ b/mdkonline
@@ -22,30 +22,25 @@
################################################################################
use strict;
-use lib qw(/usr/lib/libDrakX);
+use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use common;
use standalone;
use interactive;
use lang;
+use ugtk2 qw(:all);
+
+use mdkonline;
+use comdialog;
+use data;
BEGIN { unshift @::textdomains, 'mdkonline', 'drakfw' }
use Config;
#use LWP::Debug qw(+);
-use LWP::UserAgent;
-use Net::HTTPS;
-use HTTP::Request::Common;
-use HTTP::Request;
use Digest::MD5 qw(md5 md5_hex md5_base64);
-use MIME::Base64 qw(encode_base64);
-use Sys::Hostname;
-use ugtk2 qw(:all);
-
-use lib qw(/usr/lib/libDrakX/drakfirsttime);
-use comdialog;
-use data;
my $confdir = '/root/.MdkOnline';
+my $conffile = "$confdir/mdkupdate";
add_icon_path("/usr/share/drakfirsttime/pixmaps/");
@@ -53,15 +48,11 @@ my $in = 'interactive'->vnew('su', 'default');
my $VERSION = '1.0';
my ($create_account, $auto_update) = (0, 1);
-my $linkAccount = "http://www.mandrakeexpert.com/index2.php";
-my $wideconf = '/etc/sysconfig/mdkonline';
-
my ($o, $p);
#for compatibilities
mkdir_p($confdir) if !-d $confdir;
-mvfiles("/root/.mdkupdate", "$confdir/mdkupdate");
-#mvfiles("/root/.mdkonline", "$confdir/mdkonline");
+mdkonline::mv_files("/root/.mdkupdate", "$conffile");
$o->{mw} = ugtk2->new("MandrakeOnline" . " " . $VERSION, center => 1);
gtkset_size_request($o->{mw}{window}, 580, 470);
@@ -69,42 +60,35 @@ $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) { subsOnline() } else { $o->{nb}->next_page} },
- 1 => sub { $o->{nb}->next_page(); setEntryWithConf() },
- 2 => sub { testPasswd() },
- 3 => sub { log::l("[mdkonline] Sending configuration to remote server"); sendConfig() },
- 4 => sub { log::l("[mdkonline] Writing local configuration dir"); setConf() }
+ 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->{bottomHbox} = create_okcancel(my $w =
- {
- cancel_clicked => \&mainQuit,
- ok_clicked => sub {
- $p = $o->{nb}->get_current_page;
- $stage{$p}->();
- $p <= 0 and $o->{Prev}->set_sensitive(1);
- $p == 4 and mainQuit()
- },
- },
- undef, undef, '',
- [ "gtk-go-back", sub {
- $p = $o->{nb}->get_current_page;
- $o->{nb}->prev_page();
- $p <= 1 and init(0)
- },
- 0, 1,
- ],
- );
-$w->{cancel}->set_label(N("Skip Wizard"));
-$o->{Next} = $w->{ok};
-$o->{SkipWiz} = $w->{cancel};
-
-$w->{ok}->set_label("gtk-go-forward");
-$w->{ok}->set_use_stock(1);
-
-$o->{Prev} = $w->{buttons}{'gtk-go-back'};
-$o->{Prev}->set_use_stock(1);
-
+$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', 'gtk-go-forward', 'stock'], ['SkipWiz', N("Skip Wizard")], ['Prev', 'gtk-go-back', 'stock']) {
+ $o->{$l->[0]} = $l->[2] ? Gtk2::Button->new_from_stock($l->[1]) : 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},
@@ -180,35 +164,21 @@ $o->{mw}{rwindow}->show_all;
Gtk2->main;
ugtk2->exit(0);
-sub subsOnline {
+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 $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;
- checkErrors($login, $despwd, $despwdcfm, $o->{cmail});
+ 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 = requestURL($url);
- my $result = {
- 10 => sub { !$::error and $o->{nb}->next_page},
- 11 => sub { raiseError($o->{mw}->{window},N("Creation"),N("Login and password should be less than 12 characters\n")) },
- 12 => sub { raiseError($o->{mw}->{window},N("Special characters"),N("Special characters are not allowed\n")) },
- 13 => sub { raiseError($o->{mw}->{window},N("Empty fields"),N("Please fill in all fields\n")) },
- 14 => sub { raiseError($o->{mw}->{window},N("Email"),N("Email not valid\n")) },
- 15 => sub { raiseError($o->{mw}->{window},N("Change account"),N("Account already exist\n")) },
- };
- if ($ret->is_success) {
- my $content = $ret->content;
-# print "CODE_RETOUR = $content\n";
- if ($content =~ m/(\d+)/) { my $code = sprintf("%d",$1); eval { $result->{$code}->() } }
- } else { raiseError($o->{mw}->{window}, N("Server Problem"), N("Problem connecting to server \n")) }
+ #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}, $ret) };
}
}
-sub checkErrors {
+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) {
@@ -217,97 +187,64 @@ sub checkErrors {
raiseError($o->{mw}->{window},N("Error"), N("Not a valid mail address!\n"))
}
}
-sub setEntryWithConf {
+sub set_entry_with_conf {
+ my $wideconf = '/etc/sysconfig/mdkonline';
my %t = getVarsFromSh($wideconf);
my $host = chomp_(`hostname`) ; $host =~ /(\w+)(.*)/;
$t{MACHINE} ||= $1;
foreach (qw(login machine)) { $o->{$_}->get_text or $o->{$_}->set_text($t{uc($_)}) }
}
-sub sendConfig {
- # When we arrive here, we're sure the login/passwd is correct
- # print STDERR "Sending config\n";
- my $result = -1;
- my ($login, $boxname, $passwd);
- $login = $o->{login}->get_text; $boxname = $o->{machine}->get_text; my $passwd = md5_hex($o->{passwd}->get_text);
- reportConfig("$confdir/$login.$passwd.$boxname.online.log");
- `/usr/bin/bzip2 \\\-9 \\\-f $confdir/$login.$passwd.$boxname.online.log`;
- # Turn the binary file into a uuencoded ascii file
- open (FILE, "$confdir/$login.$passwd.$boxname.online.log.bz2") or die "$!";
- my ($chunk, $buffer);
- while (read(FILE, $chunk, 60*57)) {
- $buffer .= $chunk;
- }
- close (FILE);
- open (FILEOUT, "> $confdir/$login.$passwd.$boxname.online.log.bz2.uue") or die "$!";
- print FILEOUT encode_base64($buffer);
- close (FILEOUT);
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkOnlineAgent/0.15" . $ua->agent);
- $ua->env_proxy;
- my $w = wait_msg(N("Sending configuration..."));
- my $response = $ua->request(POST 'http://www.mandrakeonline.net/wizard.php',
-
- Content_Type => 'form-data',
- Content => [submit => "upload_wizard",
- wizard => ["$confdir/$login.$passwd.$boxname.online.log.bz2.uue"]
- ]);
- #printf("*********** Reponse is %s ***********\n", $response->as_string);
- # Check the outcome of the response
- #print "REPONSE: ".$response->content."\n";
+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);
- if ($response->is_success || $::testing) {
- $result = ($response->content =~ /^TRUE(.*)/) ? 0 : -1;
- #printf("Send Config :\nNEWKEY=%s\nRESPONSE=%s", $1, $response->content);
- $o->{currentkey} = $1;
- } else {
- # pb with the connection ?
- $result = -1;
- }
- # if information were sent correctly (exit code: 0 from scp script), go to page 5
- if (! $result || $::testing) {
- # go to last page
+ my $ww = wait_msg(N("Sending configuration..."));
+ my ($res, $key) = mdkonline::send_config($link, $tag);
+ 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 {
- # if incorrect, go/stay on page 4 to retry sending data
- # pb with the connection ?
- raiseError($o->{mw}->{window}, N("Connection problem"), N("MandrakeOnline could not be contacted, please try again at a later time"));
+ raiseError($o->{mw}->{window}, N("Connection problem"), N("Problem occurs when uploading files, please try again"));
}
}
-sub setConf {
- my $login = $o->{login}->get_text;
- my $passwd = md5_hex($o->{passwd}->get_text);
- my $boxname = $o->{machine}->get_text; my $country = lc($countries{$o->{country}->entry->get_text});
+sub set_conf() {
+ my ($login, $passwd, $boxname) = get_names();
+ my $country = lc($countries{$o->{country}->entry->get_text});
my $key = $o->{currentkey}; my $auto = 'FALSE';
if ($auto_update) { $auto = 'TRUE' };
- automatedUpgrades($login, $passwd, $boxname, $key, $country, $auto);
- writeWideConf($login, $boxname, $country);
+ mdkonline::automated_upgrades($conffile, $login, $passwd, $boxname, $key, $country, $auto);
+ mdkonline::write_wide_conf($login, $boxname, $country);
}
sub init {
my $i = shift;
$o->{Prev}->set_sensitive(0);
$o->{Next}->grab_focus;
- $i and FirstSettings();
+ $i and first_settings();
}
-sub FirstSettings {
+sub first_settings() {
foreach my $l (qw(vbox_account vbox_auto)) {
$o->{$l}->set_sensitive(0);
}
}
-sub final {
+sub final() {
$o->{Prev}->hide; $o->{SkipWiz}->hide;
$o->{Next}->set_label(N("Finish"))
}
-sub getNames {
- my ($login, $passwd, $machine) = @_;
+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 mainQuit {
+sub main_quit() {
# remove local files
- my ($login, $passwd, $boxname) = getNames();
- if ($o->{login}->get_text && $o->{passwd}->get_text) {
+ my ($login, $passwd, $boxname) = get_names();
+ if ($login && $passwd && $boxname) {
-f "$confdir/$login.$passwd.$boxname.online.log.bz2.uue" && unlink ("$confdir/$login.$passwd.$boxname.online.log.bz2.uue");
-f "$confdir/$login.$passwd.$boxname.online.log.bz2" && unlink ("$confdir/$login.$passwd.$boxname.online.log.bz2");
}
@@ -315,34 +252,23 @@ sub mainQuit {
print N("Quitting Wizard\n");
Gtk2->main_quit;
}
-sub isalphanum {
- my ($str) = @_;
- if ($str =~ /^[[:alnum:]]+$/) {
- return 1;
- } else {
- return 0;
- }
+sub is_alphanum {
+ my $is_num = sub { $_[0] =~ /^[[:alnum:]]+$/ ? 1 : 0 }
}
-sub testPasswd () {
- my $result = -1;
- my $login = $o->{login}->get_text;
- my $passwd = $o->{passwd}->get_text;
- my $boxname = $o->{machine}->get_text;
- my $test = isalphanum($boxname);
- #print ("isalnum : $test");
- if ($login && $passwd && $test && $login !~ /\s+/ && $passwd !~ /\s+/) {
-# NEW METHOD (http)
+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+/) {
+ # NEW METHOD (http)
# first, MD5ify the password
my $w = wait_msg(("Connecting ...\n"));
- $passwd = md5_hex($passwd); # or md5 () or md5_base64 ()
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkOnlineAgent/0.15" . $ua->agent);
- $ua->env_proxy;
- my $request = HTTP::Request->new(GET => 'http://www.mandrakeexpert.com/firsttimewizard/validusercheck.php?u=' . $login . '&p=' . $passwd);
- my $response = $ua->request($request);
+ $link .= '?u=' . $login . '&p=' . $passwd;
+ my $response = mdkonline::get_from_URL($link);
remove_wait_msg($w);
# Check the outcome of the response
- if ($response->is_success || $::testing) {
+ if ($response->is_success) {
$result = ($response->content =~ /TRUE/) ? 0 : -1;
} else {
# pb with the connection ? stay on page 2
@@ -354,7 +280,7 @@ sub testPasswd () {
}
# if correct, go to page 4
- if (! $result || $::testing) {
+ if (! $result) {
$o->{nb}->next_page();
} else {
# if incorrect, clear passwd and stay on page 2
@@ -362,34 +288,6 @@ sub testPasswd () {
$o->{passwd}->set_text("");
}
}
-sub reportConfig {
- my ($file) = @_;
- #touch($file);
- my $w = wait_msg(N("Reading configuration\n"));
- sub header { "
-********************************************************************************
-* $_[0]
-********************************************************************************";
- }
-open (FILE,"> $file") || die "Couldn't open $file : $!";
-join '', map { chomp; print FILE "$_\n" }
- header("scsi"), cat_("/proc/scsi/scsi"),
- header("lsmod"), cat_("/proc/modules"),
- header("cmdline"), cat_("/proc/cmdline"),
- header("pcmcia: stab"), cat_("/var/lib/pcmcia/stab") || cat_("/var/run/stab"),
- header("usb"), cat_("/proc/bus/usb/devices"),
- header("partitions"), cat_("/proc/partitions"),
- header("cpuinfo"), cat_("/proc/cpuinfo"),
- header("install.log"), cat_("/root/drakx/install.log"),
- header("fstab"), cat_("/etc/fstab"),
- header("lilo.conf"), cat_("/etc/lilo.conf"),
- header("menu.lst"), cat_("/boot/grub/menu.lst"),
- header("/etc/modules.conf"), cat_("/etc/modules.conf"),
- header("rpm -qa"), join ('', sort `rpm -qa`),
- header("mandrake version"), cat_('/etc/mandrake-release');
- close(FILE);
- remove_wait_msg($w);
-}
sub wait_msg {
my ($msg, %options) = @_;
my $mainw = ugtk2->new('mdkonline', grab => 1, if_(exists $options{transient}, transient => $options{transient}));
@@ -403,38 +301,6 @@ sub wait_msg {
$mainw;
}
sub remove_wait_msg { $_[0]->destroy }
-sub mvfiles {
- my ($source, $dest) = @_;
- -e $source and system("mv","$source","$dest");
-}
-sub automatedUpgrades {
- my ($login, $passwd, $boxname, $key, $country, $auto) = @_;
- my ($r) = cat_('/etc/mandrake-release') =~ /release\s(\S+)/;
- output "$confdir/mdkupdate",
- qq(# automatically generated file. Please don't edit
-LOGIN=$login
-PASS=$passwd
-MACHINE=$boxname
-VER=$r
-CURRENTKEY=$key
-COUNTRY=$country
-AUTO=$auto
-);
- output_p "/etc/cron.daily/mdkupdate",
- qq(#!/bin/bash
-if [ -f $confdir/mdkupdate ]; then /usr/sbin/mdkupdate --auto; fi
-);
-chmod 0755, "/etc/cron.daily/mdkupdate";
-}
-sub writeWideConf {
- my ($login, $boxname, $country) = @_;
- my $d = localtime();
- $d =~ s/\s+/_/g;
- output_with_perm $wideconf, 644,
- qq(LOGIN=$login
-MACHINE=$boxname
-COUNTRY=$country
-LASTCHECK=$d
-);
-}
+
+
diff --git a/mdkonline.pm b/mdkonline.pm
new file mode 100644
index 00000000..2be4c45b
--- /dev/null
+++ b/mdkonline.pm
@@ -0,0 +1,132 @@
+package mdkonline;
+
+use strict;
+use MIME::Base64 qw(encode_base64);
+
+use lib qw(/usr/lib/libDrakX);
+use c;
+use common;
+
+use LWP::UserAgent;
+use Net::HTTPS;
+use HTTP::Request::Common;
+use HTTP::Request;
+
+sub get_release() {
+ my ($release) = cat_('/etc/mandrake-release') =~ /release\s+(\S+)/;
+ ($release)
+}
+
+sub get_from_URL {
+ my ($link, $agent_name) = @_;
+ my $ua = LWP::UserAgent->new;
+ $ua->agent("$agent_name" . $ua->agent);
+ $ua->env_proxy;
+ my $request = HTTP::Request->new(GET => $link);
+ my $response = $ua->request($request);
+ $response
+}
+
+sub subscribe_online {
+ my ($full_link) = shift;
+ my $ret = get_from_URL($full_link, "MdkOnlineAgent");
+ my $str;
+ my $result = {
+ 10 => 'OK',
+ 11 => N("Login and password should be less than 12 characters\n"),
+ 12 => N("Special characters are not allowed\n"),
+ 13 => N("Please fill in all fields\n"),
+ 14 => N("Email not valid\n"),
+ 15 => N("Account already exist\n"),
+ };
+ if ($ret->is_success) {
+ my $content = $ret->content;
+# print "CODE_RETOUR = $content\n";
+ if ($content =~ m/(\d+)/) { my $code = sprintf("%d",$1); $str = $result->{$code} }
+ } else { $str = N("Problem connecting to server \n") }
+ $str
+}
+
+sub report_config {
+ my $file = shift;
+sub header { "
+********************************************************************************
+* $_[0]
+********************************************************************************";
+}
+open (my $FILE,"> $file") || die "Couldn't open $file : $!";
+map { chomp; print $FILE "$_\n" }
+ header("partitions"), cat_("/proc/partitions"),
+ header("cpuinfo"), cat_("/proc/cpuinfo"),
+ header("fstab"), cat_("/etc/fstab"),
+ header("/etc/modules.conf"), cat_("/etc/modules.conf"),
+ header("rpm -qa"), join ('', sort `rpm -qa`),
+ header("mandrake version"), cat_('/etc/mandrake-release');
+close($FILE);
+`/usr/bin/bzip2 \\\-f $file`;
+open (my $F, "$file" . ".bz2") or die "Cannot open file : $!";
+my ($chunk, $buffer);
+while (read($F, $chunk, 60*57)) {
+ $buffer .= $chunk;
+}
+close ($F);
+open (my $OUT, "> $file" . ".bz2.uue") or die "Cannot open file : $!";
+print $OUT encode_base64($buffer);
+close ($OUT);
+}
+
+sub send_config {
+ my ($link, $content) = @_;
+ my ($res, $key);
+ my $ua = LWP::UserAgent->new;
+ $ua->agent("MdkOnlineAgent/0.15" . $ua->agent);
+ $ua->env_proxy;
+ my $response = $ua->request(POST $link,
+ Content_Type => 'form-data',
+ Content => [ %$content ]);
+ if ($response->is_success && $response->content =~ /^TRUE(.*)/) {
+ ($res, $key) = ('TRUE', $1);
+ }
+ ($res, $key)
+}
+
+sub mv_files {
+ my ($source, $dest) = @_;
+ -e $source and system("mv","$source","$dest");
+}
+
+sub automated_upgrades {
+ my ($conffile, $login, $passwd, $boxname, $key, $country, $auto) = @_;
+ my ($r) = get_release();
+ output "$conffile",
+ qq(# automatically generated file. Please don't edit
+LOGIN=$login
+PASS=$passwd
+MACHINE=$boxname
+VER=$r
+CURRENTKEY=$key
+COUNTRY=$country
+AUTO=$auto
+);
+ output_p "/etc/cron.daily/mdkupdate",
+ qq(#!/bin/bash
+if [ -f $conffile ]; then /usr/sbin/mdkupdate --auto; fi
+);
+
+ chmod 0755, "/etc/cron.daily/mdkupdate";
+}
+
+sub write_wide_conf {
+ my ($login, $boxname, $country) = @_;
+ my $wideconf = '/etc/sysconfig/mdkonline';
+ my $d = localtime();
+ $d =~ s/\s+/_/g;
+ output_with_perm $wideconf, 644,
+ qq(LOGIN=$login
+MACHINE=$boxname
+COUNTRY=$country
+LASTCHECK=$d
+);
+}
+
+1;
diff --git a/mdkonline.spec b/mdkonline.spec
index 41ebaa61..49ce0e0a 100644
--- a/mdkonline.spec
+++ b/mdkonline.spec
@@ -4,17 +4,23 @@
Summary: The MandrakeOnline Tool
Name: %{name}
Version: %{version}
-Release: 3mdk
+Release: 4mdk
Source0: %{name}-%{version}.tar.bz2
URL: http://www.mandrakeonline.net
Packager: Daouda Lo <daouda@mandrakesoft.com>
License: GPL
Group: System/Configuration/Other
-Requires: drakfirsttime >= 1.0-0.6mdk, perl-Crypt-SSLeay >= 0.51-2mdk, perl-Gtk2-TrayIcon >= 0.03-3mdk
+Requires: %{name}-backend >= 1.1-4mdk, drakfirsttime >= 1.0-0.6mdk, perl-Crypt-SSLeay >= 0.51-2mdk, perl-Gtk2-TrayIcon >= 0.03-3mdk
BuildRequires: gettext
BuildRoot: %{_tmppath}/%{name}-buildroot
BuildArch: noarch
+%package backend
+Summary: MandrakeOnline libraries and background tools
+Group: System/Configuration/Other
+Requires: drakxtools-newt
+Conflicts: %{name} < 1.1-3mdk
+
%description
The MandrakeOnline tool is designed for registered users
who want to upload their configuration (packages, hardware infos).
@@ -28,6 +34,9 @@ The package include :
* Mdkapplet which is a KDE/Gnome applet for security updates
notification and installation.
+%description backend
+This package contains the mdkonline library and backend tools.
+
%prep
%setup -q
@@ -63,6 +72,8 @@ EOF
%post
%{update_menus}
+%post backend
+
if [ -r /etc/cron.daily/mdkupdate ]; then
perl -p -i -e 's!/usr/bin/mdkupdate!/usr/sbin/mdkupdate!' /etc/cron.daily/mdkupdate
fi
@@ -73,10 +84,17 @@ fi
%clean
rm -rf $RPM_BUILD_ROOT
+%files backend
+%defattr(-,root,root)
+%{_sbindir}/mdkupdate
+%dir %{_libdir}/libDrakX/drakfirsttime
+%{_libdir}/libDrakX/drakfirsttime/*.pm
+
%files -f %{name}.lang
%defattr(-,root,root)
%doc COPYING ChangeLog
-%{_sbindir}/*
+%{_sbindir}/mdkonline
+%{_sbindir}/drakonline
%{_bindir}/*
%{_prefix}/X11R6/bin/*
%{_menudir}/%{name}
@@ -96,6 +114,10 @@ rm -rf $RPM_BUILD_ROOT
# get the source from our cvs repository (see
# http://www.linuxmandrake.com/en/cvs.php3)
%changelog
+* Thu Jul 8 2004 Daouda LO <daouda@mandrakesoft.com> 1.1-4mdk
+- added mdkonline backend package for derivative products
+ (MNF, Corporate ...)
+
* Tue Jun 8 2004 Daouda LO <daouda@mandrakesoft.com> 1.1-3mdk
o Tue Jun 8 2004 Daouda LO <daouda@mandrakesoft.com> 1.1-2.1.100mdk
- added misc architectures (ia64, amd64, x86_64, noarch, ppc64)
diff --git a/mdkupdate b/mdkupdate
index 1875814c..6c71847c 100755
--- a/mdkupdate
+++ b/mdkupdate
@@ -21,25 +21,20 @@
################################################################################
use POSIX;
-use Digest::MD5 qw(md5 md5_hex md5_base64);
-use HTTP::Request;
-use HTTP::Request::Common;
-use LWP::UserAgent;
-use Net::HTTPS; #for https connections
-use MIME::Base64 qw(encode_base64);
-use lib qw(/usr/lib/libDrakX);
+use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use common;
+use mdkonline;
+
BEGIN { unshift @::textdomains, 'mdkupdate' }
require_root_capability();
-my $logfile = "/var/log/mdkupdate.log";
my $confdir = '/root/.MdkOnline';
my $conffile = "$confdir/mdkupdate";
my $onlineUrl = "https://www.mandrakeonline.net/";
my %url;
-foreach (qw(online_dif online_update online3_RemoteAction)) {
+foreach (qw(online_dif online_update online3_RemoteAction wizard)) {
$url->{$_} = $onlineUrl . $_ . '.php'
}
my $rpms_rep = "/root/tmp/";
@@ -50,7 +45,7 @@ my $update = grep { /^-?-update$/ } @ARGV;
#for compatibilities
mkdir_p($confdir) if !-d $confdir;
--e '/root/.mdkupdate' and system("mv","/root/.mdkupdate", "$confdir/mdkupdate");
+-e '/root/.mdkupdate' and system("mv","/root/.mdkupdate", "$conffile");
my ($scheduled, $noscheduled);
@@ -77,21 +72,21 @@ my %o = getVarsFromSh($conffile);
if ($o{LOGIN} && $o{PASS} && $o{LOGIN} !~ /\s+/ && $o{PASS} !~ /\s+/) {
my $u;
my $MandrakeUpdateURL = $url->{online3_RemoteAction} . '?action=ScheduledRPM' . '&log=' . $o{LOGIN} . '&pass=' . $o{PASS} . '&host=' . $o{MACHINE} . '&key=' . $o{CURRENTKEY};
- my $resp = getFromURL($MandrakeUpdateURL);
+ my $resp = mdkonline::get_from_URL($MandrakeUpdateURL);
my $contents = $resp->content;
#print "CONTENTS = $contents \n";
if ($resp->is_success) {
if ($contents =~ /TRUE/) { $u = 10 } elsif ($contents =~ m/(\d+)/) { $u = sprintf("%d", $1) } else { $u = 83 } ;
my $action = {
10 => sub {
- my $c2h = splitContents($contents);
+ my $c2h = split_contents($contents);
#printf("\nCONTENTS = $contents \n torf = %s\n OLDKEY = %s = %s \n NEWKEY = %s \n FTP = %s\n", $c2h->{torf}, $c2h->{OLDKEY}, $o{CURRENTKEY}, $c2h->{NEWKEY}, $c2h->{FTP} );
- if ($c2h->{torf} eq "TRUE" && $c2h->{OLDKEY} && $c2h->{NEWKEY}) { updateConf($c2h->{OLDKEY}, $c2h->{NEWKEY}) }
+ if ($c2h->{torf} eq "TRUE" && $c2h->{OLDKEY} && $c2h->{NEWKEY}) { update_conf($c2h->{OLDKEY}, $c2h->{NEWKEY}) }
if ($c2h->{FTP}) {
# for debugging purpose
printf("FTP = %s\n", $c2h->{FTP});
#$c2h->{FTP} = 'ftp://ftp.lip6.fr/pub/linux/distributions/mandrake/updates';
- addMedia($c2h->{FTP})
+ add_media($c2h->{FTP})
}
$scheduled = join(',',@{$c2h->{sched}});
$noscheduled = join(',',@{$c2h->{nosched}}); $noscheduled =~ s/\.rpm//g;
@@ -99,16 +94,16 @@ if ($o{LOGIN} && $o{PASS} && $o{LOGIN} !~ /\s+/ && $o{PASS} !~ /\s+/) {
if ($opt eq '--applet') {
system "MandrakeUpdate", "--no-confirmation", "--media=mdkupdate", "--pkg-sel=$scheduled", "--pkg-nosel=$noscheduled";
} elsif ($opt eq '--auto') {
- $o{AUTO} eq 'TRUE' and autoInstallRpms($c2h->{sched});
+ $o{AUTO} eq 'TRUE' and auto_install_rpms($c2h->{sched});
}
rpm_qa("$confdir/rpm_qa_installed_after");
my %new = getVarsFromSh($conffile);
if (! -s "$confdir/mdkupdate.rpms" || $update) {
#- send configuration and get back key to use...
- $new{CURRENTKEY} = send_config($new{LOGIN},$new{PASS},$new{MACHINE});
- delete $new{OLDKEY};
- #- save back keys.
- setVarsInSh($conffile, \%new);
+ my $r;
+
+ ($r, $new{CURRENTKEY}) = send_conf_update($new{LOGIN},$new{PASS},$new{MACHINE});
+ if ($r eq 'TRUE') { delete $new{OLDKEY}; setVarsInSh($conffile, \%new) }
} else {
#- this can safely be ignored if new configuration is sent.
send_rpm_dif($new{LOGIN},$new{PASS},$new{MACHINE},$new{OLDKEY});
@@ -135,7 +130,7 @@ if ($o{LOGIN} && $o{PASS} && $o{LOGIN} !~ /\s+/ && $o{PASS} !~ /\s+/) {
} else {
$ret = -1;
}
-sub splitContents {
+sub split_contents {
my $cont = shift;
my ($elem, $s);
$s = [ split /\n/, $cont ];
@@ -146,102 +141,13 @@ sub splitContents {
}
$elem
}
-
-################################################################################
-# Taken from mdkonline to perform complete update of rpm list (by diff), it has
-# been decided to do exactly what mdkonline does the first time to update the db.
-################################################################################
-sub report_config {
- my ($file) = @_;
-sub header { "
-********************************************************************************
-* $_[0]
-********************************************************************************";
- }
-open (FILE,"> $file") || die "Couldn't open $file : $!";
-map { chomp; print FILE "$_\n" }
- header("scsi"), cat_("/proc/scsi/scsi"),
- header("lsmod"), cat_("/proc/modules"),
- header("cmdline"), cat_("/proc/cmdline"),
- header("pcmcia: stab"), cat_("$prefix/var/lib/pcmcia/stab") || cat_("$prefix/var/run/stab"),
- header("usb"), cat_("/proc/bus/usb/devices"),
- header("partitions"), cat_("/proc/partitions"),
- header("cpuinfo"), cat_("/proc/cpuinfo"),
- header("install.log"), cat_("$prefix/root/drakx/install.log"),
- header("fstab"), cat_("$prefix/etc/fstab"),
- header("lilo.conf"), cat_("$prefix/etc/lilo.conf"),
- header("menu.lst"), cat_("$prefix/boot/grub/menu.lst"),
- header("/etc/modules.conf"), cat_("$prefix/etc/modules.conf"),
- header("rpm -qa"), join ('', sort `rpm -qa`),
- header("mandrake version"), cat_('/etc/redhat-release');
-close(FILE);
-}
-sub getFromURL {
- my ($link) = @_;
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkUpdateAgent/$VERSION" . $ua->agent);
- $ua->env_proxy;
- my $request = HTTP::Request->new(GET => $link);
- my $response = $ua->request($request);
- $response
-}
-sub send_config {
- # When we arrive here, we're sure the login/passwd is correct
- my ($login, $passwd, $box_name) = @_;
-# print STDERR "Sending config\n";
- my $result = -1;
-
- report_config("$confdir/$login.$passwd.$box_name.online.log");
- `/usr/bin/bzip2 \\\-9 \\\-f $confdir/$login.$passwd.$box_name.online.log`;
-
- # Turn the binary file into a uuencoded ascii file
- open (FILE, "$confdir/$login.$passwd.$box_name.online.log.bz2") or die "$!";
- my ($chunk, $buffer);
- while (read(FILE, $chunk, 60*57)) {
- $buffer .= $chunk;
- }
- close (FILE);
- open (FILEOUT, "> $confdir/$login.$passwd.$box_name.online.log.bz2.uue") or die "$!";
- print FILEOUT encode_base64($buffer);
- close (FILEOUT);
-
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkOnlineAgent/$VERSION" . $ua->agent);
- $ua->env_proxy;
- my $response = $ua->request(POST 'https://www.mandrakeonline.net/wizard.php',
-
- Content_Type => 'form-data',
- Content => [submit => "upload_wizard",
- wizard => ["$confdir/$login.$passwd.$box_name.online.log.bz2.uue"]
- ]);
- # Check the outcome of the response
- #print "REPONSE: ".$response->content."\n";
- if ($response->is_success) {
- $result = ($response->content =~ /TRUE(.*)/) ? 0 : -1;
- #print("key is $1\n");
- $key = $1;
- #- update local copy now.
- unlink "$confdir/mdkupdate.rpms";
- rename "$confdir/rpm_qa_installed_after", "$confdir/mdkupdate.rpms";
- } else {
- # pb with the connection ?
- $result = -1;
- }
-
- unlink "$confdir/$login.$passwd.$box_name.online.log.bz2";
- unlink "$confdir/$login.$passwd.$box_name.online.log.bz2.uue";
-
- $result == 0 && $key;
-}
-################################################################################
-
-sub autoInstallRpms {
+sub auto_install_rpms {
my ($pkgs) = shift;
my @pkg;
push(@pkg, $_ . '.rpm') foreach @{$pkgs};
- updatePkgs(@pkg);
+ update_pkgs(@pkg);
}
-sub updateConf {
+sub update_conf {
my ($oldkey, $newkey) = @_;
my %l = getVarsFromSh $conffile;
setVarsInSh($conffile, {
@@ -254,9 +160,9 @@ sub updateConf {
AUTO => $l{AUTO}
});
}
-sub addMedia {
+sub add_media {
my $mirror = shift;
- my ($r) = getRelease();
+ my ($r) = mdkonline::get_release();
my $fullpath2mir = "ftp://" . "$mirror". "/$r" . "/RPMS" . "/" ;
eval {
system "/usr/sbin/urpmi.removemedia", "mdkupdate";
@@ -264,42 +170,39 @@ sub addMedia {
};
$@ and die "Problem adding Update Media with urpmi";
}
-sub getRelease() {
- my ($release) = cat_('/etc/mandrake-release') =~ /release\s+(\S+)/;
- ($release)
-}
-sub updatePkgs {
- my (@str) = @_;
- @str or return;
+sub update_pkgs {
+ @_ or return;
eval {
- system "/usr/sbin/urpmi", "--auto", "--media", "mdkupdate", map { /^(.*)\.rpm$/ && $1 } @str;
+ system "/usr/sbin/urpmi", "--auto", "--media", "mdkupdate", map { /^(.*)\.rpm$/ && $1 } @_;
$? == 0 or die N("Unable to update packages from mdkupdate medium.\n");
};
$@ and die "Problem upgrading with urpmi";
}
+sub send_conf_update {
+ my ($login,$password,$boxname) =@_;
+ mdkonline::report_config("$confdir/$login.$password.$boxname.online.log");
+ my $tag = { submit => 'upload_wizard', wizard => [ "$confdir/$login.$password.$boxname.online.log.bz2.uue" ] };
+ my ($res, $key) = mdkonline::send_config($url->{wizard}, $tag);
+ ($res, $key)
+}
sub send_rpm_dif {
- my ($login,$password,$box_name,$oldkey) =@_;
- #`sdiff -s $confdir/rpm_qa_installed_after $confdirrpm_qa_installed_before >$confdir/$login.$password.$box_name.$oldkey.dif`;
- `sdiff -s $confdir/rpm_qa_installed_after $confdir/mdkupdate.rpms > $confdir/$login.$password.$box_name.$oldkey.dif`;
- -s "$confdir/$login.$password.$box_name.$oldkey.dif" or die N("No diff found");
- my $ua = LWP::UserAgent->new;
- $ua->agent("MdkOnlineAgent/$VERSION" . $ua->agent);
- $ua->env_proxy;
- my $response = $ua->request(POST "https://www.mandrakeonline.net/online_dif.php",
-
- Content_Type => 'form-data',
- Content => [submit => "upload_dif",
- dif_file => ["$confdir/$login.$password.$box_name.$oldkey.dif"]
- ]);
+ my ($login,$password,$boxname,$oldkey) =@_;
+ `sdiff -s $confdir/rpm_qa_installed_after $confdir/mdkupdate.rpms > $confdir/$login.$password.$boxname.$oldkey.dif`;
+ -s "$confdir/$login.$password.$boxname.$oldkey.dif" or die N("No diff found");
+ my $tag = { submit => "upload_dif", dif_file => [ "$confdir/$login.$password.$boxname.$oldkey.dif" ] };
+ my ($res, $key) = mdkonline::send_config($url->{online_dif}, $tag);
#- update mdkupdate.rpms with newer version just sent.
- if ($response->content =~ /TRUE/) {
+ if ($res eq 'TRUE') {
unlink "$confdir/mdkupdate.rpms";
rename "$confdir/rpm_qa_installed_after", "$confdir/mdkupdate.rpms";
- } else { print "REPONSE: " . $response->content . "\n"; }
+ } else {
+ log::l(N("Connection problem")."\n" . N("Mdkupdate could not upload the diff files. Send a mail to support [at] mandrakeonline [dot] net"));
+ return
+ }
}
sub clean_dir() {
- system("rm -f $confdir/*.dif $confdir/rpm_qa_installed_before $confdir/rpm_qa_installed_after");
+ system("rm -f $confdir/*log.bz2 $confdir/*log.bz2.uue $confdir/*.dif $confdir/rpm_qa_installed_before $confdir/rpm_qa_installed_after");
}
sub rpm_qa {
@@ -309,14 +212,3 @@ sub rpm_qa {
close FILE;
}
-sub log_i {
- local *LOG;
- open LOG, ">> $logfile" or die "can't output to log file\n";
- print LOG @_;
- close LOG;
-}
-
-sub fatal {
- my ($comment)=@_;
- printf STDERR "%s\n", $comment; exit($_[0]);
-}