mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-23 03:27:02 +09:00
* feat: convert generic <select> elements to select2, with new class helpers
Replaces the jQuery UI selectmenu() catch-all in setSelectMenus() with select2,
applied uniformly to single and multi selects. Fewer than 10 options disables
the search box (minimumResultsForSearch: Infinity); 10 or more enables it -
same threshold now applied to the existing select2/select2-multi classes.
New layout.js class helper: select2-multi-count, a multi-select whose
selection summary reads "N Selected"/"All Selected" instead of one chip per
option (generic multiSelectAllText/multiSelectCountText strings in html.php,
overridable per-field via data-select-all-text/data-select-count-text/
data-select-all-value). graph_template_id (html_graph.php x2, html_tree.php)
now uses it in place of the jquery.multiselect-based .graph-multiselect,
preserving the existing "All Graph Templates"/"N Templates Selected" wording
and the -1 "all" sentinel behavior (reimplemented via select2:select/unselect
events in setSelectMenus()). The old .graph-multiselect jquery.multiselect
init block is left in place (now unreachable for core's own markup) in case
a plugin/theme still emits that class itself.
select2-callback is reworked from its previously-unused static-URL contract
into an ajax-backed replacement for the legacy .drop-callback/makeCallbacks()
autocomplete widget: data-action + data-variables build the query the same
way makeCallbacks() already did (pageName + action + live values of other
named fields + search term), and data-callback still names a JS function to
invoke on selection, matching form_callback()'s existing $on_change/$class
contract. form_callback() only renders the new <select> markup when its
$class parameter contains select2-callback (opt-in); every existing caller
that doesn't request it keeps the exact legacy output. html_graph.php's
host_id filter (both places) opts in. form_multi_dropdown() gained optional
$select_all_text/$select_count_text/$select_all_value parameters (all
additive/backward compatible) to plumb the graph_template_id wording through.
Compatibility: an org-wide code search found no plugin depending on the
.select2-callback/.graph-multiselect/.drop-callback/makeCallbacks() internals
being changed here (form_callback()'s default output is unchanged; the
.graph-multiselect jquery.multiselect init stays available). Everywhere else
in core that assumed the old jQuery UI selectmenu widget on elements now
covered by the broadened catch-all (disableField()/enableField(), the SNMP
security-level/protocol refresh logic, realtime.js's ds_step/graph_start/size
refresh, api_aggregate.php's field enable/disable, and html_reports.php's
branch_id/site_id/host_template_id handling) now branches on
.select2-hidden-accessible and uses select2's own refresh mechanism
(.trigger('change.select2')) instead, alongside the untouched legacy
selectmenu branch. #user_language and #i18n_default_language (which get
their own bespoke flag-icon languageselect widget) are excluded from the
catch-all, same as before.
The install wizard (install/install.js) has its own independent selectmenu
initialization and is intentionally left untouched.
* fix: use json_encode for select2 multi-select JS translation strings
* fix: make select2 initializers idempotent to stop duplicate widgets
applySkin() (which calls setSelectMenus(), where every select2/select2-multi/
select2-multi-count/select2-callback/catch-all initializer lives) runs more
than once per page view - once from cactiReady() on initial load, and again
from the generic AJAX-completion handler after any loadUrl()/postUrl() call,
which most list/filter pages already trigger during their own initial load.
Since calling .select2() a second time on an element that already has it
initialized creates a second, independent .select2-container next to the
first (select2 does not no-op or tear down the previous instance), every
affected <select> ended up rendering twice. Guard every initializer (plus
the graph_template_id -1 sentinel's event bindings, now namespaced and
unbound first) so a second setSelectMenus() pass skips elements already
marked .select2-hidden-accessible.
* fix: match select2 dropdown styling to the dark theme's real button look
border-radius was 4px (should be 6px, matching .ui-corner-all used
everywhere else); the selection box and dropdown panel were flat black
instead of this theme's actual .ui-button/.ui-widget-content backgrounds
(a subtle gradient-highlight image and a repeating texture image,
respectively). Also add a min-width and force the selected text/dropdown
option list to a single line instead of wrapping.
* fix: match select2 dropdown styling to each theme's real button look
Same fix as the earlier dark theme commit, applied to the remaining themes.
Every theme's select2 override previously used generic placeholder colors
(border-radius: 4px, background: #ffffff/#222222) that did not match that
theme's actual .ui-state-default/.ui-button/.ui-widget-content styling:
- cacti, carrot, hollyberry, raspberry, modern, paw: selection box now uses
the real button gradient-image background instead of flat white; dropdown
panel background already matched and is unchanged.
- sunrise: selection box background corrected to transparent (matching its
real button style) and the dropdown panel to its real black background,
instead of flat white for both.
- paper-plane: selection box background corrected to this theme's real
near-black button color instead of flat white.
- midwinter: switched from hardcoded generic colors to this theme's own
CSS custom properties (var(--border-color), var(--background-content),
var(--text-color-lighter), etc.), matching jquery-ui.midwinter.css.
border-radius is now 6px everywhere, matching .ui-corner-all. All themes
also gained a min-width and forced the selected text/dropdown option list
onto a single line instead of wrapping.
* fix: default select2's dropdownAutoWidth to true
The legacy jQuery UI selectmenu widget always sized its open dropdown to fit
the widest option, regardless of how narrow the closed control itself was.
Select2 defaults to matching the dropdown's width to the control's, so wide
option text was wrapping/truncating inside a narrow panel. Set this as a
global default once instead of touching every individual select2() call.
fix: destroy any existing select2 widget before re-initializing
applySkin() runs more than once per page view. The existing
:not(.select2-hidden-accessible) guards were meant to make re-running the
select2 initializers a no-op, but duplicate widgets were still being
reported. Explicitly tear down any select2 instance still attached right
before the initializers run again, so a widget can never end up duplicated
regardless of why applySkin() re-ran.
fix: don't select2-ify a select a plugin already widget-ified with selectmenu
Symmetric to the above: if a plugin's own script already deliberately
applied jQuery UI selectmenu to one of its selects (a few do, for their own
dynamically-created fields), skip converting it to select2 too.
* fix: convert the Device filter's legacy drop-callback widget to select2-callback
html_host_filter()'s autocomplete-enabled branch never got the select2
treatment applied to every other filter field - it still built its own
<input class='drop-callback'> wired up by the older makeCallbacks()/jQuery UI
autocomplete widget (styled with the legacy ui-selectmenu-button markup),
instead of opting into form_callback()'s newer select2-callback rendering like
everything else. Left side-by-side with now-modernized neighboring filters,
this old widget stood out as a leftover "old select". Switch it to the same
select2-callback select markup (data-action='ajax_hosts',
data-variables='site_id') the 1.2.x branch already uses, reusing the existing
ajax_hosts handlers and get_allowed_ajax_hosts()'s id/label response shape.
* fix: restore select2's gradient after closing without selecting, shrink its height, and drop the now-unneeded min-width
Every theme's active/open select2 style also matched .select2-container--focus,
but select2 leaves that class on the container after the dropdown closes (it
only drops --open), so the flat "active" background stuck around until the
next selection instead of the gradient returning right away. Scope the active
look to --open only.
Also shrink the single-select control from select2's stock 28px down to 24px
(and its arrow/rendered text to match) so it sits closer to the jQuery UI
button height it's replacing, and drop the min-width: 160px placeholder added
earlier to keep wide option text from being clipped - dropdownAutoWidth now
sizes the open dropdown to its content regardless of the closed control's
width, so the constraint is no longer needed.
* feat: add configurable select2 search threshold; drop autocomplete_enabled on develop
Add the same Select Search Minimum Rows setting added on 1.2.x, wiring it
through as the select2SearchRows JS global (include/global_session.php) and
replacing the hardcoded 10-option cutoff in every select2 initializer in
layout.js.
Remove Autocomplete Enabled entirely on develop: it only ever existed to let
the Classic theme opt out of the ajax-backed callback widgets, and Classic
doesn't exist as a develop theme. html_host_filter() and the Graph Items data
source field now always use the ajax-backed rendering (select2-callback /
drop_callback) unconditionally instead of branching on the removed setting.
* fix: keep the first 20 select2 results visible before scrolling
Select2's stock results list only guaranteed ~7-8 rows (200px) before
scrolling. Pin each result row to a consistent 24px (matching the shrunk
control height) and size the list's max-height to fit 20 of them before the
scrollbar kicks in.
* fix: repair layout.js corruption from the select2SearchRows commit, and exclude .multiselect from the catch-all
A faulty automated edit in 3cbc5a75 (feat: add configurable select2 search
threshold) matched the wrong text in 4 places and clobbered unrelated code
instead of the intended minimumResultsForSearch lines:
- deleted the fa-remove icon-class swap and mangled the `if (!theme)` check
- deleted setupPageTimeout()/CsrfMagic.end()
- left a stray bare `select2SearchRows` statement before the themeReady() call
- deleted the #password/#password_confirm delayKeyup wiring and broke the
showPage deferred's closing brace
Restored all four to their pre-corruption behavior and applied the intended
select2SearchRows threshold to the actual 4 select2 init blocks this time
(select2, select2-multi, select2-multi-count, and the generic catch-all).
While in there: the catch-all's '.multi-select'/'.graph-multiselect'
exclusions never matched anything real - form_multi_dropdown() always tags
its <select multiple> with plain 'multiselect', so every field using the
older jquery.multiselect plugin (Automation's day/month pickers, Consolidation
Functions, Selective Debug, etc.) was getting select2-ified on top of its own
dedicated multiselect() init. Exclude '.multiselect' instead.
* feat: checkbox-styled option rows for select2-multi-count dropdowns
Gets closer to the old jquery-multiselect look the count-style multi-selects
(Graph Templates, etc.) replaced: each option row in the open dropdown now
shows a checkbox-style indicator instead of plain text, driven by
[aria-selected] via CSS so it stays in sync with select2's own selection
state without any extra JS bookkeeping. closeOnSelect stays off so multiple
options can still be picked without the dropdown closing between clicks; the
closed control still shows the "N Selected"/"All Selected" summary text.
* fix: match multi-select control height to single-selects and add its missing dropdown arrow
select2's stock multi-select box only had a min-height with no matching
override, so it stayed taller than every single-select control next to it;
select2-multi-count fields never actually show real per-option chips (the
rendered area always gets replaced with "N Selected"/"All Selected" text),
so it's safe to tighten this to match.
select2 also only renders a .select2-selection__arrow element for
single-selects - multi-selects (Templates, Days of Week, etc.) got none by
default, so they looked handle-less next to every single-select control. Add
a matching CSS-only arrow via ::after (flips on select2-container--open,
same as the single-select's).
* fix: stop select2's multi-select inline search box from collapsing to near-zero width
Select2 sizes the inline search input it embeds in .select2-selection__rendered
by measuring the box's natural layout; my earlier height-matching CSS
(zeroed padding, a fixed line-height, and extending the single-select's
overflow:hidden/text-overflow:ellipsis truncation to multi-selects too) broke
that measurement, so the search field rendered as a barely-visible sliver
sitting inline next to the "N Selected" text instead of expanding to a usable
width.
Back off to a lighter touch: only nudge min-height down a little (no padding/
line-height overrides), and keep the overflow/ellipsis truncation scoped to
single-selects, which is where it was actually needed (short "N Selected"/
"All Selected" labels on multi-selects don't need it and it wasn't there
before this session's changes).
* fix: hide the inline search box on select2-multi-count controls
Reducing padding/line-height (previous attempt) didn't stop the box from
showing - select2's inline search-while-typing input for multi-selects still
rendered as a tiny stray rectangle next to the "N Selected" text and kept
inflating the control's height, since that input's own margin/height are
part of the rendered area's natural content flow regardless of the parent's
box model.
select2-multi-count fields always replace the rendered area with summary
text and rely on checkboxes in the open dropdown for picking options, so the
inline search box serves no purpose here - hide it outright via the adjacent-
sibling selector (select.select2-multi-count + .select2-container), which
also lets the control's height settle back down to match single-selects
without needing to fight select2's own sizing math.
* fix: let select2-multi-count's search box work again once opened; fix vertical alignment
Hiding the inline search box outright also removed the only way to search a
multi-select's open dropdown (multi-select mode has no separate dropdown-only
search box - the inline one filters the open list too). Scope the hide to
:not(.select2-container--open) instead, so it stays out of the way while
closed but reappears once the dropdown is open.
Also wrap the "N Selected"/"All Selected" label in its own span
(select2-count-label) instead of writing bare text into
.select2-selection__rendered, so its line-height/truncation can be
controlled independently of whatever else (the search box) shares that
container - this was causing the text to sit off-center vertically.
* fix: keep the multi-select control's height fixed when its search box opens
Even scoped to select2-container--open, the inline search <li> was still
sitting inside .select2-selection__rendered as a normal block-level sibling
of the "N Selected" label span, so it pushed the label onto its own line and
grew/shifted the whole control upward whenever the dropdown opened - visible
proof the search box was structurally part of the "selection" element, not
just visually overlapping it.
Take it fully out of flow with position: absolute (sized to the control via
top/left/right/height: 100%, overriding select2's own inline width/height on
the actual <input>), so it can never affect the parent's layout regardless of
when it's shown. Also switch the control to flexbox with align-items: center
for reliable vertical centering of the label instead of a guessed
line-height, and give it the same 8px left inset the single-select's text
already has.
* fix: stop the multi-select's overlaid search field from painting over the label
The generic .select2-search--inline .select2-search__field rule gives search
boxes a solid background (matching the dropdown panel's search box, where
that's correct) - but once resized to fill the whole control via absolute
positioning, that same solid background completely hid the "N Selected"
label behind it while the dropdown was open. Make it transparent/borderless
instead, and hide the label (visibility, not display, so layout doesn't
shift) while open so there's no overlapping text underneath the cursor.
* fix: put the multi-select's search box on its own row instead of overlapping the selection
Overlaying it via position: absolute solved the layout-corruption bug but
traded it for a worse one - it now hid the "N Selected" label completely.
Let it flow normally below the label instead (its own full-width block, small
top margin for separation), matching how a search box should actually behave
- visible on its own line, not fighting the label for the same space. The
container only grows taller while the dropdown is actually open, since the
search row is hidden entirely while closed.
Also reset the stray margin select2 puts on #select2-<id>-container (the
same element as .select2-selection__rendered) - it was inflating the closed
control's height too.
* fix: multi-select search box wraps below label; vertically center label text
The row-direction flex box for select2-selection--multiple had no
flex-wrap, so once the search field was added as a second full-width flex
item its own line-item competed with the label item in the same row -
squeezing/overlapping both instead of the intended label-then-search
stacked layout. flex-wrap: wrap lets the label take row 1 and the
full-width search field naturally wrap to row 2, only while open.
Also give the label an explicit line-height matching the control's height
(same technique already used for the single-select boxes) - flex centering
alone left the text sitting a few pixels high due to the font's default
line-height metrics.
* fix: search select2-multi-count from the dropdown, not an inline box in the control
Root cause of the open-state height jump: select2 gives every multiple-select
a type-to-filter <input> INSIDE the selection control (its SelectionSearch
adapter). When the dropdown opens that input appears, growing the control and
pushing the surrounding filter rows down. No amount of CSS on an in-flow child
of the control avoids that - the search genuinely lives inside the control's
box.
Single-selects don't have this problem because their search lives in the
floating dropdown panel (DropdownSearch adapter), which is body-attached and
never affects page layout. So give the multi-count controls the same wiring:
a custom dropdownAdapter (Dropdown + DropdownSearch + MinimumResultsForSearch
+ AttachBody) that searches from the panel, and a selectionAdapter of just
MultipleSelection + EventRelay with no inline search box at all.
The control now keeps a fixed height whether open or closed, and the surrounding
form no longer shifts. Guarded so it falls back to default behavior if the
select2 AMD modules aren't reachable.
* fix: show 15 select2 dropdown rows before scrolling instead of 20
* fix: actually apply the multi-count dropdown-search adapters + trim control padding
Two bugs behind the "search still looks attached to the (green) control and the
control grows when open" report:
1. The adapters were required with the ARRAY form of select2's amd.require(),
which almond defers via setTimeout - so multiCountDropdownAdapter/
multiCountSelectionAdapter were still undefined when the init loop ran, and
select2 silently fell back to its default inline search box inside the
control. Fetch each module with the synchronous string form instead so the
adapters are actually in place at init time. The search now lives in the
floating dropdown (black), not inline in the green open-state control.
2. Vendor select2.css's .select2-container--default .select2-selection--multiple
adds padding-bottom:5px (equal specificity, so it wasn't being reset), which
left the count label sitting against the top of the control with a gap below.
Set explicit padding: 0 20px 0 0 so the flex-centered label is truly centered
and the closed control matches the single-select height.
* fix: size select2-multi-count control/dropdown to content, not the native listbox width
* fix: reload graphs after the Template select2 fully closes, not mid-teardown
* docs: track pending select2 upstream dropdown-search PR for future cleanup
* docs: link the actual select2 upstream PR (#6462)
* fix: sync checkbox visuals for graph_template_id's -1/others exclusivity; skip reload if nothing changed
Two bugs in the "All Templates" (-1) mutual-exclusivity sentinel:
1. Selecting -1 didn't visually uncheck the other checkboxes, and vice versa.
The old code flipped the underlying <option>.selected directly and fired a
plain 'change' event - but select2's own 'change' listener only refreshes
the "N Selected" summary label, not the open dropdown's rendered results
list. The checkbox marks are drawn from aria-selected on those already-
rendered <li> elements, which never got touched. Fixed by routing through
select2's own internal event bus (available via $el.data('select2')) with
'select'/'unselect' triggers instead - the exact same path a real click
takes, which also runs Results.setClasses() to redraw the checkboxes.
2. Opening the dropdown and closing it again without changing anything used
to still reload the graphs. Now the selected value is snapshotted on open
and compared on close; the reload only fires if it actually changed.
* fix: force checkbox refresh in graph_template_id sentinel to fix off-by-one visual lag
Reported symptom: click template T1 while "All Graphs & Templates" is
checked - the "All" box unchecks correctly, but T1 does not visually check.
Click T2 next - T1 (not T2) now shows checked. Click T3 - T2 shows checked.
The checkbox visual was always exactly one click behind the actual selection.
Rather than keep chasing the precise internal event-ordering that causes
this (select2's DataAdapter/Results adapters both listen to the same
internal 'select'/'unselect' events our sentinel re-triggers), force a
direct, unconditional call to the Results adapter's own setClasses() method
(exposed publicly as $el.data('select2').results) immediately after our
selection changes. This guarantees the open dropdown's checkboxes reflect
the current underlying <option> selected state before the handler returns,
independent of dispatch ordering.
* debug: temporary console diagnostics for graphTemplateSentinel checkbox lag
* fix: checkbox checkmark keys off --selected class, not aria-selected (hover was stealing it)
Root cause of the "checkbox always one click behind" bug, finally confirmed
via console diagnostics: our checkbox checkmark CSS keyed off the
aria-selected attribute, but select2's own results.js reuses that exact same
attribute for a second, unrelated purpose - tracking which row is currently
mouse-hovered/keyboard-highlighted (a legitimate ARIA listbox pattern). Every
time the mouse moves onto a new row, select2 clears aria-selected on whatever
row was previously "highlighted" and sets it on the newly-hovered row,
completely independent of actual selection state.
Since a user naturally moves the mouse toward the next item immediately after
clicking the current one, this hover-tracking code was stealing
aria-selected="true" away from the just-selected row and handing it to
whatever's now under the cursor - producing exactly the observed "previous
box shows checked, current one doesn't" pattern. Confirmed via console
logging: aria-selected was momentarily correct right after each click (when
our own forced setClasses() call ran), then immediately got reassigned by the
very next mouseenter as the user moved toward their next target.
Fix: key the checkmark off the select2-results__option--selected CSS class
instead. That class is exclusively added/removed by setClasses() based on the
real underlying <option>.selected state, and is never touched by the
mouseenter/highlight-tracking code - so it can't be hijacked by hovering.
Also removes the temporary console.log diagnostics added while tracking this
down; the forced setClasses() calls in the sentinel are kept as harmless extra
insurance.
* chore: apply php-cs-fixer alignment fixes
CI's php-cs-fixer dry-run flagged 4 files for pure whitespace/alignment
drift introduced by the select2 conversion: array `=>` operators and a
docblock's @param columns need to align to the widest key/name in their
respective blocks, and two inline PHP print tags were missing the space
before `?>`. No behavioral change.
* fix: address Copilot review findings on select2 conversion (develop)
- lib/html_form.php: form_callback()'s select2-callback opt-in path used
htmle() (double_encode=false) for the select's id/name/class, its
data-action/data-variables/data-callback attributes, and the
pre-selected option's value attribute. A pre-encoded entity in any of
these caller-supplied values would survive into the attribute and be
decoded back into markup/quotes by the browser. Use html_escape_attr()
(double_encode=true) for all of these attribute contexts; the option's
text content stays on htmle() since that's body text, not an
attribute. Same fix for form_multi_dropdown()'s three
data-select-all-text/data-select-count-text/data-select-all-value
attributes.
- lib/html_reports.php: changeTree()'s replaceWith(data) on #branch_id
only swaps the <select> element itself, leaving a live Select2
instance's sibling .select2-container orphaned in the DOM. Destroy the
existing Select2 instance first so the re-initialization a few lines
down doesn't produce a duplicate branch control.
include/layout.js's select2-callback CSRF finding: verified this is not
an actual bug. select2 4.0.13's AjaxAdapter.query() calls
options.data.call(...) and hands the result straight to $.ajax() via the
default transport; for type: 'post' with a plain-object `data` and no
processData:false/contentType override, jQuery serializes it as the POST
body via $.param(), and Cacti's csrf_check() reads the token via
filter_input(INPUT_POST, ...). The __csrf_magic data() callback already
present here (since the PR's first commit) does get sent correctly. No
global $.fn.select2.defaults override clobbers it. Replied with this
analysis rather than changing working code.
Verified: php -l on both changed PHP files; brace-balance check on
lib/html_reports.php (295 open / 295 close).
* fix: address remaining Copilot review findings on select2 conversion (develop)
- include/layout.js: move the select2-hidden-accessible teardown in
applySkin() to run before setSelectMenus() instead of after it, so the
catch-all initializer still re-enhances plain <select> elements that the
teardown just destroyed (previously they stayed native after any
post-initial-load applySkin() re-run).
- include/layout.js: namespace the select2-callback widget's
select2:select listener and unbind it before rebinding, since destroying
and recreating the Select2 instance on every AJAX filter reload does not
remove a plain jQuery listener bound to the underlying <select>, which
was accumulating duplicate invocations of the configured callback.
- include/layout.js, lib/auth.php, lib/html.php: thread $noany/$nonone
from html_host_filter() through to its ajax-backed select2-callback
widget (as data-noany/data-nonone attributes forwarded as request vars),
and have get_allowed_ajax_hosts() honor them. $sql_where is intentionally
left unapplied over the ajax path and documented as such: passing
caller-supplied raw SQL across the client/server boundary would be a new
SQL injection vector, unlike the boolean any/none toggles.
- lib/html.php: use html_escape_attr() instead of htmle() for the two
attribute contexts in html_host_filter()'s markup (data-callback and the
option value), since htmle()/html_escape() disables double_encode and so
a pre-encoded quote entity in the input could survive and be decoded
back into a live quote by the browser, breaking out of the attribute.
htmle() is kept for the visible option text.
- lib/html.php: use cacti_js_encode() instead of plain json_encode() for
the two new multi-select translation strings emitted into the inline
<script> block, since json_encode() alone does not hex-escape </script>
sequences.
- lib/html_reports.php: use the global select2SearchRows setting instead
of a hard-coded 10-row threshold when reinitializing the branch_id
Select2 control after an AJAX tree change, so the configured
"Select Search Minimum Rows" setting (including "Always") is respected.
- include/themes/paper-plane/main.css, include/themes/sunrise/main.css:
fix unreadable dark-on-dark Select2 control text (both the base control
and its rendered value) by using each theme's existing light foreground
convention instead of the near-black color left over from the plain
jQuery UI selectmenu styling.
Verified: tests/Unit/InlineScriptDataEncodingTest,
tests/Unit/Security/Xss/HtmlEscapeTest, and reports/host/graph-filter
related Unit tests all pass; php -l and node --check clean on touched
files; empirically reproduced (jsdom + real select2 4.1.0 + jQuery 4.0)
that the select2-multi-count adapter combination does not create a
duplicate inline search box, contrary to one review comment - no code
change made for that finding, replied with the reproduction instead.
140 lines
5.8 KiB
PHP
140 lines
5.8 KiB
PHP
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2026 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU General Public License |
|
|
| as published by the Free Software Foundation; either version 2 |
|
|
| of the License, or (at your option) any later version. |
|
|
| |
|
|
| This program is distributed in the hope that it will be useful, |
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
| GNU General Public License for more details. |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
| This code is designed, written, and maintained by the Cacti Group. See |
|
|
| about.php and/or the AUTHORS file for specific developer information. |
|
|
+-------------------------------------------------------------------------+
|
|
| http://www.cacti.net/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
global $config, $refresh, $messages;
|
|
|
|
$script = get_current_script_name();
|
|
$graphs = false;
|
|
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
|
|
|
|
if ($script == 'graph_view.php' || $script == 'graph.php') {
|
|
$graphs = true;
|
|
|
|
if (isset($_SESSION['custom']) && $_SESSION['custom'] == true) {
|
|
$refreshIsLogout = 'true';
|
|
} elseif (isrv('action') && gnrv('action') == 'zoom') {
|
|
$refreshIsLogout = 'true';
|
|
} else {
|
|
$refresh = api_plugin_hook_function('top_graph_refresh', read_user_setting('page_refresh'));
|
|
$refreshIsLogout = 'false';
|
|
}
|
|
} elseif (strstr($_SERVER['SCRIPT_NAME'], 'plugins')) {
|
|
$refresh = api_plugin_hook_function('top_graph_refresh', $refresh);
|
|
|
|
if (empty($refresh)) {
|
|
$refreshIsLogout = 'true';
|
|
} else {
|
|
$refreshIsLogout = 'false';
|
|
}
|
|
}
|
|
|
|
if (isset($_SESSION['refresh'])) {
|
|
if (isset($_SESSION['refresh']['seconds'])) {
|
|
$myrefresh['seconds'] = $_SESSION['refresh']['seconds'];
|
|
} else {
|
|
$myrefresh['seconds'] = ini_get('session.gc_maxlifetime');
|
|
}
|
|
|
|
if (isset($_SESSION['refresh']['logout'])) {
|
|
$refreshIsLogout = $_SESSION['refresh']['logout'];
|
|
} else {
|
|
$refreshIsLogout = 'false';
|
|
}
|
|
|
|
if (isset($_SESSION['refresh']['page'])) {
|
|
$myrefresh['page'] = sanitize_uri($_SESSION['refresh']['page']);
|
|
} else {
|
|
$myrefresh['page'] = CACTI_PATH_URL . 'logout.php?action=timeout';
|
|
$refreshIsLogout = 'true';
|
|
}
|
|
|
|
unset($_SESSION['refresh']);
|
|
} elseif (isset($refresh) && is_array($refresh)) {
|
|
$myrefresh['seconds'] = $refresh['seconds'];
|
|
$myrefresh['page'] = sanitize_uri($refresh['page']);
|
|
$refreshIsLogout = 'false';
|
|
} elseif (isset($refresh)) {
|
|
$myrefresh['seconds'] = $refresh;
|
|
$myrefresh['page'] = sanitize_uri($request_uri);
|
|
$refreshIsLogout = 'false';
|
|
} elseif (read_config_option('auth_cache_enabled') == 'on' && isset($_SESSION['cacti_remembers']) && $_SESSION['cacti_remembers'] == true) {
|
|
$myrefresh['seconds'] = 99999999;
|
|
$myrefresh['page'] = sanitize_uri($request_uri);
|
|
$refreshIsLogout = 'false';
|
|
} elseif (read_user_setting('user_auto_logout_time') > 0 && is_realm_allowed(8)) {
|
|
$myrefresh['seconds'] = read_user_setting('user_auto_logout_time');
|
|
$myrefresh['page'] = CACTI_PATH_URL . 'logout.php?action=timeout';
|
|
$refreshIsLogout = 'true';
|
|
} elseif (read_config_option('auth_method') == AUTH_METHOD_BASIC) {
|
|
$myrefresh['seconds'] = 99999999;
|
|
$myrefresh['page'] = 'index.php';
|
|
$refreshIsLogout = 'false';
|
|
} elseif (!isset($_SESSION[SESS_USER_ID]) && str_contains($request_uri, 'index.php')) {
|
|
$myrefresh['seconds'] = 99999999;
|
|
$myrefresh['page'] = sanitize_uri($request_uri);
|
|
$refreshIsLogout = 'false';
|
|
} else {
|
|
$myrefresh['seconds'] = ini_get('session.gc_maxlifetime');
|
|
$myrefresh['page'] = CACTI_PATH_URL . 'logout.php?action=timeout';
|
|
$refreshIsLogout = 'true';
|
|
}
|
|
|
|
// guest account does not auto log off
|
|
if (isset($_SESSION[SESS_USER_ID]) && $_SESSION[SESS_USER_ID] == read_config_option('guest_user')) {
|
|
$myrefresh['seconds'] = 99999999;
|
|
$myrefresh['page'] = sanitize_uri($request_uri);
|
|
$refreshIsLogout = 'false';
|
|
}
|
|
|
|
// basic auth times out when the auth provider times out
|
|
if (read_config_option('auth_method') == AUTH_METHOD_BASIC) {
|
|
$myrefresh['seconds'] = 99999999;
|
|
$myrefresh['page'] = sanitize_uri($request_uri);
|
|
$refreshIsLogout = 'false';
|
|
}
|
|
|
|
if ($graphs) {
|
|
$refresh_function = 'refreshGraphs()';
|
|
} else {
|
|
$refresh_function = '';
|
|
}
|
|
|
|
?>
|
|
<script type='text/javascript' <?php print CactiSecureHeaders::getNonceAttribute(); ?>>
|
|
var cactiVersion='<?php print $config['cacti_version']; ?>';
|
|
var cactiServerOS='<?php print CACTI_SERVER_OS; ?>';
|
|
var cactiAction='<?php print gfrv('action', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([-a-zA-Z0-9_\s]+)$/']]); ?>';
|
|
var theme='<?php print get_selected_theme(); ?>';
|
|
var refreshIsLogout=<?php print $refreshIsLogout; ?>;
|
|
var refreshPage='<?php print $myrefresh['page']; ?>';
|
|
var refreshMSeconds=<?php print $myrefresh['seconds'] * 1000; ?>;
|
|
var refreshFunction='<?php print $refresh_function; ?>';
|
|
var previousPage='';
|
|
var sessionLocale='<?php print CACTI_LOCALE; ?>';
|
|
var sessionNotices=<?php print display_output_messages(); ?>;
|
|
var sessionMessage={};
|
|
var csrfMagicToken='<?php print csrf_get_tokens(); ?>';
|
|
var select2SearchRows=<?php print intval(read_config_option('select2_search_rows')); ?>;
|
|
</script>
|