예제 #1
0
파일: util.py 프로젝트: Kirembu/FreePyBX
def del_blacklist(cid_number):
    PbxBlacklistedNumber.query.filter(PbxBlacklistedNumber.cid_number==cid_number)\
    .filter(PbxBlacklistedNumber.context==session['context']).delete()
    db.commit()
    db.flush()
    db.remove()
    return True
예제 #2
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def update_campaign_grid(self, **kw):

        w = loads(urllib.unquote_plus(request.params.get("data")))

        try:
            for i in w['modified']:
                sg = CrmCampaignGroup.query.filter(
                    CrmCampaignGroup.crm_campaign_id == i['id']).filter(
                        CrmCampaignGroup.context ==
                        session['context']).first()
                CrmGroupMember.query.filter(
                    CrmGroupMember.crm_group_id == sg.crm_group_id).delete()

                for gm in i['members'].split(","):
                    if not gm.strip().isdigit():
                        continue
                    sm = CrmGroupMember()
                    sm.crm_group_id = sg.crm_group_id
                    sm.extension = gm.strip()
                    sm.context = session['context']

                    db.add(sm)
                    db.commit()
                    db.flush()
        except:
            db.remove()
            return "Error updating campaign."

        return "Successfully updated campaign."
예제 #3
0
    def getCallers(self, sid):
        callers = []
        user = User.query.filter_by(session_id=sid).first()
        if user:
            context = user.get_context()

        for row in PbxDid.query.filter(PbxDid.context==context).all():
            for cal in db.execute("SELECT * FROM channels WHERE dest like :did", {'did': "%"+row.did}).fetchall():
                #PbxChannel.query.filter(PbxChannel.dest.like('%'+row.did).all():
                l =  PbxChannel.query.filter_by(uuid=cal.uuid).first()
                if l:
                    to_user = l.dest
                    status = l.callstate
                else:
                    to_user = ""
                    status = ""
                direction = "inbound"
                if len(cal.cid_num) > 10:
                    cid_num = cal.cid_num[len(cal.cid_num)-10:]
                else:
                    cid_num = cal.cid_num

                time_in_queue = db.execute("SELECT now() FROM channels WHERE uuid = :uuid", {'uuid': cal.uuid}).fetchone()
                callers.append(make_caller(cal.dest, cal.cid_name,cid_num, direction, cal.created, time_in_queue[0], to_user, cal.uuid, status))

        for cal in PbxChannel.query.filter_by(context=context).distinct(PbxChannel.call_uuid).all():
            if len(cal.presence_id)>3:
                if cal.presence_id.split("@")[1] == context:
                    time_in_queue = db.execute("SELECT now() FROM channels WHERE uuid = :uuid", {'uuid': cal.uuid}).fetchone()
            callers.append(make_caller(cal.dest, cal.cid_name, cal.cid_num, "outbound", cal.created, "", cal.dest, cal.uuid, cal.callstate))

        db.remove()
        return callers
예제 #4
0
    def getUsers(self, sid):
        users = []
        ep_stats = []
        user = User.query.filter_by(session_id=sid).first()

        if user:
            context = user.get_context()
        else:
            raise Exception("No session id in db matching the user calling this method.")

        for r in db.execute("SELECT DISTINCT users.first_name, users.last_name, users.id, users.customer_id, "
                            "customers.context AS context, users.portal_extension, "
                            "users.tel, users.mobile, users.username, sip_dialogs.uuid AS uuid "
                            "FROM users "
                            "INNER JOIN customers ON users.customer_id = customers.id "
                            "LEFT JOIN sip_dialogs ON sip_dialogs.presence_id = users.portal_extension || '@' || customers.context "
                            "WHERE customers.context = :context ORDER BY users.id", {'context': context}):

            for pbx_reg in PbxRegistration.query.filter(PbxRegistration.sip_realm==context).filter(PbxRegistration.sip_user==r[5]).all():
                ep_stats.append({'ip': pbx_reg.network_ip, 'port':pbx_reg.network_port})

            is_online = True if len(ep_stats) > 0 else False
            ep_stats = []

            # make_broker_user(name, id, customer_id, email, tel, mobile, ext, uuid, is_online):
            users.append(make_broker_user(r[0]+' '+r[1], r[2], r[3], r[8], r[6], r[7], r[5], r[9], is_online))

        db.remove()
        return users
