#!/usr/local/bin/perl use Sys::Syslog; use Socket; use LWP::Simple; $port = 8080; # Initialize C structure $server_addr = inet_aton('127.0.0.1'); $server_struct = pack("S n a4 x8", AF_INET,$port, $server_addr); # Set up socket $proto = (getprotobyname('tcp'))[2]; socket(SOCK, PF_INET, SOCK_STREAM,$proto)|| die "Failed to initialize socket:$!\n"; # Bind to address/port and set up pending queue setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR, 1) || die "setsockopt() failed: $!\n"; bind(SOCK, $server_struct) || die "bind() failed: $!\n"; listen(SOCK, SOMAXCONN) || die "listen() failed: $!\n"; syslog(LOG_NOTICE, "RSSmod: Started server"); # Deal with requests for (;;) { # Grab next pending request # $remote_host = accept(NEWSOCK, SOCK); die "accept() error: $!\n" unless ($remote_host); # Print a line of logging info to STDOUT $raw_addr = (unpack("S n a4 x8", $remote_host))[2]; $dot_addr = join(".", unpack("C4", $raw_addr)); if($dot_addr eq '127.0.0.1') { # Read client request and get $path while () { last if (/^\s*$/); next unless (/^GET /); $path = (split(/\s+/))[1]; } # Check what RSS should be treated if($path eq "/versiontracker") { $rdf = get "http://www.versiontracker.com/macosx/recent.rss"; $rdf =~ s/<.?img.*?>//g; print NEWSOCK <<"Header"; HTTP/1.1 200 OK Server: RSSmod v0.5 Header print NEWSOCK $rdf; } elsif($path eq "/macupdate") { $rdf = get "http://www.macupdate.com/mommy/macsurferx.xml"; $rdf =~ s/(.*?) - (.*?)<\/title>/<title>$1<\/title>\n<description>$2<\/description>/g; print NEWSOCK <<"Header"; HTTP/1.1 200 OK Server: RSSmod v0.5 Header print NEWSOCK $rdf; } else { print NEWSOCK <<"EOErrMsg"; <TITLE>Error

Error

I couldn't understand the command $path EOErrMsg } } else { syslog(LOG_ERR, "Refused connection from: $dot_addr"); } # All done reloop to wait for next request close(NEWSOCK); }