From b07fcd0597834bf1e4b8a7c3f16dcd2d1877e85d Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 1 Aug 2016 20:43:53 +0200 Subject: [PATCH] (auth) extend system_authservers.php for pluggable auth connectors, remove totp properties (moved to connector) --- src/www/system_authservers.php | 186 ++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 83 deletions(-) diff --git a/src/www/system_authservers.php b/src/www/system_authservers.php index fa7658b7d..bc02f5e45 100644 --- a/src/www/system_authservers.php +++ b/src/www/system_authservers.php @@ -30,14 +30,8 @@ require_once("guiconfig.inc"); require_once("auth.inc"); - -$auth_server_types = array( - 'ldap' => gettext("LDAP"), - 'radius' => gettext("Radius"), - 'voucher' => gettext("Voucher"), - 'totp' => gettext("Local + Timebased One Time Password") -); - +$authFactory = new \OPNsense\Auth\AuthenticationFactory(); +$authCNFOptions = $authFactory->listConfigOptions(); if (!isset($config['system']['authserver'])) { $config['system']['authserver'] = array(); @@ -69,6 +63,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['radius_auth_port'] = "1812"; $pconfig['radius_acct_port'] = "1813"; $pconfig['type'] = 'ldap'; + // gather auth plugin defaults + // the hotplug properties should be different per type, if not the default won't function correctly + foreach ($authCNFOptions as $authType) { + foreach ($authType['additionalFields'] as $fieldname => $field) { + if (!empty($field['default']) && empty($pconfig[$fieldname])) { + $pconfig[$fieldname] = $field['default']; + } + } + } } elseif ($act == "edit" && isset($id)) { $pconfig['type'] = $a_server[$id]['type']; $pconfig['name'] = $a_server[$id]['name']; @@ -111,9 +114,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['simplePasswords'] = $a_server[$id]['simplePasswords']; $pconfig['usernameLength'] = $a_server[$id]['usernameLength']; $pconfig['passwordLength'] = $a_server[$id]['passwordLength']; - } elseif ($pconfig['type'] == 'totp') { - $pconfig['graceperiod'] = $a_server[$id]['graceperiod']; - $pconfig['timeWindow'] = $a_server[$id]['timeWindow']; + } elseif (!empty($authCNFOptions[$pconfig['type']])) { + foreach ($authCNFOptions[$pconfig['type']]['additionalFields'] as $fieldname => $field) { + $pconfig[$fieldname] = $a_server[$id][$fieldname]; + } } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -173,6 +177,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($pconfig['passwordLength']) && !is_numeric($pconfig['passwordLength'])) { $input_errors[] = gettext("password length must be a number or empty for default."); } + } elseif (!empty($authCNFOptions[$pconfig['type']])) { + foreach ($authCNFOptions[$pconfig['type']]['additionalFields'] as $fieldname => $field) { + if (!empty($field['validate'])) { + foreach ($field['validate']($pconfig[$fieldname]) as $input_error) { + $input_errors[] = $input_error; + } + } + } } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); @@ -255,9 +267,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $server['simplePasswords'] = !empty($pconfig['simplePasswords']); $server['usernameLength'] = $pconfig['usernameLength']; $server['passwordLength'] = $pconfig['passwordLength']; - } elseif ($server['type'] == 'totp') { - $server['timeWindow'] = filter_var($pconfig['timeWindow'], FILTER_SANITIZE_NUMBER_INT); - $server['graceperiod'] = filter_var($pconfig['graceperiod'], FILTER_SANITIZE_NUMBER_INT); + } elseif (!empty($authCNFOptions[$server['type']])) { + foreach ($authCNFOptions[$server['type']]['additionalFields'] as $fieldname => $field) { + $server[$fieldname] = $pconfig[$fieldname]; + } } if (isset($id) && isset($config['system']['authserver'][$id])) { @@ -318,19 +331,11 @@ if (!isset($_GET['act']) || $_GET['act'] != 'new')