From e30ad7ef9b643ebce7cf55de841a353a5af77ade Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 19 Oct 2022 10:16:17 +0200 Subject: [PATCH] added shortcut-add-action link to sidebar menu Signed-off-by: Michael Kaufmann --- admin_customers.php | 2 +- admin_domains.php | 3 +- customer_domains.php | 3 +- customer_email.php | 3 +- customer_ftp.php | 3 +- customer_mysql.php | 3 +- lib/Froxlor/Api/Commands/MysqlServer.php | 2 +- lib/Froxlor/CurrentUser.php | 29 +++++++++++++++ lib/Froxlor/UI/HTML.php | 3 +- lib/navigation/00.froxlor.main.php | 47 +++++++++++++++--------- templates/Froxlor/sidebar.html.twig | 9 ++++- 11 files changed, 79 insertions(+), 28 deletions(-) diff --git a/admin_customers.php b/admin_customers.php index 284518c5..0dfabb04 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -60,7 +60,7 @@ if (($page == 'customers' || $page == 'overview') && $userinfo['customers'] != ' } $actions_links = false; - if ($userinfo['customers_used'] < $userinfo['customers'] || $userinfo['customers'] == '-1') { + if (CurrentUser::canAddResource('customers')) { $actions_links = [ [ 'href' => $linker->getLink(['section' => 'customers', 'page' => $page, 'action' => 'add']), diff --git a/admin_domains.php b/admin_domains.php index 3ce65138..bec95378 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -45,6 +45,7 @@ use Froxlor\UI\Request; use Froxlor\UI\Response; use Froxlor\User; use Froxlor\Validate\Validate; +use Froxlor\CurrentUser; $id = (int)Request::get('id'); @@ -63,7 +64,7 @@ if ($page == 'domains' || $page == 'overview') { } $actions_links = false; - if (($userinfo['domains_used'] < $userinfo['domains'] || $userinfo['domains'] == '-1') && $customerCollection->count() != 0) { + if (CurrentUser::canAddResource('domains')) { $actions_links = []; $actions_links[] = [ 'href' => $linker->getLink(['section' => 'domains', 'page' => $page, 'action' => 'add']), diff --git a/customer_domains.php b/customer_domains.php index db61d76d..07dfd09c 100644 --- a/customer_domains.php +++ b/customer_domains.php @@ -40,6 +40,7 @@ use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\UI\Response; use Froxlor\Validate\Validate; +use Froxlor\CurrentUser; // redirect if this customer page is hidden via settings if (Settings::IsInList('panel.customer_hide_options', 'domains')) { @@ -64,7 +65,7 @@ if ($page == 'overview' || $page == 'domains') { } $actions_links = false; - if (($userinfo['subdomains_used'] < $userinfo['subdomains'] || $userinfo['subdomains'] == '-1') && $parentDomainCollection->count() != 0) { + if (CurrentUser::canAddResource('subdomains')) { $actions_links = [ [ 'href' => $linker->getLink(['section' => 'domains', 'page' => 'domains', 'action' => 'add']), diff --git a/customer_email.php b/customer_email.php index 7ea5cc61..e183b7fc 100644 --- a/customer_email.php +++ b/customer_email.php @@ -40,6 +40,7 @@ use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\UI\Response; use Froxlor\Validate\Check; +use Froxlor\CurrentUser; // redirect if this customer page is hidden via settings if (Settings::IsInList('panel.customer_hide_options', 'email')) { @@ -71,7 +72,7 @@ if ($page == 'overview' || $page == 'emails') { $emaildomains_count = $result2['emaildomains']; $actions_links = false; - if (($userinfo['emails_used'] < $userinfo['emails'] || $userinfo['emails'] == '-1') && $emaildomains_count != 0) { + if (CurrentUser::canAddResource('emails')) { $actions_links = [ [ 'href' => $linker->getLink(['section' => 'email', 'page' => $page, 'action' => 'add']), diff --git a/customer_ftp.php b/customer_ftp.php index 8aeaaa69..9996b4a3 100644 --- a/customer_ftp.php +++ b/customer_ftp.php @@ -37,6 +37,7 @@ use Froxlor\UI\Listing; use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\UI\Response; +use Froxlor\CurrentUser; // redirect if this customer page is hidden via settings if (Settings::IsInList('panel.customer_hide_options', 'ftp')) { @@ -57,7 +58,7 @@ if ($page == 'overview' || $page == 'accounts') { } $actions_links = false; - if ($userinfo['ftps_used'] < $userinfo['ftps'] || $userinfo['ftps'] == '-1') { + if (CurrentUser::canAddResource('ftps')) { $actions_links = [ [ 'href' => $linker->getLink(['section' => 'ftp', 'page' => 'accounts', 'action' => 'add']), diff --git a/customer_mysql.php b/customer_mysql.php index 3a00ce2c..d80f819d 100644 --- a/customer_mysql.php +++ b/customer_mysql.php @@ -37,6 +37,7 @@ use Froxlor\UI\Listing; use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\UI\Response; +use Froxlor\CurrentUser; // redirect if this customer page is hidden via settings if (Settings::IsInList('panel.customer_hide_options', 'mysql')) { @@ -66,7 +67,7 @@ if ($page == 'overview' || $page == 'mysqls') { } $actions_links = false; - if ($userinfo['mysqls_used'] < $userinfo['mysqls'] || $userinfo['mysqls'] == '-1') { + if (CurrentUser::canAddResource('mysqls')) { $actions_links = [ [ 'href' => $linker->getLink(['section' => 'mysql', 'page' => 'mysqls', 'action' => 'add']), diff --git a/lib/Froxlor/Api/Commands/MysqlServer.php b/lib/Froxlor/Api/Commands/MysqlServer.php index 72ee0f92..6ae319d1 100644 --- a/lib/Froxlor/Api/Commands/MysqlServer.php +++ b/lib/Froxlor/Api/Commands/MysqlServer.php @@ -45,7 +45,7 @@ class MysqlServer extends ApiCommand implements ResourceEntity */ private function validateAccess() { - if ($this->isAdmin() == false || ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 0)) { + if ($this->isAdmin() == false || ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 0)) { throw new Exception("You cannot access this resource", 405); } } diff --git a/lib/Froxlor/CurrentUser.php b/lib/Froxlor/CurrentUser.php index eda5b732..af635727 100644 --- a/lib/Froxlor/CurrentUser.php +++ b/lib/Froxlor/CurrentUser.php @@ -26,6 +26,9 @@ namespace Froxlor; use Froxlor\Database\Database; +use Froxlor\UI\Collection; +use Froxlor\Api\Commands\Customers; +use Froxlor\Api\Commands\SubDomains; /** * Class to manage the current user / session @@ -126,4 +129,30 @@ class CurrentUser { $_SESSION['userinfo'] = $data; } + + public static function canAddResource(string $resource): bool + { + $addition = true; + // special cases + if ($resource == 'emails') { + $result_stmt = Database::prepare(" + SELECT COUNT(`id`) as emaildomains + FROM `" . TABLE_PANEL_DOMAINS . "` + WHERE `customerid`= :cid AND `isemaildomain` = '1' + "); + $result = Database::pexecute_first($result_stmt, [ + "cid" => $_SESSION['userinfo']['customerid'] + ]); + $addition = $result['emaildomains'] != 0; + } elseif ($resource == 'subdomains') { + $parentDomainCollection = (new Collection(SubDomains::class, $_SESSION['userinfo'], ['sql_search' => ['d.parentdomainid' => 0]])); + $addition = $parentDomainCollection != 0; + } elseif ($resource == 'domains') { + $customerCollection = (new Collection(Customers::class, $_SESSION['userinfo'])); + $addition = $customerCollection != 0; + } + + return ($_SESSION['userinfo'][$resource.'_used'] < $_SESSION['userinfo'][$resource] || $_SESSION['userinfo'][$resource] == '-1') && $addition; + } + } diff --git a/lib/Froxlor/UI/HTML.php b/lib/Froxlor/UI/HTML.php index 37f49956..703b80e4 100644 --- a/lib/Froxlor/UI/HTML.php +++ b/lib/Froxlor/UI/HTML.php @@ -87,7 +87,8 @@ class HTML 'target' => $target, 'active' => $active, 'label' => $navlabel, - 'icon' => $icon + 'icon' => $icon, + 'add_shortlink' => $element['add_shortlink'] ?? null ]; } } diff --git a/lib/navigation/00.froxlor.main.php b/lib/navigation/00.froxlor.main.php index 01abe864..1fc00df9 100644 --- a/lib/navigation/00.froxlor.main.php +++ b/lib/navigation/00.froxlor.main.php @@ -24,6 +24,7 @@ */ use Froxlor\Settings; +use Froxlor\CurrentUser; return [ 'customer' => [ @@ -36,12 +37,8 @@ return [ [ 'url' => 'customer_email.php?page=emails', 'label' => lng('menue.email.emails'), - 'required_resources' => 'emails' - ], - [ - 'url' => 'customer_email.php?page=emails&action=add', - 'label' => lng('emails.emails_add'), - 'required_resources' => 'emails' + 'required_resources' => 'emails', + 'add_shortlink' => CurrentUser::canAddResource('emails') ? 'customer_email.php?page=emails&action=add' : null, ], [ 'url' => Settings::Get('panel.webmail_url'), @@ -61,7 +58,8 @@ return [ [ 'url' => 'customer_mysql.php?page=mysqls', 'label' => lng('menue.mysql.databases'), - 'required_resources' => 'mysqls' + 'required_resources' => 'mysqls', + 'add_shortlink' => CurrentUser::canAddResource('mysqls')? 'customer_mysql.php?page=mysqls&action=add' : null, ], [ 'url' => Settings::Get('panel.phpmyadmin_url'), @@ -80,7 +78,8 @@ return [ 'elements' => [ [ 'url' => 'customer_domains.php?page=domains', - 'label' => lng('menue.domains.settings') + 'label' => lng('menue.domains.settings'), + 'add_shortlink' => CurrentUser::canAddResource('subdomains') ? 'customer_domains.php?page=domains&action=add' : null, ], [ 'url' => 'customer_domains.php?page=sslcertificates', @@ -96,7 +95,8 @@ return [ 'elements' => [ [ 'url' => 'customer_ftp.php?page=accounts', - 'label' => lng('menue.ftp.accounts') + 'label' => lng('menue.ftp.accounts'), + 'add_shortlink' => CurrentUser::canAddResource('ftps') ? 'customer_ftp.php?page=accounts&action=add' : null, ], [ 'url' => Settings::Get('panel.webftp_url'), @@ -115,12 +115,14 @@ return [ [ 'url' => 'customer_extras.php?page=htpasswds', 'label' => lng('menue.extras.directoryprotection'), - 'show_element' => (!Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) + 'show_element' => (!Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')), + 'add_shortlink' => 'customer_extras.php?page=htpasswds&action=add', ], [ 'url' => 'customer_extras.php?page=htaccess', 'label' => lng('menue.extras.pathoptions'), - 'show_element' => (!Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) + 'show_element' => (!Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')), + 'add_shortlink' => 'customer_extras.php?page=htaccess&action=add', ], [ 'url' => 'customer_logger.php?page=log', @@ -160,17 +162,20 @@ return [ [ 'url' => 'admin_customers.php?page=customers', 'label' => lng('admin.customers'), - 'required_resources' => 'customers' + 'required_resources' => 'customers', + 'add_shortlink' => CurrentUser::canAddResource('customers') ? 'admin_customers.php?page=customers&action=add' : null, ], [ 'url' => 'admin_admins.php?page=admins', 'label' => lng('admin.admins'), - 'required_resources' => 'change_serversettings' + 'required_resources' => 'change_serversettings', + 'add_shortlink' => 'admin_admins.php?page=admins&action=add' ], [ 'url' => 'admin_domains.php?page=domains', 'label' => lng('admin.domains'), - 'required_resources' => 'domains' + 'required_resources' => 'domains', + 'add_shortlink' => CurrentUser::canAddResource('domains') ? 'admin_domains.php?page=domains&action=add' : null, ], [ 'url' => 'admin_domains.php?page=sslcertificates', @@ -180,16 +185,20 @@ return [ [ 'url' => 'admin_ipsandports.php?page=ipsandports', 'label' => lng('admin.ipsandports.ipsandports'), - 'required_resources' => 'change_serversettings' + 'required_resources' => 'change_serversettings', + 'add_shortlink' => 'admin_ipsandports.php?page=ipsandports&action=add' ], [ 'url' => 'admin_mysqlserver.php?page=mysqlserver', 'label' => lng('admin.mysqlserver.mysqlserver'), + 'required_resources' => 'change_serversettings', + 'add_shortlink' => 'admin_mysqlserver.php?page=mysqlserver&action=add' ], [ 'url' => 'admin_plans.php?page=overview', 'label' => lng('admin.plans.plans'), - 'required_resources' => 'customers' + 'required_resources' => 'customers', + 'add_shortlink' => 'admin_plans.php?page=overview&action=add' ], [ 'url' => 'admin_settings.php?page=updatecounters', @@ -262,12 +271,14 @@ return [ [ 'url' => 'admin_phpsettings.php?page=overview', 'label' => lng('menue.phpsettings.maintitle'), - 'show_element' => (Settings::Get('system.mod_fcgid') == true || Settings::Get('phpfpm.enabled') == true) + 'show_element' => (Settings::Get('system.mod_fcgid') == true || Settings::Get('phpfpm.enabled') == true), + 'add_shortlink' => 'admin_phpsettings.php?page=overview&action=add' ], [ 'url' => 'admin_phpsettings.php?page=fpmdaemons', 'label' => lng('menue.phpsettings.fpmdaemons'), - 'show_element' => Settings::Get('phpfpm.enabled') == true + 'show_element' => Settings::Get('phpfpm.enabled') == true, + 'add_shortlink' => 'admin_phpsettings.php?page=fpmdaemons&action=add' ], [ 'url' => 'admin_settings.php?page=phpinfo', diff --git a/templates/Froxlor/sidebar.html.twig b/templates/Froxlor/sidebar.html.twig index 255ebc9c..6eec4bc9 100644 --- a/templates/Froxlor/sidebar.html.twig +++ b/templates/Froxlor/sidebar.html.twig @@ -12,8 +12,13 @@