Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions code/admin/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<fieldset label="COM_API" name="api">
<field name="force_output" type="text" label="COM_API_FORM_LBL_FORCE_OUTPUT"
description="COM_API_FORM_DESC_FORCE_OUTPUT" />
<field name="request_limit_time" type="radio" default="hour"
label="COM_API_CONFIG_REQ_LT_LBL" description="COM_API_CONFIG_REQ_LT_DESC"
class="btn-group">
<option value="hour">Hour</option>
Comment thread
ankush-maherwal marked this conversation as resolved.
Outdated
<option value="minute">Minute</option>
<option value="day">Day</option>
</field>
<field name="request_limit" type="text" label="COM_API_FORM_LBL_RATE_LIMIT"
description="COM_API_FORM_LBL_RATE_LIMIT_DESC" />
<field name="log_requests" type="radio" default="0"
Expand All @@ -23,6 +30,8 @@
<option value="get">GET</option>
<option value="*">ALL</option>
</field>
<field name="ip_address" type="textarea" default="*" columns="5"
label="COM_API_CONFIG_IPS_LBL" description="COM_API_CONFIG_IPS_DESC" />
<field name="cors" type="textarea" default="*" columns="5"
label="COM_API_CONFIG_CORS_LBL" description="COM_API_CONFIG_CORS_DESC" />
<field name="allow_headers" type="textarea" default="Authorization, Access-Control-Allow-Origin, Access-Control-Allow-Methods, X-Authorization, X-Compatibility-Mode, Content-Type, Accept" columns="5"
Expand Down
5 changes: 3 additions & 2 deletions code/admin/controllers/keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Factory;
use Joomla\Utilities\ArrayHelper;

/**
* Keys list controller class.
Expand Down Expand Up @@ -52,8 +53,8 @@ public function saveOrderAjax()
$order = $input->post->get('order', array(), 'array');

// Sanitize the input
JArrayHelper::toInteger($pks);
JArrayHelper::toInteger($order);
ArrayHelper::toInteger($pks);
ArrayHelper::toInteger($order);

// Get the model
$model = $this->getModel();
Expand Down
2 changes: 1 addition & 1 deletion code/admin/helpers/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

// No direct access.
defined('_JEXEC') or die();
use Joomla\CMS\HTML\HTMLHelper;

use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Factory;

Expand Down
7 changes: 6 additions & 1 deletion code/admin/language/en-GB/en-GB.com_api.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ COM_API_CONFIG_ALLOW_CORS_LBL="Allow Cross Origin Requests"
COM_API_CONFIG_ALLOW_CORS_DESC="This configuration enables CORS support. Choose if you wish to enable CORS for only GET method or for all methods."
COM_API_CONFIG_CORS_LBL="CORS URLs / Domains"
COM_API_CONFIG_CORS_DESC="List of URLs for which to allow CORS requests. Put an asterisk (*) to allow CORS requests from all domains. Alternately put a comma separated list of URL's. Ex. https://techjoomla.com, http://example.com"
COM_API_FORM_LBL_RATE_LIMIT="Hourly Rate Limit for Requests"
COM_API_FORM_LBL_RATE_LIMIT="Rate Limit for Requests"
COM_API_FORM_LBL_RATE_LIMIT_DESC="Put a number if you want to limit the number of requests made by a token in an hour to the configured value. An empty or 0 value allows unlimited requests"
COM_API_EXCLD_WORDS="Exclude request variables from log"
COM_API_EXCLD_WORDS_DESC="A comma separated list of request variables that will be redacted before being added to the API Request log"
Expand All @@ -97,6 +97,11 @@ COM_API_CONFIG_ALLOW_HEADER_DESC="Add comma separated values for Access-Control-
COM_API_FILTER_DESC="Searches in User name, hash, Request URL, POST Data. <br />uid:number searches logs for a particular user"
UNASSIGNED_HASH="No user for this API Key"

COM_API_CONFIG_IPS_DESC="List of IPs for which to allow API access. Put an asterisk (*) to allow API access from all IPs. Alternately put a comma separated list of IPs Ex. 192.168.1.1, 192.168.1.10 or IP Range Ex. 192.168.1.1-192.168.1.10 or CIDR Block Ex. 192.168.1.1/24"
COM_API_CONFIG_IPS_LBL="IP Address/IP Range/CIDR Block"
COM_API_CONFIG_REQ_LT_LBL="Rate Frequency"
COM_API_CONFIG_REQ_LT_DESC="Request limit frequency"

; Permissions
JACTION_MANAGELOGS="Manage Logs"
JACTION_MANAGELOGS_DESC="Allows users in this group to manage API logs."
Expand Down
1 change: 1 addition & 0 deletions code/admin/language/en-GB/en-GB.com_api.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COM_API_XML_DESCRIPTION="Multi"
COM_API_TEST_LABEL="Test label"

COM_API_TITLE_KEYS="API Keys"
COM_API_TITLE_LOGS="Request Logs"

COM_API_SHOW_TABLES_SQL_STATEMENT="SHOW FULL TABLES WHERE tables_in_%s LIKE %s"

Expand Down
3 changes: 1 addition & 2 deletions code/admin/models/fields/createdby.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

defined('JPATH_BASE') or die();

use Joomla\CMS\Form\FormField;
use Joomla\CMS\Factory;

Expand All @@ -16,7 +15,7 @@
*
* @since 1.0
*/
class JFormFieldCreatedby extends JFormField
class FormFieldCreatedby extends FormField
{
/**
* The form field type.
Expand Down
3 changes: 2 additions & 1 deletion code/admin/tables/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use Joomla\CMS\Access\Access;
use Joomla\Utilities\ArrayHelper;

/**
* Log Table class
Expand Down Expand Up @@ -138,7 +139,7 @@ public function store($updateNulls = false)
{
if (is_array($this->post_data))
{
$this->post_data = JArrayHelper::toString($this->post_data, '=', '&');
$this->post_data = ArrayHelper::toString($this->post_data, '=', '&');
}

return parent::store($updateNulls = false);
Expand Down
8 changes: 4 additions & 4 deletions code/admin/views/cpanel/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

defined('_JEXEC') or die();

use Joomla\CMS\MVC\View\HtmlView;

use Joomla\CMS\Language\Text;
use Joomla\CMS\Toolbar\ToolbarHelper;

/**
* Cpanel class
Expand Down Expand Up @@ -54,7 +54,7 @@ public function display($tpl = null)
*/
private function generateToolbar()
{
JToolBarHelper::title(Text::_('COM_API') . ': ' . Text::_('COM_API_CONTROL_PANEL'));
JToolBarHelper::preferences('com_api', 500, 500);
ToolbarHelper::title(Text::_('COM_API') . ': ' . Text::_('COM_API_CONTROL_PANEL'));
ToolbarHelper::preferences('com_api', 500, 500);
}
}
40 changes: 20 additions & 20 deletions code/admin/views/key/tmpl/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@
HTMLHelper::_('behavior.keepalive');

