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