ture #3748: Security Group create wizard

This commit is contained in:
Carlos Martín committed 2015-06-01 19:02:31 +02:00
1 parent be7f4d7fa6
commit 22dbb04029
7 files changed
+509 -23

No files matched your search

@@ -14,6 +14,10 @@ define(function(require) {
require('./secgroups-tab/panels/info')
];
var _formPanels = [
require('./secgroups-tab/form-panels/create')
];
var Tab = {
tabId: TAB_ID,
title: Locale.tr("Security Groups"),
@@ -27,6 +31,7 @@ define(function(require) {
actions: Actions,
dataTable: new Table(DATATABLE_ID, {actions: true, info: true}),
panels: _panels,
formPanels: _formPanels,
dialogs: _dialogs
};
@@ -6,35 +6,31 @@ define(function(require) {
var OpenNebulaSecurityGroup = require('opennebula/securitygroup');
var TAB_ID = require('./tabId');
// TODO
//var CREATE_DIALOG_ID = require('./dialogs/create/dialogId');
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
var _actions = {
/*
TODO
"SecurityGroup.create" : {
type: "create",
call: OpenNebulaSecurityGroup.create,
callback: function(request, response){
$("a[href=back]", $("#secgroups-tab")).trigger("click");
popFormDialog("create_security_group_form", $("#secgroups-tab"));
addSecurityGroupElement(request, response);
notifyCustom(tr("Security Group created"), " ID: " + response.SECURITY_GROUP.ID, false);
},
error: function(request, response){
popFormDialog("create_security_group_form", $("#secgroups-tab"));
onError(request, response);
}
"SecurityGroup.create" : {
type: "create",
call: OpenNebulaSecurityGroup.create,
callback: function(request, response) {
Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID);
Sunstone.hideFormPanel(TAB_ID);
Sunstone.getDataTable(TAB_ID).addElement(request, response);
},
error: function(request, response) {
Sunstone.hideFormPanelLoading(TAB_ID);
Notifier.onError(request, response);
},
notify: true
},
"SecurityGroup.create_dialog" : {
type: "custom",
call: function(){
Sunstone.popUpFormPanel("create_security_group_form", "secgroups-tab", "create", true);
}
type: "custom",
call: function() {
Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create");
}
},
*/
"SecurityGroup.list" : {
type: "list",
@@ -0,0 +1,296 @@
define(function(require) {
/*
DEPENDENCIES
*/
require('foundation.tab');
var BaseFormPanel = require('utils/form-panels/form-panel');
var Sunstone = require('sunstone');
var Locale = require('utils/locale');
var Tips = require('utils/tips');
var TemplateUtils = require('utils/template-utils');
var WizardFields = require('utils/wizard-fields');
var VNetsTable = require('tabs/vnets-tab/datatable');
var Utils = require('../utils/common');
/*
TEMPLATES
*/
var TemplateWizardHTML = require('hbs!./create/wizard');
var TemplateAdvancedHTML = require('hbs!./create/advanced');
/*
CONSTANTS
*/
var FORM_PANEL_ID = require('./create/formPanelId');
var TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function FormPanel() {
this.formPanelId = FORM_PANEL_ID;
this.tabId = TAB_ID;
this.actions = {
'create': {
'title': Locale.tr("Create Security Group"),
'buttonText': Locale.tr("Create"),
'resetButton': true
},
'update': {
'title': Locale.tr("Update Security Group"),
'buttonText': Locale.tr("Update"),
'resetButton': false
}
};
BaseFormPanel.call(this);
}
FormPanel.FORM_PANEL_ID = FORM_PANEL_ID;
FormPanel.prototype = Object.create(BaseFormPanel.prototype);
FormPanel.prototype.constructor = FormPanel;
FormPanel.prototype.htmlWizard = _htmlWizard;
FormPanel.prototype.htmlAdvanced = _htmlAdvanced;
FormPanel.prototype.submitWizard = _submitWizard;
FormPanel.prototype.submitAdvanced = _submitAdvanced;
FormPanel.prototype.onShow = _onShow;
FormPanel.prototype.fill = _fill;
FormPanel.prototype.setup = _setup;
return FormPanel;
/*
FUNCTION DEFINITIONS
*/
function _htmlWizard() {
var opts = {
info: false,
select: true
};
this.vnetsTable = new VNetsTable("new_sg_rule", opts);
return TemplateWizardHTML({
'formPanelId': this.formPanelId,
'vnetsTableHTML': this.vnetsTable.dataTableHTML
});
}
function _htmlAdvanced() {
return TemplateAdvancedHTML({formPanelId: this.formPanelId});
}
function _setup(context) {
var that = this;
context.off("change", '.security_group_rule_protocol');
context.on("change", '.security_group_rule_protocol', function(){
$('.range_row', context).hide();
$('.range_row input', context).removeAttr('required');
$('.icmp_type_wrapper', context).hide();
switch ($(this).val()) {
case "TCP":
case "UDP":
$('.range_row', context).show();
$(".range_row select", context).trigger("change");
break;
case "ICMP":
$('.icmp_type_wrapper', context).show();
break;
case "IPSEC":
case "ALL":
break;
}
});
context.off("change", '.security_group_rule_network_sel');
context.on("change", '.security_group_rule_network_sel', function(){
$('.security_group_rule_network',context).hide();
$('div.security_group_rule_network input',context).removeAttr('required');
that.vnetsTable.idInput().removeAttr("required");
$('.vnet_select',context).hide();
switch ($(this).val()) {
case "ANY":
break;
case "NETWORK":
$('.security_group_rule_network',context).show();
$('div.security_group_rule_network input',context).attr('required', '');
break;
case "VNET":
$('.vnet_select',context).show();
that.vnetsTable.idInput().attr("required", "");
that.vnetsTable.refreshResourceTableSelect();
break;
}
});
context.off("change", '.security_group_rule_range_sel');
context.on("change", '.security_group_rule_range_sel', function(){
switch ($(this).val()) {
case "ALL":
$('.security_group_rule_range', context).hide();
$(".security_group_rule_range input", context).removeAttr('required');
break;
case "RANGE":
$('.security_group_rule_range', context).show();
$(".security_group_rule_range input", context).attr('required', '');
break;
}
});
$('#rules_form_wizard',context).off('invalid');
$('#rules_form_wizard',context).off('valid');
$('#rules_form_wizard',context).on('invalid', function () {
}).on('valid', function() {
var rule = {};
rule["PROTOCOL"] = $(".security_group_rule_protocol", context).val();
rule["RULE_TYPE"] = $(".security_group_rule_type", context).val();
switch ($('.security_group_rule_range_sel', context).val()) {
case "ALL":
break;
case "RANGE":
rule["RANGE"] = $(".security_group_rule_range input", context).val();
break;
}
switch ($('.security_group_rule_network_sel', context).val()) {
case "ANY":
break;
case "NETWORK":
rule["IP"] = $('#security_group_rule_first_ip', context).val();
rule["SIZE"] = $('#security_group_rule_size', context).val();
break;
case "VNET":
rule["NETWORK_ID"] = that.vnetsTable.retrieveResourceTableSelect();
break;
}
if (rule["PROTOCOL"] == "ICMP" ){
var icmp_type_val = $(".security_group_rule_icmp_type", context).val();
if (icmp_type_val != ""){
rule["ICMP_TYPE"] = icmp_type_val;
}
}
var text = Utils.sgRuleToSt(rule);
$(".security_group_rules tbody", context).append(
'<tr>\
<td>'+text.PROTOCOL+'</td>\
<td>'+text.RULE_TYPE+'</td>\
<td>'+text.RANGE+'</td>\
<td>'+text.NETWORK+'</td>\
<td>'+text.ICMP_TYPE+'</td>\
<td>\
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>\
</td>\
</tr>');
// Add data to tr element
$(".security_group_rules tbody", context).children("tr").last().data("rule", rule);
// Reset new rule fields
$('#new_rule_wizard select option', context).prop('selected', function() {
return this.defaultSelected;
});
$('#new_rule_wizard select', context).trigger("change");
$('#new_rule_wizard input', context).val("");
that.vnetsTable.resetResourceTableSelect();
});
context.off("click", ".security_group_rules i.remove-tab");
context.on("click", ".security_group_rules i.remove-tab", function(){
var tr = $(this).closest('tr');
tr.remove();
});
context.foundation();
this.vnetsTable.initialize();
Tips.setup();
$('#new_rule_wizard select', context).trigger("change");
return false;
}
function _submitWizard(context) {
var name = $('#security_group_name', context).val();
var description = $('#security_group_description', context).val();
var rules = [];
$(".security_group_rules tbody tr").each(function(){
rules.push($(this).data("rule"));
});
var security_group_json = {
"NAME" : name,
"DESCRIPTION": description,
"RULE" : rules
};
if (this.action == "create") {
security_group_json = {
"security_group" : security_group_json
};
Sunstone.runAction("SecurityGroup.create",security_group_json);
return false;
} else if (this.action == "update") {
delete security_group_json["NAME"];
Sunstone.runAction(
"SecurityGroup.update",
this.resourceId,
TemplateUtils.templateToString(security_group_json));
return false;
}
}
function _submitAdvanced(context) {
if (this.action == "create") {
var template = $('textarea#template', context).val();
var security_group_json = {security_group: {security_group_raw: template}};
Sunstone.runAction("SecurityGroup.create",security_group_json);
return false;
} else if (this.action == "update") {
var template_raw = $('textarea#template', context).val();
Sunstone.runAction("SecurityGroup.update", this.resourceId, template_raw);
return false;
}
}
function _onShow(context) {
this.vnetsTable.refreshResourceTableSelect();
}
function _fill(context, element) {
this.resourceId = element.ID;
// TODO
}
});
@@ -0,0 +1,12 @@
<form data-abide="ajax" id="{{formPanelId}}Advanced" class="custom creation">
<div class="row">
<div class="large-12 columns">
<p>{{tr "Write the Security Group template here"}}</p>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<textarea id="template" rows="15" required></textarea>
</div>
</div>
</form>
@@ -0,0 +1,3 @@
define(function(require){
return 'createSecurityGroupForm';
});
@@ -0,0 +1,137 @@
<div id="create_security_group_form_wrapper">
<form data-abide="ajax" id="{{formPanelId}}Wizard" class="custom creation">
<div class="row">
<div class="medium-4 columns">
<label for="security_group_name">{{tr "Security Group Name"}}:</label>
<input required type="text" name="security_group_name" id="security_group_name"/>
</div>
<div class="medium-8 columns">
<label for="security_group_description">{{tr "Description"}}
<span class="tip">{{tr "Description for the Security Group"}}</span>
</label>
<textarea type="text" id="security_group_description" name="security_group_description" style="height: 70px;"/>
</div>
</div>
<hr/>
</form>
<form data-abide="ajax" id="rules_form_wizard" action="">
<div class="row collapse" id="new_rule_wizard">
<div class="row">
<div class="medium-4 columns">
<label>{{tr "Type"}}
<span class="tip">{{tr "Defines the direction of the rule."}}</span>
</label>
<select class="security_group_rule_type">
<option value="inbound" selected="selected">{{tr "Inbound"}}</option>
<option value="outbound">{{tr "Outbound"}}</option>
</select>
</div>
<div class="medium-4 columns">
<label>{{tr "Protocol"}}
<span class="tip">{{tr "Defines the protocol of the rule."}}</span>
</label>
<select class="security_group_rule_protocol">
<option value="TCP" selected="selected">{{tr "TCP"}}</option>
<option value="UDP">{{tr "UDP"}}</option>
<option value="ICMP">{{tr "ICMP"}}</option>
<option value="IPSEC">{{tr "IPsec"}}</option>
<option value="ALL">{{tr "All"}}</option>
</select>
</div>
<div class="medium-4 columns icmp_type_wrapper">
<label>{{tr "ICMP Type"}}
<span class="tip">{{tr "Specific ICMP type of the rule. If a type has multiple codes, it includes all the codes within."}}</span>
</label>
<select class="security_group_rule_icmp_type">
<option value="" selected="selected">{{tr "All"}}</option>
<option value = "0">0/0: Echo Reply (pong)</option>
<option value = "3">3: Destination Unreachable</option>
<option value = "4">4/0: Source Quench</option>
<option value = "5">5: Redirect</option>
<option value = "8">8/0: Echo Request (ping)</option>
<option value = "9">9/0: Router Advertisement</option>
<option value = "10">10/0: Router Solicitation</option>
<option value = "11">11: Time Exceeded</option>
<option value = "12">12: Parameter Problem</option>
<option value = "13">13/0: Timestamp Request</option>
<option value = "14">14/0: Timestamp Reply</option>
<option value = "17">17/0: Address Mask Request</option>
<option value = "18">18/0: Address Mask Reply</option>
</select>
</div>
</div>
<div class="row range_row">
<div class="medium-4 columns">
<label>{{tr "Port range"}}
<span class="tip">{{tr "Selects whether to apply this TCP or UDP rule to all the ports or just a specific set."}}</span>
</label>
<select class="security_group_rule_range_sel">
<option value="ALL" selected="selected">{{tr "All"}}</option>
<option value="RANGE">{{tr "Port range"}}</option>
</select>
</div>
<div class="medium-4 columns end security_group_rule_range">
<label>{{tr "Iptables range"}}
<span class="tip">{{tr "A Port Range to filter specific ports. Uses the iptables port syntax: port[,port|,port:port]..."}}</span>
</label>
<input type="text" placeholder="22,53,80:90,110,1024:65535"/>
</div>
</div>
<div class="row">
<div class="medium-4 columns">
<label>{{tr "Network"}}
<span class="tip">{{tr "Any: apply this rule to any connection regardless of its source or destination. Network: Apply this rule only to a custom defined network range. Virtual Network: Apply this rule only to connections with origin or destination in one of the already defined VNETs."}}</span>
</label>
<select class="security_group_rule_network_sel">
<option value="ANY" selected="selected">{{tr "Any"}}</option>
<option value="NETWORK">{{tr "Network"}}</option>
<option value="VNET">{{tr "Virtual Network"}}</option>
</select>
</div>
<div class="medium-4 columns security_group_rule_network">
<label for="security_group_rule_first_ip">{{tr "IP Start"}}:
<span class="tip">{{tr "First IP address"}}</span>
</label>
<input id="security_group_rule_first_ip" type="text" placeholder="192.168.10.1"/>
</div>
<div class="medium-4 columns security_group_rule_network">
<label for="security_group_rule_size">{{tr "Size"}}:
<span class="tip">{{tr "Number of addresses in the range"}}</span>
</label>
<input id="security_group_rule_size" type="text" placeholder="254"/>
</div>
</div>
<div class="row">
<div class="small-12 columns vnet_select">
{{{vnetsTableHTML}}}
<br/>
</div>
</div>
</div>
<div class="row">
<div class="medium-8 small-centered columns">
<button type="submit" class="add_security_group_rule button small small-12 radius">
<i class="fa fa-angle-double-down"></i> {{tr "Add Rule"}}
</button>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<table class="security_group_rules policies_table dataTable">
<thead>
<tr>
<th>{{tr "Protocol"}}</th>
<th>{{tr "Type"}}</th>
<th>{{tr "Port Range"}}</th>
<th>{{tr "Network"}}</th>
<th>{{tr "ICMP Type"}}</th>
<th style="width:3%"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</form>
</div>
@@ -61,7 +61,7 @@ define(function(require) {
}
if(rule.ICMP_TYPE != undefined){
text["ICMP_TYPE"] = icmp_to_st(rule.ICMP_TYPE);
text["ICMP_TYPE"] = _icmpToSt(rule.ICMP_TYPE);
} else {
text["ICMP_TYPE"] = "";
}
@@ -101,6 +101,43 @@ define(function(require) {
return text;
}
function _icmpToSt(icmp_type){
switch( icmp_type ){
case "": return tr("All");
case "0": return "0: Echo Reply";
case "3": return "3: Destination Unreachable";
case "4": return "4: Source Quench";
case "5": return "5: Redirect";
case "6": return "6: Alternate Host Address";
case "8": return "8: Echo";
case "9": return "9: Router Advertisement";
case "10": return "10: Router Solicitation";
case "11": return "11: Time Exceeded";
case "12": return "12: Parameter Problem";
case "13": return "13: Timestamp";
case "14": return "14: Timestamp Reply";
case "15": return "15: Information Request";
case "16": return "16: Information Reply";
case "17": return "17: Address Mask Request";
case "18": return "18: Address Mask Reply";
case "30": return "30: Traceroute";
case "31": return "31: Datagram Conversion Error";
case "32": return "32: Mobile Host Redirect";
case "33": return "33: IPv6 Where-Are-You";
case "34": return "34: IPv6 I-Am-Here";
case "35": return "35: Mobile Registration Request";
case "36": return "36: Mobile Registration Reply";
case "37": return "37: Domain Name Request";
case "38": return "38: Domain Name Reply";
case "39": return "39: SKIP";
case "40": return "40: Photuris";
case "41": return "41: ICMP messages utilized by experimental mobility protocols such as Seamoby";
case "253": return "253: RFC3692-style Experiment 1";
case "254": return "254: RFC3692-style Experiment 2";
default: return "" + icmp_type;
}
}
/*
@param {Object} info Object representing the Security Group as returned by OpenNebula
*/