Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /home/claqxcrl/anfangola.com/wp-content/plugins/matomo/app/core/CliMulti/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/claqxcrl/anfangola.com/wp-content/plugins/matomo/app/core/CliMulti/RequestParser.php
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\CliMulti;

use Piwik\SettingsPiwik;
class RequestParser
{
    private $supportsAsync;
    public function __construct($supportsAsync)
    {
        $this->supportsAsync = $supportsAsync;
    }
    public function getInProgressCommands()
    {
        $psOutput = $this->getPsOutput();
        $climultiRequestCommands = $this->getPsLinesWithCliMulti($psOutput);
        $climultiRequestCommands = $this->parseQueries($climultiRequestCommands);
        return $climultiRequestCommands;
    }
    public function getInProgressArchivingCommands()
    {
        $commands = $this->getInProgressCommands();
        $commands = $this->filterNonArchivingJobs($commands);
        return $commands;
    }
    private function getPsOutput()
    {
        if (!$this->supportsAsync) {
            // we cannot detect if web archive is still running
            return '';
        }
        return $this->invokePs();
    }
    private function filterNonArchivingJobs($commands)
    {
        $result = array_filter($commands, function ($command) {
            if (empty($command['trigger']) || $command['trigger'] != 'archivephp') {
                return false;
            }
            return true;
        });
        $result = array_values($result);
        return $result;
    }
    private function getPsLinesWithCliMulti(string $psOutput)
    {
        $instanceId = SettingsPiwik::getPiwikInstanceId();
        $lines = explode("\n", $psOutput);
        $lines = array_map('trim', $lines);
        $lines = array_filter($lines, function ($line) use($instanceId) {
            if (!empty($instanceId) && strpos($line, 'matomo-domain=' . $instanceId) === false) {
                return false;
            }
            return strpos($line, 'climulti:request') !== false && (strpos($line, 'console') !== false || strpos($line, 'php') !== false);
        });
        return $lines;
    }
    private function parseQueries(array $climultiRequestCommands)
    {
        $commandName = 'climulti:request';
        $result = [];
        foreach ($climultiRequestCommands as $command) {
            $pos = strpos($command, $commandName);
            $commandParts = substr($command, $pos + strlen($commandName));
            $commandParts = explode(" ", $commandParts);
            $commandParts = array_filter($commandParts, function ($p) {
                return strlen($p) && substr($p, 0, 1) != '-';
            });
            $query = reset($commandParts);
            parse_str($query, $parsed);
            $result[] = $parsed;
        }
        return $result;
    }
    protected function invokePs()
    {
        if (defined('PIWIK_TEST_MODE')) {
            return '';
            // skip check in tests as it might result in random failures
        }
        return `ps aux`;
    }
}

ZeroDay Forums Mini