Add an 'add node' form

feature/node-rewrite
Sven Slootweg 12 years ago
parent 40c253b80d
commit 72deb3242c

@ -481,8 +481,8 @@ input
input, label
{
/*margin-top: 0px !important;*/
margin-bottom: 0px !important;
/*margin-top: 0px !important;
margin-bottom: 0px !important;*/
}
button.column
@ -530,3 +530,85 @@ button.column
margin-right: 4px;
margin-top: 7px;
}
.toolbar
{
/*background-color: #D4D5E0;
padding: 4px;*/
margin-bottom: 8px;
margin-top: 7px;
}
.toolbar a
{
display: block;
float: left;
color: white;
padding: 4px 6px;
text-decoration: none;
background-color: #5D5C79;
font-weight: bold;
font-size: 15px;
}
.toolbar a:hover
{
background-color: #4E4D69;
}
form.add
{
background-color: #31305E;
color: white;
padding: 2px 0.5%;
font-size: 15px;
font-weight: bold;
width: 75%;
}
form.add label, form.add .filler
{
display: block;
float: left;
margin: 3px 1%;
width: 45.8%;
}
form.add input
{
display: block;
float: left;
width: 48%;
border: 0px;
margin: 3px 0.4%;
padding: 4px 2%;
}
form.add input[type="checkbox"]
{
width: auto;
margin-top: 7px;
}
form.add input[type="file"]
{
height: 24px;
font-size: 13px;
margin-top: 4px;
margin-bottom: 0px;
padding: 0px 0px;
}
form.add button[type="submit"]
{
float: right;
margin: 9px 7px 7px 7px;
font-size: 15px;
font-weight: bold;
}
form.add .field.disabled
{
background-color: #444452;
color: #B5B5B5;
}

@ -23,4 +23,5 @@ define("CVM_STATUS_STOPPED", 5 );
define("CVM_STATUS_SUSPENDED", 6 );
define("CVM_STATUS_TERMINATED", 7 );
define("REGEX_HOSTNAME", "/(([a-zA-Z0-9-]+\.)+)([a-zA-Z0-9-]+)/");
?>

@ -18,4 +18,29 @@ $(function(){
command_running = true;
}
});
$('.enabler').change(function(){
var group = $(this).data("enable-group");
if($(this).is(':checked'))
{
$('.disabled').each(function(index, item){
if($(item).data("disabled-group") == group)
{
$(item).children('input').removeAttr('disabled');
$(item).removeClass('disabled');
}
});
}
else
{
$('form .field').each(function(index, item){
if($(item).data("disabled-group") == group)
{
$(item).children('input').attr('disabled', 'disabled');
$(item).addClass('disabled');
}
});
}
})
});

@ -240,4 +240,7 @@ error-restart-start-text; Your container could not be started. If this erro
error-admin-nodes-add-name; You did not fill in a valid name.
error-admin-nodes-add-hostname; You did not fill in a valid hostname.
error-admin-nodes-add-location; You did not fill in a valid physical location.
error-form; One or more fields were not filled in correctly.
error-admin-nodes-add-publickey; You did not upload a valid public key.
error-admin-nodes-add-privatekey; You did not upload a valid private key.
error-admin-nodes-add-upload; Something went wrong while processing the uploaded keys. Ensure that the keys directory is writable.
error-form; One or more problems occurred.

