using System; using System.Collections.Generic; using System.Linq; using System.Text; #if WIN32 using MSHTML; #else using mshtml; #endif using sharpknife.Utils; using System.Globalization; using sharpknife.Controls; using System.Drawing; using System.IO; using sharpknife.Data; using sharpknife.Engines; using sharpknife.Commands; namespace sharpknife.Strategies { class NoMinimumStrategy : Strategy { private string CAPTCHA = "Just checking to make sure you are a human and not a cheat bot"; public override bool CheckLogin(WebBrowserControl browser, PTCSource source) { string html = browser.Html; return StringUtils.Contains(html, "Log-In"); } public override void Login(WebBrowserControl browser, PTCSource source) { IHTMLElementCollection inputFields = HtmlUtils.GetElementCollection(browser.Document, "input"); foreach (IHTMLInputElement element in inputFields) { if (element.name == "username") { element.value = source.Username; } else if (element.name == "password") { element.value = source.Password; } else if (element.name == "submit") { // element.form.submit(); return; } } } public override decimal GetBalance(WebBrowserControl browser, PTCSource source) { //Your account balance after all transactions: IHTMLElementCollection elements = HtmlUtils.GetElementCollection(browser.Document, "td"); int count = elements.length; foreach (IHTMLElement element in elements) { if (!string.IsNullOrEmpty(element.innerText) && element.innerText.IndexOf("Your account balance after all transactions", StringComparison.InvariantCultureIgnoreCase) >= 0) { IHTMLElementCollection innerTables = ((IHTMLElementCollection)element.all).tags("table"); if (innerTables.length == 0) { IHTMLTable table = (IHTMLTable)element.parentElement.parentElement.parentElement; int rowIndex = 2; int columnIndex = 1; if (((IHTMLElement)table).innerHTML.IndexOf("Current Earnings", StringComparison.InvariantCultureIgnoreCase) >= 0) { rowIndex++; } IHTMLTableRow row = (IHTMLTableRow)browser.GetElementAt(table.rows, rowIndex); IHTMLTableCell cell = (IHTMLTableCell)browser.GetElementAt(row.cells, columnIndex); string value = ((IHTMLElement)cell).innerText.Substring(2).Trim(); return decimal.Parse(value, CultureInfo.InvariantCulture.NumberFormat); } } } throw new Exception(); } public override bool SolveCaptcha(WebBrowserControl browser, PTCSource source) { if (browser.Search(CAPTCHA)) { // // IHTMLElementCollection images = HtmlUtils.GetElementCollection(browser.Document, "img"); string leftUrl = string.Empty; string rightUrl = string.Empty; IHTMLImgElement leftImage = null; IHTMLImgElement rightImage = null; foreach (IHTMLImgElement image in images) { if (image.width == 60 && image.height == 60) { if (image.src.IndexOf("TN=1", StringComparison.InvariantCultureIgnoreCase) > 0) { leftUrl = image.src; leftImage = image; } else if (image.src.IndexOf("TN=2", StringComparison.InvariantCultureIgnoreCase) > 0) { rightUrl = image.src; rightImage = image; } } } Bitmap leftBitmap = ImageUtils.GetImage(leftImage); Bitmap rightBitmap = ImageUtils.GetImage(rightImage); int leftNumber = ImageUtils.ParseCaptcha(leftBitmap); int rightNumber = ImageUtils.ParseCaptcha(rightBitmap); NumberCaptchaConfirm dialog = new NumberCaptchaConfirm(true) { Captcha = string.Format("{0}{1}", leftNumber, rightNumber), LeftImage = leftBitmap, RightImage = rightBitmap }; int i = 0; //4769 IHTMLElementCollection links = HtmlUtils.GetElementCollection(browser.Document, "a"); foreach (IHTMLElement captchaLink in links) { IHTMLAnchorElement anchor = (IHTMLAnchorElement)captchaLink; if (StringUtils.Contains(anchor.href, "/scripts/runner.php?KE")) { dialog.Options[i] = int.Parse(captchaLink.innerText); i++; } } bool dialogResult = dialog.ShowDialog().Value; if (!dialog.IsMatch) { string path = string.Format(@"..\..\Images\Captcha\Numbers"); leftBitmap.Save(Path.Combine(path, string.Format("{0}.png", Guid.NewGuid()))); rightBitmap.Save(Path.Combine(path, string.Format("{0}.png", Guid.NewGuid()))); } leftBitmap.Dispose(); rightBitmap.Dispose(); if (dialogResult == true) { //4769 links = HtmlUtils.GetElementCollection(browser.Document, "a"); foreach (IHTMLElement captchaLink in links) { if (captchaLink.innerText == dialog.Captcha) { captchaLink.click(); return true; } } } } else { return true; } return false; } public override Ad ParseMail(Mail mail) { string paidAd = string.Empty; if (StringUtils.Contains(mail.Body, "PAID AD BELOW")) { paidAd = StringUtils.GetTokens(mail.Body, "{}PAID AD BELOW.{}--------------------------------------
{}")[1]; } else { paidAd = StringUtils.GetTokens(mail.Body, "{}--- Non Paid Ad ---{}--- Paid Ad ---{}--- NON Paid Ad ---{}")[2]; } paidAd = paidAd.Replace("=\r\n", string.Empty); paidAd = paidAd.Replace("3D\"", "\""); paidAd = paidAd.Replace("=3D", "="); string[] links = StringUtils.GetTokens(paidAd, "
{}
{}


"); if (links[1] == links[3]) { Ad ad = new Ad() { Link = links[1] }; return ad; } return null; } public override bool ParseAds(WebBrowserControl browser, PTCSource source) { string body = browser.Html; IHTMLElementCollection tables = HtmlUtils.GetElementCollection(browser.Document, "table"); List commands = new List(); int paidAds = 0; foreach (IHTMLElement element in tables) { string table = element.innerHTML; IHTMLElementCollection innerTables = ((IHTMLElementCollection)element.all).tags("table"); if (!string.IsNullOrEmpty(table) && innerTables.length == 0) { int start = body.IndexOf(table); int end = body.IndexOf("
", start, StringComparison.InvariantCultureIgnoreCase); if (end >= 0 && body.Substring(start, end - start).IndexOf("The ad above is worth", StringComparison.InvariantCultureIgnoreCase) >= 0) { string ad = body.Substring(start, end - start); // Cheat bot checks //http://www.no-minimum.com/scripts/runner.php?REDIRECT=http%3A%2F%2Fwww.no-minimum.com%2Fimages%2Fohoh.gif&hash=7ae463cd6a3a40d64a083502d71c9bb4 if (ad.IndexOf("ohoh.gif", StringComparison.InvariantCultureIgnoreCase) >= 0) { continue; } try { AdLogItem item = new AdLogItem(DateTime.Now, ad); if (item.Value > 0) { AdCommand command = new AdCommand( item.Link, item.Timer + 5, item.Type == AdLogItem.ValueType.Cents ? AdCommand.BonusValue.Cents : AdCommand.BonusValue.Points, item.Value, source.Name); //new Uri(link).GetComponents(UriComponents.Host, UriFormat.SafeUnescaped)); commands.Add(command); //if (command.Bonus == AdCommand.BonusValue.Cents) paidAds++; } } catch (Exception ex) { } } } } ParseAdsCommand parseAdsCommand = new ParseAdsCommand(source.Name); if (paidAds > 0) { foreach (AdCommand command in commands) { CommandEngine.GetEngine().Commands.Add(command); } } else { parseAdsCommand.NextExecution = DateTime.Now.AddHours(2); } CommandEngine.GetEngine().Commands.Add(parseAdsCommand); return false; } public override decimal GetReferrals(WebBrowserControl browser, PTCSource source) { throw new NotImplementedException(); } } }