예제 #1
0
def remoteInquiry(call,userdir,curr_user,config):
	import time,fcntl,errno,os
	# acquire lock
	lockfile=open(userdir+"received/inquiry_lock","w")
	try:
		fcntl.lockf(lockfile,fcntl.LOCK_EX | fcntl.LOCK_NB) # only one inquiry at a time!

	except IOError,err: # can't get the lock
		if (err.errno in (errno.EACCES,errno.EAGAIN)):
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"fernabfrage-aktiv.la"))
			lockfile.close()
			return
예제 #2
0
def newAnnouncement(call,userdir,curr_user,config):
	capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"bitte-neue-ansage-komplett.la"))
	capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"))
	cmd=""
	while (cmd!="1"):
		capisuite.audio_receive(call,userdir+"announcement-tmp.la",60,3)
		capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"neue-ansage-lautet.la"))
		capisuite.audio_send(call,userdir+"announcement-tmp.la")
		capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"wenn-einverstanden-1.la"))
		cmd=capisuite.read_DTMF(call,0,1)
		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","announcement.la")
	os.rename(userdir+"announcement-tmp.la",userannouncement)
	userdata=pwd.getpwnam(curr_user)
	os.chown(userannouncement,userdata[2],userdata[3])

	capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"ansage-gespeichert.la"))
예제 #3
0
def voiceIncoming(call,call_from,call_to,curr_user,config):
	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=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:
			if (call_to!="-"):
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"anrufbeantworter-von.la"),1)
				cs_helpers.sayNumber(call,call_to,curr_user,config)
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"bitte-nachricht.la"),1)

		if (action!="none"):
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"),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)
			faxIncoming(call,call_from,call_to,curr_user,config,1)
		elif (dtmf_list!="" and pin!=""):
			dtmf_list+=capisuite.read_DTMF(call,3) # wait 5 seconds for input
			count=1
			while (count<3 and pin!=dtmf_list):  # try again if input was wrong
				capisuite.log("wrong PIN entered...",1,call)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"))
				dtmf_list=capisuite.read_DTMF(call,3)
				count+=1
			if (pin==dtmf_list):
				if (os.access(filename,os.R_OK)):
					os.unlink(filename)
				capisuite.log("Starting remote inquiry...",1,call)
				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)

	except capisuite.CallGoneError: # catch this here to get the cause info in the mail
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection lost with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	if (os.access(filename,os.R_OK)):
		cs_helpers.writeDescription(filename,
		  "call_from=\""+call_from+"\"\ncall_to=\""+call_to+"\"\ntime=\""
		  +time.ctime()+"\"\ncause=\"0x%x/0x%x\"\n" % (cause,causeB3))
		userdata=pwd.getpwnam(curr_user)
		os.chmod(filename,0600)
		os.chown(filename,userdata[2],userdata[3])
		os.chmod(filename[:-2]+"txt",0600)
		os.chown(filename[:-2]+"txt",userdata[2],userdata[3])

		fromaddress=cs_helpers.getOption(config,curr_user,"voice_email_from","")
		if (fromaddress==""):
			fromaddress=curr_user
		mailaddress=cs_helpers.getOption(config,curr_user,"voice_email","")
		if (mailaddress==""):
			mailaddress=curr_user
		if (action=="mailandsave"):
			cs_helpers.sendMIMEMail(fromaddress, 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)
예제 #4
0
			lastinquiry=int(lastfile.readline())
			lastfile.close()

		# sort out old messages
		oldmessages=[]
		i=0
		while (i<len(messages)):
			if (messages[i]<=lastinquiry):
				oldmessages.append(messages[i])
				del messages[i]
			else:
				i+=1

		cs_helpers.sayNumber(call,str(len(messages)),curr_user,config)
		if (len(messages)==1):
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"neue-nachricht.la"),1)
		else:
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"neue-nachrichten.la"),1)

		# menu for record new announcement
		cmd=""
		while (cmd not in ("1","9")):
			if (len(messages)+len(oldmessages)):
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"zum-abhoeren-1.la"),1)
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"fuer-neue-ansage-9.la"),1)
			cmd=capisuite.read_DTMF(call,0,1)
		if (cmd=="9"):
			newAnnouncement(call,userdir,curr_user,config)
			return

		# start inquiry