From 6a349e7fd98c331373b3ae948d273fc36058bbb7 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Nov 2021 20:32:16 +0000 Subject: [PATCH] Support for cleared boot.php --- blockbot/blockbot.php | 5 +++-- cookienotice/cookienotice.php | 4 ++-- curweather/curweather.php | 4 ++-- diaspora/Diaspora_Connection.php | 5 ++++- diaspora/diasphp.php | 5 ++++- irc/irc.php | 2 +- mailstream/mailstream.php | 3 ++- mailstream/phpmailer/class.phpmailer.php | 6 ++++-- notifyall/notifyall.php | 4 ++-- pageheader/pageheader.php | 4 ++-- rendertime/rendertime.php | 2 +- statusnet/library/codebirdsn.php | 4 +++- statusnet/statusnet.php | 5 +++-- twitter/twitter.php | 3 ++- windowsphonepush/windowsphonepush.php | 7 +++---- 15 files changed, 38 insertions(+), 25 deletions(-) diff --git a/blockbot/blockbot.php b/blockbot/blockbot.php index 3c5e3319..0ff372c5 100644 --- a/blockbot/blockbot.php +++ b/blockbot/blockbot.php @@ -15,6 +15,7 @@ use Friendica\DI; 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'; @@ -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'); } } @@ -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'); } diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index 4ca86280..bec98184 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -35,7 +35,7 @@ function cookienotice_install() */ function cookienotice_addon_admin(App $a, &$s) { - if (!is_site_admin()) { + if (!$a->isSiteAdmin()) { return; } @@ -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; } diff --git a/curweather/curweather.php b/curweather/curweather.php index 0fd60eac..118c4a9a 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -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; } @@ -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; } diff --git a/diaspora/Diaspora_Connection.php b/diaspora/Diaspora_Connection.php index a33bf608..d8390d70 100644 --- a/diaspora/Diaspora_Connection.php +++ b/diaspora/Diaspora_Connection.php @@ -1,4 +1,7 @@ setPassword($password); } - $this->cookiejar = tempnam(get_temppath(), 'cookies'); + $this->cookiejar = tempnam(System::getTempPath(), 'cookies'); return $this; } diff --git a/diaspora/diasphp.php b/diaspora/diasphp.php index f48933a6..4225353e 100644 --- a/diaspora/diasphp.php +++ b/diaspora/diasphp.php @@ -1,4 +1,7 @@ token_regex = '/content="(.*?)" name="csrf-token/'; $this->pod = $pod; - $this->cookiejar = tempnam(get_temppath(), 'cookies'); + $this->cookiejar = tempnam(System::getTempPath(), 'cookies'); } function __destruct() { diff --git a/irc/irc.php b/irc/irc.php index 4cb99c3f..b441cebf 100644 --- a/irc/irc.php +++ b/irc/irc.php @@ -118,7 +118,7 @@ return $o; } function irc_addon_admin_post (&$a) { - if(! is_site_admin()) + if(!$a->isSiteAdmin()) return; if($_POST['irc-submit']) { diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 9739913d..7e3f87f8 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -10,6 +10,7 @@ use Friendica\Content\Text\BBCode; 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; @@ -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(), diff --git a/mailstream/phpmailer/class.phpmailer.php b/mailstream/phpmailer/class.phpmailer.php index 46ff4360..ab7fe030 100644 --- a/mailstream/phpmailer/class.phpmailer.php +++ b/mailstream/phpmailer/class.phpmailer.php @@ -17,6 +17,8 @@ * FITNESS FOR A PARTICULAR PURPOSE. */ +use Friendica\Core\System; + /** * PHPMailer - PHP email creation and transport class. * @package PHPMailer @@ -2350,11 +2352,11 @@ class PHPMailer 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( diff --git a/notifyall/notifyall.php b/notifyall/notifyall.php index e5e94c7e..8eff5093 100644 --- a/notifyall/notifyall.php +++ b/notifyall/notifyall.php @@ -25,7 +25,7 @@ function notifyall_addon_admin(App $a, &$o) function notifyall_post(App $a) { - if(!is_site_admin()) { + if (!$a->isSiteAdmin()) { return; } @@ -62,7 +62,7 @@ function notifyall_post(App $a) function notifyall_content(&$a) { - if (! is_site_admin()) { + if (!$a->isSiteAdmin()) { return ''; } diff --git a/pageheader/pageheader.php b/pageheader/pageheader.php index f0d75400..ce3b2684 100644 --- a/pageheader/pageheader.php +++ b/pageheader/pageheader.php @@ -19,7 +19,7 @@ function pageheader_install() { function pageheader_addon_admin(App &$a, &$s) { - if(! is_site_admin()) { + if (!$a->isSiteAdmin()) { return; } @@ -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; } diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index 1d8e9701..135bcc76 100644 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -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 . '
' . 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), diff --git a/statusnet/library/codebirdsn.php b/statusnet/library/codebirdsn.php index cba5f936..e5e281b9 100644 --- a/statusnet/library/codebirdsn.php +++ b/statusnet/library/codebirdsn.php @@ -2,6 +2,8 @@ namespace CodebirdSN; +use Friendica\Core\System; + /** * A Twitter library in PHP. * @@ -820,7 +822,7 @@ class CodebirdSN } // 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); diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index e474264e..75e44151 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -47,6 +47,7 @@ use Friendica\Core\Hook; 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; @@ -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 { @@ -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); diff --git a/twitter/twitter.php b/twitter/twitter.php index ef64e1a2..6f53b2e4 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -85,6 +85,7 @@ use Friendica\Model\Tag; 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; @@ -734,7 +735,7 @@ function twitter_post_hook(App $a, array &$b) $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']]); diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 6ee4e0f0..4201db66 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -36,6 +36,7 @@ use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPException\UnauthorizedException; function windowsphonepush_install() { @@ -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'])); @@ -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);