Exemple #1
0
def authenticate_admin(username, password):

    auth_user = AdminUser.query.filter(AdminUser.username == username).first()

    if not auth_user:
        log.debug("No user named: '%s'", username)
        return False
    elif not auth_user.password:
        log.error("Bad username/pass:'******'")
        return False
    elif password != auth_user.password:
        log.debug("Database password for user '%s'", username)
        return False
    else:
        request.environ["REMOTE_USER"] = auth_user.username
        request.environ["HTTP_REMOTE_USER"] = auth_user.username

    session["perms"] = auth_user.permissions
    session["user"] = auth_user
    session["name"] = auth_user.name
    session["user_id"] = auth_user.id

    auth_user.register_login(username, session, request)
    db.flush()
    session.save()
    return True
Exemple #2
0
def delete_conditions(route_id):
    for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).\
    filter(PbxRoute.id==route_id).filter(PbxRoute.context==session['context']).all():
        for condition in PbxCondition.query.filter_by(pbx_route_id=route.id).all():
            PbxAction.query.filter_by(pbx_condition_id=condition.id).delete()
            PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
    db.flush()
Exemple #3
0
def delete_ivr(name):
    for ivr in PbxIVR.query.filter_by(name=name).filter_by(context=session['context']).all():

        r = PbxRoute.query.filter(PbxRoute.pbx_route_type_id==5).\
        filter(PbxRoute.name==ivr.name).filter(PbxRoute.context==session['context']).first()
        did = PbxDid.query.filter(PbxDid.pbx_route_id==r.id).first()

        if did:
            msg = "Error: IVR is in use by Inbound DID: "+str(did.did)+"!"

        tod = db.execute("select * from pbx_tod_routes where match_route_id = :id or nomatch_route_id = :id", {'id': r.id}).first()

        if tod:
            msg = "Error: IVR is in a TOD route!"

        ivr_opt = PbxIVROption.query.filter(PbxIVROption.pbx_route_id==r.id).first()

        if ivr_opt:
            msg = "Error: IVR belongs to another IVR Option."


        if not did and not ivr_opt and not tod:
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==5).\
            filter(PbxRoute.name==ivr.name).filter(PbxRoute.context==session['context']).delete()
            PbxIVROption.query.filter(PbxIVROption.pbx_ivr_id==ivr.id).delete()
            PbxIVR.query.filter(PbxIVR.name==name).filter(PbxIVR.context==session['context']).delete()
            db.flush()
        else:
            return msg

        return "Successfully deleted IVR: "+name+"."
Exemple #4
0
def delete_conf(extension):
    PbxRoute.query.filter(PbxRoute.pbx_route_type_id==7)\
    .filter(PbxRoute.name==extension).filter(PbxRoute.context==session['context']).delete()
    PbxConferenceBridge.query.filter(
        PbxConferenceBridge.extension == extension).delete()
    db.flush()
    return True
Exemple #5
0
def queue_delete(q):
    for queue in CallCenterQueue.query.filter(CallCenterQueue.id==q.id).filter(CallCenterQueue.context==session['context']).all():
        PbxRoute.query.filter(PbxRoute.pbx_route_type_id==10).filter(PbxRoute.pbx_to_id==queue.id).delete()
        CallCenterTier.query.filter(CallCenterTier.queue_id==queue.id).delete()
    CallCenterQueue.query.filter(CallCenterQueue.id==q.id).filter(CallCenterQueue.context==session['context']).delete()
    db.flush()
    return True
Exemple #6
0
def authenticate_admin(username, password):

    auth_user = AdminUser.query.filter(AdminUser.username == username).first()

    if not auth_user:
        log.debug("No user named: '%s'", username)
        return False
    elif not auth_user.password:
        log.error("Bad username/pass:'******'")
        return False
    elif password != auth_user.password:
        log.debug("Database password for user '%s'", username)
        return False
    else:
        request.environ["REMOTE_USER"] = auth_user.username
        request.environ["HTTP_REMOTE_USER"] = auth_user.username

    session["perms"] = auth_user.permissions
    session["user"] = auth_user
    session["name"] = auth_user.name
    session['user_id'] = auth_user.id

    auth_user.register_login(username, session, request)
    db.flush()
    session.save()
    return True
Exemple #7
0
def delete_fax_ext(extension):
    for ext in PbxFax.query.filter(PbxFax.extension==extension).filter(PbxFax.context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==12).filter(PbxRoute.name==ext.extension).filter(PbxRoute.context==session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==12).filter(PbxRoute.name==ext.extension).filter(PbxRoute.context==session['context']).delete()
        PbxFax.query.filter(PbxFax.extension==extension).filter(PbxFax.context==session['context']).delete()
        db.flush()
    return True
