FreeBSD Port: mgetty-1.1.34
Dmitry Kostikov
kostikov at vstu.ru
Tue Feb 14 22:55:58 PST 2006
Hello.
I am using mgetty with patch (mgetty.sc.zip in attachment) by Alexey U
Gretchaninov (scorpus at iname.com, ICQ 3272821) for some time.
This patch add some features: "answer-time" and time periods. I think,
it can be useful for other people.
"answer-time" option allow to define answer periods for rings in the
mgetty.config.
Examples:
"answer-time 23"
answer only during 23-th hour.
"answer-time 23,0,1,2"
answer during 23, 0, 1 and 2 hours.
"answer-time 23-2" или "answer-time 23:00-2:00"
answer in period from 23 to 2.
"answer-time 1.23"
answer only during 23 hour at Monday.
"answer-time 7.23"
answer only during 23 hour at Sunday.
"answer-time 2.23-2.2" или "answer-time 2.23:00-2.2:00"
answer only from 23 to 2 at Tuesday.
"answer-time 2.23-5.2" или "answer-time 2.23:00-5.2:00"
answer from 23 to 2 at Tuesday, Wednesday, Thursday and Friday.
Time periods can be combined in any order:
"answer-time 23-7,6.0-7.24" or "answer-time 1.23:00-5.7:00,6.0:00-7.24:00"
Time periods support in the mgetyy.conf
Using of such construction:
{<time period>} <option>
in mgetty.conf allow to control behaviour of mgetty, depending of
current time. I.e. option <option> will be read from config only if
current time lies in the <time period>.
Examples:
==========================
{22:00-8:00} rings 1
{8:00-22:00} rings 5
==========================
From 22 to 8 mgetty will be answer from 1 ring, in the period from 8
to 22 - from 5 rings.
==================================
{1.22:00-5.8:00} rings 1
{6.00:00-7.24:00} rings 2
{1.8:00-5.22:00} rings 5
==================================
==============================
{8:00-22:00} rings 5
{8:00-22:00} fax-only y
{22:00-8:00} rings 1
{22:00-8:00} data-only y
==============================
Hints:
1. Don't forget to restart mgetty then next period comes (with cron,
for example).
For first example:
====================================
0 22 * * * killall -q mgetty
0 8 * * * killall -q mgetty
====================================
2. /etc/nologin[.device] and answer-time have more higher priority
over {<time period>}.
Also, i attach patch-x (my adaptation of original patch for current
version of mgetty+sendfax port).
I am apologize for my english. :-(
With best regards,
Dmitry Kostikov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mgetty.sc.zip
Type: application/octet-stream
Size: 11060 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20060215/679eddef/mgetty.sc.obj
-------------- next part --------------
--- cnd.c.orig Sun Apr 17 15:55:43 2005
+++ cnd.c Wed Feb 15 08:05:15 2006
@@ -85,6 +85,9 @@
/* (if AT#CID=10 is set, contributed by Edwin Groothuis) */
{"NDID=", &CalledNr},
+ /* USR Courier V.Evr with ID SDL (Russian caller ID support) */
+ {"CallerID: ", &CallerId},
+
/* yet another incompatible modem... */
{"CALLER'S NUMBER: ", &CallerId},
--- conf_mg.c.orig Thu Nov 24 19:57:58 2005
+++ conf_mg.c Wed Feb 15 08:05:15 2006
@@ -88,7 +88,9 @@
{ "rings", {1}, CT_INT, C_PRESET },
{ "msn-list", {(p_int) NULL}, CT_CHAT, C_EMPTY },
{ "get-cnd-chat", {0}, CT_CHAT, C_EMPTY },
+ { "deny-chat", {0}, CT_CHAT, C_EMPTY },
{ "cnd-program", {(p_int) NULL}, CT_STRING, C_EMPTY },
+ { "answer-time", {(p_int) NULL}, CT_STRING, C_EMPTY },
{ "answer-chat", {0}, CT_CHAT, C_EMPTY },
{ "answer-chat-timeout", {80}, CT_INT, C_PRESET },
{ "autobauding", {FALSE}, CT_BOOL, C_PRESET },
--- conf_mg.h.orig Thu Nov 24 19:57:58 2005
+++ conf_mg.h Wed Feb 15 08:05:15 2006
@@ -33,7 +33,9 @@
rings_wanted, /* number of RINGs */
msn_list, /* ISDN MSNs (dist.ring) */
getcnd_chat, /* get caller ID (for ELINK)*/
+ deny_chat, /* hangup modem chat */
cnd_program, /* accept caller? */
+ answer_time, /* Answer time */
answer_chat, /* ATA...CONNECT...""...\n */
answer_chat_timeout, /* longer as S7! */
autobauding,
--- config.c.orig Sun Feb 28 22:17:55 1999
+++ config.c Wed Feb 15 08:05:15 2006
@@ -12,6 +12,7 @@
#include "syslibs.h"
#include <ctype.h>
#include <string.h>
+#include <time.h>
#ifndef ENOENT
#include <errno.h>
#endif
@@ -19,6 +20,8 @@
#include "mgetty.h"
#include "config.h"
+int is_time_now(char *);
+
/* read a line from FILE * fp, terminated by "\n"
* the line can be of any length (buffer will dynamically grow)
* - trailing "\n" is chopped off
@@ -323,6 +326,13 @@
{
norm_line( &line, &key );
if ( key[0] == 0 ) continue; /* empty line */
+
+ if( key[0] == '{')
+ {
+ if( strchr(key, '}') ) *strchr( key, '}' ) = 0;
+ if( !is_time_now( key + 1 ) ) continue;
+ norm_line( &line, &key );
+ }
lprintf( L_NOISE, "conf lib: read: '%s %s'", key, line );
@@ -419,6 +429,216 @@
return NOERROR;
}
+
+int is_time_now(char *timeRanges)
+{
+int firstDay, secondDay, firstHour, firstMinute, secondHour, secondMinute,
+ firstMark, secondMark, currentMark, Day, Hour, Min;
+char *p, *s, *f, *rs, *r;
+time_t Time;
+struct tm *localTime;
+
+if(!strlen(timeRanges))
+ {
+ lprintf( L_ERROR, "empty timerange(s) string!");
+ return 0;
+ }
+
+if(!(rs = strdup(timeRanges))) return 0;
+
+lprintf( L_NOISE, "work timerange(s): \"%s\"", rs);
+
+for(r = strtok(rs, ","); r; r = strtok(NULL, ","))
+ {
+ if(!strcasecmp(r, "CM")) { free(rs); return 1;}
+ if(!strlen(r)) continue;
+
+ firstDay = -1;
+ secondDay = -1;
+ firstHour = -1;
+ firstMinute = -1;
+ secondHour = -1;
+ secondMinute = -1;
+
+ lprintf( L_NOISE, "timerange: \"%s\"", r);
+
+ if((p = strchr(r, '-')))
+ {
+ if((s = strchr(r, '.')))
+ {
+ firstDay = atoi(s - 1);
+ firstHour = atoi(s + 1);
+ if((f = strchr(s + 1, ':')) && f < p) firstMinute = atoi(f + 1);
+
+ if((s = strchr(p + 1, '.')))
+ {
+ secondDay = atoi(s - 1);
+ secondHour = atoi(s + 1);
+ if((f = strchr(s + 1, ':'))) secondMinute = atoi(f + 1);
+ }
+ else
+ {
+ lprintf( L_ERROR, "can't parse timerange: \"%s\"", r);
+ free(rs);
+ return 0;
+ }
+ }
+ else
+ {
+ firstHour = atoi(r);
+ if((f = strchr(r, ':')) && f < p) firstMinute = atoi(f + 1);
+ secondHour = atoi(p + 1);
+ if((f = strchr(p + 1, ':'))) secondMinute = atoi(f + 1);
+ }
+ }
+ else
+ {
+ if((s = strchr(r, '.')))
+ {
+ firstDay = atoi(s - 1);
+ firstHour = atoi(s + 1);
+ if((p = strchr(s + 1,':'))) firstMinute = atoi(p + 1);
+ }
+ else
+ {
+ firstHour = atoi(r);
+ if((p = strchr(r,':'))) firstMinute = atoi(p + 1);
+ }
+ }
+
+ if( firstDay < -1 || firstDay > 7 || firstDay == 0 || firstHour < -1 ||
+ firstHour > 23 || firstMinute< -1 || firstMinute > 59 || secondDay < -1
+ || secondDay > 7 || secondDay == 0 || secondHour < -1 ||
+ secondHour > 24 || secondMinute < -1 || secondMinute > 59 ||
+ firstHour == -1 || (secondDay != -1 && secondHour == -1))
+ {
+ lprintf( L_ERROR, "can't parse timerange: \"%s\"", r);
+ free(rs);
+ return 0;
+ }
+
+ lprintf( L_NOISE, "parsed timerange: %i.%i:%i - %i.%i:%i", firstDay,
+ firstHour, firstMinute, secondDay, secondHour, secondMinute);
+
+ Time = time(NULL);
+ localTime = localtime(&Time);
+
+ Day = localTime->tm_wday;
+ if(!Day) Day = 7;
+ Hour = localTime->tm_hour;
+ Min = localTime->tm_min;
+
+ lprintf( L_NOISE, "current time: day %u, hour %u, min %u", Day, Hour, Min);
+
+ firstMark = firstHour * 60;
+ if(firstMinute != -1) firstMark += firstMinute;
+
+ secondMark = secondHour * 60;
+ if(secondMinute != -1) secondMark += secondMinute;
+
+ currentMark = Hour * 60 + Min;
+
+ lprintf( L_NOISE, "firstmark: %i, secondmark: %i, currentmark: %i",
+ firstMark, secondMark, currentMark);
+
+ if(secondDay != -1)
+ {
+ if(firstDay < secondDay)
+ {
+ if(Day >= firstDay && Day <= secondDay)
+ {
+ if(firstMark < secondMark)
+ {
+ if(currentMark >= firstMark && currentMark < secondMark)
+ { free(rs); return 1; }
+ }
+ else
+ {
+ if(currentMark >= firstMark || currentMark < secondMark)
+ { free(rs); return 1; }
+ }
+ }
+ }
+ else
+ {
+ if(firstDay == secondDay)
+ {
+ if(Day == firstDay)
+ {
+ if(firstMark < secondMark)
+ {
+ if(currentMark >= firstMark && currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ else
+ {
+ if(currentMark >= firstMark || currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ }
+ }
+ else
+ {
+ if(Day >= firstDay || Day <= secondDay)
+ {
+ if(firstMark < secondMark)
+ {
+ if(currentMark >= firstMark && currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ else
+ {
+ if(currentMark >= firstMark || currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ }
+ }
+ }
+ }
+ else if(secondHour != -1)
+ {
+ if(firstMark < secondMark)
+ {
+ if(currentMark >= firstMark && currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ else
+ {
+ if(currentMark >= firstMark || currentMark < secondMark)
+ { free(rs); return 1;}
+ }
+ }
+ else if(firstDay != -1)
+ {
+ if(firstMinute != -1)
+ {
+ if(Day == firstDay && Hour == firstHour && Min == firstMinute)
+ { free(rs); return 1;}
+ }
+ else
+ {
+ if(Day == firstDay && Hour == firstHour)
+ { free(rs); return 1;}
+ }
+ }
+ else
+ {
+ if(firstMinute != -1)
+ {
+ if(Hour == firstHour && Min == firstMinute)
+ { free(rs); return 1;}
+ }
+ else
+ {
+ if(Hour == firstHour)
+ { free(rs); return 1;}
+ }
+ }
+ }
+
+free(rs);
+return 0;
+}
/* makepath
*
* only needed on non-ANSI-compilers or for non-fixed arguments
--- mgetty.c.orig Thu Nov 24 20:00:30 2005
+++ mgetty.c Wed Feb 15 08:05:15 2006
@@ -38,6 +38,8 @@
#include "voice/include/voice.h"
#endif
+int is_time_now(char *);
+
/* how much time may pass between two RINGs until mgetty goes into */
/* "waiting" state again */
int ring_chat_timeout = 10;
@@ -613,6 +615,14 @@
break;
}
#endif
+
+ if(c_string(answer_time) && !is_time_now(c_string(answer_time)))
+ {
+ lprintf( L_MESG, "out of answer time - do not accept call!");
+ mgetty_state = St_nologin;
+ break;
+ }
+
mgetty_state = St_wait_for_RINGs;
break;
@@ -657,8 +667,24 @@
&what_action, &dist_ring ) == SUCCESS )
{
rings++;
- if ( access( buf, F_OK ) != 0 || /* removed? */
- virtual_ring == TRUE ) /* SIGUSR1? */
+ if ( access( buf, F_OK ) != 0 ) /* removed? */
+ {
+ if( c_string( answer_time ))
+ {
+ if( is_time_now( c_string(answer_time)))
+ {
+ mgetty_state = St_wait_for_RINGs; /* -> accept */
+ break;
+ }
+ }
+ else
+ {
+ mgetty_state = St_wait_for_RINGs; /* -> accept */
+ break;
+ }
+ }
+
+ if ( virtual_ring == TRUE ) /* SIGUSR1? */
{
mgetty_state = St_wait_for_RINGs; /* -> accept */
break;
@@ -813,6 +839,9 @@
( c_isset(cnd_program) &&
cnd_call( c_string(cnd_program), Device, dist_ring ) == 1))
{
+ if ( c_isset(deny_chat) )
+ do_chat( STDIN, c_chat(deny_chat), NULL, NULL, 10, TRUE );
+
lprintf( L_AUDIT, "denied caller dev=%s, pid=%d, caller='%s'",
Device, getpid(), CallerId);
clean_line( STDIN, 80 ); /* wait for ringing to stop */
@@ -820,6 +849,9 @@
mgetty_state = St_go_to_jail;
break;
}
+
+ if(strcmp(CallerId, "none"))
+ lprintf( L_MESG, "caller-id: '%s'", CallerId);
/* from here, there's no way back. Either the call will succeed
and mgetty will exec() something else, or it will fail and
@@ -1124,3 +1156,4 @@
}
}
}
+
--- mgetty.cfg.in.orig Mon Nov 17 22:09:41 2003
+++ mgetty.cfg.in Wed Feb 15 08:05:15 2006
@@ -32,6 +32,7 @@
#fax-group uucp
#fax-mode 0640
+# answer-time 23:00-07:00
# ----- port specific section -----
#
@@ -41,8 +42,12 @@
# Zoom V.FX 28.8, connected to ttyS0: don't do fax, less logging
#
#port ttyS0
+# answer-time 0:00-24:00
+# or
+# {22:00-8:00} rings 1
+# {8:00-22:00} rings 8
# debug 3
-# data-only y
+# {8:00-22:00} data-only y
# some other Rockwell modem, needs "switchbd 19200" to receive faxes
# properly (otherwise it will fail with "timeout").
@@ -54,6 +59,15 @@
# ZyXEL 2864, connected to ttyS2: maximum debugging, grab statistics
#
#port ttyS2
+# answer-time 23:00-7:00
+# or
+# {23:00-7:00} rings 1
+# {7:00-23:00} rings 8
+#
+# For USR Courier V.Evr with ID SDL (ver >= 3.03):
+# get-cnd-chat "" AT+S62=3+S64=1+S65=0+SR1 OK
+# deny-chat "" ATH0 OK
+#
# debug 8
# init-chat "" \d\d\d+++\d\d\dAT&FS2=255 OK ATN3S0=0S13.2=1 OK
# statistics-chat "" AT OK ATI2 OK
--- version.h.orig Wed Nov 30 11:47:43 2005
+++ version.h Wed Feb 15 08:05:15 2006
@@ -1 +1 @@
-char * mgetty_version = "interim release 1.1.34-Nov30";
+char * mgetty_version = "interim release 1.1.34-Nov30.sc";
More information about the freebsd-ports
mailing list