From 00795a713525acc10a2d81a2df9a80068e98c305 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 31 Mar 2005 08:12:32 +0000 Subject: [PATCH] rewrote it IN PERL, TAKE THAT AUSTIN ;=) --- maintenance/fetchInterwiki.pl | 254 +++++++++++----------------------- 1 file changed, 84 insertions(+), 170 deletions(-) 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;} -- 2.20.1