]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
show current users certificates on profile page
authorChristian Weiske <cweiske@cweiske.de>
Mon, 9 May 2011 16:16:53 +0000 (18:16 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 9 May 2011 16:16:53 +0000 (18:16 +0200)
data/templates/editprofile-sslclientcerts.tpl.php [new file with mode: 0644]
data/templates/editprofile.tpl.php
src/SemanticScuttle/Model/User/SslClientCert.php [new file with mode: 0644]
src/SemanticScuttle/Service/User/SslClientCert.php
src/SemanticScuttle/header.php
www/profile.php
www/scuttle.css

diff --git a/data/templates/editprofile-sslclientcerts.tpl.php b/data/templates/editprofile-sslclientcerts.tpl.php
new file mode 100644 (file)
index 0000000..e6fc5c3
--- /dev/null
@@ -0,0 +1,25 @@
+<h3><?php echo T_('SSL client certificates'); ?></h3>
+<?php if (count($sslClientCerts)) { ?>
+<table>
+ <thead>
+  <tr>
+   <th><?php echo T_('Serial'); ?></th>
+   <th><?php echo T_('Name'); ?></th>
+   <th><?php echo T_('Email'); ?></th>
+   <th><?php echo T_('Issuer'); ?></th>
+  </tr>
+ </thead>
+ <tbody>
+ <?php foreach($sslClientCerts as $cert) { ?>
+   <tr <?php if ($cert->isCurrent()) { echo 'class="ssl-current"'; } ?>>
+   <td><?php echo htmlspecialchars($cert->sslSerial); ?></td>
+   <td><?php echo htmlspecialchars($cert->sslName); ?></td>
+   <td><?php echo htmlspecialchars($cert->sslEmail); ?></td>
+   <td><?php echo htmlspecialchars($cert->sslClientIssuerDn); ?></td>
+  </tr>
+ <?php } ?>
+ </tbody>
+</table>
+<?php } else { ?>
+ <p><?php echo T_('No certificates registered'); ?></p>
+<?php } ?>
index 2a3c3b8e9cf709e51d6cbd42b732564d9f35d988..cc74f04660454b7e1d2441a722bfe65530e65d80 100644 (file)
@@ -50,13 +50,15 @@ $this->includeTemplate($GLOBALS['top_include']);
     <td><input type="submit" name="submitted" value="<?php echo T_('Save Changes'); ?>" /></td>
 </tr>
 </table>
+
+<?php include 'editprofile-sslclientcerts.tpl.php'; ?>
 <h3><?php echo T_('Actions'); ?></h3>
 <table class="profile">
 <tr>
     <th align="left"><?php echo T_('Export bookmarks'); ?></th>
     <td>
        <a href="../api/export_html.php"><?php echo T_('HTML file (for browsers)')?></a> /
-       <a href="../api/posts_all.php"><?php echo T_('XML file (like del.icio.us)')?></a> / 
+       <a href="../api/posts_all.php"><?php echo T_('XML file (like del.icio.us)')?></a> /
        <a href="../api/export_csv.php"><?php echo T_('CSV file (for spreadsheet tools)')?></a>
     </td>
 </tr>
diff --git a/src/SemanticScuttle/Model/User/SslClientCert.php b/src/SemanticScuttle/Model/User/SslClientCert.php
new file mode 100644 (file)
index 0000000..ab7b288
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @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 <cweiske@cweiske.de>
+ * @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
index 9e7b2c48504638a95f9882ea8c23caacf08d255f..3c69788cf3ffe658bbd0b1aa1089e748d0a7d101 100644 (file)
@@ -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
index d81212439b54eede58c43f4178cdbddf31de8f3e..c1c0fcd985f8ce828700a7f42ef7a2b191398c54 100644 (file)
@@ -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')
index 35864dbc6d5258fc42aacf99e32962de50afb007..446c089d53a1bce6dcdd28696d97357cb05e3a5a 100644 (file)
@@ -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;
index 78f24e98d8b8e2f047363dfc48fb14d2ddb0b7f6..9e878573e46dae100cbb0a829bcb2b4fe1fdcdd0 100644 (file)
@@ -455,6 +455,10 @@ table.profile th {
     width: 10em;
 }
 
+table tr.ssl-current td {
+    background-color: #AFA;
+}
+
 /* OTHER GUFF */
 
 dd {