Debian Codegraph @

misc/contrib/ifman

raw
1 #! /usr/bin/perl
2 #
3 # This is a utility script to manipulate Fidonet-related issues
4 # using Eugene Crosser's ifmail package
5 #
6 # Version 0.1
7 #
8 # (C) Michael Bravo and The Communication Tube, 1994
9 #
10 # You can do whatever you want with this script. I take no responsibility
11 # whatsoever in anything related to this script. If you make some useful
12 # additions to this, please think of sending them to me so I could partake
13 # of your wisdom.
14 #
15 # This script was written to help attaching and requesting files from the
16 # commandline, much like you do with Squish under DOS or OS/2. It is certainly
17 # not perfect - I used it as an exercise in Perl. It also probably lacks
18 # some other useful features, like ability to specify trunc/sent or kill/sent
19 # attributes etc etc. If you really want this or some other features
20 # implemented, write me at [email protected] or [email protected]
21 # and I will try to do what I can.
22 #
23 # Note - files don't get copied to any spool dir, so if you move attached
24 # files somewhere, they won't get sent.
25 #
26 # This script is supposed to read ifmail's config to determine where outbound
27 # directory and logfile are. The only two parameters to modify in most cases
28 # are below.
29
30 ### modified by P. Saratxaga on 28 Jun 1996
31 # when _requesting_ it musn't append $PWD to the file name. So I move that
32 # code to execute only if it is send mode.
33
34
35 $cfgfile="/etc/ifmail/config"; # where the config is
36 $ifowner="fnet"; # who is the owner of the ifmail
37
38 if ( getpwuid($<) ne $ifowner ) { print "You must be owner of ifmail\n"; exit 1; }
39
40 if ( (@ARGV < 3) || $ARGV[0] eq "-?" || $ARGV[0] eq "-h" ) {
41 &usage;
42 }
43
44 $ARGV[0] =~ tr/A-Z/a-z/;
45 $ARGV[3] =~ tr/A-Z/a-z/;
46
47 &parsecfg;
48
49 if ( $logfile ne "" ) {
50 open(LOG, ">>".$logfile) || die "Can't open logfile";
51 }
52
53 if ($ARGV[3] eq "" || $ARGV[3] eq "normal") {
54 $flavour = 'f';
55 } elsif ($ARGV[3] eq "crash") {
56 $flavour = 'c';
57 } elsif ($ARGV[3] eq "hold") {
58 $flavour = 'h';
59 } else {
60 print "Unknown flavour, assuming normal\n";
61 $flavour = 'f';
62 }
63
64 if ($ARGV[0] eq "send") {
65 if (substr($ARGV[1], 0, 1) ne "/") {
66 $cwd=`pwd`;
67 chop $cwd;
68 $ARGV[1] = $cwd."/".$ARGV[1];
69 }
70 &attach($ARGV[1], $ARGV[2]);
71 } elsif ($ARGV[0] eq "get") {
72 &request($ARGV[1], $ARGV[2]);
73 } else {
74 print "Unknown command, try ifman -h\n";
75 exit 1;
76 }
77
78 close(LOG);
79
80 exit 0;
81
82 #######################################################################
83
84 sub attach {
85 local($fspec, $address) = @_;
86
87 $floname = &resolve($address);
88
89 open(FLO, ">>".$outbound."/".$floname) || die "Can't open flo-file $outbound/$floname";
90 open(FIND, "find $fspec -print |") || die "Can't generate list of files";
91
92 if ( eof(FIND) ) {
93 print "No matching files, nothing to send\n";
94 exit 1;
95 }
96
97 while (<FIND>) {
98
99 chop;
100 $datestamp = `date \"+%D %T\"`;
101 chop $datestamp;
102 printf LOG "%s %s %s\n", $datestamp, $$, "ifman: sending $_ to $address";
103 printf FLO "%s\n", $_;
104 }
105
106 close(FLO);
107 close(FIND);
108 }
109
110 sub request {
111 local($fspec, $address) = @_;
112
113 $reqname = &resolve($address);
114
115 $reqname =~ s/\.[fch]lo/\.req/;
116
117 open(REQ, ">>".$outbound."/".$reqname) || die "Can't open req-file";
118
119 $datestamp = `date \"+%D %T\"`;
120 chop $datestamp;
121 printf LOG "%s %s %s\n", $datestamp, $$, "ifman: requesting $fspec from $address";
122 printf REQ "%s\n", $fspec;
123
124 close(REQ);
125 }
126
127 sub resolve {
128 local($addr) = @_;
129
130 if ( index($addr, ":") >=0 ) {
131 print "I cannot resolve addresses with zones!\n";
132 exit 1;
133 } elsif ( index($addr, "/") == -1 ) {
134 print "Not a valid address!\n";
135 exit 1;
136 }
137
138 ($net, $node, $point) = split(/\/|\./, $addr);
139
140 if ( defined $point ) {
141 $pointdir = sprintf("%04x%04x.pnt", $net, $node);
142 if ( ! -e $outbound."/".$pointdir ) {
143 mkdir ($outbound."/".$pointdir, 0755) || die "Can't create point directory";
144 }
145 $flo = sprintf("0000%04x.%01slo", $point, $flavour);
146 return $pointdir."/".$flo;
147 } else {
148 $flo = sprintf("%04x%04x.%01slo", $net, $node, $flavour);
149 return $flo;
150 }
151 }
152
153 sub usage {
154 print "ifmail manager script\n";
155 print "usage: ifman <cmd> <filespec> <address> [flavour]\n";
156 print " commands: send, get\n";
157 print " flavours: normal, crash, hold. Default is normal.\n";
158 print "Only 2d addresses with points are supported - no zones!\n";
159 exit 1;
160 }
161
162 sub parsecfg {
163 open(CFG, $cfgfile) || die "Can't open ifmail config file";
164
165 while (<CFG>) {
166 chop;
167 if (/^#/) { next; }
168 if (/^outbound\s+(\S+)/) { $outbound = $1; }
169 if (/^logfile\s+(\S+)/) { $logfile = $1; }
170 }
171
172 close(CFG);
173 }