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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
<?php
/**
* Two authentication factor handling
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins;
use PhpMyAdmin\Core;
use PhpMyAdmin\Message;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use function __;
use function is_array;
use function parse_url;
use function sprintf;
use function strlen;
/**
* Two factor authentication plugin class
*
* This is basic implementation which does no
* additional authentication, subclasses are expected
* to implement this.
*/
class TwoFactorPlugin
{
/** @var string */
public static $id = '';
/**
* Whether to show submit button in form
*
* @var bool
*/
public static $showSubmit = true;
/** @var TwoFactor */
protected $twofactor;
/** @var bool */
protected $provided = false;
/** @var string */
protected $message = '';
/** @var Template */
public $template;
/**
* Creates object
*
* @param TwoFactor $twofactor TwoFactor instance
*/
public function __construct(TwoFactor $twofactor)
{
$this->twofactor = $twofactor;
$this->template = new Template();
}
/**
* Returns authentication error message
*
* @return string
*/
public function getError()
{
if ($this->provided) {
if (! empty($this->message)) {
return Message::rawError(
sprintf(__('Two-factor authentication failed: %s'), $this->message)
)->getDisplay();
}
return Message::rawError(
__('Two-factor authentication failed.')
)->getDisplay();
}
return '';
}
/**
* Checks authentication, returns true on success
*/
public function check(): bool
{
return true;
}
/**
* Renders user interface to enter two-factor authentication
*
* @return string HTML code
*/
public function render()
{
return '';
}
/**
* Renders user interface to configure two-factor authentication
*
* @return string HTML code
*/
public function setup()
{
return '';
}
/**
* Performs backend configuration
*/
public function configure(): bool
{
return true;
}
/**
* Get user visible name
*
* @return string
*/
public static function getName()
{
return __('No Two-Factor Authentication');
}
/**
* Get user visible description
*
* @return string
*/
public static function getDescription()
{
return __('Login using password only.');
}
/**
* Return an application ID
*
* Either hostname or hostname with scheme.
*
* @param bool $return_url Whether to generate URL
*
* @return string
*/
public function getAppId($return_url)
{
global $config;
$url = $config->get('PmaAbsoluteUri');
$parsed = [];
if (! empty($url)) {
$parsedUrl = parse_url($url);
if (is_array($parsedUrl)) {
$parsed = $parsedUrl;
}
}
if (! isset($parsed['scheme']) || strlen($parsed['scheme']) === 0) {
$parsed['scheme'] = $config->isHttps() ? 'https' : 'http';
}
if (! isset($parsed['host']) || strlen($parsed['host']) === 0) {
$parsed['host'] = Core::getenv('HTTP_HOST');
}
if ($return_url) {
$port = '';
if (isset($parsed['port'])) {
$port = ':' . $parsed['port'];
}
return sprintf('%s://%s%s', $parsed['scheme'], $parsed['host'], $port);
}
return $parsed['host'];
}
}
|