def enabledisableapplicationcontrol(policy_id, policies_api, application_control_policy_extension, api_version, state): # Set the Application Control state print("Setting the Application Control state to: " + state) application_control_policy_extension.state = state application_control_policy_extension.block_unrecognized = "true" policy = deepsecurity.Policy() policy.application_control = application_control_policy_extension # Modify the policy on Deep Security Manager modified_policy = policies_api.modify_policy(policy_id, policy, api_version)
def describe_policy(self, policy_id, description): if not sys.warnoptions: warnings.simplefilter("ignore") api_instance = ds.PoliciesApi(ds.ApiClient(self.configuration)) policy = ds.Policy() description = description[:1998] + (description[1998:] and '..') policy.description = description api_response = api_instance.modify_policy(policy_id, policy, self.api_version, overrides=False) return api_response
def modifywrsstate(policy_id, configuration, api_version, overrides, on_off): print("Changing the WRS state to: " + on_off) policies_api = deepsecurity.PoliciesApi( deepsecurity.ApiClient(configuration)) current_wrs_settings = policies_api.describe_policy(policy_id, api_version, overrides=False) #Configure sending policy updates when the policy changes web_reputation_policy_extension = deepsecurity.WebReputationPolicyExtension( ) web_reputation_policy_extension.state = on_off policy = deepsecurity.Policy() policy.web_reputation = web_reputation_policy_extension # Modify the policy on Deep Security Manager modified_policy = policies_api.modify_policy(policy_id, policy, api_version)
def assignlirule(rule_to_apply, rule_id, policy_id, configuration, api_version, overrides, add_rule): try: # Get the current list of rules from the policy policies_api = deepsecurity.PoliciesApi( deepsecurity.ApiClient(configuration)) current_rules = policies_api.describe_policy(policy_id, api_version, overrides=False) # Add the rule_id if it doesn't already exist in current_rules if (add_rule == True): print("Adding the " + rule_to_apply + " rule to the policy") if current_rules.log_inspection.rule_ids is None: current_rules.log_inspection.rule_ids = rule_id elif rule_id not in current_rules.log_inspection.rule_ids: current_rules.log_inspection.rule_ids.append(rule_id) # Remove the rule_id if it was originally unassigned else: print("Removing the " + rule_to_apply + " rule from the policy") current_rules.log_inspection.rule_ids.remove(rule_id) # Add the new and existing intrusion prevention rules to a policy log_inspection_policy_extension = deepsecurity.LogInspectionPolicyExtension( ) log_inspection_policy_extension.rule_ids = current_rules.log_inspection.rule_ids policy = deepsecurity.Policy() policy.log_inspection = log_inspection_policy_extension # Configure sending policy updates when the policy changes policy.auto_requires_update = "on" # Modify the policy on Deep Security Manager modified_policy = policies_api.modify_policy(policy_id, policy, api_version) except ApiException as e: print( "An exception occurred when calling PolicyIntegrityMonitoringRuleAssignmentsRecommendationsApi.add_intrusion_prevention_rule_ids_to_policy: %s\n" % e)
# for Common Objects examples scan_config_id = 2 dir_list_id = 1 li_rule_name = "Inspect log for error" path = "C:/logfile.log" pattern = "^ERROR" group = "Windows Rules" xml = "PGdyb3VwIG5hbWU9IldpbmRvd3MgUnVsZXMiPg0KICA8cnVsZSBpZD0iMTAwMDAwIiBsZXZlbD0iMCI" dir_list_name = "test list" dir_path = "C:\\windows\\" # for Tenant examples account_name = "Test_tenant" tenant_id = 6 new_policy = api.Policy() new_policy.name = "Test Policy" new_policy.description = "Inherits from Base Policy" new_policy.auto_requires_update = "on" new_policy.parent_id = 1 # For Settings examples settings_policy_id = 1 firewall_fail_open_mode = True # For Computer Overrides examples override_computer_id = 2 expand = api.Expand() expand.add(expand.intrusion_prevention) # For Scheduled Tasks examples