Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.1",
"version": "1.1.0",
"name": "Enhance.name",
"description": "Enhance.description",
"authors": [
Expand Down
44 changes: 42 additions & 2 deletions enhance.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function manageEditRow($module_row, array &$vars)
*/
public function addModuleRow(array &$vars)
{
$meta_fields = ['server_label', 'hostname', 'org_id', 'api_token'];
$meta_fields = ['server_label', 'hostname', 'org_id', 'api_token', 'name_servers'];
$encrypted_fields = [];

// Set unset checkboxes
Expand Down Expand Up @@ -189,7 +189,7 @@ public function addModuleRow(array &$vars)
*/
public function editModuleRow($module_row, array &$vars)
{
$meta_fields = ['server_label','hostname','org_id','api_token'];
$meta_fields = ['server_label','hostname','org_id','api_token','name_servers'];
$encrypted_fields = [];

$this->Input->setRules($this->getRowRules($vars));
Expand Down Expand Up @@ -255,6 +255,16 @@ private function getRowRules(&$vars)
],
'message' => Language::_('Enhance.!error.api_token.valid', true)
]
],
'name_servers' => [
'count' => [
'rule' => [[$this, 'validateNameServerCount']],
'message' => Language::_('Enhance.!error.name_servers.count', true)
],
'format' => [
'rule' => [[$this, 'validateNameServers']],
'message' => Language::_('Enhance.!error.name_servers.format', true)
]
]
];

Expand All @@ -273,6 +283,36 @@ public function validateHostName($host_name)
return $validator->isDomain($host_name) || $validator->isIp($host_name);
}

/**
* Validates that at least 2 name servers are set in the given array of name servers.
*
* @param array $name_servers An array of name servers
* @return bool True if the array count is >= 2, false otherwise
*/
public function validateNameServerCount($name_servers)
{
return is_array($name_servers) && count($name_servers) >= 2;
}

/**
* Validates that the given name servers are formatted correctly.
*
* @param array $name_servers An array of name servers
* @return bool True if every name server is formatted correctly, false otherwise
*/
public function validateNameServers($name_servers)
{
if (is_array($name_servers)) {
foreach ($name_servers as $name_server) {
if (!$this->validateHostName($name_server)) {
return false;
}
}
}

return true;
}

