Merge with updates from cweiske/master
authorJustin J. Novack <jnovack@gmail.com>
Mon, 17 Sep 2012 14:08:39 +0000 (10:08 -0400)
committerJustin J. Novack <jnovack@gmail.com>
Mon, 17 Sep 2012 14:08:39 +0000 (10:08 -0400)
39 files changed:
ChangeLog
README.rst
data/config.default.php
data/config.php.dist
data/templates/base.htm
data/templates/exception.htm
data/templates/forbidden.htm [new file with mode: 0644]
data/templates/login.htm [new file with mode: 0644]
data/templates/revision-head.htm
data/templates/user.htm [new file with mode: 0644]
src/openid/config.php [new file with mode: 0644]
src/openid/wrapper.php [new file with mode: 0644]
src/phorkie/Repository.php
src/phorkie/Repository/Post.php
www/.htaccess
www/auth.php [new file with mode: 0644]
www/css/debug.css [new file with mode: 0644]
www/css/openid.css [new file with mode: 0644]
www/css/phorkie.css [moved from www/phorkie.css with 100% similarity]
www/delete.php
www/display.php
www/edit.php
www/forbidden.php [new file with mode: 0644]
www/fork.php
www/images/access_denied.png [new file with mode: 0644]
www/images/google.gif [new file with mode: 0644]
www/images/openid-inputicon.gif [new file with mode: 0644]
www/images/yahoo.gif [new file with mode: 0644]
www/index.php
www/js/jquery-1.7.2.min.js [moved from www/jquery-1.7.2.min.js with 100% similarity]
www/js/phorkie.js [moved from www/phorkie.js with 100% similarity]
www/list.php
www/login.php [new file with mode: 0644]
www/new.php
www/raw.php
www/revision.php
www/secure.php [new file with mode: 0644]
www/user.php [new file with mode: 0644]
www/www-header.php

index afefa9afa245d166e6157e87ccfd9560faafc9f7..4a9cfc5d7be6c5e0b44f18ba7ce884a8b779adf9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-09-17  Justin J. Novack <jnovack@gmail.com>
+
+       * Add OpenID authentication
+
 2012-09-16  Christian Weiske  <cweiske@cweiske.de>
 
        * Implement request #12: DOAP documents for all pastes
index c94f29ed886a4c76d1afe6eae823fafcbf99fe64..56bef951efa6c46a0bcf4013c4775dbb43f102fb 100644 (file)
@@ -190,6 +190,15 @@ URLs
   List all pastes, with optional page
 ``/new``
   Shows form for new paste
+``/login``
+  Login page for protecting site
+``/auth``
+  Authentication callback url
+``/forbidden``
+  Access denied page
+``/user``
+  Edit logged-in user information
+
 
 Internal directory layout
 =========================
@@ -227,4 +236,9 @@ If you use nginx, place the following lines into your ``server`` block:
 
     rewrite ^/search$ /search.php;
     rewrite ^/search/([0-9]+)$ /search.php?page=$1;
+
+    rewrite ^/login$ /login.php;
+    rewrite ^/auth$ /auth.php;
+    rewrite ^/forbidden$ /forbidden.php;
+    rewrite ^/user$ /user.php;
   }
index 88c9ae5ef436427b05c39bad3ba2bf2e233711d3..da1624156fe5a92540eee913f74588a475e5c277 100644 (file)
@@ -12,6 +12,12 @@ $GLOBALS['phorkie']['cfg'] = array(
     'geshi'         => 'MediaWiki/geshi/geshi/geshi.php',
     'index'         => 'new'//"new" or "list"
 );
