def delete(self, id, **kw): ''' Delete queue from DB ''' log.info(u'delete ' + kw['_id']) q = DBSession.query(Queue).get(kw['_id']) gn = (u'SV %s' % q.name, u'AG %s' % q.name) log.info(u'delete ' + kw['_id']) DBSession.delete(q) # Delete supervisor and members groups for g in DBSession.query(Group).filter(Group.group_name.in_(gn)): log.info(u'delete group "%s"' % g) DBSession.delete(g) # Remove MOH dir moh_class = asterisk_string(q.name, no_space=True) moh_dir = '/var/lib/asterisk/moh/fr/astportal/%s' % moh_class asterisk_shell('rm -rf "%s"' % moh_dir) res = Globals.manager.update_config( dir_asterisk + 'musiconhold.conf', None, [('DelCat', moh_class)]) # Delete Asterisk queue res = Globals.manager.update_config( dir_asterisk + 'queues.conf', None, [('DelCat', moh_class)]) log.debug('Delete queue "%s" returns %s' % (moh_class, res)) Globals.manager.send_action({'Action': 'QueueReload'}) if q.name in Globals.asterisk.queues.keys(): # Delete from list of queues del(Globals.asterisk.queues[moh_class]) Globals.manager.send_action({'Action': 'QueueStatus'}) flash(u'Groupe d\'appels supprimé', 'notice') redirect('/queues/')
def delete(self, id, **kw): ''' Delete department from DB ''' log.info('delete ' + kw['_id']) DBSession.delete(DBSession.query(Department).get(kw['_id'])) flash(u'Service supprimé', 'notice') redirect('/departments/')
def put(self, **kw): ''' Update sound in DB ''' id = int(kw['id']) s = DBSession.query(Sound).get(id) if kw.has_key('owner_id'): s.owner_id = kw['owner_id'] s.comment = kw['comment'] wav = kw['file'] filetype = wav.type filedata = wav.file filename = '%s/%d_%s' % (dir_tmp, s.sound_id, wav.filename) # Temporarily save uploaded audio file out = open(filename, 'w') out.write(filedata.read()) out.close() ret = process_file(filename, filetype, s.sound_id, filetype, s.name, s.language) if ret: flash(ret,'error') DBSession.delete(s) redirect('/moh/') flash(u'Son modifié') redirect('/moh/%d/edit' % id)
def delete(self, id, **kw): ''' Delete contact from DB ''' log.info('delete ' + kw['_id']) DBSession.delete(DBSession.query(Phonebook).get(kw['_id'])) flash(u'Contact supprimé', 'notice') redirect('/phonebook/')
def create(self, **kw): ''' Add new fax to DB ''' f = Fax() f.type = 0 # 0=Sent, 1=Received f.comment = kw['comment'] f.dest = kw['dest'] f.filename = kw['file'].filename u = DBSession.query(User).filter(User.user_name==request.identity['repoze.who.userid']).one() f.user_id = u.user_id try: f.src = u.phone[0].exten except: f.src = None # Try to insert file in DB: might fail if name already exists try: DBSession.add(f) DBSession.flush() except: flash(u'Impossible de créer le fax', 'error') redirect('/fax/') ret, pdf_data = process_file(kw['file'], f.fax_id, kw['dest'], u.email_address) if ret is not None: flash(ret,'error') DBSession.delete(f) redirect('/fax/') f.pdf = pdf_data flash(u'"%s" en cours d\'envoi à %s' % (kw['file'].filename, kw['dest'])) redirect('/fax/')
def delete(self, id, **kw): ''' Delete shortcut from DB ''' log.info('delete ' + kw['_id']) DBSession.delete(DBSession.query(Shortcut).get(kw['_id'])) flash(u'Raccourci supprimé', 'notice') redirect('/shortcuts/')
def delete(self, id, **kw): ''' Delete group from DB ''' log.info('delete ' + kw['_id']) DBSession.delete(DBSession.query(Group).get(kw['_id'])) flash(u'Groupe supprimé', 'notice') redirect('/groups/')
def delete(self, id, **kw): ''' Delete holiday from DB ''' log.info('delete ' + kw['_id']) DBSession.delete(DBSession.query(Holiday).get(kw['_id'])) update_extensions() flash(u'Jour férié supprimé', 'notice') redirect('/holidays/')
def create(self, **kw): ''' Add new sound to DB ''' s = Sound() s.name = kw['name'] if kw['type'] == 'moh': s.type = 0 elif kw['type'] == 'ringtone': s.type = 2 else: s.type = 1 s.comment = kw['comment'] s.language = kw['lang'] if 'owner_id' in kw.keys(): s.owner_id = kw['owner_id'] else: s.owner_id = request.identity['user'].user_id # Try to insert file in DB: might fail if name already exists try: DBSession.add(s) DBSession.flush() except: flash(u'Impossible de créer le son (vérifier son nom)', 'error') redirect('/moh/') if kw['record']: uphones = DBSession.query(User).get(request.identity['user'].user_id).phone # XXX if len(uphones)<1: # return dict(status=2) chan = uphones[0].sip_id.encode('iso-8859-1') filename = '/tmp/record-%s.wav' % chan filetype = 'audio/wav' else: wav = kw['file'] filetype = wav.type filedata = wav.file filename = '%s/%d_%s' % (dir_tmp, s.sound_id, wav.filename) # Temporarily save uploaded audio file out = open(filename, 'w') out.write(filedata.read()) out.close() ret = process_file(filename, filetype, s.sound_id, s.type, s.name, kw['lang']) if ret: flash(ret,'error') DBSession.delete(s) redirect('/moh/') flash(u'"%s" ajouté à votre bibliothèque sonore' % (s.name)) redirect('/moh/')
def delete(self, id, **kw): ''' Delete record ''' r = DBSession.query(Record).get(kw['_id']) fn = '%s/rec-%s.wav' % (dir_monitor, r.uniqueid) # remove file try: unlink(fn) except: log.error('unlink failed %s' % r.uniqueid) DBSession.delete(r) flash(u'Enregistrement supprimé', 'notice') redirect('/records/')
def delete(self, id, **kw): ''' Delete fax from DB ''' id = kw['_id'] log.info('delete ' + id) f = DBSession.query(Fax).get(id) # remove uploaded file try: if f.type==0: pdf = '%s/%d_%s' % (dir_fax, f.fax_id, re.sub(r'[^\w\.]', '_', f.filename)) else: pdf = '%s/%s' % (dir_fax, f.filename) unlink(pdf) except: # No file since move into fax in database log.warning('unlink failed %s' % id) DBSession.delete(f) flash(u'Fax supprimé', 'notice') redirect('/fax/')
def delete(self, id, **kw): """ Delete application from DB """ id = int(kw["_id"]) a = DBSession.query(Application).get(id) log.info(u"Delete application %d" % id) # 1. Delete scenario DBSession.query(Scenario).filter(Scenario.app_id == a.app_id).delete() # 2. Delete application DBSession.delete(a) # 3. Recreate extensions result = generate_dialplan() if result == 0: flash(u"Application supprimée") else: flash(u"Application supprimée", error) redirect("/applications/")
def delete(self, id, **kw): ''' Delete user from DB ''' u = DBSession.query(User).get(kw['_id']) # Delete voicemail if u.voicemail: for p in u.phone: res = Globals.manager.update_config( dir_ast + 'voicemail.conf', None, [('Delete', 'astportal', p.exten)]) log.debug('Delete voicemail.conf returns %s' % res) rmtree('%s/%s' % (dir_vm, p.exten), True) log.info('Delete voicemail directory %s/%s' % (dir_vm, p.exten)) Globals.manager.send_action({'Action': 'Command', 'command': 'voicemail reload'}) # Then delete user log.info('delete ' + kw['_id']) DBSession.delete(u) flash(u'Utilisateur supprimé', 'notice') redirect('/users/')
def delete(self, id, **kw): ''' Delete sound from DB ''' id = kw['_id'] log.info('delete ' + id) s = DBSession.query(Sound).get(id) # remove uploaded file try: dir = (dir_moh if s.type==0 else dir_sounds) % s.language unlink('%s/%s.wav' % (dir, re.sub(r'\W', '_', s.name))) except: log.error('unlink failed %s' % s.name) s = DBSession.delete(s) try: Globals.manager.send_action({'Action': 'Command', 'Command': 'moh reload'}) except: pass flash(u'Son supprimé', 'notice') redirect('/moh/')
def delete(self, id, **kw): ''' Delete phone from DB ''' p = DBSession.query(Phone).get(kw['_id']) log.info('delete %s (exten=%s, dnis=%s, sip=%s' % \ (kw['_id'], p.exten, p.dnis, p.sip_id)) # Remove from database DBSession.delete(p) # Update Asterisk config files if p.exten: # Update Asterisk DataBase Globals.manager.send_action({'Action': 'DBdel', 'Family': 'exten', 'Key': p.exten}) Globals.manager.send_action({'Action': 'DBdel', 'Family': 'netxe', 'Key': p.sip_id}) # Delete context, hint... actions = [ ('DelCat', p.sip_id), ('Delete', 'hints', 'exten', None, '%s,hint,%s/%s' % ( p.exten, 'SIP' if sip_type=='sip' else 'PJSIP', p.sip_id))] # ... and DNIS if p.dnis is not None: actions.append(('Delete', 'dnis', 'exten', None, '%s,1,Gosub(stdexten,%s,1)' % (p.dnis[-4:], p.exten))) res = Globals.manager.update_config( directory_asterisk + 'extensions.conf', 'dialplan', actions) log.debug('Delete context, hint (DNIS) from extensions.conf returns %s' % res) # Delete voicemail entry res = Globals.manager.update_config(directory_asterisk + 'voicemail.conf', 'app_voicemail', [ ('Delete', 'astportal', p.exten) ]) log.debug('Delete entry from voicemail.conf returns %s' % res) # Delete SIP entry actions = [ ('DelCat', p.sip_id) ] if sip_type=='sip': res = Globals.manager.update_config(directory_asterisk + 'sip.conf', 'chan_sip', actions) else: res = Globals.manager.update_config(directory_asterisk + 'pjsip_wizard.conf', 'res_pjsip', actions) log.debug('Delete entry from SIP returns %s' % res) mac = p.mac.replace(':', '') if p.mac is not None else '' if p.vendor=='Grandstream': # Remove private firmware directory tftp = directory_tftp + 'phones/firmware' try: for f in listdir('%s/%s' % (tftp, mac)): unlink('%s/%s/%s' % (tftp, mac, f)) rmdir('%s/%s' % (tftp, mac)) except: log.error('rmdir error %s/%s' % (tftp, mac)) # Backup phone configuration try: config = directory_tftp + 'phones/config/cfg%s' % mac rename(config, config + '.BAK') rename(config + '.txt', config + '.txt.BAK') log.warning('%s Config files saved' % mac) except: log.error('%s Config files save (%s)' % (mac, config)) flash(u'Téléphone supprimé', 'notice') redirect('/phones/')