From 40940b95aaefd87f9af96439669cc6cb184d69ef Mon Sep 17 00:00:00 2001 From: Christophe Nowicki Date: Thu, 16 Sep 2004 15:57:55 +0000 Subject: New logging system with a web interface. --- php/Attic/examples/sample-idp/admin_user.php | 17 ++-- php/Attic/examples/sample-idp/index.php | 39 ++++----- php/Attic/examples/sample-idp/log_view.php | 108 +++++++++++++++++++++++++ php/Attic/examples/sample-idp/login.php | 20 +++-- php/Attic/examples/sample-idp/logout.php | 14 ++++ php/Attic/examples/sample-idp/setup.php | 38 +++++++-- php/Attic/examples/sample-idp/singleSignOn.php | 40 +++------ php/Attic/examples/sample-idp/soapEndpoint.php | 21 +++-- php/Attic/examples/sample-idp/user_add.php | 30 +++++-- php/Attic/examples/sample-sp/index.php | 35 ++++---- php/Attic/examples/sample-sp/login.php | 2 +- php/Attic/examples/sample-sp/setup.php | 9 +++ 12 files changed, 258 insertions(+), 115 deletions(-) create mode 100644 php/Attic/examples/sample-idp/log_view.php diff --git a/php/Attic/examples/sample-idp/admin_user.php b/php/Attic/examples/sample-idp/admin_user.php index 99d97457..ca5f14ba 100644 --- a/php/Attic/examples/sample-idp/admin_user.php +++ b/php/Attic/examples/sample-idp/admin_user.php @@ -22,16 +22,21 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - $config = unserialize(file_get_contents('config.inc')); - + require_once 'Log.php'; require_once 'DB.php'; + + $config = unserialize(file_get_contents('config.inc')); $number_of_users = 5; $db = &DB::connect($config['dsn']); if (DB::isError($db)) - die($db->getMessage()); + die("Could not connect to the database"); + + // create logger + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); // Show XML dump if (!empty($_GET['dump']) && !empty($_GET['type'])) @@ -105,9 +110,9 @@ if (!isset($_GET['show_all'])) $query .= " OFFSET $startUser LIMIT " . ($startUser + $number_of_users); $res =& $db->query($query); - if (DB::isError($res)) - die($res->getMessage()); - + + if (DB::isError($db)) + die($db->getMessage()); ?> diff --git a/php/Attic/examples/sample-idp/index.php b/php/Attic/examples/sample-idp/index.php index 09939e0a..44e4570d 100644 --- a/php/Attic/examples/sample-idp/index.php +++ b/php/Attic/examples/sample-idp/index.php @@ -65,41 +65,30 @@ You can get more informations about Lasso at

- - - - - - - - - - - - - + Identity Provider Administration
+ Setup
+ Users Management + +
View log + +

+

+ Identity Provider Fonctionnality
-

- - + Local Login
- + + Local Logout -
Identity Provider Administration
Setup
Users Management
Identity Provider Fonctionnality
Local Login

- +
+ * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + require_once 'HTML/QuickForm.php'; + require_once 'DB.php'; + + $config = unserialize(file_get_contents('config.inc')); + + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); + + if ($config['log_handler'] != 'sql') + die("Unsupported log handler"); + + $number_of_msg = 8; + + $startMsg = ((empty($_GET['startMsg'])) ? 0 : $_GET['startMsg']); + + $query = "SELECT * FROM log"; + if (!isset($_GET['show_all'])) + $query .= " OFFSET $startMsg LIMIT " . ($startMsg + $number_of_msg); + + $res =& $db->query($query); + if (DB::isError($db)) + die($db->getMessage()); + + +?> + + + + + View Logs + + +
+
Status
+ + + + + + + + + + +numCols(); + $tableinfo = $db->tableInfo($res); + + $desc = array("emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug"); + + while($row = $res->fetchRow()) + { + echo ""; + for ($i = 0; $i < $num_col; $i++) + { + switch ($tableinfo[$i]['name']) + { + case "id": + break; + case "priority": + echo ""; + break; + default: + echo ""; + } + } + echo ""; + } +?> + + + + + + +
Logged events
datefilenameprioritymessage
" . $desc[$row[$i]] . "" . $row[$i] . "
 
+
+

Copyright © 2004 Entr'ouvert

