Skip to content

Commit

Permalink
Support for cleared boot.php
Browse files Browse the repository at this point in the history
  • Loading branch information
annando committed Nov 4, 2021
1 parent 95622a0 commit 6a349e7
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 25 deletions.
5 changes: 3 additions & 2 deletions blockbot/blockbot.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Jaybizzle\CrawlerDetect\CrawlerDetect;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Network\HTTPException\ForbiddenException;

require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

Expand Down Expand Up @@ -92,7 +93,7 @@ function blockbot_init_1(App $a) {

foreach ($agents as $agent) {
if (stristr($_SERVER['HTTP_USER_AGENT'], $agent)) {
System::httpExit(403, 'Bots are not allowed');
throw new ForbiddenException('Bots are not allowed');
}
}

Expand Down Expand Up @@ -130,5 +131,5 @@ function blockbot_init_1(App $a) {
}

logger::info('Blocked bot', $logdata);
System::httpExit(403, 'Bots are not allowed');
throw new ForbiddenException('Bots are not allowed');
}
4 changes: 2 additions & 2 deletions cookienotice/cookienotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function cookienotice_install()
*/
function cookienotice_addon_admin(App $a, &$s)
{
if (!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand Down Expand Up @@ -63,7 +63,7 @@ function cookienotice_addon_admin(App $a, &$s)
*/
function cookienotice_addon_admin_post(App $a)
{
if (!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions curweather/curweather.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function curweather_addon_settings(App $a, &$s)
// for accessing the API of openweathermap
function curweather_addon_admin_post(App $a)
{
if (!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand All @@ -216,7 +216,7 @@ function curweather_addon_admin_post(App $a)

function curweather_addon_admin(App $a, &$o)
{
if (!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion diaspora/Diaspora_Connection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Friendica\Core\System;

/**
* Super-skeletal class to interact with Diaspora.
*
Expand Down Expand Up @@ -29,7 +32,7 @@ public function __construct($diaspora_handle = '', $password = '') {
$this->setPassword($password);
}

$this->cookiejar = tempnam(get_temppath(), 'cookies');
$this->cookiejar = tempnam(System::getTempPath(), 'cookies');
return $this;
}

Expand Down
5 changes: 4 additions & 1 deletion diaspora/diasphp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Friendica\Core\System;

/**
* Ein fies zusammengehackter PHP-Diaspory-Client, der direkt von diesem abgeschaut ist:
* https://github.com/Javafant/diaspy/blob/master/client.py
Expand All @@ -11,7 +14,7 @@ function __construct($pod) {
$this->token_regex = '/content="(.*?)" name="csrf-token/';

$this->pod = $pod;
$this->cookiejar = tempnam(get_temppath(), 'cookies');
$this->cookiejar = tempnam(System::getTempPath(), 'cookies');
}

function __destruct() {
Expand Down
2 changes: 1 addition & 1 deletion irc/irc.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function irc_content(&$a) {
}

function irc_addon_admin_post (&$a) {
if(! is_site_admin())
if(!$a->isSiteAdmin())
return;

if($_POST['irc-submit']) {
Expand Down
3 changes: 2 additions & 1 deletion mailstream/mailstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
Expand Down Expand Up @@ -204,7 +205,7 @@ function mailstream_do_images(&$item, &$attachments)
if (!$components) {
continue;
}
$cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-');
$curlResult = DI::httpClient()->fetchFull($url, 0, '', $cookiejar);
$attachments[$url] = [
'data' => $curlResult->getBody(),
Expand Down
6 changes: 4 additions & 2 deletions mailstream/phpmailer/class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/

use Friendica\Core\System;

/**
* PHPMailer - PHP email creation and transport class.
* @package PHPMailer
Expand Down Expand Up @@ -2350,11 +2352,11 @@ public function createBody()
throw new phpmailerException($this->lang('extension_missing') . 'openssl');
}
// @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
$file = tempnam(get_temppath(), 'mail');
$file = tempnam(System::getTempPath(), 'mail');
if (false === file_put_contents($file, $body)) {
throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
}
$signed = tempnam(get_temppath(), 'signed');
$signed = tempnam(System::getTempPath(), 'signed');
//Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
if (empty($this->sign_extracerts_file)) {
$sign = @openssl_pkcs7_sign(
Expand Down
4 changes: 2 additions & 2 deletions notifyall/notifyall.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function notifyall_addon_admin(App $a, &$o)

function notifyall_post(App $a)
{
if(!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ function notifyall_post(App $a)

function notifyall_content(&$a)
{
if (! is_site_admin()) {
if (!$a->isSiteAdmin()) {
return '';
}

Expand Down
4 changes: 2 additions & 2 deletions pageheader/pageheader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function pageheader_install() {

function pageheader_addon_admin(App &$a, &$s)
{
if(! is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand All @@ -43,7 +43,7 @@ function pageheader_addon_admin(App &$a, &$s)

function pageheader_addon_admin_post(App $a)
{
if(!is_site_admin()) {
if (!$a->isSiteAdmin()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rendertime/rendertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function rendertime_page_end(Friendica\App $a, &$o)
$ignored_modules = ["fbrowser"];
$ignored = in_array(DI::module()->getName(), $ignored_modules);

if (is_site_admin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
if ($a->isSiteAdmin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {

$o = $o . '<div class="renderinfo">' . DI::l10n()->t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
round($profiler->get('database') - $profiler->get('database_write'), 3),
Expand Down
4 changes: 3 additions & 1 deletion statusnet/library/codebirdsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CodebirdSN;

use Friendica\Core\System;

/**
* A Twitter library in PHP.
*
Expand Down Expand Up @@ -820,7 +822,7 @@ protected function _buildMultipart($method, $params)
}

// To-Do
$tempfile = tempnam(get_temppath(), "mimecheck");
$tempfile = tempnam(System::getTempPath(), "mimecheck");
file_put_contents($tempfile, $data);
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
unlink($tempfile);
Expand Down
5 changes: 3 additions & 2 deletions statusnet/statusnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
Expand Down Expand Up @@ -599,7 +600,7 @@ function statusnet_post_hook(App $a, &$b)

if ($image != "") {
$img_str = DI::httpClient()->fetch($image);
$tempfile = tempnam(get_temppath(), "cache");
$tempfile = tempnam(System::getTempPath(), "cache");
file_put_contents($tempfile, $img_str);
$postdata = ["status" => $msg, "media[]" => $tempfile];
} else {
Expand Down Expand Up @@ -1417,7 +1418,7 @@ function statusnet_convertmsg(App $a, $body)
} else {
$img_str = DI::httpClient()->fetch($expanded_url, 4);

$tempfile = tempnam(get_temppath(), "cache");
$tempfile = tempnam(System::getTempPath(), "cache");
file_put_contents($tempfile, $img_str);
$mime = mime_content_type($tempfile);
unlink($tempfile);
Expand Down
3 changes: 2 additions & 1 deletion twitter/twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
use Friendica\Model\User;
use Friendica\Protocol\Activity;
use Friendica\Core\Config\Util\ConfigFileLoader;
use Friendica\Core\System;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Strings;
Expand Down Expand Up @@ -734,7 +735,7 @@ function (array $attributes, array $author_contact, $content, $is_quote_share) {

$img_str = DI::httpClient()->fetch($image['url']);

$tempfile = tempnam(get_temppath(), 'cache');
$tempfile = tempnam(System::getTempPath(), 'cache');
file_put_contents($tempfile, $img_str);

Logger::info('Uploading', ['id' => $b['id'], 'image' => $image['url']]);
Expand Down
7 changes: 3 additions & 4 deletions windowsphonepush/windowsphonepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Network\HTTPException\UnauthorizedException;

function windowsphonepush_install()
{
Expand Down Expand Up @@ -436,8 +437,7 @@ function windowsphonepush_login(App $a)
if (!isset($_SERVER['PHP_AUTH_USER'])) {
Logger::info('API_login: ' . print_r($_SERVER, true));
header('WWW-Authenticate: Basic realm="Friendica"');
header('HTTP/1.0 401 Unauthorized');
die('This api requires login');
throw new UnauthorizedException('This api requires login');
}

$user_id = User::authenticate($_SERVER['PHP_AUTH_USER'], trim($_SERVER['PHP_AUTH_PW']));
Expand All @@ -447,8 +447,7 @@ function windowsphonepush_login(App $a)
} else {
Logger::info('API_login failure: ' . print_r($_SERVER, true));
header('WWW-Authenticate: Basic realm="Friendica"');
header('HTTP/1.0 401 Unauthorized');
die('This api requires login');
throw new UnauthorizedException('This api requires login');
}

DI::auth()->setForUser($a, $record);
Expand Down

0 comments on commit 6a349e7

Please sign in to comment.