Ejemplo n.º 1
0
        private async Task <DeleteResult> PostDeleteGalleryFlowArticleAsync(GalleryArticleDeleteParameter delParam, GalleryType gallType, int delay)
        {
            string pageHtml = await GetDeleteGalleryArticlePageAsync(delParam.GalleryId, delParam.ArticleID, null, gallType);

            Tuple <ParameterStorage, string> parseResult;
            ParameterStorage delete_Params  = null;
            string           lately_gallery = null;

            try
            {
                parseResult = await HtmlParser.GetDeleteFlowArticleParameterAsync(pageHtml, gallType);
            }
            catch (Exception e)
            {
                return(new DeleteResult(false, e.Message));
            }

            delete_Params  = parseResult.Item1;
            lately_gallery = parseResult.Item2;

            if (gallType == GalleryType.Normal)
            {
                cookies.Add(new Cookie("lately_cookie", HttpUtility.UrlEncode(lately_gallery))
                {
                    Domain = "dcinside.com"
                });
            }

            await Task.Delay(delay);

            string reqURL  = null;
            string referer = null;

            if (gallType == GalleryType.Normal)
            {
                reqURL  = _galleryURL + "/forms/delete_password_submit";
                referer = _galleryURL + "/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID;
            }
            else if (gallType == GalleryType.Minor)
            {
                reqURL  = _galleryURL + "/mgallery/forms/delete_password_submit";
                referer = _galleryURL + "/mgallery/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID;
            }

            if (reqURL == null || referer == null)
            {
                throw new Exception("예상치 못한 갤러리 형식입니다.");
            }

            using (HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookies
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString);
                    client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                    client.DefaultRequestHeaders.Referrer = new Uri(referer);
                    client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
                    client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout);

                    string reqData = delete_Params.ToString();
                    reqData += "&password="******"application/x-www-form-urlencoded")))
                    {
                        res.EnsureSuccessStatusCode();

                        using (HttpContent content = res.Content)
                        {
                            string result = await content.ReadAsStringAsync();

                            if (result.StartsWith("true||"))
                            {
                                if (gallType == GalleryType.Normal)
                                {
                                    return(new DeleteResult(true, ""));
                                }
                                else
                                {
                                    return(await PostDeleteMinorGalleryFlowArticleAsync(delParam, result.Replace("true||", "")));
                                }
                            }
                            else if (result == "false||비밀번호 인증에 실패하였습니다. 다시 시도해주세요" ||
                                     result == "false|| 비밀번호가 맞지 않습니다. 다시 시도해주세요" ||
                                     result == "false||비밀번호가 잘못되었습니다. 다시 시도해주세요")
                            {
                                return(new DeleteResult(false, "비밀번호가 다릅니다."));
                            }
                            else
                            {
                                return(new DeleteResult(false, "알 수 없는 오류입니다."));
                            }
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        private async Task <DeleteResult> PostDeleteMinorGalleryFlowArticleAsync(GalleryArticleDeleteParameter delParam, string key)
        {
            string pageHtml = await GetDeleteGalleryArticlePageAsync(delParam.GalleryId, delParam.ArticleID, key, GalleryType.Minor);

            Tuple <ParameterStorage, string> parseResult;
            ParameterStorage delete_Params = null;

            try
            {
                parseResult = await HtmlParser.GetDeleteFlowArticleParameterAsync(pageHtml, GalleryType.Minor);
            }
            catch (Exception e)
            {
                return(new DeleteResult(false, e.Message));
            }

            delete_Params = parseResult.Item1;

            string reqURL  = _galleryURL + "/mgallery/forms/delete_submit";
            string referer = _galleryURL + "/mgallery/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID + "&key=" + key;

            using (HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookies
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString);
                    client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                    client.DefaultRequestHeaders.Referrer = new Uri(referer);
                    client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
                    client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout);

                    string reqData = delete_Params.ToString();

                    using (HttpResponseMessage res =
                               await client.PostAsync(reqURL, new StringContent(reqData, Encoding.UTF8, "application/x-www-form-urlencoded")))
                    {
                        res.EnsureSuccessStatusCode();

                        using (HttpContent content = res.Content)
                        {
                            string result = await content.ReadAsStringAsync();

                            if (result.StartsWith("true||" + delParam.GalleryId))
                            {
                                return(new DeleteResult(true, ""));
                            }
                            else if (result == "false||비밀번호 인증에 실패하였습니다. 다시 시도해주세요" ||
                                     result == "false|| 비밀번호가 맞지 않습니다. 다시 시도해주세요" ||
                                     result == "false||비밀번호가 잘못되었습니다. 다시 시도해주세요")
                            {
                                return(new DeleteResult(false, "비밀번호가 다릅니다."));
                            }
                            else
                            {
                                return(new DeleteResult(false, "알 수 없는 오류입니다."));
                            }
                        }
                    }
                }
        }
Ejemplo n.º 3
0
        private async Task <LoginStatus> PostLoginAsync(string id, string pw, bool retry = true)
        {
            string      gallUrl   = "gallog";
            string      gallogUrl = _gallogURL + "/" + id;
            string      referer   = _loginPageURL + "?s_url=" + HttpUtility.UrlEncode(gallUrl);
            LoginStatus status    = new LoginStatus();

            // 로그인 페이지에 한번은 접속해야 정상 동작함
            string loginPageSrc = await GetLoginPageAsync(gallUrl);

            if (loginPageSrc.Contains("로그인 되었습니다"))
            {
                status = LoginStatus.Success;
                return(status);
            }

            ParameterStorage LoginParams = await HtmlParser.GetLoginParameterAsync(loginPageSrc);

            using (HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookies
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString);
                    client.DefaultRequestHeaders.Referrer = new Uri(referer);
                    client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
                    client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout);

                    string param = "s_url=" + HttpUtility.UrlEncode(gallUrl) + "&tieup=&url=&user_id=" + id + "&password="******"&x=0&y=0&ssl_chk=on&";
                    param += LoginParams.ToString();
                    using (HttpResponseMessage res = await client.PostAsync(_loginURL, new StringContent(param, Encoding.UTF8, "application/x-www-form-urlencoded")))
                    {
                        res.EnsureSuccessStatusCode();

                        using (HttpContent content = res.Content)
                        {
                            string result = await content.ReadAsStringAsync();

                            if (result.Contains("등록된 아이디가 아닙니다."))
                            {
                                status = LoginStatus.IDError;
                            }
                            else if (result.Contains("비밀번호가 틀렸습니다."))
                            {
                                status = LoginStatus.PasswordError;
                            }
                            else if (result.Contains("아이디 또는 비밀번호가 잘못되었습니다."))
                            {
                                status = LoginStatus.ErrorBoth;
                            }
                            else if (result.Contains("로그인을 5번 실패 하셨습니다."))
                            {
                                status = LoginStatus.MaximumAttemptFailed;
                            }
                            else if (result.Contains("잘못된 접근입니다"))
                            {
                                status = LoginStatus.Unknown;
                            }
                            else if (result.Contains(gallogUrl))
                            {
                                status = LoginStatus.Success;
                            }
                            else
                            {
                                status = LoginStatus.Unknown;
                            }

                            if (retry)
                            {
                                return(await PostLoginAsync(id, pw, false));
                            }
                        }
                    }
                }

            return(status);
        }