HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [hylafax-users] Generating a Caller-ID only log file



Aidan Van Dyk wrote:

OK - I'm all for moving towards consolidating QualifyCID and
DynamicConfig.  I'm not a big fan using the exit value to control the
accept/reject behaviour.  I'ld favour a printed command ("ACCEPT\n", or
"REJECT\n", or something like "RejectCall: <boolean>\n", etc.


The attached patch does this (remove QualifyCID and move DynamicConfig to precede call answering) and expects "REJECT" from DynamicConfig (case insensitive) in order to reject calls the way that QualifyCID did before.


Lee.
diff -Nru hylafax.orig/faxd/faxGettyApp.c++ hylafax/faxd/faxGettyApp.c++
--- hylafax.orig/faxd/faxGettyApp.c++	2006-03-15 05:20:59.187776192 -0800
+++ hylafax/faxd/faxGettyApp.c++	2006-03-14 17:37:49.000000000 -0800
@@ -64,9 +64,6 @@
 {
     devfifo = -1;
     modemLock = NULL;
-    lastCIDModTime = 0;
-    cidPats = NULL;
-    acceptCID = NULL;
     setupConfig();
 
     fxAssert(_instance == NULL, "Cannot create multiple faxGettyApp instances");
@@ -75,8 +72,6 @@
 
 faxGettyApp::~faxGettyApp()
 {
-    delete acceptCID;
-    delete cidPats;
     delete modemLock;
 }
 
@@ -330,62 +325,66 @@
     bool callResolved;
     bool advanceRotary = true;
     fxStr emsg;
-    if (!isCIDOk(callid.size() > CallID::NUMBER ? callid.id(CallID::NUMBER) : "")) {	// check Caller ID if present
+    bool oktoanswer = true;
+    fxStr callid_formatted = "";
+    for (u_int i = 0; i < callid.size(); i++)
+	callid_formatted.append(quote | callid.id(i) | enquote);
+    if (callid_formatted.length()) traceProtocol("CallID:%s", (const char*) callid_formatted);
+    if (dynamicConfig.length()) {
+	fxStr cmd(dynamicConfig | quote | getModemDevice() | enquote | callid_formatted);
+	fxStr localid = "";
+	int pipefd[2], idlength, status;
+	char line[1024];
+	pipe(pipefd);
+	pid_t pid = fork();
+	switch (pid) {
+	    case -1:
+		emsg = "Could not fork for local ID.";
+		logError("%s", (const char*)emsg);
+		Sys::close(pipefd[0]);
+		Sys::close(pipefd[1]);
+		break;
+	    case  0:
+		dup2(pipefd[1], STDOUT_FILENO);
+		Sys::close(pipefd[0]);
+		Sys::close(pipefd[1]);
+		execl("/bin/sh", "sh", "-c", (const char*) cmd, (char*) NULL);
+		sleep(1);
+		exit(1);
+	    default:
+		Sys::close(pipefd[1]);
+		{
+		    FILE* fd = fdopen(pipefd[0], "r");
+		    while (fgets(line, sizeof (line)-1, fd)) {
+			line[strlen(line)-1]='\0';		// Nuke \n at end of line
+			if (strcasecmp(line, "REJECT") == 0) {
+			    oktoanswer = false;
+			} else {
+			    (void) readConfigItem(line);
+			}
+		    }
+		    Sys::waitpid(pid, status);
+		    if (status != 0) {
+			emsg = fxStr::format("Bad exit status %#o for \'%s\'", status, (const char*) cmd);
+			logError("%s", (const char*)emsg);
+		    }
+		    // modem settings may have changed...
+		    FaxModem* modem = (FaxModem*) ModemServer::getModem();
+		    modem->pokeConfig(false);
+		}
+		Sys::close(pipefd[0]);
+		break;
+	}
+    }
+    if (!oktoanswer) {		// call rejected by DynamicConfig
 	/*
 	 * Call was rejected based on Caller ID information.
 	 */
-	emsg = "ANSWER: CID REJECTED";
+	emsg = "ANSWER: CALL REJECTED";
 	traceServer("%s", (const char*)emsg);
 	callResolved = false;
 	advanceRotary = false;
     } else {
-	fxStr callid_formatted = "";
-	for (u_int i = 0; i < callid.size(); i++)
-	    callid_formatted.append(quote | callid.id(i) | enquote);
-	if (callid_formatted.length()) traceProtocol("CallID:%s", (const char*) callid_formatted);
-	if (dynamicConfig.length()) {
-	    fxStr cmd(dynamicConfig | quote | getModemDevice() | enquote | callid_formatted);
-	    fxStr localid = "";
-	    int pipefd[2], idlength, status;
-	    char line[1024];
-	    pipe(pipefd);
-	    pid_t pid = fork();
-	    switch (pid) {
-		case -1:
-		    emsg = "Could not fork for local ID.";
-		    logError("%s", (const char*)emsg);
-		    Sys::close(pipefd[0]);
-		    Sys::close(pipefd[1]);
-		    break;
-		case  0:
-		    dup2(pipefd[1], STDOUT_FILENO);
-		    Sys::close(pipefd[0]);
-		    Sys::close(pipefd[1]);
-		    execl("/bin/sh", "sh", "-c", (const char*) cmd, (char*) NULL);
-		    sleep(1);
-		    exit(1);
-		default:
-		    Sys::close(pipefd[1]);
-		    {
-			FILE* fd = fdopen(pipefd[0], "r");
-			while (fgets(line, sizeof (line)-1, fd)){
-			    line[strlen(line)-1]='\0';		// Nuke \n at end of line
-			    (void) readConfigItem(line);
-			}
-			Sys::waitpid(pid, status);
-			if (status != 0)
-			{
-			    emsg = fxStr::format("Bad exit status %#o for \'%s\'", status, (const char*) cmd);
-			    logError("%s", (const char*)emsg);
-			}
-			// modem settings may have changed...
-			FaxModem* modem = (FaxModem*) ModemServer::getModem();
-			modem->pokeConfig(false);
-		    }
-		    Sys::close(pipefd[0]);
-		    break;
-	    }
-	}
 	if (ctype != ClassModem::CALLTYPE_UNKNOWN) {
 	    /*
 	     * Distinctive ring or other means has already identified
@@ -742,13 +741,6 @@
     }
 }
 
-bool
-faxGettyApp::isCIDOk(const fxStr& cid)
-{
-    updatePatterns(qualifyCID, cidPats, acceptCID, lastCIDModTime);
-    return (qualifyCID == "" ? true : checkACL(cid, cidPats, *acceptCID));
-}
-
 /*
  * Notification handlers.
  */
@@ -986,7 +978,6 @@
 #define	N(a)	(sizeof (a) / sizeof (a[0]))
 
 faxGettyApp::stringtag faxGettyApp::strings[] = {
-{ "qualifycid",		&faxGettyApp::qualifyCID },
 { "gettyargs",		&faxGettyApp::gettyArgs },
 { "vgettyargs",		&faxGettyApp::vgettyArgs },
 { "egettyargs",		&faxGettyApp::egettyArgs },
diff -Nru hylafax.orig/faxd/faxGettyApp.h hylafax/faxd/faxGettyApp.h
--- hylafax.orig/faxd/faxGettyApp.h	2006-03-15 05:20:59.189775888 -0800
+++ hylafax/faxd/faxGettyApp.h	2006-03-14 17:31:01.000000000 -0800
@@ -67,10 +67,6 @@
 
     u_short	ringsBeforeAnswer;	// # rings to wait
     u_short	ringsHeard;		// # rings received
-    fxStr	qualifyCID;		// if set, no answer w/o acceptable cid
-    time_t	lastCIDModTime;		// last mod time of CID patterns file
-    REArray*	cidPats;		// recv cid patterns
-    fxBoolArray* acceptCID;		// accept/reject matched cid
     CallID	received_callid;	// non-null received CNID
     fxStr	gettyArgs;		// getty arguments
     fxStr	vgettyArgs;		// voice getty arguments
@@ -109,7 +105,6 @@
     bool	setupModem(bool isSend);
     void	discardModem(bool dropDTR);
 // inbound call handling
-    bool	isCIDOk(const fxStr& cid);
     bool	processCall(CallType ctype, fxStr& emsg, const CallID& callid);
     CallType	runGetty(const char* what,
 		    Getty* (*newgetty)(const fxStr&, const fxStr&),
diff -Nru hylafax.orig/man/callid.4f hylafax/man/callid.4f
--- hylafax.orig/man/callid.4f	2006-03-14 17:11:20.000000000 -0800
+++ hylafax/man/callid.4f	1969-12-31 16:00:00.000000000 -0800
@@ -1,136 +0,0 @@
-.\"	$Id: callid.4f,v 1.1.1.1 2005/11/11 21:32:03 faxguy Exp $
-.\"
-.\" HylaFAX Facsimile Software
-.\"
-.\" Copyright (c) 1994-1996 Sam Leffler
-.\" Copyright (c) 1994-1996 Silicon Graphics, Inc.
-.\" HylaFAX is a trademark of Silicon Graphics
-.\" 
-.\" Permission to use, copy, modify, distribute, and sell this software and 
-.\" its documentation for any purpose is hereby granted without fee, provided
-.\" that (i) the above copyright notices and this permission notice appear in
-.\" all copies of the software and related documentation, and (ii) the names of
-.\" Sam Leffler and Silicon Graphics may not be used in any advertising or
-.\" publicity relating to the software without the specific, prior written
-.\" permission of Sam Leffler and Silicon Graphics.
-.\" 
-.\" THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
-.\" EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
-.\" WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
-.\" 
-.\" IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
-.\" ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
-.\" OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-.\" WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
-.\" LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
-.\" OF THIS SOFTWARE.
-.\"
-.if n .po 0
-.ds Fx \fIHyla\s-1FAX\s+1\fP
-.TH CallID ${MANNUM4_5} "May 28, 2001"
-.SH NAME
-callid \- Call identification access control list
-.SH DESCRIPTION
-The \*(Fx configuration parameter
-.B QualifyCID
-specifies whether or not the identity or identifier of an inbound call
-should be checked against an access
-control list before the telephone is answered.
-This both enables call screening against those values and fax routing
-(in faxrcvd's FaxDispatch) based on those values.
-If a modem is attached to a phone line that has 
-Caller-ID or DNIS service, and
-.B QualifyCID
-is non-null, then only the calls identified by
-strings matching 
-.B CIDNumber (CallID1)
-in the file 
-(typically \fBetc/callid\fP) will be answered.
-.PP
-Patterns are specified one per line and must conform to the
-regular expressions syntax specified by
-.SM POSIX
-1003.2; see
-.IR re_format (7).
-Comments may be included; they are introduced with the ``#''
-character and extend to the end of the line.
-Any trailing white space on a line is ignored (for convenience
-when comments are used).
-.PP
-If a line begins with ``!'', then the regular expression identifies
-callers that should be
-.IR rejected ;
-otherwise regular expressions identify clients whose calls
-should be
-.IR accepted .
-The order of patterns in a
-.SM CallID
-file is important.
-When a call is to be answered, the 
-.I faxgetty
-process will compare the phone number presented by the modem
-against the patterns in the access control list
-in the order in which they appear in the file.
-The first pattern that matches the client's number
-is used to decide whether to accept or reject the call.
-If no patterns match the phone number
-then the call is not answered.
-Thus if you want to accept all but a restricted set of calls,
-the last line in the file should be ``^.*$''.
-.PP
-Note that regular expression patterns should be written to
-match a phone number exactly.
-That is, patterns should be of the form:
-.sp .5
-.ti +0.5i
-\fC^<pattern>$\fP
-.PP
-where the ``^'' and ``$'' characters are used to
-specify the start and end of the matching phone number.
-Additionally, regular expression patterns should handle
-white space that may appear in known locations.  For example,
-.sp .5
-.ti +0.5i
-\fC^([+]1){1}[ .-]*415[ .-]*555[ .-]*1212.*$\fP
-.PP
-matches the following phone number strings:
-.sp .5
-.nf
-.RS
-\fC+1.415.555.1212\fP
-\fC    415  555  1212\fP
-\fC1-415-555-1212\fP
-.RE
-.fi
-.PP
-Finally, note that regular expressions can be used to specify
-many numbers with one pattern.
-.SH NOTES
-The
-.B CIDNumber (CallID1)
-configuration parameter described in
-.IR hylafax-config (${MANNUM4_5})
-is used to store call identification information.
-This parameter must be present in the per-modem configuration
-file for call identification screening to function properly.
-If 
-.B QualifyCID
-is defined, but no
-.B CIDNumber (CallID1)
-is specified, then no match will occur and all
-incoming calls will be ignored.
-.PP
-Call identification data is only sent once by the telco or PBX, and the timing of
-its arrival varies upon the telco or PBX and the type of line.  If
-\*(Fx is configured to answer via
-.B RingsBeforeAnswer
-prior to the arrival of the data, then all
-.B CallID
-values will be null.  For example, on US analog lines, caller-ID
-data is usually sent between RINGs 1 and 2.  In this situation,
-.B RingsBeforeAnswer
-should be set to ``2'' or greater.
-.SH "SEE ALSO"
-.IR faxgetty (${MANNUM1_8}),
-.IR hylafax-config (${MANNUM4_5}),
-.IR re_format (7).
diff -Nru hylafax.orig/man/hylafax-config.4f hylafax/man/hylafax-config.4f
--- hylafax.orig/man/hylafax-config.4f	2006-03-15 05:20:59.199774368 -0800
+++ hylafax/man/hylafax-config.4f	2006-03-14 18:38:00.000000000 -0800
@@ -187,7 +187,6 @@
 PostScriptTimeout\(S1	integer	\s-1300\s+1	timeout on \*(Ps interpreter runs (secs)
 PriorityScheduling	boolean	\s-1\fIsee below\fP\s+1	use available priority job scheduling mechanism
 PS2FaxCmd\(S1	string	\s-1bin/ps2fax\s+1	\*(Ps \s-1RIP\s+1 command script
-QualifyCID	string	\-	file of Caller-ID or DNIS patterns for checking inbound calls
 QualifyPWD	string	\-	file of \s-1PWD\s+1 patterns for qualifying senders
 QualifyTSI	string	\-	file of \s-1TSI\s+1 patterns for qualifying senders
 RecvDataFormat	string	\s-1adaptive\s+1	format for received facsimile data
@@ -767,7 +766,7 @@
 .TP
 .B DynamicConfig
 The pathname of the optional shell script, e.g. ``etc/localid'', that 
-makes dynamic configuration changes, i.e., to 
+performs call rejection and makes dynamic configuration changes, i.e., to 
 .B LocalIdentifier,
 based on device ID and call identification.  The script is passed those
 values as the parameters ($1 = device id, $2 = CallID1, $3 = CallID2, $4 = CallID3, ...), 
@@ -778,7 +777,9 @@
 to be changed, then each item must be on its own line.
 This is commonly used to dynamically alter the local identification 
 of systems which use DID/DNIS, but it can also be used to allow different
-modem configurations for different senders.
+modem configurations for different senders.  To reject calls
+.B DynamicConfig
+should send ``REJECT'' on standard output.
 Note that this script must be marked as executable by the faxgetty process.
 .TP
 .B FAXNumber
@@ -1194,31 +1195,6 @@
 see
 .IR ps2fax (${MANNUM1_8}).
 .TP
-.B QualifyCID
-A string that specifies whether or not \fIcall identification information\fP
-should be checked against an access control list before accepting
-an inbound call.
-If 
-.B QualifyCID
-is non-null and there is call identification service,
-then only calls with 
-.B CallID1
-data matching identifications
-in the file specified by this string (typically \fBetc/cid\fP)
-will be accepted; see
-.IR callid (${MANNUM4_5}).
-If
-.B QualifyCID
-is not specified in the configuration file, or the value is
-null, then all incoming calls will be answerable.
-Note that call identification screening is only available when this
-service is enabled on the phone line and the modem is capable of
-presenting that information to the host.
-The
-.B CallIDPattern
-parameters must also be setup to reflect the manner in which
-the modem returns call identification information to the host.
-.TP
 .B QualifyPWD
 A string that specifies whether or not the identity of 
 calling facsimile machines should be checked against an access



Project hosted by iFAX Solutions