Exemple #8
0
def delete_conditions(route_id):
    for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).\
    filter(PbxRoute.id==route_id).filter(PbxRoute.context==session['context']).all():
        for condition in PbxCondition.query.filter_by(
                pbx_route_id=route.id).all():
            PbxAction.query.filter_by(pbx_condition_id=condition.id).delete()
            PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
    db.flush()
Exemple #9
0
def delete_group(name):
    for group in PbxGroup.query.filter(PbxGroup.name==name).filter(PbxGroup.context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==4).\
        filter(PbxRoute.name==group.name).filter(PbxRoute.context==session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==4).\
            filter(PbxRoute.name==group.name).filter(PbxRoute.context==session['context']).delete()
        PbxGroup.query.filter(PbxGroup.name==name).filter(PbxGroup.context==session['context']).delete()
        db.flush()
    return True
Exemple #10
0
def delete_tts(name):
    tts = PbxTTS.query.filter(PbxTTS.name==name).filter(PbxTTS.context==session['context']).first()
    ivr = PbxIVR.query.filter(PbxIVR.audio_type==2).filter(PbxIVR.data==str(tts.id)).first()
    db.flush()

    if ivr:
        return "Error: That TTS is in use by the IVR named "+ivr.name+"!"
    else:
        PbxTTS.query.filter(PbxTTS.name==name).filter(PbxTTS.context==session['context']).delete()
        db.flush()
    return "Successfully deleted Text to Speech."
Exemple #11
0
def delete_tod(name):
    for tod in PbxTODRoute.query.filter(PbxTODRoute.name==name)\
    .filter(PbxTODRoute.context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==6)\
        .filter(PbxRoute.name==tod.name).filter(PbxRoute.context==session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==6).\
            filter(PbxRoute.name==tod.name).filter(PbxRoute.context==session['context']).delete()
        PbxTODRoute.query.filter(PbxTODRoute.name==name)\
        .filter(PbxTODRoute.context==session['context']).delete()
        db.flush()
    return True
Exemple #12
0
def delete_group(name):
    for group in PbxGroup.query.filter(PbxGroup.name == name).filter(
            PbxGroup.context == session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==4).\
        filter(PbxRoute.name==group.name).filter(PbxRoute.context==session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==4).\
            filter(PbxRoute.name==group.name).filter(PbxRoute.context==session['context']).delete()
        PbxGroup.query.filter(PbxGroup.name == name).filter(
            PbxGroup.context == session['context']).delete()
        db.flush()
    return True
Exemple #13
0
def delete_tod(name):
    for tod in PbxTODRoute.query.filter(PbxTODRoute.name==name)\
    .filter(PbxTODRoute.context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==6)\
        .filter(PbxRoute.name==tod.name).filter(PbxRoute.context==session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==6).\
            filter(PbxRoute.name==tod.name).filter(PbxRoute.context==session['context']).delete()
        PbxTODRoute.query.filter(PbxTODRoute.name==name)\
        .filter(PbxTODRoute.context==session['context']).delete()
        db.flush()
    return True
Exemple #14
0
def queue_delete(q):
    for queue in CallCenterQueue.query.filter(
            CallCenterQueue.id == q.id).filter(
                CallCenterQueue.context == session['context']).all():
        PbxRoute.query.filter(PbxRoute.pbx_route_type_id == 10).filter(
            PbxRoute.pbx_to_id == queue.id).delete()
        CallCenterTier.query.filter(
            CallCenterTier.queue_id == queue.id).delete()
    CallCenterQueue.query.filter(CallCenterQueue.id == q.id).filter(
        CallCenterQueue.context == session['context']).delete()
    db.flush()
    return True
Exemple #15
0
def delete_virtual_mailbox(extension):
    for ext in PbxVirtualMailbox.query.filter(PbxVirtualMailbox.extension==extension).filter(PbxVirtualMailbox.context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==3).filter(PbxRoute.name==ext.extension).filter(PbxRoute.context==session['context']).all():
            for condition in PbxCondition.query.filter_by(pbx_route_id=route.id).all():
                PbxAction.query.filter_by(pbx_condition_id=condition.id).delete()
                PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==3).filter(PbxRoute.name==ext.extension).filter(PbxRoute.context==session['context']).delete()
        for sg in PbxGroup.query.filter_by(context=session['context']).all():
            PbxGroupMember.query.filter_by(pbx_group_id=sg.id).filter_by(extension=extension).delete()
        PbxVirtualMailbox.query.filter(PbxVirtualMailbox.extension==extension).filter(PbxVirtualMailbox.context==session['context']).delete()
        db.flush()
    return True