예제 #5
0
def del_blacklist(cid_number):
    PbxBlacklistedNumber.query.filter(PbxBlacklistedNumber.cid_number==cid_number)\
    .filter(PbxBlacklistedNumber.context==session['context']).delete()
    db.commit()
    db.flush()
    db.remove()
    return True
예제 #6
0
    def ad_audio(self):
        items = []
        dir = fs_vm_dir + session["context"] + "/recordings/"
        try:
            for i in os.listdir(dir):
                fo = generateFileObject(i, "", dir)
                items.append(
                    {
                        "id": "1," + fo["name"],
                        "name": "Recording: " + fo["name"],
                        "data": fo["path"],
                        "type": 1,
                        "real_id": "",
                    }
                )

            db.remove()
        except:
            pass
        out = dict({"identifier": "id", "label": "name", "items": items})

        response = make_response(out)
        response.headers = [("Content-type", "application/json; charset=UTF-8")]

        return response(request.environ, self.start_response)
예제 #7
0
def delete_cid(cid_number):
    PbxCallerIDRoute.query.filter(PbxCallerIDRoute.cid_number==cid_number)\
    .filter(PbxCallerIDRoute.context==session['context']).delete()
    db.commit()
    db.flush()
    db.remove()
    return True
예제 #8
0
    def agent_edit(self):
        schema = AgentEditForm()
        try:
            form_result = schema.to_python(request.params)
            cca = (
                CallCenterAgent.query.filter_by(context=session["context"])
                .filter(CallCenterAgent.id == form_result.get("agent_id"))
                .first()
            )
            cca.extension = form_result.get("extension")
            e = (
                PbxEndpoint.query.filter_by(user_context=session["context"])
                .filter(PbxEndpoint.auth_id == cca.extension)
                .first()
            )
            cca.context = session["context"]
            cca.domain = session["context"]
            cca.type = "callback"
            cca.record_calls = form_result.get("record_calls", 0)
            cca.timeout = form_result.get("timeout", 30)
            cca.max_no_answer = form_result.get("max_no_answer", 3)
            cca.wrap_up_time = form_result.get("wrap_up_time", 30)
            cca.reject_delay_time = form_result.get("reject_delay_time", 30)
            cca.busy_delay_time = form_result.get("busy_delay_time", 0)
            cca.no_answer_delay_time = form_result.get("no_answer_delay_time", 5)
            cca.user_id = e.user_id
            cca.pbx_endpoint_id = e.id

            db.commit()
            db.flush()

        except validators.Invalid, error:
            db.remove()
            return "Error: %s." % error
예제 #9
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def campaigns(self):
        items = []
        members = []
        for campaign in CrmCampaign.query.filter(
                context=session['context']).all():
            for member in CrmGroupMember.query.join(CrmGroup).join(
                    CrmCampaignGroup).filter(
                        CrmCampaignGroup.crm_campaign_id == campaign.id).all():
                members.append(member.extension)
            items.append({
                'id': campaign.id,
                'name': campaign.name,
                'members': ",".join(members)
            })
            members = []

        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json'),
        ]

        return response(request.environ, self.start_response)
예제 #10
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.did.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.commit()
            db.flush()
            db.remove()
        else:
            return msg

        db.remove()
        return "Successfully deleted IVR: "+name+"."
예제 #11
0
    def ad_audio(self):
        items = []
        dir = fs_vm_dir + session['context'] + "/recordings/"
        try:
            for i in os.listdir(dir):
                fo = generateFileObject(i, "", dir)
                items.append({
                    'id': '1,' + fo["name"],
                    'name': 'Recording: ' + fo["name"],
                    'data': fo["path"],
                    'type': 1,
                    'real_id': ""
                })

            db.remove()
        except:
            pass
        out = dict({'identifier': 'id', 'label': 'name', 'items': items})

        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json; charset=UTF-8'),
        ]

        return response(request.environ, self.start_response)
