#!/usr/bin/perl -w # yi.pl - perl 5 YI.ORG Client 0.01 # # This is free software; # You may redistribute this code under the same license and terms as perl itself. # Copyright 2000 by Tyler MacDonald # # Official Distribution Site: # http://www.yi.org/clients/ # use strict; use vars qw(@ARGV %cfg %help %ENV $req $resp $ua $c $VERSION); use HTTP::Request; use LWP::UserAgent; $VERSION="0.1"; %cfg=( 'url' => 'http://www.yi.org/bin/dyndns.fcgi', 'config' => "$ENV{'HOME'}/.yirc" ); if($cfg{'config'} && open(CONFIG, $cfg{'config'})) { my %c; @_=; close(CONFIG); chomp(@_); %c=@_; $cfg{$_[0]}=$_[1] while(@_=each(%c)); } foreach (@ARGV) { if(/^(.+?)=(.+)$/) { $cfg{$1}=$2; } else { $cfg{$_}++; } } if($cfg{'save'} && $cfg{'config'}) { print "Saving configuration to $cfg{'config'}.\n"; if(open(CONFIG, ">" . $cfg{'config'})) { delete($cfg{'save'}); print CONFIG join("\n", %cfg), "\n"; close(CONFIG); chmod(0700, $cfg{'config'}); } else { die "Save failed: $!"; } exit(0); } elsif($cfg{'save'}) { usage("Save option requires config file argument (config=...)"); } if(@_=grep(!$cfg{$_}, 'url', 'user', 'password')) { usage("Values required for ", join(", ", @_), "."); } $req=HTTP::Request->new('GET'=>$cfg{'url'}); $req->authorization_basic($cfg{'user'}, $cfg{'password'}); $req->url->query("ipaddr=$cfg{'ip'}") if($cfg{'ip'}); $ua=LWP::UserAgent->new; $ua->agent("yi.pl/$VERSION"); $resp=$ua->request($req) || die "Requesting URL failed"; if($resp->is_error()) { die("Request ", $req->url, " failed: ", $resp->status_line, "\n"); } $c=$resp->content(); if($c=~/STATUS:OK/) { print unhtml($c) unless($cfg{'verbose'}); } else { die unhtml($c) . "\n"; } exit(0); # Functions sub usage { print(join("\n", "Usage: $0 \[user=..\] \[password=..\] \[ip=..\] \[config=..\] \[save\] \[quiet\]", join("",@_)), "\n"); while(@_=each(%help)) { print join(length($_[0]<8) ? "\t\t" : "\t", @_), "\n"; } exit(1); } sub unhtml { my $h=shift; $h=~s/\<.+?\>//g; $h=~s/^\n|\n$|\n(\n\n)/$1||''/ges; $h; } .