def send_notification_thread():
    	wsid = 1
    	while True:
    	    time.sleep(3)
    	    
    	    #logger.debug("send_notification_thread routine ......")
    	    
            api_json_rsp = api_call("net","get_network_associate_list","")
            api_obj_rsp = json.loads(api_json_rsp)
            
            results = api_obj_rsp["result"]
            
            for result in results:
            	#logger.debug("result: mac = %s",result["macaddr"])
            	found = 0
            	for i, x in enumerate(g_user_list):
            		if x["macaddr"] == result["macaddr"]:
            			found = 1
            			break
            	if found == 0:
            		g_user_list.append(result)		
            		logger.debug("Should notification mac  %s logger on",result["macaddr"])
            		encode_device_state_notification(idcode,"1",result)
 			
            for j,y in enumerate(g_user_list):
            	found = 0 
            	for result in results:
            		if y["macaddr"] == result["macaddr"]:
            			found = 1
            			break
            	if found == 0:
            		logger.debug("Should notification mac  %s logger off",y["macaddr"])
            		g_user_list.remove(y)
            		encode_device_state_notification(idcode,"0",y)
示例#2
0
    def send_notification_thread():
        wsid = 1
        while True:
            time.sleep(3)

            #logger.debug("send_notification_thread routine ......")

            api_json_rsp = api_call("net", "get_network_associate_list", "")
            api_obj_rsp = json.loads(api_json_rsp)

            results = api_obj_rsp["result"]

            for result in results:
                #logger.debug("result: mac = %s",result["macaddr"])
                found = 0
                for i, x in enumerate(g_user_list):
                    if x["macaddr"] == result["macaddr"]:
                        found = 1
                        break
                if found == 0:
                    g_user_list.append(result)
                    logger.debug("Should notification mac  %s logger on",
                                 result["macaddr"])
                    encode_device_state_notification(idcode, "1", result)

            for j, y in enumerate(g_user_list):
                found = 0
                for result in results:
                    if y["macaddr"] == result["macaddr"]:
                        found = 1
                        break
                if found == 0:
                    logger.debug("Should notification mac  %s logger off",
                                 y["macaddr"])
                    g_user_list.remove(y)
                    encode_device_state_notification(idcode, "0", y)
	    elif data['method']=='getVersion':                                     
                get_version(ws_obj_req['wsid'],ws_obj_req['from'])                 
                continue                                                           
            elif data['method']=='manualUpgrade':                                  
                encode_router_response(ws_obj_req['wsid'],ws_obj_req['from'],{},0) 
                cnt=0                                                              
                for line in os.popen("ps | grep dmhandle"):                             
                        cnt=cnt+1                                                  
                logger.debug("dmhandle process cnt is = %d",cnt)                   
                if cnt<3:                                                         
        		os.system("cd /usr/lib/lua/dm && /usr/bin/lua /usr/lib/lua/dm/dm_ping.lua")
    	    		time.sleep(10)
                        os.system("/usr/sbin/dmhandle &")                                       
                continue
    	    	
            api_json_rsp = api_call(data['apiclass'],data['method'],data['params'])
            api_obj_rsp = json.loads(api_json_rsp)
            ws_obj_rsp = {"type":"router"}
            ws_obj_rsp["data"] = api_obj_rsp['result']
            ws_obj_rsp["error"] = 0
            ws_obj_rsp["wsid"] = ws_obj_req['wsid']
            ws_obj_rsp["from"] = ws_obj_req['from']
            ws_json_rsp = json.dumps(ws_obj_rsp)
            logger.debug("ws send: %s" % ws_json_rsp)
            ws.send(ws_json_rsp)

        else:
            logger.debug("unrecognize message")
            
    ws.close()
示例#4
0
            elif data['method'] == 'manualUpgrade':
                encode_router_response(ws_obj_req['wsid'], ws_obj_req['from'],
                                       {}, 0)
                cnt = 0
                for line in os.popen("ps | grep dmhandle"):
                    cnt = cnt + 1
                logger.debug("dmhandle process cnt is = %d", cnt)
                if cnt < 3:
                    os.system(
                        "cd /usr/lib/lua/dm && /usr/bin/lua /usr/lib/lua/dm/dm_ping.lua"
                    )
                    time.sleep(10)
                    os.system("/usr/sbin/dmhandle &")
                continue

            api_json_rsp = api_call(data['apiclass'], data['method'],
                                    data['params'])
            api_obj_rsp = json.loads(api_json_rsp)
            ws_obj_rsp = {"type": "router"}
            ws_obj_rsp["data"] = api_obj_rsp['result']
            ws_obj_rsp["error"] = 0
            ws_obj_rsp["wsid"] = ws_obj_req['wsid']
            ws_obj_rsp["from"] = ws_obj_req['from']
            ws_json_rsp = json.dumps(ws_obj_rsp)
            logger.debug("ws send: %s" % ws_json_rsp)
            ws.send(ws_json_rsp)

        else:
            logger.debug("unrecognize message")

    ws.close()
#!/usr/bin/env python

from __future__ import print_function
from apitools import api_call
import sys

if __name__ == "__main__":
    index = 0
    method = ""
    params = []
    pi = 0
    for arg in sys.argv:
        if index == 1:
            apiclass = arg
        if index == 2:
            method = arg
        if index > 2:
            params[pi] = arg
            pi += 1
        index += 1 
    ret = api_call(apiclass,method,params)
    print("%s" % ret)