Exemplo n.º 1
0
def callIncoming(call,service,call_from,call_to):
	# read config file and search for call_to in the user sections
	try:
		config=cs_helpers.readConfig()
		userlist=config.sections()
		userlist.remove('GLOBAL')
		curr_user=""

		for u in userlist:
			if config.has_option(u,'voice_numbers'):
				numbers=config.get(u,'voice_numbers')
				if (call_to in numbers.split(',') or numbers=="*"):
					if (service==capisuite.SERVICE_VOICE):
						curr_user=u
						curr_service=capisuite.SERVICE_VOICE
						break
					if (service==capisuite.SERVICE_FAXG3):
						curr_user=u
						curr_service=capisuite.SERVICE_FAXG3
						break

			if config.has_option(u,'fax_numbers'):
				numbers=config.get(u,'fax_numbers')
				if (call_to in numbers.split(',') or numbers=="*"):
				 	if (service in (capisuite.SERVICE_FAXG3,capisuite.SERVICE_VOICE)):
						curr_user=u
						curr_service=capisuite.SERVICE_FAXG3
						break

	except IOError,e:
		capisuite.error("Error occured during config file reading: "+e+" Disconnecting...")
		capisuite.reject(call,0x34A9)
		return
Exemplo n.º 2
0
def removejob(user,jobid,cslist):
    """removes (delete) a job from queue dir"""
    if (checkconfig() == -1) or (checkfaxuser(user,1) == 0):
        raise CSConfigError
    if not listtypes.has_key(cslist) or CheckJobID(jobid)==-1:
        raise CSInternalError("Invalid list/queue type oder jobid provided")
    
    qpath=BuildListPath(cslist,user)
    
    job =""
    if listtypes[cslist][1]==1:
        job=user+"-"
    job=job+listtypes[cslist][0]+"-"+jobid+".txt"
    #job=prefix+"-"+jobid+".txt"

    if (not os.access(qpath+job,os.W_OK)):
        raise CSRemoveError('Job file "%s" (ID:%s List:%s) is not valid job to remove' % (job,jobid,cslist))    
    
    control=cs_helpers.readConfig(qpath+job)
    
    # in capisuite 0.4.3, the filename options in failed and done store the original file path
    # (e.g. /var/spool/capisuite/users/me/senq/fax-12.sff).
    datafile=control.get("GLOBAL","filename")
    if cslist=="faxdone" or cslist=="faxfailed":
        # color fax check:
        fileext="sff"
        #if os.path.splitext(datafile)[1].lower()==".cff":
        if datafile.endswith("cff"):
            fileext="cff"
        datafile=qpath+job[:-3]+fileext
    if not datafile:
        raise CSRemoveError('Job file "%s" (ID:%s List:%s) does not contain a link to a datafile (e.g. sff faxfile)'\
                            ' => Invalid job file' % (job,jobid,cslist))
    try:    
        lockfile=open(qpath+job[:-3]+"lock","w")
        # lock so that it isn't deleted while sending (or else)
        fcntl.lockf(lockfile,fcntl.LOCK_EX | fcntl.LOCK_NB)
        os.unlink(qpath+job)
        os.unlink(datafile)
        fcntl.lockf(lockfile,fcntl.LOCK_UN)
        os.unlink(qpath+job[:-3]+"lock")
    except IOError,err:
        if (err.errno in (errno.EACCES,errno.EAGAIN)):
            raise CSRemoveError("Job is currently in transmission or in similar use. Can't remove.")
Exemplo n.º 3
0
def capiconfig_init(file=""):
    global CAPI_config,UsersFax_Path,UsersVoice_Path,listpath
    UsersFax_Path=""
    UsersVoice_Path=""
    GlobalSpool_Path=""
    listpath = None

    CAPI_config=cs_helpers.readConfig(file)
    if not CAPI_config:
        raise CSConfigError
    UsersFax_Path=cs_helpers.getOption(CAPI_config,"","fax_user_dir",default="")
    if not UsersFax_Path:
        raise CSConfigError
    GlobalSpool_Path=cs_helpers.getOption(CAPI_config,"","spool_dir",default="")
    if not GlobalSpool_Path:
        raise CSConfigError
    # optional value:
    UsersVoice_Path=cs_helpers.getOption(CAPI_config,"","voice_user_dir",default="")
    listpath = {"fax_user_dir":UsersFax_Path,"spool_dir":GlobalSpool_Path,"voice_user_dir":UsersVoice_Path}
