isdnctrl can use a config file

This commit is contained in:
Stefan Luethje 1997-06-24 23:35:40 +00:00
parent 63625b40ca
commit 1ccdcb1131
12 changed files with 1961 additions and 769 deletions

View File

@ -23,6 +23,13 @@ do-it-all: config
endif
SUBDIRS :=
ifeq ($(CONFIG_ISDNLOG),y)
SUBDIRS := $(SUBDIRS) lib
else
ifeq ($(CONFIG_CTRL_CONF),y)
SUBDIRS := $(SUBDIRS) lib
endif
endif
ifeq ($(CONFIG_ISDNCTRL),y)
SUBDIRS := $(SUBDIRS) isdnctrl
endif
@ -55,7 +62,7 @@ ifeq ($(CONFIG_IMONTTY),y)
SUBDIRS := $(SUBDIRS) imontty
endif
ifeq ($(CONFIG_ISDNLOG),y)
SUBDIRS := $(SUBDIRS) areacode lib isdnlog
SUBDIRS := $(SUBDIRS) areacode isdnlog
else
ifeq ($(CONFIG_LIB_AREACODE),y)
SUBDIRS := $(SUBDIRS) areacode

View File

@ -4,16 +4,19 @@
# (C) 1997 Fritz Elfert
#
#
SHELL = /bin/sh
SHELL = /bin/sh
CFLAGS = -Wall -O2 -I. $(ISDN_INCLUDE)
LDFLAGS = -L../lib @LIBS@
LDFLAGS = @LIBS@
DBMLIB = @DBMLIB@
PROGRAM = isdnctrl
MODULES = isdnctrl.o
MANPAGE = isdnctrl.8
INSTALL = @INSTALL@
INSTALL_PROGRAM = $(INSTALL) -o 0 -g 0 -m 0750
INSTALL_MAN = $(INSTALL) -o 0 -g 0 -m 0644
CC = @CC@
CC = @CC@ -DVERSION=\"$(I4LVERSION)\"
prefix = @prefix@
exec_prefix = @exec_prefix@
ifeq (../.config,$(wildcard ../.config))
@ -26,6 +29,12 @@ else
endif
MAN8DIR = $(mandir)/man8
ifdef CONFIG_CTRL_CONF
CC += -DI4L_CTRL_CONF
LDFLAGS += -L../lib -lisdn $(DBMLIB)
MODULES += ctrlconf.o
endif
.SUFFIXES:
.SUFFIXES: .c .o
@ -35,7 +44,7 @@ config:
@./configure
$(PROGRAM): $(MODULES)
$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
$(CC) $(CFLAGS) $(MODULES) $(LDFLAGS) -o $@
install-man: isdnctrl.man
$(INSTALL) -d $(MAN8DIR)

89
isdnctrl/configure vendored
View File

