diff options
| author | Colin Guthrie <colin.guthrie@tribalogic.net> | 2013-04-19 13:28:19 +0100 |
|---|---|---|
| committer | Colin Guthrie <colin.guthrie@tribalogic.net> | 2013-04-21 19:57:43 +0100 |
| commit | 20ca4e9e509a111f8de0069feeac54e3b31098ee (patch) | |
| tree | cd1a27410c2fc470d270cf79cab021781d1931aa | |
| parent | ba158e3ed03dec10e6654b0b0dd3710504bdf04d (diff) | |
| download | phorkie-20ca4e9e509a111f8de0069feeac54e3b31098ee.tar.gz phorkie-20ca4e9e509a111f8de0069feeac54e3b31098ee.zip | |
Allow usage in a subdir of a host.
31 files changed, 95 insertions, 81 deletions
@@ -61,6 +61,12 @@ Installation Look at ``config.default.php`` for values that you may adjust. 5. Set your web server's document root to ``/path/to/phorkie/www/`` + Alternatively, you can add a symlink to the ``www`` folder into your + web server's existing document root tree (being careful to keep + main phorkie folder outside the document root for security purposes) + and ensure you set the ``baseurl`` config option appropriately. You + must also set the ``RewriteBase`` in the ``.htaccess`` file or adjust + the nginx configuration accordingly. 6. Open phorkie in your web browser diff --git a/data/config.default.php b/data/config.default.php index a589924..56ddc43 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -4,6 +4,7 @@ $GLOBALS['phorkie']['cfg'] = array( 'gitdir' => __DIR__ . '/../repos/git/', 'workdir' => __DIR__ . '/../repos/work/', 'tpl' => __DIR__ . '/templates/', + 'baseurl' => '/', 'css' => '', 'title' => 'phorkie', 'topbar' => '', diff --git a/data/config.php.dist b/data/config.php.dist index ced993f..77d2005 100644 --- a/data/config.php.dist +++ b/data/config.php.dist @@ -1,4 +1,5 @@ <?php +//$GLOBALS['phorkie']['cfg']['baseurl'] = '/'; //$GLOBALS['phorkie']['cfg']['gitdir'] = '/var/cache/git/paste/git/'; //$GLOBALS['phorkie']['cfg']['workdir'] = '/var/cache/git/paste/work/'; //$GLOBALS['phorkie']['cfg']['git']['public'] = 'git://bogo/git/paste/'; diff --git a/data/templates/base.htm b/data/templates/base.htm index 8738bb0..8074938 100644 --- a/data/templates/base.htm +++ b/data/templates/base.htm @@ -1,18 +1,19 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html> - <head> + <head> + <base href="{{baseurl}}" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <link rel="stylesheet" href="/css/bootstrap.min.css"/> - <link rel="stylesheet" href="/css/font-awesome.css"/> - <link rel="stylesheet" href="/css/phorkie.css"/> + <link rel="stylesheet" href="css/bootstrap.min.css"/> + <link rel="stylesheet" href="css/font-awesome.css"/> + <link rel="stylesheet" href="css/phorkie.css"/> {% if css %} <link rel="stylesheet" href="{{css}}"/> {% endif %} <title>{% block title %}{% endblock %} - {{title}}</title> - <script src="/js/jquery.js"></script> - <script src="/js/bootstrap.min.js"></script> - <script src="/js/phorkie.js"></script> + <script src="js/jquery.js"></script> + <script src="js/bootstrap.min.js"></script> + <script src="js/phorkie.js"></script> {% block meta %}{% endblock %} </head> <body> @@ -22,17 +23,17 @@ <div class="container"> <ul class="nav"> <li> - <a class="brand" href="/">{{title}}</a> + <a class="brand" href="{{baseurl}}">{{title}}</a> </li> <li> - <a href="/new">New paste</a> + <a href="new">New paste</a> </li> <li> - <a href="/list">List all</a> + <a href="list">List all</a> </li> {% if db.adapter %} <li class="nav-collapse"> - <form class="span4 pull-right navbar-form" action="/search" method="get"> + <form class="span4 pull-right navbar-form" action="search" method="get"> <input type="text" class="search-query" name="q" placeholder="Search" value="{{query}}"/> </form> </li> @@ -41,7 +42,7 @@ <ul class="nav pull-right"> {% if identity %} <li> - <a href="/user">{{name}}</a> + <a href="user">{{name}}</a> </li> {% endif %} {% if db.adapter %} @@ -55,11 +56,11 @@ {% endif %} {% if identity %} <li> - <a href="/login?logout">Logout</a> + <a href="login?logout">Logout</a> </li> {% else %} <li> - <a href="/login">Login</a> + <a href="login">Login</a> </li> {% endif %} </ul> diff --git a/data/templates/display-sidebar-history.htm b/data/templates/display-sidebar-history.htm index eb844e4..6dda7e0 100644 --- a/data/templates/display-sidebar-history.htm +++ b/data/templates/display-sidebar-history.htm @@ -5,7 +5,7 @@ <li class="row-fluid {% if commit.hash == repo.hash or (repo.hash == '' and loop.first) %}active{%endif%}"> {% spaceless %} {% for dot in commit.getDots %} - <img src="/phorkie/dot-{{dot}}.png" alt="" style="padding-left:1px" width="4" height="4"/> + <img src="phorkie/dot-{{dot}}.png" alt="" style="padding-left:1px" width="4" height="4"/> {% endfor %} {% endspaceless %} <a class="hash" href="{{repo.getLink('revision', commit.hash)}}">{{commit.hash|slice(0, 6)}}</a> diff --git a/data/templates/exception.htm b/data/templates/exception.htm index 91120f4..f4f5d32 100644 --- a/data/templates/exception.htm +++ b/data/templates/exception.htm @@ -1,7 +1,8 @@ <!DOCTYPE html> <html> - <head> - <link rel="stylesheet" href="/css/phorkie.css" /> + <head> + <base href="{{baseurl}}" /> + <link rel="stylesheet" href="css/phorkie.css" /> <title>Error - phorkie</title> <meta name="robots" content="noindex"/> </head> diff --git a/data/templates/forbidden.htm b/data/templates/forbidden.htm index 76e728c..b32962c 100644 --- a/data/templates/forbidden.htm +++ b/data/templates/forbidden.htm @@ -21,7 +21,7 @@ </p> {% else %} <p> - We're sorry; but you have to <a href="/login">log in</a> to access this page. + 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/fork-remote-multiple.htm b/data/templates/fork-remote-multiple.htm index 8709f11..f00ef2d 100644 --- a/data/templates/fork-remote-multiple.htm +++ b/data/templates/fork-remote-multiple.htm @@ -1,4 +1,4 @@ -<form method="post" action="/fork-remote" enctype="multipart/form-data" class="well form-inline form-horizontal"> +<form method="post" action="fork-remote" enctype="multipart/form-data" class="well form-inline form-horizontal"> <input type="hidden" name="orig_url" value="{{remote_url}}" /> <div class="control-group"> <p> diff --git a/data/templates/fork-remote-new.htm b/data/templates/fork-remote-new.htm index 4dc3297..debafff 100644 --- a/data/templates/fork-remote-new.htm +++ b/data/templates/fork-remote-new.htm @@ -1,4 +1,4 @@ -<form method="post" action="/fork-remote" enctype="multipart/form-data" class="well form-horizontal"> +<form method="post" action="fork-remote" enctype="multipart/form-data" class="well form-horizontal"> <p> <strong>Copy a paste from a remote server:</strong> Just paste the website or git clone URL. diff --git a/data/templates/login.htm b/data/templates/login.htm index 70a1b69..c3ac9fd 100644 --- a/data/templates/login.htm +++ b/data/templates/login.htm @@ -9,15 +9,15 @@ <link rel="stylesheet" href="css/openid.css" /> -<form method="post" action="/login" id="openid_form"> +<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> + <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> diff --git a/data/templates/new.htm b/data/templates/new.htm index 88dade3..163b5a3 100644 --- a/data/templates/new.htm +++ b/data/templates/new.htm @@ -3,7 +3,7 @@ {% block content %} <div class="content-padding-fix"></div> -<form method="post" action="/new" enctype="multipart/form-data" class="form-horizontal"> +<form method="post" action="new" enctype="multipart/form-data" class="form-horizontal"> <div class="control-group"> <label class="control-label" for="description">Description</label> <div class="controls"> diff --git a/src/phorkie/File.php b/src/phorkie/File.php index db773df..63d23e6 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -106,13 +106,13 @@ class File { if ($type == 'raw') { if ($this->repo->hash === null) { - return '/' . $this->repo->id . '/raw/' . $this->getFilename(); + return $this->repo->id . '/raw/' . $this->getFilename(); } else { - return '/' . $this->repo->id . '/rev-raw/' . $this->repo->hash + return $this->repo->id . '/rev-raw/' . $this->repo->hash . '/' . $this->getFilename(); } } else if ($type == 'tool') { - return '/' . $this->repo->id + return $this->repo->id . '/tool/' . $option . '/' . $this->getFilename(); } diff --git a/src/phorkie/Html/Pager.php b/src/phorkie/Html/Pager.php index e58ccc6..3ccf209 100644 --- a/src/phorkie/Html/Pager.php +++ b/src/phorkie/Html/Pager.php @@ -30,7 +30,7 @@ class Html_Pager 'currentPage' => $currentPage, 'urlVar' => 'page', 'append' => $append, - 'path' => '/', + 'path' => '', 'fileName' => $filename, 'separator' => '###', 'spacesBeforeSeparator' => 0, diff --git a/src/phorkie/HtmlHelper.php b/src/phorkie/HtmlHelper.php index fd04d83..945c7ea 100644 --- a/src/phorkie/HtmlHelper.php +++ b/src/phorkie/HtmlHelper.php @@ -6,7 +6,7 @@ class HtmlHelper public function getIconUrl($email, $size = 32) { if ($email == 'anonymous@phorkie') { - return '/phorkie/anonymous.png'; + return 'phorkie/anonymous.png'; } $s = new \Services_Libravatar(); @@ -14,7 +14,7 @@ class HtmlHelper $email, array( 'size' => $size, - 'default' => Tools::fullUrl('/phorkie/anonymous.png') + 'default' => Tools::fullUrl('phorkie/anonymous.png') ) ); } diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 6b7435c..815ef5e 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -274,19 +274,19 @@ class Repository public function getLink($type, $option = null, $full = false) { if ($type == 'edit') { - $link = '/' . $this->id . '/edit'; + $link = $this->id . '/edit'; } else if ($type == 'display') { - $link = '/' . $this->id; + $link = $this->id; } else if ($type == 'fork') { - $link = '/' . $this->id . '/fork'; + $link = $this->id . '/fork'; } else if ($type == 'doap') { - $link = '/' . $this->id . '/doap'; + $link = $this->id . '/doap'; } else if ($type == 'delete') { - $link = '/' . $this->id . '/delete'; + $link = $this->id . '/delete'; } else if ($type == 'delete-confirm') { - $link = '/' . $this->id . '/delete/confirm'; + $link = $this->id . '/delete/confirm'; } else if ($type == 'revision') { - $link = '/' . $this->id . '/rev/' . $option; + $link = $this->id . '/rev/' . $option; } else { throw new Exception('Unknown link type'); } diff --git a/src/phorkie/Search/Result.php b/src/phorkie/Search/Result.php index 00bb1ec..62e7bb8 100644 --- a/src/phorkie/Search/Result.php +++ b/src/phorkie/Search/Result.php @@ -45,7 +45,7 @@ class Search_Result public function getLink($query) { - return '/search?q=' . urlencode($query); + return 'search?q=' . urlencode($query); } } diff --git a/src/phorkie/Tools.php b/src/phorkie/Tools.php index 1d3d226..fc815cc 100644 --- a/src/phorkie/Tools.php +++ b/src/phorkie/Tools.php @@ -38,14 +38,14 @@ class Tools * * @return string Full URL */ - public static function fullUrl($path) + public static function fullUrl($path = '') { if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) { $prot = 'https'; } else { $prot = 'http'; } - return $prot . '://' . $_SERVER['HTTP_HOST'] . $path; + return $prot . '://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phorkie']['cfg']['baseurl'] . $path; } /** diff --git a/www/.htaccess b/www/.htaccess index f3dc267..60419bb 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -2,28 +2,28 @@ RewriteEngine On RewriteBase / #RewriteCond %{REQUEST_FILENAME} -f -RewriteRule ^([0-9]+)$ /display.php?id=$1 -RewriteRule ^([0-9]+)/delete$ /delete.php?id=$1 -RewriteRule ^([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1 -RewriteRule ^([0-9]+)/doap$ /doap.php?id=$1 -RewriteRule ^([0-9]+)/edit$ /edit.php?id=$1 -RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1 -RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2 -RewriteRule ^([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2 -RewriteRule ^([0-9]+)/rev-raw/(.+)/(.+)$ /raw.php?id=$1&rev=$2&file=$3 -RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3 +RewriteRule ^([0-9]+)$ display.php?id=$1 +RewriteRule ^([0-9]+)/delete$ delete.php?id=$1 +RewriteRule ^([0-9]+)/delete/confirm$ delete.php?id=$1&confirm=1 +RewriteRule ^([0-9]+)/doap$ doap.php?id=$1 +RewriteRule ^([0-9]+)/edit$ edit.php?id=$1 +RewriteRule ^([0-9]+)/fork$ fork.php?id=$1 +RewriteRule ^([0-9]+)/raw/(.+)$ raw.php?id=$1&file=$2 +RewriteRule ^([0-9]+)/rev/(.+)$ revision.php?id=$1&rev=$2 +RewriteRule ^([0-9]+)/rev-raw/(.+)/(.+)$ raw.php?id=$1&rev=$2&file=$3 +RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ tool.php?id=$1&tool=$2&file=$3 -RewriteRule ^fork-remote$ /fork-remote.php -RewriteRule ^new$ /new.php +RewriteRule ^fork-remote$ fork-remote.php +RewriteRule ^new$ new.php -RewriteRule ^feed/new$ /feed-new.php -RewriteRule ^feed/updated$ /feed-updated.php +RewriteRule ^feed/new$ feed-new.php +RewriteRule ^feed/updated$ feed-updated.php -RewriteRule ^list$ /list.php -RewriteRule ^list/([0-9]+)$ /list.php?page=$1 +RewriteRule ^list$ list.php +RewriteRule ^list/([0-9]+)$ list.php?page=$1 -RewriteRule ^search$ /search.php -RewriteRule ^search/([0-9]+)$ /search.php?page=$1 +RewriteRule ^search$ search.php +RewriteRule ^search/([0-9]+)$ search.php?page=$1 -RewriteRule ^login$ /login.php -RewriteRule ^user$ /user.php +RewriteRule ^login$ login.php +RewriteRule ^user$ user.php diff --git a/www/css/openid.css b/www/css/openid.css index 296618b..4b2acbc 100644 --- a/www/css/openid.css +++ b/www/css/openid.css @@ -28,7 +28,7 @@ body { #openid_url { margin: 0px !important; width: 250px; - background: #FFF url(/images/openid-inputicon.gif) no-repeat scroll 0 50%; + background: #FFF url(../images/openid-inputicon.gif) no-repeat scroll 0 50%; padding-left:18px; } .openid_large_btn { @@ -46,10 +46,10 @@ body { float: left; } .google { - background: #FFF url(/images/google.gif) no-repeat center center; + background: #FFF url(../images/google.gif) no-repeat center center; } .yahoo { - background: #FFF url(/images/yahoo.gif) no-repeat center center; + background: #FFF url(../images/yahoo.gif) no-repeat center center; } a.openid_large_btn:hover { diff --git a/www/delete.php b/www/delete.php index 43ec9d5..e0e8d9f 100644 --- a/www/delete.php +++ b/www/delete.php @@ -14,7 +14,7 @@ if (isset($_GET['confirm']) && $_GET['confirm'] == 1) { throw new Exception_Input('Deleting only possible via POST'); } $repo->delete(); - redirect('/'); + redirect(Tools::fullUrl()); } render( diff --git a/www/edit.php b/www/edit.php index 4199c34..d1853d2 100644 --- a/www/edit.php +++ b/www/edit.php @@ -11,7 +11,7 @@ $repo->loadFromRequest(); $repopo = new Repository_Post($repo); if ($repopo->process($_POST, $_SESSION)) { - redirect($repo->getLink('display')); + redirect($repo->getLink('display', null, true)); } render( diff --git a/www/feed-new.php b/www/feed-new.php index a462808..9d21d5a 100644 --- a/www/feed-new.php +++ b/www/feed-new.php @@ -12,8 +12,8 @@ render( 'feed-new', array( 'pastes' => $db->getSearch()->listAll(0, 10, 'crdate', 'desc'), - 'url' => Tools::fullUrl('/'), - 'feedurl' => Tools::fullUrl('/feed/new'), + 'url' => Tools::fullUrl(), + 'feedurl' => Tools::fullUrl('feed/new'), ) ); ?> diff --git a/www/feed-updated.php b/www/feed-updated.php index 679a5d7..8dfe7b4 100644 --- a/www/feed-updated.php +++ b/www/feed-updated.php @@ -12,8 +12,8 @@ render( 'feed-updated', array( 'pastes' => $db->getSearch()->listAll(0, 10, 'modate', 'desc'), - 'url' => Tools::fullUrl('/'), - 'feedurl' => Tools::fullUrl('/feed/updated'), + 'url' => Tools::fullUrl(), + 'feedurl' => Tools::fullUrl('feed/updated'), ) ); ?> diff --git a/www/fork-remote.php b/www/fork-remote.php index 5d4a4ee..f34a232 100644 --- a/www/fork-remote.php +++ b/www/fork-remote.php @@ -19,7 +19,7 @@ if (isset($_POST['remote_url'])) { } $forker = new Forker(); $new = $forker->forkRemote($gitUrl, $fr->getUrl()); - redirect($new->getLink('display')); + redirect($new->getLink('display', null, true)); } else { //multiple urls found $urls = $fr->getGitUrls(); diff --git a/www/fork.php b/www/fork.php index d8a24a2..352f8bc 100644 --- a/www/fork.php +++ b/www/fork.php @@ -17,5 +17,5 @@ $forker = new Forker(); $new = $forker->forkLocal($repo); //FIXME: where to put fork source link? -redirect($new->getLink('display')); +redirect($new->getLink('display', null, true)); ?> diff --git a/www/index.php b/www/index.php index 0ee9211..5b5e4f6 100644 --- a/www/index.php +++ b/www/index.php @@ -8,6 +8,6 @@ require_once 'www-header.php'; header( 'Location: ' - . Tools::fullUrl('/' . $GLOBALS['phorkie']['cfg']['index']) + . Tools::fullUrl($GLOBALS['phorkie']['cfg']['index']) ); ?> diff --git a/www/list.php b/www/list.php index d4934bd..1ff8a87 100644 --- a/www/list.php +++ b/www/list.php @@ -19,7 +19,7 @@ $perPage = 10; list($repos, $repoCount) = $rs->getList($page, $perPage); $pager = new Html_Pager( - $repoCount, $perPage, $page + 1, '/list/%d' + $repoCount, $perPage, $page + 1, 'list/%d' ); $db = new Database(); diff --git a/www/login.php b/www/login.php index fb396b9..e141b65 100644 --- a/www/login.php +++ b/www/login.php @@ -6,7 +6,7 @@ require_once 'www-header.php'; if (isset($_REQUEST['logout'])) { unset($_SESSION); session_destroy(); - header('Location: ' . Tools::fullUrl('/')); + header('Location: ' . Tools::fullUrl()); exit(); } @@ -34,8 +34,8 @@ if (isset($_POST['openid_url'])) { $openid_url = null; } -$realm = Tools::fullUrl('/'); -$returnTo = Tools::fullUrl('/login'); +$realm = Tools::fullUrl(); +$returnTo = Tools::fullUrl('login'); try { $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url); @@ -158,11 +158,11 @@ $_SESSION['identity'] = $openid['openid.identity']; setcookie('lastopenid', $_SESSION['identity'], time() + 84600 * 60, '/login'); +$url = ''; if (isset($_SESSION['REQUEST_URI'])) { - $redirect = Tools::fullUrl($_SESSION['REQUEST_URI']); -} else { - $redirect = Tools::fullUrl('/'); + $url = substr($_SESSION['REQUEST_URI'], 1); } +$redirect = Tools::fullUrl($url); header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); exit; ?> diff --git a/www/new.php b/www/new.php index 965f534..6ec746b 100644 --- a/www/new.php +++ b/www/new.php @@ -15,7 +15,7 @@ require_once 'www-header.php'; $repopo = new Repository_Post(); if ($repopo->process($_POST, $_SESSION)) { - redirect($repopo->repo->getLink('display')); + redirect($repopo->repo->getLink('display', null, true)); } $phork = array( diff --git a/www/search.php b/www/search.php index 9c7ff6e..2f2de2e 100644 --- a/www/search.php +++ b/www/search.php @@ -7,7 +7,7 @@ $reqWritePermissions = false; require_once 'www-header.php'; if (!isset($_GET['q']) || $_GET['q'] == '') { - header('Location: ' . Tools::fullUrl('/list')); + header('Location: ' . Tools::fullUrl('list')); exit(); } $query = $_GET['q']; diff --git a/www/www-header.php b/www/www-header.php index 41b5e47..cda7047 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -84,6 +84,10 @@ if (!isset($noSecurityCheck) || $noSecurityCheck !== true) { function render($tplname, $vars = array()) { + $vars['baseurl'] = '/'; + if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) { + $vars['baseurl'] = $GLOBALS['phorkie']['cfg']['baseurl']; + } $vars['css'] = $GLOBALS['phorkie']['cfg']['css']; $vars['title'] = $GLOBALS['phorkie']['cfg']['title']; $vars['topbar'] = $GLOBALS['phorkie']['cfg']['topbar']; |
