- error checking for reading of configuration improved, many options got
optional, others produce senseful error messages now if not found, fixes bug# 531, thx to Dieter Pelzel for reporting git-svn-id: https://svn.ibp.de/svn/capisuite/trunk/capisuite@50 4ebea2bb-67d4-0310-8558-a5799e421b66
This commit is contained in:
parent
51a2465acd
commit
00faa017c2
|
@ -4,7 +4,7 @@
|
|||
# ---------------------------------------------------
|
||||
# copyright : (C) 2002 by Gernot Hillier
|
||||
# email : gernot@hillier.de
|
||||
# version : $Revision: 1.3 $
|
||||
# version : $Revision: 1.4 $
|
||||
#
|
||||
# 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
|
||||
|
@ -45,7 +45,11 @@ def usage(error=""):
|
|||
sys.exit(1)
|
||||
|
||||
def showlist(config,user):
|
||||
sendq=config.get("GLOBAL","fax_user_dir")+user+"/sendq/"
|
||||
sendq=cs_helpers.getOption(config,"","fax_user_dir")
|
||||
if (sendq==None):
|
||||
print "ERROR: option fax_user_dir not set in fax configuration"
|
||||
sys.exit(1)
|
||||
sendq=os.path.join(sendq,user,"sendq")+"/"
|
||||
|
||||
print "ID Number Tries Next try"
|
||||
|
||||
|
@ -69,7 +73,11 @@ def showlist(config,user):
|
|||
sys.exit(0)
|
||||
|
||||
def abortjob(config,user,job):
|
||||
sendq=config.get("GLOBAL","fax_user_dir")+user+"/sendq/"
|
||||
sendq=cs_helpers.getOption(config,"","fax_user_dir")
|
||||
if (sendq==None):
|
||||
print "ERROR: option fax_user_dir not set in fax configuration"
|
||||
sys.exit(1)
|
||||
sendq=os.path.join(sendq,user,"sendq")+"/"
|
||||
job="fax-"+job+".txt"
|
||||
|
||||
if (not os.access(sendq+job,os.W_OK)):
|
||||
|
@ -122,7 +130,11 @@ if (not config.has_option(user,"fax_numbers")):
|
|||
sys.exit(1)
|
||||
|
||||
# test environment
|
||||
sendq=config.get("GLOBAL","fax_user_dir")+user+"/sendq/"
|
||||
sendq=cs_helpers.getOption(config,"","fax_user_dir")
|
||||
if (sendq==None):
|
||||
print "ERROR: option fax_user_dir not set in fax configuration"
|
||||
sys.exit(1)
|
||||
sendq=os.path.join(sendq,user,"sendq")+"/"
|
||||
if (not os.access(sendq,os.W_OK)):
|
||||
print "can't write to queue dir"
|
||||
sys.exit(1)
|
||||
|
@ -133,8 +145,8 @@ if (listqueue):
|
|||
if (abort):
|
||||
abortjob(config,user,abort)
|
||||
|
||||
prefix=cs_helpers.getOption(config,user,"dial_prefix")
|
||||
if (useprefix and prefix!=None):
|
||||
prefix=cs_helpers.getOption(config,user,"dial_prefix","")
|
||||
if (useprefix):
|
||||
dialstring=prefix+dialstring
|
||||
|
||||
# convert and enqueue files
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -----------------------------------------------------------
|
||||
# copyright : (C) 2002 by Gernot Hillier
|
||||
# email : gernot@hillier.de
|
||||
# version : $Revision: 1.1 $
|
||||
# version : $Revision: 1.2 $
|
||||
#
|
||||
# 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
|
||||
|
@ -43,17 +43,17 @@ def readConfig(file=""):
|
|||
# in the global section.
|
||||
#
|
||||
# @param config the ConfigParser object containing the values
|
||||
# @param user the name of the user section to use
|
||||
# @param user user section to use, if empty only global section is read
|
||||
# @param option the name of the option to search for
|
||||
#
|
||||
# @return the value for this option or None if it's not found
|
||||
def getOption(config,user,option):
|
||||
def getOption(config,user,option,default=None):
|
||||
if config.has_option(user,option):
|
||||
return config.get(user,option)
|
||||
elif config.has_option('GLOBAL',option):
|
||||
return config.get('GLOBAL',option)
|
||||
else:
|
||||
return None
|
||||
return default
|
||||
|
||||
# @brief Search for an audio file first in user_dir, than in audio_dir
|
||||
#
|
||||
|
@ -63,10 +63,15 @@ def getOption(config,user,option):
|
|||
#
|
||||
# @return the found file with full path
|
||||
def getAudio(config,user,filename):
|
||||
import os
|
||||
systemdir=config.get('GLOBAL','audio_dir')
|
||||
userdir=config.get('GLOBAL','voice_user_dir')+user+"/"
|
||||
if (config.getint('GLOBAL','user_audio_files') and os.access(userdir+filename,os.R_OK)):
|
||||
import os,capisuite
|
||||
systemdir=getOption(config,"","audio_dir")
|
||||
if (systemdir==None):
|
||||
raise IOError("option audio_dir not found.")
|
||||
userdir=getOption(config,"","voice_user_dir")
|
||||
if (userdir==None):
|
||||
raise IOError("option voice_user_dir not found.")
|
||||
userdir=os.path.join(userdir,user)+"/"
|
||||
if (int(getOption(config,"","user_audio_files","0")) and os.access(userdir+filename,os.R_OK)):
|
||||
return userdir+filename
|
||||
else:
|
||||
return systemdir+filename
|
||||
|
@ -302,8 +307,13 @@ def sayNumber(call,number,curr_user,config):
|
|||
capisuite.audio_send(call,getAudio(config,curr_user,i+".la"),1)
|
||||
|
||||
# $Log: cs_helpers.pyin,v $
|
||||
# Revision 1.1 2003/02/19 08:19:54 gernot
|
||||
# Initial revision
|
||||
# Revision 1.2 2003/03/20 09:12:42 gernot
|
||||
# - error checking for reading of configuration improved, many options got
|
||||
# optional, others produce senseful error messages now if not found,
|
||||
# fixes bug# 531, thx to Dieter Pelzel for reporting
|
||||
#
|
||||
# Revision 1.1.1.1 2003/02/19 08:19:54 gernot
|
||||
# initial checkin of 0.4
|
||||
#
|
||||
# Revision 1.8 2003/02/10 14:03:34 ghillie
|
||||
# - cosmetical fixes in sendMIMEMail
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: fax.confin,v 1.3 2003/03/18 23:12:00 gernot Exp $
|
||||
# $Id: fax.confin,v 1.4 2003/03/20 09:12:42 gernot Exp $
|
||||
#
|
||||
# This is the fax configuration file for the scripts distributed with CapiSuite
|
||||
#
|
||||
|
@ -31,6 +31,8 @@
|
|||
|
||||
[GLOBAL]
|
||||
|
||||
# spool_dir (MANDATORY)
|
||||
#
|
||||
# Directory where idle.py will save its data. There must exist two
|
||||
# subdirectories:
|
||||
#
|
||||
|
@ -38,6 +40,8 @@
|
|||
# spool_dir/failed - jobs which have finally failed live here
|
||||
spool_dir="@spooldir@/"
|
||||
|
||||
# fax_user_dir (MANDATORY)
|
||||
#
|
||||
# Directory for all user-specific data. Contains one subdirectory
|
||||
# for each user (named like his userid). The following directory tree is used below:
|
||||
#
|
||||
|
@ -45,13 +49,13 @@ spool_dir="@spooldir@/"
|
|||
# user_dir/username/sendq - the files to send will be queued here
|
||||
fax_user_dir="@spooldir@/users/"
|
||||
|
||||
# send_tries
|
||||
# send_tries (optional, defaults to 10)
|
||||
#
|
||||
# Number of tries for sending a fax document. After completing the
|
||||
# given number of tries, the document will considered as failed.
|
||||
send_tries="10"
|
||||
|
||||
# send_delays
|
||||
# send_delays (optional, defaults to 60,60,60,300,300,3600,3600,18000,36000)
|
||||
#
|
||||
# Delays in seconds between the send_tries. The different values are separated
|
||||
# by commas. The first value gives the delay between the first and the second
|
||||
|
@ -60,7 +64,7 @@ send_tries="10"
|
|||
# values will be ignored.
|
||||
send_delays="60,60,60,300,300,3600,3600,18000,36000"
|
||||
|
||||
# send_controller
|
||||
# send_controller (optional, defaults to 1)
|
||||
#
|
||||
# This value defines which one of the installed controllers will be used for
|
||||
# sending faxes. All controllers are numbered beginning with "1". If you
|
||||
|
@ -68,20 +72,20 @@ send_delays="60,60,60,300,300,3600,3600,18000,36000"
|
|||
# there's only one send_controller supported currently.
|
||||
send_controller="1"
|
||||
|
||||
# outgoing_MSN
|
||||
# outgoing_MSN (optional, default is empty)
|
||||
#
|
||||
# The MSN (number) to use for outgoing calls. You can also leave this empty.
|
||||
# Then default MSN of your ISDN interface will be used automatically. Will
|
||||
# be overwritten by the first entry of fax_numbers if set.
|
||||
outgoing_MSN=""
|
||||
|
||||
# outgoing_timeout
|
||||
# outgoing_timeout (optional, defaults to 60)
|
||||
#
|
||||
# This value decides how long to wait for a successful connection if the other
|
||||
# party doesn't answer the call at once.
|
||||
outgoing_timeout="60"
|
||||
|
||||
# dial_prefix
|
||||
# dial_prefix (optional, defaults to empty)
|
||||
#
|
||||
# This value is used as a prefix for all outgoing numbers when using
|
||||
# capisuitefax for enqueueing a fax document. It will be saved in the
|
||||
|
@ -89,19 +93,20 @@ outgoing_timeout="60"
|
|||
# documents.
|
||||
dial_prefix=""
|
||||
|
||||
# fax_stationID
|
||||
# fax_stationID (MANDATORY)
|
||||
#
|
||||
# This is the default for the fax station ID (fax number send to the other
|
||||
# party). It must only contain the following characters <space>,'+','0'..'9'.
|
||||
# The maximal length is 20 chars.
|
||||
# The maximal length is 20 chars
|
||||
fax_stationID="+49 000 0000"
|
||||
|
||||
# fax_headline
|
||||
# fax_headline (optional, default: empty)
|
||||
#
|
||||
# This is the default for the fax headline. There's no definitive length
|
||||
# constraint given by the CAPI specification, so it may be dependent on
|
||||
# the driver you use. Just use a reasonable short string.
|
||||
fax_headline="Fax sent by CapiSuite (http://www.capisuite.de)"
|
||||
# the driver you use. Just use a reasonable short string
|
||||
#
|
||||
fax_headline="Sent by CapiSuite (www.CapiSuite.de)"
|
||||
|
||||
###############################################################################
|
||||
############################# user settings ###################################
|
||||
|
@ -116,21 +121,21 @@ fax_headline="Fax sent by CapiSuite (http://www.capisuite.de)"
|
|||
#
|
||||
# Additionally, the following options are possible:
|
||||
#
|
||||
# fax_numbers="<num1>,<num2>, ..."
|
||||
# fax_numbers="<num1>,<num2>, ..." (optional, if not set this user can't receive)
|
||||
# A list containing the numbers on which this user wants to receive incoming
|
||||
# fax calls. The values are separated by commas. The first number is also
|
||||
# used as our own number for outgoing calls. This overrides outgoing_MSN.
|
||||
# You can also use the special entry "*" which stands for accepting ALL
|
||||
# incoming calls as fax (use with care!)
|
||||
#
|
||||
# fax_email="name@domain.de"
|
||||
# fax_email="name@domain.de" (optional, defaults to empty string)
|
||||
# If given, this string indicates an email-address where the received faxes
|
||||
# and voice calls will be sent to. If it is empty, the recorded calls and
|
||||
# faxes will be sent to the user on the current system. It's also used to
|
||||
# send status reports for sent fax jobs to. If you don't want to get emails,
|
||||
# see the "action" option below
|
||||
#
|
||||
# fax_action="<action>"
|
||||
# fax_action="<action>" (MANDATORY)
|
||||
# Here you can define what action will be taken when a fax is received.
|
||||
# Currently, three possible actions are supported:
|
||||
#
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# ---------------------------------------------
|
||||
# copyright : (C) 2002 by Gernot Hillier
|
||||
# email : gernot@hillier.de
|
||||
# version : $Revision: 1.4 $
|
||||
# version : $Revision: 1.5 $
|
||||
#
|
||||
# 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
|
||||
|
@ -16,10 +16,17 @@ import capisuite,cs_helpers
|
|||
|
||||
def idle(capi):
|
||||
config=cs_helpers.readConfig()
|
||||
done=config.get('GLOBAL','spool_dir')+"done/"
|
||||
failed=config.get('GLOBAL','spool_dir')+"failed/"
|
||||
spool=cs_helpers.getOption(config,"","spool_dir")
|
||||
if (spool==None):
|
||||
capisuite.error("global option spool_dir not found.")
|
||||
return
|
||||
|
||||
done=os.path.join(spool,"done")+"/"
|
||||
failed=os.path.join(spool,"failed")+"/"
|
||||
|
||||
if (not os.access(done,os.W_OK) or not os.access(failed,os.W_OK)):
|
||||
raise "Can't read/write to the necessary spool dirs"
|
||||
capisuite.error("Can't read/write to the necessary spool dirs")
|
||||
return
|
||||
|
||||
userlist=config.sections()
|
||||
userlist.remove('GLOBAL')
|
||||
|
@ -29,8 +36,12 @@ def idle(capi):
|
|||
if (not config.has_option(user,"fax_numbers")):
|
||||
continue
|
||||
|
||||
udir=config.get("GLOBAL","fax_user_dir")+user+"/"
|
||||
sendq=udir+"sendq/"
|
||||
udir=cs_helpers.getOption(config,"","fax_user_dir")
|
||||
if (udir==None):
|
||||
capisuite.error("global option fax_user_dir not found.")
|
||||
return
|
||||
udir=os.path.join(udir,user)+"/"
|
||||
sendq=os.path.join(udir,"sendq")+"/"
|
||||
if (not os.access(udir,os.F_OK)):
|
||||
os.mkdir(udir,0700)
|
||||
os.chown(udir,userdata[2],userdata[3])
|
||||
|
@ -69,8 +80,8 @@ def idle(capi):
|
|||
|
||||
tries=control.getint("GLOBAL","tries")
|
||||
dialstring=control.get("GLOBAL","dialstring")
|
||||
mailaddress=cs_helpers.getOption(config,user,"fax_email")
|
||||
if (mailaddress=="" or mailaddress==None):
|
||||
mailaddress=cs_helpers.getOption(config,user,"fax_email","")
|
||||
if (mailaddress==""):
|
||||
mailaddress=user
|
||||
|
||||
capisuite.log("job "+job_fax+" from "+user+" to "+dialstring+" initiated",1)
|
||||
|
@ -87,8 +98,8 @@ def idle(capi):
|
|||
+("\nLast result: 0x%x/0x%x" % (result,resultB3))
|
||||
+"\n\nIt was moved to file://"+done+user+"-"+job_fax)
|
||||
else:
|
||||
max_tries=config.getint('GLOBAL','send_tries')
|
||||
delays=config.get('GLOBAL','send_delays').split(",")
|
||||
max_tries=int(cs_helpers.getOption(config,"","send_tries","10"))
|
||||
delays=cs_helpers.getOption(config,"","send_delays","60,60,60,300,300,3600,3600,18000,36000").split(",")
|
||||
delays=map(int,delays)
|
||||
if (tries<len(delays)):
|
||||
next_delay=delays[tries]
|
||||
|
@ -115,12 +126,18 @@ def idle(capi):
|
|||
|
||||
def sendfax(capi,job,dialstring,user,config):
|
||||
try:
|
||||
outgoing_nr=cs_helpers.getOption(config,user,'outgoing_MSN')
|
||||
outgoing_nr=cs_helpers.getOption(config,user,"outgoing_MSN","")
|
||||
if (outgoing_nr==""):
|
||||
outgoing_nr=(config.get(user,'fax_numbers').split(','))[0]
|
||||
(call,result)=capisuite.call_faxG3(capi,int(config.get('GLOBAL','send_controller')),
|
||||
outgoing_nr, dialstring, int(cs_helpers.getOption(config,user,'outgoing_timeout')),
|
||||
cs_helpers.getOption(config,user,'fax_stationID'), cs_helpers.getOption(config,user,'fax_headline'))
|
||||
outgoing_nr=(config.get(user,'fax_numbers').split(','))[0] # it's guaranteed that we have fax_numbers defined
|
||||
|
||||
controller=int(cs_helpers.getOption(config,"","send_controller","1"))
|
||||
timeout=int(cs_helpers.getOption(config,user,"outgoing_timeout","60"))
|
||||
stationID=cs_helpers.getOption(config,user,"fax_stationID")
|
||||
if (stationID==None):
|
||||
capisuite.error("Warning: fax_stationID for user "+user+" not set")
|
||||
stationID=""
|
||||
headline=cs_helpers.getOption(config,user,"fax_headline","")
|
||||
(call,result)=capisuite.call_faxG3(capi,controller,outgoing_nr,dialstring,timeout,stationID,headline)
|
||||
if (result!=0):
|
||||
return(result,0)
|
||||
capisuite.fax_send(call,job)
|
||||
|
@ -136,6 +153,11 @@ def movejob(job,olddir,newdir,user):
|
|||
# History:
|
||||
#
|
||||
# $Log: idle.py,v $
|
||||
# Revision 1.5 2003/03/20 09:12:42 gernot
|
||||
# - error checking for reading of configuration improved, many options got
|
||||
# optional, others produce senseful error messages now if not found,
|
||||
# fixes bug# 531, thx to Dieter Pelzel for reporting
|
||||
#
|
||||
# Revision 1.4 2003/03/13 11:09:58 gernot
|
||||
# - use stricted permissions for saved files and created userdirs. Fixes
|
||||
# bug #544
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# ----------------------------------------------------
|
||||
# copyright : (C) 2002 by Gernot Hillier
|
||||
# email : gernot@hillier.de
|
||||
# version : $Revision: 1.4 $
|
||||
# version : $Revision: 1.5 $
|
||||
#
|
||||
# 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
|
||||
|
@ -63,30 +63,23 @@ def callIncoming(call,service,call_from,call_to):
|
|||
capisuite.reject(call,1)
|
||||
return
|
||||
try:
|
||||
try:
|
||||
if (curr_service==capisuite.SERVICE_VOICE):
|
||||
udir=config.get("GLOBAL","voice_user_dir")+curr_user+"/"
|
||||
elif (curr_service==capisuite.SERVICE_FAXG3):
|
||||
udir=config.get("GLOBAL","fax_user_dir")+curr_user+"/"
|
||||
if (not os.access(udir,os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir,0700)
|
||||
os.chown(udir,userdata[2],userdata[3])
|
||||
if (not os.access(udir+"received/",os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir+"received/",0700)
|
||||
os.chown(udir+"received/",userdata[2],userdata[3])
|
||||
except KeyError:
|
||||
capisuite.error("user "+curr_user+" is not a valid system user. Disconnecting",call)
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
if (curr_service==capisuite.SERVICE_VOICE):
|
||||
delay=cs_helpers.getOption(config,curr_user,"voice_delay")
|
||||
if (delay==None):
|
||||
capisuite.error("voice_delay not found for user "+curr_user+"! -> rejecting call")
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
capisuite.log("call from "+call_from+" to "+call_to+" for "+curr_user+" connecting with voice",1,call)
|
||||
capisuite.connect_voice(call,int(cs_helpers.getOption(config,curr_user,"voice_delay")))
|
||||
capisuite.connect_voice(call,int(delay))
|
||||
voiceIncoming(call,call_from,call_to,curr_user,config)
|
||||
elif (curr_service==capisuite.SERVICE_FAXG3):
|
||||
stationID=cs_helpers.getOption(config,curr_user,"fax_stationID")
|
||||
if (stationID==None):
|
||||
capisuite.error("Warning: fax_stationID not found for user "+curr_user+" -> using empty string")
|
||||
stationID=""
|
||||
headline=cs_helpers.getOption(config,curr_user,"fax_headline","") # empty string is no problem here
|
||||
capisuite.log("call from "+call_from+" to "+call_to+" for "+curr_user+" connecting with fax",1,call)
|
||||
capisuite.connect_faxG3(call,cs_helpers.getOption(config,curr_user,"fax_stationID"),cs_helpers.getOption(config,curr_user,"fax_headline"),0)
|
||||
capisuite.connect_faxG3(call,stationID,headline,0)
|
||||
faxIncoming(call,call_from,call_to,curr_user,config)
|
||||
except capisuite.CallGoneError: # catch exceptions from connect_*
|
||||
(cause,causeB3)=capisuite.disconnect(call)
|
||||
|
@ -100,7 +93,26 @@ def callIncoming(call,service,call_from,call_to):
|
|||
# @param curr_user name of the user who is responsible for this
|
||||
# @param config ConfigParser instance holding the config data
|
||||
def faxIncoming(call,call_from,call_to,curr_user,config):
|
||||
filename=cs_helpers.uniqueName(config.get("GLOBAL","fax_user_dir")+curr_user+"/received/","fax","sff")
|
||||
try:
|
||||
udir=cs_helpers.getOption(config,"","fax_user_dir")
|
||||
if (udir==None):
|
||||
capisuite.error("global option fax_user_dir not found! -> rejecting call")
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
udir=os.path.join(udir,curr_user)+"/"
|
||||
if (not os.access(udir,os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir,0700)
|
||||
os.chown(udir,userdata[2],userdata[3])
|
||||
if (not os.access(udir+"received/",os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir+"received/",0700)
|
||||
os.chown(udir+"received/",userdata[2],userdata[3])
|
||||
except KeyError:
|
||||
capisuite.error("user "+curr_user+" is not a valid system user. Disconnecting",call)
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
filename=cs_helpers.uniqueName(udir+"received/","fax","sff")
|
||||
try:
|
||||
capisuite.fax_receive(call,filename)
|
||||
(cause,causeB3)=capisuite.disconnect(call)
|
||||
|
@ -120,10 +132,14 @@ def faxIncoming(call,call_from,call_to,curr_user,config):
|
|||
os.chmod(filename[:-3]+"txt",0600)
|
||||
os.chown(filename[:-3]+"txt",userdata[2],userdata[3])
|
||||
|
||||
mailaddress=cs_helpers.getOption(config,curr_user,"fax_email")
|
||||
if (mailaddress=="" or mailaddress==None):
|
||||
mailaddress=cs_helpers.getOption(config,curr_user,"fax_email","")
|
||||
if (mailaddress==""):
|
||||
mailaddress=curr_user
|
||||
if (cs_helpers.getOption(config,curr_user,"fax_action").lower()=="mailandsave"):
|
||||
action=cs_helpers.getOption(config,curr_user,"fax_action","").lower()
|
||||
if (action not in ("mailandsave","saveonly")):
|
||||
capisuite.error("Warning: No valid fax_action definition found for user "+curr_user+" -> assuming SaveOnly")
|
||||
action="saveonly"
|
||||
if (action=="mailandsave"):
|
||||
cs_helpers.sendMIMEMail(curr_user, mailaddress, "Fax received from "+call_from+" to "+call_to, "sff",
|
||||
"You got a fax from "+call_from+" to "+call_to+"\nDate: "+time.ctime()+"\n\n"
|
||||
+"See attached file.\nThe original file was saved to file://"+filename+"\n\n", filename)
|
||||
|
@ -136,12 +152,34 @@ def faxIncoming(call,call_from,call_to,curr_user,config):
|
|||
# @param curr_user name of the user who is responsible for this
|
||||
# @param config ConfigParser instance holding the config data
|
||||
def voiceIncoming(call,call_from,call_to,curr_user,config):
|
||||
userdir=config.get("GLOBAL","voice_user_dir")+curr_user+"/"
|
||||
filename=cs_helpers.uniqueName(userdir+"received/","voice","la")
|
||||
try:
|
||||
udir=cs_helpers.getOption(config,"","voice_user_dir")
|
||||
if (udir==None):
|
||||
capisuite.error("global option voice_user_dir not found! -> rejecting call")
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
udir=os.path.join(udir,curr_user)+"/"
|
||||
if (not os.access(udir,os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir,0700)
|
||||
os.chown(udir,userdata[2],userdata[3])
|
||||
if (not os.access(udir+"received/",os.F_OK)):
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.mkdir(udir+"received/",0700)
|
||||
os.chown(udir+"received/",userdata[2],userdata[3])
|
||||
except KeyError:
|
||||
capisuite.error("user "+curr_user+" is not a valid system user. Disconnecting",call)
|
||||
capisuite.reject(call,0x34A9)
|
||||
return
|
||||
filename=cs_helpers.uniqueName(udir+"received/","voice","la")
|
||||
action=cs_helpers.getOption(config,curr_user,"voice_action","").lower()
|
||||
if (action not in ("mailandsave","saveonly","none")):
|
||||
capisuite.error("Warning: No valid voice_action definition found for user "+curr_user+" -> assuming SaveOnly")
|
||||
action="saveonly"
|
||||
try:
|
||||
capisuite.enable_DTMF(call)
|
||||
userannouncement=userdir+cs_helpers.getOption(config,curr_user,"announcement")
|
||||
pin=cs_helpers.getOption(config,curr_user,"pin")
|
||||
userannouncement=udir+cs_helpers.getOption(config,curr_user,"announcement","announcement.la")
|
||||
pin=cs_helpers.getOption(config,curr_user,"pin","")
|
||||
if (os.access(userannouncement,os.R_OK)):
|
||||
capisuite.audio_send(call,userannouncement,1)
|
||||
else:
|
||||
|
@ -149,15 +187,22 @@ def voiceIncoming(call,call_from,call_to,curr_user,config):
|
|||
cs_helpers.sayNumber(call,call_to,curr_user,config)
|
||||
capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"bitte-nachricht.la"),1)
|
||||
|
||||
if (cs_helpers.getOption(config,curr_user,"voice_action").lower()!="none"):
|
||||
if (action!="none"):
|
||||
capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"),1)
|
||||
capisuite.audio_receive(call,filename,int(cs_helpers.getOption(config,curr_user,"record_length")), int(cs_helpers.getOption(config,curr_user,"record_silence_timeout")),1)
|
||||
length=cs_helpers.getOption(config,curr_user,"record_length","60")
|
||||
silence_timeout=cs_helpers.getOption(config,curr_user,"record_silence_timeout","5")
|
||||
capisuite.audio_receive(call,filename,int(length), int(silence_timeout),1)
|
||||
|
||||
dtmf_list=capisuite.read_DTMF(call,0)
|
||||
if (dtmf_list=="X"):
|
||||
if (os.access(filename,os.R_OK)):
|
||||
os.unlink(filename)
|
||||
capisuite.switch_to_faxG3(call,cs_helpers.getOption(config,curr_user,"fax_stationID"),cs_helpers.getOption(config,curr_user,"fax_headline"))
|
||||
stationID=cs_helpers.getOption(config,curr_user,"fax_stationID")
|
||||
if (stationID==None):
|
||||
capisuite.error("Warning: fax_stationID not found for user "+curr_user+" -> using empty string")
|
||||
stationID=""
|
||||
headline=cs_helpers.getOption(config,curr_user,"fax_headline","") # empty string is no problem here
|
||||
capisuite.switch_to_faxG3(call,stationID,headline)
|
||||
faxIncoming(call,call_from,call_to,curr_user,config)
|
||||
elif (dtmf_list!="" and pin!=""):
|
||||
dtmf_list+=capisuite.read_DTMF(call,3) # wait 5 seconds for input
|
||||
|
@ -171,7 +216,7 @@ def voiceIncoming(call,call_from,call_to,curr_user,config):
|
|||
if (os.access(filename,os.R_OK)):
|
||||
os.unlink(filename)
|
||||
capisuite.log("Starting remote inquiry...",1,call)
|
||||
remoteInquiry(call,userdir,curr_user,config)
|
||||
remoteInquiry(call,udir,curr_user,config)
|
||||
|
||||
(cause,causeB3)=capisuite.disconnect(call)
|
||||
capisuite.log("connection finished with cause 0x%x,0x%x" % (cause,causeB3),1,call)
|
||||
|
@ -190,10 +235,10 @@ def voiceIncoming(call,call_from,call_to,curr_user,config):
|
|||
os.chmod(filename[:-2]+"txt",0600)
|
||||
os.chown(filename[:-2]+"txt",userdata[2],userdata[3])
|
||||
|
||||
mailaddress=cs_helpers.getOption(config,curr_user,"voice_email")
|
||||
if (mailaddress=="" or mailaddress==None):
|
||||
mailaddress=cs_helpers.getOption(config,curr_user,"voice_email","")
|
||||
if (mailaddress==""):
|
||||
mailaddress=curr_user
|
||||
if (cs_helpers.getOption(config,curr_user,"voice_action").lower()=="mailandsave"):
|
||||
if (action=="mailandsave"):
|
||||
cs_helpers.sendMIMEMail(curr_user, mailaddress, "Voice call received from "+call_from+" to "+call_to, "la",
|
||||
"You got a voice call from "+call_from+" to "+call_to+"\nDate: "+time.ctime()+"\n\n"
|
||||
+"See attached file.\nThe original file was saved to file://"+filename+"\n\n", filename)
|
||||
|
@ -347,7 +392,7 @@ def newAnnouncement(call,userdir,curr_user,config):
|
|||
if (cmd!="1"):
|
||||
capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"bitte-neue-ansage-kurz.la"))
|
||||
capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"))
|
||||
userannouncement=userdir+cs_helpers.getOption(config,curr_user,"announcement")
|
||||
userannouncement=userdir+cs_helpers.getOption(config,curr_user,"announcement","announcement.la")
|
||||
os.rename(userdir+"announcement-tmp.la",userannouncement)
|
||||
userdata=pwd.getpwnam(curr_user)
|
||||
os.chown(userannouncement,userdata[2],userdata[3])
|
||||
|
@ -358,6 +403,11 @@ def newAnnouncement(call,userdir,curr_user,config):
|
|||
# History:
|
||||
#
|
||||
# $Log: incoming.py,v $
|
||||
# Revision 1.5 2003/03/20 09:12:42 gernot
|
||||
# - error checking for reading of configuration improved, many options got
|
||||
# optional, others produce senseful error messages now if not found,
|
||||
# fixes bug# 531, thx to Dieter Pelzel for reporting
|
||||
#
|
||||
# Revision 1.4 2003/03/13 11:08:06 gernot
|
||||
# - fix remote inquiry locking (should fix bug #534, but doesn't - anyway,
|
||||
# this fix is definitely necessary)
|
||||
|
|
Loading…
Reference in New Issue