Merge pull request #7135 from MrPetovan/task/two-factor-authentication
authorPhilipp <admin+Github@philipp.info>
Tue, 14 May 2019 05:07:03 +0000 (07:07 +0200)
committerGitHub <noreply@github.com>
Tue, 14 May 2019 05:07:03 +0000 (07:07 +0200)
Add native two-factor authentication support

src/App.php
src/Module/Admin/Summary.php
src/Protocol/ActivityPub/Processor.php

index 41c50fd..2e357f8 100644 (file)
@@ -149,7 +149,8 @@ class App
         */
        public function getBasePath()
        {
-               return $this->config->get('system', 'basepath');
+               // Don't use the basepath of the config table for basepath (it should always be the config-file one)
+               return $this->config->getCache()->get('system', 'basepath');
        }
 
        /**
index a78a6b8..901a4b0 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Register;
 use Friendica\Module\BaseAdminModule;
+use Friendica\Util\Config\ConfigFileLoader;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 
@@ -73,6 +74,40 @@ class Summary extends BaseAdminModule
                                $well_known, $well_known, $a->getBaseURL() . '/help/Install');
                }
 
+               // check legacy basepath settings
+               $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
+               $configCache = new Config\Cache\ConfigCache();
+               $configLoader->setupCache($configCache);
+               $confBasepath = $configCache->get('system', 'basepath');
+               $currBasepath = $a->getConfig()->get('system', 'basepath');
+               if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
+                       if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) {
+                               $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [
+                                       'from' => $currBasepath,
+                                       'to'   => $confBasepath,
+                               ]);
+                               $warningtext[] = L10n::t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
+                                       $currBasepath,
+                                       $confBasepath);
+                       } elseif (!is_dir($currBasepath)) {
+                               $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
+                                       'from' => $currBasepath,
+                                       'to'   => $confBasepath,
+                               ]);
+                               $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
+                                       $currBasepath,
+                                       $confBasepath);
+                       } else {
+                               $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
+                                       'from' => $currBasepath,
+                                       'to'   => $confBasepath,
+                               ]);
+                               $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
+                                       $currBasepath,
+                                       $confBasepath);
+                       }
+               }
+
                $accounts = [
                        [L10n::t('Normal Account'), 0],
                        [L10n::t('Automatic Follower Account'), 0],
index 3bb0639..53b0e7c 100644 (file)
@@ -90,12 +90,13 @@ class Processor
        /**
         * Add attachment data to the item array
         *
-        * @param array $attachments
-        * @param array $item
+        * @param array   $attachments
+        * @param array   $item
+        * @param boolean $no_images
         *
         * @return array array
         */
-       private static function constructAttachList($attachments, $item)
+       private static function constructAttachList($attachments, $item, $no_images)
        {
                if (empty($attachments)) {
                        return $item;
@@ -104,6 +105,10 @@ class Processor
                foreach ($attachments as $attach) {
                        $filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/')));
                        if ($filetype == 'image') {
+                               if ($no_images) {
+                                       continue;
+                               }
+
                                $item['body'] .= "\n[img]" . $attach['url'] . '[/img]';
                        } else {
                                if (!empty($item["attach"])) {
@@ -351,7 +356,7 @@ class Processor
 
                $item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
 
-               $item = self::constructAttachList($activity['attachments'], $item);
+               $item = self::constructAttachList($activity['attachments'], $item, !empty($activity['source']));
 
                $stored = false;