def GetFileHandler(self, sock, packet): print("[SlaveNode] GetFileHandler") objFile = MkSFile.File() uiType = packet["payload"]["data"]["ui_type"] fileType = packet["payload"]["data"]["file_type"] fileName = packet["payload"]["data"]["file_name"] folder = {'config': 'config', 'app': 'app', 'thumbnail': 'thumbnail'} path = os.path.join(".", "ui", folder[uiType], "ui." + fileType) print(path) content = objFile.LoadStateFromFile(path) if ("html" in fileType): content = content.replace("[NODE_UUID]", self.UUID) content = content.replace("[GATEWAY_IP]", self.GatewayIP) payload = { 'file_type': fileType, 'ui_type': uiType, 'content': content.encode('hex') } msg = self.Commands.ProxyResponse(packet, payload) self.MasterSocket.send(msg)
def __init__(self): self.File = MkSFile.File() self.Type = None self.UUID = "" # Flags self.IsConnected = False # Events self.OnDataReadyCallback = None jsonSystemStr = self.File.LoadStateFromFile("system.json") try: dataSystem = json.loads(jsonSystemStr) self.UUID = dataSystem["node"]["uuid"] self.DeviceInfoJson = dataSystem["device"] except: print ("Error: [LoadSystemConfig] Wrong system.json format") self.Exit()
def __init__(self): MkSAbstractNode.AbstractNode.__init__(self) # Members self.File = MkSFile.File() self.Commands = MkSLocalNodesCommands.LocalNodeCommands() self.Terminal = MkSShellExecutor.ShellExecutor() self.MachineInfo = MachineInformation() self.PortsForClients = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ] self.MasterHostName = socket.gethostname() self.MasterVersion = "1.0.1" self.PackagesList = ["Gateway", "LinuxTerminal", "USBManager"] # Default Master capabilities. self.LocalSlaveList = [] # Used ONLY by Master. self.InstalledNodes = [] self.Pipes = [] self.InstalledApps = None # Sates self.States = {'IDLE': self.StateIdle, 'WORKING': self.StateWorking} # Handlers self.RequestHandlers = { 'get_port': self.GetPortRequestHandler, 'get_local_nodes': self.GetLocalNodesRequestHandler, 'get_master_info': self.GetMasterInfoRequestHandler, 'get_file': self.GetFileHandler, 'upload_file': self.UploadFileHandler } self.ResponseHandlers = {} # Callbacks self.OnCustomCommandRequestCallback = None self.OnCustomCommandResponseCallback = None # Flags self.IsListenerEnabled = False self.PipeStdoutRun = False self.ChangeState("IDLE") self.LoadNodesOnMasterStart() thread.start_new_thread(self.PipeStdoutListener_Thread, ())
def GetNodeConfigHandler(self, key): print("[SlaveNode]# GetNodeConfigHandler", self.Pwd + "static/js/node/widget_config.js") objFile = MkSFile.File() js = objFile.LoadStateFromFile("static/js/node/widget_config.js") return js
def GetFileHandler(self, packet): print("[MasterNode] GetFileHandler") ''' { 'header': { 'source': 'WEBFACE', 'destination': 'ac6de837-9863-72a9-c789-a0aae7e9d020', 'message_type': 'DIRECT' }, 'piggybag': { 'identifier': 9 }, 'data': { 'header': { 'timestamp': 1554159118729, 'command': 'get_file' }, 'payload': { 'file_type': 'js', 'file_name': '', 'ui_type': 'config' } }, 'user': { 'key': 'ac6de837-7863-72a9-c789-a0aae7e9d93e' }, 'additional': { } } ''' objFile = MkSFile.File() uiType = packet["data"]["payload"]["ui_type"] fileType = packet["data"]["payload"]["file_type"] fileName = packet["data"]["payload"]["file_name"] folder = {'config': 'config', 'app': 'app', 'thumbnail': 'thumbnail'} path = os.path.join(".", "ui", folder[uiType], "ui." + fileType) print(path) content = objFile.LoadStateFromFile(path) if ("html" in fileType): content = content.replace("[NODE_UUID]", self.UUID) content = content.replace("[GATEWAY_IP]", self.GatewayIP) resPayload = { 'file_type': fileType, 'ui_type': uiType, 'content': content.encode('hex') } command = packet['data']['header']['command'] source = packet["header"]["source"] destination = packet["header"]["destination"] payload = resPayload piggy = packet["piggybag"] if self.OnSlaveResponseCallback is not None: self.OnSlaveResponseCallback("response", source, destination, command, payload, piggy)
def __init__(self, node_type, local_service_node): # Objects node depend on self.File = MkSFile.File() self.Connector = None self.Network = None self.LocalServiceNode = local_service_node # Node connection to WS information self.GatewayIP = "" self.ApiUrl = "" self.WsUrl = "" self.UserName = "" self.Password = "" self.NodeType = node_type # Device information self.Type = 0 self.UUID = "" self.OSType = "" self.OSVersion = "" self.BrandName = "" self.Name = "" self.Description = "" self.DeviceInfo = None self.BoardType = "" # Misc self.State = 'IDLE' self.IsRunnig = True self.AccessTick = 0 self.RegisteredNodes = [] self.SystemLoaded = False self.IsNodeMainEnabled = False self.IsHardwareBased = False self.IsNodeWSServiceEnabled = False # Based on HTTP requests and web sockets self.IsNodeLocalServerEnabled = False # Based on regular sockets # Inner state self.States = { 'IDLE': self.StateIdle, 'CONNECT_DEVICE': self.StateConnectDevice, 'INIT_NETWORK': self.StateInitNetwork, 'ACCESS': self.StateGetAccess, 'ACCESS_WAIT': self.StateAccessWait, 'LOCAL_SERVICE': self.StateLocalService, 'WORK': self.StateWork } # Callbacks self.WorkingCallback = None self.OnWSDataArrived = None self.OnWSConnected = None self.OnWSConnectionClosed = None self.OnNodeSystemLoaded = None self.OnDeviceConnected = None # Locks and Events self.NetworkAccessTickLock = threading.Lock() self.ExitEvent = threading.Event() self.ExitLocalServerEvent = threading.Event() # Debug self.DebugMode = False # Handlers self.Handlers = { 'get_node_info': self.GetNodeInfoHandler, 'get_node_status': self.GetNodeStatusHandler, 'register_subscriber': self.RegisterSubscriberHandler, 'unregister_subscriber': self.UnregisterSubscriberHandler, 'get_file': self.GetFileHandler } self.LocalServiceNode.OnExitCallback = self.OnExitHandler self.LocalServiceNode.OnNewNodeCallback = self.OnNewNodeHandler self.LocalServiceNode.OnSlaveNodeDisconnectedCallback = self.OnSlaveNodeDisconnectedHandler self.LocalServiceNode.OnSlaveResponseCallback = self.OnSlaveResponseHandler self.LocalServiceNode.OnGetNodeInfoRequestCallback = self.OnGetNodeInfoRequestHandler parser = argparse.ArgumentParser( description='Execution module called Node') parser.add_argument('--path', action='store', dest='pwd', help='Root folder of a Node') args = parser.parse_args() if args.pwd is not None: os.chdir(args.pwd)
def GetFile(self, filename, ui_type): objFile = MkSFile.File() return objFile.LoadStateFromFile("static/js/node/" + fileName)