]> git.mxchange.org Git - friendica.git/commitdiff
Normalize use of form security tokens in Admin modules
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 8 Sep 2020 14:42:25 +0000 (10:42 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 8 Sep 2020 16:27:36 +0000 (12:27 -0400)
# Conflicts:
# src/Module/Admin/Logs/Settings.php

12 files changed:
src/Module/Admin/Addons/Details.php
src/Module/Admin/Addons/Index.php
src/Module/Admin/Blocklist/Contact.php
src/Module/Admin/Blocklist/Server.php
src/Module/Admin/Features.php
src/Module/Admin/Item/Delete.php
src/Module/Admin/Logs/Settings.php
src/Module/Admin/Site.php
src/Module/Admin/Themes/Index.php
src/Module/Admin/Tos.php
src/Module/Admin/Users.php
view/templates/admin/addons/details.tpl

index 139275cfe20a8dd446bc8ddaa44bdde49dc4e18b..85b17130c4ce1160ccefc758eeafc436bbae122a 100644 (file)
@@ -42,6 +42,8 @@ class Details extends BaseAdmin
                        include_once 'addon/' . $addon . '/' . $addon . '.php';
 
                        if (function_exists($addon . '_addon_admin_post')) {
+                               self::checkFormSecurityTokenRedirectOnError($redirect, 'admin_addons_details');
+
                                $func = $addon . '_addon_admin_post';
                                $func(DI::app());
                        }
@@ -66,7 +68,7 @@ class Details extends BaseAdmin
                }
 
                if (($_GET['action'] ?? '') == 'toggle') {
-                       self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
+                       self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons_details', 't');
 
                        // Toggle addon status
                        if (Addon::isEnabled($addon)) {
@@ -124,7 +126,7 @@ class Details extends BaseAdmin
                        '$screenshot' => '',
                        '$readme' => $readme,
 
-                       '$form_security_token' => self::getFormSecurityToken('admin_addons'),
+                       '$form_security_token' => self::getFormSecurityToken('admin_addons_details'),
                ]);
        }
 }
index 3049cdc6a70282fa5e807dd907773d0bce14a453..959f9d04a1341ca6cdb787a9ec1d9eae0f9f16e4 100644 (file)
@@ -34,7 +34,7 @@ class Index extends BaseAdmin
 
                // reload active themes
                if (!empty($_GET['action'])) {
-                       parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
+                       self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
 
                        switch ($_GET['action']) {
                                case 'reload':
@@ -73,7 +73,7 @@ class Index extends BaseAdmin
                        '$addons' => $addons,
                        '$pcount' => count($addons),
                        '$noplugshint' => DI::l10n()->t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
-                       '$form_security_token' => parent::getFormSecurityToken('admin_addons'),
+                       '$form_security_token' => self::getFormSecurityToken('admin_addons'),
                ]);
        }
 }
index 8893623234dfadc8af5d59646fb534a9e6f6f974..5a7d138b23e06c3ee021187e49de2fcaf3a0bc87 100644 (file)
@@ -34,12 +34,12 @@ class Contact extends BaseAdmin
        {
                parent::post($parameters);
 
+               self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
+
                $contact_url  = $_POST['contact_url'] ?? '';
                $block_reason = $_POST['contact_block_reason'] ?? '';
                $contacts     = $_POST['contacts'] ?? [];
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
-
                if (!empty($_POST['page_contactblock_block'])) {
                        $contact_id = Model\Contact::getIdForURL($contact_url);
                        if ($contact_id) {
@@ -89,7 +89,7 @@ class Contact extends BaseAdmin
                        '$h_newblock'  => DI::l10n()->t('Block New Remote Contact'),
                        '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
 
-                       '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
+                       '$form_security_token' => self::getFormSecurityToken('admin_contactblock'),
 
                        // values //
                        '$baseurl'    => DI::baseUrl()->get(true),
index 4f19ca361d11a9f1c9d835710d7889430c29b4ed..b4be591e7ffa7e4f6dc32651c6bff01a66263795 100644 (file)
@@ -36,7 +36,7 @@ class Server extends BaseAdmin
                        return;
                }
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
+               self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
 
                if (!empty($_POST['page_blocklist_save'])) {
                        //  Add new item to blocklist
@@ -108,7 +108,7 @@ class Server extends BaseAdmin
                        '$entries' => $blocklistform,
                        '$baseurl' => DI::baseUrl()->get(true),
                        '$confirm_delete' => DI::l10n()->t('Delete entry from blocklist?'),
-                       '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")
+                       '$form_security_token' => self::getFormSecurityToken("admin_blocklist")
                ]);
        }
 }