예제 #12
0
파일: util.py 프로젝트: Kirembu/FreePyBX
def delete_cid(cid_number):
    PbxCallerIDRoute.query.filter(PbxCallerIDRoute.cid_number==cid_number)\
    .filter(PbxCallerIDRoute.context==session['context']).delete()
    db.commit()
    db.flush()
    db.remove()
    return True
예제 #13
0
    def agent_edit(self):
        schema = AgentEditForm()
        try:
            form_result = schema.to_python(request.params)
            cca = CallCenterAgent.query.filter_by(
                context=session['context']).filter(
                    CallCenterAgent.id == form_result.get('agent_id')).first()
            cca.extension = form_result.get('extension')
            e = PbxEndpoint.query.filter_by(
                user_context=session['context']).filter(
                    PbxEndpoint.auth_id == cca.extension).first()
            cca.context = session['context']
            cca.domain = session['context']
            cca.type = 'callback'
            cca.record_calls = form_result.get('record_calls', 0)
            cca.timeout = form_result.get('timeout', 30)
            cca.max_no_answer = form_result.get('max_no_answer', 3)
            cca.wrap_up_time = form_result.get('wrap_up_time', 30)
            cca.reject_delay_time = form_result.get('reject_delay_time', 30)
            cca.busy_delay_time = form_result.get('busy_delay_time', 0)
            cca.no_answer_delay_time = form_result.get('no_answer_delay_time',
                                                       5)
            cca.user_id = e.user_id
            cca.pbx_endpoint_id = e.id

            db.commit()
            db.flush()

        except validators.Invalid, error:
            db.remove()
            return 'Error: %s.' % error
예제 #14
0
    def agent_add(self):
        schema = AgentForm()
        try:
            form_result = schema.to_python(request.params)
            cca = CallCenterAgent()
            cca.extension = form_result.get('extension')
            e = PbxEndpoint.query.filter_by(
                user_context=session['context']).filter(
                    PbxEndpoint.auth_id == cca.extension).first()
            cca.context = session['context']
            cca.domain = session['context']
            cca.type = 'callback'
            cca.system = 'single_box'
            cca.name = cca.extension + "@" + session['context']
            cca.timeout = form_result.get('timeout', 30)
            cca.contact = "[call_timeout=" + cca.timeout + "]user/" + cca.name
            cca.max_no_answer = form_result.get('max_no_answer', 3)
            cca.wrap_up_time = form_result.get('wrap_up_time', 30)
            cca.reject_delay_time = form_result.get('reject_delay_time', 30)
            cca.busy_delay_time = form_result.get('busy_delay_time', 0)
            cca.no_answer_delay_time = form_result.get('no_answer_delay_time',
                                                       5)
            cca.record_calls = form_result.get('record_calls', 0)
            cca.status = 'Available'
            cca.state = 'Waiting'
            cca.user_id = e.user_id
            cca.pbx_endpoint_id = e.id

            db.add(cca)
            db.commit()
            db.flush()

        except validators.Invalid, error:
            db.remove()
            return 'Error: %s.' % error
예제 #15
0
파일: crm.py 프로젝트: Kirembu/FreePyBX
    def update_campaign_grid(self, **kw):

        w = loads(urllib.unquote_plus(request.params.get("data")))

        try:
            for i in w["modified"]:
                sg = (
                    CrmCampaignGroup.query.filter(CrmCampaignGroup.crm_campaign_id == i["id"])
                    .filter(CrmCampaignGroup.context == session["context"])
                    .first()
                )
                CrmGroupMember.query.filter(CrmGroupMember.crm_group_id == sg.crm_group_id).delete()

                for gm in i["members"].split(","):
                    if not gm.strip().isdigit():
                        continue
                    sm = CrmGroupMember()
                    sm.crm_group_id = sg.crm_group_id
                    sm.extension = gm.strip()
                    sm.context = session["context"]

                    db.add(sm)
                    db.commit()
                    db.flush()
        except:
            db.remove()
            return "Error updating campaign."

        return "Successfully updated campaign."
