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