TrackingSettings
6 years ago
views
6 years ago
AccessSettings.php
6 years ago
Admin.php
6 years ago
AdminSettings.php
6 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
6 years ago
ExclusionSettings.php
6 years ago
GeolocationSettings.php
6 years ago
GetStarted.php
6 years ago
Info.php
6 years ago
Marketplace.php
6 years ago
Menu.php
6 years ago
PrivacySettings.php
6 years ago
SafeModeMenu.php
6 years ago
Summary.php
6 years ago
SystemReport.php
6 years ago
TrackingSettings.php
6 years ago
AdvancedSettings.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo\Admin; |
| 11 | |
| 12 | use Piwik\Config; |
| 13 | use Piwik\IP; |
| 14 | use WpMatomo\Bootstrap; |
| 15 | use WpMatomo\Capabilities; |
| 16 | use WpMatomo\Settings; |
| 17 | use WpMatomo\Site; |
| 18 | use WpMatomo\TrackingCode\TrackingCodeGenerator; |
| 19 | |
| 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | exit; // if accessed directly |
| 22 | } |
| 23 | |
| 24 | class AdvancedSettings implements AdminSettingsInterface { |
| 25 | const FORM_NAME = 'matomo'; |
| 26 | const NONCE_NAME = 'matomo_advanced'; |
| 27 | |
| 28 | public static $valid_host_headers = array( |
| 29 | 'HTTP_CLIENT_IP', |
| 30 | 'HTTP_X_REAL_IP', |
| 31 | 'HTTP_X_FORWARDED_FOR', |
| 32 | 'HTTP_X_FORWARDED', |
| 33 | 'HTTP_FORWARDED_FOR', |
| 34 | 'HTTP_FORWARDED', |
| 35 | 'HTTP_CF_CONNECTING_IP', |
| 36 | 'HTTP_TRUE_CLIENT_IP', |
| 37 | 'HTTP_X_CLUSTER_CLIENT_IP', |
| 38 | ); |
| 39 | |
| 40 | public function get_title() { |
| 41 | return esc_html__( 'Advanced', 'matomo' ); |
| 42 | } |
| 43 | |
| 44 | private function update_if_submitted() { |
| 45 | if ( isset( $_POST ) |
| 46 | && ! empty( $_POST[ self::FORM_NAME ] ) |
| 47 | && is_admin() |
| 48 | && check_admin_referer( self::NONCE_NAME ) |
| 49 | && $this->can_user_manage() ) { |
| 50 | $this->apply_settings(); |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | public function can_user_manage() { |
| 59 | return current_user_can( Capabilities::KEY_SUPERUSER ); |
| 60 | } |
| 61 | |
| 62 | private function apply_settings() { |
| 63 | Bootstrap::do_bootstrap(); |
| 64 | $config = Config::getInstance(); |
| 65 | $general = $config->General; |
| 66 | $general['proxy_client_headers'] = array(); |
| 67 | |
| 68 | if (!empty($_POST[ self::FORM_NAME ]['proxy_client_header'])) { |
| 69 | $client_header = $_POST[ self::FORM_NAME ]['proxy_client_header']; |
| 70 | if (in_array($client_header, self::$valid_host_headers, true)) { |
| 71 | $general['proxy_client_headers'][] = $client_header; |
| 72 | } |
| 73 | } |
| 74 | $config->General = $general; |
| 75 | $config->forceSave(); |
| 76 | |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | public function show_settings() { |
| 81 | $was_updated = $this->update_if_submitted(); |
| 82 | |
| 83 | $matomo_client_headers = array(); |
| 84 | Bootstrap::do_bootstrap(); |
| 85 | $config = Config::getInstance(); |
| 86 | $general = $config->General; |
| 87 | if (!empty($general['proxy_client_headers']) && is_array($general['proxy_client_headers'])) { |
| 88 | $matomo_client_headers = $general['proxy_client_headers']; |
| 89 | } |
| 90 | |
| 91 | $matomo_detected_ip = IP::getIpFromHeader(); |
| 92 | |
| 93 | include dirname( __FILE__ ) . '/views/advanced_settings.php'; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | |
| 98 | } |
| 99 |