Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions app/Http/Controllers/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Constants\Permissions;
use App\Contracts\TokenizableGatewayInterface;
use App\Enums\AddonOperation;
use App\Http\Controllers\Api\ClientApiController;
use App\Http\Controllers\Api\DomainApiController;
use App\Http\Controllers\Api\InvoiceApiController;
Expand All @@ -13,7 +14,6 @@
use App\Http\Controllers\Api\TicketApiController;
use App\Http\Controllers\Controller;
use App\Http\Traits\CsvExportable;
use App\Enums\AddonOperation;
use App\Models\ActivityLog;
use App\Models\Admin;
use App\Models\AdminActivity;
Expand Down Expand Up @@ -62,9 +62,10 @@
use App\Models\TicketSpamFilter;
use App\Models\TicketStatus;
use App\Models\TodoItem;
use App\Services\Addons\AddonExecutionService;
use App\Models\Transaction;
use App\Rules\EmailList;
use App\Services\Module\ModuleRegistry;
use App\Services\Module\ModuleSwitchboard;
use App\Services\NotificationService;
use App\Services\ServerAccountSync;
use App\Support\Addons\AddonPayloadSanitizer;
Expand All @@ -75,6 +76,7 @@
use App\Support\IpAllowList;
use App\Support\ModuleSettings;
use App\Support\ServerAddress;
use App\Support\TaxNotice;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
Expand Down Expand Up @@ -662,7 +664,7 @@ public function tax()
])
->values();

return view('admin.config.tax', ['groups' => $groups, 'taxEnabled' => $taxEnabled, 'taxInclusive' => $taxInclusive, 'taxNotice' => \App\Support\TaxNotice::text()]);
return view('admin.config.tax', ['groups' => $groups, 'taxEnabled' => $taxEnabled, 'taxInclusive' => $taxInclusive, 'taxNotice' => TaxNotice::text()]);
}

public function storeTax(Request $request)
Expand Down Expand Up @@ -1549,7 +1551,7 @@ public function destroyTicketStatus(TicketStatus $status)
// Email Templates
public function updateEmailTemplate(Request $request, EmailTemplate $template)
{
$validated = $request->validate(['type' => 'nullable|string', 'name' => 'nullable|string', 'subject' => 'nullable|string', 'message' => 'nullable|string', 'from_name' => 'nullable|string', 'from_email' => 'nullable|email', 'copy_to' => ['nullable', 'string', 'max:255', new \App\Rules\EmailList], 'disabled' => 'boolean']);
$validated = $request->validate(['type' => 'nullable|string', 'name' => 'nullable|string', 'subject' => 'nullable|string', 'message' => 'nullable|string', 'from_name' => 'nullable|string', 'from_email' => 'nullable|email', 'copy_to' => ['nullable', 'string', 'max:255', new EmailList], 'disabled' => 'boolean']);

// Only a changed body makes the template the operator's own, which is
// what lets their wording replace the built-in email. The form always
Expand Down Expand Up @@ -2519,21 +2521,46 @@ public function apiDocs()
}

// ===== SSL MODULES =====
public function sslModules()
public function sslModules(ModuleSwitchboard $switchboard)
{
$registry = app(ModuleRegistry::class);
$modules = [];
$settings = [];
$active = [];
$usage = [];

foreach ($registry->getSslModules() as $name) {
$module = $registry->getSslModule($name);
if ($module) {
$modules[$name] = $module;
$settings[$name] = SslModuleSettings::getForModule($name);
$active[$name] = $switchboard->isActive('ssl', $name);
$usage[$name] = $switchboard->usage('ssl', $name);
}
}

return view('admin.config.ssl-modules', compact('modules', 'settings'));
return view('admin.config.ssl-modules', compact('modules', 'settings', 'active', 'usage'));
}

public function toggleSslModule(Request $request, string $module, ModuleSwitchboard $switchboard)
{
$request->validate(['active' => ['required', Rule::in(['0', '1'])]]);

if (! $switchboard->exists('ssl', $module)) {
abort(404);
}

$on = $request->input('active') === '1';
$result = $switchboard->setActive('ssl', $module, $on);

if ($result['success']) {
ActivityLog::log(
'Module ssl/'.$module.' switched '.($on ? 'on' : 'off'),
auth('admin')->user()?->username
);
}

return back()->with($result['success'] ? 'success' : 'error', $result['message']);
}

