Merge remote-tracking branch 'jnovack/markdown'
authorChristian Weiske <cweiske@cweiske.de>
Tue, 18 Sep 2012 22:10:19 +0000 (00:10 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 18 Sep 2012 22:10:19 +0000 (00:10 +0200)
Conflicts:
ChangeLog

48 files changed:
ChangeLog
README.rst
data/config.default.php
data/config.php.dist
data/templates/base.htm
data/templates/display-sidebar-history.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/new.htm
data/templates/pager.htm
data/templates/revision-head.htm
data/templates/user.htm [new file with mode: 0644]
src/phorkie/File.php
src/phorkie/GitCommandBinary.php
src/phorkie/HtmlHelper.php
src/phorkie/Repository.php
src/phorkie/Repository/Commit.php
src/phorkie/Repository/Post.php
src/phorkie/Tool/Manager.php
src/phorkie/Tool/Result.php
src/phorkie/Tool/Result/Line.php
src/phorkie/Tools.php
www/.htaccess
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/doap.php
www/edit.php
www/forbidden.php [new file with mode: 0644]
www/fork.php
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 99% similarity]
www/list.php
www/login.php [new file with mode: 0644]
www/new.php
www/raw.php
www/revision.php
www/search.php
www/tool.php
www/user.php [new file with mode: 0644]
www/www-header.php
www/www-security.php [new file with mode: 0644]

index 8557be7f9beead4c78a936983bafd4e6aa44ce4b..1dc1447a0165b431f0a5d6178c66965fb1286363 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
        * Add Markdown as a known file-type.
 
+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 4a157bf606bce64ba5dc999ee5bd12ce528d53fe..d41d89bf61f9f5e9e7878d50802b1405473adf3f 100644 (file)
@@ -195,6 +195,11 @@ URLs
   List all pastes, with optional page
 ``/new``
   Shows form for new paste
+``/login``
+  Login page for protecting site
+``/user``
+  Edit logged-in user information
+
 
 Internal directory layout
 =========================
@@ -233,4 +238,7 @@ 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 ^/user$ /user.php;
   }
index 3fc48f68226445e72e221f7c25118814e216fd4f..abcb43e071a4cdcd397495c60f6fdf4ccd9f7be7 100644 (file)
@@ -12,6 +12,15 @@ $GLOBALS['phorkie']['cfg'] = array(
     'geshi'         => 'MediaWiki/geshi/geshi/geshi.php',
     'index'         => 'new'//"new" or "list"
 );