+$GLOBALS['phorkie']['auth'] = array(
+    'secure'         => 0,                   // 0 = public, no authentication, 1 = protect adds/edits/deletes, 2 = use authentication
+    'userlist'       => false,               // true = user must be explicitly defined, false = anyone allowed, but they must authenticate
+    'anonymousName'  => 'Anonymous',         // Email for non-authenticated commits
+    'anonymousEmail' => 'anonymous@phorkie'  // Email for non-authenticated commits
+);
 $GLOBALS['phorkie']['tools'] = array(
     '\\phorkie\\Tool_Xmllint' => true,
     '\\phorkie\\Tool_PHPlint' => true,
index 1e814bdb6de46a7b4e75461bed773d9abbddab37..e90f704ca28bd01094cc07c79a2879edaa14bb4e 100644 (file)
@@ -5,4 +5,8 @@
 //$GLOBALS['phorkie']['cfg']['git']['private'] = 'ssh://git@bogo:paste/';
 //$GLOBALS['phorkie']['cfg']['elasticsearch'] = 'http://localhost:9200/phorkie/';
 //$GLOBALS['phorkie']['cfg']['setupcheck'] = false;
+//$GLOBALS['phorkie']['users'] = array(
+//    'https://www.google.com/accounts/o8/id?id=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
+//    'http://anonymous.phorkie.openid'
+//);
 ?>
index b9c9608616a612355584f5e9f38a5d1c9b721322..ec2b7469d1398f2f7b229b62fbcc225693626002 100644 (file)
@@ -4,10 +4,10 @@
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link rel="stylesheet" href="{{css}}"/>
-  <link rel="stylesheet" href="/phorkie.css" />
+  <link rel="stylesheet" href="/css/phorkie.css" />
   <title>{% block title %}{% endblock %} - {{title}}</title>
-  <script src="/jquery-1.7.2.min.js"></script>
-  <script src="/phorkie.js"></script>
+  <script src="/js/jquery-1.7.2.min.js"></script>
+  <script src="/js/phorkie.js"></script>
   {% block meta %}{% endblock %}
  </head>
  <body>
       <li>
        <a href="/list">List all</a>
       </li>
+      {% if identity %}
+      <li>
+       <a href="/user">{{name}} ({{email}})</a>
+      </li>
+      <li>
+       <a href="/auth?logout">Logout</a>
+      </li>
+      {% endif %}
       {% if db.adapter %}
       <li>
        <form class="navbar-search pull-left" action="/search" method="get">
@@ -57,4 +65,4 @@
   </div>
 
  </body>
-</html>
\ No newline at end of file
+</html>
index dc07fc576eebfa608366592b413e9d187ffbb566..7a96da0c82fadcc9e9c88239461706fd1df89798 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
  <head>
-  <link rel="stylesheet" href="phorkie.css" />
+  <link rel="stylesheet" href="/css/phorkie.css" />
   <title>Error - phorkie</title>
  </head>
  <body>
diff --git a/data/templates/forbidden.htm b/data/templates/forbidden.htm
new file mode 100644 (file)
index 0000000..e6965dd
--- /dev/null
@@ -0,0 +1,25 @@
+{% extends "base.htm" %}
+{% block title %}Access Denied{% endblock %}
+
+{% block content %}
+
+<fieldset>
+  <legend>Access Denied</legend>
+  <img src="images/access_denied.png" align='left'>
+  <p>We're sorry, your identity is not authorized:</p>
+  <p><code>{{ identity }}</code></p>
+  <p>If you feel this message is in error, please notify the site admin
+    and include your identity.</p>
+</fieldset>
+{% endblock %}
+
+{% block sidebar %}
+ {% if recents.results %}
+ <h3>Recently created</h3>
+ <ul>
+ {% for repo in recents.repos %}
+   {% include 'repo-sidebar-list.htm' %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+{% endblock %}
diff --git a/data/templates/login.htm b/data/templates/login.htm
new file mode 100644 (file)
index 0000000..154994a
--- /dev/null
@@ -0,0 +1,30 @@
+{% extends "base.htm" %}
+{% block title %}Login{% endblock %}
+
+{% block content %}
+
+<link rel="stylesheet" href="css/openid.css" />
+
+<form method="post" action="/auth" id="openid_form">
+  <input id="start" name="start" type="hidden" value="submit" />
+  <input id="sreg" name="sreg" type="hidden" value="on" />
+  <input id="ax" name="ax" type="hidden" value="on" />
+
+<fieldset>
+  <legend>Sign-in</legend>
+  <div id="openid_choice" style="display: block; ">
+    <p>Please choose your account provider</p>
+    <div id="openid_btns">
+      <a title="Google" href="/auth?identifier=https://www.google.com/accounts/o8/id&ax=on&sreg=on&start=submit" class="google openid_large_btn"></a>
+      <a title="Yahoo" href="/auth?identifier=http://yahoo.com&ax=on&sreg=on&start=submit" class="yahoo openid_large_btn"></a>
+    </div>
+    <div id="openid_input_area">
+      <p>or enter your OpenID URL.</p>
+      <input class="" id="identifier" type="text" name="identifier" value="http://">
+      <input class="btn" id="openid_submit" type="submit" value="Sign-In">
+    </div>
+  </div>
+</fieldset>
+
+</form>
+{% endblock %}
index 132a68feb93bdcdd5993709b8e6e05354d86c4ff..a5f7e88cf9b95ebe668bdf7a7ad03856fe057bfd 100644 (file)
@@ -10,6 +10,7 @@
    revision <strong>{{repo.hash}}</strong>
   </p>
   <p>
+   message <strong>{{repo.message}}</strong>
   </p>
  </div>
  <div class="span2">
diff --git a/data/templates/user.htm b/data/templates/user.htm
new file mode 100644 (file)
index 0000000..c8ef387
--- /dev/null
@@ -0,0 +1,15 @@
+{% extends "base.htm" %}
+{% block title %}User Preferences{% endblock %}
+
+{% block content %}
+
+<form method="post" action="/user" id="user_form">
+<fieldset>
+  <legend>User Profile</legend>
+   <p>Please update your git preferences for <code>{{ identity }}</code></p>
+   <label for='name'>Name:</label><input class="" id="name" type="text" name="name" width="35" value="{{ name }}"><br/>
+   <label for='email'>Email:</label><input class="" id="email" type="text" name="email" width="35" value="{{ email }}"><br/>
+   <input class="btn" id="submit" type="submit" value="Update">
+</fieldset>
+</form>
+{% endblock %}
diff --git a/src/openid/config.php b/src/openid/config.php
new file mode 100644 (file)
index 0000000..fdec5e1
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * OpenID 
+ * 
+ * PHP Version 5.2.0+
+ * 
+ * @category  Auth
+ * @package   OpenID
+ * @author    Bill Shupp <hostmaster@shupp.org> 
+ * @copyright 2009 Bill Shupp
+ * @license   http://www.opensource.org/licenses/bsd-license.php FreeBSD
+ * @link      http://github.com/shupp/openid
+ */
+
+set_include_path(dirname(__FILE__) . '/../../:' . get_include_path());
+
+/**
+ * Required files
+ */
+require_once 'OpenID/RelyingParty.php';
+require_once 'OpenID/Discover.php';
+require_once 'OpenID/Store.php';
+require_once 'OpenID/Extension/SREG10.php';
+require_once 'OpenID/Extension/SREG11.php';
+require_once 'OpenID/Extension/AX.php';
+require_once 'OpenID/Extension/UI.php';
+require_once 'OpenID/Extension/OAuth.php';
+require_once 'OpenID/Message.php';
+require_once 'OpenID/Observer/Log.php';
+require_once 'Net/URL2.php';
+
+// Determine realm and return_to
+$base = 'http';
+if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+    $base .= 's';
+}
+$base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
+
+$realm    = $base . '/';
+$returnTo = $base . dirname($_SERVER['PHP_SELF']);
+if ($returnTo[strlen($returnTo) - 1] != '/') {
+    $returnTo .= '/';
+}
+$returnTo .= 'auth';
+
+// SQL storage example
+// $storeOptions = array(
+//     'dsn' => 'mysql://user:pass@db.example.com/openid'
+// );
+// OpenID::setStore(OpenID_Store::factory('MDB2', $storeOptions));
+//
+// // The first time you run it, you'll also need to create the tables:
+// OpenID::getStore()->createTables();
+
+?>
diff --git a/src/openid/wrapper.php b/src/openid/wrapper.php
new file mode 100644 (file)
index 0000000..cb57f4e
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ * OpenID 
+ * 
+ * PHP Version 5.2.0+
+ * 
+ * @category  Auth
+ * @package   OpenID
+ * @author    Bill Shupp <hostmaster@shupp.org> 
+ * @copyright 2009 Bill Shupp
+ * @license   http://www.opensource.org/licenses/bsd-license.php FreeBSD
+ * @link      http://github.com/shupp/openid
+ */
+?>
+<html>
+    <head>
+        <title>PEAR OpenID Debug</title>
+        <link rel="stylesheet" href="/css/debug.css" type="text/css" />
+    </head>
+    <body>
+<?php
+if (isset($contents)) {
+    echo $contents;
+}
+?>
+    </body>
+</html>
index 46b2f6526fa4d2ee083a6e541141361ce638a436..995a16d01282272b381467496e7a183c8156c27a 100644 (file)
@@ -32,6 +32,12 @@ class Repository
      */
     public $hash;
 
+    /**
+     * Commit message of the last (or current) revision
+     *
+     * @var string
+     */
+    public $message;
 
 
     /**
@@ -56,6 +62,7 @@ class Repository
         $this->id = (int)$_GET['id'];
         $this->loadDirs();
         $this->loadHash();
+        $this->loadMessage();
     }
 
     protected function loadDirs()
@@ -97,6 +104,23 @@ class Repository
         $this->hash = $output;
     }
 
+    public function loadMessage()
+    {
+        $rev = (isset($this->hash)) ? $this->hash : 'HEAD';
+        $output = $this->getVc()->getCommand('log')
+            ->setOption('oneline')
+            ->addArgument('-1')
+            ->addArgument($rev)
+            ->execute();
+        $output = trim($output);
+        if (strpos($output, ' ') > 0) {
+            $output = substr($output, strpos($output, ' '), strlen($output));
+            $this->message = trim($output);
+        } else {
+            $this->message = "This commit message intentionally left blank.";
+        }
+    }
+
     public function loadById($id)
     {
         if (!is_numeric($id)) {
index de987e0a74fe07e70245c7cbd53df8e99957399d..ed44cf1535bd030d2f3ff364e8c4e6d4c23d02b1 100644 (file)
@@ -15,7 +15,7 @@ class Repository_Post
      *
      * @return boolean True if the post was successful
      */
-    public function process($postData)
+    public function process($postData, $sessionData)
     {
         if (!isset($postData['files'])) {
             return false;
@@ -117,11 +117,17 @@ class Repository_Post
             }
         }
 
+        $commitmsg = "phorkie commit";
+        if (isset($sessionData['identity'])) {
+            $commitmsg .= " from ".$sessionData['identity'];
+        } else {
+            $commitmsg .= " by ".$sessionData['ipaddr'];
+        }
+
         if ($bCommit) {
             $vc->getCommand('commit')
-                ->setOption('message', '')
-                ->setOption('allow-empty-message')
-                ->setOption('author', 'Anonymous <anonymous@phorkie>')
+                ->setOption('message', $commitmsg)
+                ->setOption('author', $sessionData['name'].' <'.$sessionData['email'].'>')
                 ->execute();
             $bChanged = true;
         }
index c379b234b9b81c63b7b176561f4068cdca2d2dcf..4c52627c5f369a025ae0d7a78d63453299c9d636 100644 (file)
@@ -20,3 +20,8 @@ RewriteRule ^list/([0-9]+)$ /list.php?page=$1
 
 RewriteRule ^search$ /search.php
 RewriteRule ^search/([0-9]+)$ /search.php?page=$1
+
+RewriteRule ^auth$ /auth.php
+RewriteRule ^login$ /login.php
+RewriteRule ^forbidden$ /forbidden.php
+RewriteRule ^user$ /user.php
diff --git a/www/auth.php b/www/auth.php
new file mode 100644 (file)
index 0000000..b8d08ff
--- /dev/null
@@ -0,0 +1,223 @@
+<?php
+/**
+ * OpenID 
+ * 
+ * PHP Version 5.2.0+
+ * 
+ * @category  Auth
+ * @package   OpenID
+ * @author    Bill Shupp <hostmaster@shupp.org> 
+ * @copyright 2009 Bill Shupp
+ * @license   http://www.opensource.org/licenses/bsd-license.php FreeBSD
+ * @link      http://github.com/shupp/openid
+ */
+
+// A tool for testing Relying Party functionality
+set_include_path(
+    __DIR__ . '/../../src/'
+    . PATH_SEPARATOR . get_include_path()
+);
+
+require_once 'www-header.php';
+require_once 'openid/config.php';
+
+
+if (isset($_REQUEST['logout'])) {
+    unset($_SESSION);
+    session_destroy();
+    $redirect = 'http://' . $_SERVER['HTTP_HOST'];
+    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
+       exit;
+}
+
+if (!count($_GET) && !count($_POST)) {
+    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/login";
+    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
+    exit;
+}
+
+// Hackaround Non-Javascript Login Page
+if (!count($_POST) && isset($_GET['start'])) {
+    $_POST = $_GET;
+}
+
+if (isset($_POST['identifier'])) {
+    $identifier = $_POST['identifier'];
+} else if (isset($_SESSION['identifier'])) {
+    $identifier = $_SESSION['identifier'];
+} else {
+    $identifier = null;
+}
+
+try {
+    $o = new OpenID_RelyingParty($returnTo, $realm, $identifier);
+} catch (OpenID_Exception $e) {
+    $contents  = "<div class='openid_results'>\n";
+    $contents .= "<pre>" . $e->getMessage() . "</pre>\n";
+    $contents .= "</div class='openid_results'>";
+    include_once 'openid/wrapper.php';
+    exit;
+}
+
+if (!empty($_POST['disable_associations'])
+    || !empty($_SESSION['disable_associations'])) {
+
+    $o->disableAssociations();
+    $_SESSION['disable_associations'] = true;
+}
+
+$log = new OpenID_Observer_Log;
+OpenID::attach($log);
+
+if (isset($_POST['start'])) {
+
+    $_SESSION['identifier'] = $identifier;
+    try {
+        $authRequest = $o->prepare();
+    } catch (OpenID_Exception $e) {
+        $contents  = "<div class='openid_results'>\n";
+        $contents .= "<pre>" . $e->getMessage() . "</pre>\n";
+        $contents .= "</div class='openid_results'>";
+        include_once 'openid/wrapper.php';
+        exit;
+    }
+
+    // checkid_immediate
+    if (!empty($_POST['checkid_immediate'])) {
+        $authRequest->setMode('checkid_immediate');
+    }
+
+    // SREG
+    if (!empty($_POST['sreg'])) {
+        $sreg = new OpenID_Extension_SREG11(OpenID_Extension::REQUEST);
+        $sreg->set('required', 'email,firstname,lastname,nickname');
+        $sreg->set('optional', 'gender,dob');
+        $authRequest->addExtension($sreg);
+    }
+
+    // AX
+    if (!empty($_POST['ax'])) {
+        $ax = new OpenID_Extension_AX(OpenID_Extension::REQUEST);
+        $ax->set('type.email', 'http://axschema.org/contact/email');
+        $ax->set('type.firstname', 'http://axschema.org/namePerson/first');
+        $ax->set('type.lastname', 'http://axschema.org/namePerson/last');
+        $ax->set('mode', 'fetch_request');
+        $ax->set('required', 'email,firstname,lastname');
+        $authRequest->addExtension($ax);
+    }
+
+    // UI
+    if (!empty($_POST['ui'])) {
+        $ui = new OpenID_Extension_UI(OpenID_Extension::REQUEST);
+        $ui->set('mode', 'popup');
+        $ui->set('language', 'en-US');
+        $authRequest->addExtension($ui);
+    }
+
+    // OAuth
+    if (!empty($_POST['oauth'])) {
+        $oauth = new OpenID_Extension_OAuth(OpenID_Extension::REQUEST);
+        $oauth->set('consumer', $_POST['oauth_consumer_key']);
+        $_SESSION['OAuth_consumer_key']    = $_POST['oauth_consumer_key'];
+        $_SESSION['OAuth_consumer_secret'] = $_POST['oauth_consumer_secret'];
+
+        $oauth->set('scope', $_POST['oauth_scope']);
+        $_SESSION['OAuth_scope'] = $_POST['oauth_scope'];
+
+        $_SESSION['OAuth_access_token_url']    = $_POST['oauth_access_token_url'];
+        $_SESSION['OAuth_access_token_method'] = $_POST['oauth_access_token_method'];
+
+        $authRequest->addExtension($oauth);
+    }
+    
+    $url = $authRequest->getAuthorizeURL();
+    
+    if (empty($_POST['debug'])) {
+        header("Location: $url");
+        exit;
+    }
+    
+} else {
+    if (isset($_SESSION['identifier'])) {
+        $usid = $_SESSION['identifier'];
+        unset($_SESSION['identifier']);
+    } else {
+        $usid = null;
+    }
+
+    unset($_SESSION['disable_associations']);
+
+    if (!count($_POST)) {
+        list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']);
+    } else {
+        // I hate php sometimes
+        $queryString = file_get_contents('php://input');
+    }
+
+    $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
+    $id      = $message->get('openid.claimed_id');
+    $mode    = $message->get('openid.mode');
+
+    try {
+        $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString),
+                                          $message);
+
+        if ($result->success()) {
+            $status  = "<tr><td>Status:</td><td><font color='green'>SUCCESS!";
+            $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
+        } else {
+            $status  = "<tr><td>Status:</td><td><font color='red'>FAIL!";
+            $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
+        }
+    } catch (OpenID_Exception $e) {
+        $status  = "<tr><td>Status:</td><td><font color='red'>EXCEPTION!";
+        $status .= " ({$e->getMessage()} : {$e->getCode()})</font></td></tr>";
+    }
+
+    // OAuth hyprid fetching access token
+    if (isset($_SESSION['OAuth_consumer_key'],
+              $_SESSION['OAuth_consumer_secret'],
+              $_SESSION['OAuth_access_token_url'],
+              $_SESSION['OAuth_access_token_method'])) {
+
+        try {
+            $oauth = new OpenID_Extension_OAuth(OpenID_Extension::RESPONSE,
+                                                $message);
+
+            // Fix line lengths.
+            $consumerKey    = $_SESSION['OAuth_consumer_key'];
+            $consumerSecret = $_SESSION['OAuth_consumer_key'];
+            $tokenURL       = $_SESSION['OAuth_access_token_url'];
+            $tokenMethod    = $_SESSION['OAuth_access_token_method'];
+
+            $oauthData = $oauth->getAccessToken($consumerKey,
+                                                $consumerSecret,
+                                                $tokenURL,
+                                                array(),
+                                                $tokenMethod);
+
+        } catch (Exception $e) {
+        }
+    }
+
+    $openid = $message->getArrayFormat();
+
+       $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null;
+    $email = (isset($openid['openid.ext2.value.email']) && !isset($email)) ? $openid['openid.ext2.value.email'] : $email;
+    $email = (isset($openid['openid.sreg.email']) && !isset($email)) ? $openid['openid.sreg.email'] : $email;
+    $email = (isset($openid['openid.ax.value.email']) && !isset($email)) ? $openid['openid.ax.value.email'] : $email;
+    $_SESSION['email'] = (isset($email)) ? $email : $GLOBALS['phorkie']['auth']['anonymousEmail'];
+
+    $name = (isset($openid['openid.ext1.value.firstname']) && isset($openid['openid.ext1.value.lastname'])) ? $openid['openid.ext1.value.firstname']." ".$openid['openid.ext1.value.lastname'] : null;
+    $name = (isset($openid['openid.sreg.firstname']) && isset($openid['openid.sreg.lastname']) && !isset($name)) ? $openid['openid.sreg.firstname']." ".$openid['openid.sreg.lastname'] : $name;
+    $name = (isset($openid['openid.sreg.nickname']) && !isset($name)) ? $openid['openid.sreg.nickname'] : $name;
+    $_SESSION['name'] = (isset($name)) ? $name : $_SERVER['REMOTE_ADDR'];
+
+    $_SESSION['identity'] = $openid['openid.identity'];
+
+    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SESSION['REQUEST_URI'];
+    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
+    exit;
+}
+
+?>
diff --git a/www/css/debug.css b/www/css/debug.css
new file mode 100644 (file)
index 0000000..634243a
--- /dev/null
@@ -0,0 +1,85 @@
+html, body {
+    background: #ededed;
+    font: 82.5% Helvetica Neue, HelveticaNeue, Helvetica, sans-serif;
+    margin: 30px 0 0; padding: 0px; }
+
+h3 {
+    color: #aaa;
+    margin: 0; padding: 0;
+    font-size: 1.3em;
+    
+    position: absolute;
+    top: 30px;
+    width: 100%;
+    text-align: center;
+    left: 0;
+}
+
+h3 a {
+    color: #111;
+    text-decoration: none;
+}
+
+h3 a:hover {
+    text-decoration: underline;
+    
+}
+
+form {
+    padding: 30px;
+    background: #fff;
+        -moz-border-radius: 6px;
+    -webkit-border-radius: 6px;
+    width: 400px;
+    margin: 50px auto 0;
+    }
+    
+table {
+        font-size: 1.1em !important;
+        font-weight: bold;
+}
+
+td {
+    width: 200px;
+}
+.discover_results {
+    margin: 60px 0 ;
+    padding: 30px;
+    background: #111;
+    text-align: center;
+}
+
+
+.discover_results b {
+    color: #fff;
+    font-size: 2.4em;
+}
+
+.relyingparty_results {
+    width: 100%;
+}
+
+.relyingparty_results table b {
+    display: block;
+    width: 300px;   
+    font-size: 1.7em;
+    color: #fff;
+}
+
+
+pre, .relyingparty_results p table {
+    font-size: 1.2em;
+    width: 900px !important;
+    text-align: left;
+    margin: 0 auto;
+    
+    color: #ddd;
+    padding: 30px;
+
+}
+
+.relyingparty_results {
+    background: #111;
+    padding: 30px;
+    margin: 60px 0;
+}
diff --git a/www/css/openid.css b/www/css/openid.css
new file mode 100644 (file)
index 0000000..38988a7
--- /dev/null
@@ -0,0 +1,64 @@
+body {
+  font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
+}
+#openid_form {
+  width: 470px;        
+}
+#openid_form legend {
+  font-weight: bold;
+}
+#openid_choice {
+  display: none;
+}
+#openid_input_area {
+  clear: both;
+}
+#openid_btns {
+  height: 66px;
+  margin-bottom: 10px;
+}
+#openid_btns br {
+  clear: both;
+}
+#openid_highlight {
+  padding: 3px;
+  background-color: #FFFCC9;
+  float: left;
+}
+#identifier {
+  margin: 0px !important;
+  width: 250px;
+  background: #FFF url(/images/openid-inputicon.gif) no-repeat scroll 0 50%;
+  padding-left:18px;
+}
+.openid_large_btn {
+  width: 100px;
+  height: 60px;
+  border: 1px solid #DDD;
+  margin: 3px;
+  float: left;
+}
+.openid_small_btn {
+  width: 24px;
+  height: 24px;
+  border: 1px solid #DDD;
+  margin: 3px;
+  float: left;
+}
+.google {
+  background: #FFF url(/images/google.gif) no-repeat center center;
+}
+.yahoo {
+  background: #FFF url(/images/yahoo.gif) no-repeat center center;
+}
+
+a.openid_large_btn:hover {
+  outline: none;
+  border: 1px solid #030303;
+}
+a.openid_large_btn:focus {
+  -moz-outline-style: none;
+}
+.openid_selected {
+  border: 4px solid #DDD;
+}      
similarity index 100%
rename from www/phorkie.css
rename to www/css/phorkie.css
index 6d68ae4486d4ce365fd0e31c7289bb17bd46ee89..f332028876216ec01e636e78145d467f1f6d6605 100644 (file)
@@ -4,6 +4,9 @@ namespace phorkie;
  * Delete paste or ask for deletion
  */
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] > 0) {
+    require_once 'secure.php';
+}
 
 $repo = new Repository();
 $repo->loadFromRequest();
