2019-05-02 01:33:33 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-02 01:33:33 +00:00
|
|
|
|
2019-10-11 15:55:02 +00:00
|
|
|
namespace Friendica\Module\HTTPException;
|
2019-05-02 01:33:33 +00:00
|
|
|
|
2022-06-23 20:42:35 +00:00
|
|
|
use Friendica\App;
|
2019-05-02 01:33:33 +00:00
|
|
|
use Friendica\BaseModule;
|
2022-06-23 20:42:35 +00:00
|
|
|
use Friendica\Core\L10n;
|
2022-05-18 02:13:54 +00:00
|
|
|
use Friendica\Core\System;
|
2020-01-18 21:07:07 +00:00
|
|
|
use Friendica\DI;
|
2022-06-23 20:42:35 +00:00
|
|
|
use Friendica\Module\Response;
|
2019-05-02 01:33:33 +00:00
|
|
|
use Friendica\Network\HTTPException;
|
2022-06-23 20:42:35 +00:00
|
|
|
use Friendica\Util\Profiler;
|
2021-11-21 22:37:17 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2022-06-23 20:42:35 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2019-05-02 01:33:33 +00:00
|
|
|
|
|
|
|
class PageNotFound extends BaseModule
|
|
|
|
{
|
2022-06-23 20:42:35 +00:00
|
|
|
/** @var string */
|
|
|
|
private $remoteAddress;
|
|
|
|
|
|
|
|
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Request $request, array $server, array $parameters = [])
|
|
|
|
{
|
|
|
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
|
|
|
|
|
|
|
$this->remoteAddress = $request->getRemoteAddress();
|
|
|
|
}
|
|
|
|
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function content(array $request = []): string
|
2019-05-02 01:33:33 +00:00
|
|
|
{
|
2020-01-18 19:52:34 +00:00
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
|
2019-05-02 01:33:33 +00:00
|
|
|
}
|
2021-11-20 14:38:03 +00:00
|
|
|
|
2021-11-28 12:44:42 +00:00
|
|
|
public function run(array $request = []): ResponseInterface
|
2021-11-20 14:38:03 +00:00
|
|
|
{
|
|
|
|
/* The URL provided does not resolve to a valid module.
|
|
|
|
*
|
|
|
|
* On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
|
|
|
|
* We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
|
|
|
|
* we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
|
|
|
|
* this will often succeed and eventually do the right thing.
|
|
|
|
*
|
|
|
|
* Otherwise we are going to emit a 404 not found.
|
|
|
|
*/
|
|
|
|
$queryString = $this->server['QUERY_STRING'];
|
|
|
|
// Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
|
|
|
|
if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) {
|
2022-05-18 02:13:54 +00:00
|
|
|
System::exit();
|
2021-11-20 14:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
|
|
|
|
$this->logger->info('index.php: dreamhost_error_hack invoked.', ['Original URI' => $this->server['REQUEST_URI']]);
|
|
|
|
$this->baseUrl->redirect($this->server['REQUEST_URI']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->logger->debug('index.php: page not found.', [
|
|
|
|
'request_uri' => $this->server['REQUEST_URI'],
|
2022-06-23 20:42:35 +00:00
|
|
|
'address' => $this->remoteAddress,
|
2021-11-20 14:38:03 +00:00
|
|
|
'query' => $this->server['QUERY_STRING']
|
|
|
|
]);
|
|
|
|
|
2021-11-28 12:44:42 +00:00
|
|
|
return parent::run($request); // TODO: Change the autogenerated stub
|
2021-11-20 14:38:03 +00:00
|
|
|
}
|
2019-05-02 01:33:33 +00:00
|
|
|
}
|