/// <summary>
        /// Example of find disabled rules
        /// </summary>
        static void Main()
        {
            //Asks The user for the arguments
            Console.WriteLine("Enter server IP Address or host name (for a multi-domain environment, provide the IP address of the MDS): ");
            string server = Console.ReadLine();

            Console.WriteLine("Enter user name: ");
            string username = Console.ReadLine();

            Console.WriteLine("Enter password: "******"Domain name (leave empty for a SmartCenter environment): ");
            string domain = Console.ReadLine();

            Console.WriteLine("Policy package name (default value is 'Standard'): ");
            string package = Console.ReadLine();

            if (string.IsNullOrEmpty(package))
            {
                package = "standard";
            }

            ApiClient client = new ApiClient();

            //Validity Fingerprint
            try
            {
                ApiUtils.CheckFingerprint(client, server);
            }
            catch (ApiClientException)
            {
                EndProgram(client, null, false);
            }

            JObject payload = new JObject
            {
                { "user", username },
                { "password", password },
                { "domain", domain },
                { "continue-last-session", false },
                { "read-only", true }
            };

            //Login to Management server
            ApiLoginResponse loginRes = null;

            try
            {
                loginRes = client.Login(server, payload);
            }
            catch (ApiClientException)
            {
                ApiUtils.WriteLineColored("Login failed.", ConsoleColor.Green);
                EndProgram(client, loginRes, false);
            }

            if (loginRes == null)
            {
                ApiUtils.WriteLineColored("Login failed.", ConsoleColor.Green);
                EndProgram(client, loginRes, false);
            }

            if (!loginRes.Success)
            {
                ApiUtils.WriteLineColored(loginRes.ErrorMessage, ConsoleColor.Red);
                EndProgram(client, loginRes, false);
            }

            //Go over all the access layer in the given package and  print all the rules and there status
            Dictionary <string, string> layers = GetAccessLayers(client, loginRes, package);

            foreach (string layerUid in layers.Keys)
            {
                Console.WriteLine("Layer name: " + layers[layerUid]);
                List <RuleInfo> rules = GetRules(client, loginRes, layerUid);
                foreach (RuleInfo rule in rules)
                {
                    Console.WriteLine(rule.ToString());
                }
                Console.WriteLine("");
            }
            Console.WriteLine("done.");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Beispiel #2
0
        /// <summary>
        /// Example of add host
        /// </summary>
        static void Main()
        {
            ApiClientArgs apiArgs = new ApiClientArgs {
                DebugFile = "debug.txt"
            };
            ApiClient client = new ApiClient(apiArgs);

            Console.WriteLine("Enter server ip or host name: ");
            string server = Console.ReadLine();

            try
            {
                ApiUtils.CheckFingerprint(client, server);
            }
            catch (ApiClientException)
            {
                ApiUtils.EndProgram();
            }

            Console.WriteLine("Enter username: "******"Enter password: "******"Enter a name for the new host object: ");
            string hostName = Console.ReadLine();

            Console.WriteLine("Enter host IP: ");
            string hostIp = Console.ReadLine();

            // make the API add-host call.
            ApiResponse addhostRes = client.ApiCall(res, "add-host", new JObject {
                { "name", hostName }, { "ip-address", hostIp }
            });

            if (addhostRes == null)
            {
                ApiUtils.WriteLineColored("Add-Host failed.", ConsoleColor.Red);
                Logout(res, client);
                ApiUtils.EndProgram();
            }

            if (!addhostRes.Success)
            {
                ApiUtils.WriteLineColored("Add-Host failed. Error: " + addhostRes.ErrorMessage, ConsoleColor.Red);
                Logout(res, client);
                ApiUtils.EndProgram();
            }

            ApiUtils.WriteLineColored("Add-Host succeeded.", ConsoleColor.Green);

            // try to publish changes and then logout.
            ApiResponse publishRes = client.ApiCall(res, "publish", "{}");

            if (!publishRes.Success)
            {
                ApiUtils.WriteLineColored("Publish failed. Error: " + publishRes.ErrorMessage, ConsoleColor.Red);
                Logout(res, client);
                ApiUtils.EndProgram();
            }

            ApiUtils.WriteLineColored("Publish succeeded.", ConsoleColor.Green);
            Logout(res, client);
            ApiUtils.EndProgram();
            Console.ReadKey();
        }