예제 #16
0
파일: crm.py 프로젝트: Kirembu/FreePyBX
    def account_by_id(self, id):
        items = []
        for account in (
            CrmAccount.query.join(CrmCampaign)
            .filter(CrmAccount.customer_id == session["customer_id"])
            .filter(CrmAccount.user_id == session["user_id"])
            .filter(CrmCampaign.name == id)
            .all()
        ):
            items.append(
                {
                    "id": account.id,
                    "name": str(account.first_name) + " " + str(account.last_name),
                    "address": account.address,
                    "city": account.city,
                    "state": account.state,
                    "zip": account.zip,
                    "tel": account.tel,
                    "mobile": account.mobile,
                    "email": account.email,
                    "crm_campaign_id": account.crm_campaign_id,
                }
            )
        db.remove()

        out = dict({"identifier": "id", "label": "name", "items": items})
        response = make_response(out)
        response.headers = [("Content-type", "application/json")]

        return response(request.environ, self.start_response)
예제 #17
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
    db.flush()
    db.remove()
    return True
예제 #18
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.commit()
    db.flush()
    db.remove()
    return True
예제 #19
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
    db.flush()
    db.remove()
예제 #20
0
파일: base.py 프로젝트: Kirembu/FreePyBX
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
예제 #21
0
def get_talk_time(ext, context):
    rows =  db.execute("SELECT coalesce(sum(billsec)/60,0) AS mins FROM cdr "
                       "WHERE (caller_id_number=:ext OR destination_number=:ext) "
                       "AND start_stamp BETWEEN CURRENT_DATE AND CURRENT_TIMESTAMP "
                       "AND bleg_uuid IS NOT NULL AND context = :context",
            {'ext':ext, 'context': context})
    r = rows.fetchone()
    db.remove()
    return r.mins
예제 #22
0
파일: base.py 프로젝트: malakhA/FreePyBX
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
예제 #23
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.commit()
    db.flush()
    db.remove()
예제 #24
0
파일: core.py 프로젝트: Kirembu/FreePyBX
    def register_login(class_, username, session, request):
        user = db.query(AdminUser).filter(AdminUser.username==username).first()
        if user:
            now = datetime.now()
            user.last_login = now
            user.session_id = session.id
            user.remote_addr = request.environ["HTTP_REMOTE_EU"]
            db.commit()
            db.flush()

        db.remove()
예제 #25
0
def get_volume(ext, context):
    rows =  db.execute("SELECT count(*) AS ct "
                       "FROM cdr "
                       "WHERE  (caller_id_number=:ext OR destination_number=:ext) "
                       "AND start_stamp BETWEEN CURRENT_DATE "
                       "AND CURRENT_TIMESTAMP AND bleg_uuid IS NOT NULL "
                       "AND context = :context",
            {'ext':ext, 'context': context})
    r = rows.fetchone()
    db.remove()
    return r.ct
예제 #26
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
        db.flush()
        db.remove()
    return True
예제 #27
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
        db.flush()
        db.remove()
    return True
예제 #28
0
파일: crm.py 프로젝트: Kirembu/FreePyBX
    def account_lead_types(self):
        items = []
        for act in CrmLeadType.query.filter(context=session["context"]).all():
            items.append({"id": act.id, "name": act.name, "desc": act.description})
        db.remove()

        out = dict({"identifier": "id", "label": "name", "items": items})
        response = make_response(out)
        response.headers = [("Content-type", "application/json")]

        return response(request.environ, self.start_response)
예제 #29
0
파일: crm.py 프로젝트: Kirembu/FreePyBX
    def campaigns_ids(self):
        names = []
        ids = []
        for row in CrmCampaign.query.filter(context=session["context"]).all():
            names.append(row.name)
            ids.append(row.id)
        db.remove()
        headers = [("Content-type", "application/json")]
        out = dict({"names": names, "ids": ids})
        response = make_response(out)

        return response(request.environ, self.start_response)
예제 #30
0
    def del_tier(self, **kw):

        try:
            CallCenterTier.query.filter_by(id=request.params.get("id", 0)).delete()
            db.commit()
            db.flush()
            db.remove()

        except:
            return "Error deleting tier agent."

        return "Successfully deleted tier agent."
예제 #31
0
    def billing_service_types(self):
        items=[]
        for bs in BillingServiceType.query.all():
            items.append({'id': bs.id, 'name': bs.name, 'description': bs.description})

        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [("Content-type", 'application/json'),]

        return response(request.environ, self.start_response)
