2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 angular.module('abs').controller('fwPolicyController',
21 ['$scope', '$window', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification',
22 function ($scope, $window, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
25 $scope.policyNavigator;
26 $scope.savebutton = true;
27 $scope.refreshCheck = false;
29 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
30 $scope.temp.policy = {
31 policyType : "Config",
32 configPolicyType : "Firewall Config"
36 $scope.refresh = function(){
37 if($scope.refreshCheck){
38 $scope.policyNavigator.refresh();
40 $scope.modal('createNewPolicy', true);
41 $scope.temp.policy = "";
44 $scope.modal = function(id, hide) {
45 return $('#' + id).modal(hide ? 'hide' : 'show');
48 $('#ttlDate').datepicker({
49 dateFormat: 'dd/mm/yy',
52 onSelect: function(date) {
53 angular.element($('#ttlDate')).triggerHandler('input');
57 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
59 $scope.data = JSON.parse(j.data);
60 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
63 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
65 $scope.data = JSON.parse(j.data);
66 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
69 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
75 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
81 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
83 $scope.data = JSON.parse(j.data);
84 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
87 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
89 $scope.data = JSON.parse(j.data);
90 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
93 $scope.viewFWRule = function(policy){
94 var uuu = "policyController/ViewFWPolicyRule.htm";
95 var postData={policyData: policy};
100 contentType: 'application/json',
101 data: JSON.stringify(postData),
102 success : function(data){
103 $scope.$apply(function(){
104 window.alert(data.policyData);
107 error : function(data){
108 Notification.error("Error Occured while Showing Rule.");
114 $scope.saveFWPolicy = function(policy){
115 if(policy.itemContent != undefined){
116 $scope.refreshCheck = true;
117 $scope.policyNavigator = policy.itemContent;
118 policy.itemContent = "";
120 $scope.savebutton = false;
121 var uuu = "policycreation/save_policy";
122 var postData={policyData: policy};
127 contentType: 'application/json',
128 data: JSON.stringify(postData),
129 success : function(data){
130 $scope.$apply(function(){
131 $scope.data=data.policyData;
132 if($scope.data == 'success'){
133 $scope.temp.policy.readOnly = 'true';
134 $scope.pushStatus=data.policyData.split("&")[1];
135 if($scope.pushStatus=="successPush"){
136 Notification.success("Policy pushed successfully");
138 Notification.success("Policy Saved Successfully.");
139 }else if ($scope.data == 'PolicyExists'){
140 $scope.savebutton = true;
141 Notification.error("Policy Already Exists with Same Name in Scope.");
145 error : function(data){
146 Notification.error("Error Occured while saving Policy.");
151 $scope.validatePolicy = function(policy){
152 document.getElementById("validate").innerHTML = "";
153 var uuu = "policyController/validate_policy.htm";
154 var postData={policyData: policy};
159 contentType: 'application/json',
160 data: JSON.stringify(postData),
161 success : function(data){
162 $scope.$apply(function(){
163 $scope.validateData = data.data.replace(/\"/g, "");
164 $scope.data=data.data.substring(1,8);
165 var size = data.data.length;
166 if($scope.data == 'success'){
167 Notification.success("Validation Success.");
168 $scope.savebutton = false;
170 var displayWarning = data.data.substring(19,size);
171 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
172 document.getElementById("validate").style.color = "white";
173 document.getElementById("validate").style.backgroundColor = "skyblue";
176 Notification.error("Validation Failed.");
177 document.getElementById("validate").innerHTML = $scope.validateData;
178 document.getElementById("validate").style.color = "white";
179 document.getElementById("validate").style.backgroundColor = "red";
180 $scope.savebutton = true;
186 error : function(data){
187 Notification.error("Validation Failed.");
188 $scope.savebutton = true;
193 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
194 $scope.temp.policy.attributes = [];
195 $scope.temp.policy.fwattributes = [];
197 if($scope.temp.policy.attributes.length == 0){
198 $scope.temp.policy.attributes = [];
200 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
201 if($scope.temp.policy.fwattributes.length == 0){
202 $scope.temp.policy.fwattributes = [];
207 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
208 $scope.addNewChoice = function() {
209 var newItemNo = $scope.temp.policy.attributes.length+1;
210 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
212 $scope.removeChoice = function() {
213 var lastItem = $scope.temp.policy.attributes.length-1;
214 $scope.temp.policy.attributes.splice(lastItem);
217 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
218 $scope.addNewFWDictList = function() {
219 var newItemNo = $scope.temp.policy.fwattributes.length+1;
220 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
222 $scope.removefwDictChoice = function() {
223 var lastItem = $scope.temp.policy.fwattributes.length-1;
224 $scope.temp.policy.fwattributes.splice(lastItem);