/**
Expand Down
14 changes: 2 additions & 12 deletions app/Http/Controllers/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@
use Illuminate\Validation\Rule;

/**
* Every installed module on one screen, each with its on/off switch.
* Server modules on one screen, each with its on/off switch.
* The rules about what a switch means live in ModuleSwitchboard.
*/
class ModuleController extends Controller
{
public function __construct(private ModuleSwitchboard $switchboard) {}

public function index()
{
return view('admin.config.modules', [
'groups' => $this->switchboard->rows(),
'pageIcon' => 'fa-cubes',
]);
}

public function serverModules()
{
$groups = $this->switchboard->rows();

return view('admin.config.modules', [
'groups' => ['server' => $groups['server']],
'groups' => ['server' => $this->switchboard->rowsFor('server')],
'pageTitle' => __('admin.modules.type_server'),
'pageDescription' => __('admin.modules.server_description'),
'pageIcon' => 'fa-server',
Expand Down
56 changes: 35 additions & 21 deletions app/Services/Module/ModuleSwitchboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use Illuminate\Support\Collection;

/**
* Every installed module on one screen, each with its on/off switch.
* Installed modules and their on/off switches for the pages that show them.
*
* NO NEW SWITCH WHERE ONE ALREADY EXISTS. Gateways, registrars and addons
* each had an on/off setting long before this screen, read by the code that
* each had an on/off setting long before this class, read by the code that
* matters (checkout, domain search, the addon loader). This class reads and
* writes exactly those settings, so flipping a gateway here and on the
* gateways page is the same act. Only server and SSL modules had no switch;
Expand Down Expand Up @@ -43,33 +43,47 @@ public function rows(): Collection
{
$rows = collect();

foreach (['server', 'gateway', 'registrar', 'ssl'] as $type) {
$rows[$type] = collect(array_keys($this->registry->classesOf($type)))
->map(fn (string $key) => (object) [
'type' => $type,
'key' => $key,
'label' => $this->label($type, $key),
'third_party' => $this->registry->isDiscovered($type, $key),
'active' => $this->isActive($type, $key),
'in_use' => $this->usage($type, $key),
foreach (self::TYPES as $type) {
$rows[$type] = $this->rowsFor($type);
}

return $rows;
}

/**
* @return Collection<int, object>
*/
public function rowsFor(string $type): Collection
{
if (! in_array($type, self::TYPES, true)) {
return collect();
}

if ($type === 'addon') {
return $this->addons->all()
->map(fn ($addon, $key) => (object) [
'type' => 'addon',
'key' => (string) $key,
'label' => $addon->getDisplayName(),
'third_party' => false,
'active' => $this->addons->isActive((string) $key),
'in_use' => 0,
])
->sortBy(fn ($row) => mb_strtolower($row->label))
->values();
}

$rows['addon'] = $this->addons->all()
->map(fn ($addon, $key) => (object) [
'type' => 'addon',
'key' => (string) $key,
'label' => $addon->getDisplayName(),
'third_party' => false,
'active' => $this->addons->isActive((string) $key),
'in_use' => 0,
return collect(array_keys($this->registry->classesOf($type)))
->map(fn (string $key) => (object) [
'type' => $type,
'key' => $key,
'label' => $this->label($type, $key),
'third_party' => $this->registry->isDiscovered($type, $key),
'active' => $this->isActive($type, $key),
'in_use' => $this->usage($type, $key),
])
->sortBy(fn ($row) => mb_strtolower($row->label))
->values();

return $rows;
}

public function exists(string $type, string $key): bool
Expand Down
1 change: 0 additions & 1 deletion lang/de/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,6 @@
'invoices.charge_now_refused' => 'Nicht belastet (:reason).',
'invoices.charge_now_log' => 'Karte jetzt belasten: :outcome',
'dashboard.live_servers' => 'Live-Server',
'nav.modules' => 'Module',
'live_servers.title' => 'Live-Server',
'live_servers.description' => 'Ihre Panelica-Server. „Anmelden“ öffnet das Control Panel des Servers in einem neuen Tab – angemeldet als Inhaber des API-Schlüssels des Servers.',
'live_servers.none' => 'Noch keine Panelica-Server.',
Expand Down
1 change: 0 additions & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3723,7 +3723,6 @@
'invoices.charge_now_refused' => 'Not charged (:reason).',
'invoices.charge_now_log' => 'Charge card now: :outcome',
'dashboard.live_servers' => 'Live Servers',
'nav.modules' => 'Modules',
'live_servers.title' => 'Live Servers',
'live_servers.description' => 'Your Panelica servers. Log in opens the server\'s control panel in a new tab, signed in as the owner of the server\'s API key.',
'live_servers.none' => 'No Panelica servers yet.',
Expand Down
1 change: 0 additions & 1 deletion lang/es/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3463,7 +3463,6 @@
'invoices.charge_now_refused' => 'No cobrado (:reason).',
'invoices.charge_now_log' => 'Cargar tarjeta ahora: :outcome',
'dashboard.live_servers' => 'Servidores en vivo',
'nav.modules' => 'Módulos',
'live_servers.title' => 'Servidores en vivo',
'live_servers.description' => 'Sus servidores Panelica. «Iniciar sesión» abre el panel de control del servidor en una pestaña nueva con la sesión iniciada como propietario de la clave API del servidor.',
'live_servers.none' => 'Aún no hay servidores de Panelica.',
Expand Down
1 change: 0 additions & 1 deletion lang/it/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3487,7 +3487,6 @@
'invoices.charge_now_refused' => 'Non addebitata (:reason).',
'invoices.charge_now_log' => 'Addebita la carta ora: :outcome',
'dashboard.live_servers' => 'Server attivi',
'nav.modules' => 'Moduli',
'live_servers.title' => 'Server attivi',
'live_servers.description' => 'I tuoi server Panelica. Accedi apre il pannello di controllo del server in una nuova scheda, autenticato come il proprietario della chiave API del server.',
'live_servers.none' => 'Nessun server Panelica finora.',
Expand Down
1 change: 0 additions & 1 deletion lang/pl/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3721,7 +3721,6 @@
'invoices.charge_now_refused' => 'Nie obciążono (:reason).',
'invoices.charge_now_log' => 'Obciąż kartę teraz: :outcome',
'dashboard.live_servers' => 'Serwery na żywo',
'nav.modules' => 'Moduły',
'live_servers.title' => 'Serwery na żywo',
'live_servers.description' => 'Twoje serwery Panelica. Zaloguj otwiera panel serwera w nowej karcie, jako właściciel klucza API serwera.',
'live_servers.none' => 'Brak serwerów Panelica.',
Expand Down
1 change: 0 additions & 1 deletion lang/ru/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3391,7 +3391,6 @@
'invoices.charge_now_refused' => 'Не списано (:reason).',
'invoices.charge_now_log' => 'Списать с карты сейчас: :outcome',
'dashboard.live_servers' => 'Рабочие серверы',
'nav.modules' => 'Модули',
'live_servers.title' => 'Рабочие серверы',
'live_servers.description' => 'Ваши серверы Panelica. «Войти» открывает панель управления сервером в новой вкладке от имени владельца API-ключа сервера.',
'live_servers.none' => 'Серверов Panelica пока нет.',
Expand Down
1 change: 0 additions & 1 deletion lang/tr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3721,7 +3721,6 @@
'invoices.charge_now_refused' => 'Çekilmedi (:reason).',
'invoices.charge_now_log' => 'Kartı şimdi çek: :outcome',
'dashboard.live_servers' => 'Canlı Sunucular',
'nav.modules' => 'Modüller',
'live_servers.title' => 'Canlı Sunucular',
'live_servers.description' => 'Panelica sunucularınız. Giriş, sunucunun kontrol panelini yeni sekmede açar; sunucunun API anahtarının sahibi olarak oturum açılır.',
'live_servers.none' => 'Henüz Panelica sunucusu yok.',
Expand Down
1 change: 0 additions & 1 deletion lang/uk/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3408,7 +3408,6 @@
'invoices.charge_now_refused' => 'Не списано (:reason).',
'invoices.charge_now_log' => 'Списати з картки зараз: :outcome',
'dashboard.live_servers' => 'Активні сервери',
'nav.modules' => 'Модулі',
'live_servers.title' => 'Активні сервери',
'live_servers.description' => 'Ваші сервери Panelica. Кнопка входу відкриває панель керування сервером у новій вкладці від імені власника серверного API-ключа.',
'live_servers.none' => 'Серверів Panelica ще немає.',
Expand Down
1 change: 0 additions & 1 deletion lang/zh/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3721,7 +3721,6 @@
'invoices.charge_now_refused' => '未扣款(:reason)。',
'invoices.charge_now_log' => '立即扣款::outcome',
'dashboard.live_servers' => '在线服务器',
'nav.modules' => '模块',
'live_servers.title' => '在线服务器',
'live_servers.description' => '您的 Panelica 服务器。点击登录将在新标签页中打开服务器控制面板,并以该服务器 API 密钥所有者的身份登录。',
'live_servers.none' => '尚无 Panelica 服务器。',
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/config/addon-modules.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<span style="font-size:11px;color:var(--pn-muted);font-weight:400;">v{{ $addon->getVersion() }}</span>
</span>
<span class="badge {{ ($statuses[$name] ?? false) ? 'badge-active' : 'badge-cancelled' }}">
{{ ($statuses[$name] ?? false) ? __('admin.addon_modules.status_active') : __('admin.addon_modules.status_inactive') }}
{{ ($statuses[$name] ?? false) ? __('common.status.active') : __('common.status.inactive') }}
</span>
</summary>
<div style="padding:0 16px 16px;border-top:1px solid #e5e7eb;">
Expand Down
Loading
Loading