+$GLOBALS['phorkie']['auth'] = array(
+    // 0 = public, no authentication, 1 = protect adds/edits/deletes,
+    // 2 = require authentication
+    'securityLevel'   => 0,
+    'listedUsersOnly' => false,
+    'users'           => array(),             // Array of OpenIDs that may login
+    '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..ced993f508afe4e654b5d8c337358e874c9b4e04 100644 (file)
@@ -5,4 +5,11 @@
 //$GLOBALS['phorkie']['cfg']['git']['private'] = 'ssh://git@bogo:paste/';
 //$GLOBALS['phorkie']['cfg']['elasticsearch'] = 'http://localhost:9200/phorkie/';
 //$GLOBALS['phorkie']['cfg']['setupcheck'] = false;
+
+//$GLOBALS['phorkie']['auth']['securityLevel'] = 0;
+//$GLOBALS['phorkie']['auth']['listedUsersOnly'] = false;
+//$GLOBALS['phorkie']['auth']['users'] = array(
+//    'https://www.google.com/accounts/o8/id?id=ABCDEFGHIJKLMNOPQRSTUVWXYZ',
+//    'http://anonymous.phorkie.openid'
+//);
 ?>
index b9c9608616a612355584f5e9f38a5d1c9b721322..dc065662b29b37eb91c0d8f926c4d7ce20e6cbff 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>
       {% if db.adapter %}
       <li>
-       <form class="navbar-search pull-left" action="/search" method="get">
+       <form class="navbar-search" action="/search" method="get">
         <input type="text" class="search-query" name="q" placeholder="Search" value="{{query}}"/>
        </form>
       </li>
       {% endif %}
      </ul>
+     <ul class="nav pull-right">
+      {% if identity %}
+      <li>
+       <a href="/user">{{name}} ({{email}})</a>
+      </li>
+      <li>
+       <a href="/login?logout">Logout</a>
+      </li>
+      {% else %}
+      <li>
+       <a href="/login">Login</a>
+      </li>
+      {% endif %}
+     </ul>
     </div>
    </div>
   </div>
@@ -53,8 +67,8 @@
    <a href="//sf.net/p/phorkie/">phorkie</a>,
    the self-hosted, git-based pastebin software is available under the
    <a href="https://sf.net/p/phorkie/">
-    <acronym title="GNU Affero General Public License">AGPL</acronym></a>.
+    <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
   </div>
 
  </body>
-</html>
\ No newline at end of file
+</html>
index b3ef9df3f0e0aba95ce407f48251fc9e95f3ffb6..bf388843395d7d800fcbbec21c7f5b039b2eac53 100644 (file)
@@ -15,4 +15,4 @@
 {% else %}
 <p>No commits yet</p>
 {% endfor %}
-</ul>
\ No newline at end of file
+</ul>
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..a39bcf7
--- /dev/null
@@ -0,0 +1,24 @@
+{% extends "base.htm" %}
+{% block title %}Access Denied{% endblock %}
+
+{% block content %}
+
+<h2>Access Denied</h2>
+{% if identity %}
+<p>
+ You are logged in with the following OpenID:
+</p>
+<p>
+ <code>{{identity}}</code>
+</p>
+<p>
+ Unfortunately, your OpenID is not unlocked.
+ Contact the site administrator to get access.
+</p>
+{% else %}
+<p>
+ We're sorry; but you have to <a href="/login">log in</a> to access this page.
+</p>
+{% endif %}
+{% endblock %}
+
diff --git a/data/templates/login.htm b/data/templates/login.htm
new file mode 100644 (file)
index 0000000..084b438
--- /dev/null
@@ -0,0 +1,27 @@
+{% extends "base.htm" %}
+{% block title %}Login{% endblock %}
+
+{% block content %}
+
+<link rel="stylesheet" href="css/openid.css" />
+
+<form method="post" action="/login" id="openid_form">
+
+<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="/login?openid_url=https://www.google.com/accounts/o8/id" class="google openid_large_btn"></a>
+      <a title="Yahoo" href="/login?openid_url=http://yahoo.com/" class="yahoo openid_large_btn"></a>
+    </div>
+    <div id="openid_input_area">
+      <p>or enter your OpenID URL.</p>
+      <input id="openid_url" type="text" name="openid_url" value="http://" />
+      <input class="btn" id="openid_submit" type="submit" value="Sign in" />
+    </div>
+  </div>
+</fieldset>
+
+</form>
+{% endblock %}
index 5b75bbac62d2a5587536b288574b62d9f1800d89..89c2fe01a5d4168f75e877e26f1d02269e459abf 100644 (file)
@@ -37,4 +37,4 @@ $(document).ready(function() {
  {% endfor %}
  </ul>
  {% endif %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
index 085a281d7091aa529f47940d2ce84bd5342a743f..9be2b9f4ecddbf64c4e242f2da634423299fff60 100644 (file)
@@ -45,4 +45,4 @@
  {% endif %}
 </ul>
 </div>
-{% endif %}
\ No newline at end of file
+{% endif %}
index 132a68feb93bdcdd5993709b8e6e05354d86c4ff..9a60b05fa56ad40dc98f10bee92d19e192283454 100644 (file)
@@ -9,8 +9,6 @@
   <p>
    revision <strong>{{repo.hash}}</strong>
   </p>
-  <p>
-  </p>
  </div>
  <div class="span2">
  </div>
diff --git a/data/templates/user.htm b/data/templates/user.htm
new file mode 100644 (file)
index 0000000..eb032bd
--- /dev/null
@@ -0,0 +1,16 @@
+{% 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.</p>
+   <p><label>OpenID:</label><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 %}
index 331f2e546be5b72b96c9d96960ca8b7c4f6526e6..f378f60a75f58614003e39b913d702f9fbd3a763 100644 (file)
@@ -165,4 +165,4 @@ class File
     }
 }
 
-?>
\ No newline at end of file
+?>
index 13a31db30a5274ffe63400982d4156ef1fdbe64e..a0053491f307f87a3d88265475a494b35c4a1c4d 100644 (file)
@@ -12,4 +12,4 @@ class GitCommandBinary extends \VersionControl_Git_Util_Command
     }
 }
 
