public void tvCommands() { WOL.WakeOnLan(macAddress); if (wsClientKey != "none") { wsClient.Send("{\"type\":\"request\",\"id\":\"switchinput_" + msgCount + "\",\"uri\":\"ssap://tv/switchInput\",\"payload\":{\"inputId\":\"HDMI_1\"}}"); _logger.Debug("Requesting Device switch to HDMI1 inside tvcommands Function"); msgCount++; } else { _logger.Debug("wsClientKey is none so sleeping 5 seconds and trying again"); Thread.Sleep(5000); if (wsClientKey != "none") { _logger.Debug("Requesting Device switch to HDMI1 inside tvcommands Function after pausing for 5 seconds."); wsClient.Send("{\"type\":\"request\",\"id\":\"switchinput_" + msgCount + "\",\"uri\":\"ssap://tv/switchInput\",\"payload\":{\"inputId\":\"HDMI_1\"}}"); msgCount++; } else { Thread.Sleep(5000); } } }
public async Task <IActionResult> Acorda(string macAddress) { try { await WOL.WakeOnLan(macAddress); return(Ok()); } catch (Exception ex) { return(BadRequest(ex)); } }
bool ICommand.Run(string MessageText, SlackRTM.Events.Message RawMessage, bool IsTargeted, SlackRTM.Slack Instance) { /* **** * WOL. * ****/ var match = Regex.Match( MessageText, // TODO: Use IsTargeted string.Concat("@", Instance.Self.Name, @":?\s+Wake (?<name>\w+)"), RegexOptions.IgnoreCase); if (match.Success) { NetworkData network = Singleton <NetworkData> .Instance; var LastHost = network.Find(match.Groups["name"].Value); Instance.SetLastHost(LastHost); Instance.SendMessage(RawMessage.Channel, string.Format("Waking {0}!", LastHost.FriendlyName)); WOL.WakeOnLan(LastHost.HardwareAddress); return(true); } return(false); }
private async Task ProcessRequestAsync(HttpListenerContext context) { try { var response = context.Response; var request = context.Request; string responseString = ""; switch (request.HttpMethod) { case "POST": using (Stream body = request.InputStream) { using StreamReader reader = new StreamReader(body, request.ContentEncoding); string value = reader.ReadToEnd(); JObject json = JObject.Parse(value); string password = json["password"].Value <string>(); int id = json["id"].Value <int>(); if (!string.IsNullOrEmpty(password) || !string.IsNullOrEmpty(Config.GetPassword())) { if (password != Config.GetPassword()) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return; } } var hosts = Config.GetHosts(); if (id < 0 || id >= hosts.Count) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } await WOL.WakeOnLan(hosts[id].Mac); } break; case "GET": if (context.Request.RawUrl == "/") { responseString = File.ReadAllText("html/admin.html").Replace("{{url}}", $"http://{Config.GetAddress()}"); StringBuilder items = new StringBuilder(); int i = 0; foreach (var host in Config.GetHosts()) { items.Append($"<a class=\"text-center label\">{host.Name} {host.Mac}</a> ") .Append($"<button class=\"btn btn-primary \" data-id=\"{i++}\">唤醒</button>") .Append("<p></p>"); } responseString = responseString.Replace("{{items}}", items.ToString()); } else { responseString = File.ReadAllText("html" + context.Request.RawUrl); } break; } byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); } catch (Exception ex) { Console.WriteLine("远程管理服务器错误:" + ex.Message); } finally { context.Response.OutputStream.Close(); } }
public void setupClient() { _logger.Debug("Begining the setupClient function"); WOL.WakeOnLan(macAddress); _logger.Debug("Sending the WOL Packet over to " + this.whichTV); wsClient = new WebSocket(this.IP); wsClient.OnOpen += (o, e) => { _logger.Info("Successfully Connected to " + this.whichTV); //wsClient.Send("{\"type\":\"register\",\"id\":\"register_0\",\"payload\":{\"forcePairing\":false,\"pairingType\":\"PROMPT\",\"manifest\":{\"manifestVersion\":1,\"appVersion\":\"1.1\",\"signed\":{\"created\":\"20140509\",\"appId\":\"com.lge.test\",\"vendorId\":\"com.lge\",\"localizedAppNames\":{\"\":\"LG Remote App\",\"ko-KR\":\"??? ?\",\"zxx-XX\":\"?? R??ot? A??\"},\"localizedVendorNames\":{\"\":\"LG Electronics\"},\"permissions\":[\"TEST_SECURE\",\"CONTROL_INPUT_TEXT\",\"CONTROL_MOUSE_AND_KEYBOARD\",\"READ_INSTALLED_APPS\",\"READ_LGE_SDX\",\"READ_NOTIFICATIONS\",\"SEARCH\",\"WRITE_SETTINGS\",\"WRITE_NOTIFICATION_ALERT\",\"CONTROL_POWER\",\"READ_CURRENT_CHANNEL\",\"READ_RUNNING_APPS\",\"READ_UPDATE_INFO\",\"UPDATE_FROM_REMOTE_APP\",\"READ_LGE_TV_INPUT_EVENTS\",\"READ_TV_CURRENT_TIME\"],\"serial\":\"2f930e2d2cfe083771f68e4fe7bb07\"},\"permissions\":[\"LAUNCH\",\"LAUNCH_WEBAPP\",\"APP_TO_APP\",\"CLOSE\",\"TEST_OPEN\",\"TEST_PROTECTED\",\"CONTROL_AUDIO\",\"CONTROL_DISPLAY\",\"CONTROL_INPUT_JOYSTICK\",\"CONTROL_INPUT_MEDIA_RECORDING\",\"CONTROL_INPUT_MEDIA_PLAYBACK\",\"CONTROL_INPUT_TV\",\"CONTROL_POWER\",\"READ_APP_STATUS\",\"READ_CURRENT_CHANNEL\",\"READ_INPUT_DEVICE_LIST\",\"READ_NETWORK_STATE\",\"READ_RUNNING_APPS\",\"READ_TV_CHANNEL_LIST\",\"WRITE_NOTIFICATION_TOAST\",\"READ_POWER_STATE\",\"READ_COUNTRY_INFO\"],\"signatures\":[{\"signatureVersion\":1,\"signature\":\"eyJhbGdvcml0aG0iOiJSU0EtU0hBMjU2Iiwia2V5SWQiOiJ0ZXN0LXNpZ25pbmctY2VydCIsInNpZ25hdHVyZVZlcnNpb24iOjF9.hrVRgjCwXVvE2OOSpDZ58hR+59aFNwYDyjQgKk3auukd7pcegmE2CzPCa0bJ0ZsRAcKkCTJrWo5iDzNhMBWRyaMOv5zWSrthlf7G128qvIlpMT0YNY+n/FaOHE73uLrS/g7swl3/qH/BGFG2Hu4RlL48eb3lLKqTt2xKHdCs6Cd4RMfJPYnzgvI4BNrFUKsjkcu+WD4OO2A27Pq1n50cMchmcaXadJhGrOqH5YmHdOCj5NSHzJYrsW0HPlpuAx/ECMeIZYDh6RMqaFM2DXzdKX9NmmyqzJ3o/0lkk/N97gfVRLW5hA29yeAwaCViZNCP8iC9aO0q9fQojoa7NQnAtw==\"}]}}}"); isConnected = true; connectionStatus = 2; }; wsClient.OnMessage += (o, e) => { _logger.Info("Received a message from the TV Webscokets server. The message is " + e.Data.ToString()); dynamic recMsg = JsonConvert.DeserializeObject(e.Data.ToString().Replace("-", "")); //check if this is the TV passing back the client code if (recMsg.type == "registered") { this.wsClientKey = recMsg.payload.clientkey; this.isPaired = true; } if (recMsg.type == "error") { //Error Messages that could be received from the TVs //We are not paired because the TV has prompted the user to accept the pairing. if (recMsg.error == "409 register already in progress") { } if (recMsg.error == "403 cancelled") { this.isPaired = false; } } }; wsClient.OnError += (o, e) => { Console.WriteLine("There is an error connecting and the message is " + e.Message.ToString()); _logger.Error("There is an error connecting and the message is " + e.Message.ToString()); //errorRecvd = true; }; wsClient.OnClose += (sender, e) => { //Console.WriteLine("This stupid disconnected"); _logger.Warn("The websocket connection with " + this.whichTV + " with an ip address of has been lost"); this.connectionStatus = 0; }; _logger.Info("Trying to Connect"); try { this.connectionStatus = 1; wsClient.Connect(); } catch (Exception e) { _logger.Error("There was a failure to connect and the message is " + e.ToString()); } }