2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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', function ($scope, $window, PolicyAppService, modalService, $modal, Notification) {
23 $scope.savebutton = true;
24 $scope.finalPath = null;
26 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
28 $scope.data = JSON.parse(j.data);
29 console.log($scope.data);
30 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
31 console.log($scope.securityZoneDictionaryDatas);
33 console.log("failed");
36 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
38 $scope.data = JSON.parse(j.data);
39 console.log($scope.data);
40 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
41 console.log($scope.termListDictionaryDatas);
43 console.log("failed");
46 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
48 $scope.data = JSON.parse(j.data);
49 console.log($scope.data);
50 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
51 console.log($scope.fwDictListDictionaryDatas);
53 console.log("failed");
56 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
58 $scope.data = JSON.parse(j.data);
59 console.log($scope.data);
60 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
61 console.log($scope.fwParentListDictionaryDatas);
63 console.log("failed");
66 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
68 $scope.data = JSON.parse(j.data);
69 console.log($scope.data);
70 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
71 console.log($scope.fwTagPickerDictionaryDatas);
73 console.log("failed");
76 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
78 $scope.data = JSON.parse(j.data);
79 console.log($scope.data);
80 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
81 console.log($scope.riskTypeDictionaryDatas);
83 console.log("failed");
86 function extend(obj, src) {
87 for (var key in src) {
88 if (src.hasOwnProperty(key)) obj[key] = src[key];
93 $scope.viewFWRule = function(policy){
95 var uuu = "policyController/ViewFWPolicyRule.htm";
96 var postData={policyData: policy};
101 contentType: 'application/json',
102 data: JSON.stringify(postData),
103 success : function(data){
104 $scope.$apply(function(){
105 window.alert(data.policyData);
108 error : function(data){
109 Notification.error("Error Occured while Showing Rule.");
115 $scope.saveFWPolicy = function(policy){
116 $scope.savebutton = false;
118 var uuu = "policycreation/save_policy";
119 var postData={policyData: policy};
124 contentType: 'application/json',
125 data: JSON.stringify(postData),
126 success : function(data){
127 $scope.$apply(function(){
128 $scope.data=data.policyData;
129 if($scope.data == 'success'){
130 $scope.temp.policy.readOnly = 'true';
131 $scope.pushStatus=data.policyData.split("&")[1];
132 if($scope.pushStatus=="successPush"){
133 Notification.success("Policy pushed successfully");
135 Notification.success("Policy Saved Successfully.");
136 }else if ($scope.data == 'PolicyExists'){
137 $scope.savebutton = true;
138 Notification.error("Policy Already Exists with Same Name in Scope.");
141 console.log($scope.data);
143 error : function(data){
144 Notification.error("Error Occured while saving Policy.");
149 $scope.validatePolicy = function(policy){
151 document.getElementById("validate").innerHTML = "";
152 var uuu = "policyController/validate_policy.htm";
153 var postData={policyData: policy};
158 contentType: 'application/json',
159 data: JSON.stringify(postData),
160 success : function(data){
161 $scope.$apply(function(){
162 $scope.validateData = data.data.replace(/\"/g, "");
163 $scope.data=data.data.substring(1,8);
164 var size = data.data.length;
165 if($scope.data == 'success'){
166 Notification.success("Validation Success.");
167 $scope.savebutton = false;
169 var displayWarning = data.data.substring(19,size);
170 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
171 document.getElementById("validate").style.color = "white";
172 document.getElementById("validate").style.backgroundColor = "skyblue";
175 Notification.error("Validation Failed.");
176 document.getElementById("validate").innerHTML = $scope.validateData;
177 document.getElementById("validate").style.color = "white";
178 document.getElementById("validate").style.backgroundColor = "red";
179 $scope.savebutton = true;
183 console.log($scope.data);
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);