Avoid setting base url in config, instead automatically construct base

url from request
This commit is contained in:
Haocen Xu 2020-07-05 21:04:51 -04:00
parent 33bcce593a
commit 071b088777
No known key found for this signature in database
GPG key ID: 3F0D955A0F6AD729
5 changed files with 16 additions and 10 deletions

View file

@ -7,10 +7,6 @@
; (optional) set a project name to be displayed on the website
; name = "PrivateBin"
; The full URL, with the domain name and directories that point to the PrivateBin files
; This URL is essential to allow Opengraph images to be displayed on social networks
; basepath = ""
; enable or disable the discussion feature, defaults to true
discussion = true

View file

@ -38,7 +38,6 @@ class Configuration
private static $_defaults = array(
'main' => array(
'name' => 'PrivateBin',
'basepath' => '',
'discussion' => true,
'opendiscussion' => false,
'password' => true,

View file

@ -369,7 +369,6 @@ class Controller
$page = new View;
$page->assign('NAME', $this->_conf->getKey('name'));
$page->assign('BASEPATH', I18n::_($this->_conf->getKey('basepath')));
$page->assign('ERROR', I18n::_($this->_error));
$page->assign('STATUS', I18n::_($this->_status));
$page->assign('VERSION', self::VERSION);

View file

@ -3,6 +3,19 @@ use PrivateBin\I18n;
$isCpct = substr($template, 9, 8) === '-compact';
$isDark = substr($template, 9, 5) === '-dark';
$isPage = substr($template, -5) === '-page';
$protocol = 'http:';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
$protocol = 'https:';
}
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' == $_SERVER['HTTP_X_FORWARDED_PROTO'])) {
// none secure, assumed trusted proxy, however won't threaten client security
$protocol = 'https:';
}
$host = $_SERVER['HTTP_HOST'];
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
// none secure, assumed trusted proxy, however won't threaten client security
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
?><!DOCTYPE html>
<html lang="<?php echo I18n::_('en'); ?>">
<head>
@ -74,7 +87,7 @@ endif;
<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-GCiSgkYlcyJq3SOMOAh52rIlUAoGH8yDJzOm/NkzBorbk2qiBSjc289/RxpeZJcdu36fQObFTzLvz4Do/2LFsA==" crossorigin="anonymous"></script>
<!-- icon -->
<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />
<link rel="apple-touch-icon" href="<?php echo I18n::encode("{$protocol}//{$host}/"); ?>img/apple-touch-icon.png" sizes="180x180" />
<link rel="icon" type="image/png" href="img/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="img/favicon-16x16.png" sizes="16x16" />
<link rel="manifest" href="manifest.json?<?php echo rawurlencode($VERSION); ?>" />
@ -86,11 +99,11 @@ endif;
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="<?php echo I18n::_('Encrypted note on PrivateBin') ?>" />
<meta name="twitter:description" content="<?php echo I18n::_('Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.') ?>" />
<meta name="twitter:image" content="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" />
<meta name="twitter:image" content="<?php echo I18n::encode("{$protocol}//{$host}/"); ?>img/apple-touch-icon.png" />
<meta property="og:title" content="<?php echo I18n::_($NAME); ?>" />
<meta property="og:site_name" content="<?php echo I18n::_($NAME); ?>" />
<meta property="og:description" content="<?php echo I18n::_('Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.') ?>" />
<meta property="og:image" content="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" />
<meta property="og:image" content="<?php echo I18n::encode("{$protocol}//{$host}/"); ?>img/apple-touch-icon.png" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="180" />
<meta property="og:image:height" content="180" />

View file

@ -34,7 +34,6 @@ class ViewTest extends PHPUnit_Framework_TestCase
/* Setup Routine */
$page = new View;
$page->assign('NAME', 'PrivateBinTest');
$page->assign('BASEPATH', '');
$page->assign('ERROR', self::$error);
$page->assign('STATUS', self::$status);
$page->assign('VERSION', self::$version);