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=========================================================
24 angular.module('abs').controller('fwPolicyController', function ($scope, $window, PolicyDictionaryService,modalService, $modal, Notification, PapUrlService) {
27 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
29 PapUrlService.getPapUrl().then(function(data) {
31 papUrl = config.PAP_URL;
34 PolicyDictionaryService.getSecurityZoneDictionaryData(papUrl).then(function (data) {
36 $scope.data = JSON.parse(j.data);
37 console.log($scope.data);
38 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
39 console.log($scope.securityZoneDictionaryDatas);
41 console.log("failed");
44 PolicyDictionaryService.getTermListDictionaryData(papUrl).then(function (data) {
46 $scope.data = JSON.parse(j.data);
47 console.log($scope.data);
48 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
49 console.log($scope.termListDictionaryDatas);
51 console.log("failed");
54 PolicyDictionaryService.getFWDictionaryListDictionaryData(papUrl).then(function (data) {
56 $scope.data = JSON.parse(j.data);
57 console.log($scope.data);
58 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
59 console.log($scope.fwDictListDictionaryDatas);
61 console.log("failed");
64 PolicyDictionaryService.getFWParentListDictionaryData().then(function (data) {
66 $scope.data = JSON.parse(j.data);
67 console.log($scope.data);
68 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
69 console.log($scope.fwParentListDictionaryDatas);
71 console.log("failed");
74 PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
76 $scope.data = JSON.parse(j.data);
77 console.log($scope.data);
78 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
79 console.log($scope.riskTypeDictionaryDatas);
81 console.log("failed");
84 PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
86 $scope.data = JSON.parse(j.data);
87 console.log($scope.data);
88 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
89 console.log($scope.riskLevelDatas);
91 console.log("failed");
94 PolicyDictionaryService.getGuardValueData().then(function (data) {
96 $scope.data = JSON.parse(j.data);
97 console.log($scope.data);
98 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
99 console.log($scope.guardDatas);
100 }, function (error) {
101 console.log("failed");
108 function extend(obj, src) {
109 for (var key in src) {
110 if (src.hasOwnProperty(key)) obj[key] = src[key];
115 $scope.viewFWRule = function(policy){
117 var uuu = "policyController/ViewFWPolicyRule.htm";
118 var postData={policyData: policy};
123 contentType: 'application/json',
124 data: JSON.stringify(postData),
125 success : function(data){
126 $scope.$apply(function(){
127 window.alert(data.policyData);
130 error : function(data){
131 Notification.error("Error Occured while Showing Rule.");
137 $scope.saveFWPolicy = function(policy){
139 /* var finalData = extend(policy, $scope.attributeDatas[0]);
140 console.log(finalData);*/
141 var uuu = "policyController/save_FirewallPolicy.htm";
142 var postData={policyData: policy};
147 contentType: 'application/json',
148 data: JSON.stringify(postData),
149 success : function(data){
150 $scope.$apply(function(){
151 $scope.data=data.data;
152 $scope.temp.policy.readOnly = 'true';
153 Notification.success("Policy Saved Successfully.");
155 console.log($scope.data);
156 $modalInstance.close();
159 error : function(data){
160 Notification.error("Error Occured while saving Policy.");
165 $scope.validatePolicy = function(policy){
167 var uuu = "policyController/validate_policy.htm";
168 var postData={policyData: policy};
173 contentType: 'application/json',
174 data: JSON.stringify(postData),
175 success : function(data){
176 $scope.$apply(function(){
177 $scope.data=data.data.substring(1,8);
178 var size = data.data.length;
179 if($scope.data == 'success'){
180 Notification.success("Validation Success.");
182 var displayWarning = data.data.substring(19,size);
183 window.alert(displayWarning);
186 Notification.error("Validation Failed.");
190 console.log($scope.data);
191 /*$modalInstance.close();*/
194 error : function(data){
195 Notification.error("Validation Failed.");
200 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
201 $scope.temp.policy.attributes = [];
202 $scope.temp.policy.fwattributes = [];
204 if($scope.temp.policy.attributes.length == 0){
205 $scope.temp.policy.attributes = [];
207 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
208 if($scope.temp.policy.fwattributes.length == 0){
209 $scope.temp.policy.fwattributes = [];
214 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
215 $scope.addNewChoice = function() {
216 var newItemNo = $scope.temp.policy.attributes.length+1;
217 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
219 $scope.removeChoice = function() {
220 var lastItem = $scope.temp.policy.attributes.length-1;
221 $scope.temp.policy.attributes.splice(lastItem);
224 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
225 $scope.addNewFWDictList = function() {
226 var newItemNo = $scope.temp.policy.fwattributes.length+1;
227 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
229 $scope.removefwDictChoice = function() {
230 var lastItem = $scope.temp.policy.fwattributes.length-1;
231 $scope.temp.policy.fwattributes.splice(lastItem);