#!/usr/bin/perl #----------------------------------------------------------------------------- # # POPular -- A POP3 server and proxy for large mail systems # # $Id: ctrl.pl,v 1.2 2001/02/09 15:59:07 sqrt Exp $ # # http://www.remote.org/jochen/mail/popular/ # #----------------------------------------------------------------------------- # # ctrl.pl # # This is a test program for the pproxy control interface. It is not much # more then a demo, though. # #----------------------------------------------------------------------------- # # Copyright (C) 1999-2001 Jochen Topf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA # #----------------------------------------------------------------------------- use strict; use IO::Socket; my $sname = "/var/run/popular/ctrl.pl.socket.$$"; my $sock = new IO::Socket::UNIX ( Type => SOCK_DGRAM, Local => $sname, Peer => '/var/run/popular/pproxy.socket', ); die("Can't open socket: $!\n") unless ($sock); my $a = cmd($sock, "show id"); if ($a ne '00 set id "pproxy"') { die("returned something unexpected\n"); } my $list = cmd($sock, 'vserv list'); $list =~ s/^.*: //; my @vservs = split(/ /, $list); foreach my $vserv (@vservs) { my $l = cmd($sock, "vserv show $vserv"); $l =~ /^00 vserv conf "([^"]*)" iface "([^"]*)" port "([^"]*)" prot "([^"]*)" state "([^"]*)" namespace "([^"]*)" bannerok "([^"]*)" bannererr "([^"]*)"$/; # print "vserv|$1|$2|$3|$4|$5|$6|$7|$8\n"; print "vserv|$1|$2|$3|$4|$5|$6\n"; } print "\n"; $list = cmd($sock, 'backend list'); $list =~ s/^.*: //; my @backends = split(/ /, $list); foreach my $backend (@backends) { my $l = cmd($sock, "backend show $backend"); $l =~ /^00 backend conf "([^"]*)" host "([^"]*)" port "([^"]*)" prot "([^"]*)" state "([^"]*)"$/; print "backend|$1|$2|$3|$4|$5\n"; } $sock->close(); unlink($sname); exit 0; #----------------------------------------------------------------------------- sub cmd { my ($s, $request) = @_; my $answer; # print "-> $request\n"; $s->send($request); $s->recv($answer, 1024); # print "<- $answer\n"; return $answer; } #-- THE END ------------------------------------------------------------------