From 967ba79ece58dd0164accbf46078964c58fec230 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 9 May 2011 18:16:53 +0200 Subject: show current users certificates on profile page --- data/templates/editprofile-sslclientcerts.tpl.php | 25 ++++++++ data/templates/editprofile.tpl.php | 4 +- src/SemanticScuttle/Model/User/SslClientCert.php | 72 ++++++++++++++++++++++ src/SemanticScuttle/Service/User/SslClientCert.php | 28 +++++++++ src/SemanticScuttle/header.php | 1 + www/profile.php | 4 +- www/scuttle.css | 4 ++ 7 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 data/templates/editprofile-sslclientcerts.tpl.php create mode 100644 src/SemanticScuttle/Model/User/SslClientCert.php diff --git a/data/templates/editprofile-sslclientcerts.tpl.php b/data/templates/editprofile-sslclientcerts.tpl.php new file mode 100644 index 0000000..e6fc5c3 --- /dev/null +++ b/data/templates/editprofile-sslclientcerts.tpl.php @@ -0,0 +1,25 @@ +

+ + + + + + + + + + + + + isCurrent()) { echo 'class="ssl-current"'; } ?>> + + + + + + + +
sslSerial); ?>sslName); ?>sslEmail); ?>sslClientIssuerDn); ?>
+ +

+ diff --git a/data/templates/editprofile.tpl.php b/data/templates/editprofile.tpl.php index 2a3c3b8..cc74f04 100644 --- a/data/templates/editprofile.tpl.php +++ b/data/templates/editprofile.tpl.php @@ -50,13 +50,15 @@ $this->includeTemplate($GLOBALS['top_include']); + +

diff --git a/src/SemanticScuttle/Model/User/SslClientCert.php b/src/SemanticScuttle/Model/User/SslClientCert.php new file mode 100644 index 0000000..ab7b288 --- /dev/null +++ b/src/SemanticScuttle/Model/User/SslClientCert.php @@ -0,0 +1,72 @@ + + * @license AGPL http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * SSL client certificate model. Represents one single client certificate + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license AGPL http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_User_SslClientCert +{ + public $id; + public $uId; + public $sslSerial; + public $sslClientIssuerDn; + public $sslName; + public $sslEmail; + + /** + * Creates and returns a new object and fills it with + * tha passed values from the database. + * + * @param array $arCertRow Database row array + * + * @return SemanticScuttle_Model_User_SslClientCert + */ + public static function fromDb($arCertRow) + { + $cert = new self(); + foreach (get_object_vars($cert) as $variable => $dummy) { + if (isset($arCertRow[$variable])) { + $cert->$variable = $arCertRow[$variable]; + } + } + return $cert; + } + + + + /** + * Tells you if this certificate is the one the user is currently browsing + * with. + * + * @return boolean True if this certificate is the current browser's + */ + public function isCurrent() + { + if (!isset($_SERVER['SSL_CLIENT_M_SERIAL']) + || !isset($_SERVER['SSL_CLIENT_I_DN']) + ) { + return false; + } + + return $this->sslSerial == $_SERVER['SSL_CLIENT_M_SERIAL'] + && $this->sslClientIssuerDn == $_SERVER['SSL_CLIENT_I_DN']; + } + +} +?> \ No newline at end of file diff --git a/src/SemanticScuttle/Service/User/SslClientCert.php b/src/SemanticScuttle/Service/User/SslClientCert.php index 9e7b2c4..3c69788 100644 --- a/src/SemanticScuttle/Service/User/SslClientCert.php +++ b/src/SemanticScuttle/Service/User/SslClientCert.php @@ -180,5 +180,33 @@ class SemanticScuttle_Service_User_SslClientCert extends SemanticScuttle_DbServi return (int)$row['uId']; } + + /** + * Fetches all registered certificates for the user from the database + * and returns it. + * + * @return array Array with all certificates for the user. Empty if + * there are none, SemanticScuttle_Model_User_SslClientCert + * objects otherwise. + */ + public function getUserCerts($uId) + { + $query = 'SELECT * FROM ' . $this->getTableName() + . ' ORDER BY sslSerial DESC'; + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not load SSL client certificates', + '', __LINE__, __FILE__, $query, $this->db + ); + return array(); + } + + $certs = array(); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $certs[] = SemanticScuttle_Model_User_SslClientCert::fromDb($row); + } + $this->db->sql_freeresult($dbresult); + return $certs; + } } ?> \ No newline at end of file diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index d812124..c1c0fcd 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -84,6 +84,7 @@ require_once 'SemanticScuttle/Service/Factory.php'; require_once 'SemanticScuttle/functions.php'; require_once 'SemanticScuttle/Model/Bookmark.php'; require_once 'SemanticScuttle/Model/UserArray.php'; +require_once 'SemanticScuttle/Model/User/SslClientCert.php'; if (count($GLOBALS['serviceoverrides']) > 0 && !defined('UNIT_TEST_MODE') diff --git a/www/profile.php b/www/profile.php index 35864db..446c089 100644 --- a/www/profile.php +++ b/www/profile.php @@ -121,7 +121,9 @@ if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) { $templatename = 'editprofile.tpl.php'; $tplVars['formaction'] = createURL('profile', $user); $tplVars['token'] = $_SESSION['token']; - + $tplVars['sslClientCerts'] = SemanticScuttle_Service_Factory::get( + 'User_SslClientCert' + )->getUserCerts($currentUser->getId()); } $tplVars['objectUser'] = $userinfo; diff --git a/www/scuttle.css b/www/scuttle.css index 78f24e9..9e87857 100644 --- a/www/scuttle.css +++ b/www/scuttle.css @@ -455,6 +455,10 @@ table.profile th { width: 10em; } +table tr.ssl-current td { + background-color: #AFA; +} + /* OTHER GUFF */ dd { -- cgit v1.2.3
/ - / + /