Added option to make Status-Page public available. Including Label for

de_DE and en_US language.

Added the needed Database entries to psm/Util/Install/Installer.php
upgrade370() function - but dunno if it's working this way.

Attention: user_id is reserved for anonymous user
This commit is contained in:
V3ndetta 2020-10-21 12:57:47 +02:00
parent aad1a1eda7
commit 64be484635
No known key found for this signature in database
GPG Key ID: 08718915BE866719
9 changed files with 87 additions and 6 deletions

View File

@ -275,6 +275,7 @@ $sm_lang = array(
Protokollierungsdaten im System. Geben Sie die Ziffer \'0\' ein, um die
automatische Bereinigung/Löschung zu deaktivieren.',
'log_retention_days' => 'Tage',
'public_status' => 'Status Seite öffentlich machen?',
),
'notifications' => array(
'off_sms' => 'Dienst/Webseite \'%LABEL%\' ist offline: ip=%IP%, port=%PORT%. Fehler=%ERROR%',
@ -322,6 +323,7 @@ $sm_lang = array(
Ihr Passwort zurücksetzen können.',
'success_password_reset' => 'Ihr Passwort wurde erfolgreich zurückgesetzt. Bitte versuchen Sie, sich erneut
anzumelden.',
'anonymous_username' => 'Anonymous',
),
'error' => array(
'401_unauthorized' => 'Nicht autorisiert',

View File

@ -418,6 +418,7 @@ $sm_lang = array(
'log_retention_days' => 'days',
'user_agent' => 'User Agent',
'user_agent_key_note' => 'Custom user agent used by monitor within communication with external services.',
'public_status' => 'Make Status-Page public?'
),
'notifications' => array(
'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%',
@ -518,6 +519,7 @@ $sm_lang = array(
'error_reset_invalid_link' => 'The reset link you provided is invalid.',
'success_password_forgot' => 'An email has been sent to you with information how to reset your password.',
'success_password_reset' => 'Your password has been reset successfully. Please login.',
'anonymous_username' => 'Anonymous',
),
'error' => array(
'401_unauthorized' => 'Unauthorized',

View File

@ -278,8 +278,10 @@ abstract class AbstractController implements ControllerInterface
'label_help' => psm_get_lang('menu', 'help'),
'label_profile' => psm_get_lang('users', 'profile'),
'label_logout' => psm_get_lang('login', 'logout'),
'label_login' => psm_get_lang('login', 'login'),
'url_profile' => psm_build_url(array('mod' => 'user_profile')),
'url_logout' => psm_build_url(array('logout' => 1)),
'url_login' => psm_build_url(array('mod' => 'user_profile')),
'label_current' => psm_get_lang('system', 'current'),
);
@ -311,6 +313,11 @@ abstract class AbstractController implements ControllerInterface
psm_get_lang('login', 'welcome_usermenu')
);
}
else {
$tpl_data['label_usermenu'] = psm_get_lang('login','anonymous_username');
}
$tpl_data['ulvl'] = $ulvl;
return $this->twig->render('main/menu.tpl.html', $tpl_data);
}

View File

