Add an 'add node' form
parent
40c253b80d
commit
72deb3242c
@ -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
|
||||
));
|
@ -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>
|
Loading…
Reference in New Issue