index c8df8a9963b92ef2e82da0a6d1626f659bb86010..2376d30b58416ec5112c108539161eb7ac4cc5a1 100644 (file)
@@ -4,6 +4,9 @@ namespace phorkie;
  * Display paste contents
  */
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] == 2) {
+    require_once 'secure.php';
+}
 
 $repo = new Repository();
 $repo->loadFromRequest();
index 562c97cbd5391f8441e0bf28df2343c8d3068fe5..db4428b3cb36958778bf86cafb408bb58428fa49 100644 (file)
@@ -4,12 +4,15 @@ namespace phorkie;
  * Edit paste contents
  */
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] > 0) {
+    require_once 'secure.php';
+}
 
 $repo = new Repository();
 $repo->loadFromRequest();
 
 $repopo = new Repository_Post($repo);
-if ($repopo->process($_POST)) {
+if ($repopo->process($_POST, $_SESSION)) {
     redirect($repo->getLink('display'));
 }
 
diff --git a/www/forbidden.php b/www/forbidden.php
new file mode 100644 (file)
index 0000000..1f587a2
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Access Denied
+ */
+namespace phorkie;
+require_once 'www-header.php';
+
+$db = new Database();
+render(
+    'forbidden',
+    array(
+        'recents'     => $db->getSearch()->listAll(0, 5, 'crdate', 'desc'),
+    )
+);
+?>
index 799763273667ec8388b1f94e70ab3688c9af60f9..cc2ed33c68de4d754162b4f0e4e81630d8cdcf3f 100644 (file)
@@ -4,6 +4,9 @@
  */
 namespace phorkie;
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] > 0) {
+    require_once 'secure.php';
+}
 
 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
     throw new Exception_Input('Forking only possible via POST');