index a97bc0e7bb453b3090b875184d73f34092544168..51ba9140ef144a00fe081f02747b19c39c705c11 100644 (file)
@@ -32,7 +32,7 @@ class Features extends BaseAdmin
        {
                parent::post($parameters);
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features');
+               self::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features');
 
                $features = Feature::get(false);
 
@@ -80,7 +80,7 @@ class Features extends BaseAdmin
 
                $tpl = Renderer::getMarkupTemplate('admin/features.tpl');
                $o = Renderer::replaceMacros($tpl, [
-                       '$form_security_token' => parent::getFormSecurityToken("admin_manage_features"),
+                       '$form_security_token' => self::getFormSecurityToken("admin_manage_features"),
                        '$baseurl'             => DI::baseUrl()->get(true),
                        '$title'               => DI::l10n()->t('Manage Additional Features'),
                        '$features'            => $features,
index 0ad20f97c983ffc423ed3a9c9f16c90f0736e488..028e228d34f63519f318c70d6b1303c24184d97a 100644 (file)
@@ -37,7 +37,7 @@ class Delete extends BaseAdmin
                        return;
                }
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/item/delete', 'admin_deleteitem');
+               self::checkFormSecurityTokenRedirectOnError('/admin/item/delete', 'admin_deleteitem');
 
                if (!empty($_POST['page_deleteitem_submit'])) {
                        $guid = trim(Strings::escapeTags($_POST['deleteitemguid']));
@@ -68,7 +68,7 @@ class Delete extends BaseAdmin
                        '$intro1' => DI::l10n()->t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
                        '$intro2' => DI::l10n()->t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
                        '$deleteitemguid' => ['deleteitemguid', DI::l10n()->t("GUID"), '', DI::l10n()->t("The GUID of the item you want to delete."), 'required', 'autofocus'],
-                       '$form_security_token' => parent::getFormSecurityToken("admin_deleteitem")
+                       '$form_security_token' => self::getFormSecurityToken("admin_deleteitem")
                ]);
        }
 }
index 5158108e463ff75874194bfba6703c485bd3423c..0b5993798657c929fcdf9af70089bfd818e6fbe3 100644 (file)
@@ -33,25 +33,26 @@ class Settings extends BaseAdmin
        {
                parent::post($parameters);
 
-               if (!empty($_POST['page_logs'])) {
-                       parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
+               if (empty($_POST['page_logs'])) {
+                       return;
+               }
 
-                       $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
-                       $debugging = !empty($_POST['debugging']);
-                       $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
+               self::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
 
-                       if (is_file($logfile) &&
-                       !is_writeable($logfile)) {
-                               notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
-                               return;
-                       }
+               $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
+               $debugging = !empty($_POST['debugging']);
+               $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
 
-                       DI::config()->set('system', 'logfile', $logfile);
-                       DI::config()->set('system', 'debugging', $debugging);
-                       DI::config()->set('system', 'loglevel', $loglevel);
+               if (is_file($logfile) &&
+               !is_writeable($logfile)) {
+                       notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
+                       return;
                }
 
-               info(DI::l10n()->t("Log settings updated."));
+               DI::config()->set('system', 'logfile', $logfile);
+               DI::config()->set('system', 'debugging', $debugging);
+               DI::config()->set('system', 'loglevel', $loglevel);
+
                DI::baseUrl()->redirect('admin/logs');
        }
 
@@ -86,7 +87,7 @@ class Settings extends BaseAdmin
                        '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
                        '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory.")],
                        '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
-                       '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
+                       '$form_security_token' => self::getFormSecurityToken("admin_logs"),
                        '$phpheader' => DI::l10n()->t("PHP logging"),
                        '$phphint' => DI::l10n()->t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
                        '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
index 2e16cc657ebe43807ee9998302a23c7484d4e80d..6380f3d935bd2658d06670cbf961f9d38c3ae0c2 100644 (file)
@@ -718,7 +718,7 @@ class Site extends BaseAdmin
                        '$relay_server_tags'      => ['relay_server_tags', DI::l10n()->t('Server tags'), DI::config()->get('system', 'relay_server_tags'), DI::l10n()->t('Comma separated list of tags for the "tags" subscription.')],
                        '$relay_user_tags'        => ['relay_user_tags', DI::l10n()->t('Allow user tags'), DI::config()->get('system', 'relay_user_tags', true), DI::l10n()->t('If enabled, the tags from the saved searches will used for the "tags" subscription in addition to the "relay_server_tags".')],
 
-                       '$form_security_token'    => parent::getFormSecurityToken('admin_site'),
+                       '$form_security_token'    => self::getFormSecurityToken('admin_site'),
                        '$relocate_button'        => DI::l10n()->t('Start Relocation'),
                ]);
        }