예제 #32
0
def get_talk_time(ext, context):
    rows = db.execute(
        "SELECT coalesce(sum(billsec)/60,0) AS mins FROM cdr "
        "WHERE (caller_id_number=:ext OR destination_number=:ext) "
        "AND start_stamp BETWEEN CURRENT_DATE AND CURRENT_TIMESTAMP "
        "AND bleg_uuid IS NOT NULL AND context = :context", {
            'ext': ext,
            'context': context
        })
    r = rows.fetchone()
    db.remove()
    return r.mins
예제 #33
0
파일: util.py 프로젝트: Kirembu/FreePyBX
def get_route_labels_ids():
    route_labels = []
    route_ids = []

    for row in db.execute("SELECT sr.id, srt.name|| ':' ||sr.name AS name "
                          "FROM pbx_routes sr "
                          "INNER JOIN pbx_route_types srt ON sr.pbx_route_type_id = srt.id "
                          "WHERE sr.context = :context", {'context': session['context']}):
        route_labels.append(row.name)
        route_ids.append(row.id)
    db.remove()
    return (route_labels,route_ids)
예제 #34
0
    def register_login(class_, username, session, request):
        user = db.query(AdminUser).filter(
            AdminUser.username == username).first()
        if user:
            now = datetime.now()
            user.last_login = now
            user.session_id = session.id
            user.remote_addr = request.environ["HTTP_REMOTE_EU"]
            db.commit()
            db.flush()

        db.remove()
예제 #35
0
    def del_tier(self, **kw):

        try:
            CallCenterTier.query.filter_by(
                id=request.params.get('id', 0)).delete()
            db.commit()
            db.flush()
            db.remove()

        except:
            return "Error deleting tier agent."

        return "Successfully deleted tier agent."
예제 #36
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.commit()
        db.flush()
        db.remove()
    return True
예제 #37
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
        db.flush()
        db.remove()
    return True
예제 #38
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.commit()
        db.flush()
        db.remove()
    return True
예제 #39
0
def get_route_labels_ids():
    route_labels = []
    route_ids = []

    for row in db.execute(
            "SELECT sr.id, srt.name|| ':' ||sr.name AS name "
            "FROM pbx_routes sr "
            "INNER JOIN pbx_route_types srt ON sr.pbx_route_type_id = srt.id "
            "WHERE sr.context = :context", {'context': session['context']}):
        route_labels.append(row.name)
        route_ids.append(row.id)
    db.remove()
    return (route_labels, route_ids)
예제 #40
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.commit()
        db.flush()
        db.remove()
    return True
예제 #41
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def campaigns_ids(self):
        names = []
        ids = []
        for row in CrmCampaign.query.filter(context=session['context']).all():
            names.append(row.name)
            ids.append(row.id)
        db.remove()
        headers = [
            ("Content-type", 'application/json'),
        ]
        out = dict({'names': names, 'ids': ids})
        response = make_response(out)

        return response(request.environ, self.start_response)
예제 #42
0
def get_volume(ext, context):
    rows = db.execute(
        "SELECT count(*) AS ct "
        "FROM cdr "
        "WHERE  (caller_id_number=:ext OR destination_number=:ext) "
        "AND start_stamp BETWEEN CURRENT_DATE "
        "AND CURRENT_TIMESTAMP AND bleg_uuid IS NOT NULL "
        "AND context = :context", {
            'ext': ext,
            'context': context
        })
    r = rows.fetchone()
    db.remove()
    return r.ct
