mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	[CLOUDSTACK-10329] Button in ACL rules page to export all rules as a CSV file (#2494)
This commit is contained in:
		
							parent
							
								
									af52b1a873
								
							
						
					
					
						commit
						cd3a128090
					
				| @ -3241,6 +3241,7 @@ div.toolbar div.button.main-action, | |||||||
|   height: 12px; |   height: 12px; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | div.toolbar div.button.export:hover, | ||||||
| div.toolbar div.button.add:hover, | div.toolbar div.button.add:hover, | ||||||
| div.toolbar div.button.refresh:hover, | div.toolbar div.button.refresh:hover, | ||||||
| div.toolbar div.button.main-action:hover, | div.toolbar div.button.main-action:hover, | ||||||
| @ -13414,3 +13415,32 @@ div.panel.copy-template-destination-list div.list-view div.fixed-header{ | |||||||
| .multi-edit-add-list .ui-button.copytemplatecancel { | .multi-edit-add-list .ui-button.copytemplatecancel { | ||||||
|     left: 310px; |     left: 310px; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | div.button.export { | ||||||
|  | 	position: relative; | ||||||
|  | 	left: 0px; | ||||||
|  | 	top: 5px; | ||||||
|  | 	font-size: 12px; | ||||||
|  | 	font-weight: 100; | ||||||
|  | 	color: #000000; | ||||||
|  | 	margin: 0 10px 0 0; | ||||||
|  | 	cursor: pointer; | ||||||
|  | 	text-shadow: 0px 1px 1px #DEE5EA; | ||||||
|  | 	padding: 5px 5px 5px 5px; | ||||||
|  | 	background: linear-gradient(to bottom, rgba(247,247,247,1) 1%,rgba(234,234,234,1) 100%); | ||||||
|  | 	border: 1px solid #B7B7B7; | ||||||
|  | 	float: right; | ||||||
|  | 	border-radius: 4px 4px 4px 4px; | ||||||
|  | 	height: 12px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | div.button.export a { | ||||||
|  | 	padding: 0px 0 3px 20px; | ||||||
|  | 	background: url(../images/exportCsvIcon.png) no-repeat; | ||||||
|  | 	position: relative; | ||||||
|  | 	left: 0px; | ||||||
|  | 	top: 0px; | ||||||
|  | 	background-size: 15.5px; | ||||||
|  | 	text-decoration: none; | ||||||
|  | 	color: black; | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								ui/images/exportCsvIcon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ui/images/exportCsvIcon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 100 KiB | 
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Accounts", |     "label.accounts": "Accounts", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Accounts", |     "label.accounts": "Accounts", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Benutzerkonten", |     "label.accounts": "Benutzerkonten", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL-Kennung", |     "label.acl.id": "ACL-Kennung", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL-Listenregeln", |     "label.acl.list.rules": "ACL-Listenregeln", | ||||||
|     "label.acl.name": "ACL-Name", |     "label.acl.name": "ACL-Name", | ||||||
|     "label.acl.replaced": "ACL ersetzt", |     "label.acl.replaced": "ACL ersetzt", | ||||||
|  | |||||||
| @ -102,6 +102,7 @@ var dictionary = { | |||||||
| "label.accounts":"Accounts", | "label.accounts":"Accounts", | ||||||
| "label.acl":"ACL", | "label.acl":"ACL", | ||||||
| "label.acl.id":"ACL ID", | "label.acl.id":"ACL ID", | ||||||
|  | "label.acl.export": "Export ACLs", | ||||||
| "label.acl.list.rules":"ACL List Rules", | "label.acl.list.rules":"ACL List Rules", | ||||||
| "label.acl.name":"ACL Name", | "label.acl.name":"ACL Name", | ||||||
| "label.acl.replaced":"ACL replaced", | "label.acl.replaced":"ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Cuentas", |     "label.accounts": "Cuentas", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ID de ACL", |     "label.acl.id": "ID de ACL", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "Lista de Reglas ACL", |     "label.acl.list.rules": "Lista de Reglas ACL", | ||||||
|     "label.acl.name": "Nombre de ACL", |     "label.acl.name": "Nombre de ACL", | ||||||
|     "label.acl.replaced": "ACL reemplazada", |     "label.acl.replaced": "ACL reemplazada", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Comptes", |     "label.accounts": "Comptes", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ID ACL", |     "label.acl.id": "ID ACL", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "Liste règles ACL", |     "label.acl.list.rules": "Liste règles ACL", | ||||||
|     "label.acl.name": "Nom ACL", |     "label.acl.name": "Nom ACL", | ||||||
|     "label.acl.replaced": "ACL remplacée", |     "label.acl.replaced": "ACL remplacée", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Számlák", |     "label.accounts": "Számlák", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL név", |     "label.acl.name": "ACL név", | ||||||
|     "label.acl.replaced": "ACL lehelyettesítve", |     "label.acl.replaced": "ACL lehelyettesítve", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Utenti", |     "label.accounts": "Utenti", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "アカウント", |     "label.accounts": "アカウント", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL ルールのリスト", |     "label.acl.list.rules": "ACL ルールのリスト", | ||||||
|     "label.acl.name": "ACL 名", |     "label.acl.name": "ACL 名", | ||||||
|     "label.acl.replaced": "ACL が置き換えられました", |     "label.acl.replaced": "ACL が置き換えられました", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "계정 정보", |     "label.accounts": "계정 정보", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Kontoer", |     "label.accounts": "Kontoer", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL Liste Regler", |     "label.acl.list.rules": "ACL Liste Regler", | ||||||
|     "label.acl.name": "ACL Navn", |     "label.acl.name": "ACL Navn", | ||||||
|     "label.acl.replaced": "ACL erstattet", |     "label.acl.replaced": "ACL erstattet", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Accounts", |     "label.accounts": "Accounts", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL lijst regels", |     "label.acl.list.rules": "ACL lijst regels", | ||||||
|     "label.acl.name": "ACL naam", |     "label.acl.name": "ACL naam", | ||||||
|     "label.acl.replaced": "ACL vervangen", |     "label.acl.replaced": "ACL vervangen", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Konta", |     "label.accounts": "Konta", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Contas", |     "label.accounts": "Contas", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "Lista de regas de ACL", |     "label.acl.list.rules": "Lista de regas de ACL", | ||||||
|     "label.acl.name": "Nome da ACL", |     "label.acl.name": "Nome da ACL", | ||||||
|     "label.acl.replaced": "ACL trocado", |     "label.acl.replaced": "ACL trocado", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "Учётные записи", |     "label.accounts": "Учётные записи", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL List Rules", |     "label.acl.list.rules": "ACL List Rules", | ||||||
|     "label.acl.name": "ACL Name", |     "label.acl.name": "ACL Name", | ||||||
|     "label.acl.replaced": "ACL replaced", |     "label.acl.replaced": "ACL replaced", | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ var dictionary = { | |||||||
|     "label.accounts": "帐户", |     "label.accounts": "帐户", | ||||||
|     "label.acl": "ACL", |     "label.acl": "ACL", | ||||||
|     "label.acl.id": "ACL ID", |     "label.acl.id": "ACL ID", | ||||||
|  |     "label.acl.export": "Export ACLs", | ||||||
|     "label.acl.list.rules": "ACL列表策略", |     "label.acl.list.rules": "ACL列表策略", | ||||||
|     "label.acl.name": "ACL 名称", |     "label.acl.name": "ACL 名称", | ||||||
|     "label.acl.replaced": "ACL 已替换", |     "label.acl.replaced": "ACL 已替换", | ||||||
|  | |||||||
| @ -15,6 +15,53 @@ | |||||||
| // specific language governing permissions and limitations
 | // specific language governing permissions and limitations
 | ||||||
| // under the License.
 | // under the License.
 | ||||||
| (function($, cloudStack) { | (function($, cloudStack) { | ||||||
|  |     var isNumeric = function (n) { | ||||||
|  |         return !isNaN(parseFloat(n)); | ||||||
|  |     }; | ||||||
|  |     var createSafeCsvValue = function(value){ | ||||||
|  |         if(value){ | ||||||
|  |             return '"' + value + '"'; | ||||||
|  |         } | ||||||
|  |         return ""; | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     var generateCsvForAclRules = function(aclRules){ | ||||||
|  |         var csv = createSafeCsvValue('id') + ','; | ||||||
|  |         for(var field in aclRuleFields){ | ||||||
|  |             var fieldLabel = aclRuleFields[field].label; | ||||||
|  |             var fieldLabelTranslated = _l(fieldLabel); | ||||||
|  |             csv = csv + createSafeCsvValue(fieldLabelTranslated) + ','; | ||||||
|  |         } | ||||||
|  |         csv = csv.substr(0, csv.length - 1) + '\n'; | ||||||
|  |         if(!aclRules){ | ||||||
|  |             return csv; | ||||||
|  |         } | ||||||
|  |         aclRules.forEach(function(entry){ | ||||||
|  |             csv = csv +  | ||||||
|  |             createSafeCsvValue(entry.id) + ',' +  | ||||||
|  |             createSafeCsvValue(entry.number) + ',' + | ||||||
|  |             createSafeCsvValue(entry.cidrlist) + ',' + | ||||||
|  |             createSafeCsvValue(entry.action) + ',' ; | ||||||
|  |              | ||||||
|  |             if(isNumeric(entry.protocol)){ | ||||||
|  |                 csv = csv + | ||||||
|  |                 createSafeCsvValue(_l('label.protocol.number')) + ',' + | ||||||
|  |                 createSafeCsvValue(entry.protocol) + ','; | ||||||
|  |             }else{ | ||||||
|  |                 csv = csv + | ||||||
|  |                 createSafeCsvValue(entry.protocol) + ',' + | ||||||
|  |                 createSafeCsvValue('') + ','; | ||||||
|  |             } | ||||||
|  |             csv = csv + | ||||||
|  |             createSafeCsvValue(entry.startport) + ',' + | ||||||
|  |             createSafeCsvValue(entry.endport) + ',' + | ||||||
|  |             createSafeCsvValue(entry.icmptype) + ',' + | ||||||
|  |             createSafeCsvValue(entry.icmpcode) + ',' + | ||||||
|  |             createSafeCsvValue(entry.traffictype) + ',' + | ||||||
|  |             createSafeCsvValue(entry.reason) + '\n'; | ||||||
|  |         }); | ||||||
|  |         return csv; | ||||||
|  |     }; | ||||||
|     var assignVMAction = function() { |     var assignVMAction = function() { | ||||||
|         return { |         return { | ||||||
|             label: 'label.assign.vms', |             label: 'label.assign.vms', | ||||||
| @ -1327,8 +1374,9 @@ | |||||||
|                                             networkid: false |                                             networkid: false | ||||||
|                                         }, |                                         }, | ||||||
|                                         dataProvider: function(args) { |                                         dataProvider: function(args) { | ||||||
|  |                                             var aclListId = args.context.aclLists[0].id; | ||||||
|                                             $.ajax({ |                                             $.ajax({ | ||||||
|                                                 url: createURL('listNetworkACLs&aclid=' + args.context.aclLists[0].id), |                                                 url: createURL('listNetworkACLs&aclid=' + aclListId), | ||||||
|                                                 success: function(json) { |                                                 success: function(json) { | ||||||
|                                                     var items = json.listnetworkaclsresponse.networkacl; |                                                     var items = json.listnetworkaclsresponse.networkacl; | ||||||
| 
 | 
 | ||||||
| @ -1369,6 +1417,9 @@ | |||||||
|                                                                 	 } |                                                                 	 } | ||||||
|                                                                 	 if(data.protocol != 'protocolnumber'){ |                                                                 	 if(data.protocol != 'protocolnumber'){ | ||||||
|                                                                 		 data.protocolnumber = undefined; |                                                                 		 data.protocolnumber = undefined; | ||||||
|  |                                                                 	 }else{ | ||||||
|  |                                                                 	     data.protocol = data.protocolnumber; | ||||||
|  |                                                                 	     data.protocolnumber = undefined; | ||||||
|                                                                 	 } |                                                                 	 } | ||||||
|                                                                 	 if(data.protocol === 'all'){ |                                                                 	 if(data.protocol === 'all'){ | ||||||
|                                                                 		 data.startport = undefined; |                                                                 		 data.startport = undefined; | ||||||
| @ -1389,6 +1440,32 @@ | |||||||
|                                                         }); |                                                         }); | ||||||
|                                                         jQuery('#details-tab-aclRules').siblings('div.toolbar').append($addAclRuleDivButton); |                                                         jQuery('#details-tab-aclRules').siblings('div.toolbar').append($addAclRuleDivButton); | ||||||
|                                                     } |                                                     } | ||||||
|  |                                                     if(jQuery('#details-tab-aclRules').siblings('div.toolbar').children('div.export').size() === 0){ | ||||||
|  |                                                         var $exportAclsDivButton = jQuery('<div>').addClass('button export'); | ||||||
|  |                                                         var $linkExportAclRulesButtonMessage = jQuery('<a>').html(_l('label.acl.export')); | ||||||
|  |                                                          | ||||||
|  |                                                         $exportAclsDivButton.html($linkExportAclRulesButtonMessage); | ||||||
|  |                                                         $exportAclsDivButton.click(function(){ | ||||||
|  |                                                              | ||||||
|  |                                                             $.ajax({ | ||||||
|  |                                                                 url: createURL('listNetworkACLs&aclid=' + aclListId), | ||||||
|  |                                                                 type: "GET", | ||||||
|  |                                                                 async: false, | ||||||
|  |                                                                 success: function(json) { | ||||||
|  |                                                                     var acls = json.listnetworkaclsresponse.networkacl; | ||||||
|  |                                                                     var csv = generateCsvForAclRules(acls); | ||||||
|  |                                                                      | ||||||
|  |                                                                     window.URL = window.URL || window.webkiURL; | ||||||
|  |                                                                     var blob = new Blob([csv]); | ||||||
|  |                                                                     var blobURL = window.URL.createObjectURL(blob); | ||||||
|  |                                                                      | ||||||
|  |                                                                     $linkExportAclRulesButtonMessage.attr("href", blobURL); | ||||||
|  |                                                                     $linkExportAclRulesButtonMessage.attr("download", "aclRules.csv"); | ||||||
|  |                                                                 } | ||||||
|  |                                                             }); | ||||||
|  |                                                         }); | ||||||
|  |                                                         jQuery('#details-tab-aclRules').siblings('div.toolbar').append($exportAclsDivButton); | ||||||
|  |                                                     } | ||||||
|                                                 } |                                                 } | ||||||
|                                             }); |                                             }); | ||||||
|                                         } |                                         } | ||||||
| @ -4371,18 +4448,6 @@ | |||||||
|                                     return capability.name == 'LbSchemes'; |                                     return capability.name == 'LbSchemes'; | ||||||
|                                 }) : []; |                                 }) : []; | ||||||
| 
 | 
 | ||||||
|                                 /*      var lbSchemes = $.grep( |  | ||||||
|                   $.grep( |  | ||||||
|                     tier.service, |  | ||||||
|                     function(service) { |  | ||||||
|                       return service.name == 'Lb'; |  | ||||||
|                     } |  | ||||||
|                   )[0].capability, |  | ||||||
|                   function(capability) { |  | ||||||
|                     return capability.name == 'LbSchemes'; |  | ||||||
|                   } |  | ||||||
|                 );*/ |  | ||||||
| 
 |  | ||||||
|                                 var hasLbScheme = function(schemeVal) { |                                 var hasLbScheme = function(schemeVal) { | ||||||
|                                     return $.grep( |                                     return $.grep( | ||||||
|                                         lbSchemes, |                                         lbSchemes, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user