예제 #1
0
        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 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);
        }
예제 #3
0
        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]);
                            }
                        }
                    }
                }
        }