index 955ddadc700f6827f1142a5e0933d35ff2356fd3..f25d64b474f4d46640b8b2f530d85043eae5b032 100644 (file)
@@ -37,7 +37,7 @@ class Index extends BaseAdmin
 
                // reload active themes
                if (!empty($_GET['action'])) {
-                       parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
+                       self::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
 
                        switch ($_GET['action']) {
                                case 'reload':
@@ -119,7 +119,7 @@ class Index extends BaseAdmin
                        '$noplugshint'         => DI::l10n()->t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
                        '$experimental'        => DI::l10n()->t('[Experimental]'),
                        '$unsupported'         => DI::l10n()->t('[Unsupported]'),
-                       '$form_security_token' => parent::getFormSecurityToken('admin_themes'),
+                       '$form_security_token' => self::getFormSecurityToken('admin_themes'),
                ]);
        }
 }
index 811a0eb25c0a7d10e8e666ff20540fa2694b6bb9..fef199c351fac87b111db9f568b80016bb5ab1bf 100644 (file)
@@ -31,12 +31,12 @@ class Tos extends BaseAdmin
        {
                parent::post($parameters);
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos');
-
                if (empty($_POST['page_tos'])) {
                        return;
                }
 
+               self::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos');
+
                $displaytos = !empty($_POST['displaytos']);
                $displayprivstatement = !empty($_POST['displayprivstatement']);
                $tostext = (!empty($_POST['tostext']) ? strip_tags(trim($_POST['tostext'])) : '');
@@ -64,7 +64,7 @@ class Tos extends BaseAdmin
                        '$preview' => DI::l10n()->t('Privacy Statement Preview'),
                        '$privtext' => $tos->privacy_complete,
                        '$tostext' => ['tostext', DI::l10n()->t('The Terms of Service'), DI::config()->get('system', 'tostext'), DI::l10n()->t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')],
-                       '$form_security_token' => parent::getFormSecurityToken('admin_tos'),
+                       '$form_security_token' => self::getFormSecurityToken('admin_tos'),
                        '$submit' => DI::l10n()->t('Save Settings'),
                ]);
        }
index f82f9f8c740e996de7b50004eea68d1f4db9cff3..751b618afc3220ddea822867531f913d4d5d103c 100644 (file)
@@ -36,6 +36,8 @@ class Users extends BaseAdmin
        {
                parent::post($parameters);
 
+               self::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users');
+
                $pending     = $_POST['pending']           ?? [];
                $users       = $_POST['user']              ?? [];
                $nu_name     = $_POST['new_user_name']     ?? '';
@@ -43,8 +45,6 @@ class Users extends BaseAdmin
                $nu_email    = $_POST['new_user_email']    ?? '';
                $nu_language = DI::config()->get('system', 'language');
 
-               parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users');
-
                if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') {
                        try {
                                User::createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language);
index f5bb165e05cf93e8aa20671bbb0492bd06f47e6e..81625fecf14bca9de2ca5c0548fec10dbd0717d2 100644 (file)
@@ -24,6 +24,7 @@
        {{if $admin_form}}
        <h3>{{$settings}}</h3>
        <form method="post" action="{{$baseurl}}/admin/{{$function}}/{{$addon}}">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
                {{$admin_form nofilter}}
        </form>
        {{/if}}