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 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 function extend(obj, src) {
116 for (var key in src) {
117 if (src.hasOwnProperty(key)) obj[key] = src[key];
122 $scope.viewFWRule = function(policy){
124 var uuu = "policyController/ViewFWPolicyRule.htm";
125 var postData={policyData: policy};
130 contentType: 'application/json',
131 data: JSON.stringify(postData),
132 success : function(data){
133 $scope.$apply(function(){
134 window.alert(data.policyData);
137 error : function(data){
138 Notification.error("Error Occured while Showing Rule.");
144 $scope.saveFWPolicy = function(policy){
145 if(policy.itemContent != undefined){
146 $scope.refreshCheck = true;
147 $scope.policyNavigator = policy.itemContent;
148 policy.itemContent = "";
150 $scope.savebutton = false;
152 var uuu = "policycreation/save_policy";
153 var postData={policyData: policy};
158 contentType: 'application/json',
159 data: JSON.stringify(postData),
160 success : function(data){
161 $scope.$apply(function(){
162 $scope.data=data.policyData;
163 if($scope.data == 'success'){
164 $scope.temp.policy.readOnly = 'true';
165 $scope.pushStatus=data.policyData.split("&")[1];
166 if($scope.pushStatus=="successPush"){
167 Notification.success("Policy pushed successfully");
169 Notification.success("Policy Saved Successfully.");
170 }else if ($scope.data == 'PolicyExists'){
171 $scope.savebutton = true;
172 Notification.error("Policy Already Exists with Same Name in Scope.");
175 console.log($scope.data);
177 error : function(data){
178 Notification.error("Error Occured while saving Policy.");
183 $scope.validatePolicy = function(policy){
185 document.getElementById("validate").innerHTML = "";
186 var uuu = "policyController/validate_policy.htm";
187 var postData={policyData: policy};
192 contentType: 'application/json',
193 data: JSON.stringify(postData),
194 success : function(data){
195 $scope.$apply(function(){
196 $scope.validateData = data.data.replace(/\"/g, "");
197 $scope.data=data.data.substring(1,8);
198 var size = data.data.length;
199 if($scope.data == 'success'){
200 Notification.success("Validation Success.");
201 $scope.savebutton = false;
203 var displayWarning = data.data.substring(19,size);
204 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
205 document.getElementById("validate").style.color = "white";
206 document.getElementById("validate").style.backgroundColor = "skyblue";
209 Notification.error("Validation Failed.");
210 document.getElementById("validate").innerHTML = $scope.validateData;
211 document.getElementById("validate").style.color = "white";
212 document.getElementById("validate").style.backgroundColor = "red";
213 $scope.savebutton = true;
217 console.log($scope.data);
220 error : function(data){
221 Notification.error("Validation Failed.");
222 $scope.savebutton = true;
227 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
228 $scope.temp.policy.attributes = [];
229 $scope.temp.policy.fwattributes = [];
231 if($scope.temp.policy.attributes.length == 0){
232 $scope.temp.policy.attributes = [];
234 if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
235 if($scope.temp.policy.fwattributes.length == 0){
236 $scope.temp.policy.fwattributes = [];
241 $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
242 $scope.addNewChoice = function() {
243 var newItemNo = $scope.temp.policy.attributes.length+1;
244 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
246 $scope.removeChoice = function() {
247 var lastItem = $scope.temp.policy.attributes.length-1;
248 $scope.temp.policy.attributes.splice(lastItem);
251 $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
252 $scope.addNewFWDictList = function() {
253 var newItemNo = $scope.temp.policy.fwattributes.length+1;
254 $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
256 $scope.removefwDictChoice = function() {
257 var lastItem = $scope.temp.policy.fwattributes.length-1;
258 $scope.temp.policy.fwattributes.splice(lastItem);