-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.php
More file actions
60 lines (47 loc) · 1.62 KB
/
Controller.php
File metadata and controls
60 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\McpServer;
use Piwik\Access;
use Piwik\Piwik;
use Piwik\SettingsPiwik;
use Piwik\View;
class Controller extends \Piwik\Plugin\ControllerAdmin
{
public function __construct(private SystemSettings $systemSettings)
{
}
public function connect(): string
{
Piwik::checkUserHasSomeViewAccess();
$view = new View('@McpServer/connect');
$this->setBasicVariablesView($view);
$view->assign('isMcpEnabled', $this->systemSettings->isMcpEnabled());
$view->assign('canEnableMcp', Access::getInstance()->hasSuperUserAccess());
$view->assign('mcpApiEndpoint', $this->getMcpApiEndpointUrl());
$view->assign('mcpSettingsUrl', $this->getMcpSettingsUrl());
$view->assign('userSecurityUrl', $this->getUserSecurityUrl());
return $view->render();
}
private function getMcpApiEndpointUrl(): string
{
return $this->getBaseUrl() . '/index.php?module=API&method=McpServer.mcp&format=mcp';
}
private function getUserSecurityUrl(): string
{
return $this->getBaseUrl() . '/index.php?module=UsersManager&action=userSecurity#authtokens';
}
private function getMcpSettingsUrl(): string
{
return $this->getBaseUrl() . '/index.php?module=CoreAdminHome&action=generalSettings#McpServer';
}
private function getBaseUrl(): string
{
return rtrim((string) SettingsPiwik::getPiwikUrl(), '/');
}
}