Пример #1
0
        private static void ProcessChapter(dynamic chapter, OutputChapter current)
        {
            Console.WriteLine(chapter["name"]);
            var c = new OutputChapter(chapter["name"].ToString(), current);

            foreach (var cmd in chapter["commands-data"])
            {
                ProcessCommandData(cmd, c);
            }

            if (cmdExtras.ContainsKey((string)chapter["name"]))
            {
                var list = cmdExtras[(string)chapter["name"]];
                list.Sort();
                foreach (var cmd in list)
                {
                    new OutputCmdlet(c, cmd.Cmdlet, cmd.Type.Name, cmd.Cmdlet);
                }
            }

            if (chapter["sub-chapters"] != null)
            {
                foreach (var subChapter in chapter["sub-chapters"])
                {
                    ProcessChapter(subChapter, c);
                }
            }
        }
Пример #2
0
        private static void CreateExtraContentJson(string path)
        {
            var extraCmds = GetImplementedExtraCmdlets();
            var output    = new OutputChapter("chapters");

            var list = extraCmds.Keys.ToList();

            list.Sort();

            OutputChapter current = null;

            foreach (string i in list)
            {
                string[] keys = i.Split('/');
                if (current == null || !current.Name.Equals(keys[0]))
                {
                    Console.WriteLine(keys[0]);
                    current = new OutputChapter(keys[0], output);
                }

                Console.WriteLine(keys[1]);
                new OutputCmdlet(current, extraCmds[i].Cmdlet, extraCmds[i].Type.Name, extraCmds[i].Cmdlet);
            }

            // Output results to file
            File.WriteAllText($@"{path}\extra-content.json", JsonConvert.SerializeObject(output.SubChapters, Formatting.Indented));
        }
Пример #3
0
        public OutputCmdlet(OutputChapter parent, string name, string @class, string cmdlet)
        {
            Name   = name;
            Class  = @class;
            Cmdlet = cmdlet;

            parent.Cmdlets.Add(this);
        }
Пример #4
0
        private static void ProcessCommandData(dynamic cmd, OutputChapter current)
        {
            string name = cmd["name"]["web"];

            Console.WriteLine(name);
            if (cmds.ContainsKey(name))
            {
                new OutputCmdlet(current, name, cmds[name].Type.Name, cmds[name].Cmdlet);
            }
            else
            {
                new OutputCmdlet(current, name, null, null);
            }
        }
Пример #5
0
        private static void AppendIAContentJson(OutputChapter output)
        {
            var iaCmds = GetImplementedIACmdlets();

            var list = iaCmds.Keys.ToList();

            list.Sort();

            var current = new OutputChapter("Identity Awareness", output);

            foreach (string i in list)
            {
                Console.WriteLine(iaCmds[i].Cmdlet);
                new OutputCmdlet(current, iaCmds[i].ApiCmd, iaCmds[i].Type.Name, iaCmds[i].Cmdlet);
            }
        }
Пример #6
0
        private static void CreateContentJson(string path)
        {
            GetImplementedCmdlets();
            var output = new OutputChapter("chapters");

            // Get List of all Check Point API calls
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                using (var response = client.GetAsync($"https://sc1.checkpoint.com/documents/latest/APIs/data/v1.1/dynamic/content.json").Result)
                {
                    if (response.IsSuccessStatusCode)
                    {
                        string strJson = response.Content.ReadAsStringAsync().Result;

                        dynamic content = JsonConvert.DeserializeObject(strJson);

                        foreach (var chapter in content["chapters"])
                        {
                            ProcessChapter(chapter, output);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error getting content.json");
                    }
                }
            }

            // Remove empty chapters
            foreach (var chapter in output.SubChapters.ToList())
            {
                if (chapter.SubChapters.Count == 0 && chapter.Cmdlets.Count == 0)
                {
                    output.SubChapters.Remove(chapter);
                }
            }

            AppendIAContentJson(output);

            // Output results to file
            File.WriteAllText($@"{path}\content.json", JsonConvert.SerializeObject(output.SubChapters, Formatting.Indented));
        }
Пример #7
0
 public OutputChapter(string name, OutputChapter parent)
 {
     Name = name;
     parent.SubChapters.Add(this);
 }