1 |
#!/usr/bin/perl |
2 |
# |
3 |
# printfax.pl 1.5.0, last changed 2000/03/22 |
4 |
# |
5 |
################################################################### |
6 |
# |
7 |
# Copyright (C) 2000 Horst F <horstf@gmx.de> |
8 |
# |
9 |
# This program is free software; you can redistribute it and/or |
10 |
# modify it under the terms of the GNU General Public License as |
11 |
# published by the Free Software Foundation; either version 2 of |
12 |
# the License, or (at your option) any later version. |
13 |
# |
14 |
# This program is distributed in the hope that it will be useful, |
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
# General Public License for more details. |
18 |
# |
19 |
# You should have received a copy of the GNU General Public License |
20 |
# along with this program; if not, write to the Free Software |
21 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 |
# |
23 |
################################################################### |
24 |
# |
25 |
# based on the script by |
26 |
# Heiko Schlittermann <heiko@lotte.sax.de> |
27 |
# added some modifications by |
28 |
# Don Hayward <don@marinelab.sarasota.fl.us> |
29 |
# Simon Hyde <shyde@poboxes.com> |
30 |
# Helmut Lichtenberg <heli@tzv.fal.de> |
31 |
# Ondrejicka Stefan <ondrej@idata.sk> |
32 |
# Bryan Halvorson <bryan@pkgplus.com> |
33 |
# |
34 |
# NOTE: I'm neither a perl nor network expert (as well |
35 |
# English isn't my natural language too) |
36 |
# |
37 |
##### |
38 |
# This script is intended to be used in conjunction with |
39 |
# ``Winsock Respond Daemon'' written by "Horst F" <horstf@gmx.de> |
40 |
# |
41 |
# You can download the current version from |
42 |
# http://www.boerde.de/~horstf/ |
43 |
# |
44 |
# called from smb.conf: |
45 |
# print command = ( /usr/bin/printfax.pl %I %s %U %m; rm %s ) & |
46 |
# |
47 |
# History (changes since 1996/10/28/): |
48 |
# [1996/10/28] |
49 |
# - one script for all perl versions since 5.0 (or earlier?) |
50 |
# (joining the scripts for 5.002 and for earlier versions) |
51 |
# - replace of 'localhost' with call of hostname(), hope |
52 |
# this fixes the problem with SunOS |
53 |
# [1996/10/29 1.3.2] |
54 |
# - the use of hostname() doesn't solve the problem with SunOS, |
55 |
# the problem was gethostbyname, but now it works |
56 |
# - start version numbering, now it's 1.3.2 |
57 |
# [1997/09/22 1.3.3] |
58 |
# - minor bug fix: |
59 |
# use "require/import" instead of "use Sys::Hostname" because |
60 |
# "use" includes a file at compile time and so it includes |
61 |
# Sys::Hostname every time, not only for perl version < 5.002 |
62 |
# [1997/10/29 1.3.4] |
63 |
# - reading faxnumbers from file in user's home dir or everywhere |
64 |
# - added debug output |
65 |
# [1998/01/26 1.3.5] |
66 |
# - report errors with winpopup |
67 |
# - additional faxspool arguments in configuration section |
68 |
# - optional faxnumber preprocessing |
69 |
# [1999/02/19 1.4.0] |
70 |
# - allows '*' in faxnumber now |
71 |
# - missing smbclient don't breaks the use of multiple faxnumbers |
72 |
# - added support for Hylafax (untested) |
73 |
# [1999/07/01 1.4.1] |
74 |
# - avoid winpopup timeout (seen with WinNT) |
75 |
# [1999/12/05 1.4.2] |
76 |
# - bug fix: use '-d' switch for hylafax when no faxreceiver given |
77 |
# [2000/03/22 1.5.0] |
78 |
# - added support for Windows NT Terminal Server |
79 |
# - added workaround for the double connection problem |
80 |
# - added additional logging features |
81 |
#### |
82 |
|
83 |
require 5.0; # Don't know if required include files exist |
84 |
# in earlier versions |
85 |
use strict; |
86 |
no strict "refs"; |
87 |
use Socket; |
88 |
|
89 |
# this is only required for perl versions below 5.002 |
90 |
if ( $] < 5.002 ) { |
91 |
require Sys::Hostname; |
92 |
import Sys::Hostname; |
93 |
} |
94 |
|
95 |
my($last, $tmp); |
96 |
|
97 |
### |
98 |
### CONFIGURATION Section |
99 |
### |
100 |
|
101 |
my($port, $usedelay, $defaultdelay, $acct, $faxspool, $smbclient, |
102 |
$logsmbhostname, $usesmbuser, $msg_to, $msg_ignored, |
103 |
$msg_spooled, $msg_failed, $debug, $allowfile, $filechar, |
104 |
$version, $nosendondebug, @faxspool_args, $msg_norespond, |
105 |
$msg_strangeerr, $intl_with, $unillegal, $unillegalnumbers, |
106 |
$termserver_ip, $ts_user, %respond_port, $minfaxsize, |
107 |
$cmdlinefmt); |
108 |
|
109 |
### printfax.pl version string |
110 |
$version = 'printfax.pl 1.5.0'; |
111 |
|
112 |
### The default port we'll connect to RESPOND |
113 |
$port = 5555; |
114 |
|
115 |
### Use delay |
116 |
$usedelay = 1; |
117 |
|
118 |
### Default delay for delayed faxes |
119 |
$defaultdelay = '18:00'; |
120 |
|
121 |
### The log file we'll write the accounting information to |
122 |
### (It has to be writeable by the user samba is running as for faxes) |
123 |
$acct = '/var/spool/fax/outgoing/printfax.log'; |
124 |
|
125 |
### Format of commandline |
126 |
$cmdlinefmt='mgetty'; |
127 |
# $cmdlinefmt='hylafax'; |
128 |
|
129 |
### The faxspoolprogram |
130 |
### for mgetty+sendfax: |
131 |
$faxspool = '/usr/bin/faxspool'; |
132 |
### for hylafax: |
133 |
# $faxspool = '/usr/bin/sendfax'; |
134 |
|
135 |
### Additional faxspool args (e.g. header, coverpage) |
136 |
### empty: |
137 |
@faxspool_args = qw(); |
138 |
### for mgetty+sendfax with a special header: |
139 |
# @faxspool_args = qw( -h /usr/local/etc/mgetty+sendfax/faxheader.smb ); |
140 |
### for hylafax with send email when job is done or requeued and use |
141 |
### a4 sized paper: |
142 |
# @faxspool_args = qw(-D -R -s a4); |
143 |
|
144 |
### The smbclient program, sender is the faxsystem. |
145 |
### Set to "" if you don't want to use smbclient |
146 |
$smbclient = '/usr/bin/smbclient -U FAX'; |
147 |
#$smbclient = ''; |
148 |
|
149 |
### The secure path for binaries searched |
150 |
### (faxspool makes usage of the PATH environment!) |
151 |
$ENV{PATH} = '/usr/local/bin:/usr/bin:/bin' . |
152 |
':/usr/local/sbin:/usr/sbin:/sbin' . |
153 |
':/usr/X11R6/bin'; |
154 |
|
155 |
### Use smb hostname for logging, set to 0 for inet hostname |
156 |
### (ip address will be logged in both cases) |
157 |
$logsmbhostname = 1; |
158 |
|
159 |
### use smbuser for returning mail, ignore what the user types in |
160 |
### (smbuser will be allways used for logging) |
161 |
$usesmbuser = 0; |
162 |
|
163 |
### Preprocess faxnumbers, disable it if you use faxspool aliases |
164 |
# this replaces a leading '+', "" for no replace |
165 |
$intl_with = ""; |
166 |
# delete all non numbers |
167 |
$unillegal = 0; |
168 |
# delete all non numbers, if faxnum contains only numbers and these characters |
169 |
# "" for no delete |
170 |
$unillegalnumbers = "()/-"; |
171 |
|
172 |
### messages for smbclient |
173 |
### English: |
174 |
$msg_to = "to"; |
175 |
$msg_ignored = "ignored"; |
176 |
$msg_spooled = "spooled"; |
177 |
$msg_failed = "failed"; |
178 |
$msg_norespond = "You doesn't have started RESPOND\nLaunch RESPOND and try again\n"; |
179 |
$msg_strangeerr = "Some serverside error\nTry again or contact administrator\n"; |
180 |
### German: |
181 |
# $msg_to = "an"; |
182 |
# $msg_ignored = "ignoriert"; |
183 |
# $msg_spooled = "gespoolt"; |
184 |
# $msg_failed = "fehlgeschlagen"; |
185 |
# $msg_norespond = "Respond laeuft nicht.\nBitte Respond starten und nochmal versuchen.\n"; |
186 |
# $msg_strangeerr = "Fehler im Faxserver.\nBitte den Administrator benachrichtigen.\n"; |
187 |
|
188 |
### allow file for faxnumbers |
189 |
$allowfile = 1; |
190 |
$filechar = '@'; |
191 |
|
192 |
### set $debug to 1 for debug messages and $nosendondebug to 1 if |
193 |
### you don't want to spool files on debug |
194 |
### debug messages go to syslog (or stderr, if called from commandline) |
195 |
$debug = 0; |
196 |
$nosendondebug = 1; |
197 |
|
198 |
### NT Terminal server and Win2000 sends out bogus print requests with |
199 |
### short files. Treat requests with files less than this size as bogus. |
200 |
$minfaxsize = "100"; |
201 |
|
202 |
### extra config info for NT Terminal server. |
203 |
### If you don't have an NT terminal server you can safely ignore this |
204 |
### section. Currently only one terminal server is supported. |
205 |
|
206 |
# IP address of the terminal server, leave empty if you have none |
207 |
# $termserver_ip = "192.168.101.171"; |
208 |
$termserver_ip = ""; |
209 |
|
210 |
# Array of user-port assignments |
211 |
# If a request comes from the terminal server from one of the |
212 |
# users in the array the assigned port will be used instead of the |
213 |
# default port to connect to Respond |
214 |
%respond_port = ( |
215 |
# Samples |
216 |
# "me", "5556", |
217 |
# "myself", "5557", |
218 |
# "and_I", "5558" |
219 |
); |
220 |
|
221 |
### |
222 |
### NOTHING else to configure |
223 |
### |
224 |
|
225 |
### Message buffer for smbclient (to avoid timeout) |
226 |
my($messagebuffer); |
227 |
$messagebuffer = ''; |
228 |
|
229 |
### Append a message to message buffer |
230 |
sub smbmessage { |
231 |
$messagebuffer .= "@_"; |
232 |
} |
233 |
|
234 |
### Send message buffer to windows client |
235 |
my($smbhost); |
236 |
sub sendmessage { |
237 |
if ($messagebuffer && $smbclient && (!$debug || ($debug && ! -t STDERR))) { |
238 |
open(SF,"|$smbclient -M $smbhost") || ($smbclient = ""); |
239 |
$last = select(SF); $| = 1; select($last); |
240 |
printf SF "$messagebuffer"; |
241 |
close(SF); |
242 |
} |
243 |
} |
244 |
|
245 |
### Error functions |
246 |
|
247 |
sub norespond { |
248 |
if ($smbclient) { |
249 |
&smbmessage("$msg_norespond"); |
250 |
&sendmessage(); |
251 |
} |
252 |
die "@_"; |
253 |
} |
254 |
|
255 |
sub strangeerr { |
256 |
if ($smbclient) { |
257 |
&smbmessage("$msg_strangeerr"); |
258 |
&sendmessage(); |
259 |
} |
260 |
die "@_"; |
261 |
} |
262 |
|
263 |
sub silenterr { |
264 |
die "@_"; |
265 |
} |
266 |
|
267 |
### If called non interactivly ... use the logger to report errors |
268 |
### in syslog |
269 |
|
270 |
-t STDERR |
271 |
|| open(STDERR, "|logger -itprintfax") |
272 |
|| die "$0\[$$]: Can't open logger: $!\n"; |
273 |
|
274 |
|
275 |
### Make STDERR unbuffered |
276 |
$last = select(STDERR); $| = 1; |
277 |
select($last); |
278 |
|
279 |
if ($debug) { |
280 |
print STDERR "$version started with: ", join(" ",@ARGV), "\n"; |
281 |
} |
282 |
|
283 |
### COMMAND line processing |
284 |
my($remote_ip, $faxfile, $smbuser, $faxfname); |
285 |
|
286 |
# 1.: The ip address (smb.conf: %I) |
287 |
$remote_ip = $ARGV[0]; |
288 |
# 2.: The name of the faxfile with path (%s) |
289 |
$faxfile = $ARGV[1]; |
290 |
# 3.: The samba session setup user (%U) |
291 |
# used for accounting and if RESPOND doesn't return the user name |
292 |
$smbuser = $ARGV[2]; |
293 |
# 4.: The NetBIOS hostname (%m) |
294 |
$smbhost = $ARGV[3]; |
295 |
|
296 |
# Strip any domain from smbhost if required |
297 |
# (sometimes %m gets the full qualified internet name) |
298 |
$smbhost =~ s/^([^.]+).*$/$1/; |
299 |
|
300 |
# Strip path from filename |
301 |
($faxfname = $faxfile) =~ s|.*/||; |
302 |
|
303 |
### Check on the file that samba handed us |
304 |
if (!(-f $faxfile)) { |
305 |
&strangeerr( "$0\[$$]: Fax file given on the command line doesn't exist.\n"); |
306 |
} |
307 |
if (-z $faxfile) { |
308 |
&silenterr( "$0\[$$]: Fax file given on the command line is zero length.\n"); |
309 |
} |
310 |
if ((-s $faxfile) < $minfaxsize) { |
311 |
&silenterr( "$0\[$$]: Fax file size is less than $minfaxsize.\n"); |
312 |
} |
313 |
|
314 |
### See if we're talking to a user on a terminal server |
315 |
if ($remote_ip eq $termserver_ip) { |
316 |
# get the user name |
317 |
$ts_user = $smbuser; |
318 |
$ts_user =~ tr/A-Z/a-z/; |
319 |
|
320 |
# if the terminal server user has a different port number |
321 |
# assigned to the respond program, reset $port to match it. |
322 |
if ($respond_port{$ts_user}) { |
323 |
$port = $respond_port{$ts_user}; |
324 |
} |
325 |
if ($debug) { |
326 |
print STDERR "User $ts_user is on a Terminal Server. Using port $port for respond.\n"; |
327 |
} |
328 |
} |
329 |
|
330 |
|
331 |
### Check config |
332 |
if (($cmdlinefmt ne 'hylafax') && ($cmdlinefmt ne 'mgetty')) { |
333 |
&strangeerr( "$0\[$$]: Illegal value for cmdlinefmt: $cmdlinefmt\n"); |
334 |
} |
335 |
|
336 |
### Establish the socket connection |
337 |
my($ip_remote, $remote, $proto); |
338 |
$proto = getprotobyname('tcp'); |
339 |
|
340 |
# Since version 5.002 perl uses new ipc method |
341 |
if ( $] < 5.002 ) { |
342 |
# This is for perl versions below 5.002 |
343 |
|
344 |
my($ip_local, $local); |
345 |
$ip_local = (gethostbyname(hostname()))[4]; |
346 |
$local = &Socket::sockaddr_in(AF_INET, 0, unpack('C4', $ip_local)); |
347 |
|
348 |
# This does not work on some systems (gethostbyname doesn't work properly): |
349 |
# $ip_remote = (gethostbyname($remote_ip))[4] || |
350 |
# &strangeerr("$0\[$$]: No such host: $remote_ip\n"); |
351 |
# $remote = &Socket::sockaddr_in(AF_INET, $port, unpack('C4', $ip_remote)); |
352 |
|
353 |
# so we use this: |
354 |
$remote = &Socket::sockaddr_in(AF_INET, $port, split(/\./, $remote_ip)); |
355 |
|
356 |
if ($debug) { |
357 |
print STDERR "trying to connect to $remote_ip as ", |
358 |
join ('.', unpack('C4', $ip_local)), "\n"; |
359 |
} |
360 |
|
361 |
socket(S, AF_INET, SOCK_STREAM, $proto) |
362 |
|| &strangeerr("$0\[$$]: Can't get socket: $!\n"); |
363 |
|
364 |
bind(S, $local) || &strangeerr("$0\[$$]: Can't bind socket: $!\n"); |
365 |
|
366 |
} else { |
367 |
# This must be used since perl version 5.002 |
368 |
|
369 |
# This seams to work: |
370 |
$ip_remote = inet_aton($remote_ip) || &strangeerr("$0\[$$]: No host: $remote_ip\n"); |
371 |
$remote = sockaddr_in($port, $ip_remote); |
372 |
|
373 |
# if not, try this: |
374 |
# $remote = sockaddr_in($port, pack('C4', split(/\./, $remote_ip))); |
375 |
|
376 |
if ($debug) { |
377 |
print STDERR "trying to connect to $remote_ip\n"; |
378 |
} |
379 |
|
380 |
socket(S, PF_INET, SOCK_STREAM, $proto) |
381 |
|| &strangeerr("$0\[$$]: Can't get socket: $!\n"); |
382 |
|
383 |
} |
384 |
connect(S, $remote) || &norespond("$0\[$$]: Can't connect to $remote_ip: $!\n"); |
385 |
|
386 |
|
387 |
if ($debug) { |
388 |
print STDERR "connected\n"; |
389 |
} |
390 |
|
391 |
### Get the needed information |
392 |
my($faxnum, $user, $faxreceiver, $fullname, $delayed); |
393 |
|
394 |
# Read FaxNr, User, Receivers name and Users fullname |
395 |
# as well as strip trailing \n or \r |
396 |
($faxnum = <S>) =~ tr/\r\n//d; |
397 |
($user = <S>) =~ tr/\r\n//d; |
398 |
($faxreceiver = <S>) =~ tr/\r\n//d; |
399 |
($fullname = <S>) =~ tr/\r\n//d; |
400 |
($delayed = <S>) =~ tr/\r\n//d; |
401 |
|
402 |
if ($debug) { |
403 |
print STDERR "got faxnumber: $faxnum\n"; |
404 |
print STDERR "got receiver : $faxreceiver\n"; |
405 |
print STDERR "got sender : $user\n"; |
406 |
print STDERR "got fullname : $fullname\n"; |
407 |
print STDERR "got delay : $delayed\n"; |
408 |
} |
409 |
|
410 |
# use default delay if respond's delay checkbox checked |
411 |
if ( $delayed eq 'delayed' ) { $delayed = $defaultdelay; } |
412 |
|
413 |
# Close the query connection |
414 |
close(S); |
415 |
|
416 |
# use samba user if no user is given |
417 |
$user = $smbuser unless $user; |
418 |
|
419 |
# allways use smbuser (look in the configuration section) |
420 |
$user = $smbuser if $usesmbuser; |
421 |
|
422 |
# user needs to lowercased too |
423 |
$user =~ tr/A-Z/a-z/; |
424 |
|
425 |
my(@faxnums, $gcos); |
426 |
|
427 |
# split space or comma delimited faxnums (for more then one receiver) |
428 |
@faxnums = split(/[ ,]+/, $faxnum); |
429 |
|
430 |
|
431 |
# Retrieve additional information about the user (here: the users |
432 |
# fullname) and the date |
433 |
|
434 |
# Extract fullname from /etc/passwd |
435 |
# only if we didn't get it from respond |
436 |
$fullname =~ s/^ *(.*) *$/\1/; |
437 |
if ( ! $fullname ) { |
438 |
$gcos = (getpwnam($user))[6]; |
439 |
$fullname = (split(/,/, $gcos))[0]; |
440 |
} |
441 |
$fullname = $user unless $fullname; |
442 |
|
443 |
### OK, do accounting |
444 |
|
445 |
# What says the clock? |
446 |
my($s, $m, $h, $dy, $mo, $yr); |
447 |
($s, $m, $h, $dy, $mo, $yr) = (localtime(time))[0..5]; |
448 |
$mo++; # month is 0 based. |
449 |
|
450 |
my($host, $faxdest); |
451 |
|
452 |
# Log smb or inet hostname (look in the configuration section) |
453 |
if ( $logsmbhostname ) { |
454 |
|
455 |
# Use the NetBIOS name for accounting: |
456 |
$host = "$smbhost($remote_ip)"; |
457 |
|
458 |
# Uppercase looks more NetBIOS like :-) |
459 |
# uncomment if you don't want this |
460 |
$host =~ tr/a-z/A-Z/; |
461 |
|
462 |
} else { |
463 |
|
464 |
# Use the internet name for accounting: |
465 |
$host = (gethostbyaddr(pack('C4', split(/\./, $remote_ip)),AF_INET))[0]; |
466 |
|
467 |
# Strip domains from name |
468 |
$host =~ s/^([^.]+).*$/$1/; |
469 |
$host = ($host) ? "$host($remote_ip)" : $remote_ip; |
470 |
|
471 |
} |
472 |
|
473 |
# Open the accounting file |
474 |
open(ACCT, ">>$acct") || &strangeerr("$0\[$$]: Can't open `$acct': $!\n"); |
475 |
|
476 |
# Make it unbuffered |
477 |
$last = select(ACCT); $| = 1; |
478 |
select($last); |
479 |
|
480 |
|
481 |
# If no faxnum is given it's assumed that cancelling the fax is ok. |
482 |
scalar(@faxnums) || do { |
483 |
printf ACCT "[%02d/%02d/%02d] %02d:%02d:%02d Fax from $host by $smbuser", |
484 |
$mo, $dy, $yr, $h, $m, $s; |
485 |
if ( $faxreceiver ) { |
486 |
print ACCT " to $faxreceiver"; |
487 |
$faxdest = " " . $msg_to . " $faxreceiver"; |
488 |
} |
489 |
print ACCT " cancelled\n"; |
490 |
if ($smbclient) { |
491 |
&smbmessage("Fax $faxfname$faxdest $msg_ignored\n"); |
492 |
&sendmessage(); |
493 |
} |
494 |
close(ACCT); |
495 |
if ($debug) { |
496 |
print STDERR "No faxnumbers given. Fax cancelled. Aborting\n"; |
497 |
} |
498 |
exit 0; |
499 |
}; |
500 |
|
501 |
### Spool it |
502 |
|
503 |
my(@fixargs, @faxargs, $fnum, $retval); |
504 |
|
505 |
# Arguments for faxspool call |
506 |
# --- Change this for other fax programs |
507 |
if ($cmdlinefmt eq 'hylafax') { |
508 |
@fixargs = ("-f",$user,"-r", $fullname); |
509 |
} elsif ($cmdlinefmt eq 'mgetty') { |
510 |
@fixargs = ("-q","-f","$user","-F","$fullname"); |
511 |
} |
512 |
@fixargs = (@fixargs,@faxspool_args) if @faxspool_args; |
513 |
|
514 |
# set delay if required |
515 |
if ( ($delayed ne '') && $usedelay ) { |
516 |
# Additional argument for faxspool call |
517 |
# --- Change this for other fax programs |
518 |
if ($cmdlinefmt eq 'hylafax') { |
519 |
push(@fixargs,"-a",$delayed); |
520 |
} elsif ($cmdlinefmt eq 'mgetty') { |
521 |
@fixargs = (@fixargs,"-t","$delayed"); |
522 |
} |
523 |
} |
524 |
|
525 |
# do the "faxnumbers in a file" handling |
526 |
|
527 |
my(@newfaxnums, @numfiles1, @numfiles2, @files, $file, $fnum2); |
528 |
|
529 |
if ($allowfile) { |
530 |
|
531 |
# seperate between faxnumbers and filenames |
532 |
foreach $fnum (@faxnums) { |
533 |
if (substr($fnum,0,1) eq $filechar ) { |
534 |
push(@numfiles1, $fnum); |
535 |
} else { |
536 |
push(@newfaxnums, $fnum); |
537 |
} |
538 |
} |
539 |
@faxnums = @newfaxnums; |
540 |
|
541 |
# now process the file(s), a file can contain other filenames |
542 |
while (scalar(@numfiles1)) { |
543 |
foreach $fnum (@numfiles1) { |
544 |
$file = substr($fnum, 1); |
545 |
|
546 |
# Don't read a file twice (avoid endless loop)! |
547 |
next if scalar(grep($_ eq $file, @files)); |
548 |
push(@files, $file); |
549 |
|
550 |
# Get user's home dir, if path is not absolute |
551 |
if (substr($file,0,1) ne '/') { |
552 |
$file = (getpwnam($smbuser))[7] . "/$file"; |
553 |
} |
554 |
|
555 |
# Read a file |
556 |
|
557 |
if ($debug) { |
558 |
print STDERR "read file $file - "; |
559 |
} |
560 |
|
561 |
if (open(NUMBERS,"<$file")) { |
562 |
while (<NUMBERS>) { |
563 |
|
564 |
# remove \r and \n |
565 |
tr/\r\n//d; |
566 |
|
567 |
# remove trailing blanks |
568 |
s/^ *(.*) *$/$1/; |
569 |
|
570 |
# ignore comments |
571 |
next if /^#/; |
572 |
|
573 |
# separate between faxnumbers and filenames |
574 |
foreach $fnum2 (split(/[ ,]+/)) { |
575 |
if (substr($fnum2,0,1) eq $filechar) { |
576 |
push(@numfiles2, $fnum2); |
577 |
} else { |
578 |
push(@faxnums, $fnum2); |
579 |
} |
580 |
} |
581 |
} |
582 |
close(NUMBERS); |
583 |
|
584 |
if ($debug) { |
585 |
print STDERR "ok\n", |
586 |
} |
587 |
|
588 |
} elsif ($debug) { |
589 |
print STDERR "failed\n"; |
590 |
} |
591 |
} |
592 |
|
593 |
# recurse files |
594 |
@numfiles1 = @numfiles2; |
595 |
@numfiles2 = (); |
596 |
|
597 |
} |
598 |
} |
599 |
|
600 |
# preprocess faxnumbers |
601 |
if ( $intl_with || $unillegal || $unillegalnumbers) { |
602 |
for($tmp=0; $tmp<scalar(@faxnums); $tmp++) { |
603 |
$faxnums[$tmp] =~ s/^\+/$intl_with/ if $intl_with; |
604 |
if ( $unillegalnumbers ) { |
605 |
$_ = $faxnums[$tmp]; |
606 |
# remove separator chars |
607 |
eval "tr[$unillegalnumbers][]d;"; |
608 |
$faxnums[$tmp] = $_ if tr/*0-9// == length; |
609 |
} else { |
610 |
# remove all except digits and * |
611 |
$faxnums[$tmp] =~ tr/*0-9//cd if $unillegal; |
612 |
} |
613 |
} |
614 |
} |
615 |
# delete duplicate faxnumbers |
616 |
@newfaxnums = sort(@faxnums); |
617 |
@faxnums = (); |
618 |
$fnum2 = ""; |
619 |
while ($fnum = shift(@newfaxnums)) { |
620 |
push(@faxnums, $fnum) if ($fnum ne $fnum2); |
621 |
$fnum2 = $fnum; |
622 |
} |
623 |
|
624 |
|
625 |
# Spool it once for every number in $faxnum |
626 |
foreach $fnum (@faxnums) { |
627 |
printf ACCT "[%02d/%02d/%02d] %02d:%02d:%02d Fax from $host by $smbuser ", |
628 |
$mo, $dy, $yr, $h, $m, $s; |
629 |
|
630 |
# Build faxspool arguments from above arguments, number and file |
631 |
# --- Change this for other fax programs |
632 |
if( $cmdlinefmt eq 'hylafax' ) { |
633 |
if ( $faxreceiver ) { |
634 |
# Add receivers name to faxspool arguments |
635 |
@faxargs = (@fixargs,"-d",$faxreceiver . '@'. $fnum,$faxfile); |
636 |
} else { |
637 |
@faxargs = (@fixargs,"-d",$fnum,$faxfile); |
638 |
} |
639 |
} elsif ( $cmdlinefmt eq 'mgetty' ) { |
640 |
@faxargs = (@fixargs,$fnum,$faxfile); |
641 |
if ( $faxreceiver ) { |
642 |
# Add receivers name to faxspool arguments |
643 |
@faxargs = ("-D","$faxreceiver",@faxargs); |
644 |
} |
645 |
} else { |
646 |
@faxargs = (@fixargs,$fnum,$faxfile); |
647 |
} |
648 |
|
649 |
if ( $faxreceiver ) { |
650 |
print ACCT "to $faxreceiver ($fnum)"; |
651 |
$faxdest = "$faxreceiver ($fnum)"; |
652 |
} else { |
653 |
print ACCT "to $fnum"; |
654 |
$faxdest = "$fnum"; |
655 |
} |
656 |
|
657 |
# Call the fax spooler |
658 |
if ($debug) { |
659 |
print STDERR "simulate " if ($nosendondebug); |
660 |
print STDERR "call: $faxspool ", join(" ", @faxargs), "\n"; |
661 |
} |
662 |
if (!$debug || ($debug && !$nosendondebug)) { |
663 |
system($faxspool, @faxargs); |
664 |
} |
665 |
|
666 |
|
667 |
# Report the state to the logfile |
668 |
$retval = $?; |
669 |
if ($debug && !$nosendondebug) { |
670 |
print STDERR "spooling "; |
671 |
print STDERR ($retval == 0) ? "succeeded\n" : "failed\n"; |
672 |
} |
673 |
print ACCT (($retval == 0) ? " spooled\n" : " failed\n"); |
674 |
if ($smbclient) { |
675 |
&smbmessage("Fax $faxfname $msg_to $faxdest " ); |
676 |
&smbmessage(($retval == 0) ? $msg_spooled : $msg_failed ); |
677 |
&smbmessage("\n"); |
678 |
} |
679 |
} |
680 |
|
681 |
### Done |
682 |
if ($smbclient) { |
683 |
&sendmessage(); |
684 |
} |
685 |
close(ACCT); |
686 |
exit 0; |