diff --git a/www/images/access_denied.png b/www/images/access_denied.png
new file mode 100644 (file)
index 0000000..c13d7b9
Binary files /dev/null and b/www/images/access_denied.png differ
diff --git a/www/images/google.gif b/www/images/google.gif
new file mode 100644 (file)
index 0000000..1b6cd07
Binary files /dev/null and b/www/images/google.gif differ
diff --git a/www/images/openid-inputicon.gif b/www/images/openid-inputicon.gif
new file mode 100644 (file)
index 0000000..cde836c
Binary files /dev/null and b/www/images/openid-inputicon.gif differ
diff --git a/www/images/yahoo.gif b/www/images/yahoo.gif
new file mode 100644 (file)
index 0000000..42adbfa
Binary files /dev/null and b/www/images/yahoo.gif differ
index 9a05add9b9741d78ce46a87345123577fe4821dc..7ac6fcfbc868cefd485775280c4a3cec1e04e081 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+/**
+ * Jump to the index as per the configuration
+ */
 namespace phorkie;
 require_once 'www-header.php';
 require_once $GLOBALS['phorkie']['cfg']['index'].".php";
similarity index 100%
rename from www/phorkie.js
rename to www/js/phorkie.js
index 911f26d1a728b54dcb7a9d22d452cae65d539dc6..17f46b1eb6de7de8f89db8881356e509cca0753b 100644 (file)
@@ -1,9 +1,12 @@
 <?php
 /**
- * Fork a repository
+ * List a repository
  */
 namespace phorkie;
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] == 2) {
+    require_once 'secure.php';
+}
 $rs = new Repositories();
 
 $page = 0;
