Fix all existing links and redirection to ?do=login

This commit is contained in:
ArthurHoaro 2020-01-23 20:05:41 +01:00
parent dd51f653d0
commit 9e4cc28e29
6 changed files with 31 additions and 31 deletions

View file

@ -159,7 +159,7 @@ function checkDateFormat($format, $string)
*/ */
function generateLocation($referer, $host, $loopTerms = array()) function generateLocation($referer, $host, $loopTerms = array())
{ {
$finalReferer = '?'; $finalReferer = './?';
// No referer if it contains any value in $loopCriteria. // No referer if it contains any value in $loopCriteria.
foreach (array_filter($loopTerms) as $value) { foreach (array_filter($loopTerms) as $value) {

View file

@ -41,7 +41,7 @@ http://<replace_domain>/?do=daily
http://<replace_domain>/?post http://<replace_domain>/?post
http://<replace_domain>/?do=export http://<replace_domain>/?do=export
http://<replace_domain>/?do=import http://<replace_domain>/?do=import
http://<replace_domain>/?do=login http://<replace_domain>/login
http://<replace_domain>/?do=picwall http://<replace_domain>/?do=picwall
http://<replace_domain>/?do=pluginadmin http://<replace_domain>/?do=pluginadmin
http://<replace_domain>/?do=tagcloud http://<replace_domain>/?do=tagcloud

View file

@ -252,7 +252,7 @@ if (isset($_POST['login'])) {
// Optional redirect after login: // Optional redirect after login:
if (isset($_GET['post'])) { if (isset($_GET['post'])) {
$uri = '?post='. urlencode($_GET['post']); $uri = './?post='. urlencode($_GET['post']);
foreach (array('description', 'source', 'title', 'tags') as $param) { foreach (array('description', 'source', 'title', 'tags') as $param) {
if (!empty($_GET[$param])) { if (!empty($_GET[$param])) {
$uri .= '&'.$param.'='.urlencode($_GET[$param]); $uri .= '&'.$param.'='.urlencode($_GET[$param]);
@ -263,22 +263,22 @@ if (isset($_POST['login'])) {
} }
if (isset($_GET['edit_link'])) { if (isset($_GET['edit_link'])) {
header('Location: ?edit_link='. escape($_GET['edit_link'])); header('Location: ./?edit_link='. escape($_GET['edit_link']));
exit; exit;
} }
if (isset($_POST['returnurl'])) { if (isset($_POST['returnurl'])) {
// Prevent loops over login screen. // Prevent loops over login screen.
if (strpos($_POST['returnurl'], 'do=login') === false) { if (strpos($_POST['returnurl'], '/login') === false) {
header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST']));
exit; exit;
} }
} }
header('Location: ?'); header('Location: ./?');
exit; exit;
} else { } else {
$loginManager->handleFailedLogin($_SERVER); $loginManager->handleFailedLogin($_SERVER);
$redir = '&username='. urlencode($_POST['login']); $redir = '?username='. urlencode($_POST['login']);
if (isset($_GET['post'])) { if (isset($_GET['post'])) {
$redir .= '&post=' . urlencode($_GET['post']); $redir .= '&post=' . urlencode($_GET['post']);
foreach (array('description', 'source', 'title', 'tags') as $param) { foreach (array('description', 'source', 'title', 'tags') as $param) {
@ -288,7 +288,7 @@ if (isset($_POST['login'])) {
} }
} }
// Redirect to login screen. // Redirect to login screen.
echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'?do=login'.$redir.'\';</script>'; echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'./login'.$redir.'\';</script>';
exit; exit;
} }
} }
@ -923,7 +923,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
// Show login screen, then redirect to ?post=... // Show login screen, then redirect to ?post=...
if (isset($_GET['post'])) { if (isset($_GET['post'])) {
header( // Redirect to login page, then back to post link. header( // Redirect to login page, then back to post link.
'Location: ?do=login&post='.urlencode($_GET['post']). 'Location: /login?post='.urlencode($_GET['post']).
(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').
(!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').
(!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):'').
@ -934,7 +934,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
if (isset($_GET['edit_link'])) { if (isset($_GET['edit_link'])) {
header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); header('Location: /login?edit_link='. escape($_GET['edit_link']));
exit; exit;
} }
@ -1890,7 +1890,7 @@ function install($conf, $sessionManager, $loginManager)
echo '<script>alert(' echo '<script>alert('
.'"Shaarli is now configured. ' .'"Shaarli is now configured. '
.'Please enter your login/password and start shaaring your bookmarks!"' .'Please enter your login/password and start shaaring your bookmarks!"'
.');document.location=\'?do=login\';</script>'; .');document.location=\'./login\';</script>';
exit; exit;
} }

View file

@ -203,7 +203,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
public function testGenerateLocationLoop() public function testGenerateLocationLoop()
{ {
$ref = 'http://localhost/?test'; $ref = 'http://localhost/?test';
$this->assertEquals('?', generateLocation($ref, 'localhost', array('test'))); $this->assertEquals('./?', generateLocation($ref, 'localhost', array('test')));
} }
/** /**
@ -212,7 +212,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
public function testGenerateLocationOut() public function testGenerateLocationOut()
{ {
$ref = 'http://somewebsite.com/?test'; $ref = 'http://somewebsite.com/?test';
$this->assertEquals('?', generateLocation($ref, 'localhost')); $this->assertEquals('./?', generateLocation($ref, 'localhost'));
} }

View file

@ -60,7 +60,7 @@
</li> </li>
{else} {else}
<li class="pure-menu-item pure-u-lg-0 shaarli-menu-mobile" id="shaarli-menu-mobile-login"> <li class="pure-menu-item pure-u-lg-0 shaarli-menu-mobile" id="shaarli-menu-mobile-login">
<a href="?do=login" class="pure-menu-link">{'Login'|t}</a> <a href="/login" class="pure-menu-link">{'Login'|t}</a>
</li> </li>
{/if} {/if}
</ul> </ul>
@ -80,7 +80,7 @@
</li> </li>
{if="!$is_logged_in"} {if="!$is_logged_in"}
<li class="pure-menu-item" id="shaarli-menu-desktop-login"> <li class="pure-menu-item" id="shaarli-menu-desktop-login">
<a href="?do=login" class="pure-menu-link" <a href="/login" class="pure-menu-link"
data-open-id="header-login-form" data-open-id="header-login-form"
id="login-button" aria-label="{'Login'|t}" title="{'Login'|t}"> id="login-button" aria-label="{'Login'|t}" title="{'Login'|t}">
<i class="fa fa-user" aria-hidden="true"></i> <i class="fa fa-user" aria-hidden="true"></i>

View file

@ -25,7 +25,7 @@
<li><a href="?do=tools">Tools</a></li> <li><a href="?do=tools">Tools</a></li>
<li><a href="?do=addlink">Add link</a></li> <li><a href="?do=addlink">Add link</a></li>
{else} {else}
<li><a href="?do=login">Login</a></li> <li><a href="/login">Login</a></li>
{/if} {/if}
<li><a href="{$feedurl}?do=rss{$searchcrits}" class="nomobile">RSS Feed</a></li> <li><a href="{$feedurl}?do=rss{$searchcrits}" class="nomobile">RSS Feed</a></li>
{if="$showatom"} {if="$showatom"}