Skip to content

Commit 0d3b65d

Browse files
Merge pull request #150 from vinayak-patil/j4x
Issue fixes - #63,#122,#80 - Joomla 4 & PHP 8.0 compatibility
2 parents 7e5af12 + be1b3b4 commit 0d3b65d

File tree

23 files changed

+162
-125
lines changed

23 files changed

+162
-125
lines changed

changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
#### Legend
4+
5+
- Bug Fix (-)
6+
- Feature Addition (+)
7+
8+
### com_api v4.0.0
9+
10+
##### - Bug fixes:
11+
- #194540 - API Rate Limit Exceeded,403 - Issue #122
12+
- Drop support to accept token as 'Key' parameter from GET/POST request - Tokens should not be accepted via request variables
13+
14+
15+
##### + Features Added:
16+
- #175851 - Joomla 4 & PHP 8.0 compatible
17+
- #194541 - Added IP based restrictions to access the APIs, Issue #63

code/admin/config.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
<fieldset label="COM_API" name="api">
44
<field name="force_output" type="text" label="COM_API_FORM_LBL_FORCE_OUTPUT"
55
description="COM_API_FORM_DESC_FORCE_OUTPUT" />
6+
<field name="request_limit_time" type="radio" default="hour"
7+
label="COM_API_CONFIG_REQ_LT_LBL" description="COM_API_CONFIG_REQ_LT_DESC"
8+
class="btn-group">
9+
<option value="hour">COM_API_CONFIG_RLT_HOUR</option>
10+
<option value="minute">COM_API_CONFIG_RLT_MINUTE</option>
11+
<option value="day">COM_API_CONFIG_RLT_DAY</option>
12+
</field>
613
<field name="request_limit" type="text" label="COM_API_FORM_LBL_RATE_LIMIT"
714
description="COM_API_FORM_LBL_RATE_LIMIT_DESC" />
815
<field name="log_requests" type="radio" default="0"
916
label="COM_API_CONFIG_LOG_LBL" description="COM_API_CONFIG_LOG_DESC"
1017
class="btn-group">
11-
<option value="0">No</option>
12-
<option value="1">Yes</option>
18+
<option value="0">JNO</option>
19+
<option value="1">JYES</option>
1320
</field>
1421
<field name="exclude_log" type="text" default="password,pass,passwd,pwd,key"
1522
label="COM_API_EXCLD_WORDS" description="COM_API_EXCLD_WORDS_DESC" />
@@ -19,10 +26,12 @@
1926
<field name="allow_cors" type="radio" default="0"
2027
label="COM_API_CONFIG_ALLOW_CORS_LBL" description="COM_API_CONFIG_ALLOW_CORS_DESC"
2128
class="btn-group">
22-
<option value="0">No</option>
23-
<option value="get">GET</option>
24-
<option value="*">ALL</option>
29+
<option value="0">JNO</option>
30+
<option value="get">COM_API_CONFIG_GET_CORS</option>
31+
<option value="*">JALL</option>
2532
</field>
33+
<field name="ip_address" type="textarea" columns="5"
34+
label="COM_API_CONFIG_IPS_LBL" description="COM_API_CONFIG_IPS_DESC" />
2635
<field name="cors" type="textarea" default="*" columns="5"
2736
label="COM_API_CONFIG_CORS_LBL" description="COM_API_CONFIG_CORS_DESC" />
2837
<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"

code/admin/controllers/keys.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Joomla\CMS\MVC\Controller\AdminController;
1313
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
1414
use Joomla\CMS\Factory;
15+
use Joomla\Utilities\ArrayHelper;
1516

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

5455
// Sanitize the input
55-
JArrayHelper::toInteger($pks);
56-
JArrayHelper::toInteger($order);
56+
ArrayHelper::toInteger($pks);
57+
ArrayHelper::toInteger($order);
5758

5859
// Get the model
5960
$model = $this->getModel();

code/admin/helpers/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
// No direct access.
1010
defined('_JEXEC') or die();
11+
use Joomla\CMS\HTML\HTMLHelper;
1112

1213
use Joomla\CMS\Language\Text;
13-
use Joomla\CMS\HTML\HTMLHelper;
1414
use Joomla\CMS\Object\CMSObject;
1515
use Joomla\CMS\Factory;
1616

code/admin/language/en-GB/en-GB.com_api.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ COM_API_CONFIG_ALLOW_CORS_LBL="Allow Cross Origin Requests"
8686
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."
8787
COM_API_CONFIG_CORS_LBL="CORS URLs / Domains"
8888
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"
89-
COM_API_FORM_LBL_RATE_LIMIT="Hourly Rate Limit for Requests"
89+
COM_API_FORM_LBL_RATE_LIMIT="Rate Limit for Requests"
9090
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"
9191
COM_API_EXCLD_WORDS="Exclude request variables from log"
9292
COM_API_EXCLD_WORDS_DESC="A comma separated list of request variables that will be redacted before being added to the API Request log"
@@ -97,6 +97,15 @@ COM_API_CONFIG_ALLOW_HEADER_DESC="Add comma separated values for Access-Control-
9797
COM_API_FILTER_DESC="Searches in User name, hash, Request URL, POST Data. <br />uid:number searches logs for a particular user"
9898
UNASSIGNED_HASH="No user for this API Key"
9999