-?>
\ No newline at end of file
+?>
index af046cf2c8caa03fc7495f93136298404d8a0a35..ea21ab59cafa6706f37387543cbd4143535569cc 100644 (file)
@@ -25,4 +25,4 @@ class HtmlHelper
     }
 }
 
-?>
\ No newline at end of file
+?>
index 46b2f6526fa4d2ee083a6e541141361ce638a436..43f2b23dddf0be98f7ac56626cd1cc506be35541 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,28 @@ class Repository
         $this->hash = $output;
     }
 
+       /**
+     * Populates $this->message
+     *
+     * @return void
+     */
+    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 05c988b5be0210570a56e99b96acf5f4631a9507..62f1d408cb8f09373d2b3709479af07881f510c2 100644 (file)
@@ -70,4 +70,4 @@ class Repository_Commit
     }
 }
 
-?>
\ No newline at end of file
+?>
index de987e0a74fe07e70245c7cbd53df8e99957399d..9119e06c2ce0f1484351dc63ce688060898cbecf 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,23 @@ class Repository_Post
             }
         }
 
+        $commitmsg = "phorkie commit";
+
+        if (isset($sessionData['identity'])) {
+            $notes = $sessionData['identity'];
+        } else {
+            $notes = $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();
+            //FIXME: git needs ref BEFORE add. ideally VersionControl_Git needs to be updated
+            $vc->getCommand('notes --ref=identity add')
+                               ->setOption('force')
+                ->setOption('message', "$notes")
                 ->execute();
             $bChanged = true;
         }
index 8e18199d4dd5483b13532c83cfd2a50857769fdc..ca93b4a07319382f7f6adc3573eca01d85340cc6 100644 (file)
@@ -43,4 +43,4 @@ class Tool_Manager
     }
 }
 
-?>
\ No newline at end of file
+?>
index 22ea2730d305fbbfa15076989aa82a02818b7743..94dfe5e540de419f4e234f3b3faed4cce2b0be0e 100644 (file)
@@ -6,4 +6,4 @@ class Tool_Result
     public $annotations;
 }
 
-?>
\ No newline at end of file
+?>
index a788db64bd0ec6099168686ce9267cb3ecfa2444..1fa8bcb635b1ea185a562a386d642fc58de3cd18 100644 (file)
@@ -31,4 +31,4 @@ class Tool_Result_Line
     }
 }
 
-?>
\ No newline at end of file
+?>
index 843b2df6d04e2d008cc1d0794d6ebff2ffab186e..e4aab634583887e98b4e4985673bd4b092a00f19 100644 (file)
@@ -62,4 +62,4 @@ class Tools
 
 }
 
-?>
\ No newline at end of file
+?>
index c379b234b9b81c63b7b176561f4068cdca2d2dcf..1f03facd28af0b2222a9e94c7a6c46dd8fafe203 100644 (file)
@@ -20,3 +20,6 @@ RewriteRule ^list/([0-9]+)$ /list.php?page=$1
 
 RewriteRule ^search$ /search.php
 RewriteRule ^search/([0-9]+)$ /search.php?page=$1
