Move function declaration braces to meet PSR-2 standard.

pull/1111/head
very-ape 2021-05-17 10:37:13 -07:00
parent aa2992adb1
commit 3f5880b914
1 changed files with 35 additions and 17 deletions

View File

@ -20,9 +20,12 @@ require_once(__DIR__ . '/vendor/autoload.php');
define("PW_LEN", 32); // number of characters to use for random passwords define("PW_LEN", 32); // number of characters to use for random passwords
function saml_module($a) {} function saml_module($a)
{
}
function saml_init($a) { function saml_init($a)
{
if ($a->argc < 2) return; if ($a->argc < 2) return;
switch ($a->argv[1]) { switch ($a->argv[1]) {
@ -43,7 +46,8 @@ function saml_init($a) {
exit(); exit();
} }
function saml_metadata() { function saml_metadata()
{
try { try {
$settings = new \OneLogin\Saml2\Settings(saml_settings()); $settings = new \OneLogin\Saml2\Settings(saml_settings());
$metadata = $settings->getSPMetadata(); $metadata = $settings->getSPMetadata();
@ -63,18 +67,21 @@ function saml_metadata() {
} }
} }
function saml_install() { function saml_install()
{
Hook::register('login_hook', __FILE__, 'saml_sso_initiate'); Hook::register('login_hook', __FILE__, 'saml_sso_initiate');
Hook::register('logging_out', __FILE__, 'saml_slo_initiate'); Hook::register('logging_out', __FILE__, 'saml_slo_initiate');
Hook::register('head', __FILE__, 'saml_head'); Hook::register('head', __FILE__, 'saml_head');
Hook::register('footer', __FILE__, 'saml_footer'); Hook::register('footer', __FILE__, 'saml_footer');
} }
function saml_head(&$a, &$b) { function saml_head(&$a, &$b)
{
DI::page()->registerStylesheet(__DIR__ . '/saml.css'); DI::page()->registerStylesheet(__DIR__ . '/saml.css');
} }
function saml_footer(&$a, &$b) { function saml_footer(&$a, &$b)
{
$fragment = addslashes(BBCode::convert(DI::config()->get('saml', 'settings_statement'))); $fragment = addslashes(BBCode::convert(DI::config()->get('saml', 'settings_statement')));
$b .= <<<EOL $b .= <<<EOL
<script> <script>
@ -84,7 +91,8 @@ if (target.length) { target.append("<p>$fragment</p>"); }
EOL; EOL;
} }
function saml_is_configured() { function saml_is_configured()
{
return return
DI::config()->get('saml', 'idp_id') && DI::config()->get('saml', 'idp_id') &&
DI::config()->get('saml', 'client_id') && DI::config()->get('saml', 'client_id') &&
@ -97,7 +105,8 @@ function saml_is_configured() {
} }
function saml_sso_initiate(&$a, &$b) { function saml_sso_initiate(&$a, &$b)
{
if (!saml_is_configured()) return; if (!saml_is_configured()) return;
$auth = new \OneLogin\Saml2\Auth(saml_settings()); $auth = new \OneLogin\Saml2\Auth(saml_settings());
@ -109,7 +118,8 @@ function saml_sso_initiate(&$a, &$b) {
exit(); exit();
} }
function saml_sso_reply($a) { function saml_sso_reply($a)
{
$auth = new \OneLogin\Saml2\Auth(saml_settings()); $auth = new \OneLogin\Saml2\Auth(saml_settings());
$requestID = null; $requestID = null;
@ -159,7 +169,8 @@ function saml_sso_reply($a) {
} }
} }
function saml_slo_initiate(&$a, &$b) { function saml_slo_initiate(&$a, &$b)
{
$auth = new \OneLogin\Saml2\Auth(saml_settings()); $auth = new \OneLogin\Saml2\Auth(saml_settings());
$sloBuiltUrl = $auth->logout(); $sloBuiltUrl = $auth->logout();
@ -170,7 +181,8 @@ function saml_slo_initiate(&$a, &$b) {
exit(); exit();
} }
function saml_slo_reply() { function saml_slo_reply()
{
$auth = new \OneLogin\Saml2\Auth(saml_settings()); $auth = new \OneLogin\Saml2\Auth(saml_settings());
if (isset($_SESSION) && isset($_SESSION['LogoutRequestID'])) { if (isset($_SESSION) && isset($_SESSION['LogoutRequestID'])) {
@ -190,7 +202,8 @@ function saml_slo_reply() {
} }
} }
function saml_input($key, $label, $description) { function saml_input($key, $label, $description)
{
return [ return [
'$' . $key => [ '$' . $key => [
$key, $key,
@ -202,7 +215,8 @@ function saml_input($key, $label, $description) {
]; ];
} }
function saml_addon_admin (&$a, &$o) { function saml_addon_admin (&$a, &$o)
{
$form = $form =
saml_input( saml_input(
'settings_statement', 'settings_statement',
@ -256,8 +270,10 @@ function saml_addon_admin (&$a, &$o) {
$o = Renderer::replaceMacros( $t, $form); $o = Renderer::replaceMacros( $t, $form);
} }
function saml_addon_admin_post (&$a) { function saml_addon_admin_post (&$a)
$safeset = function ($key) { {
$safeset = function ($key)
{
$val = (!empty($_POST[$key]) ? Strings::escapeTags(trim($_POST[$key])) : ''); $val = (!empty($_POST[$key]) ? Strings::escapeTags(trim($_POST[$key])) : '');
DI::config()->set('saml', $key, $val); DI::config()->set('saml', $key, $val);
}; };
@ -274,7 +290,8 @@ function saml_addon_admin_post (&$a) {
DI::config()->set('saml', 'settings_statement', $_POST['settings_statement']); DI::config()->set('saml', 'settings_statement', $_POST['settings_statement']);
} }
function saml_create_user($username, $email, $name) { function saml_create_user($username, $email, $name)
{
if (!strlen($email) || !strlen($name)) { if (!strlen($email) || !strlen($name)) {
Logger::error('Could not create user: no email or username given.'); Logger::error('Could not create user: no email or username given.');
return false; return false;
@ -313,7 +330,8 @@ function saml_create_user($username, $email, $name) {
} }
} }
function saml_settings() { function saml_settings()
{
return array( return array(
// If 'strict' is True, then the PHP Toolkit will reject unsigned // If 'strict' is True, then the PHP Toolkit will reject unsigned
// or unencrypted messages if it expects them to be signed or encrypted. // or unencrypted messages if it expects them to be signed or encrypted.