Exemplo n.º 4
0
def ChangeJob(user,jobid,cslist,dialstring=None,starttime=None,addressee=None,subject=None):
    """changes a job, imports missing values from the job file
    a replacement for change_job_advanced (not dual error checks, etc)
    """
    if (checkconfig() == -1) or (checkfaxuser(user,1) == 0):
        raise CSConfigError
    if not listtypes.has_key(cslist) or CheckJobID(jobid)==-1:
        raise CSInternalError("Invalid list/queue type or jobid provided")

    # the next line (if-statement), limit this funtion to only
    # modify the fax send queue
    if cslist!="faxsend":
        raise CSInternalError("Cannot modify any other queue than fax send")
    
    qpath=BuildListPath(cslist,user)
    if (not os.access(qpath,os.R_OK | os.W_OK )):
        raise CSInternalError("Can't read/write queue dir: "+cslist)
    jobfile = BuildJobFile(user,jobid,cslist)
    try:
        control=cs_helpers.readConfig(qpath+jobfile)
    except IOError,err:
        raise CSJobChangeError("Failed to read the jobfile - IOError: %s" % err)
Exemplo n.º 5
0
def idle(capi):
	config=cs_helpers.readConfig()
	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)):
		capisuite.error("Can't read/write to the necessary spool dirs")
		return

	userlist=config.sections()
	userlist.remove('GLOBAL')

	for user in userlist: # search in all user-specified sendq's
		userdata=pwd.getpwnam(user)
		outgoing_nr=cs_helpers.getOption(config,user,"outgoing_MSN","")
                if (outgoing_nr==""):
			incoming_nrs=cs_helpers.getOption(config,user,"fax_numbers","")
			if (incoming_nrs==""):
				continue
			else:
				outgoing_nr=(incoming_nrs.split(','))[0] 

		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])
		if (not os.access(sendq,os.F_OK)):
			os.mkdir(sendq,0700)
			os.chown(sendq,userdata[2],userdata[3])

		files=os.listdir(sendq)
		files=filter (lambda s: re.match("fax-.*\.txt",s),files)

		for job in files:
			job_fax="%ssff" % job[:-3]
			real_user_c=os.stat(os.path.join(sendq,job)).st_uid
			real_user_j=os.stat(os.path.join(sendq,job_fax)).st_uid
			if (real_user_j!=pwd.getpwnam(user)[2] or real_user_c!=pwd.getpwnam(user)[2]):
				capisuite.error("job %s seems to be manipulated (wrong uid)! Ignoring..." % os.path.join(sendq,job_fax))
				continue

			lockfile=open(os.path.join(sendq,"%slock" % job[:-3]),"w")
			# read directory contents
			fcntl.lockf(lockfile,fcntl.LOCK_EX) # lock so that it isn't deleted while sending

			if (not os.access(os.path.join(sendq,job),os.W_OK)): # perhaps it was cancelled?
				fcntl.lockf(lockfile,fcntl.LOCK_UN)
				lockfile.close()
				os.unlink(os.path.join(sendq,"%slock" % job[:-3]))
				continue

			control=cs_helpers.readConfig(os.path.join(sendq,job))
			# set DST value to -1 (unknown), as strptime sets it wrong for some reason
			starttime=(time.strptime(control.get("GLOBAL","starttime")))[0:8]+(-1,)
			starttime=time.mktime(starttime)
			if (starttime>time.time()):
				fcntl.lockf(lockfile,fcntl.LOCK_UN)
				lockfile.close()
				os.unlink(os.path.join(sendq,"%slock" % job[:-3]))
				continue

			tries=control.getint("GLOBAL","tries")
			dialstring=control.get("GLOBAL","dialstring")
			addressee=cs_helpers.getOption(control,"GLOBAL","addressee","")
			subject=cs_helpers.getOption(control,"GLOBAL","subject","")
			mailaddress=cs_helpers.getOption(config,user,"fax_email","")
			if (mailaddress==""):
				mailaddress=user
			fromaddress=cs_helpers.getOption(config,user,"fax_email_from","")
			if (fromaddress==""):
				fromaddress=user

			capisuite.log("job %s from %s to %s initiated" % (job_fax,user,dialstring),1)
			result,resultB3 = sendfax(capi,os.path.join(sendq,job_fax),outgoing_nr,dialstring,user,config)
			tries+=1
			capisuite.log("job %s: result was %x,%x" % (job_fax,result,resultB3),1)

			if (result in (0,0x3400,0x3480,0x3490,0x349f) and resultB3==0):
				movejob(job_fax,sendq,done,user)
				capisuite.log("job %s: finished successfully" % job_fax,1)
				mailtext="Your fax job to %s (%s) was sent successfully.\n\n" \
				  "Subject: %s\nFilename: %s\nNeeded tries: %i\n" \
				  "Last result: 0x%x/0x%x\n\nIt was moved to " \
				  "file://%s on host \"%s\"" % (addressee,dialstring, \
				  subject,job_fax,tries,result,resultB3, \
				  os.path.join(done,"%s-%s" % (user,job_fax)), \
				  os.uname()[1])
				cs_helpers.sendSimpleMail(fromaddress,mailaddress,
				  "Fax to %s (%s) sent successfully." % (addressee,dialstring),
				  mailtext)
			else:
				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-1)<len(delays)):
					next_delay=delays[tries-1]
				else:
					next_delay=delays[-1]
				starttime=time.time()+next_delay
				capisuite.log("job %s: delayed for %i seconds" % (job_fax,next_delay),2)
				cs_helpers.writeDescription(os.path.join(sendq,job_fax), \
				  "dialstring=\"%s\"\nstarttime=\"%s\"\ntries=\"%i\"\n" \
				  "user=\"%s\"\naddressee=\"%s\"\nsubject=\"%s\"\n" \
				  % (dialstring,time.ctime(starttime),tries,user, \
				  addressee,subject))
				if (tries>=max_tries):
					movejob(job_fax,sendq,failed,user)
					capisuite.log("job %s: failed finally" % job_fax,1)
					mailtext="I'm sorry, but your fax job to %s (%s) " \
					  "failed finally.\n\nSubject: %s\n" \
					  "Filename: %s\nTries: %i\n" \
					  "Last result: 0x%x/0x%x\n\n" \
					  "It was moved to file://%s-%s on host %s.\n\n" \
					  % (addressee,dialstring,subject,job_fax,tries,result, \
					  resultB3,os.path.join(failed,user),job_fax,os.uname()[1]) 
					cs_helpers.sendSimpleMail(fromaddress,mailaddress,
					  "Fax to %s (%s) FAILED." % (addressee,dialstring),
					  mailtext)

			fcntl.lockf(lockfile,fcntl.LOCK_UN)
			lockfile.close()
			os.unlink("%slock" % os.path.join(sendq,job[:-3]))