diff --git a/www/login.php b/www/login.php
new file mode 100644 (file)
index 0000000..87c34f4
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Display sign-in page
+ */
+namespace phorkie;
+require_once 'www-header.php';
+render(
+    'login',
+    null
+);
+?>
index ef9daecf50b7c96d89f8bad3921da56070c7ea74..8d1a231d1ff9e339f2bc062702c886ea074ddc20 100644 (file)
@@ -11,9 +11,12 @@ namespace phorkie;
  * Creates and redirects to display page
  */
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] > 0) {
+    require_once 'secure.php';
+}
 
 $repopo = new Repository_Post();
-if ($repopo->process($_POST)) {
+if ($repopo->process($_POST, $_SESSION)) {
     redirect($repopo->repo->getLink('display'));
 }
 
index 8bda11e8fbaeb9b363bb726bf27239ad9de32eef..67a21ee2287b818e211651f74fc9440a0d5b5f77 100644 (file)
@@ -4,6 +4,9 @@
  */
 namespace phorkie;
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] == 2) {
+    require_once 'secure.php';
+}
 $repo = new Repository();
 $repo->loadFromRequest();
 
index 53ac4581b45b379a4d84e5c57b56b9a5d1689a31..06462afa72f9e6af525241a65e2c4700ce212074 100644 (file)
@@ -4,6 +4,9 @@ namespace phorkie;
  * Display paste contents
  */
 require_once 'www-header.php';
