? 1: #pragma checksum "d:\wwwroot\i.wskmn.com\bx\index.aspx" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "06E3BA995E0A72447B4A09C3AF3375B8A8179638"
? 2: //------------------------------------------------------------------------------
? 3: // <auto-generated>
? 4: // ?????????
? 5: // ?????:4.0.30319.42000
? 6: //
? 7: // ??????????????????,????
? 8: // ??????,?????????
? 9: // </auto-generated>
? 10: //------------------------------------------------------------------------------
? 11:
? 12: namespace ASP {
? 13:
? 14: #line 395 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 15: using System.Web.SessionState;
? 16:
? 17: #line default
? 18: #line hidden
? 19:
? 20: #line 387 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 21: using System.ComponentModel.DataAnnotations;
? 22:
? 23: #line default
? 24: #line hidden
? 25:
? 26: #line 400 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 27: using System.Web.UI.WebControls.WebParts;
? 28:
? 29: #line default
? 30: #line hidden
? 31:
? 32: #line 10 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 33: using iTextSharp.text.pdf;
? 34:
? 35: #line default
? 36: #line hidden
? 37:
? 38: #line 4 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 39: using System.Threading.Tasks;
? 40:
? 41: #line default
? 42: #line hidden
? 43:
? 44: #line 396 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 45: using System.Web.Security;
? 46:
? 47: #line default
? 48: #line hidden
? 49:
? 50: #line 388 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 51: using System.Configuration;
? 52:
? 53: #line default
? 54: #line hidden
? 55:
? 56: #line 383 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 57: using System;
? 58:
? 59: #line default
? 60: #line hidden
? 61:
? 62: #line 6 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 63: using System.Drawing;
? 64:
? 65: #line default
? 66: #line hidden
? 67:
? 68: #line 386 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 69: using System.Collections.Specialized;
? 70:
? 71: #line default
? 72: #line hidden
? 73:
? 74: #line 384 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 75: using System.Collections;
? 76:
? 77: #line default
? 78: #line hidden
? 79:
? 80: #line 402 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 81: using System.Xml.Linq;
? 82:
? 83: #line default
? 84: #line hidden
? 85:
? 86: #line 2 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 87: using System.IO;
? 88:
? 89: #line default
? 90: #line hidden
? 91:
? 92: #line 399 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 93: using System.Web.UI.WebControls;
? 94:
? 95: #line default
? 96: #line hidden
? 97:
? 98: #line 401 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 99: using System.Web.UI.HtmlControls;
? 100:
? 101: #line default
? 102: #line hidden
? 103:
? 104: #line 398 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 105: using System.Web.UI;
? 106:
? 107: #line default
? 108: #line hidden
? 109:
? 110: #line 394 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 111: using System.Web.DynamicData;
? 112:
? 113: #line default
? 114: #line hidden
? 115:
? 116: #line 392 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 117: using System.Web;
? 118:
? 119: #line default
? 120: #line hidden
? 121:
? 122: #line 391 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 123: using System.Text.RegularExpressions;
? 124:
? 125: #line default
? 126: #line hidden
? 127:
? 128: #line 5 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 129: using System.Net;
? 130:
? 131: #line default
? 132: #line hidden
? 133:
? 134: #line 393 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 135: using System.Web.Caching;
? 136:
? 137: #line default
? 138: #line hidden
? 139:
? 140: #line 389 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 141: using System.Linq;
? 142:
? 143: #line default
? 144: #line hidden
? 145:
? 146: #line 397 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 147: using System.Web.Profile;
? 148:
? 149: #line default
? 150: #line hidden
? 151:
? 152: #line 7 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 153: using System.Diagnostics;
? 154:
? 155: #line default
? 156: #line hidden
? 157:
? 158: #line 9 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 159: using iTextSharp.text;
? 160:
? 161: #line default
? 162: #line hidden
? 163:
? 164: #line 11 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 165: using iTextSharp.tool.xml;
? 166:
? 167: #line default
? 168: #line hidden
? 169:
? 170: #line 3 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 171: using System.Text;
? 172:
? 173: #line default
? 174: #line hidden
? 175:
? 176: #line 385 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config"
? 177: using System.Collections.Generic;
? 178:
? 179: #line default
? 180: #line hidden
? 181:
? 182:
? 183: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
? 184: public class bx_index_aspx : global::System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpAsyncHandler, System.Web.IHttpHandler {
? 185:
? 186: private static bool @__initialized;
? 187:
? 188: private static object @__fileDependencies;
? 189:
? 190:
? 191: #line 13 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 192:
? 193: private string wzurl = "http://wz4.wskmn.com/?cmd="; // ????????
? 194: //private string wlink_url = "http://link.wskmn.com/bx1/?count=0"; // ??????
? 195: private string wlink_url = "http://link.wskmn.com/bx1/?br=0"; // ??????
? 196: private string imgurl = "http://img.wskmn.com/img/?cmd=img";
? 197: private string mp4url = "http://img.wskmn.com/img/?cmd=mp4";
? 198: private string call_url = "http://img.wskmn.com/img/?cmd=call";
? 199: private string addr_url = "http://img.wskmn.com/img/?cmd=addr";
? 200:
? 201: private string models_folder = "model\\"; // ?????????
? 202: private string error_folder = "error\\"; // ??????????????
? 203: private string spider_folder = "spider\\"; // ????????????
? 204: private string list_folder = "list\\"; // ???????? ???????????????????????
? 205:
? 206: private string list_file = "list.txt";
? 207: private string keywords_file = "keywords.txt"; // ???????? ???????????????????????
? 208: private string file_keywordlist = "keywordlist.txt";
? 209:
? 210: private string tz1 = " sua "; // ????
? 211: private string tz2 = " em ";
? 212:
? 213: //???????
? 214: private string ch_keywords_list_chkey = "bx_spider_file_data";
? 215: private string ch_ReadError_chkey = "bx_spider_ReadError_"; //?????????
? 216:
? 217:
? 218: private const string KeyPrefix = "ch_keywords_list_chkey";
? 219:
? 220: string ch_yet_cache = "ch_yet_cache_"; //??????
? 221:
? 222:
? 223:
? 224: //true
? 225: //false
? 226: private string[] folder_Array = { "/notícias/", "/html/", "/artigo/","/liberar/","/notícias/" }; // ???3
? 227: private string[] filetype_Array = { ".html" }; // ???3
? 228: private string[] index_saveArray = { "/", "", "/index.html", "/index.php", "/index.asp", "/index.htm" }; // ????
? 229:
? 230: private string sites_folder = "sites\\"; //?????
? 231:
? 232: private string[] writef_extension = { "htm" }; // ???????????? ?????????????????.unknow
? 233:
? 234: private int keywords_number = 26940; // ?????????? ?????-1
? 235:
? 236: private int http_timeout = 3000;
? 237:
? 238: private bool spider_logfile = false; //?????? true??? false???
? 239:
? 240: private bool site_list = false; //?????? true??? false???
? 241:
? 242: private string charset = "utf-8"; //??????
? 243:
? 244: private bool url_redirect = true; //?url??????? ?? 1??key1 ?????? key1-key1-2023-11-19-id.??? fasle?????
? 245:
? 246: private int cache_timeout = 360; // ?????????????????? 360,360X2
? 247:
? 248:
? 249:
? 250:
? 251:
? 252:
? 253:
? 254: public void Page_Load(object sender, EventArgs e)
? 255: {
? 256: PageAsyncTask t = new PageAsyncTask(PageLoadAsync);
? 257: Page.RegisterAsyncTask(t);
? 258: Page.ExecuteRegisteredAsyncTasks();
? 259: }
? 260:
? 261: public async Task PageLoadAsync()
? 262: {
? 263: string ch_yet_cache = format().Replace("/","").Replace("\\","").Replace(".","");
? 264:
? 265: if (Request.QueryString["cmd"] == "clear")
? 266: {
? 267: ClearCache(); //????
? 268: Response.Write(DateTime.Now + "<br>" + "clear cache is success!");
? 269: Response.End();
? 270: }
? 271: else if(Application[ch_yet_cache] != null && Application[ch_yet_cache].ToString() != "error")
? 272: {
? 273: DateTime currentTime = DateTime.Now;
? 274: string formattedTime = currentTime.ToString("HH:mm:ss");
? 275: if(formattedTime.Contains("16:23:2"))
? 276: {
? 277: ClearCache();
? 278: }
? 279: Response.Write(Application[ch_yet_cache].ToString());
? 280: Response.End();
? 281: }
? 282: else if(url("id").Contains("wailian.txt"))
? 283: {
? 284: Response.Write(ReadError("wailian.txt"))
? 285: Response.End();
? 286: }
? 287: else
? 288: {
? 289: try
? 290: {
? 291: if (urls().Contains(".pdf"))
? 292: {
? 293: string btitle=GetRightPart();
? 294: if (btitle=="{error-1}")
? 295: {
? 296: btitle=GetRandomValue(keywords_file);
? 297:
? 298: }
? 299:
? 300: //??????????????????????
? 301: //string img="<img src=\"" +await GetWebContentAsync(imgurl,charset,http_timeout) +"\" alt=\"{k0}\" title=\"{k0}\"></img><br>\r\n";
? 302: string jz=
? 303: "<h2>{k0}</h2>"+
? 304: "<p>"+await get_wz_news()+"</p>"+
? 305: "<h2>{k0}</h2>"+
? 306: "<p>"+await get_wz_line()+"</p>"+
? 307: "<p>"+await get_wz_line()+"</p>"+
? 308: "<h2>{k0}</h2>"+
? 309: "<p>"+await get_wz_all()+"</p>";
? 310:
? 311:
? 312: //string content=jz.Replace("{k0}",btitle);
? 313: //string content=img.Replace("{k0}",btitle)+jz.Replace("{k0}",btitle);
? 314: string content=jz.Replace("{k0}",btitle);
? 315: string base64s=GeneratePDF(btitle,content,url("domain"),btitle,btitle);
? 316: Response.Write(base64s);
? 317: Response.End();
? 318: //return WriteFF(format(),base64s,1);
? 319: }
? 320: else
? 321: {
? 322: Response.Write(await getsource());
? 323: Response.Write("<!--" + DateTime.Now + "-->");
? 324: Response.End();
? 325: }
? 326: }
? 327: catch
? 328: {
? 329: ClearCache();
? 330: }
? 331:
? 332: }
? 333:
? 334: //
? 335: }
? 336:
? 337: protected string GeneratePDF(string pageTitle, string pageContent, string author, string subject, string keywords)
? 338: {
? 339: // ??????
? 340: Document doc = new Document();
? 341:
? 342: // ???????? PDF ??
? 343: MemoryStream memoryStream = new MemoryStream();
? 344:
? 345: // ?? PdfWriter
? 346: PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
? 347: string pageTitlea="<h1 style=\"color:red;\">"+pageTitle+"</h1><hr></hr>";
? 348: string htmlc=pageTitlea+pageContent+"<hr></hr>";
? 349:
? 350:
? 351:
? 352:
? 353: // ??????????
? 354: doc.Open();
? 355:
? 356: // ?? XMLWorker ? HTML ????? PDF
? 357: using (TextReader reader = new StringReader(htmlc))
? 358: {
? 359: XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, reader);
? 360: }
? 361:
? 362:
? 363: // ?????????????
? 364: doc.Add(new Paragraph("Author: " + author));
? 365: doc.Add(new Paragraph("Subject: " + subject));
? 366: doc.Add(new Paragraph("Keywords: " + keywords));
? 367: doc.Add(new Paragraph("Update: " + DateTime.Now.ToString()));
? 368:
? 369: // ????
? 370: doc.Close();
? 371:
? 372:
? 373: // ????? PDF ??
? 374: byte[] pdfBytes = memoryStream.ToArray();
? 375: string base64String = Convert.ToBase64String(pdfBytes);
? 376: return base64String;
? 377:
? 378: }
? 379:
? 380: //????
? 381:
? 382: protected void ClearCache()
? 383: {
? 384: HttpContext.Current.Application.RemoveAll();
? 385: }
? 386:
? 387: protected async Task<string> getsource()
? 388: {
? 389: if (spider_logfile)
? 390: {
? 391: string spider_folder1=cfolder(spider_folder);
? 392: string filename = spider_folder1 + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".txt";
? 393: string content = DateTime.Now + ": " + urls() + "\r\n";
? 394: AppendToFileUTF8(filename, content);
? 395:
? 396: }
? 397:
? 398:
? 399:
? 400: string ff=format(); //???????
? 401:
? 402: if (fileExists(ff)) //???????? ???????
? 403: {
? 404: string ss=ReadError(ff);
? 405: return ss;
? 406: }
? 407:
? 408: else
? 409: {
? 410: try
? 411: {
? 412: // ??????? ???????????
? 413: string ss=await Site();
? 414: return ss;
? 415: }
? 416: catch
? 417: {
? 418: ClearCache();
? 419: return "error";
? 420: }
? 421:
? 422: }
? 423:
? 424: }
? 425:
? 426: public async Task<string> Site()
? 427: {
? 428:
? 429: if (site_list)
? 430: {
? 431: WriteToFile(list_folder+list_file,url("domain"));
? 432: }
? 433: string ch_yet_cache = format().Replace("/","").Replace("\\","").Replace(".","");
? 434: string uuu = "http://" + urls();
? 435: string down = (await GetWebContentAsync(uuu, charset, http_timeout)).ToLower();
? 436: string[] lines = down.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
? 437: int lineCount = lines.Length;
? 438: if (down == "{error}" || down.Contains("Not Found") || down.Contains("HTTP Error") || down.Contains("server error") || lineCount < 31)
? 439: {
? 440: string ss = WriteFF(format(), await error(),0);
? 441: return ss;
? 442: }
? 443: else
? 444: {
? 445: List<string> linesList = GetRandomLines(keywords_file, 3);
? 446: string k0 = linesList[0];
? 447: string k1 = linesList[1];
? 448: string k2 = linesList[2];
? 449:
? 450: string st=down;
? 451: st=ReplaceFirst(st,"charset.*?>","charset=\"utf-8\"/>");
? 452: st=ReplaceFirst(st,"<htm.*?>","<html lang=\"pt-BR\">");
? 453: st=ReplaceFirst(st,"<meta.*?equiv.*?language.*?>","<meta http-equiv=\"content-language\" content=\"pt-BR\">\r\n");
? 454: st=ReplaceFirst(st,"</head>","</head>\r\n"+ReadError("head.txt")+"\r\n"+ReadError("h1.txt")+"\r\n");
? 455:
? 456: st = ReplaceFirst(st, "<title[\\s\\S]*?/title>", "<title>{k0},{k1},{k2}-" + url("domain") + "</title>");
? 457: st=ReplaceFirst(st,"<meta.*?ords.*?>","<meta name=\"keywords\" content=\"{k0},{k1},{k2}\">");
? 458: st=ReplaceFirst(st,"<meta.*?ription.*?>","<meta name=\"description\" content=\"{k0},{k1},{k2}\">");
? 459:
? 460: st=ReplaceFirst(st,"</ul>","<li><strong>"+GetNnn()+"</strong></li></ul>");
? 461: st=ReplaceFirst(st,"<b>[\\s\\S]*?</b>","<b>{k0}</b>");
? 462: st=ReplaceFirst(st,"</body>","</body>\r\n<div name=\"links\" id=\"site_links\" style=\"display:none;\">\r\n<ul><li>{upx}</li>"+await wlinks(5)+"</ul></div>");
? 463:
? 464:
? 465: st=ReplaceAll(st,"<strong>[\\s\\S]*?</strong>","<strong>" + "{k0}" + "</strong>");
? 466: st=ReplaceAll(st,"<h1[\\s\\S]*?</h1>","<h1>{k0}</h1>");
? 467: st=ReplaceAll(st,"<h2[\\s\\S]*?</h2>","<h2>{k0}</h2>");
? 468: st=ReplaceAll(st,"<h3[\\s\\S]*?</h3>","<h3><strong>{k0}</strong></h3>");
? 469: st=ReplaceAll(st,"<h4[\\s\\S]*?</h4>","<h4><strong>{k1}</strong></h4>");
? 470: st=ReplaceAll(st,"<h5[\\s\\S]*?</h5>","<h5><strong>{k2}</strong></h5>");
? 471:
? 472: st=await ReplaceKeyWithRandomValue(st,"<p>([\\s\\S]*?)</p>");
? 473:
? 474: StringBuilder sd = new StringBuilder(st);
? 475: sd.Replace("©", await call_data() + "\r\n©")
? 476: .Replace("reserved","reserved\r\n" +await addr_data())
? 477: .Replace("copyright","copyright <strong>{k0}</strong>")
? 478: .Replace("{domain}",url("domain"))
? 479: .Replace("{now}",DateTime.Now.ToString())
? 480: .Replace("{k0}",k0)
? 481: .Replace("{k1}",k1)
? 482: .Replace("{k2}",k2);
? 483:
? 484: string contents = WriteFF(format(),sd.ToString(),1);
? 485: Application[ch_yet_cache] = contents;
? 486: return contents;
? 487: }
? 488: }
? 489:
? 490:
? 491: public void WriteToFile(string filePath, string content)
? 492: {
? 493: if (string.IsNullOrEmpty(content))
? 494: {
? 495: return;
? 496: }
? 497:
? 498: string fullPath = Server.MapPath(filePath);
? 499:
? 500: using (FileStream fs = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
? 501: {
? 502: using (StreamReader sr = new StreamReader(fs))
? 503: {
? 504: string fileContent = sr.ReadToEnd();
? 505:
? 506: if (!fileContent.Contains(content))
? 507: {
? 508: using (StreamWriter sw = new StreamWriter(fs))
? 509: {
? 510: sw.WriteLine(content);
? 511: }
? 512: }
? 513: }
? 514: }
? 515: }
? 516:
? 517:
? 518:
? 519:
? 520: //??????
? 521: public static string ReplaceFirst(string input, string pattern, string replacement)
? 522: {
? 523: Regex regex = new Regex(pattern, RegexOptions.Compiled);
? 524: return regex.Replace(input, replacement, 1);
? 525: }
? 526:
? 527: // ????
? 528: public static string ReplaceAll(string input, string pattern, string replacement)
? 529: {
? 530: Regex regex = new Regex(pattern, RegexOptions.Compiled);
? 531: return regex.Replace(input, replacement);
? 532: }
? 533:
? 534:
? 535: public async Task<string> ReplaceKeyWithRandomValue(string content, string key)
? 536: {
? 537: Regex regEx = new Regex(key, RegexOptions.Compiled);
? 538: MatchCollection matches = regEx.Matches(content);
? 539:
? 540: StringBuilder result = new StringBuilder();
? 541: int start = 0;
? 542:
? 543: foreach (Match match in matches)
? 544: {
? 545: result.Append(content, start, match.Index - start);
? 546: result.Append(await get_wz_line());
? 547: start = match.Index + match.Length;
? 548: }
? 549:
? 550: result.Append(content, start, content.Length - start);
? 551:
? 552: return result.ToString();
? 553: }
? 554:
? 555:
? 556:
? 557: /*
? 558:
? 559: // ?????? ????????
? 560: //??
? 561: Stopwatch stopwatch = new Stopwatch();
? 562: stopwatch.Start();
? 563: // ??
? 564: stopwatch.Stop();
? 565: long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
? 566: long elapsedNanoseconds = stopwatch.ElapsedTicks * 1000000000 / Stopwatch.Frequency;
? 567: Response.Write("????(??): " + elapsedMilliseconds + " ??<br>");
? 568: Response.Write("????(??): " + elapsedNanoseconds + " ??<br>");
? 569: Response.End();
? 570: return null;
? 571:
? 572: */
? 573: protected async Task<string> error()
? 574: {
? 575:
? 576: //????
? 577: string path_error=error_folder + url("domain") +".txt";
? 578: string ch_yet_cache = format().Replace("/","").Replace("\\","").Replace(".","");
? 579:
? 580: List<string> lines = GetRandomLines(keywords_file, 11);
? 581: string kk;
? 582: string k0 = lines[0];
? 583: string k1 = lines[1];
? 584: string k2 = lines[2];
? 585: string k3 = lines[3];
? 586: string k4 = lines[4];
? 587: string k5 = lines[5];
? 588: string k6 = lines[6];
? 589: string k7 = lines[7];
? 590: string k8 = lines[8];
? 591: string k9 = lines[9];
? 592: string k10 = lines[10];
? 593:
? 594: //0ms ??????
? 595: //12ms ???????
? 596: //??????????
? 597: if (GetRightPart()=="{error-1}")
? 598: {
? 599: kk=k0;
? 600: }
? 601: else
? 602: {
? 603: kk=GetRightPart();
? 604: }
? 605:
? 606: if (fileExists(path_error)) //?????????????
? 607: {
? 608:
? 609:
? 610: //2ms
? 611: //18ms
? 612:
? 613: string e1 =ReadError(path_error);
? 614:
? 615:
? 616: //2ms
? 617: //23ms
? 618:
? 619: e1 = replace_key(e1,"{key}");
? 620: //2ms
? 621: //29ms
? 622:
? 623: e1 = replace_href(e1,"{href}");
? 624:
? 625: //13ms
? 626: //30ms
? 627:
? 628: e1 = replace_nnn(e1,"{nn}");
? 629:
? 630: //41ms
? 631: //23ms
? 632: // ??
? 633:
? 634: //????
? 635: e1 = await replace_jz(e1,"{jz}");
? 636:
? 637: //6621ms ?????
? 638: //150ms ???????
? 639:
? 640:
? 641:
? 642: //6957ms
? 643: //190ms
? 644:
? 645: e1 = await replace_img1(e1,"{img1}");
? 646: //6614ms
? 647: //224ms
? 648:
? 649:
? 650: StringBuilder sb = new StringBuilder(e1);
? 651:
? 652: //????
? 653: sb.Replace("{now}", DateTime.Now.ToString())
? 654: .Replace("{url}", urls())
? 655: .Replace("{domain}",url("domain"))
? 656: .Replace("{color}",color())
? 657: .Replace("{num}",GenerateRandomNumber(5).ToString())
? 658: .Replace("{num1}",GenerateRandomNumber(1).ToString())
? 659: .Replace("{num2}",GenerateRandomNumber(2).ToString())
? 660: .Replace("{w}",await wlinks(1))
? 661: .Replace("{w1}",await wlinks(1))
? 662: .Replace("{news}",await get_wz_news())
? 663: .Replace("{wz}",await get_wz_all())
? 664: .Replace("{pdf}",await get_pdf_url())
? 665: .Replace("{lunlian}",await wlinks(5))
? 666: .Replace("{mb}","<a href=\"/\" title=\"{k0}\">Home</a>>><a>{k0}</a>")
? 667: .Replace("{sp}", @"<video controls style=""width:80%;"" title=""{k0}""><source src=""" + await GetWebContentAsync(mp4url, charset, http_timeout) + @""" type=""video/mp4""><p>{k0}</p></video>")
? 668: .Replace("{sp}",await GetWebContentAsync(mp4url, charset, http_timeout))
? 669: .Replace("{k1}",k1)
? 670: .Replace("{k2}",k2)
? 671: .Replace("{k3}",k3)
? 672: .Replace("{k4}",k4)
? 673: .Replace("{k5}",k5)
? 674: .Replace("{k6}",k6)
? 675: .Replace("{k7}",k7)
? 676: .Replace("{k8}",k8)
? 677: .Replace("{k9}",k9)
? 678: .Replace("{k10}",k10);
? 679:
? 680: //10576ms
? 681: //290ms
? 682:
? 683: string ssd=sb.ToString();
? 684: ssd=await replace_img(ssd,"{img}");
? 685: string error_content=ssd.Replace("{k0}",kk).ToString();
? 686:
? 687: Application[ch_yet_cache] = error_content;
? 688:
? 689: return error_content;
? 690:
? 691: }
? 692: else //???????????
? 693: {
? 694: //???????? ???????????????????????
? 695:
? 696:
? 697: StringBuilder sb = new StringBuilder(ReadError(GetRandomTxtFileFromFolder(models_folder)));
? 698: //2ms
? 699:
? 700: sb.Replace("{addr}",await addr_data())
? 701: .Replace("{call}",await call_data());
? 702: //671ms
? 703:
? 704: string e1 = rand_replace(sb.ToString(),"{rand}");
? 705: //716ms
? 706:
? 707: AppendToFileUTF8(path_error, e1); //??????????
? 708: //669ms
? 709:
? 710: e1 = replace_key(e1,"{key}");
? 711: //646ms
? 712:
? 713:
? 714: e1 = replace_href(e1,"{href}");
? 715: //699ms
? 716:
? 717: e1 = replace_nnn(e1,"{nn}");
? 718: //715ms
? 719:
? 720:
? 721: //????
? 722: e1 = await replace_jz(e1,"{jz}");
? 723: //12550ms
? 724:
? 725:
? 726:
? 727:
? 728: //9487ms
? 729:
? 730: e1 = await replace_img1(e1,"{img1}");
? 731: //12137ms
? 732:
? 733:
? 734: sb.Clear();
? 735: sb.Append(e1);
? 736: sb.Replace("{now}", DateTime.Now.ToString())
? 737: .Replace("{url}", urls())
? 738: .Replace("{domain}",url("domain"))
? 739: .Replace("{color}",color())
? 740: .Replace("{num}",GenerateRandomNumber(5).ToString())
? 741: .Replace("{num1}",GenerateRandomNumber(1).ToString())
? 742: .Replace("{num2}",GenerateRandomNumber(2).ToString())
? 743: .Replace("{w}",await wlinks(1))
? 744: .Replace("{w1}",await wlinks(1))
? 745: .Replace("{news}",await get_wz_news())
? 746: .Replace("{wz}",await get_wz_all())
? 747: .Replace("{pdf}",await get_pdf_url())
? 748: .Replace("{lunlian}",await wlinks(5))
? 749: .Replace("{mb}","<a href=\"/\" title=\"{k0}\">Home</a>>><p>{k0}</p>")
? 750: .Replace("{sp}", @"<video controls style=""width:80%;"" title=""{k0}""><source src=""" + await GetWebContentAsync(mp4url, charset, http_timeout) + @""" type=""video/mp4""><p>{k0}</p></video>")
? 751: .Replace("{sp}",await GetWebContentAsync(mp4url, charset, http_timeout))
? 752:
? 753: .Replace("{k1}",k1)
? 754: .Replace("{k2}",k2)
? 755: .Replace("{k3}",k3)
? 756: .Replace("{k4}",k4)
? 757: .Replace("{k5}",k5)
? 758: .Replace("{k6}",k6)
? 759: .Replace("{k7}",k7)
? 760: .Replace("{k8}",k8)
? 761: .Replace("{k9}",k9)
? 762: .Replace("{k10}",k10);
? 763: //14346ms
? 764: string ssd=sb.ToString();
? 765: ssd=await replace_img(ssd,"{img}");
? 766: string error_content = ssd.Replace("{k0}",kk).ToString();
? 767:
? 768: Application[ch_yet_cache] = error_content;
? 769:
? 770: return error_content;
? 771: }
? 772:
? 773: }
? 774:
? 775:
? 776:
? 777:
? 778:
? 779: public string rand_replace(string inputString, string teze)
? 780: {
? 781: StringBuilder result = new StringBuilder(inputString.Length);
? 782: int currentIndex = 0;
? 783:
? 784: int startPos = inputString.IndexOf(teze, currentIndex);
? 785: while (startPos != -1)
? 786: {
? 787: result.Append(inputString, currentIndex, startPos - currentIndex);
? 788: result.Append(GenerateRandomPassword(10));
? 789: currentIndex = startPos + teze.Length;
? 790: startPos = inputString.IndexOf(teze, currentIndex);
? 791: }
? 792:
? 793: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 794:
? 795: return result.ToString();
? 796: }
? 797:
? 798:
? 799: public string GenerateRandomPassword(int length)
? 800: {
? 801:
? 802: string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
? 803:
? 804: StringBuilder randomPassword = new StringBuilder();
? 805: for (int i = 0; i < length; i++)
? 806: {
? 807: char randomChar = allowedChars[Random.Next(allowedChars.Length)];
? 808: randomPassword.Append(randomChar);
? 809: }
? 810:
? 811: return randomPassword.ToString();
? 812: }
? 813:
? 814: public string GetRandomTxtFileFromFolder(string folderName)
? 815: {
? 816: string targetFolder = Server.MapPath(folderName);
? 817: string cacheKey = "models_" + targetFolder;
? 818:
? 819: // ????????
? 820: if (HttpContext.Current.Cache[cacheKey] == null)
? 821: {
? 822: Dictionary<int, string> txtFiles = new Dictionary<int, string>();
? 823: DirectoryInfo dirInfo = new DirectoryInfo(targetFolder);
? 824: int index = 0;
? 825:
? 826: // ?? txtFiles ??
? 827: foreach (FileInfo fileInfo in dirInfo.GetFiles())
? 828: {
? 829: if (fileInfo.Extension.ToLower() == ".txt")
? 830: {
? 831: txtFiles.Add(index, fileInfo.Name); // ?????,????
? 832: index++;
? 833: }
? 834: }
? 835:
? 836: // ?? txtFiles ??
? 837: if (txtFiles.Count > 0)
? 838: {
? 839: HttpContext.Current.Cache.Insert(cacheKey, txtFiles);
? 840: }
? 841: }
? 842:
? 843: // ???????
? 844: if (HttpContext.Current.Cache[cacheKey] != null)
? 845: {
? 846: Dictionary<int, string> txtFiles = (Dictionary<int, string>)HttpContext.Current.Cache[cacheKey];
? 847: int randomIndex = Random.Next(txtFiles.Count);
? 848: return models_folder + txtFiles[randomIndex];
? 849: }
? 850: else
? 851: {
? 852: return models_folder + "error.txt";
? 853: }
? 854: }
? 855:
? 856:
? 857: /////////////////////////////////////////////////////////////////////////////////////////////////////////
? 858: ////??????????????? ???????
? 859: /////////////////////////////////////////////////////////////////////////////////////////////////////////
? 860:
? 861: public async Task<string> addr_data()
? 862: {
? 863: string jz="<address>endereço:"+ await GetWebContentAsync(addr_url,charset,http_timeout) +"</address>";
? 864: return jz;
? 865: }
? 866:
? 867: public async Task<string> call_data()
? 868: {
? 869: string sou_s=await GetWebContentAsync(call_url,charset,http_timeout);
? 870: string jz="Contate-nos:<a href=\"tel:" + sou_s.Replace(" ","") +"\">" + sou_s+"</a>";
? 871: return jz;
? 872: }
? 873:
? 874:
? 875: public async Task<string> get_wz_line()
? 876: {
? 877: string iurl=wzurl+ "line&rand=" + Random.Next();
? 878: string jz=await GetWebContentAsync(iurl,charset,http_timeout);
? 879: jz=jz.Replace(tz1,"{k0}").Replace(tz2,"{k0}");
? 880: await Task.Delay(1); // ??1??
? 881: return jz;
? 882: }
? 883:
? 884: public async Task<string> get_wz_all()
? 885: {
? 886: string iurl=wzurl+ "all&rand=" + Random.Next();
? 887: string jz=await GetWebContentAsync(iurl,charset,http_timeout);
? 888: jz=jz.Replace(tz1,"{k0}").Replace(tz2,"{k0}");
? 889: return jz;
? 890: }
? 891:
? 892: public async Task<string> get_wz_news()
? 893: {
? 894: string iurl=wzurl+ "news&rand=" + Random.Next();
? 895: string jz=await GetWebContentAsync(iurl,"utf-8",http_timeout);
? 896: jz=jz.Replace(tz1,"{k0}").Replace(tz2,"{k0}");
? 897: return jz;
? 898: }
? 899:
? 900: public async Task<string> get_pdf_url()
? 901: {
? 902: try
? 903: {
? 904: string href=GetNnn();
? 905: string link = ExtractLink(href);
? 906: string extension = Path.GetExtension(link); //?????
? 907: string pdf_name=href.Replace(extension, ".pdf");
? 908: return pdf_name;
? 909: }
? 910: catch
? 911: {
? 912: return "4k4.com.br";
? 913: }
? 914: }
? 915:
? 916: static string ExtractLink(string anchorText)
? 917: {
? 918: // ???????????
? 919: var match = Regex.Match(anchorText, @"<a\s+[^>]*href=""([^""]*)""[^>]*>");
? 920:
? 921: if (match.Success)
? 922: {
? 923: return match.Groups[1].Value;
? 924: }
? 925:
? 926: return string.Empty;
? 927: }
? 928:
? 929: public async Task<string> wlinks(int count)
? 930: {
? 931: StringBuilder lunx = new StringBuilder();
? 932:
? 933: for (int n = 0; n < count; n++)
? 934: {
? 935: lunx.Append("<li>");
? 936: lunx.Append(await GetWebContentAsync(wlink_url, charset, http_timeout));
? 937: lunx.Append("</li>");
? 938: await Task.Delay(1); // ??1??
? 939: }
? 940:
? 941: return lunx.ToString();
? 942: }
? 943:
? 944:
? 945:
? 946: //???????
? 947: public async Task<string> GetWebContentAsync(string strURL, string strCharset, int intTimeout)
? 948: {
? 949:
? 950: try
? 951: {
? 952: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
? 953: request.Timeout = intTimeout;
? 954: request.ContentType = "application/x-www-form-urlencoded";
? 955:
? 956: WebResponse response = await request.GetResponseAsync();
? 957:
? 958: if (((HttpWebResponse)response).StatusCode != HttpStatusCode.OK)
? 959: {
? 960: return "{error}";
? 961: }
? 962:
? 963: Stream receiveStream = response.GetResponseStream();
? 964: StreamReader readStream = null;
? 965:
? 966: if (strCharset == null)
? 967: readStream = new StreamReader(receiveStream);
? 968: else
? 969: readStream = new StreamReader(receiveStream, Encoding.GetEncoding(strCharset));
? 970:
? 971: string data = await readStream.ReadToEndAsync();
? 972:
? 973: response.Close();
? 974: readStream.Close();
? 975: return data;
? 976: }
? 977: catch
? 978: {
? 979: return "{error}";
? 980: }
? 981: }
? 982: //////////////////////////////////////////////////////////////////////////////////////////////////////////
? 983: ////??????
? 984: //////////////////////////////////////////////////////////////////////////////////////////////////////////
? 985:
? 986:
? 987:
? 988: public string color()
? 989: {
? 990: //Random rnd = new Random();
? 991: int red = Random.Next(256);
? 992: int green = Random.Next(256);
? 993: int blue = Random.Next(256);
? 994: Color randomColor = Color.FromArgb(red, green, blue);
? 995: return "#" + randomColor.R.ToString("X2") + randomColor.G.ToString("X2") + randomColor.B.ToString("X2");
? 996: }
? 997:
? 998: public class MinMaxValue
? 999: {
? 1000: public int MinValue { get; set; }
? 1001: public int MaxValue { get; set; }
? 1002: }
? 1003:
? 1004: private static Dictionary<int, MinMaxValue> GenerateRandomNumbermyBounds = new Dictionary<int, MinMaxValue>
? 1005: {
? 1006: { 1, new MinMaxValue { MinValue = 0, MaxValue = 9 } },
? 1007: { 2, new MinMaxValue { MinValue = 10, MaxValue = 99 } },
? 1008: { 3, new MinMaxValue { MinValue = 100, MaxValue = 999 } },
? 1009: { 4, new MinMaxValue { MinValue = 1000, MaxValue = 9999 } },
? 1010: { 6, new MinMaxValue { MinValue = 100000, MaxValue = 999999 } }
? 1011: };
? 1012:
? 1013:
? 1014: public int GenerateRandomNumber(int length)
? 1015: {
? 1016: int minValue;
? 1017: int maxValue;
? 1018:
? 1019: if (GenerateRandomNumbermyBounds.ContainsKey(length))
? 1020: {
? 1021: minValue = GenerateRandomNumbermyBounds[length].MinValue;
? 1022: maxValue = GenerateRandomNumbermyBounds[length].MaxValue;
? 1023: }
? 1024: else
? 1025: {
? 1026: minValue = (int)Math.Pow(10, length - 1);
? 1027: maxValue = (int)Math.Pow(10, length) - 1;
? 1028: }
? 1029:
? 1030: return Random.Next(minValue, maxValue + 1);
? 1031: }
? 1032:
? 1033:
? 1034:
? 1035:
? 1036: ///////////////////////////////////////////////////////////////////////////////////////////////////
? 1037: // ????????
? 1038: ///////////////////////////////////////////////////////////////////////////////////////////////////
? 1039: //img
? 1040: public async Task<string> replace_img(string inputString, string teze)
? 1041: {
? 1042: StringBuilder result = new StringBuilder(inputString.Length);
? 1043: int currentIndex = 0;
? 1044:
? 1045: int startPos = inputString.IndexOf(teze, currentIndex);
? 1046: while (startPos != -1)
? 1047: {
? 1048: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1049:
? 1050: result.Append("<img src=\"" +await GetWebContentAsync(imgurl,charset,http_timeout) +"\" style=\"width:80%;height:55vh;\" alt=\"{k0}\" title=\"{k0}\"><br>");
? 1051: currentIndex = startPos + teze.Length;
? 1052: startPos = inputString.IndexOf(teze, currentIndex);
? 1053: await Task.Delay(1); // ??1??
? 1054: }
? 1055:
? 1056: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1057:
? 1058: return result.ToString();
? 1059: }
? 1060:
? 1061: //img1
? 1062: public async Task<string> replace_img1(string inputString, string teze)
? 1063: {
? 1064: StringBuilder result = new StringBuilder(inputString.Length);
? 1065: int currentIndex = 0;
? 1066:
? 1067: int startPos = inputString.IndexOf(teze, currentIndex);
? 1068: while (startPos != -1)
? 1069: {
? 1070: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1071: result.Append(await GetWebContentAsync(imgurl,charset,http_timeout));
? 1072: currentIndex = startPos + teze.Length;
? 1073: startPos = inputString.IndexOf(teze, currentIndex);
? 1074: await Task.Delay(1); // ??1??
? 1075: }
? 1076:
? 1077: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1078:
? 1079: return result.ToString();
? 1080: }
? 1081:
? 1082: //mp4
? 1083: public async Task<string> replace_sp(string inputString, string teze)
? 1084: {
? 1085: StringBuilder result = new StringBuilder(inputString.Length);
? 1086: int currentIndex = 0;
? 1087:
? 1088: int startPos = inputString.IndexOf(teze, currentIndex);
? 1089: while (startPos != -1)
? 1090: {
? 1091: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1092: result.Append(await GetWebContentAsync(mp4url,charset,http_timeout));
? 1093: currentIndex = startPos + teze.Length;
? 1094: startPos = inputString.IndexOf(teze, currentIndex);
? 1095: }
? 1096:
? 1097: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1098:
? 1099: return result.ToString();
? 1100: }
? 1101:
? 1102:
? 1103: public async Task<string> replace_jz(string inputString, string teze)
? 1104: {
? 1105: StringBuilder result = new StringBuilder(inputString.Length);
? 1106: int currentIndex = 0;
? 1107:
? 1108: int startPos = inputString.IndexOf(teze, currentIndex);
? 1109: while (startPos != -1)
? 1110: {
? 1111: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1112: result.Append(await get_wz_line());
? 1113: currentIndex = startPos + teze.Length;
? 1114: startPos = inputString.IndexOf(teze, currentIndex);
? 1115: await Task.Delay(1); // ??1??
? 1116: }
? 1117:
? 1118: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1119:
? 1120: return result.ToString();
? 1121: }
? 1122:
? 1123: ///////////////////////////////////////////////////////////////////////////////////////////////////
? 1124:
? 1125:
? 1126: public string GetNnn()
? 1127: {
? 1128: string line = GetRandomValue(file_keywordlist);
? 1129:
? 1130: if (line.Contains(","))
? 1131: {
? 1132: string[] arrays = line.Split(',');
? 1133: //string combin = GetRandomItem(folder_Array) + arrays[0] + GetRandomItem(filetype_Array);
? 1134: string combin = "/0.html";
? 1135: if (url_redirect) //?????url????
? 1136: {
? 1137: //a20-bet-depósito-mínimo-2012-123-456-id-0.html
? 1138: combin=GetRandomItem(folder_Array) +arrays[1].Replace(" ","-")+"-"+ DateTime.Now.ToString("yyyy-MM-dd")+"-id-"+arrays[0] + GetRandomItem(filetype_Array);
? 1139: }
? 1140: else
? 1141: {
? 1142: combin=GetRandomItem(folder_Array) + arrays[0] + GetRandomItem(filetype_Array);
? 1143: }
? 1144: string link = String.Format("<a href=\"{0}\" title=\"{1}\">{1}</a>", combin, arrays[1]);
? 1145: return link;
? 1146: }
? 1147: else
? 1148: {
? 1149: return "<a href=\"/\" title=\"{k0}\">{k0}</a>";
? 1150: }
? 1151: }
? 1152:
? 1153:
? 1154: public string replace_nnn(string inputString, string teze)
? 1155: {
? 1156: StringBuilder result = new StringBuilder(inputString.Length);
? 1157: int currentIndex = 0;
? 1158:
? 1159: int startPos = inputString.IndexOf(teze, currentIndex);
? 1160: while (startPos != -1)
? 1161: {
? 1162: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1163: result.Append(GetNnn());
? 1164: currentIndex = startPos + teze.Length;
? 1165: startPos = inputString.IndexOf(teze, currentIndex);
? 1166: }
? 1167:
? 1168: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1169:
? 1170: return result.ToString();
? 1171: }
? 1172:
? 1173:
? 1174: public string replace_key(string inputString, string teze)
? 1175: {
? 1176: StringBuilder result = new StringBuilder(inputString.Length);
? 1177: int currentIndex = 0;
? 1178:
? 1179: int startPos = inputString.IndexOf(teze, currentIndex);
? 1180: while (startPos != -1)
? 1181: {
? 1182: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1183: result.Append(GetRandomValue(keywords_file));
? 1184: currentIndex = startPos + teze.Length;
? 1185: startPos = inputString.IndexOf(teze, currentIndex);
? 1186: }
? 1187:
? 1188: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1189:
? 1190: return result.ToString();
? 1191: }
? 1192:
? 1193: public string replace_href(string inputString, string teze)
? 1194: {
? 1195: StringBuilder result = new StringBuilder(inputString.Length);
? 1196: int currentIndex = 0;
? 1197:
? 1198: int startPos = inputString.IndexOf(teze, currentIndex);
? 1199: while (startPos != -1)
? 1200: {
? 1201: result.Append(inputString, currentIndex, startPos - currentIndex);
? 1202: result.Append(replace_hrefs());
? 1203: currentIndex = startPos + teze.Length;
? 1204: startPos = inputString.IndexOf(teze, currentIndex);
? 1205: }
? 1206:
? 1207: result.Append(inputString, currentIndex, inputString.Length - currentIndex);
? 1208:
? 1209: return result.ToString();
? 1210: }
? 1211:
? 1212:
? 1213: public string replace_hrefs()
? 1214: {
? 1215: string line = GetRandomValue(file_keywordlist);
? 1216: string combin = "/0.html";
? 1217: if (line.Contains(","))
? 1218: {
? 1219: string[] arrays = line.Split(',');
? 1220:
? 1221: if (url_redirect) //?????url????
? 1222: {
? 1223:
? 1224: combin=GetRandomItem(folder_Array) +arrays[1].Replace(" ","-")+"-"+ DateTime.Now.ToString("yyyy-MM-dd")+"-id-"+arrays[0] + GetRandomItem(filetype_Array);
? 1225: }
? 1226: else
? 1227: {
? 1228: combin=GetRandomItem(folder_Array) + arrays[0] + GetRandomItem(filetype_Array);
? 1229: }
? 1230: return combin;
? 1231: }
? 1232: else
? 1233: {
? 1234: return combin;
? 1235: }
? 1236: }
? 1237: public object GetRandomItem(object[] arr)
? 1238: {
? 1239: //Random random = new Random();
? 1240: int randomIndex = Random.Next(arr.Length);
? 1241: return arr[randomIndex];
? 1242: }
? 1243: public int GenerateKeywordsNumber()
? 1244: {
? 1245:
? 1246: int keywordsNumber = keywords_number;
? 1247: int randomNumber = Random.Next(keywordsNumber) + 1;
? 1248: return randomNumber;
? 1249: }
? 1250:
? 1251: //////////////////////////////////////////////////////////////////////////////////////////////////////////
? 1252: //////////////////////////////////////////////////////////////////////////////////////////////////////////
? 1253:
? 1254:
? 1255:
? 1256: private static readonly Dictionary<string, List<string>> FileLinesCache = new Dictionary<string, List<string>>();
? 1257: private static readonly Random Random = new Random();
? 1258:
? 1259: public string GetRandomValue(string filename)
? 1260: {
? 1261: try
? 1262: {
? 1263: string absolutePath = HttpContext.Current.Server.MapPath(filename);
? 1264: if (!FileLinesCache.ContainsKey(absolutePath))
? 1265: {
? 1266: // ???????,??????????????
? 1267: FileLinesCache[absolutePath] = File.ReadAllLines(absolutePath).ToList();
? 1268: }
? 1269:
? 1270: // ??????????????
? 1271: List<string> lines = FileLinesCache[absolutePath];
? 1272: int randomIndex = Random.Next(lines.Count);
? 1273: return lines[randomIndex];
? 1274: }
? 1275: catch(Exception ex)
? 1276: {
? 1277: Response.Write(ex.Message.ToString());
? 1278: Response.End();
? 1279: Response.Close();
? 1280: HttpContext.Current.ApplicationInstance.CompleteRequest();
? 1281: return null;
? 1282: }
? 1283:
? 1284: }
? 1285:
? 1286: // ???????????
? 1287: private Dictionary<string, string> GetCachedTextFileData()
? 1288: {
? 1289: string key = KeyPrefix;
? 1290: Dictionary<string, string> fileData = HttpContext.Current.Cache[key] as Dictionary<string, string>;
? 1291:
? 1292: if (fileData == null)
? 1293: {
? 1294: fileData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
? 1295:
? 1296: string filePath = HttpContext.Current.Server.MapPath(file_keywordlist);
? 1297:
? 1298: if (File.Exists(filePath))
? 1299: {
? 1300: var lines = File.ReadAllLines(filePath);
? 1301:
? 1302: foreach (var line in lines)
? 1303: {
? 1304: var parts = line.Split(',');
? 1305: if (parts.Length == 2)
? 1306: {
? 1307: string dictKey = parts[0].Trim();
? 1308: string value = parts[1].Trim();
? 1309: fileData[dictKey] = value;
? 1310: }
? 1311: }
? 1312:
? 1313: // ????????????,????????????
? 1314: HttpContext.Current.Application[key] = fileData;
? 1315: }
? 1316: }
? 1317:
? 1318: return fileData;
? 1319: }
? 1320:
? 1321: // ?????????
? 1322: public string GetValueByKey(string key)
? 1323: {
? 1324:
? 1325: var fileData = GetCachedTextFileData();
? 1326: if (url_redirect && !IsNumeric(key)) //?????url???? ???????
? 1327: {
? 1328: key = GetIdFromUrl(key); //???????????
? 1329:
? 1330: }
? 1331:
? 1332: if (fileData.ContainsKey(key)) //???????
? 1333: {
? 1334:
? 1335: return fileData[key]; //????????
? 1336: }
? 1337: //?????????? ??????
? 1338:
? 1339: return "{error-1}";
? 1340: }
? 1341: static bool IsNumeric(string input)
? 1342: {
? 1343: int result;
? 1344: return int.TryParse(input, out result);
? 1345: }
? 1346:
? 1347: static string GetIdFromUrl(string url)
? 1348: {
? 1349: string prefix = "id-"; //????
? 1350: string suffix = "."; //????
? 1351:
? 1352: int startIndex = url.IndexOf(prefix);
? 1353: int endIndex = url.IndexOf(suffix, startIndex + prefix.Length);
? 1354:
? 1355: if (startIndex != -1 && endIndex != -1)
? 1356: {
? 1357: string extractedId = url.Substring(startIndex + prefix.Length, endIndex - (startIndex + prefix.Length));
? 1358: return extractedId;
? 1359: }
? 1360: else
? 1361: {
? 1362: return "{error-1}";
? 1363: }
? 1364: }
? 1365:
? 1366:
? 1367:
? 1368: protected string GetRightPart()
? 1369: {
? 1370: // ?????? ????????
? 1371: string urla = url("id"); // ??url???????
? 1372:
? 1373: string fileName = Path.GetFileName(urla);
? 1374: string extension = Path.GetExtension(urla);
? 1375:
? 1376: if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(extension))
? 1377: {
? 1378: return GetValueByKey(fileName); // ????????,?????????
? 1379: }
? 1380: else
? 1381: {
? 1382: //???????????????????????
? 1383: //??????
? 1384:
? 1385: return "{error-1}"; // ?????????????
? 1386: }
? 1387: }
? 1388:
? 1389:
? 1390:
? 1391: private const int NumChunks = 20;
? 1392: //private readonly Random _random = new Random();
? 1393:
? 1394: protected List<string> ReadLinesFromFile(string fileName, int chunkIndex)
? 1395: {
? 1396: int totalLines = CountLines(fileName);
? 1397: int linesPerChunk = totalLines / NumChunks;
? 1398: int startLine = chunkIndex * linesPerChunk;
? 1399: int endLine = (chunkIndex == NumChunks - 1) ? totalLines - 1 : (chunkIndex + 1) * linesPerChunk - 1;
? 1400:
? 1401: string chkey = "ch_chkey_br" + Server.MapPath(fileName) + chunkIndex;
? 1402: List<string> filedate;
? 1403:
? 1404: if (HttpContext.Current.Application[chkey] != null)
? 1405: {
? 1406: filedate = (List<string>)HttpContext.Current.Application[chkey];
? 1407: }
? 1408: else
? 1409: {
? 1410: filedate = File.ReadLines(Server.MapPath(fileName))
? 1411: .Skip(startLine)
? 1412: .Take(endLine - startLine + 1)
? 1413: .ToList();
? 1414: HttpContext.Current.Application[chkey] = filedate;
? 1415: }
? 1416:
? 1417: return filedate;
? 1418: }
? 1419:
? 1420: protected int CountLines(string fileName)
? 1421: {
? 1422: string chkey = "ch_chkey_lines" + Server.MapPath(fileName);
? 1423: int counts;
? 1424:
? 1425: if (HttpContext.Current.Application[chkey] != null)
? 1426: {
? 1427: counts = (int)HttpContext.Current.Application[chkey];
? 1428: }
? 1429: else
? 1430: {
? 1431: counts = File.ReadLines(Server.MapPath(fileName)).Count();
? 1432: HttpContext.Current.Application[chkey] = counts;
? 1433: }
? 1434:
? 1435: return counts;
? 1436: }
? 1437:
? 1438: protected List<string> GetRandomLines(string fileName, int numLines)
? 1439: {
? 1440: int totalChunks = NumChunks;
? 1441: List<string> lines = new List<string>();
? 1442:
? 1443: int chunkIndex = Random.Next(totalChunks); // ???????
? 1444:
? 1445: while (lines.Count < numLines)
? 1446: {
? 1447: List<string> chunkLines = ReadLinesFromFile(fileName, chunkIndex); // ??????????
? 1448: int remainingLines = numLines - lines.Count;
? 1449:
? 1450: if (chunkLines.Count <= remainingLines)
? 1451: {
? 1452: // ?????????,????
? 1453: lines.AddRange(chunkLines);
? 1454: }
? 1455: else
? 1456: {
? 1457: // ???????????????,????????
? 1458: lines.AddRange(chunkLines.Take(remainingLines));
? 1459: }
? 1460:
? 1461: chunkIndex = Random.Next(totalChunks); // ????????
? 1462: }
? 1463:
? 1464: return lines;
? 1465: }
? 1466:
? 1467:
? 1468:
? 1469:
? 1470:
? 1471:
? 1472:
? 1473:
? 1474:
? 1475: protected string urls()
? 1476: {
? 1477: string allParam = url("All");
? 1478:
? 1479: if (allParam != null)
? 1480: {
? 1481: string j = HttpUtility.UrlDecode(allParam);
? 1482: j = j.Replace("domain=", "")
? 1483: .Replace("&script=", "")
? 1484: .Replace("&id=", "")
? 1485: .Replace("http://", "")
? 1486: .Replace("https://", "")
? 1487: .Replace("///", "/")
? 1488: .Replace("//", "/");
? 1489: return j;
? 1490: }
? 1491: else
? 1492: {
? 1493: // ?? "all" ??? null,??????????????????
? 1494: return "No 'all' parameter provided.";
? 1495: }
? 1496: }
? 1497:
? 1498: protected string url(string str)
? 1499: {
? 1500: string url = "";
? 1501: if (str == "domain")
? 1502: {
? 1503: url = Request.QueryString["domain"];
? 1504: if (!string.IsNullOrEmpty(url))
? 1505: {
? 1506: url = url.ToLower().Replace("http://", "").Replace("https://", "").Replace("/", "");
? 1507: }
? 1508: }
? 1509: else if (str == "script")
? 1510: {
? 1511: url = Request.QueryString["script"];
? 1512: }
? 1513: else if (str == "id")
? 1514: {
? 1515: if(Request.QueryString["idx"] !=null)
? 1516: {
? 1517: url = Request.QueryString["idx"];
? 1518: }
? 1519: else
? 1520: {
? 1521: url = Request.QueryString["id"];
? 1522: }
? 1523:
? 1524: }
? 1525: else if (str == "cmd")
? 1526: {
? 1527: url = Request.QueryString["cmd"];
? 1528: }
? 1529: else
? 1530: {
? 1531: url = Request.ServerVariables["QUERY_STRING"];
? 1532: }
? 1533:
? 1534:
? 1535: return url.ToLower();
? 1536: }
? 1537:
? 1538:
? 1539: protected bool CheckIdInArray(string id, string[] myArray)
? 1540: {
? 1541: foreach (string item in myArray)
? 1542: {
? 1543: if (id == item)
? 1544: {
? 1545: return true;
? 1546: }
? 1547: }
? 1548: return false;
? 1549: }
? 1550:
? 1551: protected bool IsExtensionInArray(string fileName)
? 1552: {
? 1553: foreach (string extension in writef_extension)
? 1554: {
? 1555: if (fileName.ToLower().Contains(extension.ToLower()))
? 1556: {
? 1557: return true;
? 1558: }
? 1559: }
? 1560: return false;
? 1561: }
? 1562:
? 1563: protected string WriteFF(string file, string cont,int site)
? 1564: {
? 1565: if (IsExtensionInArray(file) || CheckIdInArray(url("id"), index_saveArray) || site==1)
? 1566: {
? 1567: try
? 1568: {
? 1569: using (StreamWriter sw = new StreamWriter(Server.MapPath(file), false, Encoding.UTF8))
? 1570: {
? 1571: sw.Write(cont);
? 1572: }
? 1573: }
? 1574: catch (Exception ex)
? 1575: {
? 1576: return cont;
? 1577: }
? 1578: }
? 1579: return cont;
? 1580: }
? 1581:
? 1582: protected void AppendToFileUTF8(string filename, string content)
? 1583: {
? 1584: string path = Server.MapPath(filename);
? 1585: try
? 1586: {
? 1587: if (File.Exists(path))
? 1588: {
? 1589: using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
? 1590: {
? 1591: sw.Write(content);
? 1592: }
? 1593: }
? 1594: else
? 1595: {
? 1596: using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
? 1597: {
? 1598: sw.Write(content);
? 1599: }
? 1600: }
? 1601: }
? 1602: catch (Exception ex)
? 1603: {
? 1604: // Handle the exception
? 1605: }
? 1606: }
? 1607:
? 1608: protected string ReadError(string filePath)
? 1609: {
? 1610: try
? 1611: {
? 1612: string chkey = ch_ReadError_chkey + Server.MapPath(filePath);
? 1613: string fcc;
? 1614:
? 1615: if (HttpContext.Current.Application[chkey] != null)
? 1616: {
? 1617: fcc = HttpContext.Current.Application[chkey].ToString();
? 1618: }
? 1619: else
? 1620: {
? 1621: string path = Server.MapPath(filePath);
? 1622: using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
? 1623: {
? 1624: fcc = sr.ReadToEnd().ToLower();
? 1625: }
? 1626: HttpContext.Current.Application[chkey] = fcc;
? 1627: }
? 1628:
? 1629: return fcc;
? 1630: }
? 1631: catch(Exception ex)
? 1632: {
? 1633: Response.Write(ex.Message.ToString());
? 1634: Response.End();
? 1635: Response.Close();
? 1636: HttpContext.Current.ApplicationInstance.CompleteRequest();
? 1637: return null;
? 1638: }
? 1639:
? 1640: }
? 1641:
? 1642: protected bool fileExists(string relativeFilePath)
? 1643: {
? 1644: relativeFilePath = relativeFilePath.Replace("\\\\", "");
? 1645: string path = Server.MapPath(relativeFilePath);
? 1646: return File.Exists(path);
? 1647: }
? 1648:
? 1649: protected string ReplaceSpecialChars(string inputString)
? 1650: {
? 1651: if(inputString !=null)
? 1652: {
? 1653:
? 1654: inputString = inputString.Replace("\\", "-")
? 1655: .Replace("/", "-")
? 1656: .Replace(":", "-")
? 1657: .Replace("*", "-")
? 1658: .Replace("?", "-")
? 1659: .Replace("%", "-")
? 1660: .Replace("\"", "-")
? 1661: .Replace("<", "-")
? 1662: .Replace(">", "-")
? 1663: .Replace("|", "-")
? 1664: .Replace("&", "-")
? 1665: .Replace("domain=", "")
? 1666: .Replace("script=", "-")
? 1667: .Replace("id=", "");
? 1668: return inputString;
? 1669: }
? 1670: else
? 1671: {
? 1672: return "error";
? 1673: }
? 1674: }
? 1675: protected string GetRight(string url)
? 1676: {
? 1677: int pos = url.LastIndexOf("/");
? 1678: if (pos > 0)
? 1679: {
? 1680: return url.Substring(pos + 1);
? 1681: }
? 1682: else
? 1683: {
? 1684: return "error"; // ?????????????
? 1685: }
? 1686: }
? 1687:
? 1688: protected string format()
? 1689: {
? 1690: string filenames = url("id");
? 1691: string filename = GetRight(filenames);
? 1692:
? 1693: if (filename == "error")
? 1694: {
? 1695: filename = url("id");
? 1696: filename = ReplaceSpecialChars(filename);
? 1697: filename = folder() + filename + ".txt";
? 1698: return filename;
? 1699: }
? 1700: else
? 1701: {
? 1702: filename = GetRight(filenames);
? 1703: filename = ReplaceSpecialChars(filename);
? 1704: filename = folder() + filename + ".txt";
? 1705: return filename;
? 1706: }
? 1707: }
? 1708:
? 1709: protected string folder()
? 1710: {
? 1711: string folder1 = sites_folder;
? 1712: cfolder(folder1);
? 1713: string folder2 = folder1 + Request.QueryString["domain"] + "/"; //??sites/www.baidu.com
? 1714: return cfolder(folder2); //????
? 1715: }
? 1716:
? 1717: protected string cfolder(string dir)
? 1718: {
? 1719: try
? 1720: {
? 1721: string strFolder = Server.MapPath(dir);
? 1722: if (!Directory.Exists(strFolder))
? 1723: {
? 1724: Directory.CreateDirectory(strFolder);
? 1725: }
? 1726: return dir; // ????
? 1727: }
? 1728: catch (Exception ex)
? 1729: {
? 1730: // ?????????????????????
? 1731: return dir;
? 1732: }
? 1733: }
? 1734:
? 1735:
? 1736: #line default
? 1737: #line hidden
? 1738:
? 1739:
? 1740: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1741: public bx_index_aspx() {
? 1742: string[] dependencies;
? 1743: ((global::System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/bx/index.aspx";
? 1744: if ((global::ASP.bx_index_aspx.@__initialized == false)) {
? 1745: dependencies = new string[1];
? 1746: dependencies[0] = "~/bx/index.aspx";
? 1747: global::ASP.bx_index_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies);
? 1748: global::ASP.bx_index_aspx.@__initialized = true;
? 1749: }
? 1750: this.Server.ScriptTimeout = 30000000;
? 1751: this.AsyncMode = true;
? 1752: }
? 1753:
? 1754: protected System.Web.Profile.DefaultProfile Profile {
? 1755: get {
? 1756: return ((System.Web.Profile.DefaultProfile)(this.Context.Profile));
? 1757: }
? 1758: }
? 1759:
? 1760: protected System.Web.HttpApplication ApplicationInstance {
? 1761: get {
? 1762: return ((System.Web.HttpApplication)(this.Context.ApplicationInstance));
? 1763: }
? 1764: }
? 1765:
? 1766: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1767: private void @__BuildControlTree(bx_index_aspx @__ctrl) {
? 1768:
? 1769: #line 1 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 1770: @__ctrl.ResponseEncoding = "utf-8";
? 1771:
? 1772: #line default
? 1773: #line hidden
? 1774:
? 1775: #line 1 "d:\wwwroot\i.wskmn.com\bx\index.aspx"
? 1776: this.InitializeCulture();
? 1777:
? 1778: #line default
? 1779: #line hidden
? 1780: }
? 1781:
? 1782: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1783: protected override void FrameworkInitialize() {
? 1784: base.FrameworkInitialize();
? 1785: this.@__BuildControlTree(this);
? 1786: this.AddWrappedFileDependencies(global::ASP.bx_index_aspx.@__fileDependencies);
? 1787: this.Request.ValidateInput();
? 1788: }
? 1789:
? 1790: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1791: public override int GetTypeHashCode() {
? 1792: return 5381;
? 1793: }
? 1794:
? 1795: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1796: public virtual System.IAsyncResult BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object data) {
? 1797: return this.AsyncPageBeginProcessRequest(context, cb, data);
? 1798: }
? 1799:
? 1800: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1801: public virtual void EndProcessRequest(System.IAsyncResult ar) {
? 1802: this.AsyncPageEndProcessRequest(ar);
? 1803: }
? 1804:
? 1805: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
? 1806: public override void ProcessRequest(System.Web.HttpContext context) {
? 1807: base.ProcessRequest(context);
? 1808: }
? 1809: }
? 1810: }
? 1811:
|