Skip to content

Commit

Permalink
better url generation to cover subfolder case. fix #552
Browse files Browse the repository at this point in the history
still perfectible though…
  • Loading branch information
NicolasCARPi committed Dec 13, 2017
1 parent 5f252cd commit 9d3c711
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/classes/AbstractMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function getTmpPath()
protected function getUrl()
{
$Request = Request::createFromGlobals();
$url = 'https://' . $Request->getHttpHost() . '/' . $this->Entity->page . '.php';
$url = Tools::getUrl($Request) . '/' . $this->Entity->page . '.php';

return $url . "?mode=view&id=" . $this->Entity->id;
}
Expand Down
4 changes: 2 additions & 2 deletions app/classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function alertAdmin($team)
}
// get url
$Request = Request::createFromGlobals();
$url = 'https://' . $Request->getHttpHost() . '/admin.php';
$url = 'https://' . $Request->getHost() . ':' . $Request->getPort() . $Request->getBaseUrl() . '/admin.php';

// Create the message
$footer = "\n\n~~~\nSent from eLabFTW https://www.elabftw.net\n";
Expand Down Expand Up @@ -228,7 +228,7 @@ public function alertUserIsValidated($email)

// now let's get the URL so we can have a nice link in the email
$Request = Request::createFromGlobals();
$url = 'https://' . $Request->getHttpHost() . '/login.php';
$url = 'https://' . $Request->getHost() . ':' . $Request->getPort() . $Request->getBaseUrl() . '/login.php';

$footer = "\n\n~~~\nSent from eLabFTW https://www.elabftw.net\n";
// Create the message
Expand Down
4 changes: 3 additions & 1 deletion app/classes/MakePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private function addLinkedItems()

// create Request object
$Request = Request::createFromGlobals();
$url = 'https://' . $Request->getHttpHost() . '/database.php';
$url = Tools::getUrl($Request) . '/' . $this->Entity->page . '.php';
// not pretty but gets the job done
$url = str_replace('app/classes/', '', $url);

foreach ($linksArr as $link) {
$fullItemUrl = $url . "?mode=view&id=" . $link['link_id'];
Expand Down
13 changes: 13 additions & 0 deletions app/classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
namespace Elabftw\Elabftw;

use Symfony\Component\HttpFoundation\Request;

/**
* Toolbelt full of useful functions
*/
Expand Down Expand Up @@ -344,4 +346,15 @@ public static function getCleanTitle($title)
{
return str_replace(array('#', "&39;", "&34;"), '', $title) . " - eLabFTW";
}

/**
* Return a full URL of the elabftw install
*
* @param Request $Request
* @return string the url
*/
public static function getUrl($Request)
{
return 'https://' . $Request->getHost() . ':' . $Request->getPort() . $Request->getBasePath();
}
}
4 changes: 3 additions & 1 deletion app/controllers/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
$deadline = Crypto::encrypt(time() + 3600, Key::loadFromAsciiSafeString(SECRET_KEY));

// build the reset link
$resetLink = 'https://' . $Request->getHttpHost() . '/change-pass.php';
$resetLink = Tools::getUrl($Request) . '/change-pass.php';
// not pretty but gets the job done
$resetLink = str_replace('app/controllers/', '', $resetLink);
$resetLink .='?key=' . $key . '&deadline=' . $deadline . '&userid=' . $user['userid'];

// Send an email with the reset link
Expand Down
4 changes: 3 additions & 1 deletion app/init.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
$configFilePath = dirname(dirname(__FILE__)) . '/config.php';
// redirect to install page if the config file is not here
if (!is_readable($configFilePath)) {
$url = 'https://' . $Request->getHttpHost() . '/install/index.php';
$url = Tools::getUrl($Request) . '/install/index.php';
// not pretty but gets the job done
$url = str_replace('app/', '', $url);
header('Location: ' . $url);
throw new Exception('Redirecting to install folder');
}
Expand Down
4 changes: 3 additions & 1 deletion app/models/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ private function alertOwner()

// Create the message
$Request = Request::createFromGlobals();
$url = 'https://' . $Request->getHttpHost() . '/experiments.php';
$url = Tools::getUrl($Request) . '/' . $this->Entity->page . '.php';
// not pretty but gets the job done
$url = str_replace('app/models/', '', $url);
$url .= "?mode=view&id=" . $this->Entity->id;

$footer = "\n\n~~~\nSent from eLabFTW https://www.elabftw.net\n";
Expand Down
4 changes: 3 additions & 1 deletion install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
// if we are not in https, die saying we work only in https
if (!$Request->isSecure() && !$Request->server->has('HTTP_X_FORWARDED_PROTO')) {
// get the url to display a link to click (without the port)
$url = 'https://' . $Request->getHttpHost();
$url = Tools::getUrl($Request);
// not pretty but gets the job done
$url = str_replace('install/', '', $url);
$message = "eLabFTW works only in HTTPS. Please enable HTTPS on your server. Or click this link : <a href='" .
$url . "'>$url</a>";
throw new Exception($message);
Expand Down
2 changes: 1 addition & 1 deletion login.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// if we are not in https, die saying we work only in https
if (!$Request->isSecure() && !$Request->server->has('HTTP_X_FORWARDED_PROTO')) {
// get the url to display a link to click (without the port)
$url = 'https://' . $Request->getHttpHost();
$url = Tools::getUrl($Request);
$message = "eLabFTW works only in HTTPS. Please enable HTTPS on your server. Or click this link : <a href='" .
$url . "'>$url</a>";
throw new Exception($message);
Expand Down

0 comments on commit 9d3c711

Please sign in to comment.