Пример #1
0
def InitializeRemove():

    ui = rs.shapingrule_list()

    if ui:
        for iui in ui:
            rs.shapingrule_remove(iui)

    ui = rs.fwrule_list()

    if ui:
        for iui in ui:
            rs.fwrule_remove(iui)

    if rs.object_find("/PortObjects/Ubiquiti_CRM"):
        ui = rs.object_list("/PortObjects/Ubiquiti_CRM")

        if ui:
            for iui in ui:
                if iui.items:
                    for item in iui.items:
                        iui.remove(item)
                    rs.object_remove(iui)
            rs.object_remove("/PortObjects/Ubiquiti_CRM")

    if rs.object_find("/ProtocolObjects/Ubiquiti_CRM"):
        ui = rs.object_list("/ProtocolObjects/Ubiquiti_CRM")

        if ui:
            for iui in ui:
                if iui.items:
                    for item in iui.items:
                        iui.remove(item)
                    rs.object_remove(iui)
            rs.object_remove("/ProtocolObjects/Ubiquiti_CRM")

    if rs.object_find("/NetObjects/Ubiquiti_CRM"):
        ui = rs.object_list("/NetObjects/Ubiquiti_CRM")

        if ui:
            for iui in ui:
                if iui.items:
                    for item in iui.items:
                        iui.remove(item)
                    rs.object_remove(iui)
            rs.object_remove("/NetObjects/Ubiquiti_CRM")

    ui = rs.shapingobject_list()

    if ui:
        for iui in ui:
            rs.shapingobject_remove(iui)

    return
Пример #2
0
def makeClients(client,plan,status,clientIP):
        
    # UCRM Client Variable
    pcl = str("UCRM_Client_%s" % client)
    
    # UCRM Service Plan
    psn = str("UCRM_%s" % plan)
    
    # UCRM Client Status
    pst = str(status)
    
    # UCRM Client IP
    if len(clientIP) < 2:
        for pcip in clientIP:
            cdip = pcip + "/32"
    elif len(clientIP) > 2:
        for pcip in clientIP:
            cdip = pcip + "/32"
    else:
        for pcip in clientIP:
            cdip = pcip
    
    # Create Authorized NetObject on active status
    if pst == "1":
        if rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl):
            rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl)
        elif not rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl):
            o = rs.object_add("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl)
            o.add(pcip)

    # Create Unauthorized NetObject on suspended status
    if pst == "2":
        if rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl):
            rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl)
        elif not rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl):
            o = rs.object_add("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl)
            o.add(pcip)
    
    # Remove NetObject on terminated status
    if pst == "3":
        if rs.object_find("/NetObjects/Ubiquiti_CRM/Services/%s" % pcl):
            if rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl):
                rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl)
                rs.object_remove("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (psn, pcl))
            elif rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl):
                rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl)
                rs.object_remove("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (psn, pcl))
        elif rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl):
            rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Authorized/%s" % pcl)
        elif rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl):
            rs.object_remove("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized/%s" % pcl)

    # Exit the function
    return
Пример #3
0
def makeOpenAccess(ips):
    for ip in ips:
        fip = ip.split("/")[0]
        fobj = rs.object_find(
            "/NetObjects/Ubiquiti_CRM/UCRM_Open_Access").items
        fobjf = []
        for fo in fobj:
            stfo = str(fo)
            sfo = "".join(stfo)
            rfo = sfo.split("/")[0]
            fobjf.append(rfo)
        if not fip in fobjf:
            o = rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Open_Access")
            o.add(fip)

    # Exit the function after the FOR loop
    return
