Merge pull request #569 from torrentpier/ajax-check-if-is-ajax

Check if request is ajax
This commit is contained in:
Roman Kelesidis 2023-03-08 11:03:24 +07:00 committed by GitHub
commit bbcd7a1c2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View file

@ -198,6 +198,11 @@ switch ($bb_cfg['datastore_type']) {
$datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); $datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']);
} }
function is_ajax(): bool
{
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
function sql_dbg_enabled() function sql_dbg_enabled()
{ {
return (SQL_DEBUG && DBG_USER && !empty($_COOKIE['sql_log'])); return (SQL_DEBUG && DBG_USER && !empty($_COOKIE['sql_log']));

View file

@ -147,6 +147,7 @@ define('SEARCH_TYPE_TRACKER', 1);
// Ajax error codes // Ajax error codes
define('E_AJAX_GENERAL_ERROR', 1000); define('E_AJAX_GENERAL_ERROR', 1000);
define('E_AJAX_NEED_LOGIN', 1001); define('E_AJAX_NEED_LOGIN', 1001);
define('E_AJAX_NOT_REQUEST', 1002);
// Private messaging // Private messaging
define('PRIVMSGS_READ_MAIL', 0); define('PRIVMSGS_READ_MAIL', 0);

View file

@ -74,6 +74,10 @@ class Ajax
// Action params // Action params
$action_params = null; $action_params = null;
if (!is_ajax()) {
$this->ajax_die('Not AJAX request', E_AJAX_NOT_REQUEST);
}
if (!$action || !\is_string($action)) { if (!$action || !\is_string($action)) {
$this->ajax_die('no action specified'); $this->ajax_die('no action specified');
} elseif (!$action_params =& $this->valid_actions[$action]) { } elseif (!$action_params =& $this->valid_actions[$action]) {