-
Notifications
You must be signed in to change notification settings - Fork 1
/
Handler.php
115 lines (99 loc) · 3.15 KB
/
Handler.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Copyright (C) Apis Networks, Inc - All Rights Reserved.
*
* Unauthorized copying of this file, via any medium, is
* strictly prohibited without consent. Any dissemination of
* material herein is prohibited.
*
* For licensing inquiries email <[email protected]>
*
* Written by Matt Saladna <[email protected]>, August 2020
*/
namespace Module\Support\Webapps\App\Type\Wordpress;
use Module\Support\Webapps\App\Type\Unknown\Handler as Unknown;
use function is_array;
class Handler extends Unknown
{
const NAME = 'WordPress';
const ADMIN_PATH = '/wp-admin';
const LINK = 'https://wordpress.org/';
const DEFAULT_FORTIFICATION = 'max';
const FEAT_ALLOW_SSL = true;
const FEAT_RECOVERY = true;
const TRANSIENT_RECONFIGURABLES = [
'migrate', 'duplicate', 'debug', 'language', 'maintenance'
];
public function recover(): bool
{
if (!$this->wordpress_disable_all_plugins($this->hostname, $this->path)) {
return warn('failed to disable all plugins');
}
$themes = $this->wordpress_theme_status($this->hostname, $this->path);
$filtered = array_filter($themes, static function ($v, $k) {
if (!$v['current']) {
return false;
}
if (0 !== strncmp($k, 'twenty', 6)) {
return false;
}
return true;
}, ARRAY_FILTER_USE_BOTH);
if ($filtered) {
$theme = key($filtered);
return $this->wordpress_enable_theme($this->hostname, $this->path, $theme) &&
info('Theme reset to %s', $theme);
}
return true;
}
private function installPlugins($plugins): void
{
if (!is_array($plugins)) {
$plugins = (array)$plugins;
}
foreach ($plugins as $plugin) {
if ($this->wordpress_install_plugin($this->hostname, $this->path, $plugin)) {
info("installed plugin `%s'", $plugin);
}
}
}
public function changePassword(string $password): bool
{
return $this->wordpress_change_admin($this->hostname, $this->path, ['user_pass' => $password]);
}
public function handle(array $params): bool
{
if (isset($params['render'])) {
\Lararia\Bootstrapper::minstrap();
echo view('@webapp(wordpress)::partials.plugin-table', ['app' => $this]);
exit;
} else if (isset($params['sso-check'])) {
\Lararia\Bootstrapper::minstrap();
echo view('@webapp(wordpress)::partials.actions.sso', ['app' => $this]);
exit;
}
if (isset($params['install-package'])) {
return $this->wordpress_install_package($params['install-package']);
}
if (isset($params['uninstall-package'])) {
return $this->wordpress_uninstall_package($params['uninstall-package']);
}
if (isset($params['enable-sso']) || isset($params['install-sso'])) {
$sso = Sso::instantiateContexted($this->getAuthContext(), [$this]);
if (isset($params['install-sso'])) {
if (!$this->wordpress_install_package($params['install-sso'])) {
return false;
}
defer($_, static function () use ($sso) {
$sso->handle();
});
}
// override Y/n prompt
return $sso->enable();
}
if (isset($params['wordpress-sso'])) {
return Sso::instantiateContexted($this->getAuthContext(), [$this])->handle();
}
return parent::handle($params);
}
}