Пример #4
0
def makeClientPlan(client,plan,devIP):
    
    # UCRM Client Variable
    pcl = str("UCRM_Client_%s" % client)
    
    # UCRM Service Plan
    psn = str("UCRM_%s" % plan)

    # Set pdip as the client's device IP
    if len(devIP) < 2:
        for pdip in devIP:
            cdip = pdip + "/32"
    elif len(devIP) > 2:
        for pdip in devIP:
            cdip = pdip + "/32"
    else:
        for pdip in devIP:
            cdip = pdip

    # Gather service plan data
    surl = ucrmInfo.ucrmURL + "/service-plans"
    splan = ucrmInfo.ucrmConnect(surl,ucrmInfo.appKey)

    # Check to see if the customer's plan matches the one they were on and remove the old one
    for sp in splan:
        oldplan = str("UCRM_" + sp["name"])

        if rs.object_find("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (oldplan,pcl)):
            if oldplan != psn:
                rs.object_remove("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (oldplan,pcl))

    # Check to see if the customer is existing under their plan and add them if not
    if not rs.object_find("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (psn, pcl)):
        o = rs.object_add("/NetObjects/Ubiquiti_CRM/Services/%s/%s" % (psn, pcl))
        o.add(pdip)

    # Exit the function
    return
Пример #5
0
def InitializeAdd():

    if not rs.object_find("/PortObjects/Ubiquiti_CRM"):
        rs.object_add("/PortObjects/Ubiquiti_CRM")

    if not rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_DHCP"):
        o = rs.object_add("/PortObjects/Ubiquiti_CRM/UCRM_DHCP")
        o.add("67-68")

    if not rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_DNS"):
        o = rs.object_add("/PortObjects/Ubiquiti_CRM/UCRM_DNS")
        o.add("53")

    if not rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_HTTP"):
        o = rs.object_add("/PortObjects/Ubiquiti_CRM/UCRM_HTTP")
        o.add("81")

    if not rs.object_find("/ProtocolObjects/Ubiquiti_CRM"):
        rs.object_add("/ProtocolObjects/Ubiquiti_CRM")

    if not rs.object_find("/ProtocolObjects/Ubiquiti_CRM/UCRM_UDP"):
        o = rs.object_add("/ProtocolObjects/Ubiquiti_CRM/UCRM_UDP")
        o.add("UDP")

    if not rs.object_find("/ProtocolObjects/Ubiquiti_CRM/UCRM_ICMP"):
        o = rs.object_add("/ProtocolObjects/Ubiquiti_CRM/UCRM_ICMP")
        o.add("ICMP")

    if not rs.object_find("/NetObjects/Ubiquiti_CRM"):
        o = rs.object_add("/NetObjects/Ubiquiti_CRM")
        o.set_visible(True)

    if not rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Authorized"):
        rs.object_add("/NetObjects/Ubiquiti_CRM/UCRM_Authorized")

    if not rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized"):
        rs.object_add("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized")

    if not rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Open_Access"):
        rs.object_add("/NetObjects/Ubiquiti_CRM/UCRM_Open_Access")

    if not rs.object_find("/NetObjects/Ubiquiti_CRM/Services"):
        rs.object_add("/NetObjects/Ubiquiti_CRM/Services")

    if not rs.fwrule_find("UCRM Authorized Users"):
        hn = rs.object_get("/NetObjects/Ubiquiti_CRM/UCRM_Authorized").id
        o = rs.fwrule_add("UCRM Authorized Users",
                          rs.FWRULE_ACTION_ACCEPT,
                          quick=True)
        o.cond_add(rs.CONDITION_NETOBJECT_HOST, rs.CONDITION_OP_EQ, [hn])

    if not rs.fwrule_find("UCRM Open Access"):
        hn = rs.object_get("/NetObjects/Ubiquiti_CRM/UCRM_Open_Access").id
        o = rs.fwrule_add("UCRM Open Access",
                          rs.FWRULE_ACTION_ACCEPT,
                          quick=True)
        o.cond_add(rs.CONDITION_NETOBJECT_HOST, rs.CONDITION_OP_EQ, [hn])

    if not rs.fwrule_find("UCRM Delinquent Redirect"):
        hn1 = rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized").id
        hn2 = rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Open_Access").id
        hn3 = rs.object_find(
            "/ServiceObjects/Procera Networks Categorization/Categories/Web Browsing"
        ).id
        o = rs.fwrule_add(
            "UCRM Delinquent Redirect",
            rs.FWRULE_ACTION_INJECT,
            quick=True,
            inject_data=
            'HTTP/1.1 307 Temporary Redirect\nLocation: http://ucrm.atlinkservices.com:81\nConnection: close'
        )
        o.cond_add(rs.CONDITION_NETOBJECT_CLIENT, rs.CONDITION_OP_EQ, [hn1])
        o.cond_add(rs.CONDITION_NETOBJECT_SERVER, rs.CONDITION_OP_NE, [hn2])
        o.cond_add(rs.CONDITION_SERVICEOBJECT, rs.CONDITION_OP_EQ, [hn3])

    if not rs.fwrule_find("UCRM Delinquent Drop"):
        hn1 = rs.object_find("/NetObjects/Ubiquiti_CRM/UCRM_Unauthorized").id
        hn = rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_HTTP").id
        o = rs.fwrule_add("UCRM Delinquent Drop",
                          rs.FWRULE_ACTION_DROP,
                          quick=True)
        o.cond_add(rs.CONDITION_NETOBJECT_HOST, rs.CONDITION_OP_EQ, [hn1])
        o.cond_add(rs.CONDITION_PORTOBJECT_SERVER, rs.CONDITION_OP_NE, [hn])

    if not rs.fwrule_find("UCRM DNS Accept"):
        hn = rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_DNS").id
        hn1 = rs.object_find("/ProtocolObjects/Ubiquiti_CRM/UCRM_UDP").id
        o = rs.fwrule_add("UCRM DNS Accept",
                          rs.FWRULE_ACTION_ACCEPT,
                          quick=True)
        o.cond_add(rs.CONDITION_PORTOBJECT_SERVER, rs.CONDITION_OP_EQ, [hn])
        o.cond_add(rs.CONDITION_PROTOCOLOBJECT, rs.CONDITION_OP_EQ, [hn1])

    if not rs.fwrule_find("UCRM DHCP Accept"):
        hn1 = rs.object_find("/ProtocolObjects/Ubiquiti_CRM/UCRM_UDP").id
        hn = rs.object_find("/PortObjects/Ubiquiti_CRM/UCRM_DHCP").id
        o = rs.fwrule_add("UCRM DHCP Accept",
                          rs.FWRULE_ACTION_ACCEPT,
                          quick=True)
        o.cond_add(rs.CONDITION_PROTOCOLOBJECT, rs.CONDITION_OP_EQ, [hn1])
        o.cond_add(rs.CONDITION_PORTOBJECT_SERVER, rs.CONDITION_OP_EQ, [hn])

    if not rs.fwrule_find("UCRM ICMP Accept"):
        hn = rs.object_find("/ProtocolObjects/Ubiquiti_CRM/UCRM_ICMP").id
        o = rs.fwrule_add("UCRM ICMP Accept",
                          rs.FWRULE_ACTION_ACCEPT,
                          quick=True)
        o.cond_add(rs.CONDITION_PROTOCOLOBJECT, rs.CONDITION_OP_EQ, [hn])

    return