+ + + diff --git a/php/Attic/examples/sample-idp/login.php b/php/Attic/examples/sample-idp/login.php index 33bd4120..21b196f9 100644 --- a/php/Attic/examples/sample-idp/login.php +++ b/php/Attic/examples/sample-idp/login.php @@ -21,14 +21,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - $config = unserialize(file_get_contents('config.inc')); require_once 'HTML/QuickForm.php'; require_once 'Log.php'; require_once 'DB.php'; + $config = unserialize(file_get_contents('config.inc')); + + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); + // create logger - $logger = &Log::factory($config['log_handler'], '', $config['log_name']."::".$_SERVER['PHP_SELF']); + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); /* * @@ -70,15 +77,6 @@ return (0); } - $db = &DB::connect($config['dsn']); - - if (DB::isError($db)) - { - $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ALERT); - $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); - die("Could not connect to the database"); - } - if ($config['auth_type'] == 'auth_basic') { if (!isset($_SERVER['PHP_AUTH_USER'])) diff --git a/php/Attic/examples/sample-idp/logout.php b/php/Attic/examples/sample-idp/logout.php index 2114757f..8b5681b3 100644 --- a/php/Attic/examples/sample-idp/logout.php +++ b/php/Attic/examples/sample-idp/logout.php @@ -22,6 +22,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + require_once 'Log.php'; + require_once 'DB.php'; + + $config = unserialize(file_get_contents('config.inc')); + + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); + + // create logger + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); + session_start(); # Destroy The PHP Session diff --git a/php/Attic/examples/sample-idp/setup.php b/php/Attic/examples/sample-idp/setup.php index 5cc64f2b..d71de39f 100644 --- a/php/Attic/examples/sample-idp/setup.php +++ b/php/Attic/examples/sample-idp/setup.php @@ -78,8 +78,7 @@ $config = array( 'dsn' => "pgsql://idp:idp@localhost/idp", 'server_dump_filename' => "lasso_server_dump.xml", - 'log_name' => $_SERVER['SERVER_NAME'], - 'log_handler' => 'syslog', + 'log_handler' => 'sql', 'auth_type' => 'auth_form', 'idp-metadata' => $cwd . "/metadata_idp1.xml", 'idp-public_key' => $cwd . "/public-key_idp1.pem", @@ -252,6 +251,35 @@ print "OK"; + print "
Create table 'log' : "; + $query = "DROP TABLE log CASCADE"; + $res =& $db->query($query); + + $query = "CREATE TABLE log ( + id integer primary key, + logtime timestamp, + ident varchar(16), + priority integer, + message text)"; + + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + print "OK"; + + print "
Create sequence 'log_id' : "; + + $query = "DROP SEQUENCE log_id"; + $res =& $db->query($query); + + $query = "CREATE SEQUENCE log_id"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + print "OK"; + $db->disconnect(); // Check if IdP files does exists @@ -402,16 +430,12 @@ Logging - - Name : - ' maxlength='100'> -   - Handler :   diff --git a/php/Attic/examples/sample-idp/singleSignOn.php b/php/Attic/examples/sample-idp/singleSignOn.php index 45970fd2..9623e32c 100644 --- a/php/Attic/examples/sample-idp/singleSignOn.php +++ b/php/Attic/examples/sample-idp/singleSignOn.php @@ -23,13 +23,20 @@ */ require_once 'HTML/QuickForm.php'; + require_once 'Log.php'; require_once 'DB.php'; $config = unserialize(file_get_contents('config.inc')); + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); + // create logger - $logger = &Log::factory($config['log_handler'], '', $config['log_name']."::".$_SERVER['PHP_SELF']); - + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); + session_start(); lasso_init(); @@ -55,15 +62,7 @@ updateDumpsFromSession($login); initFromAuthnRequest($login); - // connect to the data base - $db = &DB::connect($config['dsn']); - if (DB::isError($db)) - { - $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ALERT); - $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); - die("Could not connect to the database"); - } - + // User must *NOT* Authenticate with the IdP if (!$login->mustAuthenticate()) @@ -385,16 +384,6 @@ die("Login dump is not registred"); } - // connect to the data base - $db = &DB::connect($config['dsn']); - - if (DB::isError($db)) - { - $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ALERT); - $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); - die("Could not connect to the database"); - } - $login = LassoLogin::newFromDump($server, $_SESSION['login_dump']); if (($user_id = authentificateUser($db, $form->exportValue('username'), @@ -430,15 +419,6 @@ // User must NOT Authenticate with the IdP if (!$login->mustAuthenticate()) { - // conect to the data base - $db = &DB::connect($config['dsn']); - if (DB::isError($db)) - { - $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ALERT); - $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); - die("Could not connect to the database"); - } - $user_id = getUserIDFromNameIdentifier($db, $login->nameIdentifier); if (!$user_id) diff --git a/php/Attic/examples/sample-idp/soapEndpoint.php b/php/Attic/examples/sample-idp/soapEndpoint.php index 7a7f8f09..887a5063 100644 --- a/php/Attic/examples/sample-idp/soapEndpoint.php +++ b/php/Attic/examples/sample-idp/soapEndpoint.php @@ -22,13 +22,19 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - require_once 'DB.php'; require_once 'Log.php'; + require_once 'DB.php'; header("Content-Type: text/xml\r\n"); + + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); - // create logger - $logger = &Log::factory($config['log_handler'], '', $config['log_name']."::".$_SERVER['PHP_SELF']); + // create logger + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); if (empty($HTTP_RAW_POST_DATA)) { @@ -45,15 +51,6 @@ $requestype = lasso_getRequestTypeFromSoapMsg($HTTP_RAW_POST_DATA); $server = LassoServer::newFromDump($server_dump); - $db = &DB::connect($config['dsn']); - - if (DB::isError($db)) - { - $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ALERT); - $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); - die("Could not connect to the database"); - } - switch ($requestype) { // Login diff --git a/php/Attic/examples/sample-idp/user_add.php b/php/Attic/examples/sample-idp/user_add.php index c763d3de..014677b1 100644 --- a/php/Attic/examples/sample-idp/user_add.php +++ b/php/Attic/examples/sample-idp/user_add.php @@ -1,6 +1,6 @@ addElement('header', null, 'Add New User'); @@ -37,18 +49,20 @@ if ($form->validate()) { - $config = unserialize(file_get_contents('config.inc')); - $db = &DB::connect($config['dsn']); - if (DB::isError($db)) - die($db->getMessage()); - - $query = "INSERT INTO users (user_id, username, password) VALUES(nextval('user_id_seq'),'"; - $query .= $form->exportValue('username') . "','" . $form->exportValue('password') . "')"; + $query = "INSERT INTO users (user_id, username, password) VALUES(nextval('user_id_seq'),"; + $query .= $db->quoteSmart($form->exportValue('username')) . ","; + $query .= $db->quoteSmart($form->exportValue('password')) . ")"; $res =& $db->query($query); if (DB::isError($res)) + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_ERR); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); die("username exist!"); + } + + $logger->log("Create User '" . $form->exportValue('username') . "'", PEAR_LOG_NOTICE); $db->disconnect(); ?> Lasso at

