public void Process(DtoHubAction action) { Logger.Debug("Received Hub Action"); Logger.Debug(action.Action); switch (action.Action) { case "Collect_Inventory": var t = new Thread(RunInventory); t.Start(); break; case "Message": var message = JsonConvert.DeserializeObject <DtoMessage>(action.Message); var activeTrayPorts = new ServiceSetting().GetSetting("active_login_ports").Value; foreach (var port in activeTrayPorts.Split(',')) { var localPort = port; var m = new Thread(() => RunMessage(message.Message, message.Title, localPort, message.Timeout)); m.Start(); } break; case "Force_Checkin": var f = new Thread(RunCheckin); f.Start(); break; case "Reboot": Logger.Info("Server Issued Reboot Request. Rebooting."); var r = new Thread(() => RunReboot(action.Message)); r.Start(); break; case "Shutdown": Logger.Info("Server Issued Shutdown Request. Shutting Down."); var s = new Thread(() => RunShutdown(action.Message)); s.Start(); break; case "Start_Mesh": var sm = new Thread(() => RunStartMesh()); sm.Start(); break; case "Wol_Task": var wolTask = JsonConvert.DeserializeObject <DtoWolTask>(action.Message); var w = new Thread(() => RunWakeup(wolTask)); w.Start(); break; default: Logger.Info("Action Was Not Recognized."); break; } }
public DtoBoolResponse Message(DtoMessage message) { var activeTrayPorts = new ServiceSetting().GetSetting("active_login_ports").Value; foreach (var port in activeTrayPorts.Split(',')) { var localPort = port; var t = new Thread(() => RunMessage(message.Message, message.Title, localPort, message.Timeout)); t.Start(); } return(new DtoBoolResponse { Value = true }); }
public DtoModuleResult Run() { Logger.Info("Running Message Module: " + _module.DisplayName); var activeTrayPorts = new ServiceSetting().GetSetting("active_login_ports").Value; foreach (var port in activeTrayPorts.Split(',')) { var localPort = port; var t = new Thread(() => RunMessage(_module.Message, _module.Title, localPort, _module.Timeout)); t.Start(); } Logger.Info($"Message Module {_module.DisplayName} Completed"); return(_moduleResult); }
//https://www.codeproject.com/Tips/268108/Find-the-open-port-on-a-machine-using-Csharp private string GetOpenPort() { int portStartIndex; int portEndIndex; try { var portRange = new ServiceSetting().GetSetting("login_port_range").Value; var splitPortRange = portRange.Split('-'); portStartIndex = Convert.ToInt32(splitPortRange[0]); portEndIndex = Convert.ToInt32(splitPortRange[1]); } catch (Exception ex) { Logger.Error("Could Not Parse Tray App Port Range"); Logger.Error(ex.Message); return(null); } try { var properties = IPGlobalProperties.GetIPGlobalProperties(); var tcpEndPoints = properties.GetActiveTcpListeners(); var usedPorts = tcpEndPoints.Select(p => p.Port).ToList(); var unusedPort = 0; for (var port = portStartIndex; port < portEndIndex; port++) { if (usedPorts.Contains(port)) { continue; } unusedPort = port; break; } return(unusedPort.ToString()); } catch (Exception ex) { Logger.Error("Could Not Find Unused Port In Range"); Logger.Error(ex.Message); return(null); } }
public void Process(DtoHubAction action) { Logger.Debug("Received Hub Action"); Logger.Debug(action.Action); switch (action.Action) { case "Collect_Inventory": var t = new Thread(RunInventory); t.Start(); break; case "Current_Users": var cu = new Thread(GetLoggedInUsers); cu.Start(); break; case "Get_Status": var gs = new Thread(GetStatus); gs.Start(); break; case "Message": var message = JsonConvert.DeserializeObject <DtoMessage>(action.Message); var activeTrayPorts = new ServiceSetting().GetSetting("active_login_ports").Value; foreach (var port in activeTrayPorts.Split(',')) { var localPort = port; var m = new Thread(() => RunMessage(message.Message, message.Title, localPort, message.Timeout)); m.Start(); } new APICall().PolicyApi.UpdateLastSocketResult(new DtoStringResponse() { Value = "Message Sent" }); break; case "Force_Checkin": var f = new Thread(RunCheckin); f.Start(); break; case "Reboot": Logger.Info("Server Issued Reboot Request. Rebooting."); var r = new Thread(() => RunReboot(action.Message)); r.Start(); break; case "Shutdown": Logger.Info("Server Issued Shutdown Request. Shutting Down."); var s = new Thread(() => RunShutdown(action.Message)); s.Start(); break; case "Start_Remote_Control": var sm = new Thread(() => RunStartRemoteControl()); sm.Start(); break; case "Wol_Task": var wolTask = JsonConvert.DeserializeObject <DtoWolTask>(action.Message); var w = new Thread(() => RunWakeup(wolTask)); w.Start(); break; case "Run_Module": var policy = JsonConvert.DeserializeObject <DtoClientPolicy>(action.Message); var rsm = new Thread(() => RunSingleModule(policy)); rsm.Start(); break; case "Logs": var logType = action.Message; var l = new Thread(() => SendLog(logType)); l.Start(); break; default: Logger.Info("Action Was Not Recognized."); break; } }