Esempio n. 1
0
        public static string CreateTableFromDatabase(ManagementObjectCollection results, List <string> keys, List <string> names, string errorMessage)
        {
            if (SCCM.HasValues(results))
            {
                HTMLTableHelper tableHelper = new HTMLTableHelper(names.ToArray());

                foreach (ManagementObject o in results) //Has one!
                {
                    List <string> properties = new List <string>();
                    foreach (var p in keys)
                    {
                        string temp = o.Properties[p].Value.ToString();
                        if (o.Properties[p].Type.ToString() == "DateTime")
                        {
                            temp = DateTimeConverter.Convert(temp);
                        }
                        properties.Add(temp);
                    }
                    tableHelper.AddRow(properties.ToArray());
                }

                return(tableHelper.GetTable());
            }
            else
            {
                return(errorMessage);
            }
        }
Esempio n. 2
0
        public static string CreateVerticalTableFromDatabase(ManagementObjectCollection results, List <string> keys, List <string> names, string errorMessage)
        {
            HTMLTableHelper tableHelper = new HTMLTableHelper(2);
            var             sb          = new StringBuilder();

            if (SCCM.HasValues(results))
            {
                int i = 0;
                var o = results.OfType <ManagementObject>().FirstOrDefault();

                foreach (var p in keys)
                {
                    var property = o.Properties[p];
                    if (o.Properties[p].Value == null)
                    {
                        tableHelper.AddRow(new string[] { names[i], "not found" });
                    }
                    else if (o.Properties[p].Name == "Size" || o.Properties[p].Name == "FreeSpace")
                    {
                        tableHelper.AddRow(new string[] { names[i], (int.Parse(o.Properties[p].Value.ToString()) / 1024).ToString() });
                    }
                    else if (property.Type.ToString() == "DateTime")
                    {
                        tableHelper.AddRow(new string[] { names[i], DateTimeConverter.Convert(o.Properties[p].Value.ToString()) });
                    }
                    else
                    {
                        tableHelper.AddRow(new string[] { names[i], o.Properties[p].Value.ToString() });
                    }
                    i++;
                }
            }
            else
            {
                return(errorMessage);
            }

            return(tableHelper.GetTable());
        }
Esempio n. 3
0
        private static StringBuilder PrintTableOfCases(object jsonO, Func <string, bool> filter)
        {
            dynamic json   = jsonO;
            var     helper = new HTMLTableHelper(new string[] { "ID", "Title", "Status", "Last Change" });


            for (int i = 0; i < json["MyRequest"].Count; i++)
            {
                var temp = json["MyRequest"][i];
                var name = json["MyRequest"][i]["Status"]["Name"];
                if (filter(json["MyRequest"][i]["Status"]["Name"].Value))
                {
                    string id = json["MyRequest"][i]["Id"].Value;
                    string link;
                    if (id.StartsWith("IR"))
                    {
                        link = "https://service.aau.dk/Incident/Edit/" + id;

                        //Filter away if its closed as converted to SR
                        if ((idForConvertedToSR.Equals(json["MyRequest"][i]["ResolutionCategory"]["Id"].Value)))
                        {
                            continue;
                        }
                    }
                    else //if (id.StartsWith("SR"))
                    {
                        link = "https://service.aau.dk/ServiceRequest/Edit/" + id;
                    }
                    string   sID         = "<a href=\"" + link + "\" target=\"_blank\">" + json["MyRequest"][i]["Id"].Value + "</a><br/>";
                    string   sTitle      = json["MyRequest"][i]["Title"].Value;
                    string   sStatus     = json["MyRequest"][i]["Status"]["Name"].Value;
                    DateTime tmp         = json["MyRequest"][i]["LastModified"].Value;
                    string   sLastChange = Convert.ToDateTime(tmp).ToString("yyyy-MM-dd HH:mm");

                    helper.AddRow(new String[] { sID, sTitle, sStatus, sLastChange });
                }
            }


            return(new StringBuilder(helper.GetTable()));
        }
