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);
32 $scope.temp.policy = "";
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
41 $scope.data = JSON.parse(j.data);
42 console.log($scope.data);
43 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
44 console.log($scope.securityZoneDictionaryDatas);
46 console.log("failed");
49 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
54 console.log($scope.termListDictionaryDatas);
56 console.log("failed");
59 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
64 console.log($scope.fwDictListDictionaryDatas);
66 console.log("failed");
69 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
74 console.log($scope.fwParentListDictionaryDatas);
76 console.log("failed");
79 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
84 console.log($scope.fwTagPickerDictionaryDatas);
86 console.log("failed");
89 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
94 console.log($scope.riskTypeDictionaryDatas);
96 console.log("failed");
99 function extend(obj, src) {
100 for (var key in src) {
101 if (src.hasOwnProperty(key)) obj[key] = src[key];
106 $scope.viewFWRule = function(policy){
108 var uuu = "policyController/ViewFWPolicyRule.htm";
109 var postData={policyData: policy};
114 contentType: 'application/json',
115 data: JSON.stringify(postData),
116 success : function(data){
117 $scope.$apply(function(){
118 window.alert(data.policyData);
121 error : function(data){
122 Notification.error("Error Occured while Showing Rule.");
128 $scope.saveFWPolicy = function(policy){
129 if(policy.itemContent != undefined){
130 $scope.refreshCheck = true;
131 $scope.policyNavigator = policy.itemContent;
132 policy.itemContent = "";
134 $scope.savebutton = false;
136 var uuu = "policycreation/save_policy";
137 var postData={policyData: policy};
142 contentType: 'application/json',
143 data: JSON.stringify(postData),
144 success : function(data){
145 $scope.$apply(function(){
146 $scope.data=data.policyData;
147 if($scope.data == 'success'){
148 $scope.temp.policy.readOnly = 'true';
149 $scope.pushStatus=data.policyData.split("&")[1];
150 if($scope.pushStatus=="successPush"){
151 Notification.success("Policy pushed successfully");
153 Notification.success("Policy Saved Successfully.");
154 }else if ($scope.data == 'PolicyExists'){
155 $scope.savebutton = true;
156 Notification.error("Policy Already Exists with Same Name in Scope.");
159 console.log($scope.data);
161 error : function(data){
162 Notification.error("Error Occured while saving Policy.");
167 $scope.validatePolicy = function(policy){
169 document.getElementById("validate").innerHTML = "";
170 var uuu = "policyController/validate_policy.htm";
171 var postData={policyData: policy};
176 contentType: 'application/json',
177 data: JSON.stringify(postData),
178 success : function(data){
179 $scope.$apply(function(){
180 $scope.validateData = data.data.replace(/\"/g, "");
181 $scope.data=data.data.substring(1,8);
182 var size = data.data.length;
183 if($scope.data == 'success'){
184 Notification.success("Validation Success.");
185 $scope.savebutton = false;
187 var displayWarning = data.data.substring(19,size);
188 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
189 document.getElementById("validate").style.color = "white";
190 document.getElementById("validate").style.backgroundColor = "skyblue";
193 Notification.error("Validation Failed.");
194 document.getElementById("validate").innerHTML = $scope.validateData;
195 document.getElementById("validate").style.color = "white";
196 document.getElementById("validate").style.backgroundColor = "red";
197 $scope.savebutton = true;
201 console.log($scope.data);
204 error : function(data){
205 Notification.error("Validation Failed.");
206 $scope.savebutton = true;
211 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
212 $scope.temp.policy.attributes = [];
213 $scope.temp.policy.fwattributes = [];
215 if($scope.temp.policy.attributes.length == 0){
216 $scope.temp.policy.attributes = [];
218 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
219 if($scope.temp.policy.fwattributes.length == 0){
220 $scope.temp.policy.fwattributes = [];
225 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
226 $scope.addNewChoice = function() {
227 var newItemNo = $scope.temp.policy.attributes.length+1;
228 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
230 $scope.removeChoice = function() {
231 var lastItem = $scope.temp.policy.attributes.length-1;
232 $scope.temp.policy.attributes.splice(lastItem);
235 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
236 $scope.addNewFWDictList = function() {
237 var newItemNo = $scope.temp.policy.fwattributes.length+1;
238 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
240 $scope.removefwDictChoice = function() {
241 var lastItem = $scope.temp.policy.fwattributes.length-1;
242 $scope.temp.policy.fwattributes.splice(lastItem);