Exemple #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);
            }
        }
Exemple #2
0
        private static string CreateGroupTable(List <string> group)
        {
            HTMLTableHelper groupTableHelper = new HTMLTableHelper(new string[] { "Domain", "Name" });

            createGroupTableRows(group, groupTableHelper, null);

            return(groupTableHelper.GetTable());
        }
        public string[] GetFileshareTables()
        {
            //TODO Things to show in basic info: Type fileshare/department and Domain plan/its/adm

            HTMLTableHelper[] groupTableHelper = new HTMLTableHelper[4];
            for (int i = 0; i < 4; i++)
            {
                groupTableHelper[i] = new HTMLTableHelper(new string[] { "Name", "Type", "Access" });
            }

            List <string> accessNames = new List <string> {
                "Full", "Modify", "Read", "Edit", "Contribute"
            };

            foreach (string accessName in accessNames)
            {
                string  temp  = Regex.Replace(Group.adpath, @"_[a-zA-Z]*,OU", $"_{accessName},OU");
                ADcache group = null;
                try
                {
                    group = new GroupADcache(temp);
                }
                catch (Exception)
                {
                }

                if (group != null)
                {
                    List <string>[] adpaths = new List <string>[] { group.getGroups("member"), group.getGroupsTransitive("member"), group.getGroups("memberOf"), group.getGroupsTransitive("memberOf") };
                    for (int i = 0; i < 4; i++)
                    {
                        TableGenerator.createGroupTableRows(adpaths[i], groupTableHelper[i], accessName);
                    }
                }
            }

            return(new string[] {
                groupTableHelper[0].GetTable(),
                groupTableHelper[1].GetTable(),
                groupTableHelper[2].GetTable(),
                groupTableHelper[3].GetTable()
            });
        }
Exemple #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(2);

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

            sb.Append(table.printStart());
            sb.Append(table.printRow(new string[] { "Drive Letter", "share" }, true));

            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;

                sb.Append(table.printRow(new string[] { drive, share }, true));

            }

            sb.Append(table.printEnd());

            sb.Append("<h3>Raw<h3>");
            foreach (string line in lines)
            {

                sb.Append(String.Format("<code>{0}</code><br/>", line.Replace("\r", "")));

            }

            return sb.ToString();
        }
        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()));
        }
Exemple #6
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());
        }
Exemple #7
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());
        }
Exemple #8
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 });
                }
            }
        }
Exemple #9
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()));
        }
Exemple #10
0
        protected string doAction(string userjson)
        {
            //Print the user info! 
            var sb = new StringBuilder();

            if (userjson == null)
            {
                sb.Append("User not found i SCSM");
                return sb.ToString();
            }

            JavaScriptSerializer js = new JavaScriptSerializer();
            js.MaxJsonLength = Int32.MaxValue;
            dynamic json = js.Deserialize<dynamic>(userjson);

            sb.Append("<br /><br />" + string.Format("<a href=\"{0}{1}\">Servie Portal User Info</a>", "https://service.aau.dk/user/UserRelatedInfoById/", userID) + "<br/>");


            sb.Append("<h1>Open Requests</h1><br />");

            var helper = new HTMLTableHelper(4);
            sb.Append(helper.printStart());
            sb.Append(helper.printRow(new string[] { "ID", "Title", "Status", "Last Change" }, true));

            for (int i = 0; i < json["MyRequest"].Length; i++)
            {
                if (!"Closed".Equals(json["MyRequest"][i]["Status"]["Name"]))
                {
                    string id = json["MyRequest"][i]["Id"];
                    string link;
                    if (id.StartsWith("IR"))
                    {
                        link = "https://service.aau.dk/Incident/Edit/" + id;
                    }
                    else //if (id.StartsWith("SR"))
                    {
                        link = "https://service.aau.dk/ServiceRequest/Edit/" + id;
                    }
                    string sID = "<a href=\"" + link + "\" target=\"_blank\">" + json["MyRequest"][i]["Id"] + "</a><br/>";
                    string sTitle = json["MyRequest"][i]["Title"];
                    string sStatus = json["MyRequest"][i]["Status"]["Name"];
                    string tmp = json["MyRequest"][i]["LastModified"];
                    string sLastChange = Convert.ToDateTime(tmp).ToString();

                    sb.Append(helper.printRow(new String[] { sID, sTitle, sStatus, sLastChange }));
                    //sb.Append("<a href=\"" + link + "\" target=\"_blank\">" + json["MyRequest"][i]["Id"] + " - " + json["MyRequest"][i]["Title"] + " - " + json["MyRequest"][i]["Status"]["Name"] + "</a><br/>");
                }
            }
            sb.Append(helper.printEnd());

            sb.Append("<br /><br /><h3>Closed Requests</h3>");
            sb.Append(helper.printStart());
            sb.Append(helper.printRow(new string[] { "ID", "Title", "Status", "Last Change" }, true));


            for (int i = 0; i < json["MyRequest"].Length; i++)
            {
                if ("Closed".Equals(json["MyRequest"][i]["Status"]["Name"]))
                {
                    string id = json["MyRequest"][i]["Id"];
                    string link;
                    if (id.StartsWith("IR"))
                    {
                        link = "https://service.aau.dk/Incident/Edit/" + id;
                    }
                    else //if (id.StartsWith("SR"))
                    {
                        link = "https://service.aau.dk/ServiceRequest/Edit/" + id;
                    }
                    string sID = "<a href=\"" + link + "\" target=\"_blank\">" + json["MyRequest"][i]["Id"] + "</a><br/>";
                    string sTitle = json["MyRequest"][i]["Title"];
                    string sStatus = json["MyRequest"][i]["Status"]["Name"];
                    string tmp = json["MyRequest"][i]["LastModified"];
                    string sLastChange = Convert.ToDateTime(tmp).ToString();

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

            sb.Append(helper.printEnd());


            //sb.Append("<br /><br/>IsAssignedToUser<br />");
            //foreach (dynamic s in json["IsAssignedToUser"])
            //for (int i = 0; i < json["IsAssignedToUser"].Length; i++)
            //{
            //    sb.Append(json["IsAssignedToUser"][i]["Id"] + " -" + json["IsAssignedToUser"][i]["DisplayName"] + " - " + json["IsAssignedToUser"][i]["Status"]["Name"] + "<br/>");
            //}

            return sb.ToString();
        }