Beispiel #1
0
        private void ProcessSourceTask(ICaptchaSolutionSourceTask sourceTask)
        {
            if (sourceTask.Solution != null)
            {
                ICaptchaHarvesterTask harvesterTask     = null;
                RecaptchaSolution     recaptchaSolution = null;

                lock (m_lock)
                {
                    harvesterTask = m_sourceTasks[sourceTask] != null ? m_sourceTasks[sourceTask] : m_tasks.FirstOrDefault(t => !m_sourceTasks.ContainsValue(t));

                    m_tasks.Remove(harvesterTask);

                    recaptchaSolution = new RecaptchaSolution(sourceTask.Solution as string);
                }

                AddSolution(recaptchaSolution, harvesterTask);
            }

            lock (m_lock)
            {
                sourceTask.SolutionReleased -= SolutionReleaseEventHanlder;
                m_sourceTasks.Remove(sourceTask);
            }

            RestoreBalance();

            lock (m_lock)
            {
                if (m_manualSource.CurrentTask == null)
                {
                    AddSourceTask(m_tasks.FirstOrDefault(), false);
                }
            }
        }
Beispiel #2
0
        protected override bool ProcessTask(ICaptchaHarvesterTask task)
        {
            bool ret = false;

            if (task.Parameter != null)
            {
                lock (m_lock)
                {
                    AddSourceTask(task);
                }
            }
            else
            {
                RecaptchaSolution solution = GetOne();

                if (solution != null)
                {
                    task.Solution = solution;

                    ret = true;
                }
            }

            return(ret);
        }
Beispiel #3
0
        private void AddSolution(RecaptchaSolution solution, ICaptchaHarvesterTask harvesterTask = null)
        {
            if (harvesterTask != null)
            {
                harvesterTask.Solution = solution;

                ReleaseTask(harvesterTask);
            }
            else
            {
                lock (m_lock)
                {
                    m_solutions.Add(solution);

                    if (m_solutions.Count == 1)
                    {
                        m_oldestSolution = m_solutions.First();
                        m_liveTimer.Change(m_solutionLiveTime, Timeout.Infinite);
                    }
                }

                OnPropertyChanged("SolutionsCount");
            }
        }
Beispiel #4
0
        public RecaptchaSolution GetOne()
        {
            RecaptchaSolution ret = null;

            lock (m_lock)
            {
                if (m_solutions.Any())
                {
                    RecaptchaSolution solution = m_solutions.First();

                    m_solutions.Remove(solution);
                    ret = solution;
                }
            }

            if (ret != null)
            {
                RestoreBalance();
            }

            OnPropertyChanged("SolutionsCount");

            return(ret);
        }
