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
|
#!/usr/bin/perl
################################################################################
# Mdkupdate #
# #
# Copyright (C) 2002 MandrakeSoft #
#
# Daouda Lo <daouda@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 Digest::MD5 qw(md5 md5_hex md5_base64);
use HTTP::Request;
use HTTP::Request::Common;
use LWP::UserAgent;
use MDK::Common;
use lib qw(/usr/lib/libDrakX);
use Locale::GetText;
#- I18N.
setlocale (LC_ALL, "");
Locale::GetText::textdomain ("mdkupdate");
sub _ {
my ($format, @params) = @_;
sprintf(Locale::GetText::I_($format), @params);
}
my $VERSION = "0.16";
my $security = 0;
sub usage {
print STDERR _("mdkupdate version %s
Copyright (C) 2002 MandrakeSoft.
This is free software and may be redistributed under the terms of the GNU GPL.
usage:
") . _(" --help - print this help message.
") . _(" --security - use only security media.
") . _(" -v - verbose mode.
", $VERSION );
exit(0);
}
#parse the file and leave the comments out
my @parsed = grep {!/^#/} parse_file("/root/.mdkupdate");
# authenticate before
my $valid_customer = connect_site("http://mandrakeonline.net/online_user.php");
`urpmi.addmedia --update security_$parsed[3] $parsed[4] with ../base/hdlist.cz`;
sub connect_site () {
my ($url) =@_;
my $result = -1;
my $login = $parsed[1];
my $passwd= $parsed[2];
if ($login && $passwd && $login !~ /\s+/ && $passwd !~ /\s+/) {
my $ua = LWP::UserAgent->new;
$ua->agent("MdkUpdateAgent/0.15" . $ua->agent);
my $request = HTTP::Request->new(GET => $url.'?log='.$login.'&pass='.$passwd);
#add hostname to authentication.
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 ? stay on page 2
print STDERR _("Connection problem")."\n"._("MandrakeOnline could not be contacted, we will try again");
return;
}
} else {
$result = -1; # not needed, but this way it's clear
}
# if correct, return 1
if (! $result) {
$result;
} else {
# if incorrect, clear passwd and stay on page 2
print STDERR _("Wrong password")."\n"._("Your login or password was wrong")."\n"._("You'll need to have an account on MandrakeOnline, or update your subscription. For any problems send mail to support@mandrakeonline.com");
return -1;
}
}
sub parse_file {
my ($file)=@_;
my @list_hosts;
open( FILE, $file ) or die "load_text: missing file $file : $!";
while (<FILE>) {
chomp;
unshift(@list_hosts,$_);
}
close( FILE );
reverse @list_hosts;
}
sub log_it {
local *LOG;
open LOG, ">>/var/log/mdkupdate.log" or die "can't output to log file\n";
print LOG @_;
}
sub fatal {
my ($comment)=@_;
printf STDERR "%s\n", $comment; exit($_[0]);
}
|