Exemple #16
0
def delete_extension_by_user_id(user_id):
    for ext in PbxEndpoint.query.filter(PbxEndpoint.user_id==user_id).filter(PbxEndpoint.user_context==session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).filter(PbxRoute.name==ext.auth_id).filter(PbxRoute.context==session['context']).all():
            for condition in PbxCondition.query.filter_by(pbx_route_id=route.id).all():
                PbxAction.query.filter_by(pbx_condition_id=condition.id).delete()
                PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).filter(PbxRoute.name==ext.auth_id).filter(PbxRoute.context==session['context']).delete()
        for sg in PbxGroup.query.filter_by(context=session['context']).all():
            PbxGroupMember.query.filter_by(pbx_group_id=sg.id).filter_by(extension=ext.auth_id).delete()
        PbxEndpoint.query.filter(PbxEndpoint.user_id==user_id).filter(PbxEndpoint.user_context==session['context']).delete()
        db.flush()
    return True
Exemple #17
0
def delete_fax_ext(extension):
    for ext in PbxFax.query.filter(PbxFax.extension == extension).filter(
            PbxFax.context == session['context']).all():
        for route in PbxRoute.query.filter(
                PbxRoute.pbx_route_type_id == 12).filter(
                    PbxRoute.name == ext.extension).filter(
                        PbxRoute.context == session['context']).all():
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id == 12).filter(
                PbxRoute.name == ext.extension).filter(
                    PbxRoute.context == session['context']).delete()
        PbxFax.query.filter(PbxFax.extension == extension).filter(
            PbxFax.context == session['context']).delete()
        db.flush()
    return True
Exemple #18
0
def delete_tts(name):
    tts = PbxTTS.query.filter(PbxTTS.name == name).filter(
        PbxTTS.context == session['context']).first()
    ivr = PbxIVR.query.filter(PbxIVR.audio_type == 2).filter(
        PbxIVR.data == str(tts.id)).first()
    db.flush()

    if ivr:
        return "Error: That TTS is in use by the IVR named " + ivr.name + "!"
    else:
        PbxTTS.query.filter(PbxTTS.name == name).filter(
            PbxTTS.context == session['context']).delete()
        db.flush()
    return "Successfully deleted Text to Speech."
Exemple #19
0
    def ccq_add(self):
        schema = QueueForm()
        try:
            form_result = schema.to_python(request.params)
            ccq = CallCenterQueue()
            ccq.name = form_result['name']
            ccq.context = session['context']
            ccq.domain = session['context']
            ccq.audio_type = form_result.get('audio_name').split(",")[0]
            ccq.audio_name = form_result.get('audio_name').split(",")[1]
            ccq.moh_sound = form_result.get('moh_sound', 'local_stream://moh')
            ccq.time_base_score = form_result.get('time_base_score', 'system')
            ccq.max_wait_time = form_result.get('max_wait_time', 0)
            ccq.max_wait_time_with_no_agent = form_result.get(
                'max_wait_time_with_no_agent', 0)
            ccq.max_wait_time_with_no_agent_reached = form_result.get(
                'max_wait_time_with_no_agent_reached', 5)
            ccq.tier_rules_apply = form_result.get('tier_rules_apply', False)
            ccq.tier_rule_wait_second = form_result.get(
                'tier_rule_wait_second', 300)
            ccq.tier_rule_wait_multiply_level = form_result.get(
                'tier_rule_wait_multiply_level', False)
            ccq.tier_rule_agent_no_wait = form_result.get(
                'tier_rule_agent_no_wait', False)
            ccq.discard_abandoned_after = form_result.get(
                'discard_abandoned_after', 1800)
            ccq.abandoned_resume_allowed = form_result.get(
                'abandoned_resume_allowed', False)
            ccq.strategy = form_result.get('strategy', 'callback')
            ccq.failed_route_id = form_result.get('failed_route_id', 0)
            ccq.record_calls = form_result.get('record_calls', False)
            ccq.announce_position = form_result.get('announce_position', False)
            ccq.announce_sound = form_result.get('announce_sound').split(
                ",")[1]
            ccq.announce_frequency = form_result.get('announce_frequency')

            db.add(ccq)
            db.flush()

            dir = fs_vm_dir + session[
                'context'] + "/queue-recordings/" + ccq.name

            if not os.path.exists(dir):
                os.makedirs(dir)

        except validators.Invalid, error:
            db.rollback()
            return 'Error: %s.' % error