// Import CSS
$document = Factory::getDocument();
$document->addStyleSheet('components/com_api/assets/css/api.css');
?>
HTMLHelper::_('stylesheet','components/com_api/assets/css/api.css');

<script type="text/javascript">
js = jQuery.noConflict();
js(document).ready(function()
{

});

Joomla.submitbutton = function(task)
{
if (task == 'key.cancel')
Factory::getDocument()->addScriptDeclaration(
"
js = jQuery.noConflict();
js(document).ready(function()
{
Joomla.submitform(task, document.getElementById('key-form'));
}
else

});

Joomla.submitbutton = function(task)
{
if (task != 'key.cancel' && document.formvalidator.isValid(document.getElementById('key-form')))
if (task == 'key.cancel')
{
Joomla.submitform(task, document.getElementById('key-form'));
}
else
{
alert('<?php echo $this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
if (task != 'key.cancel' && document.formvalidator.isValid(document.getElementById('key-form')))
{
Joomla.submitform(task, document.getElementById('key-form'));
}
else
{
alert('".$this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED'))."');
}
}
}
}
</script>
");
?>

<div class="<?php echo COM_APIS_WRAPPER_CLASS; ?> api-key">
<form action="<?php echo Route::_('index.php?option=com_api&layout=edit&id=' . (int) $this->item->id); ?>" method="post" enctype="multipart/form-data" name="adminForm" id="key-form" class="form-validate">
Expand Down
18 changes: 10 additions & 8 deletions code/admin/views/key/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Joomla\CMS\Form\Form;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Toolbar\ToolbarHelper;


