From 63a168ff8f65c0eea3459aee32efc5e9be9cd5de Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 21 Apr 2017 22:33:00 +0200 Subject: [PATCH] Make it possible to run indieauth-openid as .phar --- .gitignore | 7 +++-- README.rst | 19 ++++++++++++++ build.xml | 67 +++++++++++++++++++++++++++++++++++++++++++++++ config.php.dist | 5 ++++ src/phar-stub.php | 59 +++++++++++++++++++++++++++++++++++++++++ www/about.php | 5 +++- www/index.php | 21 ++++++++++++++- 7 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 build.xml create mode 100644 config.php.dist create mode 100644 src/phar-stub.php diff --git a/.gitignore b/.gitignore index 4a22837..a617350 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -data/tokens.sq3 -README.html +/config.php +/data/tokens.sq3 +/dist/ +/lib/ +/README.html diff --git a/README.rst b/README.rst index bd7637c..ba0a4ec 100644 --- a/README.rst +++ b/README.rst @@ -11,6 +11,7 @@ __ http://openid.net/ Setup ===== +0. Install dependencies 1. Setup your webserver: make ``www/`` the root (document) directory of the new virtual host 2. Make ``data/`` world-writable (or at least writable by the web server) @@ -20,6 +21,16 @@ Setup +Configuration +============= +A sqlite file ``data/tokens.sq3`` is created by indieauth-openid. +To configure that path, copy ``config.php.dist`` to ``config.php`` and +adjust it. + +If you're using the ``.phar`` file, append ``.config.php`` to the full +file name - e.g. ``indieauth-openid-0.1.0.phar.config.php``. + + ============ Dependencies ============ @@ -32,6 +43,14 @@ Dependencies * OpenID +Installation +============ +Install the dependencies:: + + $ pear install net_url2-2.2.1 + $ pear install openid-alpha + + ======= License ======= diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bd8d096 --- /dev/null +++ b/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config.php.dist b/config.php.dist new file mode 100644 index 0000000..f8005a7 --- /dev/null +++ b/config.php.dist @@ -0,0 +1,5 @@ + diff --git a/src/phar-stub.php b/src/phar-stub.php new file mode 100644 index 0000000..19a31a4 --- /dev/null +++ b/src/phar-stub.php @@ -0,0 +1,59 @@ + diff --git a/www/about.php b/www/about.php index 425b23a..c56b9aa 100644 --- a/www/about.php +++ b/www/about.php @@ -4,7 +4,10 @@ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) { } else { $prot = 'http'; } -$epUrl = $prot . '://' . $_SERVER['HTTP_HOST'] . '/'; +$epUrl = $prot . '://' . $_SERVER['HTTP_HOST'] . '/'; +if (Phar::running()) { + $epUrl .= ltrim($_SERVER['SCRIPT_NAME'], '/') . '/'; +} $hepUrl = htmlspecialchars($epUrl); ?> diff --git a/www/index.php b/www/index.php index 2e6b4c8..cb69845 100644 --- a/www/index.php +++ b/www/index.php @@ -29,7 +29,22 @@ require_once 'OpenID/Exception.php'; function loadDb() { - $db = new PDO('sqlite:' . __DIR__ . '/../data/tokens.sq3'); + $pharFile = \Phar::running(); + if ($pharFile == '') { + $dsn = 'sqlite:' . __DIR__ . '/../data/tokens.sq3'; + $cfgFilePath = __DIR__ . '/config.php'; + } else { + //remove phar:// from the path + $dir = dirname(substr($pharFile, 7)) . '/'; + $dsn = 'sqlite:' . $dir . '/tokens.sq3'; + $cfgFilePath = substr($pharFile, 7) . '.config.php'; + } + //allow overriding DSN + if (file_exists($cfgFilePath)) { + include $cfgFilePath; + } + + $db = new PDO($dsn); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec("CREATE TABLE IF NOT EXISTS authtokens( code TEXT, @@ -175,6 +190,8 @@ if (isset($_GET['openid_mode']) && $_GET['openid_mode'] != '') { } } catch (OpenID_Exception $e) { error('Error verifying OpenID login: ' . $e->getMessage()); + } catch (Exception $e) { + error(get_class($e) . ': ' . $e->getMessage()); } } @@ -212,6 +229,8 @@ if ($_SERVER['REQUEST_METHOD'] == 'GET') { exit(0); } catch (OpenID_Exception $e) { error('OpenID error: ' . $e->getMessage()); + } catch (Exception $e) { + error(get_class($e) . ': ' . $e->getMessage()); } } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { $redirect_uri = verifyUrlParameter($_POST, 'redirect_uri'); -- 2.30.2