/**
* Validates the API connection
*
Expand Down
14 changes: 14 additions & 0 deletions language/en_us/enhance.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@
// Add row
$lang['Enhance.add_row.box_title'] = 'Enhance - Add Server';
$lang['Enhance.add_row.add_btn'] = 'Add Server';
$lang['Enhance.add_row.name_servers_title'] = 'Name Servers';
$lang['Enhance.add_row.name_server_btn'] = 'Add Additional Name Server';
$lang['Enhance.add_row.name_server_col'] = 'Name Server';
$lang['Enhance.add_row.name_server_host_col'] = 'Hostname';
$lang['Enhance.add_row.name_server'] = 'Name server %1$s'; // %1$s is the name server number (e.g. 3)
$lang['Enhance.add_row.remove_name_server'] = 'Remove';


// Edit row
$lang['Enhance.edit_row.box_title'] = 'Enhance - Edit Server';
$lang['Enhance.edit_row.edit_btn'] = 'Update Server';
$lang['Enhance.edit_row.name_servers_title'] = 'Name Servers';
$lang['Enhance.edit_row.name_server_btn'] = 'Add Additional Name Server';
$lang['Enhance.edit_row.name_server_col'] = 'Name Server';
$lang['Enhance.edit_row.name_server_host_col'] = 'Hostname';
$lang['Enhance.edit_row.name_server'] = 'Name server %1$s'; // %1$s is the name server number (e.g. 3)
$lang['Enhance.edit_row.remove_name_server'] = 'Remove';


// Row meta
Expand All @@ -64,6 +76,8 @@
$lang['Enhance.!error.org_id.empty'] = 'Please enter an organization ID.';
$lang['Enhance.!error.api_token.empty'] = 'Please enter an API token.';
$lang['Enhance.!error.api_token.valid'] = 'Unable to connect to the Enhance server. Please verify your API credentials.';
$lang['Enhance.!error.name_servers.count'] = 'You must define at least 2 name servers.';
$lang['Enhance.!error.name_servers.format'] = 'One or more of the name servers entered are invalid.';
$lang['Enhance.!error.module_row.missing'] = 'An internal error occurred. The module row is unavailable.';
$lang['Enhance.!error.domain.format'] = 'Please enter a valid domain name.';
$lang['Enhance.!error.username.format'] = 'The username may contain only letters, numbers, dashes, and underscores and must be between 3 and 16 characters in length.';
Expand Down
70 changes: 70 additions & 0 deletions views/default/add_row.pdt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,38 @@
</li>
</ul>
</div>
<div class="title_row">
<h3><?php $this->_('Enhance.add_row.name_servers_title');?></h3>
</div>
<div class="pad">
<div class="links_row">
<a class="btn btn-default pull-right btn-sm ns_row_add" href="#"><i class="fa fa-plus"></i> <span><?php $this->_('Enhance.add_row.name_server_btn');?></span></a>
</div>
<table class="table">
<thead>
<tr class="heading_row">
<td><?php $this->Form->label($this->_('Enhance.add_row.name_server_col', true));?></td>
<td><?php $this->Form->label($this->_('Enhance.add_row.name_server_host_col', true));?></td>
<td class="last"></td>
</tr>
</thead>
<tbody>
<?php
$num_servers = count($vars->name_servers ?? []);
for ($i = 0; $i < max(2, $num_servers); $i++) {
?>
<tr class="ns_row<?php echo ($i % 2 == 1) ? ' odd_row' : '';?>">
<td><?php $this->_('Enhance.add_row.name_server', false, '<span>' . ($i + 1) . '</span>');?></td>
<td><?php $this->Form->fieldText('name_servers[]', $vars->name_servers[$i] ?? null, ['class' => 'block']);?></td>
<td><a href="#" class="manage ns_row_remove"><?php $this->_('Enhance.add_row.remove_name_server');?></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>

<div class="button_row">
<?php
$this->Form->fieldSubmit('save', $this->_('Enhance.add_row.add_btn', true), ['class' => 'btn btn-primary pull-right']);
Expand All @@ -46,3 +78,41 @@
</div>
<?php
$this->Widget->end();
?>
<script type="text/javascript">
$(document).ready(function() {
// Add a row
$('.ns_row_add').click(function() {
var fields = $('tr.ns_row:first').clone(true);
$(fields).find('input').val('');
$('td:first span', fields).text($('tr.ns_row').length+1);
$('tr.ns_row:last').after(fields);
updateNsRows();
return false;
});
// Remove a row
$('.ns_row_remove').click(function() {
if ($('tr.ns_row').length > 1) {
$(this).closest('tr').remove();
// Reorder the counts for these rows
$i=1;
$('tr.ns_row').each(function() {
$('td:first span', this).text($i++);
});
}
updateNsRows();
return false;
});
});

// Zebra-stripe name server rows
function updateNsRows() {
var i = 0;
$('tr.ns_row').each(function() {
if (i++%2 == 1)
$(this).addClass('odd_row');
else
$(this).removeClass('odd_row');
});
}
</script>
70 changes: 70 additions & 0 deletions views/default/edit_row.pdt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@
</ul>
</div>

<div class="title_row">
<h3><?php $this->_('Enhance.edit_row.name_servers_title');?></h3>
</div>
<div class="pad">
<div class="links_row">
<a class="btn btn-default pull-right btn-sm ns_row_add" href="#"><i class="fa fa-plus"></i> <span><?php $this->_('Enhance.edit_row.name_server_btn');?></span></a>
</div>
<table class="table">
<thead>
<tr class="heading_row">
<td><?php $this->Form->label($this->_('Enhance.edit_row.name_server_col', true));?></td>
<td><?php $this->Form->label($this->_('Enhance.edit_row.name_server_host_col', true));?></td>
<td class="last"></td>
</tr>
</thead>
<tbody>
<?php
$num_servers = count($vars->name_servers ?? []);
for ($i = 0; $i < max(2, $num_servers); $i++) {
?>
<tr class="ns_row<?php echo ($i % 2 == 1) ? ' odd_row' : '';?>">
<td><?php $this->_('Enhance.edit_row.name_server', false, '<span>' . ($i + 1) . '</span>');?></td>
<td><?php $this->Form->fieldText('name_servers[]', $vars->name_servers[$i] ?? null, ['class' => 'block']);?></td>
<td><a href="#" class="manage ns_row_remove"><?php $this->_('Enhance.edit_row.remove_name_server');?></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>

<div class="button_row">
<?php
$this->Form->fieldSubmit('save', $this->_('Enhance.edit_row.edit_btn', true), ['class' => 'btn btn-primary pull-right']);
Expand All @@ -47,3 +79,41 @@
</div>
<?php
$this->Widget->end();
?>
<script type="text/javascript">
$(document).ready(function() {
// Add a row
$('.ns_row_add').click(function() {
var fields = $('tr.ns_row:first').clone(true);
$(fields).find('input').val('');
$('td:first span', fields).text($('tr.ns_row').length+1);
$('tr.ns_row:last').after(fields);
updateNsRows();
return false;
});
// Remove a row
$('.ns_row_remove').click(function() {
if ($('tr.ns_row').length > 1) {
$(this).closest('tr').remove();
// Reorder the counts for these rows
$i=1;
$('tr.ns_row').each(function() {
$('td:first span', this).text($i++);
});
}
updateNsRows();
return false;
});
});

// Zebra-stripe name server rows
function updateNsRows() {
var i = 0;
$('tr.ns_row').each(function() {
if (i++%2 == 1)
$(this).addClass('odd_row');
else
$(this).removeClass('odd_row');
});
}
</script>