mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
use shared identity driver, fix active option detection, other optimizations
This commit is contained in:
parent
555f08e59b
commit
06834d92c4
4 changed files with 163 additions and 113 deletions
|
|
@ -19,6 +19,8 @@ use \Yggverse\Yoda\Entity\Browser\Container\Page;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Model\Identity\Gemini;
|
use \Yggverse\Yoda\Model\Identity\Gemini;
|
||||||
|
|
||||||
|
use \Yggverse\Net\Address;
|
||||||
|
|
||||||
class Auth
|
class Auth
|
||||||
{
|
{
|
||||||
// GTK
|
// GTK
|
||||||
|
|
@ -161,50 +163,86 @@ class Auth
|
||||||
// Build options list
|
// Build options list
|
||||||
foreach ($this->_options as $id => $option)
|
foreach ($this->_options as $id => $option)
|
||||||
{
|
{
|
||||||
// Detect active identity
|
// Detect option type
|
||||||
$option->gtk->set_active(
|
switch ($id)
|
||||||
boolval(
|
|
||||||
$this->page->container->browser->database->auth->like(
|
|
||||||
$this->page->navbar->request->getValue(), 1 // one
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Append option
|
|
||||||
$content->add(
|
|
||||||
$option->gtk
|
|
||||||
);
|
|
||||||
|
|
||||||
// Is new and option has name entity
|
|
||||||
if (!$id && !is_null($option->name))
|
|
||||||
{
|
{
|
||||||
// Append name entry after new identity option
|
// Is new cert option
|
||||||
$content->add(
|
case Auth\Option\Identity::ID_CRT_NEW:
|
||||||
$option->name->gtk,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
// Append separator
|
// Set extra margin
|
||||||
$content->add(
|
$option->gtk->set_margin_bottom(
|
||||||
new GtkSeparator(
|
$option::MARGIN
|
||||||
GtkOrientation::VERTICAL
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set margin
|
// Append option
|
||||||
$option->gtk->set_margin_bottom(
|
$content->add(
|
||||||
self::MARGIN
|
$option->gtk
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Append name entry after new identity option
|
||||||
|
$content->add(
|
||||||
|
$option->name->gtk,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Append separator
|
||||||
|
$content->add(
|
||||||
|
new GtkSeparator(
|
||||||
|
GtkOrientation::VERTICAL
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Is logout option
|
||||||
|
case Auth\Option\Identity::ID_LOG_OUT:
|
||||||
|
|
||||||
|
// Set extra margin
|
||||||
|
$option->gtk->set_margin_bottom(
|
||||||
|
$option::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Append option
|
||||||
|
$content->add(
|
||||||
|
$option->gtk
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Is DB
|
||||||
|
default:
|
||||||
|
|
||||||
|
// Append option
|
||||||
|
$content->add(
|
||||||
|
$option->gtk
|
||||||
|
);
|
||||||
|
|
||||||
|
// Detect active option match identity driver conditions
|
||||||
|
switch (true)
|
||||||
|
{
|
||||||
|
case parse_url(
|
||||||
|
$this->page->navbar->request->getValue(),
|
||||||
|
PHP_URL_SCHEME
|
||||||
|
) == 'gemini':
|
||||||
|
|
||||||
|
$option->gtk->set_active(
|
||||||
|
boolval(
|
||||||
|
Gemini::match(
|
||||||
|
new Address(
|
||||||
|
$this->page->navbar->request->getValue()
|
||||||
|
),
|
||||||
|
$this->page->container->browser->database
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add final separator
|
|
||||||
$content->add(
|
|
||||||
new GtkLabel
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
$this->gtk->show_all();
|
$this->gtk->show_all();
|
||||||
|
|
||||||
|
|
@ -216,7 +254,7 @@ class Auth
|
||||||
{
|
{
|
||||||
if ($option->gtk->get_active())
|
if ($option->gtk->get_active())
|
||||||
{
|
{
|
||||||
// Route ID
|
// Detect option type
|
||||||
switch ($id)
|
switch ($id)
|
||||||
{
|
{
|
||||||
case Auth\Option\Identity::ID_LOG_OUT:
|
case Auth\Option\Identity::ID_LOG_OUT:
|
||||||
|
|
@ -299,13 +337,19 @@ class Auth
|
||||||
// Detect active option
|
// Detect active option
|
||||||
foreach ($this->_options as $id => $option)
|
foreach ($this->_options as $id => $option)
|
||||||
{
|
{
|
||||||
// Is new and option has name entity
|
// Detect option type
|
||||||
if (!$id && !is_null($option->name))
|
switch ($id)
|
||||||
{
|
{
|
||||||
// Update sensibility
|
case Auth\Option\Identity::ID_CRT_NEW:
|
||||||
$option->name->gtk->set_sensitive(
|
|
||||||
$option->gtk->get_active()
|
// Is name entity defined
|
||||||
);
|
if (!is_null($option->name))
|
||||||
|
{
|
||||||
|
// Update sensibility
|
||||||
|
$option->name->gtk->set_sensitive(
|
||||||
|
$option->gtk->get_active()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class Name
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->gtk->set_margin_bottom(
|
$this->gtk->set_margin_bottom(
|
||||||
$this::MARGIN
|
$this::MARGIN * 2
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->gtk->show();
|
$this->gtk->show();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Model\Connection;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Model\Connection;
|
use \Yggverse\Yoda\Model\Connection;
|
||||||
use \Yggverse\Yoda\Model\Filesystem;
|
use \Yggverse\Yoda\Model\Filesystem;
|
||||||
|
use \Yggverse\Yoda\Model\Identity\Gemini as Identity;
|
||||||
|
|
||||||
use \Yggverse\Gemini\Client\Request;
|
use \Yggverse\Gemini\Client\Request;
|
||||||
use \Yggverse\Gemini\Client\Response;
|
use \Yggverse\Gemini\Client\Response;
|
||||||
|
|
@ -36,7 +37,7 @@ class Gemini
|
||||||
$options = $request->getOptions();
|
$options = $request->getOptions();
|
||||||
|
|
||||||
// Apply identity if available
|
// Apply identity if available
|
||||||
if ($identity = $this->matchIdentity($address))
|
if ($identity = Identity::match($address, $this->_connection->database))
|
||||||
{
|
{
|
||||||
$crt = tmpfile();
|
$crt = tmpfile();
|
||||||
|
|
||||||
|
|
@ -366,72 +367,6 @@ class Gemini
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return identity match request | NULL
|
|
||||||
*
|
|
||||||
* https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function matchIdentity(
|
|
||||||
Address $address,
|
|
||||||
array $identities = []
|
|
||||||
): ?object
|
|
||||||
{
|
|
||||||
foreach (
|
|
||||||
// Select host records
|
|
||||||
$this->_connection->database->auth->like(
|
|
||||||
sprintf(
|
|
||||||
'%s%%',
|
|
||||||
$address->get(
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) as $auth
|
|
||||||
) {
|
|
||||||
// Parse result address
|
|
||||||
$request = new Address(
|
|
||||||
$auth->request
|
|
||||||
);
|
|
||||||
|
|
||||||
// Filter results match current path prefix
|
|
||||||
if (str_starts_with($address->getPath(), $request->getPath()))
|
|
||||||
{
|
|
||||||
$identities[
|
|
||||||
$auth->identity
|
|
||||||
] = $auth->request;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Results found
|
|
||||||
if ($identities)
|
|
||||||
{
|
|
||||||
uasort( // max-level
|
|
||||||
$identities,
|
|
||||||
function ($a, $b)
|
|
||||||
{
|
|
||||||
return mb_strlen($b) <=> mb_strlen($a);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_connection->database->identity->get(
|
|
||||||
intval(
|
|
||||||
array_key_first(
|
|
||||||
$identities
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getMimeByMeta(
|
public static function getMimeByMeta(
|
||||||
?string $meta = null
|
?string $meta = null
|
||||||
): ?string
|
): ?string
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ use \Exception;
|
||||||
use \OpenSSLAsymmetricKey;
|
use \OpenSSLAsymmetricKey;
|
||||||
use \OpenSSLCertificate;
|
use \OpenSSLCertificate;
|
||||||
|
|
||||||
|
use \Yggverse\Net\Address;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Model\Database;
|
||||||
|
|
||||||
class Gemini extends \Yggverse\Yoda\Abstract\Model\Identity
|
class Gemini extends \Yggverse\Yoda\Abstract\Model\Identity
|
||||||
{
|
{
|
||||||
// Init defaults
|
// Init defaults
|
||||||
|
|
@ -79,4 +83,71 @@ class Gemini extends \Yggverse\Yoda\Abstract\Model\Identity
|
||||||
|
|
||||||
throw new Exception;
|
throw new Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return identity match Address | NULL
|
||||||
|
*
|
||||||
|
* https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function match(
|
||||||
|
Address $address,
|
||||||
|
Database $database,
|
||||||
|
array $identities = []
|
||||||
|
): ?object
|
||||||
|
{
|
||||||
|
foreach (
|
||||||
|
// Select host records
|
||||||
|
$database->auth->like(
|
||||||
|
sprintf(
|
||||||
|
'%s%%',
|
||||||
|
$address->get(
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) as $auth
|
||||||
|
) {
|
||||||
|
// Parse result address
|
||||||
|
$request = new Address(
|
||||||
|
$auth->request
|
||||||
|
);
|
||||||
|
|
||||||
|
// Filter results match current path prefix
|
||||||
|
if (str_starts_with($address->getPath(), $request->getPath()))
|
||||||
|
{
|
||||||
|
$identities[
|
||||||
|
$auth->identity
|
||||||
|
] = $auth->request;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Results found
|
||||||
|
if ($identities)
|
||||||
|
{
|
||||||
|
uasort( // max-level
|
||||||
|
$identities,
|
||||||
|
function ($a, $b)
|
||||||
|
{
|
||||||
|
return mb_strlen($b) <=> mb_strlen($a);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $database->identity->get(
|
||||||
|
intval(
|
||||||
|
array_key_first(
|
||||||
|
$identities
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue