Current Path : /usr/src/contrib/dialog/samples/copifuncs/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/src/contrib/dialog/samples/copifuncs/copi.ifman2 |
if ( getpwuid($<) ne $ifowner ) { print "You must be owner of ifmail\n"; exit 1; } if ( (@ARGV < 3) || $ARGV[0] eq "-?" || $ARGV[0] eq "-h" ) { &usage; } $ARGV[0] =~ tr/A-Z/a-z/; $ARGV[3] =~ tr/A-Z/a-z/; &parsecfg; if ( $logfile ne "" ) { open(LOG, ">>".$logfile) || die "Can't open logfile"; } if (substr($ARGV[1], 0, 1) ne "/") { $cwd=`pwd`; chop $cwd; $ARGV[1] = $cwd."/".$ARGV[1]; } if ($ARGV[3] eq "" || $ARGV[3] eq "normal") { $flavour = 'f'; } elsif ($ARGV[3] eq "crash") { $flavour = 'c'; } elsif ($ARGV[3] eq "hold") { $flavour = 'h'; } else { print "Unknown flavour, assuming normal\n"; $flavour = 'f'; } if ($ARGV[0] eq "send") { &attach($ARGV[1], $ARGV[2]); } elsif ($ARGV[0] eq "get") { &request($ARGV[1], $ARGV[2]); } else { print "Unknown command, try ifman -h\n"; exit 1; } close(LOG); exit 0; ####################################################################### sub attach { local($fspec, $address) = @_; $floname = &resolve($address); open(FLO, ">>".$outbound."/".$floname) || die "Can't open flo-file $outbound/$floname"; open(FIND, "find $fspec -print |") || die "Can't generate list of files"; if ( eof(FIND) ) { print "No matching files, nothing to send\n"; exit 1; } while (<FIND>) { chop; $datestamp = `date \"+%D %T\"`; chop $datestamp; printf LOG "%s %s %s\n", $datestamp, $$, "ifman: sending $_ to $address"; printf FLO "%s\n", $_; } close(FLO); close(FIND); } sub request { local($fspec, $address) = @_; $reqname = &resolve($address); $reqname =~ s/\.[fch]lo/\.req/; open(REQ, ">>".$outbound."/".$reqname) || die "Can't open req-file"; $datestamp = `date \"+%D %T\"`; chop $datestamp; printf LOG "%s %s %s\n", $datestamp, $$, "ifman: requesting $fspec from $address"; printf REQ "%s\n", $fspec; close(REQ); } sub resolve { local($addr) = @_; if ( index($addr, ":") >=0 ) { print "I cannot resolve addresses with zones!\n"; exit 1; } elsif ( index($addr, "/") == -1 ) { print "Not a valid address!\n"; exit 1; } ($net, $node, $point) = split(/\/|\./, $addr); if ( defined $point ) { $pointdir = sprintf("%04x%04x.pnt", $net, $node); if ( ! -e $outbound."/".$pointdir ) { mkdir ($outbound."/".$pointdir, 0755) || die "Can't create point directory"; } $flo = sprintf("0000%04x.%01slo", $point, $flavour); return $pointdir."/".$flo; } else { $flo = sprintf("%04x%04x.%01slo", $net, $node, $flavour); return $flo; } } sub usage { print "ifmail manager script\n"; print "usage: ifman <cmd> <filespec> <address> [flavour]\n"; print " commands: send, get\n"; print " flavours: normal, crash, hold. Default is normal.\n"; print "Only 2d addresses with points are supported - no zones!\n"; exit 1; } sub parsecfg { open(CFG, $cfgfile) || die "Can't open ifmail config file"; while (<CFG>) { chop; if (/^#/) { next; } if (/^outbound\s+(\S+)/) { $outbound = $1; } if (/^logfile\s+(\S+)/) { $logfile = $1; } } close(CFG); }