Ejemplo n.º 1
0
def halt_shadowsocks_obfs_service(service_idf):
    rtn = returnModel()
    from model.db_ss_obfs_server import ssOBFSServerDatabase
    from model.db_traffic import serviceTraffic
    from proc.proc_ss import ssOBFS_Process
    ssDB = ssOBFSServerDatabase()
    ssProc = ssOBFS_Process()
    trafficDB = serviceTraffic()

    item = ssDB.getItem(service_idf)

    if item == None:
        return rtn.error(500)
    elif item["status"] == "error":
        return rtn.error(item["code"])
    else:
        port = int(item["info"]["server_port"])
        result = ssProc.deleteServer(port)
        if result == False:
            return rtn.error(450)
        else:
            # kill record in database
            ssDB.deleteInstance(service_idf)
            trafficDB.deleteItem(service_idf)
            return rtn.success(200)
Ejemplo n.º 2
0
def get_shadowsocks_obfs_conf(service_idf):
    rtn = returnModel()
    from model.db_ss_obfs_server import ssOBFSServerDatabase
    from proc.proc_ss import ssOBFS_Process
    ssOBFSProc = ssOBFS_Process()
    ssDB = ssOBFSServerDatabase()
    item = ssDB.getItem(service_idf)

    if item == None:
        return rtn.error(500)
    elif item["status"] == "error":
        return rtn.error(item['code'])
    else:
        port   = item["info"]["server_port"]
        passwd = item["info"]["password"]
        conf   = ssOBFSProc.generateLocalConfig(port,passwd)
        return rtn.success(conf)
Ejemplo n.º 3
0
def start_shadowsocks_obfs(traffic_strategy):
    return_data = {
        "service_idf":"",
        "config":""
    }
    rtn = returnModel()
    from model.db_ss_obfs_server import ssOBFSServerDatabase
    from model.db_traffic import serviceTraffic
    from proc.proc_ss import ssOBFS_Process
    ssDB = ssOBFSServerDatabase()
    ssProc = ssOBFS_Process()
    ssT    = serviceTraffic()
    port = 0
    # lock: to prevent infinite loop (for any reason)
    lock = 20
    while lock > 0:
        lock -= 1
        rand_port = randint(config["SHADOWSOCKS_MIN_PORT"],config["SHADOWSOCKS_MAX_PORT"])
        if ssDB.portCollision(int(rand_port)) == False:
            port = rand_port
            break

    if port == 0:
        return rtn.error(422)
    else:
        # first generate params
        service_idf  = gen_service_idf()
        passwd = gen_password(16)
        res    = ssDB.insertServerInstance(service_idf,port,passwd)

        if res == None:
            return rtn.error(423)
        elif res["status"] == "error":
            return rtn.error(423)
        elif res["status"] == "success":
            result = ssProc.createServer(port,passwd)
            ssT.createNewTraffic(service_idf,traffic_strategy)
            if result == True:
                return_data["service_idf"] = service_idf
                return_data["config"]      = ssProc.generateLocalConfig(port,passwd)
                return rtn.success(return_data)
            else:
                return rtn.error(1200)
    pass
Ejemplo n.º 4
0
def update_traffic():
    servDB    = serviceInfo()
    trafficDB = serviceTraffic()
    HB        = redisHeartBeatPacket()
    item_result = servDB.getItems()
    if item_result == None:
        return None
    elif item_result["status"] == "error":
        return None
    else:
        # get all items
        items = item_result["info"]

        for item in items:
            serv_type = item["service_type"]
            serv_idf  = item["service_idf"]
            # TODO 暂时只对使用shadowsocks-obfs的服务进行流量更新
            if serv_type == "shadowsocks-obfs":
                from model.db_ss_obfs_server import ssOBFSServerDatabase
                from proc.proc_ss import ssOBFS_Process
                ssProc = ssOBFS_Process()
                ssDB   = ssOBFSServerDatabase()

                # get service listen port
                port_result = ssDB.getItem(serv_idf)
                if port_result != None:
                    if port_result["status"] == "success":
                        port = int(port_result["info"]["server_port"])
                        # get traffic
                        t_info = ssProc.getTraffic(port)

                        # change to MBs X.YYY MB
                        u_t    = round(float(t_info["upload"]) / (1000 * 1000),3)
                        d_t    = round(float(t_info["download"]) / (1000 * 1000),3)
                        trafficDB.updateTraffic(serv_idf,u_t,d_t)
                        HB.updateTraffic(serv_idf,u_t,d_t)