Beispiel #5
0
        protected override StepResult Paying(ICheckoutTaskContext context, CheckoutTask task, CancellationToken cancelToken)
        {
            StepResult res = StepResult.Ok;
            SupremeUSABotTaskContext cxt = context as SupremeUSABotTaskContext;

            string         html       = null;
            HttpStatusCode?statusCode = null;

            int timeElapsed = TimeHelper.GetUnixTimeStamp() - cxt.CheckoutTimestamp;

            if (timeElapsed * 1000 < task.Footsite.Settings.DelayInCheckout)
            {
                Logger.LogEvent(task.Log, $"TASK {task.Id}",
                                $"Delay in checkout {task.Footsite.Settings.DelayInCheckout - timeElapsed * 1000} ms");

                cancelToken.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(task.Footsite.Settings.DelayInCheckout - timeElapsed * 1000));
                if (cancelToken.IsCancellationRequested)
                {
                    return(StepResult.Canceled);
                }
            }

            task.State = CheckoutTaskState.WaitingCaptcha;
            Logger.LogEvent(task.Log, $"TASK {task.Id}", $"Waiting captcha...");

            string token = null;

            while (true)
            {
                ICaptchaHarvesterTask harvesterTask = new CaptchaHarvesterTaskBase(null);

                Release.CaptchaHarvester.GetSolution(harvesterTask);

                WaitHandle.WaitAny(new[] { harvesterTask.SolutionReadyEvent, cancelToken.WaitHandle });

                if (cancelToken.IsCancellationRequested)
                {
                    return(StepResult.Canceled);
                }

                RecaptchaSolution solution = harvesterTask.Solution as RecaptchaSolution;

                if (solution.TimeStamp > cxt.CheckoutTimestamp)
                {
                    token = solution.Value;

                    break;
                }

                harvesterTask.SolutionReadyEvent.Dispose();
            }

            Logger.LogEvent(task.Log, $"TASK {task.Id}", $"Waiting captcha... done");

            task.State = CheckoutTaskState.Paying;

            using (HttpRequestMessage tohruCommitMessage = new HttpRequestMessage()
            {
                RequestUri = new Uri(m_tohruCommitPath),
                Method = HttpMethod.Post
            })
            {
                tohruCommitMessage.Headers.TryAddWithoutValidation("User-Agent", BrowserAgent);
                tohruCommitMessage.Headers.TryAddWithoutValidation("Accept", "*/*");
                tohruCommitMessage.Headers.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
                tohruCommitMessage.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream");
                tohruCommitMessage.Headers.TryAddWithoutValidation("Refer", "https://www.supremenewyork.com/checkout");
                tohruCommitMessage.Content = new StringContent(m_tohruTrackInfo);

                HttpHelper.GetStringSync(tohruCommitMessage, cxt.Client, out statusCode, cancelToken);
            }

            string billPhoneNumber = task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.PhoneNumber.Insert(3, "-").Insert(7, "-");

            using (HttpRequestMessage checkoutRequest = new HttpRequestMessage()
            {
                RequestUri = new Uri($"https://{task.Footsite.Domain}{m_checkoutPath}"),
                Method = HttpMethod.Post
            })
            {
                checkoutRequest.Headers.TryAddWithoutValidation("User-Agent", BrowserAgent);
                checkoutRequest.Headers.TryAddWithoutValidation("Accept", "*/*");
                checkoutRequest.Headers.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
                checkoutRequest.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                checkoutRequest.Headers.TryAddWithoutValidation("Refer", "https://www.supremenewyork.com/checkout");
                checkoutRequest.Headers.TryAddWithoutValidation("X-Requested-With", "XMLHttpRequest");
                checkoutRequest.Headers.TryAddWithoutValidation("Accept-Language", "en-US,en;q=0.8,en-GB;q=0.6");
                checkoutRequest.Headers.Add("X-CSRF-Token", cxt.CsrfToken);
                checkoutRequest.Content = new FormUrlEncodedContent(new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("store_credit_id", cxt.StoreId),
                    new KeyValuePair <string, string>("same_as_billing_address", "1"),
                    new KeyValuePair <string, string>("credit_card[last_name]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.SecondName),
                    new KeyValuePair <string, string>("credit_card[first_name]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.FirstName),
                    new KeyValuePair <string, string>("order[email]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.Email),
                    new KeyValuePair <string, string>("order[tel]", billPhoneNumber),
                    new KeyValuePair <string, string>("order[billing_address]", $"{task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.StreetAddress1}, {task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.StreetAddressLine2}"),
                    new KeyValuePair <string, string>("order[billing_city]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.City),
                    new KeyValuePair <string, string>("order[billing_state]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.State?.Abbreviation),
                    new KeyValuePair <string, string>("order[billing_zip]", task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.PostalCode),
                    new KeyValuePair <string, string>("order[billing_country]", ConvertCommonCountryNameToSupremeName(task.Profile.ReleaseCheckoutProfile.CheckoutProfile.BillingAddress.Country.Code)),
                    new KeyValuePair <string, string>("credit_card[type]", ConvertCommonCreditCardTypeToSupremeType(task.Profile.ReleaseCheckoutProfile.CheckoutProfile.PayCard.Type.Code) ?? ""),
                    new KeyValuePair <string, string>(cxt.CreditCardNumberFieldName, task.Profile.ReleaseCheckoutProfile.CheckoutProfile.PayCard.Number),
                    new KeyValuePair <string, string>(cxt.CreditCardMonthFieldName, task.Profile.ReleaseCheckoutProfile.CheckoutProfile.PayCard.ExpirationDate.Value.ToString("MM")),
                    new KeyValuePair <string, string>(cxt.CreditCardYearFieldName, task.Profile.ReleaseCheckoutProfile.CheckoutProfile.PayCard.ExpirationDate.Value.ToString("yyyy")),
                    new KeyValuePair <string, string>(cxt.CreditCardCVVFieldName, task.Profile.ReleaseCheckoutProfile.CheckoutProfile.PayCard.CVS),
                    new KeyValuePair <string, string>("order[terms]", "0"),
                    new KeyValuePair <string, string>("order[terms]", "1"),
                    new KeyValuePair <string, string>("g-recaptcha-response", token),
                    new KeyValuePair <string, string>("utf8", cxt.Utf8Symbol),
                    new KeyValuePair <string, string>("authenticity_token", cxt.AuthenticityToken),

                    cxt.ExtraField
                });

                html = HttpHelper.GetStringSync(checkoutRequest, cxt.Client, out statusCode, cancelToken);
            }

            if (cancelToken.IsCancellationRequested)
            {
                return(StepResult.Canceled);
            }
            if ((res = CheckResult(html, statusCode)) != StepResult.Ok)
            {
                return(res);
            }

            JObject checkoutReponseJObject = null;
            string  checkoutStatus         = null;
            string  slug = null;

            try
            {
                checkoutReponseJObject = JObject.Parse(html);
                checkoutStatus         = checkoutReponseJObject["status"].Value <string>();
            }
            catch (Exception e)
            {
                Logger.LogEvent(task.Log, $"TASK {task.Id}", "Could not get checkout response. Contact with support.");
            }

            if (checkoutStatus != null)
            {
                if (checkoutStatus == "queued")
                {
                    try
                    {
                        slug = checkoutReponseJObject["slug"].Value <string>();
                    }
                    catch (Exception e)
                    {
                        Logger.LogEvent(task.Log, $"TASK {task.Id}", "Could not get queue id. Contact with support.");
                    }

                    if (slug != null)
                    {
                        cxt.Slug = slug;

                        CheckoutStep queuedCheckout = new CheckoutStep(QueuedCheckout, "Waiting in Queue", CheckoutTaskState.Undefined);
                        CheckoutStep retryCheckout  = new CheckoutStep(RetryCheckout, "Checking paying status", CheckoutTaskState.Undefined);
                        TimeSpan     executionTime;

                        res = queuedCheckout.Run(cxt, task, TimeSpan.FromMilliseconds(task.Footsite.Settings.RetryPeriod), out executionTime, cancelToken);

                        if (res == StepResult.Ok)
                        {
                            checkoutStatus = cxt.QueuedCheckoutResponse["status"].Value <string>();

                            int attempts = 1;

                            while (attempts < 5 && res != StepResult.Canceled && checkoutStatus == "failed")
                            {
                                Logger.LogEvent(task.Log, $"TASK {task.Id}", $"Attempt {attempts} is failed... retry");
                                attempts++;

                                cancelToken.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(task.Footsite.Settings.RetryPeriod));
                                if (cancelToken.IsCancellationRequested)
                                {
                                    return(StepResult.Canceled);
                                }

                                res = retryCheckout.Run(cxt, task,
                                                        TimeSpan.FromMilliseconds(task.Footsite.Settings.RetryPeriod),
                                                        out executionTime, cancelToken);

                                if (res == StepResult.Ok)
                                {
                                    checkoutStatus = cxt.QueuedCheckoutResponse["status"].Value <string>();
                                }
                            }
                        }
                    }
                }

                if (res == StepResult.Ok)
                {
                    if (checkoutStatus == "failed")
                    {
                        string errorMessage = "";

                        try
                        {
                            foreach (JToken errorJToken in checkoutReponseJObject["errors"])
                            {
                                errorMessage += $"{errorJToken.First().Value<string>()};";
                            }
                        }
                        catch (Exception e)
                        {
                            ;
                        }

                        if (errorMessage != "")
                        {
                            Logger.LogEvent(task.Log, $"TASK {task.Id}", $"Has got errors: {errorMessage}");
                        }

                        res = StepResult.Failed;
                    }
                    else if (checkoutStatus == "dup")
                    {
                        Logger.LogEvent(task.Log, $"TASK {task.Id}", $"Has got duplication");

                        res = StepResult.Failed;
                    }
                    else if (checkoutReponseJObject.ToString().Contains("Your order has been submitted") || cxt.QueuedCheckoutResponse != null && cxt.QueuedCheckoutResponse.ToString().Contains("Your order has been submitted"))
                    {
                        res = StepResult.Ok;
                    }
                    else
                    {
                        Logger.LogEvent(task.Log, $"TASK {task.Id}",
                                        $"Could not resolve checkout status '{checkoutStatus}'. Contact with support.");

                        res = StepResult.Failed;
                    }
                }
            }
            else
            {
                res = StepResult.Failed;
            }

            return(res);
        }