#!/usr/bin/perl # # gnomie # http://www.bradfitz.com/programming/hacks/gnomie/ # bradfitz@bradfitz.com # # This code is released under the GNU Public License, # which you can find all over the place. # my $PORT = 7775; # change this, perhaps. # no need to change this stuff: # (most of it's just stolen from the perlipc man page) use strict; use Win32; use Win32::API; use IO::Socket; my $EOL = "\015\012"; my $shellopen = new Win32::API("shell32", "ShellExecute", ['N', 'P', 'P', 'P', 'P', 'I'], 'N'); my $proto = getprotobyname('tcp'); socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!"; bind(Server, sockaddr_in($PORT, INADDR_ANY)) || die "bind: $!"; listen(Server,SOMAXCONN) || die "listen: $!"; my $paddr; for ( ; $paddr = accept(Client,Server); close Client) { my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); print "Connection!\n"; my $line = ; chomp $line; print "Line = $line\n"; if ($line =~ /^url (http:\/\/.+)$/) { my $url = $1; $url =~ s/\s+$//; $url =~ s/\s/%20/g; $shellopen->Call(0, "open", $url, 0, 0, 0); print Client "200 Opened\n"; } else { print Client "500 Malformed request.\n"; } }