summaryrefslogtreecommitdiffstats
path: root/php
diff options
context:
space:
mode:
authorChristophe Nowicki <cnowicki@easter-eggs.com>2004-09-16 15:57:55 +0000
committerChristophe Nowicki <cnowicki@easter-eggs.com>2004-09-16 15:57:55 +0000
commit40940b95aaefd87f9af96439669cc6cb184d69ef (patch)
treef0d65eaa1369aeaca88f5774f2ca2cba4932ca27 /php
parent7ea2275ca076a880c27448cdbdfe09ffa9f15db8 (diff)
downloadlasso-40940b95aaefd87f9af96439669cc6cb184d69ef.tar.gz
lasso-40940b95aaefd87f9af96439669cc6cb184d69ef.tar.xz
lasso-40940b95aaefd87f9af96439669cc6cb184d69ef.zip
New logging system with a web interface.
Diffstat (limited to 'php')
-rw-r--r--php/Attic/examples/sample-idp/admin_user.php17
-rw-r--r--php/Attic/examples/sample-idp/index.php39
-rw-r--r--php/Attic/examples/sample-idp/log_view.php108
-rw-r--r--php/Attic/examples/sample-idp/login.php20
-rw-r--r--php/Attic/examples/sample-idp/logout.php14
-rw-r--r--php/Attic/examples/sample-idp/setup.php38
-rw-r--r--php/Attic/examples/sample-idp/singleSignOn.php40
-rw-r--r--php/Attic/examples/sample-idp/soapEndpoint.php21
-rw-r--r--php/Attic/examples/sample-idp/user_add.php30
-rw-r--r--php/Attic/examples/sample-sp/index.php35
-rw-r--r--php/Attic/examples/sample-sp/login.php2
-rw-r--r--php/Attic/examples/sample-sp/setup.php9
12 files changed, 258 insertions, 115 deletions
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());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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 <b>Lasso</b> at <br>
<body>
<p>
-<table border="1" frame="above">
-<tr>
- <td><b>Identity Provider Administration</b></td>
-</tr>
-<tr>
- <td><a href="setup.php">Setup</a></td>
-</tr>
-<tr>
- <td><a href="admin_user.php">Users Management</a></td>
-</tr>
-<tr>
- <td><b>Identity Provider Fonctionnality</b></td>
-</tr>
+ <b>Identity Provider Administration</b><br>
+ <a href="setup.php">Setup</a><br>
+ <a href="admin_user.php">Users Management</a>
+<?php if ($config['log_handler'] == 'sql') { ?>
+ <br><a href="log_view.php">View log</a>
+<?php } ?>
+</p>
+<p>
+ <b>Identity Provider Fonctionnality</b><br>
<?php
if (!isset($_SESSION["user_id"])) {
?>
-<tr>
- <td><a href="login.php">Local Login</a></td>
-</tr>
+ <a href="login.php">Local Login</a><br>
<?php } else { ?>
-<tr>
+<!--
<td><a href="federate.php">Create federation</a></td>
-</tr>
-<tr>
<td><a href="defederate.php">Destroy federation</a></td>
-</tr>
-<tr>
- <td><a href="logout.php">Local Logout</a></td>
-</tr>
+-->
+ <a href="logout.php">Local Logout</a>
<?php } ?>
-</table>
</p>
<p>
-<table border="1" frame="above">
+<table>
<caption><b>Status</b></caption>
<tr>
<?php
diff --git a/php/Attic/examples/sample-idp/log_view.php b/php/Attic/examples/sample-idp/log_view.php
new file mode 100644
index 00000000..fb68fbdc
--- /dev/null
+++ b/php/Attic/examples/sample-idp/log_view.php
@@ -0,0 +1,108 @@
+<?php
+/*
+ * Identity Provider Example -- View log
+ *
+ * Copyright (C) 2004 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: Christophe Nowicki <cnowicki@easter-eggs.com>
+ *
+ * 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());
+
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<head>
+ <title>View Logs</title>
+</head>
+<body>
+<br>
+<table border='1' width='100%'>
+<caption>Logged events</caption>
+<thead>
+<tr>
+ <td align='center'>date</td>
+ <td align='center'>filename</td>
+ <td align='center'>priority</td>
+ <td align='center'>message</td>
+</tr>
+</thead>
+<tbody>
+<?php
+ $num_col = $res->numCols();
+ $tableinfo = $db->tableInfo($res);
+
+ $desc = array("emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug");
+
+ while($row = $res->fetchRow())
+ {
+ echo "<tr>";
+ for ($i = 0; $i < $num_col; $i++)
+ {
+ switch ($tableinfo[$i]['name'])
+ {
+ case "id":
+ break;
+ case "priority":
+ echo "<td align='center'>" . $desc[$row[$i]] . "</td>";
+ break;
+ default:
+ echo "<td align='center'>" . $row[$i] . "</td>";
+ }
+ }
+ echo "</tr>";
+ }
+?>
+<tr>
+</tr>
+</tbody>
+<tfoot>
+<td colspan='5'>&nbsp;</td>
+</tfoot>
+</table>
+<br>
+<p>Copyright &copy; 2004 Entr'ouvert</p>
+</body>
+</html>
+
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 "<br>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 "<br>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
@@ -403,15 +431,11 @@
<td colspan='3' align='center'>Logging</td>
</tr>
<tr>
- <td>Name :</td>
- <td><input type='text' name='log_name' size='50' value='<?php echo $config['log_name']; ?>' maxlength='100'></td>
- <td>&nbsp;</td>
-</tr>
-<tr>
<td>Handler :</td>
<td>
<select name='log_handler'>
<option value="null" <?php if ($config['log_handler'] == 'null') echo 'selected="selected"'; ?>>NULL (disabled)</option>
+ <option value="sql" <?php if ($config['log_handler'] == 'sql') echo 'selected="selected"'; ?>>Database</option>
<option value="syslog" <?php if ($config['log_handler'] == 'syslog') echo 'selected="selected"'; ?>>Syslog</option>
</select>
</td><td>&nbsp;</td>
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 @@
<?php
/*
- * Service Provider Example -- User Administration
+ * Identity Provider Example -- User Administration
*
* Copyright (C) 2004 Entr'ouvert
* http://lasso.entrouvert.org
@@ -23,8 +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
+ $conf['db'] = $db;
+ $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf);
+
$form = new HTML_QuickForm('frm');
$form->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();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
diff --git a/php/Attic/examples/sample-sp/index.php b/php/Attic/examples/sample-sp/index.php
index 700198f4..199e8286 100644
--- a/php/Attic/examples/sample-sp/index.php
+++ b/php/Attic/examples/sample-sp/index.php
@@ -66,34 +66,39 @@ You can get more informations about <b>Lasso</b> at <br>
<body>
<p>
-<table border="1" frame="above">
-<tr>
- <td><b>Service Provider Administration</b></td>
-</tr>
-<tr>
- <td><a href="setup.php">Setup</a></td>
-</tr>
+<b>Service Provider Administration</b><br>
+<a href="setup.php">Setup</a><br>
+<a href="admin_user.php">Users Management</a><br>
+</p>
+<p>
+ <b>Serice Provider Fonctionnality</b>
+<table>
+<?php
+ if (!isset($_SESSION["nameidentifier"])) {
+ ?>
<tr>
- <td><a href="admin_user.php">Users Management</a></td>
+ <td colspan="2">Single SignOn using an IdP</td>
</tr>
<tr>
- <td><b>Serice Provider Fonctionnality</b></td>
+ <td>Provider</td>
+ <td>Profile</td>
</tr>
-<?php
- if (!isset($_SESSION["nameidentifier"])) {
- ?>
<tr>
- <td><a href="login.php">Login!</a></td>
+ <td><?php echo $config['providerID']; ?></td>
+ <td><a href="login.php">post</a> | <a href="login.php">artifact</a></td>
</tr>
<?php } else { ?>
<tr>
- <td><a href="logout.php">Logout!</a></td>
+ <td colspan="2">Single Logout</td>
+<tr>
+ <td colspan="2"><a href="logout.php">Logout!</a></td>
</tr>
<?php } ?>
</table>
</p>
+
<p>
-<table border="1" frame="above">
+<table>
<caption><b>Status</b></caption>
<tr>
<?php
diff --git a/php/Attic/examples/sample-sp/login.php b/php/Attic/examples/sample-sp/login.php
index 339a8a2e..229aa28a 100644
--- a/php/Attic/examples/sample-sp/login.php
+++ b/php/Attic/examples/sample-sp/login.php
@@ -42,7 +42,7 @@
$request->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 "<br>Check file " . $config[$file] . " : ";
@@ -293,10 +295,17 @@
</tr>
<tr>
+ <td>ProviderID :</td>
+ <td><input type='text' name='providerID' size='50' value='<?php echo $config['providerID']; ?>'></td>
+ <td>&nbsp;</td>
+</tr>
+
+<tr>
<td>Metadata :</td>
<td><input type='text' name='idp-metadata' size='50' value='<?php echo $config['idp-metadata']; ?>'></td>
<td>&nbsp;</td>
</tr>
+
<tr>
<td>Public Key :</td>
<td><input type='text' name='idp-public_key' size='50' value='<?php echo $config['idp-public_key']; ?>'>