Example #1
0
 public static ResultsController Get()
 {
     if (instance is null)
     {
         instance = new ResultsController();
     }
     return(instance);
 }
        public IEnumerable <ResultsController.Result> Get()
        {
            FileController.Get().AnalyzeFile();

            return(ResultsController.Get().results);
        }
        private void ParseLine(String line)
        {
            // ignore string starting with "#" unless it is #Fields (else branch always gets executed first)
            if (line.StartsWith("#") == false)
            {
                // tokenize the line
                List <string> tokens = line.Split(' ').ToList <string>();

                string currIP = "", currFQDN = "";

                // we should already know our important param position in the string, so we try to parse it
                foreach (IIS_Parameter importantParam in importantParams)
                {
                    string content = tokens[importantParam.logOrder];
                    // update results (= num of calls for this ip, fqdn)
                    if (importantParam.paramType == IIS_Parameters.ClientIP)
                    {
                        if (importantParam.IsParseable(content))
                        {
                            currIP = content; // save it to map in the dict
                        }
                        else
                        {
                            // content isnt parseable, so it isnt what we expected to be (ie. it isnt an IP address)
                            Console.WriteLine("ERROR: param " + importantParam.paramType + " content is not parseable");
                            // are these things errors ? like "::1%0" what even are these
                            currIP   = "ANOMALY: " + content;
                            currFQDN = "is this an error?";
                        }
                    }
                    else
                    {
                        if ((importantParam.paramType == IIS_Parameters.Username) && (content != "-"))
                        {
                            if (importantParam.IsParseable(content))
                            {
                                currFQDN = content; // save it to map in the dict
                            }
                        }

                        // other important params go here, maybe use a switch case
                    }

                    // overwrite param last content
                    //if (importantParam.lastContent.Equals(content) == false)
                    //    importantParam.lastContent = content; // unused but may be useful
                }


                ResultsController.Get().UpdateResults(currIP, currFQDN);
            }

            else
            {
                // we can use this line to establish the param order, so that we know exatcly "where" to find the param we need ( = which token number)
                if (line.StartsWith("#Fields:"))
                {
                    importantParams.Clear();

                    List <string> fields = line.Split(' ').ToList <string>();

                    foreach (string field in fields)
                    {
                        IIS_Parameter token = ParameterFactory.Get().CreateParameter(field);
                        if (token != null)
                        {
                            token.logOrder = fields.IndexOf(field) - 1; // -1 bc of "#Fields:"
                            importantParams.Add(token);
                        }
                    }
                }
            }
        }