private static string GetImageUrl(string ip, string user, string pass) { var req = new DigestHttpWebRequest(user, pass); req.Method = WebRequestMethods.Http.Post; var formData = new MultipartFormData(); formData.AddFile("archive", "", "application/octet-stream"); formData.Add("passwd", ""); formData.Add("mysubmit", "Screenshot"); req.PostData = formData.GetMultipartFormData(); req.ContentType = formData.ContentType; Uri uri = new Uri(string.Format(URL, ip)); using (HttpWebResponse webResponse = req.GetResponse(uri)) using (Stream responseStream = webResponse.GetResponseStream()) { if (responseStream != null) { using (StreamReader streamReader = new StreamReader(responseStream)) { var responseString = streamReader.ReadToEnd(); var pattern = "<img src=\"(.*?)\">"; MatchCollection matches = Regex.Matches(responseString, pattern); foreach (Match m in matches) { return(String.Format("http://{0}/{1}", ip, m.Groups[1])); } } } } return(null); }
private void DeployZip(string zipFile) { var responseString = string.Empty; var req = new DigestHttpWebRequest(UserName, Password); req.Method = WebRequestMethods.Http.Post; var formData = new MultipartFormData(); formData.Add("mysubmit", "Install"); formData.AddFile("archive", zipFile, "application/x-zip-compressed"); req.PostData = formData.GetMultipartFormData(); req.ContentType = formData.ContentType; Uri uri = new Uri(string.Format(URL, BoxIP)); using (HttpWebResponse webResponse = req.GetResponse(uri)) using (Stream responseStream = webResponse.GetResponseStream()) { if (responseStream != null) { using (StreamReader streamReader = new StreamReader(responseStream)) { responseString = streamReader.ReadToEnd(); string pattern = "<font color=\"red\">(.*?)<\\/font>"; MatchCollection matches = Regex.Matches(responseString, pattern); foreach (Match m in matches) { if (m.Groups[1].Value.Contains("Install Success")) { LogTaskMessage($"Deploy result: {m.Groups[1]}"); } else { Log.LogError($"Deploy result: {m.Groups[1]}"); } } } } } }
private void DeployZip(string zipFile, string ip, ConfigModel options) { var responseString = string.Empty; var req = new DigestHttpWebRequest(options.User, options.Pass); req.Method = WebRequestMethods.Http.Post; var formData = new MultipartFormData(); formData.Add("mysubmit", "Install"); formData.AddFile("archive", zipFile, "application/x-zip-compressed"); req.PostData = formData.GetMultipartFormData(); req.ContentType = formData.ContentType; Uri uri = new Uri(string.Format(URL, ip)); using (HttpWebResponse webResponse = req.GetResponse(uri)) using (Stream responseStream = webResponse.GetResponseStream()) { if (responseStream != null) { using (StreamReader streamReader = new StreamReader(responseStream)) { responseString = streamReader.ReadToEnd(); string pattern = "<font color=\"red\">(.*?)<\\/font>"; MatchCollection matches = Regex.Matches(responseString, pattern); foreach (Match m in matches) { Console.WriteLine("Deploy result: {0}", m.Groups[1]); } } } } }
private void Update(string html, bool hidden1 = false, bool hidden2 = false, bool hidden3 = false) { if (!hidden1 && !hidden2 && !hidden3) { return; } HtmlParser par = new HtmlParser(); IHtmlDocument document; document = par.Parse(html); var form = document.QuerySelector("[id='updateArtForm']"); if (form == null) { Console.WriteLine("> not found form update"); return; } var nodes = form.QuerySelectorAll("input,textarea"); MultipartFormData formdata = new MultipartFormData(); foreach (var node in nodes) { string name = node.GetAttribute("name"); string value = ""; //if (name == "ltoRelaunch"|| name== "LimitedTime") // continue; if (name == "Description" || name == "Keywords") { value = node.TextContent; } else { value = node.GetAttribute("value"); } if (name.Contains("amount")) { value = value.Remove(value.Length - 2); } formdata.Add(new FormElement(name, value)); } formdata.RemoveElements("ltoRelaunch"); formdata.RemoveElements("LimitedTime"); if (hidden1) { formdata.SetValue("ExcludeFromSearch", "1"); } else { formdata.RemoveElements("ExcludeFromSearch"); } if (hidden2) { formdata.SetValue("DoNotAllowGoogle", "1"); } else { formdata.RemoveElements("DoNotAllowGoogle"); } if (hidden3) { formdata.SetValue("isBlackout", "2"); } else { formdata.RemoveElements("isBlackout"); } formdata.Add(new FormElement("submit", "")); string res = http.Request("POST", "https://manager.hostingrocket.com/my-art-edit.cfm", new string[] { "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryffQeAkANeAVRVjmj" }, formdata.GetData("----WebKitFormBoundaryffQeAkANeAVRVjmj")); //File.WriteAllText("res_update.html", res); //File.WriteAllBytes("post.txt", formdata.GetData("----WebKitFormBoundaryffQeAkANeAVRVjmj")); }