Ejemplo n.º 1
0
   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/')
Ejemplo n.º 2
0
   def create(self, pwd1, pwd2, **kw):
      ''' Add new user to DB
      '''
      if DBSession.query(User).filter(User.user_name==kw['user_name']).all():
         flash(u'Ce compte existe déjà, utilisateur pas créé', 'error')
         redirect('/users/')

      log.info('new ' + kw['user_name'])
      u = User()
      u.user_name = kw['user_name']
      u.firstname = kw['firstname']
      u.lastname = kw['lastname']
      u.email_address = kw['email_address']
      u.fax = kw['fax']
      u.voicemail = kw['voicemail']
      u.email_voicemail = kw['email_voicemail']
      u.password = pwd1
      u.display_name = u.lastname + ' ' + u.firstname
      u.ascii_name = asterisk_string(u.display_name)
      over = kw.get('over')
      if over is not None:
         Globals.manager.send_action({'Action': 'DBput',
            'Family': 'over', 'Key': over, 'Val': 'context'})

      if 'groups' in kw:
         u.groups = DBSession.query(Group).\
               filter(Group.group_id.in_(kw['groups'])).all()

      DBSession.add(u)
      flash(u'Nouvel utilisateur "%s" créé' % (kw['user_name']))

      redirect('/users/')
Ejemplo n.º 3
0
   def put(self, **kw):
      ''' Update user in DB
      '''
      if not in_group('admin') and request.identity['user'].user_id != kw['user_id']:
         flash(u'Accès interdit !', 'error')
         redirect('/')

      uid = int(kw['user_id'])
      log.info('update user %d (voicemail=%s, email_voicemail=%s)' % (uid, kw['voicemail'], kw['email_voicemail']))
      u = DBSession.query(User).get(uid)
      u.firstname = kw['firstname']
      u.lastname = kw['lastname']
      u.email_address = kw['email_address']
      u.fax = kw['fax']
      u.voicemail = kw['voicemail']
      u.email_voicemail = kw['email_voicemail']
      u.password = kw['pwd1'] 
      u.display_name = u.lastname + ' ' + u.firstname
      u.ascii_name = asterisk_string(u.display_name)

      for p in u.phone:

         # Update fax_reject
         if u.fax:
            Globals.manager.send_action({'Action': 'DBdel',
               'Family': 'fax_reject', 'Key': p.exten})
         else:
            Globals.manager.send_action({'Action': 'DBput',
               'Family': 'fax_reject', 'Key': p.exten, 'Val': 1})

         # Update voicemail
         # First, delete existing voicemail entry
         Globals.manager.update_config(
            dir_ast  + 'voicemail.conf', 
            None, [('Delete', 'astportal', p.exten)])
         rmtree('%s/%s' % (dir_vm, p.exten), True)
         log.info('Delete voicemail directory %s/%s' % (dir_vm, p.exten))
         res = Globals.manager.update_config(
            sip_file, sip_chan, [('Delete', p.sip_id, mailbox)])
         log.debug('Update SIP (delete mb) returns %s' % res)

         if u.voicemail:
            # Then, add new voicemail
            vm = u'>%s,%s,%s' \
               % (u.password, u.ascii_name, u.email_address if u.email_voicemail else '')
            res = Globals.manager.update_config(
               dir_ast  + 'voicemail.conf', 
               'app_voicemail', [('Append', 'astportal', p.exten, vm)])
            log.debug('Update voicemail.conf returns %s' % res)


            res = Globals.manager.update_config(
               sip_file, sip_chan, 
               [('Append', p.sip_id, mailbox, '%s@astportal' % p.exten)]
               )
            log.debug('Update SIP (append) returns %s' % res)

         # Last, reload Asterisk
         Globals.manager.send_action({'Action': 'Command',
               'command': 'voicemail reload'})
         Globals.manager.send_action({'Action': 'Command',
               'command': sip_type + ' reload' })

      if kw.has_key('user_name'): # Modification par administrateur
         u.user_name = kw['user_name']
         u.groups = DBSession.query(Group). \
               filter(Group.group_id.in_(kw['groups'])).all()

      flash(u'Utilisateur modifié')
      redirect('/users/%d/edit' % uid)
Ejemplo n.º 4
0
    def pdf_export(self, id, **kw):

        app = DBSession.query(Application).get(id)
        log.info("pdf_export: id=%s" % (id))

        action_by_id = {}
        for a in DBSession.query(Action):
            action_by_id[a.action_id] = asterisk_string(a.name)

        prev_context = None
        nodes = []
        edges = []
        label = []
        for s in (
            DBSession.query(Scenario).filter(Scenario.app_id == id).order_by(Scenario.context).order_by(Scenario.step)
        ):

            if prev_context is None:  # First loop
                log.debug(" * * * First context")
                prev_context = s.context

            elif prev_context != s.context:  # Next context
                log.debug(" * * * Write context %s" % prev_context)
                nodes.append(mk_label(label, action_by_id))
                label = []
                prev_context = s.context

            edges += mk_edges(s)
            label.append(s)

        log.debug(" * * * Write last %s" % prev_context)
        nodes.append(mk_label(label, action_by_id))

        dir_tmp = mkdtemp()
        dot = open(dir_tmp + "/graphviz.dot", "w")
        dot.write("digraph g {\n")
        for n in nodes:
            dot.write(asterisk_string(n))
        log.debug("edges: %s" % edges)
        for e in edges:
            dot.write(asterisk_string(e))
        dot.write("}\n")
        dot.close()

        fn = "%s/%s.pdf" % (dir_tmp, app.name)
        from pygraphviz import AGraph

        g = AGraph(dir_tmp + "/graphviz.dot")
        log.debug(" * * * AGraph encoding %s" % g.encoding)
        g.layout(prog="dot")
        g.draw(fn)

        import os

        try:
            st = os.stat(fn)
            f = open(fn)
        except:
            flash(u"Erreur à la génération du fichier PDF", "error")
            redirect("")
        rh = response.headers
        rh["Pragma"] = "public"  # for IE
        rh["Expires"] = "0"
        rh["Cache-control"] = "must-revalidate, post-check=0, pre-check=0"  # for IE
        rh["Cache-control"] = "max-age=0"  # for IE
        rh["Content-Type"] = "application/pdf"
        rh["Content-Disposition"] = str(
            (u'attachment; filename="%s.pdf"; size=%d;' % (app.name, st.st_size)).encode("utf-8")
        )
        rh["Content-Transfer-Encoding"] = "binary"
        return f.read()