- - - - - - - +Service Provider Administration
+Setup
+Users Management
+

+

+ Serice Provider Fonctionnality +

Service Provider Administration
Setup
+ - + - + + - - + + - + + +
Users ManagementSingle SignOn using an IdP
Serice Provider FonctionnalityProviderProfile
Login!post | artifact
Logout!Single Logout
Logout!

+

- +
nameIdPolicy = lassoLibNameIDPolicyTypeFederated; $request->consent = lassoLibConsentObtained; - $login->buildAuthnRequestMsg("https://idp1/metadata"); + $login->buildAuthnRequestMsg($config['providerID']); $url = $login->msgUrl; diff --git a/php/Attic/examples/sample-sp/setup.php b/php/Attic/examples/sample-sp/setup.php index 01d283ed..eebd81ed 100644 --- a/php/Attic/examples/sample-sp/setup.php +++ b/php/Attic/examples/sample-sp/setup.php @@ -50,6 +50,7 @@ 'sp-public_key' => $cwd . "/public-key_sp1.pem", 'sp-private_key' => $cwd . "/private-key-raw_sp1.pem", 'sp-ca' => $cwd . "/certificate_sp1.pem", + 'providerID' => "https://idp1/metadata", 'idp-metadata' => $cwd . "/metadata_idp1.xml", 'idp-public_key' => $cwd . "/public-key_idp1.pem", 'idp-ca' => $cwd . "/certificate_idp1.pem", @@ -145,6 +146,7 @@ $keys = array_keys($config); $files = preg_grep("/(sp|idp)/", $keys); + foreach($files as $file) { print "
Check file " . $config[$file] . " : "; @@ -292,11 +294,18 @@ + + + + + + +
Status
Identity Provider
ProviderID :'> 
Metadata : '>  
Public Key : '> -- cgit