From 0f263407a5bda8921c4fbb2b9ab15fa911439775 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 12 Oct 2020 10:32:25 -0500 Subject: [PATCH 1/8] make redirect conditional on previous view --- web/includes/actions/logout.php | 2 +- web/includes/actions/user.php | 4 ---- web/index.php | 3 +++ web/skins/classic/views/user.php | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/includes/actions/logout.php b/web/includes/actions/logout.php index a80511aa7..116ae278c 100644 --- a/web/includes/actions/logout.php +++ b/web/includes/actions/logout.php @@ -23,7 +23,7 @@ if ( $action == 'logout' ) { userLogout(); $view = 'login'; } elseif ( $action == 'config' ) { - $redirect = '?view=user&uid='.$user['Id']; + $redirect = '?view=user&prev=console&uid='.$user['Id']; } ?> diff --git a/web/includes/actions/user.php b/web/includes/actions/user.php index 496b6b214..372108355 100644 --- a/web/includes/actions/user.php +++ b/web/includes/actions/user.php @@ -66,9 +66,7 @@ if ( $action == 'Save' ) { } else { dbQuery('INSERT INTO Users SET '.implode(', ', $changes)); } - $refreshParent = true; } # end if changes - $redirect = '?view=options&tab=users'; } else if ( ZM_USER_SELF_EDIT and ( $_REQUEST['uid'] == $user['Id'] ) ) { $uid = $user['Id']; @@ -99,9 +97,7 @@ if ( $action == 'Save' ) { zm_session_start(); generateAuthHash(ZM_AUTH_HASH_IPS, true); session_write_close(); - $refreshParent = true; } - $redirect = '?view=options&tab=users'; } } // end if $action == user ?> diff --git a/web/index.php b/web/index.php index 3d6f24fc7..46140a1a3 100644 --- a/web/index.php +++ b/web/index.php @@ -183,6 +183,9 @@ $user = null; if ( isset($_REQUEST['view']) ) $view = detaintPath($_REQUEST['view']); +if ( isset($_REQUEST['redirect']) ) + $redirect = '?view='.detaintPath($_REQUEST['redirect']); + # Add CSP Headers $cspNonce = bin2hex(zm_random_bytes(16)); diff --git a/web/skins/classic/views/user.php b/web/skins/classic/views/user.php index 06dde73a1..8d795809a 100644 --- a/web/skins/classic/views/user.php +++ b/web/skins/classic/views/user.php @@ -69,6 +69,7 @@ xhtmlHeaders(__FILE__, translate('User').' - '.$newUser->Username());
+ From ed5f6b262573ebb9c7163b0a98d90e760061471c Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 12 Oct 2020 12:16:52 -0500 Subject: [PATCH 2/8] convert shutdown popup to modal --- web/ajax/modals/shutdown.php | 64 ++++++++++++++++++++++++ web/skins/classic/includes/functions.php | 6 +-- web/skins/classic/js/skin.js | 15 ++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 web/ajax/modals/shutdown.php diff --git a/web/ajax/modals/shutdown.php b/web/ajax/modals/shutdown.php new file mode 100644 index 000000000..0cfea0111 --- /dev/null +++ b/web/ajax/modals/shutdown.php @@ -0,0 +1,64 @@ +'.implode('
', $output).'

'.PHP_EOL; +} + +$cancel_str = ''; +if ( isset($_POST['when']) and ($_POST['when'] != 'NOW') and ($action != 'cancel') ) { + $cancel_str = '

You may cancel this shutdown by clicking '.translate('Cancel').'