+if ($GLOBALS['phorkie']['auth']['secure'] == 2) {
+    require_once 'secure.php';
+}
 
 $repo = new Repository();
 $repo->loadFromRequest();
diff --git a/www/secure.php b/www/secure.php
new file mode 100644 (file)
index 0000000..4b81d59
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+/** 
+ * Protect page
+ */
+namespace phorkie;
+require_once 'www-header.php';
+$_SESSION['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
+if (!isset($_SESSION['identity'])) {
+    header("Location: /login");
+    exit;
+}
+if ($GLOBALS['phorkie']['auth']['secure'] > 0 &&
+    $GLOBALS['phorkie']['auth']['userlist']) {
+    if (!in_array($_SESSION['identity'], $GLOBALS['phorkie']['users'])) {
+        $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/forbidden";
+        header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
+        exit;
+    }
+}
+?>
diff --git a/www/user.php b/www/user.php
new file mode 100644 (file)
index 0000000..1cc8aeb
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Edit user information
+ */
+namespace phorkie;
+require_once 'www-header.php';
+if (!isset($_SESSION['identity'])) {
+    require_once 'secure.php';
+}
+
+if (isset($_POST['name'])) {
+    $_SESSION['name'] = substr(filter_var($_POST['name'], FILTER_SANITIZE_STRING), 0, 35);
+}
+
+if (isset($_POST['email'])) {
+    $_SESSION['email'] = substr(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL), 0, 35);
+}
+
+render(
+    'user',
+    array(
+        'identity' => $_SESSION['identity'],
+        'name'     => $_SESSION['name'],
+        'email'    => $_SESSION['email']
+    )
+);
+?>
index 72a2e670578149cc5ac97d6430bb5390550b4c38..5785a3ec300ff16552a627896f99ebf65e71fca2 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace phorkie;
+session_start();
 set_include_path(
     __DIR__ . '/../src/'
     . PATH_SEPARATOR . get_include_path()
@@ -46,6 +47,12 @@ if (file_exists(__DIR__ . '/../data/config.php')) {
 if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
     SetupCheck::run();
 }
+
+// Set/Get git commit session variables
+$_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR'];
+if (!isset($_SESSION['name']))  { $_SESSION['name']  = $GLOBALS['phorkie']['auth']['anonymousName'];  }
+if (!isset($_SESSION['email'])) { $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail']; }
+
 \Twig_Autoloader::register();
 
 $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']);
@@ -63,6 +70,11 @@ function render($tplname, $vars)
     $vars['css'] = $GLOBALS['phorkie']['cfg']['css'];
     $vars['title'] = $GLOBALS['phorkie']['cfg']['title'];
     $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar'];
+    if (isset($_SESSION['identity'])) {
+        $vars['identity'] = $_SESSION['identity'];
+        $vars['name'] = $_SESSION['name'];
+        $vars['email'] = $_SESSION['email'];
+    }
     $vars['db'] = new Database();
 
     $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
@@ -73,4 +85,4 @@ function redirect($target)
     header('Location: ' . $target);
     exit();
 }
-?>
\ No newline at end of file
+?>