100+
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"
101+
COM_API_CONFIG_IPS_LBL="IP Address/IP Range/CIDR Block"
102+
COM_API_CONFIG_REQ_LT_LBL="Rate Frequency"
103+
COM_API_CONFIG_REQ_LT_DESC="Request limit frequency"
104+
COM_API_CONFIG_RLT_HOUR="Hour"
105+
COM_API_CONFIG_RLT_MINUTE="Minute"
106+
COM_API_CONFIG_RLT_DAY="Day"
107+
COM_API_CONFIG_GET_CORS="Get"
108+
100109
; Permissions
101110
JACTION_MANAGELOGS="Manage Logs"
102111
JACTION_MANAGELOGS_DESC="Allows users in this group to manage API logs."

code/admin/language/en-GB/en-GB.com_api.sys.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COM_API_XML_DESCRIPTION="Multi"
99
COM_API_TEST_LABEL="Test label"
1010

1111
COM_API_TITLE_KEYS="API Keys"
12+
COM_API_TITLE_LOGS="Request Logs"
1213

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

code/admin/models/fields/createdby.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
defined('JPATH_BASE') or die();
10-
1110
use Joomla\CMS\Form\FormField;
1211
use Joomla\CMS\Factory;
1312

code/admin/tables/log.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Joomla\CMS\Factory;
1515
use Joomla\Registry\Registry;
1616
use Joomla\CMS\Access\Access;
17+
use Joomla\Utilities\ArrayHelper;
1718

1819
/**
1920
* Log Table class
@@ -138,7 +139,7 @@ public function store($updateNulls = false)
138139
{
139140
if (is_array($this->post_data))
140141
{
141-
$this->post_data = JArrayHelper::toString($this->post_data, '=', '&');
142+
$this->post_data = ArrayHelper::toString($this->post_data, '=', '&');
142143
}
143144

144145
return parent::store($updateNulls = false);

code/admin/views/cpanel/view.html.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88

99
defined('_JEXEC') or die();
10-
11-
use Joomla\CMS\MVC\View\HtmlView;
10+
1211
use Joomla\CMS\Language\Text;
12+
use Joomla\CMS\Toolbar\ToolbarHelper;
1313

1414
/**
1515
* Cpanel class
@@ -54,7 +54,7 @@ public function display($tpl = null)
5454
*/
5555
private function generateToolbar()
5656
{
57-
JToolBarHelper::title(Text::_('COM_API') . ': ' . Text::_('COM_API_CONTROL_PANEL'));
58-
JToolBarHelper::preferences('com_api', 500, 500);
57+
ToolbarHelper::title(Text::_('COM_API') . ': ' . Text::_('COM_API_CONTROL_PANEL'));
58+
ToolbarHelper::preferences('com_api', 500, 500);
5959
}
6060
}

code/admin/views/key/tmpl/edit.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@
2828
HTMLHelper::_('behavior.keepalive');
2929

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

35-
<script type="text/javascript">
36-
js = jQuery.noConflict();
37-
js(document).ready(function()
38-
{
39-
40-
});
41-
42-
Joomla.submitbutton = function(task)
43-
{
44-
if (task == 'key.cancel')
33+
Factory::getDocument()->addScriptDeclaration(
34+
"
35+
js = jQuery.noConflict();
36+
js(document).ready(function()
4537
{
46-
Joomla.submitform(task, document.getElementById('key-form'));
47-
}
48-
else
38+
39+
});
40+
41+
Joomla.submitbutton = function(task)
4942
{
50-
if (task != 'key.cancel' && document.formvalidator.isValid(document.getElementById('key-form')))
43+
if (task == 'key.cancel')
5144
{
5245
Joomla.submitform(task, document.getElementById('key-form'));
5346
}
5447
else
5548
{
56-
alert('<?php echo $this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
49+
if (task != 'key.cancel' && document.formvalidator.isValid(document.getElementById('key-form')))
50+
{
51+
Joomla.submitform(task, document.getElementById('key-form'));
52+
}
53+
else
54+
{
55+
alert('".$this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED'))."');
56+
}
5757
}
5858
}
59-
}
60-
</script>
59+
");
60+
?>
6161

6262
<div class="<?php echo COM_APIS_WRAPPER_CLASS; ?> api-key">
6363
<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">

0 commit comments

Comments
 (0)