Exemple #1
0
        private string GetBrowsCap()
        {
            string jsonpath = localappdata + "\\logextractor\\browscap.json";

            if (File.Exists(jsonpath))
            {
                try
                {
                    string json = File.ReadAllText(jsonpath);
                    return(json);
                }
                catch (Exception e) {
                    MessageBag msgbag = new MessageBag();
                    msgbag.AddError(e.Message);
                    msgbag.PrintErrors();
                }
                return(null);
            }
            else
            {
                if (!local_access)
                {
                    return(null);
                }

                try
                {
                    HttpClient client = new HttpClient();
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    var response = client.GetAsync("https://10.19.214.112/browscap.json").Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string json = response.Content.ReadAsStringAsync().Result;
                        if (json != null)
                        {
                            DirectoryInfo dir = Directory.CreateDirectory(localappdata + "\\logextractor");
                            if (dir.Exists)
                            {
                                File.AppendAllText(jsonpath, json);
                                return(json);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBag msgbag = new MessageBag();
                    msgbag.AddError(e.Message);
                    msgbag.PrintErrors();
                }
                return(null);
            }
        }
Exemple #2
0
 public void LogLine(string line)
 {
     try
     {
         File.AppendAllText(logpath, line + Environment.NewLine);
     }
     catch (Exception e)
     {
         MessageBag msgbag = new MessageBag();
         msgbag.AddError(e.Message);
         msgbag.PrintErrors();
     }
 }
Exemple #3
0
 public Conf(string[] args)
 {
     local_access = CanPing("10.19.214.112");
     foreach (string arg in args)
     {
         if (arg.StartsWith("/"))
         {
             if (arg == "/a" || arg == "/arin")
             {
                 if (!local_access)
                 {
                     new MessageBag("error", "Unable to access Geo Server").PrintErrors();
                 }
                 arin = true;
             }
             else if (arg == "/b" || arg == "/browser")
             {
                 browser = true;
             }
             else if (arg == "/c" || arg == "/count")
             {
                 count = true;
             }
             else if (arg == "/d" || arg == "/distinct")
             {
                 distinct = true;
             }
             else if (arg == "/e" || arg == "/external")
             {
                 external = true;
             }
             else if (arg == "/f" || arg == "/flagged")
             {
                 flagged = true;
             }
             else if (arg == "/g" || arg == "/geoip")
             {
                 if (local_access)
                 {
                     geoip = true;
                 }
                 else
                 {
                     messageBag.AddError("Geo IP server at 10.19.214.112 is not reachable");
                 }
             }
             else if (arg == "/i" || arg == "/ignore")
             {
                 ignore_filedate = true;
             }
             else if (arg == "/n" || arg == "/nonc")
             {
                 no_nc = true;
             }
             else if (arg == "/o")
             {
                 outofarin = true;
             }
             else if (arg == "/p")
             {
                 onlyarin = true;
             }
             else if (arg == "/q" || arg == "/quiet")
             {
                 quiet = true;
             }
             else if (arg == "/r" || arg == "/request")
             {
                 request = true;
             }
             else if (arg == "/ts" || arg == "/timestamps")
             {
                 ts = true;
             }
             else if (arg == "/u" || arg == "/agent")
             {
                 useragent = true;
             }
             else if (arg == "/w" || arg == "/nowsvc")
             {
                 no_wsvc = true;
             }
             else if (arg == "/?" || arg == "/help")
             {
                 wantshelp = true;
             }
             else if (arg == "/foreign")
             {
                 if (local_access)
                 {
                     foreign  = true;
                     geoip    = true;
                     external = true;
                     no_nc    = true;
                 }
                 else
                 {
                     messageBag.AddError("Geo IP server at 10.19.214.112 is not reachable");
                 }
             }
             else if (Regex.IsMatch(arg, regex_outfilename))
             {
                 string outpath = Regex.Replace(arg, regex_outfilename, "");
                 if (outfilename != null)
                 {
                     messageBag.AddError("Only one outfile may be specfied");
                 }
                 else
                 {
                     outfilename = outpath;
                 }
             }
             else if (Regex.IsMatch(arg, regex_datebefore))
             {
                 if (before_date != null)
                 {
                     messageBag.AddError("Only one before date may be specfied");
                 }
                 else
                 {
                     string datestring = Regex.Replace(arg, regex_datebefore, "").Replace("\"", "").Trim();
                     if (Regex.IsMatch(datestring, @"[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}"))
                     {
                         DateTime bdate;
                         if (DateTime.TryParse(datestring, out bdate))
                         {
                             before_date = bdate;
                             ts          = true;
                         }
                         else
                         {
                             messageBag.AddError("Invalid Date");
                         }
                     }
                     else
                     {
                         messageBag.AddError("Invalid Before Date. Try format mm/dd/yyyy");
                     }
                 }
             }
             else if (Regex.IsMatch(arg, regex_dateafter))
             {
                 if (after_date != null)
                 {
                     messageBag.AddError("Only one after date may be specfied");
                 }
                 else
                 {
                     string datestring = Regex.Replace(arg, regex_dateafter, "").Replace("\"", "").Trim();
                     if (Regex.IsMatch(datestring, @"[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}"))
                     {
                         DateTime adate;
                         if (DateTime.TryParse(datestring, out adate))
                         {
                             after_date = adate;
                             ts         = true;
                         }
                         else
                         {
                             messageBag.AddError("Invalid Date");
                         }
                     }
                     else
                     {
                         messageBag.AddError("Invalid After Date. Try format mm/dd/yyyy");
                     }
                 }
             }
             else if (Regex.IsMatch(arg, regex_ip))
             {
                 if (ip != null)
                 {
                     messageBag.AddError("Only one IP filter may be specfied");
                 }
                 else
                 {
                     string ipstring = Regex.Replace(arg, regex_ip, "").Replace("\"", "").Trim();
                     if (Regex.IsMatch(ipstring, @"^\d{1,3}(\.\d{1,3}){1,3}$"))
                     {
                         ip = ipstring;
                     }
                     else
                     {
                         messageBag.AddError("Invalid IP Format.");
                     }
                 }
             }
             else if (Regex.IsMatch(arg, regex_exclude))
             {
                 if (ip_exclude != null)
                 {
                     messageBag.AddError("Only one excluded IP may be specfied");
                 }
                 else
                 {
                     string ipstring = Regex.Replace(arg, regex_exclude, "").Replace("\"", "").Trim();
                     if (Regex.IsMatch(ipstring, @"^\d{1,3}(\.\d{1,3}){1,3}$"))
                     {
                         ip_exclude = ipstring;
                     }
                     else
                     {
                         messageBag.AddError("Invalid Exclude IP Format.");
                     }
                 }
             }
             else if (Regex.IsMatch(arg, regex_status_code))
             {
                 if (status_code != null)
                 {
                     messageBag.AddError("Only one HTTP Status Code may be specified");
                 }
                 else
                 {
                     string status_code_string = Regex.Replace(arg, regex_status_code, "").Replace("\"", "").Trim();
                     if (Regex.IsMatch(status_code_string, @"^(2|3|4|5)(\d{1,2})?$"))
                     {
                         status_code = status_code_string;
                     }
                     else
                     {
                         messageBag.AddError("Invalid status code.");
                     }
                 }
             }
             else if (Regex.IsMatch(arg, regex_request))
             {
                 if (request_pattern != null)
                 {
                     messageBag.AddError("Only one request pattern may be specified");
                 }
                 else
                 {
                     request         = true;
                     request_pattern = Regex.Replace(arg, regex_request, "").Replace("\"", "").Trim();
                     try
                     {
                         bool testpattern = Regex.IsMatch("randomstring", request_pattern);
                     }
                     catch
                     {
                         messageBag.AddError("Invalid pattern: " + request_pattern);
                     }
                 }
             }
             else
             {
                 messageBag.AddError("Invalid Option: " + arg);
             }
         }
         else
         {
             string p = arg.Trim();
             if (p.EndsWith(".txt") || p.EndsWith(".log"))
             {
                 if (!infiles.Contains(p))
                 {
                     infiles.Add(p);
                 }
             }
             else
             {
                 if (Directory.Exists(p))
                 {
                     string[] files = Directory.GetFiles(p);
                     foreach (string file in files)
                     {
                         if (file.EndsWith(".txt") || file.EndsWith(".log"))
                         {
                             if (!infiles.Contains(file))
                             {
                                 infiles.Add(file);
                             }
                         }
                     }
                 }
                 else
                 {
                     messageBag.AddError("Log file not found: '" + p + "'");
                 }
             }
         }
     }
 }