-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleHelper.cs
64 lines (51 loc) · 1.75 KB
/
ModuleHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.IO;
namespace dumptrack
{
public class ModuleHelper
{
public ModuleHelper ()
{
}
public static bool HasProcessedUrl(string url){
if (!File.Exists (Config.getInstance().ProcessedUrlsPath)) {
File.Create (Config.getInstance().ProcessedUrlsPath);
//Little delay otherwise locks the next read on mono which is weird but hey
System.Threading.Thread.Sleep (2000);
}
string data = "";
using (StreamReader reader = new StreamReader (Config.getInstance().ProcessedUrlsPath)) {
data = reader.ReadToEnd ();
}
return data.IndexOf (url) != -1;
}
public static bool IsViolation(string url, string offence){
string fixedUrl = url.StartsWith ("http") ? url : "http://" + url;
string urlData = new WebUtilities (Config.getInstance().EnableProxy).GetResponse (fixedUrl, true);
if (urlData != null && urlData.Length > 0) {
SaveData (url, urlData, offence);
return urlData.IndexOf (offence) > -1;
}
return false;
}
public static void MarkUrlAsProcessed(string url){
using (StreamWriter writer = new StreamWriter (Config.getInstance().ProcessedUrlsPath,true)) {
writer.WriteLine (url);
writer.Close ();
}
}
public static void SaveData (string url, string urlData, string offence){
using (StreamWriter writer = new StreamWriter("dumps-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt",true)){
writer.WriteLine(offence + ":" + url);
writer.WriteLine(urlData);
}
}
public static void ReportViolation(string url, string offence){
string filename = "offencelist-" + DateTime.Now.ToString ("yyyy-MM-dd") + ".txt";
using (StreamWriter writer = new StreamWriter (filename,true)) {
writer.WriteLine (offence + ":" + url);
writer.Close ();
}
}
}
}