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', ['$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 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
28 $scope.temp.policy = {
29 policyType : "Config",
30 configPolicyType : "Firewall Config"
34 $scope.refresh = function(){
35 if($scope.refreshCheck){
36 $scope.policyNavigator.refresh();
38 $scope.modal('createNewPolicy', true);
39 $scope.temp.policy = "";
42 $scope.modal = function(id, hide) {
43 return $('#' + id).modal(hide ? 'hide' : 'show');
46 $('#ttlDate').datepicker({
47 dateFormat: 'dd/mm/yy',
50 onSelect: function(date) {
51 angular.element($('#ttlDate')).triggerHandler('input');
55 PolicyAppService.getData('getDictionary/get_SecurityZoneDataByName').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
60 console.log($scope.securityZoneDictionaryDatas);
62 console.log("failed");
65 PolicyAppService.getData('getDictionary/get_TermListDataByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
70 console.log($scope.termListDictionaryDatas);
72 console.log("failed");
75 PolicyAppService.getData('getDictionary/get_FWDictionaryListDataByName').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 console.log($scope.data);
79 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
80 console.log($scope.fwDictListDictionaryDatas);
82 console.log("failed");
85 PolicyAppService.getData('getDictionary/get_FWParentListDataByName').then(function (data) {
87 $scope.data = JSON.parse(j.data);
88 console.log($scope.data);
89 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
90 console.log($scope.fwParentListDictionaryDatas);
92 console.log("failed");
95 PolicyAppService.getData('getDictionary/get_TagPickerNameByName').then(function (data) {
97 $scope.data = JSON.parse(j.data);
98 console.log($scope.data);
99 $scope.fwTagPickerDictionaryDatas = JSON.parse($scope.data.fwTagPickerDictionaryDatas);
100 console.log($scope.fwTagPickerDictionaryDatas);
101 }, function (error) {
102 console.log("failed");
105 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
107 $scope.data = JSON.parse(j.data);
108 console.log($scope.data);
109 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
110 console.log($scope.riskTypeDictionaryDatas);
111 }, function (error) {
112 console.log("failed");
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){
138 if(policy.itemContent != undefined){
139 $scope.refreshCheck = true;
140 $scope.policyNavigator = policy.itemContent;
141 policy.itemContent = "";
143 $scope.savebutton = false;
145 var uuu = "policycreation/save_policy";
146 var postData={policyData: policy};
151 contentType: 'application/json',
152 data: JSON.stringify(postData),
153 success : function(data){
154 $scope.$apply(function(){
155 $scope.data=data.policyData;
156 if($scope.data == 'success'){
157 $scope.temp.policy.readOnly = 'true';
158 $scope.pushStatus=data.policyData.split("&")[1];
159 if($scope.pushStatus=="successPush"){
160 Notification.success("Policy pushed successfully");
162 Notification.success("Policy Saved Successfully.");
163 }else if ($scope.data == 'PolicyExists'){
164 $scope.savebutton = true;
165 Notification.error("Policy Already Exists with Same Name in Scope.");
168 console.log($scope.data);
170 error : function(data){
171 Notification.error("Error Occured while saving Policy.");
176 $scope.validatePolicy = function(policy){
178 document.getElementById("validate").innerHTML = "";
179 var uuu = "policyController/validate_policy.htm";
180 var postData={policyData: policy};
185 contentType: 'application/json',
186 data: JSON.stringify(postData),
187 success : function(data){
188 $scope.$apply(function(){
189 $scope.validateData = data.data.replace(/\"/g, "");
190 $scope.data=data.data.substring(1,8);
191 var size = data.data.length;
192 if($scope.data == 'success'){
193 Notification.success("Validation Success.");
194 $scope.savebutton = false;
196 var displayWarning = data.data.substring(19,size);
197 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
198 document.getElementById("validate").style.color = "white";
199 document.getElementById("validate").style.backgroundColor = "skyblue";
202 Notification.error("Validation Failed.");
203 document.getElementById("validate").innerHTML = $scope.validateData;
204 document.getElementById("validate").style.color = "white";
205 document.getElementById("validate").style.backgroundColor = "red";
206 $scope.savebutton = true;
210 console.log($scope.data);
213 error : function(data){
214 Notification.error("Validation Failed.");
215 $scope.savebutton = true;
220 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
221 $scope.temp.policy.attributes = [];
222 $scope.temp.policy.fwattributes = [];
224 if($scope.temp.policy.attributes.length == 0){
225 $scope.temp.policy.attributes = [];
227 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
228 if($scope.temp.policy.fwattributes.length == 0){
229 $scope.temp.policy.fwattributes = [];
234 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
235 $scope.addNewChoice = function() {
236 var newItemNo = $scope.temp.policy.attributes.length+1;
237 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
239 $scope.removeChoice = function() {
240 var lastItem = $scope.temp.policy.attributes.length-1;
241 $scope.temp.policy.attributes.splice(lastItem);
244 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
245 $scope.addNewFWDictList = function() {
246 var newItemNo = $scope.temp.policy.fwattributes.length+1;
247 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
249 $scope.removefwDictChoice = function() {
250 var lastItem = $scope.temp.policy.fwattributes.length-1;
251 $scope.temp.policy.fwattributes.splice(lastItem);