예제 #43
0
    def getCallers(self, sid):
        callers = []
        user = User.query.filter_by(session_id=sid).first()
        if user:
            context = user.get_context()

        for row in PbxDid.query.filter(PbxDid.context == context).all():
            for cal in db.execute(
                    "SELECT * FROM channels WHERE dest like :did", {
                        'did': "%" + row.did
                    }).fetchall():
                #PbxChannel.query.filter(PbxChannel.dest.like('%'+row.did).all():
                l = PbxChannel.query.filter_by(uuid=cal.uuid).first()
                if l:
                    to_user = l.dest
                    status = l.callstate
                else:
                    to_user = ""
                    status = ""
                direction = "inbound"
                if len(cal.cid_num) > 10:
                    cid_num = cal.cid_num[len(cal.cid_num) - 10:]
                else:
                    cid_num = cal.cid_num

                time_in_queue = db.execute(
                    "SELECT now() FROM channels WHERE uuid = :uuid", {
                        'uuid': cal.uuid
                    }).fetchone()
                callers.append(
                    make_caller(cal.dest, cal.cid_name, cid_num, direction,
                                cal.created, time_in_queue[0], to_user,
                                cal.uuid, status))

        for cal in PbxChannel.query.filter_by(context=context).distinct(
                PbxChannel.call_uuid).all():
            if len(cal.presence_id) > 3:
                if cal.presence_id.split("@")[1] == context:
                    time_in_queue = db.execute(
                        "SELECT now() FROM channels WHERE uuid = :uuid", {
                            'uuid': cal.uuid
                        }).fetchone()
            callers.append(
                make_caller(cal.dest, cal.cid_name, cal.cid_num, "outbound",
                            cal.created, "", cal.dest, cal.uuid,
                            cal.callstate))

        db.remove()
        return callers
예제 #44
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.commit()
            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.remove()
            return 'Error: %s.' % error
예제 #45
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def add_crm_account_note(self, **kw):

        try:
            cn = CrmNote()
            cn.note = request.params.get('crm_note')
            cn.crm_account_id = request.params.get('crm_acct_id')
            cn.created = datetime.now()

            db.add(cn)
            db.commit()
            db.flush()

        except validators.Invalid, error:
            db.remove()
            return 'Error: %s' % error
예제 #46
0
파일: crm.py 프로젝트: Kirembu/FreePyBX
    def add_crm_account_note(self, **kw):

        try:
            cn = CrmNote()
            cn.note = request.params.get("crm_note")
            cn.crm_account_id = request.params.get("crm_acct_id")
            cn.created = datetime.now()

            db.add(cn)
            db.commit()
            db.flush()

        except validators.Invalid, error:
            db.remove()
            return "Error: %s" % error
예제 #47
0
파일: core.py 프로젝트: Kirembu/FreePyBX
    def register_login(class_, username, session, request):
        user = User.query.filter_by(username=username).first()
        if user:
            now = datetime.now()
            user.last_login = now
            user.session_id = session.id
            user.remote_addr = request.environ["HTTP_REMOTE_EU"]
            db.commit()
            db.flush()

            if True:
                s = Shift(session.id, user.id, 1)
                db.add(s)
                db.commit()
                db.flush()
        db.remove()
예제 #48
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def account_by_id(self, id):
        items = []
        for account in CrmAccount.query.join(CrmCampaign).filter(CrmAccount.customer_id==session['customer_id'])\
                    .filter(CrmAccount.user_id==session['user_id']).filter(CrmCampaign.name==id).all():
            items.append({'id': account.id, 'name': str(account.first_name)+" "+str(account.last_name), 'address': account.address, \
                          'city': account.city, 'state': account.state, 'zip': account.zip, 'tel': account.tel, 'mobile': account.mobile, \
                          'email': account.email, 'crm_campaign_id': account.crm_campaign_id})
        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json'),
        ]

        return response(request.environ, self.start_response)
예제 #49
0
    def register_login(class_, username, session, request):
        user = User.query.filter_by(username=username).first()
        if user:
            now = datetime.now()
            user.last_login = now
            user.session_id = session.id
            user.remote_addr = request.environ["HTTP_REMOTE_EU"]
            db.commit()
            db.flush()

            if True:
                s = Shift(session.id, user.id, 1)
                db.add(s)
                db.commit()
                db.flush()
        db.remove()
예제 #50
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
        db.flush()
        db.remove()
    return True
예제 #51
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
        db.flush()
        db.remove()
    return True
예제 #52
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.commit()
    db.flush()
    db.remove()
    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.commit()
        db.flush()
        db.remove()
    return "Successfully deleted TTS."