/**
* View class key form.
Expand Down Expand Up @@ -95,11 +97,11 @@ protected function addToolbar()

if (JVERSION >= '3.0')
{
JToolBarHelper::title($viewTitle, 'pencil-2');
ToolBarHelper::title($viewTitle, 'pencil-2');
}
else
{
JToolBarHelper::title($viewTitle, 'key.png');
ToolBarHelper::title($viewTitle, 'key.png');
}

if (isset($this->item->checked_out))
Expand All @@ -116,28 +118,28 @@ protected function addToolbar()
// If not checked out, can save the item.
if (! $checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create'))))
{
JToolBarHelper::apply('key.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('key.save', 'JTOOLBAR_SAVE');
ToolBarHelper::apply('key.apply', 'JTOOLBAR_APPLY');
ToolBarHelper::save('key.save', 'JTOOLBAR_SAVE');
}

if (! $checkedOut && ($canDo->get('core.create')))
{
JToolBarHelper::custom('key.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
ToolBarHelper::custom('key.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
}

// If an existing item, can save to a copy.
if (! $isNew && $canDo->get('core.create'))
{
JToolBarHelper::custom('key.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
ToolBarHelper::custom('key.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
}

if (empty($this->item->id))
{
JToolBarHelper::cancel('key.cancel', 'JTOOLBAR_CANCEL');
ToolBarHelper::cancel('key.cancel', 'JTOOLBAR_CANCEL');
}
else
{
JToolBarHelper::cancel('key.cancel', 'JTOOLBAR_CLOSE');
ToolBarHelper::cancel('key.cancel', 'JTOOLBAR_CLOSE');
}
}
}
16 changes: 6 additions & 10 deletions code/admin/views/keys/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html');

// Import CSS
$document = Factory::getDocument();
$document->addStyleSheet('components/com_api/assets/css/api.css');
HTMLHelper::_('stylesheet','components/com_api/assets/css/api.css');

$user = Factory::getUser();
$userId = $user->get('id');
Expand All @@ -38,29 +37,26 @@
}

$sortFields = $this->getSortFields();
?>

<script type="text/javascript">
Factory::getDocument()->addScriptDeclaration('
Joomla.orderTable = function()
{
table = document.getElementById("sortTable");
direction = document.getElementById("directionTable");
order = table.options[table.selectedIndex].value;

if (order !== '<?php echo $listOrder; ?>')
if (order !== "' . $listOrder . '")
{
dirn = 'asc';
dirn = "asc";
}
else
{
dirn = direction.options[direction.selectedIndex].value;
}

Joomla.tableOrdering(order, dirn, '');
Joomla.tableOrdering(order, dirn, "");
}
</script>
');

<?php
if (! empty($this->extra_sidebar))
{
$this->sidebar .= $this->extra_sidebar;
Expand Down
25 changes: 12 additions & 13 deletions code/admin/views/keys/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
*/

// No direct access.
defined('_JEXEC') or die();

defined('_JEXEC') or die();
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;

/**
* View class for list of keys
Expand Down Expand Up @@ -97,11 +96,11 @@ protected function addToolbar()

if (JVERSION >= '3.0')
{
JToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'key');
ToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'key');
}
else
{
JToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'keys.png');
ToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'keys.png');
}

// Check if the form exists before showing the add/edit buttons
Expand All @@ -111,22 +110,22 @@ protected function addToolbar()
{
if ($canDo->get('core.create'))
{
JToolBarHelper::addNew('key.add', 'JTOOLBAR_NEW');
ToolBarHelper::addNew('key.add', 'JTOOLBAR_NEW');
}

if ($canDo->get('core.edit') && isset($this->items[0]))
{
JToolBarHelper::editList('key.edit', 'JTOOLBAR_EDIT');
ToolBarHelper::editList('key.edit', 'JTOOLBAR_EDIT');
}
}

if ($canDo->get('core.edit.state'))
{
if (isset($this->items[0]->state))
{
JToolBarHelper::divider();
JToolBarHelper::custom('keys.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
JToolBarHelper::custom('keys.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
ToolBarHelper::divider();
ToolBarHelper::custom('keys.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
ToolBarHelper::custom('keys.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
}
}

Expand All @@ -135,14 +134,14 @@ protected function addToolbar()
{
if ($canDo->get('core.delete'))
{
JToolBarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'keys.delete', 'JTOOLBAR_DELETE');
JToolBarHelper::divider();
ToolBarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'keys.delete', 'JTOOLBAR_DELETE');
ToolBarHelper::divider();
}
}

if ($canDo->get('core.admin'))
{
JToolBarHelper::preferences('com_api');
ToolBarHelper::preferences('com_api');
}

// Set sidebar action - New in 3.0
Expand Down
Loading