+
+RewriteRule ^login$ /login.php
+RewriteRule ^user$ /user.php
diff --git a/www/css/openid.css b/www/css/openid.css
new file mode 100644 (file)
index 0000000..296618b
--- /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;
+}
+#openid_url {
+  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..43ec9d5be24a9ad7162dbfac9854fa05e81a7200 100644 (file)
@@ -3,6 +3,7 @@ namespace phorkie;
 /**
  * Delete paste or ask for deletion
  */
+$reqWritePermissions = true;
 require_once 'www-header.php';
 
 $repo = new Repository();
index c8df8a9963b92ef2e82da0a6d1626f659bb86010..ffc978629c3ddc293d3227ceec5132f92b18af12 100644 (file)
@@ -3,6 +3,7 @@ namespace phorkie;
 /**
  * Display paste contents
  */
+$reqWritePermissions = false;
 require_once 'www-header.php';
 
 $repo = new Repository();
index db00df4d3dec8d891444450b80c1f7e2b15d41f4..63a66e630d57a21b71ade37b10eab5ec0ef9df82 100644 (file)
@@ -4,6 +4,7 @@ namespace phorkie;
  * Display DOAP of the paste.
  * Contains a machine-readable project description with Git URL.
  */
+$reqWritePermissions = false;
 require_once 'www-header.php';
 
 $repo = new Repository();
index 562c97cbd5391f8441e0bf28df2343c8d3068fe5..4de3d47cb93b4310d6529b2ba80083a9f2d8aed2 100644 (file)
@@ -3,13 +3,14 @@ namespace phorkie;
 /**
  * Edit paste contents
  */
+$reqWritePermissions = true;
 require_once 'www-header.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..f55c4ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace phorkie;
+/**
+ * Show an access denied error
+ */
+
+header('HTTP/1.0 403 Forbidden');
+render(
+    'forbidden',
+    array(
+        'identity' => isset($_SESSION['identity']) ? $_SESSION['identity'] : null
+    )
+);
+exit();
+?>
index 799763273667ec8388b1f94e70ab3688c9af60f9..6c96a6acb3b85d2918bcf12c10a353c1ddc53b41 100644 (file)
@@ -3,6 +3,7 @@
  * Fork a repository
  */
 namespace phorkie;
+$reqWritePermissions = true;
 require_once 'www-header.php';
 
 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
@@ -30,4 +31,4 @@ foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
 
 //FIXME: where to put fork source link?
 redirect($new->getLink('display'));
-?>
\ No newline at end of file
+?>
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..0ee9211679cbe1aa1e79c936af4117b372015271 100644 (file)
@@ -1,5 +1,13 @@
 <?php
+/**
+ * Jump to the index as per the configuration
+ */
 namespace phorkie;
+$reqWritePermissions = false;
 require_once 'www-header.php';
-require_once $GLOBALS['phorkie']['cfg']['index'].".php";
+
+header(
+    'Location: '
+    . Tools::fullUrl('/' . $GLOBALS['phorkie']['cfg']['index'])
+);
 ?>
similarity index 99%
rename from www/phorkie.js
rename to www/js/phorkie.js
index 1171b1acc8b1cbc23c101abba7e2ff3093a87515..7078e8fe9173bc8a17b9ac9facb0a8985189b5d0 100644 (file)
@@ -50,4 +50,4 @@ function toggleAdditional(elem, time)
     jt.children('i').toggleClass('icon-chevron-down')
         .toggleClass('icon-chevron-up');
     jt.parents('.row-fluid').children('.additional').toggle(time);
-}
\ No newline at end of file
+}
index 911f26d1a728b54dcb7a9d22d452cae65d539dc6..750e811dfbbe6301d21471c872f18abd1edf8255 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 /**
- * Fork a repository
+ * List a repository
  */
 namespace phorkie;