@ -58,6 +58,7 @@ class ConfigController extends AbstractController
'log_jabber',
'show_update',
'combine_notifications',
'public_status',
);
/**
@ -641,6 +642,7 @@ class ConfigController extends AbstractController
'label_user_agent' => psm_get_lang('config', 'user_agent'),
'label_user_agent_key_note' => psm_get_lang('config', 'user_agent_key_note'),
'label_site_title' => psm_get_lang('config', 'site_title'),
'label_public_status' => psm_get_lang('config','public_status'),
);
}
}

View File

@ -46,12 +46,24 @@ abstract class AbstractServerController extends AbstractController
$sql_where = '';
if ($this->getUser()->getUserLevel() > PSM_USER_ADMIN) {
// restrict by user_id
$sql_join = "JOIN `" . PSM_DB_PREFIX . "users_servers` AS `us` ON (
`us`.`user_id`={$this->getUser()->getUserId()}
if ($this->getUser()->getUserLevel() == PSM_USER_ANONYMOUS && psm_get_conf(public_status) == true) {
// restrict by user_id of anonymous User - if configured to do so
$sql_join = "JOIN `" . PSM_DB_PREFIX . "users_servers` AS `us` ON (
`us`.`user_id`= 0
AND `us`.`server_id`=`s`.`server_id`
)";
}
else {
// restrict by user_id
$sql_join = "JOIN `" . PSM_DB_PREFIX . "users_servers` AS `us` ON (
`us`.`user_id`={$this->getUser()->getUserId()}
AND `us`.`server_id`=`s`.`server_id`
)";
}
}
if ($server_id !== null) {
$server_id = intval($server_id);
$sql_where = "WHERE `s`.`server_id`={$server_id} ";

View File

@ -43,6 +43,12 @@ class StatusController extends AbstractServerController
$this->setCSRFKey('status');
$this->setActions(array('index', 'saveLayout'), 'index');
/**
* Check for configuration of public available Status-Page
*/
if (psm_get_conf('public_status'))
$this->setMinUserLevelRequired(PSM_USER_ANONYMOUS,array('index'));
}
/**
@ -92,10 +98,19 @@ class StatusController extends AbstractServerController
if ($server['last_offline_nice'] != psm_get_lang('system', 'never')) {
$server['last_offline_duration_nice'] = "(" . $server['last_offline_duration'] . ")";
}
$server['url_view'] = psm_build_url(
array('mod' => 'server', 'action' => 'view', 'id' => $server['server_id'], 'back_to' => 'server_status')
);
/**
* Link Server-Title with detailed Status-Page only when User is NOT Anonymous
*/
if ($this->getUser()->getUserLevel() != PSM_USER_ANONYMOUS) {
$server['url_view'] = psm_build_url(
array('mod' => 'server', 'action' => 'view', 'id' => $server['server_id'], 'back_to' => 'server_status')
);
}
else
{
$server['url_view'] = psm_build_url();
}
if ($server['status'] == "off") {
$layout_data['servers_offline'][] = $server;
} elseif ($server['warning_threshold_counter'] > 0) {

View File

@ -369,6 +369,9 @@ class Installer
if (version_compare($version_from, '3.6.0', '<')) {
$this->upgrade360();
}
if (version_compare($version_from, '3.7.0', '<')) {
$this->upgrade370();
}
psm_update_conf('version', $version_to);
}
@ -756,4 +759,22 @@ class Installer
ADD `discord` ENUM( 'yes','no' ) NOT NULL DEFAULT 'yes' AFTER `sms`;";
$this->execSQL($queries);
}
/**
* Upgrade for v3.7.0 release
* Added support for public Status-Pages
*/
protected function upgrade370()
{
$queries = array();
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('public_status', '0')";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users`
(`user_id`, `user_name`, `password`, `password_reset_hash`, `password_reset_timestamp`, `rememberme_token`, `level`, `name`, `mobile`, `discord`, `pushover_key`, `pushover_device`, `webhook_url`, `webhook_json`, `telegram_id`, `jabber`, `email`)
VALUES
('0', 'anonymous', 'NO_PASSWORD_REQUIRED', NULL, NULL, NULL, '30', '', '', '', '', '', '', '{\"text\":\"servermon: #message\"}', '', '', '')";
$queries[] = "UPDATE `" . PSM_DB_PREFIX . "users` SET `user_id` = '0' WHERE `monitor_users`.`user_id` = 3";
$this->execSQL($queries);
}
}

View File

@ -19,6 +19,7 @@
</ul>
</noscript>
<noscript><div hidden></noscript>
{% if ulvl < 30 %}
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -35,4 +36,21 @@
</li>
-->
</ul>
{% else %}
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ label_usermenu }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ url_login|raw }}">{{ label_login }} </a>
</div>
</li>
<!--
<li class="nav-item">
<i class="text-white fas fa-universal-access fa-lg nav-link"></i>
</li>
-->
</ul>
{% endif %}
<noscript></div></noscript>

View File

@ -62,6 +62,8 @@
{{ macro.input_field("text", "password_encrypt_key", null, "password_encrypt_key", label_password_encrypt_key, password_encrypt_key, "cab03a766...", "40", "password_encrypt_key_help", label_password_encrypt_key_note) }}
<!-- Custom user agent -->
{{ macro.input_field("text", "user_agent", null, "user_agent", label_user_agent, user_agent, "Mozilla/5.0...", "255", "user_agent_key_help", label_user_agent_key_note) }}
<!-- Public Status-Page -->
{{ macro.input_checkbox("public_status","public_status[]", label_public_status, public_status_checked) }}
</fieldset>
<!-- Notification settings -->
<fieldset>