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