+$reqWritePermissions = false;
 require_once 'www-header.php';
 $rs = new Repositories();
 
diff --git a/www/login.php b/www/login.php
new file mode 100644 (file)
index 0000000..77e3953
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+namespace phorkie;
+$noSecurityCheck = true;
+require_once 'www-header.php';
+
+if (isset($_REQUEST['logout'])) {
+    unset($_SESSION);
+    session_destroy();
+    header('Location: ' . Tools::fullUrl('/'));
+    exit();
+}
+
+if (!count($_GET) && !count($_POST)) {
+    render('login');
+    exit();
+}
+
+// Hackaround Non-Javascript Login Page
+if (!count($_POST) && isset($_GET['openid_url'])) {
+    $_POST = $_GET;
+}
+
+if (isset($_POST['openid_url'])) {
+    $openid_url = $_POST['openid_url'];
+} else if (isset($_SESSION['openid_url'])) {
+    $openid_url = $_SESSION['openid_url'];
+} else {
+    $openid_url = null;
+}
+
+$realm    = Tools::fullUrl('/');
+$returnTo = Tools::fullUrl('/login');
+
+try {
+    $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url);
+} catch (OpenID_Exception $e) {
+    throw new Exception($e->getMessage());
+}
+
+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['openid_url'])) {
+
+    $_SESSION['openid_url'] = $openid_url;
+    try {
+        $authRequest = $o->prepare();
+    } catch (OpenID_Exception $e) {
+        throw new Exception($e->getMessage());
+    }
+
+    // SREG
+    $sreg = new \OpenID_Extension_SREG11(\OpenID_Extension::REQUEST);
+    $sreg->set('required', 'email,fullname');
+    $authRequest->addExtension($sreg);
+
+    // AX, http://stackoverflow.com/a/7657061/282601
+    $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('type.fullname', 'http://axschema.org/namePerson');
+    $ax->set('mode', 'fetch_request');
+    $ax->set('required', 'email,firstname,lastname,fullname');
+    $authRequest->addExtension($ax);
+
+    $url = $authRequest->getAuthorizeURL();
+
+    header("Location: $url");
+    exit;
+    
+}
+
+if (isset($_SESSION['openid_url'])) {
+    $usid = $_SESSION['openid_url'];
+    unset($_SESSION['openid_url']);
+} 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>";
+}
+
+
+$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($openid['openid.ax.type.email'])
+    && $openid['openid.ax.type.email'] == 'http://axschema.org/contact/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.fullname']) && !isset($name)
+    ? $openid['openid.sreg.fullname']
+    : $name;
+$name = isset($openid['openid.ax.value.fullname'])
+    && isset($openid['openid.ax.type.fullname'])
+    && $openid['openid.ax.type.fullname'] == 'http://axschema.org/namePerson'
+    && !isset($name)
+    ? $openid['openid.ax.value.fullname']
+    : $name;
+
+$_SESSION['name'] = isset($name) ? $name : $_SERVER['REMOTE_ADDR'];
+$_SESSION['identity'] = $openid['openid.identity'];
+
+if (isset($_SESSION['REQUEST_URI'])) {
+    $redirect = Tools::fullUrl($_SESSION['REQUEST_URI']);
+} else {
+    $redirect = Tools::fullUrl('/');
+}
+header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
+exit;
+?>
index ef9daecf50b7c96d89f8bad3921da56070c7ea74..7a708917ef45912a6be54cb6e82e069bdbc90858 100644 (file)
@@ -10,10 +10,11 @@ namespace phorkie;
  *
  * Creates and redirects to display page
  */
+$reqWritePermissions = true;
 require_once 'www-header.php';
 
 $repopo = new Repository_Post();