'.PHP_EOL; +} + +$cancel_btn = ''; +if ( isset($_POST['when']) and ($_POST['when'] != 'NOW') and ($action != 'cancel') ) { + $cancel_btn = ''.PHP_EOL; +} + +?> + diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index dc97e295a..70bb8d163 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -756,9 +756,9 @@ function getStatusBtnHTML($status) { //$result .= ''.PHP_EOL; if ( ZM_SYSTEM_SHUTDOWN ) { - $result .= ''.PHP_EOL; + $result .= ''.PHP_EOL; } } else if ( canView('System') ) { diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index a7781b961..df2d45a7e 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -956,3 +956,18 @@ function exportEvent() { .fail(logAjaxFail); $j('#exportProgress').removeClass( 'invisible' ); } + +// Load the Function modal on page load +function getShutdownModal() { + $j.getJSON(thisUrl + '?request=modal&modal=shutdown') + .done(function(data) { + if ( $j('#shutdownModal').length ) { + $j('#shutdownModal').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + // Manage the Shutdown modal + $j('#shutdownModal').modal('show'); + }) + .fail(logAjaxFail); +} From 1db31ba574e16c2bc4e5d879be0d3909d063347f Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 12 Oct 2020 12:20:21 -0500 Subject: [PATCH 3/8] remove makePopupLink function. Use makeLink instead --- web/includes/functions.php | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/web/includes/functions.php b/web/includes/functions.php index 9950c4266..f42a1029d 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -424,6 +424,9 @@ function deleteEvent($event) { } # CAN EDIT } +/** + * $label must be already escaped. It can't be done here since it sometimes contains HTML tags. + */ function makeLink($url, $label, $condition=1, $options='') { $string = ''; if ( $condition ) { @@ -443,32 +446,6 @@ function makeHelpLink($ohndx) { return $string; } -/** - * $label must be already escaped. It can't be done here since it sometimes contains HTML tags. - */ -function makePopupLink($url, $winName, $winSize, $label, $condition=1, $options='') { - // Avoid double-encoding since some consumers incorrectly pass a pre-escaped URL. - $string = ''; - } else { - $string .= '>'; - } - $string .= $label; - $string .= ''; - return $string; -} - function makeButton($url, $buttonValue, $condition=1, $options='') { $string = ' - + + diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index faef50c4f..c6171a47a 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -830,6 +830,16 @@ function getShutdownModal() { } // Manage the Shutdown modal $j('#shutdownModal').modal('show'); + // Redirect to the current view after the form is submitted - avoids a blank screen + $j('#shutdownForm').append(''); + $j('#restartBtn').click(function(evt) { + evt.preventDefault(); + $j('#shutdownForm').submit(); + }); + $j('#shutdownBtn').click(function(evt) { + evt.preventDefault(); + $j('#shutdownForm').submit(); + }); }) .fail(logAjaxFail); } diff --git a/web/skins/classic/views/shutdown.php b/web/skins/classic/views/shutdown.php deleted file mode 100644 index 25d5d3d34..000000000 --- a/web/skins/classic/views/shutdown.php +++ /dev/null @@ -1,79 +0,0 @@ - - -
- -
-ZM_PATH_SHUTDOWN is not defined. This is normally configured in /etc/zm/conf.d/01-system-paths.conf
'; - } else if ( !file_exists(ZM_PATH_SHUTDOWN) ) { - echo '
Path does not exist for ZM_PATH_SHUTDOWN. Current value is '.ZM_PATH_SHUTDOWN.'
'; - } else { -?> - -
- -'.implode('
', $output).'

'; - } - if ( isset($_POST['when']) and ($_POST['when'] != 'NOW') and ($action != 'cancel') ) { - echo '

You may cancel this shutdown by clicking '.translate('Cancel').'

'; - } -?> -

Warning

- This command will either shutdown or restart all ZoneMinder Servers
-

-

- - -

-
- - - - - - -
- - -
- - From 89c76ec140cb2ae8ed3e2e15665d9be264ac84ec Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 12 Oct 2020 14:52:57 -0500 Subject: [PATCH 8/8] no need to clare $view as global --- web/ajax/modals/shutdown.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/ajax/modals/shutdown.php b/web/ajax/modals/shutdown.php index 78c133a87..a461f0074 100644 --- a/web/ajax/modals/shutdown.php +++ b/web/ajax/modals/shutdown.php @@ -1,6 +1,4 @@