Update of /cvsroot/php-blog/additional_plugins/serendipity_event_externalauth
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16591/additional_plugins/serendipity_event_externalauth
Modified Files:
serendipity_event_externalauth.php
Log Message:
fix linebreaks
Index: serendipity_event_externalauth.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_externalauth/serendipity_event_externalauth.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- serendipity_event_externalauth.php 6 Jan 2005 10:12:46 -0000 1.2
+++ serendipity_event_externalauth.php 7 Jan 2005 12:11:09 -0000 1.3
@@ -1,214 +1,218 @@
-<?php # $Id$
-
-switch ($serendipity['lang']) {
- case 'de':
- @define('PLUGIN_EVENT_EXTERNALAUTH_TITLE', 'Externe Benutzer-Authentifizierung (LDAP) [EXPERIMENTAL]');
- @define('PLUGIN_EVENT_EXTERNALAUTH_DESC', 'Ermöglicht die externe authentifizierung für Logins der Benutzer. Die Zugangsdaten werden im lokalen Serendipity Datenbank-Framework gecached.');
- @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE', 'Authentifizierungs-Quelle');
- @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC', 'Wählen Sie die Quelle der externen Zugangsdaten');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL', 'Standard Benutzerlevel');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC', 'Wählen Sie den Standard-Benutzerlevel für einen neu hinzugefügten externen Benutzer');
- @define('PLUGIN_EVENT_EXTERNALAUTH_HOST', 'Ziel-Host');
- @define('PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC', 'Auf welchem Server befindet sich die Authentifizierungsquelle');
- @define('PLUGIN_EVENT_EXTERNALAUTH_PORT', 'Ziel-Port');
- @define('PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC', 'Verbindungs-Port der Authentifizierungsquelle. Ein leerer Wert nutzt den Standardport.');
- @define('PLUGIN_EVENT_EXTERNALAUTH_RDN', 'Authentifizierungsstring');
- @define('PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC', 'String für die Authentifizierung. %1 wird durch den Benutzernamen, %2 durch das Passwort und %3 durch das MD5-kodierte Passwort ersetzt');
- @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN', 'Externe Authentifizierung nur einmalig durchführen');
- @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC', 'Soll die externe Authentifizierung nur einmal pro Session ausgeführt werden, oder bei jeder Anfrage? JA wird die Geschwindigkeit erhöhen, NEIN die Sicherheit.');
-
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF', 'Chefredakteur');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR', 'Editor');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN', 'Administrator');
- break;
-
- case 'en':
- default:
- @define('PLUGIN_EVENT_EXTERNALAUTH_TITLE', 'External user authentication (LDAP) [EXPERIMENTAL]');
- @define('PLUGIN_EVENT_EXTERNALAUTH_DESC', 'Allows to use external ressource to validate logins. Logins will be cached in the Serendipity database framework.');
- @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE', 'Source of external authentication');
- @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC', 'Select the source of your external user credentials');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL', 'Default userlevel');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC', 'Which is the default userlevel for a new external user');
- @define('PLUGIN_EVENT_EXTERNALAUTH_HOST', 'Authentication host');
- @define('PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC', 'Enter the location of the authentication host');
- @define('PLUGIN_EVENT_EXTERNALAUTH_PORT', 'Authentication host port');
- @define('PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC', 'Enter the port of the authentication host. Empty value will use the default port');
- @define('PLUGIN_EVENT_EXTERNALAUTH_RDN', 'Authentication string');
- @define('PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC', 'String used for authentication. %1 will be replaced by the username, %2 will contain the password and %3 the MD5-encoded password');
- @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN', 'Only perform once per session');
- @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC', 'Should the external auth only take place once for a whole session, or upon each request. TRUE will increase performance, FALSE will increase security.');
-
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF', 'Chief');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR', 'Editor');
- @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN', 'Administrator');
- break;
-}
-
-class serendipity_event_externalauth extends serendipity_event
-{
- var $title = PLUGIN_EVENT_EXTERNALAUTH_TITLE;
-
- function introspect(&$propbag)
- {
- global $serendipity;
-
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_TITLE);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_DESC);
- $propbag->add('stackable', false);
- $propbag->add('author', 'Garvin Hicking');
- $propbag->add('version', '1.0');
- $propbag->add('event_hooks', array(
- 'backend_auth' => true
- ));
- $propbag->add('configuration', array('host', 'port', 'rdn', 'source', 'userlevel', 'firstlogin'));
- }
-
- function introspect_config_item($name, &$propbag)
- {
- switch($name) {
- case 'firstlogin':
- $propbag->add('type', 'boolean');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC);
- $propbag->add('default', true);
- break;
-
- case 'rdn':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_RDN);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC);
- $propbag->add('default', 'uid=%1,ou=people,dc=yourdomain,dc=com');
- break;
-
- case 'port':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_PORT);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC);
- $propbag->add('default', '');
- break;
-
- case 'port':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_PORT);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC);
- $propbag->add('default', '');
- break;
-
- case 'host':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_HOST);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC);
- $propbag->add('default', 'localhost');
- break;
-
- case 'source':
- $propbag->add('type', 'select');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_SOURCE);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC);
- $propbag->add('default', 'LDAP');
- $propbag->add('select_values', array('LDAP' => 'LDAP'));
- break;
-
- case 'userlevel':
- $propbag->add('type', 'select');
- $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL);
- $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC);
- $propbag->add('default', USERLEVEL_EDITOR);
- $propbag->add('select_values', array(
- PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN => USERLEVEL_ADMIN,
- PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF => USERLEVEL_CHIEF,
- PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR => USERLEVEL_EDITOR,
-
- ));
- break;
- }
- return true;
- }
-
- function generate_content(&$title) {
- $title = PLUGIN_EVENT_EXTERNALAUTH_TITLE;
- }
-
- function event_hook($event, &$bag, &$eventData) {
- global $serendipity;
-
- $hooks = &$bag->get('event_hooks');
- if (isset($hooks[$event])) {
- switch($event) {
- case 'backend_auth':
- $is_md5 =& $eventData;
- if ($is_md5) {
- $md5_password = $password;
- } else {
- $md5_password = md5($password);
- }
-
- if ($_SESSION['serendipityAuthedUser'] == true && serendipity_db_bool($this->get_config('firstlogin'))) {
- return true;
- }
-
- switch($this->get_config('source')) {
- case 'LDAP':
- default:
- $port = $this->get_config('port');
- if (!empty($port)) {
- $ds = ldap_connect($this->get_config('host'), $port);
- } else {
- $ds = ldap_connect($this->get_config('host'));
- }
-
- if ($ds) {
- $rdn = str_replace(
- array(
- '%1',
- '%2',
- '%3'
- ),
-
- array(
- $addData['username'],
- $addData['password'],
- $md5_password
- ),
-
- $this->get_config('rdn')
- );
- $valid = ldap_bind($ds, $rdn, $addData['password']);
- ldap_close($ds);
- } else {
- $valid = false;
- }
- break;
- }
-
- if ($valid) {
- serendipity_db_query("UPDATE {$serendipity['dbPrefix']}authors
- SET password = '" . serendipity_db_escape_string($md5_password) . "'
- WHERE username = '" . serendipity_db_escape_string($addData['username']) . "'");
- if (serendipity_db_affected_rows() == 0) {
- serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}authors (username, password, email, mail_comments, mail_trackbacks, userlevel)
- VALUES ('". serendipity_db_escape_string($addData['username']) ."', '". serendipity_db_escape_string($md5_password) . "', '', 1, 1, " . $this->get_config('userlevel') . ")");
- }
- } else {
- // If an account is no longer valid in the external source we set the password to something unknown. We can't delete it because that would destroy article references.
- serendipity_db_query("UPDATE {$serendipity['dbPrefix']}authors
- SET password = '" . serendipity_db_escape_string(md5(time())) . "'
- WHERE username = '" . serendipity_db_escape_string($addData['username']) . "'");
- }
-
- return true;
- break;
-
- default:
- return false;
- break;
- }
- } else {
- return false;
- }
- }
-}
-
-/* vim: set sts=4 ts=4 expandtab : */
-?>
\ No newline at end of file
+<?php # $Id$
+
+switch ($serendipity['lang']) {
+ case 'de':
+ @define('PLUGIN_EVENT_EXTERNALAUTH_TITLE', 'Externe Benutzer-Authentifizierung (LDAP) [EXPERIMENTAL]');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_DESC', 'Ermöglicht die externe authentifizierung für Logins der Benutzer. Die Zugangsdaten werden im lokalen Serendipity Datenbank-Framework gecached.');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE', 'Authentifizierungs-Quelle');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC', 'Wählen Sie die Quelle der externen Zugangsdaten');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL', 'Standard Benutzerlevel');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC', 'Wählen Sie den Standard-Benutzerlevel für einen neu hinzugefügten externen Benutzer');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_HOST', 'Ziel-Host');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC', 'Auf welchem Server befindet sich die Authentifizierungsquelle');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_PORT', 'Ziel-Port');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC', 'Verbindungs-Port der Authentifizierungsquelle. Ein leerer Wert nutzt den Standardport.');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_RDN', 'Authentifizierungsstring');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC', 'String für die Authentifizierung. %1 wird durch den Benutzernamen, %2 durch das Passwort und %3 durch das MD5-kodierte Passwort ersetzt');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN', 'Externe Authentifizierung nur einmalig durchführen');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC', 'Soll die externe Authentifizierung nur einmal pro Session ausgeführt werden, oder bei jeder Anfrage? JA wird die Geschwindigkeit erhöhen, NEIN die Sicherheit.');
+
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF', 'Chefredakteur');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR', 'Editor');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN', 'Administrator');
+ break;
+
+ case 'en':
+ default:
+ @define('PLUGIN_EVENT_EXTERNALAUTH_TITLE', 'External user authentication (LDAP) [EXPERIMENTAL]');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_DESC', 'Allows to use external ressource to validate logins. Logins will be cached in the Serendipity database framework.');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE', 'Source of external authentication');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC', 'Select the source of your external user credentials');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL', 'Default userlevel');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC', 'Which is the default userlevel for a new external user');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_HOST', 'Authentication host');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC', 'Enter the location of the authentication host');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_PORT', 'Authentication host port');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC', 'Enter the port of the authentication host. Empty value will use the default port');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_RDN', 'Authentication string');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC', 'String used for authentication. %1 will be replaced by the username, %2 will contain the password and %3 the MD5-encoded password');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN', 'Only perform once per session');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC', 'Should the external auth only take place once for a whole session, or upon each request. TRUE will increase performance, FALSE will increase security.');
+
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF', 'Chief');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR', 'Editor');
+ @define('PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN', 'Administrator');
+ break;
+}
+
+class serendipity_event_externalauth extends serendipity_event
+{
+ var $title = PLUGIN_EVENT_EXTERNALAUTH_TITLE;
+
+ function introspect(&$propbag)
+ {
+ global $serendipity;
+
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_TITLE);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_DESC);
+ $propbag->add('stackable', false);
+ $propbag->add('author', 'Garvin Hicking');
+ $propbag->add('version', '1.0');
+ $propbag->add('event_hooks', array(
+ 'backend_auth' => true
+ ));
+ $propbag->add('configuration', array('host', 'port', 'rdn', 'source', 'userlevel', 'firstlogin'));
+ }
+
+ function introspect_config_item($name, &$propbag)
+ {
+ switch($name) {
+ case 'firstlogin':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_FIRSTLOGIN_DESC);
+ $propbag->add('default', true);
+ break;
+
+ case 'rdn':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_RDN);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_RDN_DESC);
+ $propbag->add('default', 'uid=%1,ou=people,dc=yourdomain,dc=com');
+ break;
+
+ case 'port':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_PORT);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC);
+ $propbag->add('default', '');
+ break;
+
+ case 'port':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_PORT);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_PORT_DESC);
+ $propbag->add('default', '');
+ break;
+
+ case 'host':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_HOST);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_HOST_DESC);
+ $propbag->add('default', 'localhost');
+ break;
+
+ case 'source':
+ $propbag->add('type', 'select');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_SOURCE);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_SOURCE_DESC);
+ $propbag->add('default', 'LDAP');
+ $propbag->add('select_values', array('LDAP' => 'LDAP'));
+ break;
+
+ case 'userlevel':
+ $propbag->add('type', 'select');
+ $propbag->add('name', PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL);
+ $propbag->add('description', PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_DESC);
+ $propbag->add('default', USERLEVEL_EDITOR);
+ $propbag->add('select_values', array(
+ PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_ADMIN => USERLEVEL_ADMIN,
+ PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_CHIEF => USERLEVEL_CHIEF,
+ PLUGIN_EVENT_EXTERNALAUTH_USERLEVEL_EDITOR => USERLEVEL_EDITOR,
+
+ ));
+ break;
+ }
+ return true;
+ }
+
+ function generate_content(&$title) {
+ $title = PLUGIN_EVENT_EXTERNALAUTH_TITLE;
+ }
+
+ function event_hook($event, &$bag, &$eventData) {
+ global $serendipity;
+
+ $hooks = &$bag->get('event_hooks');
+ if (isset($hooks[$event])) {
+ switch($event) {
+ case 'backend_auth':
+ $is_md5 =& $eventData;
+ if ($is_md5) {
+ $md5_password = $password;
+ } else {
+ $md5_password = md5($password);
+ }
+
+ if ($_SESSION['serendipityAuthedUser'] == true && serendipity_db_bool($this->get_config('firstlogin'))) {
+ return true;
+ }
+
+ switch($this->get_config('source')) {
+ case 'LDAP':
+ default:
+ if (!function_exists('ldap_connect')) {
+ return false;
+ }
+
+ $port = $this->get_config('port');
+ if (!empty($port)) {
+ $ds = ldap_connect($this->get_config('host'), $port);
+ } else {
+ $ds = ldap_connect($this->get_config('host'));
+ }
+
+ if ($ds) {
+ $rdn = str_replace(
+ array(
+ '%1',
+ '%2',
+ '%3'
+ ),
+
+ array(
+ $addData['username'],
+ $addData['password'],
+ $md5_password
+ ),
+
+ $this->get_config('rdn')
+ );
+ $valid = ldap_bind($ds, $rdn, $addData['password']);
+ ldap_close($ds);
+ } else {
+ $valid = false;
+ }
+ break;
+ }
+
+ if ($valid) {
+ serendipity_db_query("UPDATE {$serendipity['dbPrefix']}authors
+ SET password = '" . serendipity_db_escape_string($md5_password) . "'
+ WHERE username = '" . serendipity_db_escape_string($addData['username']) . "'");
+ if (serendipity_db_affected_rows() == 0) {
+ serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}authors (username, password, email, mail_comments, mail_trackbacks, userlevel)
+ VALUES ('". serendipity_db_escape_string($addData['username']) ."', '". serendipity_db_escape_string($md5_password) . "', '', 1, 1, " . $this->get_config('userlevel') . ")");
+ }
+ } else {
+ // If an account is no longer valid in the external source we set the password to something unknown. We can't delete it because that would destroy article references.
+ serendipity_db_query("UPDATE {$serendipity['dbPrefix']}authors
+ SET password = '" . serendipity_db_escape_string(md5(time())) . "'
+ WHERE username = '" . serendipity_db_escape_string($addData['username']) . "'");
+ }
+
+ return true;
+ break;
+
+ default:
+ return false;
+ break;
+ }
+ } else {
+ return false;
+ }
+ }
+}
+
+/* vim: set sts=4 ts=4 expandtab : */
+?>
|