Exemplo n.º 6
0
			cs_helpers.sayNumber(call,str(len(curr_msgs)),curr_user,config)
			if (curr_msgs==messages):
				if (len(curr_msgs)==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)
			else:
				if (len(curr_msgs)==1):
					capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachricht.la"),1)
				else:
					capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachrichten.la"),1)

			i=0
			while (i<len(curr_msgs)):
				filename=userdir+"received/voice-"+str(curr_msgs[i])+".la"
				descr=cs_helpers.readConfig(filename[:-2]+"txt")
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachricht.la"),1)
				cs_helpers.sayNumber(call,str(i+1),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"von.la"),1)
				cs_helpers.sayNumber(call,descr.get('GLOBAL','call_from'),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"fuer.la"),1)
				cs_helpers.sayNumber(call,descr.get('GLOBAL','call_to'),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"am.la"),1)
				calltime=time.strptime(descr.get('GLOBAL','time'))
				cs_helpers.sayNumber(call,str(calltime[2]),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"..la"),1)
				cs_helpers.sayNumber(call,str(calltime[1]),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"..la"),1)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"um.la"),1)
				cs_helpers.sayNumber(call,str(calltime[3]),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"uhr.la"),1)
Exemplo n.º 7
0
			cs_helpers.sayNumber(call,str(len(curr_msgs)),curr_user,config,"f")
			if (curr_msgs==messages):
				if (len(curr_msgs)==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)
			else:
				if (len(curr_msgs)==1):
					capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachricht.la"),1)
				else:
					capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachrichten.la"),1)

			i=0
			while (i<len(curr_msgs)):
				filename=os.path.join(userdir,"received/voice-%i.la" % curr_msgs[i])
				descr=cs_helpers.readConfig("%stxt" % filename[:-2])
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"nachricht.la"),1)
				cs_helpers.sayNumber(call,str(i+1),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"von.la"),1)
				cs_helpers.sayNumber(call,descr.get('GLOBAL','call_from'),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"fuer.la"),1)
				cs_helpers.sayNumber(call,descr.get('GLOBAL','call_to'),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"am.la"),1)
				calltime=time.strptime(descr.get('GLOBAL','time'))
				cs_helpers.sayNumber(call,str(calltime[2]),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"..la"),1)
				cs_helpers.sayNumber(call,str(calltime[1]),curr_user,config)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"..la"),1)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"um.la"),1)
				cs_helpers.sayNumber(call,str(calltime[3]),curr_user,config,"n")
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"uhr.la"),1)