Exemple #20
0
def delete_extension_by_ext(extension):
    for ext in PbxEndpoint.query.filter(
            PbxEndpoint.auth_id == extension).filter(
                PbxEndpoint.user_context == session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).\
        filter(PbxRoute.name==ext.auth_id).filter(PbxRoute.context==session['context']).all():
            for condition in PbxCondition.query.filter_by(
                    pbx_route_id=route.id).all():
                PbxAction.query.filter_by(
                    pbx_condition_id=condition.id).delete()
                PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==1).\
            filter(PbxRoute.name==ext.auth_id).filter(PbxRoute.context==session['context']).delete()
        for sg in PbxGroup.query.filter_by(context=session['context']).all():
            PbxGroupMember.query.filter_by(pbx_group_id=sg.id).filter_by(
                extension=ext.auth_id).delete()
        PbxEndpoint.query.filter(PbxEndpoint.auth_id == extension).filter(
            PbxEndpoint.user_context == session['context']).delete()
        db.flush()
    return True
Exemple #21
0
def delete_virtual_extension(extension):
    for ext in PbxVirtualExtension.query.filter(
            PbxVirtualExtension.extension == extension).filter(
                PbxVirtualExtension.context == session['context']).all():
        for route in PbxRoute.query.filter(PbxRoute.pbx_route_type_id==2).\
        filter(PbxRoute.name==ext.extension).filter(PbxRoute.context==session['context']).all():
            for condition in PbxCondition.query.filter_by(
                    pbx_route_id=route.id).all():
                PbxAction.query.filter_by(
                    pbx_condition_id=condition.id).delete()
                PbxCondition.query.filter_by(pbx_route_id=route.id).delete()
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id == 2).filter(
                PbxRoute.name == ext.extension).filter(
                    PbxRoute.context == session['context']).delete()
        for sg in PbxGroup.query.filter_by(context=session['context']).all():
            PbxGroupMember.query.filter_by(pbx_group_id=sg.id).filter_by(
                extension=extension).delete()
        PbxVirtualExtension.query.filter(
            PbxVirtualExtension.extension == extension).filter(
                PbxVirtualExtension.context == session['context']).delete()
        db.flush()
    return True
Exemple #22
0
    def ccq_add(self):
        schema = QueueForm()
        try:
            form_result = schema.to_python(request.params)
            ccq = CallCenterQueue()
            ccq.name = form_result['name']
            ccq.context = session['context']
            ccq.domain = session['context']
            ccq.audio_type = form_result.get('audio_name').split(",")[0]
            ccq.audio_name = form_result.get('audio_name').split(",")[1]
            ccq.moh_sound = form_result.get('moh_sound', 'local_stream://moh')
            ccq.time_base_score = form_result.get('time_base_score', 'system')
            ccq.max_wait_time = form_result.get('max_wait_time', 0)
            ccq.max_wait_time_with_no_agent = form_result.get('max_wait_time_with_no_agent', 0)
            ccq.max_wait_time_with_no_agent_reached = form_result.get('max_wait_time_with_no_agent_reached', 5)
            ccq.tier_rules_apply = form_result.get('tier_rules_apply', False)
            ccq.tier_rule_wait_second = form_result.get('tier_rule_wait_second', 300)
            ccq.tier_rule_wait_multiply_level = form_result.get('tier_rule_wait_multiply_level', False)
            ccq.tier_rule_agent_no_wait = form_result.get('tier_rule_agent_no_wait', False)
            ccq.discard_abandoned_after = form_result.get('discard_abandoned_after', 1800)
            ccq.abandoned_resume_allowed = form_result.get('abandoned_resume_allowed', False)
            ccq.strategy = form_result.get('strategy', 'callback')
            ccq.failed_route_id = form_result.get('failed_route_id', 0)
            ccq.record_calls = form_result.get('record_calls', False)
            ccq.announce_position = form_result.get('announce_position', False)
            ccq.announce_sound = form_result.get('announce_sound').split(",")[1]
            ccq.announce_frequency = form_result.get('announce_frequency')

            db.add(ccq)
            db.flush()

            dir = fs_vm_dir+session['context']+"/queue-recordings/"+ccq.name

            if not os.path.exists(dir):
                os.makedirs(dir)

        except validators.Invalid, error:
            db.rollback()
            return 'Error: %s.' % error