예제 #53
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def account_lead_types(self):
        items = []
        for act in CrmLeadType.query.filter(context=session['context']).all():
            items.append({
                'id': act.id,
                'name': act.name,
                'desc': act.description
            })
        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json'),
        ]

        return response(request.environ, self.start_response)
예제 #54
0
    def delete_queue(self, **kw):

        id = request.params.get('id', None)
        q = CallCenterQueue.query.filter(CallCenterQueue.id == id).filter(
            CallCenterQueue.context == session['context']).first()

        queue = CallCenterQueue.query.filter(
            CallCenterQueue.id == q.id).first()
        CallCenterTier.query.filter(
            CallCenterTier.queue_id == queue.id).delete()
        CallCenterQueue.query.filter(CallCenterQueue.id == q.id).delete()

        db.commit()
        db.flush()
        db.remove()

        return "Successfully removed queue."
예제 #55
0
파일: util.py 프로젝트: Kirembu/FreePyBX
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.commit()
    db.flush()
    db.remove()
    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.commit()
        db.flush()
        db.remove()
    return "Successfully deleted TTS."
예제 #56
0
    def update_agent_grid(self):

        try:
            w = loads(urllib.unquote_plus(request.params.get("data")))

            for i in w['modified']:
                log.debug(w['modified'])
                fsa = CallCenterAgent.query.filter(
                    CallCenterAgent.name == str(i['extension']) + "@" +
                    str(session['context'])).first()
                fsa.status = i['status']

                db.commit()
                db.flush()
                db.remove()

        except DataInputError, error:
            return 'Error: %s' % error
예제 #57
0
    def billing_service_types(self):
        items = []
        for bs in BillingServiceType.query.all():
            items.append({
                'id': bs.id,
                'name': bs.name,
                'description': bs.description
            })

        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json'),
        ]

        return response(request.environ, self.start_response)
예제 #58
0
    def getAgents(self, sid):
        agents = []
        user = User.query.filter_by(session_id=sid).first()
        if user:
            context = user.get_context()
        else:
            raise Exception("No user in session...")

        for row in User.query.filter(User.customer_id==user.customer_id).all():
            if not len(row.portal_extension):
                continue
            else:
                extension = row.portal_extension

            agent = make_agent(row.first_name+' '+row.last_name,  get_volume(extension, context), get_talk_time(extension, context))
            agents.append(agent)
        db.remove()
        return agents
예제 #59
0
    def update_agent_grid(self):

        try:
            w = loads(urllib.unquote_plus(request.params.get("data")))

            for i in w["modified"]:
                log.debug(w["modified"])
                fsa = CallCenterAgent.query.filter(
                    CallCenterAgent.name == str(i["extension"]) + "@" + str(session["context"])
                ).first()
                fsa.status = i["status"]

                db.commit()
                db.flush()
                db.remove()

        except DataInputError, error:
            return "Error: %s" % error
예제 #60
0
파일: crm.py 프로젝트: malakhA/FreePyBX
    def account_by_id(self, id, **kw):
        items = []
        for crm in CrmAccount.query.filter(
                CrmAccount.customer_id == session['customer_id']).filter(
                    CrmAccount.id == id).all():
            items.append({'id': crm.id, 'first_name': crm.first_name, 'last_name': crm.last_name, 'address': crm.address, 'address_2': crm.address_2,\
                          'city': crm.city, 'state': crm.state, 'zip': crm.zip, 'title': crm.title, 'tel': crm.tel, 'mobile': crm.mobile,\
                          'tel_ext': crm.tel_ext, 'customer': crm.customer, 'email': crm.email, 'url': crm.url, 'crm_account_status_type_id': crm.crm_account_status_type_id,\
                          'crm_lead_type_id': crm.crm_lead_type_id, 'crm_campaign_id': crm.crm_campaign_id, 'created': crm.created.strftime("%m/%d/%Y %I:%M:%S %p"),\
                          'last_modified': crm.last_modified.strftime("%m/%d/%Y %I:%M:%S %p"), 'active': crm.active})
        db.remove()

        out = dict({'identifier': 'id', 'label': 'name', 'items': items})
        response = make_response(out)
        response.headers = [
            ("Content-type", 'application/json'),
        ]

        return response(request.environ, self.start_response)