Commit c78bac3b authored by Nigel McNie's avatar Nigel McNie

Improvements to authentication plugins:

 * Give authentication plugins titles and descriptions, which are used by the authlist pieform element so people see an easier name
 * Add a new API method to the PluginAuth class, is_usable(). This can be used by auth plugins to check that required extensions are available. The authlist element will tell the user what they need to do to enable a plugin.
parent eb329310
......@@ -128,6 +128,10 @@ class PluginAuthImap extends PluginAuth {
return true;
}
public static function is_usable() {
return extension_loaded('imap');
}
public static function get_instance_config_options($institution, $instance = 0) {
// TODO: put these strings in a lang file
$options['/imap'] = 'IMAP';
......
......@@ -27,6 +27,8 @@
defined('INTERNAL') || die();
$string['internal'] = 'Internal';
$string['title'] = 'Internal';
$string['description'] = 'Authenticate against Mahara\'s database';
$string['completeregistration'] = 'Complete Registration';
$string['emailalreadytaken'] = 'This e-mail address has already registered here';
......
......@@ -26,6 +26,10 @@
defined('INTERNAL') || die();
$string['title'] = 'LDAP';
$string['description'] = 'Authenticate against an LDAP server';
$string['notusable'] = 'Please install the PHP LDAP extension';
$string['contexts'] = 'Contexts';
$string['distinguishedname'] = 'Distinguished name';
$string['hosturl'] = 'Host URL';
......
......@@ -401,6 +401,10 @@ class PluginAuthLdap extends PluginAuth {
return true;
}
public static function is_usable() {
return extension_loaded('ldap');
}
public static function get_instance_config_options($institution, $instance = 0) {
// list of user_type
$utopt = array();
......
......@@ -654,6 +654,18 @@ function auth_get_available_auth_types($institution=null) {
return array();
}
foreach ($result as &$row) {
$row->title = get_string('title', 'auth.' . $row->name);
safe_require('auth', $row->name);
if ($row->is_usable = call_static_method('PluginAuth' . $row->name, 'is_usable')) {
$row->description = get_string('description', 'auth.' . $row->name);
}
else {
$row->description = get_string('notusable', 'auth.' . $row->name);
}
}
usort($result, create_function('$a, $b', 'return strnatcasecmp($a->title, $b->title);'));
return $result;
}
/**
......@@ -1424,6 +1436,14 @@ class PluginAuth extends Plugin {
return $subscriptions;
}
/**
* Can be overridden by plugins to assert when they are able to be used.
* For example, a plugin might check that a certain PHP extension is loaded
*/
public static function is_usable() {
return true;
}
public static function update_active_flag($event, $user) {
$active = true;
......
......@@ -26,6 +26,7 @@
defined('INTERNAL') || die();
$string['none'] = 'None';
$string['title'] = 'None';
$string['description'] = 'Anyone can log in. Use for testing only!';
?>
......@@ -443,6 +443,10 @@ class PluginAuthXmlrpc extends PluginAuth {
return true;
}
public static function is_usable() {
return extension_loaded('xmlrpc') && extension_loaded('openssl') && extension_loaded('curl');
}
public static function get_instance_config_options($institution, $instance = 0) {
$peer = new Peer();
......
......@@ -36,9 +36,6 @@ $string['unknowndbtype'] = 'Your server configuration references an unknown data
$string['libxmlextensionnotloaded'] = 'Your server configuration does not include the libxml extension. Mahara requires this in order to parse XML data for the installer and for backups. Please make sure that it is loaded in php.ini, or install it if it is not installed.';
$string['gdextensionnotloaded'] = 'Your server configuration does not include the gd extension. Mahara requires this in order to perform resizes and other operations on uploaded images. Please make sure that it is loaded in php.ini, or install it if it is not installed.';
$string['sessionextensionnotloaded'] = 'Your server configuration does not include the session extension. Mahara requires this in order to support users logging in. Please make sure that it is loaded in php.ini, or install it if it is not installed.';
$string['opensslextensionnotloaded'] = 'Your server configuration does not include the openssl extension. Mahara does not require this, but it is necessary if you wish to enable networking support.';
$string['curlextensionnotloaded'] = 'Your server configuration does not include the curl extension. Mahara does not require this, but it is necessary if you wish to enable networking support.';
$string['xmlrpcextensionnotloaded'] = 'Your server configuration does not include the xmlrpc extension. Mahara does not require this, but it is necessary if you wish to enable networking support.';
$string['registerglobals'] = 'You have dangerous PHP settings, register_globals is on. Mahara is trying to work around this, but you should really fix it';
$string['magicquotesgpc'] = 'You have dangerous PHP settings, magic_quotes_gpc is on. Mahara is trying to work around this, but you should really fix it';
$string['magicquotesruntime'] = 'You have dangerous PHP settings, magic_quotes_runtime is on. Mahara is trying to work around this, but you should really fix it';
......
......@@ -69,17 +69,6 @@ function ensure_sanity() {
throw new ConfigSanityException(get_string('sessionextensionnotloaded', 'error'));
}
// Various optional extensions
if (!extension_loaded('openssl')) {
log_environ(get_string('opensslextensionnotloaded', 'error'));
}
if (!extension_loaded('curl')) {
log_environ(get_string('curlextensionnotloaded', 'error'));
}
if (!extension_loaded('xmlrpc')) {
log_environ(get_string('xmlrpcextensionnotloaded', 'error'));
}
// register globals workaround
if (ini_get_bool('register_globals')) {
log_environ(get_string('registerglobals', 'error'));
......
......@@ -177,7 +177,8 @@ section name=mysec loop=$instancelist
}}<div class="authInstance" id="instanceDiv{{$instancelist[mysec]->id}}">
<label class="authLabel">
<a href="" onclick="editinstance({{$instancelist[mysec]->id}},'{{$instancelist[mysec]->authname}}'); return false;">
{{$instancelist[mysec]->instancename}}</a>
{{assign var=section value=$instancelist[mysec]->authname}}
{{str tag="title" section="auth.$section"}}</a>
</label>
<span class="authIcons" id="arrows{{$instancelist[mysec]->id}}">
{{ if $instancelist[mysec]->index + 1 < $instancelist[mysec]->total }}
......@@ -194,7 +195,7 @@ section name=mysec loop=$instancelist
<br>
<select name="dummy" id="dummySelect" {{if $institution eq ''}}disabled{{/if}}>
{{section name=mysec2 loop=$authtypes}}
<option>{{$authtypes[mysec2]->name}}</option>
<option value="{{$authtypes[mysec2]->name|escape}}"{{if !$authtypes[mysec2]->is_usable}} disabled="disabled"{{/if}}>{{$authtypes[mysec2]->title|escape}} - {{$authtypes[mysec2]->description|escape}}</option>
{{/section}}
</select>
<a href="" onclick="addinstance(); return false;">[+]</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment