home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_28_2.lzh
/
support
/
killplum
< prev
next >
Wrap
Text File
|
1998-10-15
|
4KB
|
163 lines
#!/bin/perl -w
# $Id: killplum,v 2.5 1998/10/06 04:24:32 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
$NAME = 'plum';
if ($] < 5) {
foreach $inc (@INC) {
if (-r "$inc/sys/socket.ph") {
eval { require 'sys/socket.ph' };
$SOCKET = "$inc/sys/socket.ph" unless $@;
last;
}
if (-r "$inc/socket.ph") {
eval { require 'socket.ph' };
$SOCKET = "$inc/socket.ph" unless $@;
last;
}
}
} else {
eval 'use Socket';
$SOCKET = 'Socket.pm' unless $@;
}
$NIL = $;;
$NOTRAILING = &'list('004', '215', '221', '324', '341', '367', 'mode');
$IRCPORT = 6667;
$SOCKADDR = 'S n N x8';
$PROTO = getprotobyname('tcp');
$AF_INET = eval { &AF_INET } || 2;
$PF_INET = eval { &PF_INET } || 2;
$SOCK_STREAM = eval { &SOCK_STREAM } || 1;
$'rin = '';
$handle = 0;
&main(@ARGV);
sub main {
local(@args) = @_;
local($path);
if ($0 =~ /^(.*)[\\\/][^\\\/]*$/) {
$path = "$1/..";
} else {
$path = '..';
}
&load("$path/$NAME.conf") if -r "$path/$NAME.conf";
&load("$NAME.conf") if -r "$NAME.conf";
foreach $user (@args) {
&load("$path/$NAME-$user.conf") if -r "$path/$NAME-$user.conf";
&load("$NAME-$user.conf") if -r "$NAME-$user.conf";
}
}
sub load {
local($file) = @_;
local($line, $var, $arg, $host, $pass, $name, $port);
open(FILE, $file) || return;
while (defined($line = <FILE>)) {
$line =~ s/^\s+//;
next if $line =~ /^[\#\;]/;
$line =~ tr/\r\n//d;
next unless $line;
$line =~ s/\s+$//;
if (!($line =~ /^[\+\-\=]\s*(\S+)/)) {
if ((($var, $arg) = split(/\s*\:\s*/, $line, 2)) == 2) {
if ($var eq 'plum.client') {
($host, $pass) = split(/\s+/, $arg, 2);
($name, $port) = split(/\:/, $host, 2);
$port = $IRCPORT unless $port;
&exit($port, $pass || '');
}
}
}
}
close(FILE);
}
sub exit {
local($port, $pass) = @_;
local($no);
if ($no = &'connect("127.0.0.1", $port)) {
&print($no, &'build('', 'PASS', $pass));
&print($no, &'build('', 'NICK', $NAME));
&print($no, &'build('', 'USER', $NAME, '*', '*', $NAME));
&print($no, &'build('', 'EXIT', $NAME));
}
}
sub print {
local($no, $str) = @_;
local($socket);
$socket = $'socket[$no];
print $socket $str;
}
sub 'build {
local($prefix, $cmd, @params) = @_;
local($trailing);
return '' unless $cmd;
if (scalar(@params)) {
$trailing = pop(@params) || '';
if (&'exist($NOTRAILING, "\L$cmd\E")) {
push(@params, "$trailing ");
} else {
push(@params, ":$trailing");
}
} else {
@params = ();
}
unshift(@params, $cmd);
unshift(@params, ":$prefix") if $prefix;
return join(' ', @params) . "\r\n";
}
sub 'exist {
local($list, @items) = @_;
return 0 unless $list;
foreach $item (@items) {
return 1 if index("\L$list\E", $NIL . "\L$item\E" . $NIL) != -1;
}
return 0;
}
sub 'list {
local(@array) = @_;
local($list);
if (scalar(@array)) {
$list = $NIL . join($NIL, @array) . $NIL;
} else {
$list = '';
}
return $list;
}
sub 'connect {
local($host, $port) = @_;
local($serverno, $socket, $ip, @addr, $name);
if ($host =~ /^\d+$/) {
$ip = $host;
} elsif ($host =~ /^[\d\.]+$/) {
@addr = split(/\./, $host);
$ip = unpack('N', pack('C4', @addr, 0, 0, 0));
} else {
$ip = unpack('N', (gethostbyname($host))[4] || "\0\0\0\0");
}
return 0 unless $ip;
$socket = '\'S' . ++$handle;
socket($socket, $PF_INET, $SOCK_STREAM, $PROTO) || return 0;
$name = pack($SOCKADDR, $AF_INET, $port, $ip);
connect($socket, $name) || return 0;
$serverno = fileno($socket);
vec($'rin, $serverno, 1) = 1;
$'socket[$serverno] = $socket;
select((select($socket), $| = 1)[0]);
return $serverno;
}