]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/updatelists.pl
HinzugefĆ¼gt:
[ipfire-2.x.git] / src / scripts / updatelists.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use LWP::UserAgent;
5 require "CONFIG_ROOT/general-functions.pl";
6
7 my @this;
8 my $return = &downloadlist();
9 if($return && $return->is_success) {
10 unless(open(LIST, ">CONFIG_ROOT/patches/available")) {
11 die "Could not open available lists database.";
12 }
13 flock LIST, 2;
14 @this = split(/----START LIST----\n/,$return->content);
15 print LIST $this[1];
16 close(LIST);
17 } else {
18 die "Could not download patches list.";
19 }
20
21 sub downloadlist {
22 unless(-e "CONFIG_ROOT/red/active") {
23 die "Not connected.";
24 }
25
26 my $downloader = LWP::UserAgent->new;
27 $downloader->timeout(5);
28
29 my %proxysettings;
30 &General::readhash("CONFIG_ROOT/proxy/settings", \%proxysettings);
31
32 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
33 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
34 if ($proxysettings{'UPSTREAM_USER'}) {
35 $downloader->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$peer:$peerport/");
36 } else {
37 $downloader->proxy("http","http://$peer:$peerport/");
38 }
39 }
40
41 return $downloader->get("http://www.ipcop.org/patches/${General::version}", 'Cache-Control', 'no-cache');
42 }