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