Exemple #23
0
def delete_ivr(name):
    for ivr in PbxIVR.query.filter_by(name=name).filter_by(
            context=session['context']).all():

        r = PbxRoute.query.filter(PbxRoute.pbx_route_type_id==5).\
        filter(PbxRoute.name==ivr.name).filter(PbxRoute.context==session['context']).first()
        did = PbxDid.query.filter(PbxDid.pbx_route_id == r.id).first()

        if did:
            msg = "Error: IVR is in use by Inbound DID: " + str(did.did) + "!"

        tod = db.execute(
            "select * from pbx_tod_routes where match_route_id = :id or nomatch_route_id = :id",
            {
                'id': r.id
            }).first()

        if tod:
            msg = "Error: IVR is in a TOD route!"

        ivr_opt = PbxIVROption.query.filter(
            PbxIVROption.pbx_route_id == r.id).first()

        if ivr_opt:
            msg = "Error: IVR belongs to another IVR Option."

        if not did and not ivr_opt and not tod:
            PbxRoute.query.filter(PbxRoute.pbx_route_type_id==5).\
            filter(PbxRoute.name==ivr.name).filter(PbxRoute.context==session['context']).delete()
            PbxIVROption.query.filter(
                PbxIVROption.pbx_ivr_id == ivr.id).delete()
            PbxIVR.query.filter(PbxIVR.name == name).filter(
                PbxIVR.context == session['context']).delete()
            db.flush()
        else:
            return msg

        return "Successfully deleted IVR: " + name + "."
Exemple #24
0
    def campaign_add(self, **kw):
        schema = CrmCampaignForm()
        try:
            form_result = schema.to_python(request.params)
            crm_campaign = CrmCampaign()
            crm_campaign.name = form_result.get('campaign_name')
            crm_campaign.context = session['context']

            db.add(crm_campaign)
            db.flush()

            crm_group = CrmGroup()
            group.name = form_result.get('campaign_name')
            db.add(crm_group)
            db.flush()

            crm_campaign_group = CrmCampaignGroup()
            crm_campaign_group.name = form_result.get('campaign_name')
            crm_campaign_group.crm_group_id = crm_group.id
            crm_campaign_group.crm_campaign_id = crm_campaign.id
            crm_campaign_group.context = session['context']
            db.add(crm_campaign_group)
            db.flush()

            for extension in form_result.get('campaign_extensions').split(","):
                if not extension.isdigit():
                    continue
                crm_group_member = CrmGroupMember()
                crm_group_member.crm_group_id = crm_group.id
                crm_group_member.context = session['context']
                crm_group_member.extension = extension

                db.add(crm_group_member)
                db.commit()

        except validators.Invalid, error:
            db.rollback()
            return 'Error: %s' % error
Exemple #25
0
def delete_cid(cid_number):
    PbxCallerIDRoute.query.filter(PbxCallerIDRoute.cid_number==cid_number)\
    .filter(PbxCallerIDRoute.context==session['context']).delete()
    db.flush()
    return True
Exemple #26
0
def delete_did(context, did_id):
    PbxRoute.query.filter_by(context=context,
                             pbx_to_id=did_id,
                             pbx_route_type_id=9).delete()
    PbxDid.query.filter_by(context=context, id=did_id).delete()
    db.flush()
Exemple #27
0
def delete_customer(context):
    PbxRoute.query.filter(PbxRoute.context==context).delete()
    Customer.query.filter(Customer.context==context).delete()
    db.flush()
Exemple #28
0
def delete_did(context, did_id):
    PbxRoute.query.filter_by(context=context, pbx_to_id=did_id, pbx_route_type_id=9).delete()
    PbxDid.query.filter_by(context=context, id=did_id).delete()
    db.flush()
Exemple #29
0
def del_blacklist(cid_number):
    PbxBlacklistedNumber.query.filter(PbxBlacklistedNumber.cid_number==cid_number)\
    .filter(PbxBlacklistedNumber.context==session['context']).delete()
    db.flush()
    return True
Exemple #30
0
def delete_customer(context):
    PbxRoute.query.filter(PbxRoute.context == context).delete()
    Customer.query.filter(Customer.context == context).delete()
    db.flush()
Exemple #31
0
def delete_conf(extension):
    PbxRoute.query.filter(PbxRoute.pbx_route_type_id==7)\
    .filter(PbxRoute.name==extension).filter(PbxRoute.context==session['context']).delete()
    PbxConferenceBridge.query.filter(PbxConferenceBridge.extension==extension).delete()
    db.flush()
    return True
Exemple #32
0
def del_blacklist(cid_number):
    PbxBlacklistedNumber.query.filter(PbxBlacklistedNumber.cid_number==cid_number)\
    .filter(PbxBlacklistedNumber.context==session['context']).delete()
    db.flush()
    return True
Exemple #33
0
def delete_cid(cid_number):
    PbxCallerIDRoute.query.filter(PbxCallerIDRoute.cid_number==cid_number)\
    .filter(PbxCallerIDRoute.context==session['context']).delete()
    db.flush()
    return True