-if ($repopo->process($_POST)) {
+if ($repopo->process($_POST, $_SESSION)) {
     redirect($repopo->repo->getLink('display'));
 }
 
index 8bda11e8fbaeb9b363bb726bf27239ad9de32eef..605462da41d267184cb522219917ca21a51caccb 100644 (file)
@@ -1,9 +1,11 @@
 <?php
+namespace phorkie;
 /**
  * Displays a file
  */
-namespace phorkie;
+$reqWritePermissions = false;
 require_once 'www-header.php';
+
 $repo = new Repository();
 $repo->loadFromRequest();
 
index 53ac4581b45b379a4d84e5c57b56b9a5d1689a31..4d4f97cb01bd3c3beb8e5a436c1f5c0f2d1c5c55 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 namespace phorkie;
 /**
- * Display paste contents
+ * Display historic paste contents
  */
+$reqWritePermissions = false;
 require_once 'www-header.php';
 
 $repo = new Repository();
index cb72c6aa8c64cfacd1980b7354127a61d1631ce9..9c7ff6e5c77a2cb9ac549b15eb736c66f9842403 100644 (file)
@@ -3,6 +3,7 @@ namespace phorkie;
 /**
  * Search for a search term
  */
+$reqWritePermissions = false;
 require_once 'www-header.php';
 
 if (!isset($_GET['q']) || $_GET['q'] == '') {
index d42954cb35526355c4aea8891096fd7aaffbd6bb..647d6a7517b2c9a56f74a223489616b012372669 100644 (file)
@@ -30,4 +30,4 @@ render(
     )
 );
 
-?>
\ No newline at end of file
+?>
diff --git a/www/user.php b/www/user.php
new file mode 100644 (file)
index 0000000..8b86a50
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Edit user information
+ */
+namespace phorkie;
+$reqWritePermissions = true;
+require_once 'www-header.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..9aa873240aa2a3dff64a909f1c57b2c50e391f75 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace phorkie;
+session_start();
+
 set_include_path(
     __DIR__ . '/../src/'
     . PATH_SEPARATOR . get_include_path()
@@ -46,6 +48,16 @@ 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']);
@@ -58,11 +70,20 @@ $twig = new \Twig_Environment(
 );
 //$twig->addExtension(new \Twig_Extension_Debug());
 
-function render($tplname, $vars)
+if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {
+    require __DIR__ . '/www-security.php';
+}
+
+function render($tplname, $vars = array())
 {
     $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 +94,4 @@ function redirect($target)
     header('Location: ' . $target);
     exit();
 }
-?>
\ No newline at end of file
+?>
diff --git a/www/www-security.php b/www/www-security.php
new file mode 100644 (file)
index 0000000..5051b0f
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace phorkie;
+/**
+ * security levels + login requirement:
+ */
+
+if (!isset($GLOBALS['phorkie']['auth']['securityLevel'])) {
+    //not set? highest level of security
+    $GLOBALS['phorkie']['auth']['securityLevel'] = 2;
+}
+
+if ($GLOBALS['phorkie']['auth']['securityLevel'] == 0) {
+    //everyone may do everything
+    return;
+}
+
+$logged_in = false;
+if (!isset($_SESSION['identity'])) {
+    //not logged in 
+} else if ($GLOBALS['phorkie']['auth']['listedUsersOnly']) {
+    if (in_array($_SESSION['identity'], $GLOBALS['phorkie']['auth']['users'])) {
+        $logged_in = true;
+    }
+} else {
+    //session identity exists, no special checks required
+    $logged_in = true;
+}
+
+if ($logged_in) {
+    //you may do everything if you're logged in
+    return;
+}
+
+if (!isset($reqWritePermissions)) {
+    $reqWritePermissions = true;
+}
+if ($GLOBALS['phorkie']['auth']['securityLevel'] == 1
+    && !$reqWritePermissions
+) {
+    return;
+}
+
+$_SESSION['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
+require 'forbidden.php';
+?>