Esempio n. 4
0
        //Returns a html table displaying loginscript data and raw data parition
        public string parseAndDisplayLoginScript(string loginscript)
        {
            var sb = new StringBuilder();

            var lines = loginscript.Split('\n');

            //Remote comment
            var linesNetUse          = lines.Where <string>(s => s.StartsWith("net use", StringComparison.CurrentCultureIgnoreCase)).ToArray <string>();
            var linesNetUseNotDelete = linesNetUse.Where <string>(s => !s.ToLower().Contains(" /d")).ToArray <string>();

            var table = new HTMLTableHelper(new string[] { "Drive Letter", "share" });

            sb.Append("<h3>Networkdrives</h3>");;

            foreach (string line in linesNetUseNotDelete)
            {
                //net use S: \\adm.aau.dk\Fileshares\DRIFTSDB

                Regex pattern = new Regex(@"net use (?<drive>.): (?<share>.*)");
                Match match   = pattern.Match(line.ToLower());

                string drive = match.Groups["drive"].Value;
                string share = match.Groups["share"].Value;

                table.AddRow(new string[] { drive, share });
            }

            sb.Append(table.GetTable());
            sb.Append("<h3>Raw<h3>");
            foreach (string line in lines)
            {
                sb.Append(String.Format("<code>{0}</code><br/>", line.Replace("\r", "")));
            }

            return(sb.ToString());
        }
Esempio n. 5
0
        public static void createGroupTableRows(List <string> adpaths, HTMLTableHelper groupTableHelper, string accessName = null)
        {
            foreach (string adpath in adpaths)
            {
                var split  = adpath.Split(',');
                var name   = split[0].Replace("CN=", "");
                var domain = split.Where <string>(s => s.StartsWith("DC=")).ToArray <string>()[0].Replace("DC=", "");
                var link   = name;
                var type   = "unknown";
                if (!adpath.Contains("OU"))
                {
                    type = "unknown";
                }
                else if (adpath.Contains("OU=Groups"))
                {
                    link = getGroupLink(adpath, name);
                    type = "Group";
                }
                else if (adpath.Contains("OU=Admin Groups"))
                {
                    link = getGroupLink(adpath, name);
                    type = "Admin group";
                }
                else if (adpath.Contains("OU=People"))
                {
                    link = getPersonLink(domain, name);
                    type = "Person";
                }
                else if (adpath.Contains("OU=Admin Identities"))
                {
                    link = getPersonLink(domain, name);
                    type = "Admin identity";
                }
                else if (adpath.Contains("OU=Admin"))
                {
                    type = "Admin (Server?)";
                }
                else if (adpath.Contains("OU=Server"))
                {
                    type = "Server";
                }
                else if (adpath.Contains("OU=Microsoft Exchange Security Groups"))
                {
                    link = getGroupLink(adpath, name);
                    type = "Microsoft Exchange Security Groups";
                }
                else
                {
                    type = "Special, find it in adpath";
                    Console.WriteLine();
                }

                if (accessName == null) //Is not fileshare
                {
                    groupTableHelper.AddRow(new string[] { domain, link });
                }
                else
                {
                    groupTableHelper.AddRow(new string[] { link, type, accessName });
                }
            }
        }
Esempio n. 6
0
        public static Tuple <string, string> CreateTableAndRawFromDatabase(ManagementObjectCollection results, List <string> keys, string errorMessage)
        {
            HTMLTableHelper tableHelper = new HTMLTableHelper(2);
            var             sb          = new StringBuilder();

            if (SCCM.HasValues(results))
            {
                foreach (ManagementObject o in results) //Has one!
                {
                    //OperatingSystemNameandVersion = Microsoft Windows NT Workstation 6.1

                    foreach (var property in o.Properties)
                    {
                        string key   = property.Name;
                        object value = property.Value;

                        if (keys.Contains(key))
                        {
                            if (value != null)
                            {
                                if (value.GetType().Equals(typeof(string[])))
                                {
                                    string joinedValues = string.Join(", ", (string[])value);
                                    tableHelper.AddRow(new string[] { key, joinedValues });
                                }
                                else if (property.Type.ToString() == "DateTime")
                                {
                                    tableHelper.AddRow(new string[] { key, DateTimeConverter.Convert(value.ToString()) });
                                }
                                else
                                {
                                    tableHelper.AddRow(new string[] { key, value.ToString() });
                                }
                            }
                            else
                            {
                                tableHelper.AddRow(new string[] { key, "" });
                            }
                        }

                        int      i    = 0;
                        string[] arry = null;
                        if (value != null && value.GetType().IsArray)
                        {
                            if (value is string[])
                            {
                                arry = (string[])value;
                            }
                            else
                            {
                                arry = new string[] { "none-string value" }; //XXX get the byte value
                            }
                            foreach (string f in arry)
                            {
                                sb.Append(string.Format("{0}[{2}]: {1}<br />", key, f, i));
                                i++;
                            }
                        }
                        else
                        {
                            sb.Append(string.Format("{0}: {1}<br />", key, property.Value));
                        }
                    }
                }
            }
            else
            {
                sb.Append(errorMessage);
            }

            return(Tuple.Create(tableHelper.GetTable(), sb.ToString()));
        }