예제 #1
0
파일: revoke.py 프로젝트: DemoHn/ss-droplet
def revoke(service_idf):
    rtn  = returnModel()
    inDB = serviceInfo()
    rDB  = redisDevice(service_idf)
    # first get item
    item_result = inDB.getItem(service_idf)

    if item_result == None:
        return rtn.error(500)
    elif item_result["status"] == "error":
        return rtn.error(item_result["code"])
    else:
        info = item_result["info"]
        # delete server instance in the database and halt the process
        service_type = info["service_type"]

        if service_type == "shadowsocks":
            res = halt_shadowsocks_service(service_idf)
        elif service_type == "shadowsocks-obfs":
            res = halt_shadowsocks_obfs_service(service_idf)
        else:
            return rtn.error(405)

        if res["status"] == "success":
            result = inDB.deleteItem(service_idf)
            rDB.deleteSet()
            if result["status"] == "success":
                return rtn.success(200)
            else:
                return result
        else:
            return res
    pass
예제 #2
0
def connect(service_idf,mac_addr):
    rtn  = returnModel()
    rd   = redisDevice(service_idf)
    siDB = serviceInfo()
    # first, find if service_idf can be found
    result = siDB.getItem(service_idf)
    if result == None:
        return rtn.error(500)
    elif result["status"] == "error":
        return rtn.error(430)
    else:
        info = result['info']
        # check if devices num is not full
        if (rd.countDevice()+int(rd.deviceInList(mac_addr))) > int(info["max_devices"]):
            return rtn.error(431)
        else:
            conf_return_model = {
                "service_type":"",
                "expire_time":"",
                "info":{}
            }
            # register device into device_db
            rd.newDevice(mac_addr)
            conf_return_model["expire_time"] = info["expire_time"]
            # get configuration
            if info["service_type"] == "shadowsocks":
                conf_return_model["service_type"] = "shadowsocks"
                res = get_shadowsocks_conf(service_idf)
            elif info["service_type"] == "shadowsocks-obfs":
                conf_return_model["service_type"] = "shadowsocks-obfs"
                res = get_shadowsocks_obfs_conf(service_idf)
            else:
                return rtn.error(405)

            if res["status"] == "error":
                return rtn.error(res["code"])
            else:
                conf_return_model['info'] = res['info']

            # get conf string then return
            return rtn.success(conf_return_model)
        pass