From b0687c328fcaa4d891b31c2146694654cd4707c9 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Sun, 16 Sep 2012 00:43:33 -0400
Subject: Organize files into directories
---
data/templates/base.htm | 6 +++---
data/templates/exception.htm | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
(limited to 'data')
diff --git a/data/templates/base.htm b/data/templates/base.htm
index b9c9608..2b8544b 100644
--- a/data/templates/base.htm
+++ b/data/templates/base.htm
@@ -4,10 +4,10 @@
-
+
{% block title %}{% endblock %} - {{title}}
-
-
+
+
{% block meta %}{% endblock %}
diff --git a/data/templates/exception.htm b/data/templates/exception.htm
index dc07fc5..7a96da0 100644
--- a/data/templates/exception.htm
+++ b/data/templates/exception.htm
@@ -1,7 +1,7 @@
-
+
Error - phorkie
--
cgit v1.2.3
From a73791f16d10ea0e2c477f29d9049d75516aa774 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Sun, 16 Sep 2012 01:17:46 -0400
Subject: Added OpenID Authentication
---
data/config.default.php | 5 +
data/config.php.dist | 4 +
data/templates/base.htm | 8 ++
data/templates/forbidden.htm | 21 ++++
data/templates/login.htm | 44 +++++++
src/openid/config.php | 55 +++++++++
src/openid/wrapper.php | 27 +++++
www/.htaccess | 4 +
www/auth.php | 258 ++++++++++++++++++++++++++++++++++++++++
www/css/debug.css | 85 +++++++++++++
www/css/openid.css | 64 ++++++++++
www/delete.php | 3 +
www/display.php | 3 +
www/edit.php | 3 +
www/forbidden.php | 11 ++
www/fork.php | 3 +
www/images/access_denied.png | Bin 0 -> 15610 bytes
www/images/google.gif | Bin 0 -> 1596 bytes
www/images/openid-inputicon.gif | Bin 0 -> 237 bytes
www/images/yahoo.gif | Bin 0 -> 1682 bytes
www/index.php | 3 +
www/list.php | 5 +-
www/login.php | 11 ++
www/new.php | 3 +
www/raw.php | 3 +
www/revision.php | 3 +
www/secure.php | 11 ++
www/www-header.php | 4 +
28 files changed, 640 insertions(+), 1 deletion(-)
create mode 100644 data/templates/forbidden.htm
create mode 100644 data/templates/login.htm
create mode 100644 src/openid/config.php
create mode 100644 src/openid/wrapper.php
create mode 100644 www/auth.php
create mode 100644 www/css/debug.css
create mode 100644 www/css/openid.css
create mode 100644 www/forbidden.php
create mode 100644 www/images/access_denied.png
create mode 100644 www/images/google.gif
create mode 100644 www/images/openid-inputicon.gif
create mode 100644 www/images/yahoo.gif
create mode 100644 www/login.php
create mode 100644 www/secure.php
(limited to 'data')
diff --git a/data/config.default.php b/data/config.default.php
index 88c9ae5..7ecbda3 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -12,6 +12,11 @@ $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
+ 'anonymousEmail' => 'anonymous@phorkie' // Email for non-authenticated commits
+);
$GLOBALS['phorkie']['tools'] = array(
'\\phorkie\\Tool_Xmllint' => true,
'\\phorkie\\Tool_PHPlint' => true,
diff --git a/data/config.php.dist b/data/config.php.dist
index 1e814bd..e90f704 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -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'
+//);
?>
diff --git a/data/templates/base.htm b/data/templates/base.htm
index 2b8544b..8192b6b 100644
--- a/data/templates/base.htm
+++ b/data/templates/base.htm
@@ -25,6 +25,14 @@
List all
+ {% if identity %}
+
+ {{name}} ({{email}})
+
+
+ Logout
+
+ {% endif %}
{% if db.adapter %}
{% if identity %}
- {{name}} ({{email}})
+ {{name}} ({{email}})
Logout
@@ -65,4 +65,4 @@
-
\ No newline at end of file
+
diff --git a/data/templates/user.htm b/data/templates/user.htm
new file mode 100644
index 0000000..c8ef387
--- /dev/null
+++ b/data/templates/user.htm
@@ -0,0 +1,15 @@
+{% extends "base.htm" %}
+{% block title %}User Preferences{% endblock %}
+
+{% block content %}
+
+
+{% endblock %}
diff --git a/www/.htaccess b/www/.htaccess
index fd2963b..c1d339d 100644
--- a/www/.htaccess
+++ b/www/.htaccess
@@ -23,3 +23,4 @@ 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/user.php b/www/user.php
new file mode 100644
index 0000000..1cc8aeb
--- /dev/null
+++ b/www/user.php
@@ -0,0 +1,27 @@
+ $_SESSION['identity'],
+ 'name' => $_SESSION['name'],
+ 'email' => $_SESSION['email']
+ )
+);
+?>
--
cgit v1.2.3
From 5935a357efd7be14481b21560347f70116891e16 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Sun, 16 Sep 2012 13:52:17 -0400
Subject: ADD: Commit as logged in user
---
data/config.default.php | 1 +
src/phorkie/Repository/Post.php | 14 ++++++++++----
www/edit.php | 2 +-
www/new.php | 2 +-
www/www-header.php | 6 ++++++
5 files changed, 19 insertions(+), 6 deletions(-)
(limited to 'data')
diff --git a/data/config.default.php b/data/config.default.php
index 7ecbda3..da16241 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -15,6 +15,7 @@ $GLOBALS['phorkie']['cfg'] = array(
$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(
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php
index de987e0..ed44cf1 100644
--- a/src/phorkie/Repository/Post.php
+++ b/src/phorkie/Repository/Post.php
@@ -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 ')
+ ->setOption('message', $commitmsg)
+ ->setOption('author', $sessionData['name'].' <'.$sessionData['email'].'>')
->execute();
$bChanged = true;
}
diff --git a/www/edit.php b/www/edit.php
index 226b774..db4428b 100644
--- a/www/edit.php
+++ b/www/edit.php
@@ -12,7 +12,7 @@ $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/new.php b/www/new.php
index fc6d5f3..8d1a231 100644
--- a/www/new.php
+++ b/www/new.php
@@ -16,7 +16,7 @@ if ($GLOBALS['phorkie']['auth']['secure'] > 0) {
}
$repopo = new Repository_Post();
-if ($repopo->process($_POST)) {
+if ($repopo->process($_POST, $_SESSION)) {
redirect($repopo->repo->getLink('display'));
}
diff --git a/www/www-header.php b/www/www-header.php
index 74863e1..5785a3e 100644
--- a/www/www-header.php
+++ b/www/www-header.php
@@ -47,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']);
--
cgit v1.2.3
From 0845bf175dc416cdf107209fc34f7b37bf42b6e6 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Sun, 16 Sep 2012 15:17:28 -0400
Subject: data/templates/revision-head.htm - ADD: display commit message
---
data/templates/revision-head.htm | 1 +
src/phorkie/Repository.php | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
(limited to 'data')
diff --git a/data/templates/revision-head.htm b/data/templates/revision-head.htm
index 132a68f..a5f7e88 100644
--- a/data/templates/revision-head.htm
+++ b/data/templates/revision-head.htm
@@ -10,6 +10,7 @@
revision {{repo.hash}}
+ message {{repo.message}}
diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php
index 448982b..6ed3807 100644
--- a/src/phorkie/Repository.php
+++ b/src/phorkie/Repository.php
@@ -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)) {
--
cgit v1.2.3
From 76aa2ab76d8f2305db7a2bb7cdbe461cca0146a3 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Mon, 17 Sep 2012 09:53:19 -0400
Subject: ADD: Add identity to /forbidden page for easy administration
---
data/templates/forbidden.htm | 6 +++++-
www/auth.php | 9 ---------
www/secure.php | 8 ++++++++
3 files changed, 13 insertions(+), 10 deletions(-)
(limited to 'data')
diff --git a/data/templates/forbidden.htm b/data/templates/forbidden.htm
index ad40a9f..e6965dd 100644
--- a/data/templates/forbidden.htm
+++ b/data/templates/forbidden.htm
@@ -5,7 +5,11 @@
{% endblock %}
diff --git a/www/auth.php b/www/auth.php
index bb4fcb2..b8d08ff 100644
--- a/www/auth.php
+++ b/www/auth.php
@@ -201,15 +201,6 @@ if (isset($_POST['start'])) {
}
$openid = $message->getArrayFormat();
- if ($GLOBALS['phorkie']['auth']['secure'] > 0 &&
- $GLOBALS['phorkie']['auth']['userlist']) {
- if (!in_array($openid['openid.identity'], $GLOBALS['phorkie']['users'])) {
- $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/forbidden";
- header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
- exit;
- }
- }
- // include_once 'openid/wrapper.php';
$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;
diff --git a/www/secure.php b/www/secure.php
index 07cdfb6..4b81d59 100644
--- a/www/secure.php
+++ b/www/secure.php
@@ -9,4 +9,12 @@ 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;
+ }
+}
?>
--
cgit v1.2.3
From 13989a4e7cb4453225762dab6b5e5a7565b43df8 Mon Sep 17 00:00:00 2001
From: "Justin J. Novack"
Date: Mon, 17 Sep 2012 15:30:15 -0400
Subject: FIX: login - sreg/ax default, identifier renamed to openid_url
---
data/templates/login.htm | 6 +++---
www/auth.php | 46 +++++++++++++++++++++-------------------------
www/css/openid.css | 2 +-
www/www-header.php | 5 ++++-
4 files changed, 29 insertions(+), 30 deletions(-)
(limited to 'data')
diff --git a/data/templates/login.htm b/data/templates/login.htm
index 154994a..7e724b0 100644
--- a/data/templates/login.htm
+++ b/data/templates/login.htm
@@ -15,12 +15,12 @@
Please choose your account provider
diff --git a/www/auth.php b/www/auth.php
index 1cafd59..29d7b37 100644
--- a/www/auth.php
+++ b/www/auth.php
@@ -41,16 +41,16 @@ if (!count($_POST) && isset($_GET['start'])) {
$_POST = $_GET;
}
-if (isset($_POST['identifier'])) {
- $identifier = $_POST['identifier'];
-} else if (isset($_SESSION['identifier'])) {
- $identifier = $_SESSION['identifier'];
+if (isset($_POST['openid_url'])) {
+ $openid_url = $_POST['openid_url'];
+} else if (isset($_SESSION['openid_url'])) {
+ $openid_url = $_SESSION['openid_url'];
} else {
- $identifier = null;
+ $openid_url = null;
}
try {
- $o = new OpenID_RelyingParty($returnTo, $realm, $identifier);
+ $o = new OpenID_RelyingParty($returnTo, $realm, $openid_url);
} catch (OpenID_Exception $e) {
$contents = "\n";
$contents .= "
" . $e->getMessage() . "
\n";
@@ -69,7 +69,7 @@ OpenID::attach($log);
if (isset($_POST['start'])) {
- $_SESSION['identifier'] = $identifier;
+ $_SESSION['openid_url'] = $openid_url;
try {
$authRequest = $o->prepare();
} catch (OpenID_Exception $e) {
@@ -86,23 +86,19 @@ if (isset($_POST['start'])) {
}
// 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);
- }
+ $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);
- }
+ $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'])) {
@@ -136,9 +132,9 @@ if (isset($_POST['start'])) {
}
} else {
- if (isset($_SESSION['identifier'])) {
- $usid = $_SESSION['identifier'];
- unset($_SESSION['identifier']);
+ if (isset($_SESSION['openid_url'])) {
+ $usid = $_SESSION['openid_url'];
+ unset($_SESSION['openid_url']);
} else {
$usid = null;
}
diff --git a/www/css/openid.css b/www/css/openid.css
index 38988a7..296618b 100644
--- a/www/css/openid.css
+++ b/www/css/openid.css
@@ -25,7 +25,7 @@ body {
background-color: #FFFCC9;
float: left;
}
-#identifier {
+#openid_url {
margin: 0px !important;
width: 250px;
background: #FFF url(/images/openid-inputicon.gif) no-repeat scroll 0 50%;
diff --git a/www/www-header.php b/www/www-header.php
index 64dca11..96cd481 100644
--- a/www/www-header.php
+++ b/www/www-header.php
@@ -1,6 +1,9 @@
Date: Mon, 17 Sep 2012 15:50:56 -0400
Subject: FIX: Combine auth.php to login.php
---
README.rst | 3 -
data/templates/login.htm | 6 +-
src/openid/config.php | 2 +-
www/.htaccess | 1 -
www/auth.php | 216 ----------------------------------------------
www/login.php | 217 +++++++++++++++++++++++++++++++++++++++++++++--
6 files changed, 216 insertions(+), 229 deletions(-)
delete mode 100644 www/auth.php
(limited to 'data')
diff --git a/README.rst b/README.rst
index 0b40b39..b92804a 100644
--- a/README.rst
+++ b/README.rst
@@ -192,8 +192,6 @@ URLs
Shows form for new paste
``/login``
Login page for protecting site
-``/auth``
- Authentication callback url
``/user``
Edit logged-in user information
@@ -236,6 +234,5 @@ If you use nginx, place the following lines into your ``server`` block:
rewrite ^/search/([0-9]+)$ /search.php?page=$1;
rewrite ^/login$ /login.php;
- rewrite ^/auth$ /auth.php;
rewrite ^/user$ /user.php;
}
diff --git a/data/templates/login.htm b/data/templates/login.htm
index 7e724b0..418432e 100644
--- a/data/templates/login.htm
+++ b/data/templates/login.htm
@@ -5,7 +5,7 @@
-