@ -0,0 +1,84 @@
<?php
/*
* CVM is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_CVM)) { die("Unauthorized."); }
$sErrors = array();
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
{
$sErrors[] = $locale->strings['error-admin-nodes-add-name'];
}
if(empty($_POST['hostname']) || preg_match(REGEX_HOSTNAME, $_POST['hostname']) === 0)
{
$sErrors[] = $locale->strings['error-admin-nodes-add-hostname'];
}
if(empty($_POST['location']))
{
$sErrors[] = $locale->strings['error-admin-nodes-add-location'];
}
if(isset($_POST['customkey']))
{
$sKeyId = random_string(20);
if($_FILES["publickey"]["error"] == UPLOAD_ERR_OK)
{
$sPublicKeyName = "{$sKeyId}.public.key";
}
else
{
$sErrors[] = $locale->strings['error-admin-nodes-add-publickey'];
}
if($_FILES["privatekey"]["error"] == UPLOAD_ERR_OK)
{
$sPrivateKeyName = "{$sKeyId}.private.key";
}
else
{
$sErrors[] = $locale->strings['error-admin-nodes-add-privatekey'];
}
}
if(empty($sErrors))
{
if(isset($_POST['customkey']) == false ||
(move_uploaded_file($_FILES['publickey']['tmp_name'], "/etc/cvm/keys/{$sPublicKeyName}") &&
move_uploaded_file($_FILES['privatekey']['tmp_name'], "/etc/cvm/keys/{$sPrivateKeyName}")))
{
$sNode = new Node(0);
$sNode->uName = $_POST['name'];
$sNode->uHostname = $_POST['hostname'];
$sNode->uPhysicalLocation = $_POST['location'];
$sNode->uHasCustomKey = isset($_POST['customkey']);
$sNode->uPublicKey = $sPublicKeyName;
$sNode->uPrivateKey = $sPrivateKeyName;
$sNode->InsertIntoDatabase();
redirect("/admin/nodes/");
}
else
{
$sErrors[] = $locale->strings['error-admin-nodes-add-upload'];
}
}
}
$sPageContents = Templater::AdvancedParse("admin.nodes.add", $locale->strings, array(
'errors' => $sErrors
));

@ -169,6 +169,13 @@ try
'auth_error' => "error.access.php",
'_menu' => "admin"
),
/* Admin - Nodes - Add */
'^/admin/nodes/add/?$' => array(
'target' => "module.admin.nodes.add.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/test/?$' => "module.test.php"
)
);

@ -0,0 +1,58 @@
<h2>{%!title-admin-addnode}</h2>
{%if isempty|errors == false}
<div class="errorhandler error-error">
<div class="error-title">{%!error-form}</div>
<div class="error-message">
<ul>
{%foreach error in errors}
<li>{%?error}</li>
{%/foreach}
</ul>
</div>
</div>
{%/if}
<form enctype="multipart/form-data" method="post" action="/admin/nodes/add/" class="add">
<div class="field">
<label for="form_addnode_name">{%!addnode-name}</label>
{%input type="text" group="addnode" name="name"}
<div class="clear"></div>
</div>
<div class="field">
<label for="form_addnode_hostname">{%!addnode-hostname}</label>
{%input type="text" group="addnode" name="hostname"}
<div class="clear"></div>
</div>
<div class="field">
<label for="form_addnode_location">{%!addnode-location}</label>
{%input type="text" group="addnode" name="location"}
<div class="clear"></div>
</div>
<div class="field">
<label for="form_addnode_customkey">{%!addnode-customkeypair}</label>
{%input type="checkbox" group="addnode" name="customkey" data-enable-group="customkey" class="enabler"}
<div class="clear"></div>
</div>
<div class="disabled field" data-disabled-group="customkey">
<label for="form_addnode_publickey">{%!addnode-publickey}</label>
{%input type="file" group="addnode" name="publickey" disabled="disabled"}
<div class="clear"></div>
</div>
<div class="disabled field" data-disabled-group="customkey">
<label for="form_addnode_privatekey">{%!addnode-privatekey}</label>
{%input type="file" group="addnode" name="privatekey" disabled="disabled"}
<div class="clear"></div>
</div>
<div class="field">
<div class="filler"></div>
<button type="submit" name="submit">{%!button-admin-addnode}</button>
<div class="clear"></div>
</div>
</form>

@ -1,5 +1,10 @@
<h2>{%!title-admin-nodelist}</h2>
<div class="toolbar">
<a href="/admin/nodes/add/">Add node</a>
<div class="clear"></div>
</div>
<table class="vpslist">
<tr>
<th>{%!list-column-hostname}</th>

Loading…
Cancel
Save