forked from roland-d/backendtoken
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackendtoken.php
More file actions
97 lines (84 loc) · 1.83 KB
/
backendtoken.php
File metadata and controls
97 lines (84 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Original version
* Axel < axel[at]quelloffen.com >
* http://www.joomlaconsulting.de
*
* @package BackendToken
*
* @author RolandD Cyber Produkis <contact@rolandd.com>
* @copyright Copyright (C) 2019 RolandD Cyber Produksi. All rights reserved.
* @license GNU/GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://rolandd.com
**/
defined('_JEXEC') or die;
use Joomla\CMS\Application\AdministratorApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Uri\Uri;
/**
* Backend Token.
*
* @package BackendToken
* @since 2.0.0
*/
class plgSystemBackendtoken extends CMSPlugin
{
/**
* An application instance
*
* @var AdministratorApplication
* @since 2.0.0
*/
protected $app;
/**
* Trigger on after being initialised.
*
* @return void
*
* @since 2.0.0
*
* @throws Exception
*/
public function onAfterInitialise(): void
{
if (!$this->app->isClient('administrator'))
{
return;
}
// Already logged in
$user = Factory::getUser();
if (!$user->guest)
{
return;
}
// Consider request empty
$request = '';
// Handle a direct entry to the admin login page
if ($this->app->input->getMethod() === 'GET')
{
$request = $this->app->input->getString('token', 'no token set');
}
// Handle after login form submission
if ($this->app->input->getMethod() === 'POST')
{
// Need to get the token from the referer URL
$uri = new Uri($_SERVER['HTTP_REFERER']);
$request = $uri->getVar('token', 'no token set');
}
$token = $this->params->get('token', 1);
// Invalid access token
if ($token !== $request)
{
$url = (string) $this->params->get('url');
// Fallback to site
if ($url === '')
{
$url = Uri::root();
}
$this->app->redirect($url);
$this->app->close();
die;
}
}
}