@ -16,6 +16,11 @@ ac_default_prefix=/usr
# Initialize some variables set by options.
# The variables have the same names as the options, with
# dashes changed to underlines.
if test -r ../.config ; then
source ../.config
fi
build=NONE
cache_file=./config.cache
exec_prefix=NONE
@ -717,6 +722,88 @@ else
fi
if test "$CONFIG_CTRL_CONF" = "y"; then
echo $ac_n "checking for -ldbm""... $ac_c" 1>&6
ac_lib_var=`echo dbm'_'dbm_open | tr './+\055' '__p_'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_save_LIBS="$LIBS"
LIBS="-ldbm $LIBS"
cat > conftest.$ac_ext <<EOF
#line 868 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char dbm_open();
int main() { return 0; }
int t() {
dbm_open()
; return 0; }
EOF
if { (eval echo configure:880: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
DBMLIB=-ldbm; cat >> confdefs.h <<\EOF
#define HAVE_LIBDBM 1
EOF
else
echo "$ac_t""no" 1>&6
echo $ac_n "checking for -lgdbm""... $ac_c" 1>&6
ac_lib_var=`echo gdbm'_'gdbm_open | tr './+\055' '__p_'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_save_LIBS="$LIBS"
LIBS="-lgdbm $LIBS"
cat > conftest.$ac_ext <<EOF
#line 907 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char gdbm_open();
int main() { return 0; }
int t() {
gdbm_open()
; return 0; }
EOF
if { (eval echo configure:919: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
DBMLIB=-lgdbm; cat >> confdefs.h <<\EOF
#define HAVE_LIBGDBM 1
EOF
else
echo "$ac_t""no" 1>&6
fi
fi
fi
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
# On Suns, sometimes $CPP names a directory.
@ -1174,6 +1261,7 @@ s%@INSTALL_DATA@%$INSTALL_DATA%g
s%@CC@%$CC%g
s%@CPP@%$CPP%g
s%@INSTALL@%$INSTALL%g
s%@DBMLIB@%$DBMLIB%g
CEOF
EOF
@ -1231,6 +1319,7 @@ s%@configure_input@%$configure_input%g
s%@srcdir@%$srcdir%g
s%@top_srcdir@%$top_srcdir%g
s%@INSTALL@%$INSTALL%g
" -f conftest.subs $ac_given_srcdir/$ac_file_in > $ac_file
fi; done
rm -f conftest.subs

View File

@ -17,7 +17,10 @@ AC_CHECK_HEADER(linux/isdnif.h,,AC_MSG_ERROR("\nMissing linux/isdnif.h. Kernel s
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_CHECK_LIB(dbm, dbm_open, DBMLIB=-ldbm; AC_DEFINE(HAVE_LIBDBM),
AC_CHECK_LIB(gdbm, gdbm_open, DBMLIB=-lgdbm; AC_DEFINE(HAVE_LIBGDBM)))
AC_TYPE_SIGNAL
AC_SUBST(INSTALL)
AC_SUBST(DBMLIB)
AC_OUTPUT(Makefile)

650
isdnctrl/ctrlconf.c Normal file
View File

@ -0,0 +1,650 @@
/* $Id$
*
* ISDN accounting for isdn4linux. (Utilities)
*
* Copyright 1995, 1997 by Stefan Luethje (luethje@sl-gw.lake.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
*
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <linux/isdn.h>
#include "isdnctrl.h"
#include "ctrlconf.h"
/*****************************************************************************/
#define PHONE(phone) ((isdn_net_ioctl_phone*) phone)
/*****************************************************************************/
static int readinterfaces(int fd, section* CSec, section *PSec);
static char* readoptions(int fd, char *name, int is_master, section *CSec, section *PSec);
static int del_all_numbers(int fd, char *name, int direction);
static char* write_all_numbers(char *numbers);
static int set_all_numbers(int fd, char *name, int direction, char *numbers);
static int create_interface(int fd, char *name);
static int interface_exist(int fd, char *name);
/*****************************************************************************/
int writeconfig(int fd, char *file)
{
section *Section;
section *ConfigSection;
section *PhoneSection;
ConfigSection = read_file(NULL,file,C_NOT_UNIQUE|C_NO_WARN_FILE);
read_conffiles(&PhoneSection,NULL);
if ((Section = Set_Section(&ConfigSection,CONF_SEC_ISDNCTRL,C_OVERWRITE | C_WARN)) == NULL)
return -1;
readinterfaces(fd,Section,PhoneSection);
if (write_file(ConfigSection,file,cmd,VERSION) == NULL)
return -1;
return 0;
}
/*****************************************************************************/
static int readinterfaces(int fd, section* CSec, section *PSec)
{
char name[10];
FILE *iflst;
char s[BUFSIZ];
char *p;
if ((iflst = fopen("/proc/net/dev", "r")) == NULL)
{
perror("/proc/net/dev");
return -1;
}
while (!feof(iflst))
{
fgets(s, sizeof(s), iflst);
if ((p = strchr(s, ':')))
{
*p = 0;
sscanf(s, "%s", name);
p = readoptions(fd, name, 1, CSec, PSec);
while (p != NULL && *p != '\0')
{
strcpy(name, p);
p = readoptions(fd, name, 0, CSec, PSec);
}
}
}
fclose(iflst);
return 0;
}
/*****************************************************************************/
static char* readoptions(int fd, char *name, int is_master, section *CSec, section *PSec)
{
static isdn_net_ioctl_cfg cfg;
section *SubSec = NULL;
char inphone[BUFSIZ];
char outphone[BUFSIZ];
char string[256];
char *interface = is_master?CONF_SEC_INTERFACE:CONF_SEC_SLAVE;
char *RetCode = NULL;
if (name == NULL && *name != '\0')
return NULL;
strcpy(cfg.name, name);
if (ioctl(fd, IIOCNETGCF, &cfg) < 0)
return NULL;
strcpy(PHONE(inphone)->name, name);
PHONE(inphone)->outgoing = 0;
if (ioctl(fd, IIOCNETGNM, PHONE(inphone)) < 0)
return NULL;
strcpy(PHONE(outphone)->name, name);
PHONE(outphone)->outgoing = 1;
if (ioctl(fd, IIOCNETGNM, PHONE(outphone)) < 0)
return NULL;
if (Set_Section(&SubSec,interface,C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_NAME,name, C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (*cfg.eaz != '\0')
if (Set_Entry(SubSec,interface,CONF_ENT_EAZ,cfg.eaz, C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (*inphone != '\0')
if (Set_Entry(SubSec,interface,CONF_ENT_PHONE_IN,write_all_numbers(inphone), C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (*outphone != '\0')
if (Set_Entry(SubSec,interface,CONF_ENT_PHONE_OUT,write_all_numbers(outphone), C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_SECURE, cfg.secure?"on":"off", C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (cfg.callback)
{
if (Set_Entry(SubSec,interface,CONF_ENT_CALLBACK,num2callb[cfg.callback], C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_CBHUP, cfg.cbhup?"on":"off", C_OVERWRITE | C_WARN) == NULL)
return NULL;
sprintf(string,"%d",cfg.cbdelay / 5);
if (Set_Entry(SubSec,interface,CONF_ENT_CBDELAY, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (cfg.dialmax)
{
sprintf(string,"%d",cfg.dialmax);
if (Set_Entry(SubSec,interface,CONF_ENT_DIALMAX, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (cfg.onhtime)
{
sprintf(string,"%d",cfg.onhtime);
if (Set_Entry(SubSec,interface,CONF_ENT_HUPTIMEOUT, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (Set_Entry(SubSec,interface,CONF_ENT_IHUP, cfg.ihup?"on":"off", C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_CHARGEHUP, cfg.chargehup?"on":"off", C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (cfg.chargeint)
{
sprintf(string,"%d",cfg.chargeint);
if (Set_Entry(SubSec,interface,CONF_ENT_CHARGEINT, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (Set_Entry(SubSec,interface,CONF_ENT_L2_PROT, num2key(cfg.l2_proto, l2protostr, l2protoval), C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_L3_PROT, num2key(cfg.l3_proto, l3protostr, l3protoval), C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (Set_Entry(SubSec,interface,CONF_ENT_ENCAP, num2key(cfg.p_encap, pencapstr, pencapval), C_OVERWRITE | C_WARN) == NULL)
return NULL;
if (*cfg.slave != '\0')
{
if (Set_Entry(SubSec,interface,CONF_ENT_ADDSLAVE, cfg.slave, C_OVERWRITE | C_WARN) == NULL)
return NULL;
sprintf(string,"%d",cfg.slavedelay);
if (Set_Entry(SubSec,interface,CONF_ENT_SDELAY, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
RetCode = cfg.slave;
}
if (*cfg.drvid != '\0')
{
sprintf(string,"%s %s",cfg.drvid,cfg.exclusive>0?"exclusive":"");
if (Set_Entry(SubSec,interface,CONF_ENT_BIND, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (cfg.pppbind >= 0)
{
sprintf(string,"%d",cfg.pppbind);
if (Set_Entry(SubSec,interface,CONF_ENT_PPPBIND, string, C_OVERWRITE | C_WARN) == NULL)
return NULL;
}
if (Set_SubSection(CSec,CONF_ENT_INTERFACES,SubSec,C_APPEND | C_WARN) == NULL)
return NULL;
return RetCode;
}
/*****************************************************************************/
static char* write_all_numbers(char *numbers)
{
return numbers;
}
/*****************************************************************************/
int readconfig(int fd, char *file)
{
section *Section;
section *ConfigSection;
section *PhoneSection;
entry *Entry;
char *argv[5];
char *name;
int cnt = 1;
if ((ConfigSection = read_file(NULL,file,C_NOT_UNIQUE|C_NO_WARN_FILE)) == NULL)
return -1;
read_conffiles(&PhoneSection,NULL);
if ((Section = Get_Section(ConfigSection,CONF_SEC_ISDNCTRL)) == NULL)
{
fprintf(stderr,"File `%s' has no section `%s'!\n",file,CONF_SEC_ISDNCTRL);
return -1;
}
if ((Entry = Get_Entry(Section->entries,CONF_ENT_INTERFACES)) == NULL)
{
fprintf(stderr,"Section `%s' has no entry `%s'!\n",CONF_SEC_ISDNCTRL,CONF_ENT_INTERFACES);
return -1;
}
if ((Section = Entry->subsection) == NULL)
{
fprintf(stderr,"Entry `%s' has no subsections!\n",CONF_ENT_INTERFACES);
return -1;
}
while (Section != NULL)
{
if ((Entry = Get_Entry(Section->entries,CONF_ENT_NAME)) == NULL)
{
fprintf(stderr,"Missing the interface name of the %d. interface sections!\n",cnt);
return -1;
}
else
name = Entry->value;
if (!strcmp(Section->name, CONF_SEC_INTERFACE))
create_interface(fd,name);
Entry = Section->entries;
while (Entry != NULL)
{
if (!strcmp(Entry->name,CONF_ENT_NAME))
{
}
else
if (!strcmp(Entry->name,CONF_ENT_EAZ))
{
argv[0] = cmds[EAZ].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_PHONE_IN))
{
del_all_numbers(fd,name,0);
set_all_numbers(fd,name,0,Entry->value);
}
else
if (!strcmp(Entry->name,CONF_ENT_PHONE_OUT))
{
del_all_numbers(fd,name,1);
set_all_numbers(fd,name,1,Entry->value);
}
else
if (!strcmp(Entry->name,CONF_ENT_SECURE))
{
argv[0] = cmds[SECURE].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_CALLBACK))
{
argv[0] = cmds[CALLBACK].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_CBDELAY))
{
argv[0] = cmds[CBDELAY].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_CBHUP))
{
argv[0] = cmds[CBHUP].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_DIALMAX))
{
argv[0] = cmds[DIALMAX].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_HUPTIMEOUT))
{
argv[0] = cmds[HUPTIMEOUT].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_IHUP))
{
argv[0] = cmds[IHUP].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_CHARGEHUP))
{
argv[0] = cmds[CHARGEHUP].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_CHARGEINT))
{
argv[0] = cmds[CHARGEINT].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_L2_PROT))
{
argv[0] = cmds[L2_PROT].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_L3_PROT))
{
argv[0] = cmds[L3_PROT].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_ENCAP))
{
argv[0] = cmds[ENCAP].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_BIND))
{
char string[256];
char *ptr;
strcpy(string, Entry->value);
if ((ptr = strchr(string,' ')) != NULL)
while (isspace(*ptr)) *ptr++ = '\0';
argv[0] = cmds[BIND].cmd;
argv[1] = name;
argv[2] = string;
argv[3] = ptr;
argv[4] = NULL;
exec_args(fd,ptr?4:3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_PPPBIND))
{
argv[0] = cmds[PPPBIND].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_ADDSLAVE))
{
argv[0] = cmds[ADDSLAVE].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
if (!strcmp(Entry->name,CONF_ENT_SDELAY))
{
argv[0] = cmds[SDELAY].cmd;
argv[1] = name;
argv[2] = Entry->value;
argv[3] = NULL;
exec_args(fd,3,argv);
}
else
{
fprintf(stderr,"Unknown entry `%s' in interface section `%s'!\n",Entry->name,name);
return -1;
}
Entry = Entry->next;
}
Section = Section->next;
cnt++;
}
return 0;
}
/*****************************************************************************/
static int interface_exist(int fd, char *name)
{
char iname[10];
FILE *iflst;
char s[BUFSIZ];
char *p;
if ((iflst = fopen("/proc/net/dev", "r")) == NULL)
{
perror("/proc/net/dev");
return -1;
}
while (!feof(iflst))
{
fgets(s, sizeof(s), iflst);
if ((p = strchr(s, ':')))
{
*p = 0;
sscanf(s, "%s", iname);
if (!strcmp(name,iname))
{
fclose(iflst);
return 1;
}
}
}
fclose(iflst);
return 0;
}
/*****************************************************************************/
static int create_interface(int fd, char *name)
{
char *argv[3];
if (interface_exist(fd,name))
return -1;
argv[0] = cmds[ADDIF].cmd;
argv[1] = name;
argv[2] = NULL;
exec_args(fd,2,argv);
return 0;
}
/*****************************************************************************/
static int set_all_numbers(int fd, char *name, int direction, char *numbers)
{
isdn_net_ioctl_phone phone;
char phonestr[BUFSIZ];
char *ptr = phonestr;
char *ptr2;
strcpy(phonestr, numbers);
if (*phonestr != '\0')
{
strcpy(phone.name, name);
phone.outgoing = direction;
do
{
if ((ptr = strrchr(phonestr,' ')) == NULL)
ptr = phonestr;
else
{
ptr2 = ptr++;
while (isspace(*ptr2) && ptr2 != phonestr) *ptr2-- = '\0';
}
strcpy(phone.phone, ptr);
if (*ptr != '\0')
{
if (ioctl(fd, IIOCNETANM, &phone) < 0)
{
perror(name);
return -1;
}
}
}
while (ptr != phonestr);
}
return 0;
}
/*****************************************************************************/
static int del_all_numbers(int fd, char *name, int direction)
{
isdn_net_ioctl_phone phone;
char phonestr[BUFSIZ];
char *ptr = phonestr;
char *ptr2;
if (name == NULL)
return -1;
strcpy(PHONE(phonestr)->name, name);
PHONE(phonestr)->outgoing = direction;
if (ioctl(fd, IIOCNETGNM, PHONE(phonestr)) < 0)
{
perror(name);
return -1;
}
if (*phonestr != '\0')
{
strcpy(phone.name, name);
phone.outgoing = direction;
do
{
if ((ptr = strrchr(phonestr,' ')) == NULL)
ptr = phonestr;
else
{
ptr2 = ptr++;
while (isspace(*ptr2) && ptr2 != phonestr) *ptr2-- = '\0';
}
if (*ptr != '\0')
{
strcpy(phone.phone, ptr);
if (ioctl(fd, IIOCNETDNM, &phone) < 0)
{
perror(name);
return -1;
}
}
}
while (ptr != phonestr);
}
return 0;
}
/*****************************************************************************/

60
isdnctrl/ctrlconf.h Normal file
View File

@ -0,0 +1,60 @@
/* $Id$
*
* ISDN accounting for isdn4linux. (Utilities)
*
* Copyright 1995, 1997 by Stefan Luethje (luethje@sl-gw.lake.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
*
*/
#include "../lib/libisdn.h"
/*****************************************************************************/
#define CONF_SEC_ISDNCTRL "ISDNCTRL"
#define CONF_ENT_INTERFACES "INTERFACES"
#define CONF_SEC_INTERFACE "INTERFACE"
#define CONF_SEC_SLAVE "SLAVE"
#define CONF_ENT_NAME "NAME"
#define CONF_ENT_EAZ "EAZ"
#define CONF_ENT_PHONE_IN "PHONE_IN"
#define CONF_ENT_PHONE_OUT "PHONE_OUT"
#define CONF_ENT_SECURE "SECURE"
#define CONF_ENT_CALLBACK "CALLBACK"
#define CONF_ENT_CBHUP "CBHUP"
#define CONF_ENT_CBDELAY "CBDELAY"
#define CONF_ENT_DIALMAX "DIALMAX"
#define CONF_ENT_HUPTIMEOUT "HUPTIMEOUT"
#define CONF_ENT_IHUP "IHUP"
#define CONF_ENT_CHARGEHUP "CHARGEHUP"
#define CONF_ENT_CHARGEINT "CHARGEINT"
#define CONF_ENT_L2_PROT "L2_PROT"
#define CONF_ENT_L3_PROT "L3_PROT"
#define CONF_ENT_ENCAP "ENCAP"
#define CONF_ENT_SDELAY "SDELAY"
#define CONF_ENT_ADDSLAVE "ADDSLAVE"
#define CONF_ENT_BIND "BIND"
#define CONF_ENT_PPPBIND "PPPBIND"
/*****************************************************************************/
int writeconfig(int fd, char *file);
int readconfig(int fd, char *file);
/*****************************************************************************/

File diff suppressed because it is too large Load Diff

151
isdnctrl/isdnctrl.h Normal file
View File

@ -0,0 +1,151 @@
/* $Id$
* ISDN driver for Linux. (Control-Utility)
*
* Copyright 1994,95 by Fritz Elfert (fritz@wuemaus.franken.de)
* Copyright 1995 Thinking Objects Software GmbH Wuerzburg
*
* This file is part of Isdn4Linux.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
*
*/
/*****************************************************************************/
enum {
ADDIF, ADDSLAVE, DELIF, DIAL,
BIND, UNBIND, PPPBIND, PPPUNBIND,
BUSREJECT, MAPPING, SYSTEM, HANGUP,
ADDPHONE, DELPHONE, LIST, EAZ,
VERBOSE, GETCONF, HUPTIMEOUT, CBDELAY,
CHARGEINT, DIALMAX, SDELAY, CHARGEHUP,
CBHUP, IHUP, SECURE, CALLBACK,
L2_PROT, L3_PROT, ADDLINK, REMOVELINK,
ENCAP, TRIGGER,
#ifdef I4L_CTRL_CONF
WRITECONF, READCONF
#endif /* I4L_CTRL_CONF */
};
typedef struct {
char *cmd;
char *argno;
} cmd_struct;
/*****************************************************************************/
#ifdef _ISDNCTRL_C_
#define _EXTERN
cmd_struct cmds[] =
{
{"addif", "01"},
{"addslave", "2"},
{"delif", "1"},
{"dial", "1"},
{"bind", "123"},
{"unbind", "1"},
{"pppbind", "12"},
{"pppunbind", "1"},
{"busreject", "2"},
{"mapping", "12"},
{"system", "1"},
{"hangup", "1"},
{"addphone", "3"},
{"delphone", "3"},
{"list", "1"},
{"eaz", "12"},
{"verbose", "1"},
{"getconf", "01"},
{"huptimeout", "12"},
{"cbdelay", "12"},
{"chargeint", "12"},
{"dialmax", "12"},
{"sdelay", "12"},
{"chargehup", "12"},
{"cbhup", "12"},
{"ihup", "12"},
{"secure", "12"},
{"callback", "12"},
{"l2_prot", "12"},
{"l3_prot", "12"},
{"addlink", "1"},
{"removelink", "1"},
{"encap", "12"},
{"trigger", "01"},
#ifdef I4L_CTRL_CONF
{"writeconf", "01"},
{"readconf", "01"},
#endif /* I4L_CTRL_CONF */
{NULL,}
};
char *l2protostr[] = {
"x75i", "x75ui", "x75bui", "hdlc", "\0"
};
int l2protoval[] = {
ISDN_PROTO_L2_X75I, ISDN_PROTO_L2_X75UI,
ISDN_PROTO_L2_X75BUI, ISDN_PROTO_L2_HDLC, -1
};
char *l3protostr[] = {
"trans", "\0"
};
int l3protoval[] = {
ISDN_PROTO_L3_TRANS, -1
};
char *pencapstr[] = {
"ethernet", "rawip", "ip", "cisco-h", "syncppp",
"uihdlc", "\0"
};
int pencapval[] = {
ISDN_NET_ENCAP_ETHER, ISDN_NET_ENCAP_RAWIP,
ISDN_NET_ENCAP_IPTYP, ISDN_NET_ENCAP_CISCOHDLC,
ISDN_NET_ENCAP_SYNCPPP, ISDN_NET_ENCAP_UIHDLC, -1
};
char *num2callb[] = {
"off", "in", "out"
};
#else
#define _EXTERN extern
_EXTERN cmd_struct cmds[];
_EXTERN char *l2protostr[];
_EXTERN int l2protoval[];
_EXTERN char *l3protostr[];
_EXTERN int l3protoval[];
_EXTERN char *pencapstr[];
_EXTERN int pencapval[];
_EXTERN char *num2callb[];
#endif
_EXTERN char *cmd;
_EXTERN int key2num(char *key, char **keytable, int *numtable);
_EXTERN char * num2key(int num, char **keytable, int *numtable);
_EXTERN int exec_args(int fd, int argc, char **argv);
#undef _EXTERN
/*****************************************************************************/

View File

@ -1,4 +1,4 @@
.TH ISDNCTRL 8 "02. April 1996"
.TH ISDNCTRL 8 "25. June 1997"
.UC 4
.SH NAME
isdnctrl \- get/set ISDN device information
@ -196,6 +196,12 @@ interfaces cannot use that interface anymore.
.B unbind name
Unbinds a the previously bound interface "name".
.TP 5
.B pppbind name [num]
Binds the current interface to a ippp device (/dev/ipppX).
This works only for syncronous ppp.
The value must be a number.
If no number is omitted, it shows the the curring binding.
.TP 5
.B busreject driverId [on|off]
If switched on, isdn4linux replies a REJECT to incoming calls, it
cannot match to any configured interface. If switched off, nothing
@ -236,6 +242,217 @@ Force dialing of interface "name".
.TP 5
.B mapping driverId MSN0[,MSN1[,MSN2]] ... [,MSN9]
Installs a mapping-table for MSN<->EAZ-mapping. See README for details.
.TP 5
.B writeconf [file]
Writes the configuration into a file. If "file" is omitted, the default file
/etc/isdn/isdn.conf will be used.
.TP 5
.B readconf [file]
Reads the configuration from a file. If "file" is omitted, the default file
/etc/isdn/isdn.conf will be used.
.SS Syntax of the configuration file
This syntax will be used for the options
.B readconf
and
.B writeconf.
All entries are included in the section
.B [ISDNCTRL].
This section contains an entry
.B INTERFACES,
which describes the interfaces. Each subsection
.B [INTERFACE]
or
.B [SLAVE]
describes one interface. There are the following entries possible:
.TP 5
.B NAME
The name of the interface.
This entry is required.
.B Example:
NAME = ippp0
.TP 5
.B EAZ
Set the EAZ or the MSN.
This entry is required.
.B Example:
EAZ = 4711
.TP 5
.B PHONE_IN
Set the incoming phone number(s).
It requires at least one blank between the different numbers.
.B Example:
PHONE_IN = 08151234 08151235 08151236
.TP 5
.B PHONE_OUT
Set the outgoing phone number(s).
It requires at least one blank between the different numbers.
.B Example:
PHONE_OUT = 08151237 08151238
.TP 5
.B SECURE
Turn on or off the security feature.
Allowed values are "on" and "off".
.B Example:
SECURE = on
.TP 5
.B CALLBACK
Selects callback mode.
Allowed values are "off", "in" and "out".
.B Example:
CALLBACK = in
.TP 5
.B CBHUP
Turns on or off hangup before starting callback.
Allowed values are "on" and "off".
.B Example:
CBHUP = on
.TP 5
.B CBDELAY
Set the callback delay to "seconds".
.B Example:
CBDELAY = 5
.TP 5
.B DIALMAX
Set the number of dial atempts to "num".
.B Example:
DIALMAX = 1
.TP 5
.B HUPTIMEOUT
Set the hanguptime to "seconds".
.B Example:
HUPTIMEOUT = 20
.TP 5
.B IHUP
Turns on or off the hangup timeout for incoming calls.
Allowed values are "on" and "off".
.B Example:
IHUP = on
.TP 5
.B CHARGEHUP
Turns on or off hangup before next charge info.
Allowed values are "on" and "off".
.B Example:
CHARGEHUP = on
.TP 5
.B CHARGEINT
Sets the charge interval to "seconds".
.B Example:
CHARGEINT = 1
.TP 5
.B L2_PROT
Set the layer-2 protocol.
Allowed values are "x75i", "x75ui", "x75bui" and "hdlc".
.B Example:
L2_PROT = hdlc
.TP 5
.B L3_PROT
Set the layer-3 protocol.
Allowed value is only "trans".
.B Example:
L3_PROT = trans
.TP 5
.B ENCAP
Sets the encapsulation mode.
Allowed values are "rawip", "ip", "cisco_h", "ethernet", "syncppp" and "uihdlc".
.B Example:
ENCAP = rawip
.TP 5
.B SDELAY
Set the delay in seconds for the slave-dialing.
.B Example:
SDELAY = 0
.TP 5
.B ADDSLAVE
Adds a slave interface for channel-bundling.
.B Example:
ADDSLAVE = s-ippp0
.TP 5
.B BIND
Binds the current interface to a specific physical channel.
Before and after the comma may not be a blank.
.B Example:
BIND = teles1,0
.TP 5
.B PPPBIND
Binds the current interface to a ippp device (/dev/ipppX).
This works only for syncronous ppp.
The value must be a number.
.B Example:
PPPBIND = 0
.TP 5
.B Example for a configuration file
[ISDNCTRL]
INTERFACES = {
[INTERFACE]
NAME = isdn0
EAZ = 4711
PHONE_IN = 08151234
PHONE_OUT = 08151234
SECURE = on
DIALMAX = 1
HUPTIMEOUT= 20
IHUP = on
CHARGEHUP = on
L2_PROT = hdlc
L3_PROT = trans
ENCAP = rawip
ADDSLAVE = s-isdn0
SDELAY = 10
[SLAVE]
NAME = s-isdn0
EAZ = 4711
PHONE_OUT = 08151234
SECURE = on
DIALMAX = 1
HUPTIMEOUT= 10
IHUP = on
CHARGEHUP = on
L2_PROT = hdlc
L3_PROT = trans
ENCAP = rawip
[INTERFACE]
NAME = ippp0
EAZ = 4712
PHONE_OUT = 08151235 08151236
SECURE = on
DIALMAX = 5
HUPTIMEOUT= 200
IHUP = on
CHARGEHUP = on
L2_PROT = hdlc
L3_PROT = trans
ENCAP = syncppp
PPPBIND = 0
}
.SH WILDCARDS
For matching incoming calls phone numbers can be be set by

View File

@ -20,6 +20,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.12 1997/06/22 23:03:34 luethje
* In subsection FLAGS it will be checked if the section name FLAG is korrect
* isdnlog recognize calls abroad
* bugfix for program starts
*
* Revision 1.11 1997/05/25 19:41:13 luethje
* isdnlog: close all files and open again after kill -HUP
* isdnrep: support vbox version 2.0
@ -1226,8 +1231,10 @@ static info_args** Set_Flags(section *SPtr, int *Flags)
{
RetCode[NumArgs]->time = EPtr->value;
}
/*
else
_print_msg("Error: Invalid variable `%s'!\n",EPtr->name);
*/
EPtr = EPtr->next;
}

View File

@ -54,6 +54,7 @@ comment 'Runtime configuration tools'
bool 'isdnctrl' CONFIG_ISDNCTRL
if [ "$CONFIG_ISDNCTRL" = "y" ]; then
bool 'Enable isdnctrl debug-option' CONFIG_ISDNCTRL_DEBUG
bool 'Enable configfile-option (uses dbm lib)' CONFIG_CTRL_CONF
fi
bool 'iprofd' CONFIG_IPROFD
endmenu

View File

@ -34,6 +34,7 @@ CONFIG_AREACODE_DATA='/usr/lib/isdn'
#
CONFIG_ISDNCTRL=y
# CONFIG_ISDNCTRL_DEBUG is not set
# CONFIG_CTRL_CONF is not set
CONFIG_IPROFD=y
#