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', ['$scope', '$window', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.savebutton = true;
25 $scope.refreshCheck = false;
27 $scope.refresh = function(){
28 if($scope.refreshCheck){
29 $scope.policyNavigator.refresh();
31 $scope.modal('createNewPolicy', true);
34 $scope.modal = function(id, hide) {
35 return $('#' + id).modal(hide ? 'hide' : 'show');
38 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
40 $scope.data = JSON.parse(j.data);
41 console.log($scope.data);
42 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
43 console.log($scope.securityZoneDictionaryDatas);
45 console.log("failed");
48 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
50 $scope.data = JSON.parse(j.data);
51 console.log($scope.data);
52 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
53 console.log($scope.termListDictionaryDatas);
55 console.log("failed");
58 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
60 $scope.data = JSON.parse(j.data);
61 console.log($scope.data);
62 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
63 console.log($scope.fwDictListDictionaryDatas);
65 console.log("failed");
68 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
70 $scope.data = JSON.parse(j.data);
71 console.log($scope.data);
72 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
73 console.log($scope.fwParentListDictionaryDatas);
75 console.log("failed");
78 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
80 $scope.data = JSON.parse(j.data);
81 console.log($scope.data);
82 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
83 console.log($scope.fwTagPickerDictionaryDatas);
85 console.log("failed");
88 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
90 $scope.data = JSON.parse(j.data);
91 console.log($scope.data);
92 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
93 console.log($scope.riskTypeDictionaryDatas);
95 console.log("failed");
98 function extend(obj, src) {
99 for (var key in src) {
100 if (src.hasOwnProperty(key)) obj[key] = src[key];
105 $scope.viewFWRule = function(policy){
107 var uuu = "policyController/ViewFWPolicyRule.htm";
108 var postData={policyData: policy};
113 contentType: 'application/json',
114 data: JSON.stringify(postData),
115 success : function(data){
116 $scope.$apply(function(){
117 window.alert(data.policyData);
120 error : function(data){
121 Notification.error("Error Occured while Showing Rule.");
127 $scope.saveFWPolicy = function(policy){
128 if(policy.itemContent != undefined){
129 $scope.refreshCheck = true;
130 $scope.policyNavigator = policy.itemContent;
131 policy.itemContent = "";
133 $scope.savebutton = false;
135 var uuu = "policycreation/save_policy";
136 var postData={policyData: policy};
141 contentType: 'application/json',
142 data: JSON.stringify(postData),
143 success : function(data){
144 $scope.$apply(function(){
145 $scope.data=data.policyData;
146 if($scope.data == 'success'){
147 $scope.temp.policy.readOnly = 'true';
148 $scope.pushStatus=data.policyData.split("&")[1];
149 if($scope.pushStatus=="successPush"){
150 Notification.success("Policy pushed successfully");
152 Notification.success("Policy Saved Successfully.");
153 }else if ($scope.data == 'PolicyExists'){
154 $scope.savebutton = true;
155 Notification.error("Policy Already Exists with Same Name in Scope.");
158 console.log($scope.data);
160 error : function(data){
161 Notification.error("Error Occured while saving Policy.");
166 $scope.validatePolicy = function(policy){
168 document.getElementById("validate").innerHTML = "";
169 var uuu = "policyController/validate_policy.htm";
170 var postData={policyData: policy};
175 contentType: 'application/json',
176 data: JSON.stringify(postData),
177 success : function(data){
178 $scope.$apply(function(){
179 $scope.validateData = data.data.replace(/\"/g, "");
180 $scope.data=data.data.substring(1,8);
181 var size = data.data.length;
182 if($scope.data == 'success'){
183 Notification.success("Validation Success.");
184 $scope.savebutton = false;
186 var displayWarning = data.data.substring(19,size);
187 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
188 document.getElementById("validate").style.color = "white";
189 document.getElementById("validate").style.backgroundColor = "skyblue";
192 Notification.error("Validation Failed.");
193 document.getElementById("validate").innerHTML = $scope.validateData;
194 document.getElementById("validate").style.color = "white";
195 document.getElementById("validate").style.backgroundColor = "red";
196 $scope.savebutton = true;
200 console.log($scope.data);
203 error : function(data){
204 Notification.error("Validation Failed.");
205 $scope.savebutton = true;
210 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
211 $scope.temp.policy.attributes = [];
212 $scope.temp.policy.fwattributes = [];
214 if($scope.temp.policy.attributes.length == 0){
215 $scope.temp.policy.attributes = [];
217 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
218 if($scope.temp.policy.fwattributes.length == 0){
219 $scope.temp.policy.fwattributes = [];
224 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
225 $scope.addNewChoice = function() {
226 var newItemNo = $scope.temp.policy.attributes.length+1;
227 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
229 $scope.removeChoice = function() {
230 var lastItem = $scope.temp.policy.attributes.length-1;
231 $scope.temp.policy.attributes.splice(lastItem);
234 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
235 $scope.addNewFWDictList = function() {
236 var newItemNo = $scope.temp.policy.fwattributes.length+1;
237 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
239 $scope.removefwDictChoice = function() {
240 var lastItem = $scope.temp.policy.fwattributes.length-1;
241 $scope.temp.policy.fwattributes.splice(lastItem);