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