From: Ævar Arnfjörð Bjarmason Date: Thu, 31 Mar 2005 08:12:32 +0000 (+0000) Subject: rewrote it IN PERL, TAKE THAT AUSTIN ;=) X-Git-Tag: 1.5.0alpha1~453 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=00795a713525acc10a2d81a2df9a80068e98c305;p=lhc%2Fweb%2Fwiklou.git rewrote it IN PERL, TAKE THAT AUSTIN ;=) --- diff --git a/maintenance/fetchInterwiki.pl b/maintenance/fetchInterwiki.pl index 7313aac65e..a4ff14a031 100644 --- a/maintenance/fetchInterwiki.pl +++ b/maintenance/fetchInterwiki.pl @@ -1,189 +1,103 @@ -#!/usr/bin/perl +#!/usr/bin/env perl +# Copyright (C) 2005 Ævar Arnfjörð Bjarmason +use strict; +use warnings; +use Socket; -$intermap = "http://usemod.com/intermap.txt"; -unless( -r "intermap.txt" ) { - print "Fetching $intermap...\n"; - # For some reason we're redirected to microsoft.com with wget useragent - print `wget -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0" $intermap`; -} +# Conf +my $map = &get(&url('http://usemod.com/intermap.txt')); + +# --- # +my $cont; +my @map = split /\n/, $map; open IW, ">Interwiki.php"; -print IW " ) { - $x =~ /^([a-z0-9]+)\s(http:\/\/.+)$/i; - ($name, $url) = ($1, $2); - print IW "\t\"$name\" => \"$url\$1\",\n"; +$cont .= "\t# The usemod interwiki map\n"; +for (my $i=0;$i<=$#map;++$i) { + my ($name, $url) = $map[$i] =~ m#^([^ ]+) (.+)#i; + $cont .= "\t'$name' => '$url\$1',\n"; } -print IW <Interwiki.php"; +print IW $cont; +close IW; + +sub get { + my ($host, $url) = @_; + my $cont; + my $eat; + + my $proto = getprotobyname('tcp'); + socket(Socket, AF_INET, SOCK_STREAM, $proto); + my $iaddr = inet_aton("$host"); + my $port = getservbyname('http', 'tcp'); + my $sin = sockaddr_in($port, $iaddr); + connect(Socket, $sin); + send Socket, "GET $url HTTP/1.0\r\nHost: $host\r\n\r\n",0; + while () { + $cont .= $_ if $eat; # mmm, food + ++$eat if ($_ =~ /^(\n|\r\n|)$/); + } + return $cont; +} + +sub url {my ($server, $path) = $_[0] =~ m#.*(?=//)//([^/]*)(.*)#g;}