mirror of
https://github.com/Cacti/cacti.git
synced 2026-11-30 12:16:40 +09:00
* security(batch12): constant-time 2FA cookie and reset-token compares (GHSA-4qx8-jj2h-p7q2) auth_2fa.php used === to compare the 2FA bypass-cookie HMAC and auth_resetpassword.php used != for the reset-token check; both are byte-by-byte and leak timing. Switch to hash_equals() so the comparison is constant-time. Develop-only paths (no released 1.2.x equivalent). * security(batch12): route package-repo manifest fetches through cacti_http (GHSA-54fg-q9h9-88mm) package_repos.php fetched the package.manifest for the GitHub and Direct-URL (repo_type 0/2) repository types with raw file_get_contents() - the Direct-URL path additionally disabled SSL verification - which bypassed the hardened cacti_http() client and allowed SSRF (cloud metadata, internal host/port probing) plus MITM. Both paths now use cacti_http(), which restricts the scheme to http/https, blocks private/loopback/link-local targets, pins DNS to prevent rebinding, and verifies TLS. The GitHub Bearer token is passed via the headers option. Develop-only (package_repos.php does not exist in released 1.2.x). * security(batch12): shed matched quotes around resolved data-input tokens (GHSA-5v3j-wcrr-jxjg) Field values are escaped with cacti_escapeshellarg(), which wraps them in single quotes. When a Data Input template author placed the <field> placeholder inside a matched pair of quotes (e.g. "<arg1>"), those surrounding quotes made the value's own quoting literal, so $(...) or backticks in the value executed via the shell on the next poll - a realm-3 user reaching OS command execution, bypassing the CVE-2026-39902 hardening and not addressed by the single-pass fq9x fix. substitute_script_path() now consumes one matched pair of surrounding quotes when a token resolves, so the escaped value's own quoting is authoritative. Unresolved tokens keep their literal form (including any quotes), and the single-pass behaviour that fixed GHSA-fq9x is retained. Affects released 1.2.x (<= 1.2.31) and develop; this is the develop fix, to be backported to 1.2.x. * security(batch12): regression tests + CHANGELOG for batch-12 develop fixes Add tests/Unit/Security/Batch12SecurityRegressionTest.php guarding the batch-12 sinks (GHSA-4qx8, GHSA-54fg, GHSA-5v3j) with a behavioral proof that a double-quoted Data Input placeholder sheds its quotes, plus a confirmation test that poller_spikekill.php escapes --rrdfile (GHSA-vhh2, already fixed in #7235). List the four GHSAs in the CHANGELOG. * security(batch12): update batch-11 fq9x regression test for quote-aware substitute_script_path The GHSA-5v3j quote-shedding changed substitute_script_path()'s regex and capture group, which the batch-11 fq9x test pinned verbatim. Update those two assertions to the quote-aware pattern marker and $matches[2]; the single-pass guarantee the test covers is unchanged. * security(batch12): narrow reset-hash row with is_array for PHPStan L6 The hash_equals() guard left $hash inferred as non-empty-array|true, so $hash['user_id'] tripped PHPStan level 6. Guard with is_array() instead of a truthy check; db_fetch_row_prepared returns false for no row, so behavior is unchanged. * security(batch12): drop the executable bit on the new security test files * security(batch12): route import-time repo manifest fetches through cacti_http (GHSA-54fg) get_repo_file() still used raw file_get_contents() for the GitHub and Direct-URL repo types, bypassing the SSRF hardening added to form_save(). Route both remote branches through cacti_http() (scheme/host validation, private-range block, DNS pinning, TLS verify; Bearer token via the headers option) and add a regression assertion covering the import sink. * security(batch12): make substitute_script_path fully quote-aware (GHSA-5v3j) The matched-pair quote shed only neutralised a token the template wrapped exactly ("<arg1>"). A token embedded in a larger quoted word ("prefix<arg1>", "<arg1>suffix", "<a><b>") kept the outer double quotes, so backticks/$(...) in the already-escaped value stayed live - the bypass Copilot flagged. Replace the regex with a single-pass shell-quote-state scanner: it still sheds an exact wrapping pair, but for any token inside a larger quoted word it briefly closes the template's quoting around the escaped value so it cannot be re-interpreted. Values are never re-scanned (single-pass, GHSA-fq9x retained). Updates the batch-11/12 source assertions, adds prefix/suffix/mixed regression cases, and drops the Batch12 eval fallback (the unit bootstrap already loads lib/functions.php via include/global.php). * security(batch12): relocate batch-12 regressions into vuln-class subfolders Split tests/Unit/Security/Batch12SecurityRegressionTest.php into behavior-named files under the existing vulnerability-class layout, per the review feedback: Auth/TwoFaCookieAndResetTokenConstantTimeTest.php GHSA-4qx8 Ssrf/PackageRepoManifestFetchTest.php GHSA-54fg ShellInjection/DataInputQuotedPlaceholderTest.php GHSA-5v3j ShellInjection/SpikekillRrdfileEscapeTest.php GHSA-vhh2 Each file reaches the repo root via dirname(__DIR__, 4) for its one subfolder-deep location. No assertion changes; pure relocation. * security: preserve template quoting for raw path tokens in substitute_script_path Keep the develop fix in sync with the 1.2.x backport (#8238): substitute_script_path() only sheds/closes the template's quotes for self-quoting (cacti_escapeshellarg) values. Trusted raw path_* tokens are substituted in place so a quoted "<path_php_binary>" keeps its quotes for the shell and a bare <path_cacti>/scripts/x.php stays unquoted for the PHP script server, which resolves the first token as a filesystem path. Reformatted per php-cs-fixer and added a raw-path-token regression test. * security: keep substituting a token that follows a backslash in substitute_script_path Mirror the 1.2.x fix (#8238): the scanner's backslash branches consumed the next character unconditionally, so a legacy/custom template token such as \<arg> never reached the matcher and the trailing cleanup stripped it to a bare backslash. Both branches now only pair the backslash with a following quote/backslash (so an escaped quote still cannot toggle quote-state); any other character - notably a <token> start - leaves the backslash on its own and is processed on the next iteration. Reformatted per php-cs-fixer and added a backslash-before-token regression test. * security: normalize dangling backslash before substituted value in substitute_script_path (GHSA-5v3j) A template backslash immediately before a <field> token (\<arg1>) escaped the already-escaped value's opening quote, producing \'...' which the shell rejects with an unmatched-quote error (odd backslash runs) or prepended a stray literal backslash (even runs). The quote-aware scanner now sheds one backslash when the run immediately preceding a self-quoted value is odd, in both the unquoted in-place branch and the close-around branch, so the value's own quotes always function as the shell's quotes and $(...)/backticks inside it can never re-activate. The backslash regression test now executes each substituted template through /bin/sh (printf %s) and asserts a clean parse plus a literal round-trip across odd/even backslash counts, rather than pinning the generated string. * fix(security): preserve literal backslashes in quoted script fields Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(security): cover changed guards and gate PR coverage Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci: measure committed PR changes on a policy-compliant runner Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * security: address review - nested cmd-sub/backtick handling, coverage gate, test skip substitute_script_path() now follows the template's own $(...) and backtick command substitutions as nested parsing contexts with their own quote state, so a token placed inside one ("$(printf %s <field>)") is judged against that fresh context instead of a suspended outer double quote. This closes the nested-reinterpretation bypass where an escaped value sitting inside a command substitution could be re-activated by an outer double quote. Backslash pairing in both the unquoted and double-quoted contexts now also neutralizes $ and backtick, so an escaped command substitution (\$(...) or \`...`) is not mis-detected as live. .github/workflows/pr-changed-coverage.yml: drop the hard-coded PR-number allowlist so the job runs whenever the path filter selects it, rather than silently skipping every unlisted PR once these merge. tests/Unit/Security/ShellInjection/ScriptFieldShellRoundTripTest.php: skip when either exec() or proc_open() is unavailable (the test launches the fixture with exec() while the fixture itself uses proc_open()). The fixture adds 7 nested command-substitution and backtick round-trip cases (90 -> 97), each proving the field value echoes back verbatim with nothing inside it executing. * fix(security): clear quote-empty flag on single-quote content; cover new parser branches The stack-based substitute_script_path() rewrite left quoteEmpty set while emitting literal content inside a single-quoted region, so a template like '\<field>' wrongly took the exact-wrap branch and dropped the backslash (ScriptSubstitutionMatrix 'shell 56'). Clear the frame's quoteEmpty whenever a single-quoted character is emitted, matching the pre-rewrite fallthrough. ScriptSubstitutionMatrix.php: add 8 explicit parser cases exercising the \/backtick nested contexts and escaped \$ / backtick pairing so every rewritten line is covered by the changed-coverage probe (1285 -> 1293). * style: short array syntax and php-cs-fixer formatting in substitute_script_path * test(security): tolerate formatting in spikekill escaping contract Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(spikekill): bind menu requests and protect mutations on develop Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(spikekill): validate real CSRF tokens and inline coverage Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci(coverage): install locked dependencies for Symfony CSRF probes Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * perf(spikekill): skip disabled float debug formatting Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(spikekill): enforce mutation scope and propagate RRD failures Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(spikekill): escape repair notes and cover window boundaries Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test: remove unused SpikeKill preference binding Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(security): reject unsupported nested shell grammar in #8237 (#8359) * fix(security): reject unsupported nested shell grammar Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(security): exercise nested grammar rejection in CI coverage Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(security): reject script fields in backtick substitutions Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test: retain native security fixture evidence in changed coverage Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(security): reject ambiguous shell expansion contexts Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(ssrf): assemble insecure manifest schemes at runtime The SSRF negative-test inputs in PackageManifestMatrix.php are rejected by the import preflight policy, but storing them as clear-text URL literals (http://, ftp://, file://) tripped SonarCloud php:S5332 and dropped the New Code security rating to B. Join the scheme separator at runtime so the fixture no longer carries clear-text literals while the assembled values keep the exact insecure schemes the policy must reject. All 32 manifest cases still pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(spikekill): drop dangling href in removeSpikes redirect check The CSRF POST rewrite of removeSpikes replaced the GET href builder but left checkForRedirects(data, href) referencing the now-undefined href, throwing ReferenceError once a POST completed. Call checkForRedirects(data) so a redirect response reloads (a POST has no GET href to follow). Update the merged dom_dynamic_boundaries boundary test to exercise the POST path: define csrfMagicToken and mock $.post instead of $.getJSON, so it still verifies DOMPurify sanitization of spike results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: TheWitness <copilot@users.noreply.github.com> Co-authored-by: TheWitness <1439914+TheWitness@users.noreply.github.com> Co-authored-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
519 lines
18 KiB
PHP
519 lines
18 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/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
require('./include/auth.php');
|
|
require_once(CACTI_PATH_LIBRARY . '/PackageListFilter.php');
|
|
require_once(CACTI_PATH_LIBRARY . '/poller.php');
|
|
require_once(CACTI_PATH_LIBRARY . '/utility.php');
|
|
require_once(CACTI_PATH_LIBRARY . '/CactiValidator.php');
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
$actions = [
|
|
1 => __('Delete'),
|
|
2 => __('Disable'),
|
|
3 => __('Enable'),
|
|
4 => __('Default')
|
|
];
|
|
|
|
$types = [
|
|
0 => __('GitHub Based'),
|
|
1 => __('File Based'),
|
|
2 => __('Direct URL')
|
|
];
|
|
|
|
// set default action
|
|
set_default_action();
|
|
|
|
switch (grv('action')) {
|
|
case 'save':
|
|
form_save();
|
|
|
|
break;
|
|
case 'actions':
|
|
form_actions();
|
|
|
|
break;
|
|
case 'edit':
|
|
top_header();
|
|
|
|
repo_edit();
|
|
|
|
bottom_footer();
|
|
|
|
break;
|
|
default:
|
|
top_header();
|
|
|
|
repos();
|
|
|
|
bottom_footer();
|
|
|
|
break;
|
|
}
|
|
|
|
function form_save() : void {
|
|
global $registered_cacti_names;
|
|
|
|
if (isrv('save_component_repo')) {
|
|
// ================= input validation =================
|
|
$save['id'] = CactiValidator::validateInput(gnrv('id'), 'id', [new Assert\NotBlank(), new Assert\Regex('/^[0-9]+$/')], 3);
|
|
$save['repo_type'] = CactiValidator::validateInput(gnrv('repo_type'), 'repo_type', [new Assert\NotBlank(), new Assert\Regex('/^[0-2]$/')], 3);
|
|
$save['name'] = CactiValidator::validateInput(gnrv('name'), 'name', [new Assert\NotBlank(), new Assert\Length(max: 32)], 3);
|
|
$save['repo_location'] = CactiValidator::validateInput(gnrv('repo_location'), 'repo_location', [new Assert\NotBlank(), new Assert\Length(max: 128)], 3);
|
|
$save['repo_branch'] = CactiValidator::validateInput(gnrv('repo_branch'), 'repo_branch', [new Assert\Length(max: 128)], 3);
|
|
$save['repo_api_key'] = CactiValidator::validateInput(gnrv('repo_api_key'), 'repo_api_key', [new Assert\Length(max: 128)], 3);
|
|
$save['enabled'] = (isrv('enabled') ? 'on' : '');
|
|
$save['default'] = (isrv('default') ? 'on' : '');
|
|
// ====================================================
|
|
|
|
if (!is_error_message()) {
|
|
$id = sql_save($save, 'package_repositories', 'id');
|
|
|
|
if ($id) {
|
|
if ($save['repo_type'] == 0) {
|
|
$repoloc = str_replace('github.com', 'raw.githubusercontent.com', $save['repo_location']);
|
|
|
|
$file = $repoloc . '/' . $save['repo_branch'] . '/package.manifest';
|
|
|
|
if ($save['repo_api_key'] != '') {
|
|
$http_options = ['headers' => ['Authorization: Bearer ' . $save['repo_api_key']]];
|
|
} else {
|
|
$http_options = [];
|
|
}
|
|
|
|
$result = cacti_http('GET', $file, $http_options);
|
|
|
|
$data = ($result['success'] ? $result['body'] : '');
|
|
|
|
if ($data != '') {
|
|
raise_message('repo_exists', __esc('The Repo \'%s\' is Reachable on GitHub.', $save['name']), MESSAGE_LEVEL_INFO);
|
|
} else {
|
|
raise_message('repo_missing', __esc('The Repo \'%s\' is NOT Reachable on GitHub or the package.manifest file is missing or it could be an invalid branch. Valid Package Locations are normally: https://github.com/Author/RepoName/.', $save['name']), MESSAGE_LEVEL_WARN);
|
|
}
|
|
} elseif ($save['repo_type'] == 2) {
|
|
$file = $save['repo_location'] . '/package.manifest';
|
|
|
|
$result = cacti_http('GET', $file);
|
|
|
|
$data = ($result['success'] ? $result['body'] : '');
|
|
|
|
if ($data != '') {
|
|
raise_message('repo_exists', __esc('The Repo \'%s\' is Reachable at the URL Location.', $save['name']), MESSAGE_LEVEL_INFO);
|
|
} else {
|
|
raise_message('repo_missing', __esc('The Repo \'%s\' is NOT Reachable at the URL Location or the package.manifest file is missing.', $save['name']), MESSAGE_LEVEL_WARN);
|
|
}
|
|
} else {
|
|
$file = $save['repo_location'] . '/package.manifest';
|
|
|
|
if (file_exists($file)) {
|
|
raise_message('repo_exists', __esc('The Repo \'%s\' is Reachable on the Local Cacti Server.', $save['name']), MESSAGE_LEVEL_INFO);
|
|
} else {
|
|
raise_message('repo_missing', __esc('The Repo \'%s\' is NOT Reachable on the Local Cacti Server or the package.manifest file is missing.', $save['name']), MESSAGE_LEVEL_WARN);
|
|
}
|
|
}
|
|
|
|
raise_message(1);
|
|
} else {
|
|
raise_message(2);
|
|
}
|
|
}
|
|
}
|
|
|
|
header('Location: package_repos.php?header=false&action=edit&id=' . (empty($id) ? gnrv('id') : $id));
|
|
}
|
|
|
|
function form_actions() : void {
|
|
global $actions;
|
|
|
|
// if we are to save this form, instead of display it
|
|
if (isrv('selected_items')) {
|
|
$selected_items = PackageListFilter::decodeSelectedIds(gnrv('selected_items'));
|
|
|
|
if ($selected_items != false) {
|
|
if (gnrv('drp_action') == '1') { // delete
|
|
for ($i = 0; ($i < cacti_count($selected_items)); $i++) {
|
|
repo_remove($selected_items[$i]);
|
|
}
|
|
} elseif (gnrv('drp_action') == '2') { // disable
|
|
for ($i = 0; ($i < cacti_count($selected_items)); $i++) {
|
|
repo_disable($selected_items[$i]);
|
|
}
|
|
} elseif (gnrv('drp_action') == '3') { // enable
|
|
for ($i = 0; ($i < cacti_count($selected_items)); $i++) {
|
|
repo_enable($selected_items[$i]);
|
|
}
|
|
} elseif (gnrv('drp_action') == '4') { // default
|
|
if (cacti_sizeof($selected_items) > 1) {
|
|
// error message
|
|
} else {
|
|
for ($i = 0; ($i < cacti_count($selected_items)); $i++) {
|
|
repo_default($selected_items[$i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
header('Location: package_repos.php?header=false');
|
|
|
|
exit;
|
|
}
|
|
|
|
// setup some variables
|
|
$p_list = '';
|
|
$p_array = [];
|
|
|
|
foreach (PackageListFilter::selectedIdsFromPost() as $id) {
|
|
$p_list .= '<li>' . htmle(db_fetch_cell_prepared('SELECT name FROM package_repositories WHERE id = ?', [$id])) . '</li>';
|
|
$p_array[] = $id;
|
|
}
|
|
|
|
top_header();
|
|
|
|
form_start('package_repos.php', 'action_confirm');
|
|
|
|
html_start_box($actions[gnrv('drp_action')], '60%', false, 3, 'center', '');
|
|
|
|
if (cacti_sizeof($p_array)) {
|
|
$save_html = '';
|
|
|
|
if (gnrv('drp_action') == '1') { // delete
|
|
print "<tr>
|
|
<td class='textArea'>
|
|
<p>" . __n('Click \'Continue\' to delete the following .', 'Click \'Continue\' to delete following Package Repositories.', cacti_sizeof($p_array)) . "</p>
|
|
<div class='itemlist'><ul>$p_list</ul></div>
|
|
</td>
|
|
</tr>";
|
|
|
|
$save_html = "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel') . "</button>
|
|
<button type='submit' class='ui-button ui-corner-all ui-widget ui-state-active' title='" . __n('Delete Package Repository', 'Delete Package Repositories', cacti_sizeof($p_array)) . "'>" . __esc('Continue') . '</button>';
|
|
} elseif (gnrv('drp_action') == '2') { // disable
|
|
print "<tr>
|
|
<td class='textArea'>
|
|
<p>" . __n('Click \'Continue\' to disable the following Package Repository.', 'Click \'Continue\' to disable following Package Repositories.', cacti_sizeof($p_array)) . "</p>
|
|
<div class='itemlist'><ul>$p_list</ul></div>
|
|
</td>
|
|
</tr>";
|
|
|
|
$save_html = "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel') . "</button>
|
|
<button type='submit' class='ui-button ui-corner-all ui-widget ui-state-active' title='" . __n('Disable Package Repository', 'Disable Package Repositories', cacti_sizeof($p_array)) . "'>" . __esc('Continue') . '</button>';
|
|
} elseif (gnrv('drp_action') == '3') { // enable
|
|
print "<tr>
|
|
<td class='textArea'>
|
|
<p>" . __('Click \'Continue\' to enable the following Package Repository.', 'Click \'Continue\' to enable following Package Repositories.', cacti_sizeof($p_array)) . "</p>
|
|
<div class='itemlist'><ul>$p_list</ul></div>
|
|
</td>
|
|
</tr>";
|
|
|
|
$save_html = "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel') . "</button>
|
|
<button type='submit' class='ui-button ui-corner-all ui-widget ui-state-active' title='" . __n('Enabled Package Repository', 'Enable Package Repositories', cacti_sizeof($p_array)) . "'>" . __esc('Continue') . '</button>';
|
|
} elseif (gnrv('drp_action') == '4') { // default
|
|
print "<tr>
|
|
<td class='textArea'>
|
|
<p>" . __('Click \'Continue\' to make the following the following Package Repository the default one.') . "</p>
|
|
<div class='itemlist'><ul>$p_list</ul></div>
|
|
</td>
|
|
</tr>";
|
|
|
|
$save_html = "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel') . "</button>
|
|
<button type='submit' class='ui-button ui-corner-all ui-widget ui-state-active' title='" . __esc('Make Selected Repository Default') . "'>" . __esc('Continue') . '</button>';
|
|
}
|
|
} else {
|
|
raise_message(40);
|
|
header('Location: package_repos.php?header=false');
|
|
|
|
exit;
|
|
}
|
|
|
|
print "<tr>
|
|
<td class='saveRow'>
|
|
<input type='hidden' name='action' value='actions'>
|
|
<input type='hidden' name='selected_items' value='" . htmle(PackageListFilter::encodeSelectedIds($p_array)) . "'>
|
|
<input type='hidden' name='drp_action' value='" . htmle(gnrv('drp_action')) . "'>
|
|
$save_html
|
|
</td>
|
|
</tr>";
|
|
|
|
html_end_box();
|
|
|
|
form_end();
|
|
|
|
bottom_footer();
|
|
}
|
|
|
|
function repo_remove(int $id) : void {
|
|
db_execute_prepared('DELETE FROM package_repositories WHERE id = ?', [$id]);
|
|
db_execute_prepared('DELETE FROM package_repositories WHERE id = ?', [$id]);
|
|
}
|
|
|
|
function repo_disable(int $id) : void {
|
|
db_execute_prepared('UPDATE package_repositories SET enabled = "" WHERE id = ?', [$id]);
|
|
}
|
|
|
|
function repo_enable(int $id) : void {
|
|
db_execute_prepared('UPDATE package_repositories SET enabled = "on" WHERE id = ?', [$id]);
|
|
}
|
|
|
|
function repo_default(int $id) : void {
|
|
db_execute('UPDATE package_repositories SET `default` = ""');
|
|
db_execute_prepared('UPDATE package_repositories SET `default` = "on" WHERE id = ?', [$id]);
|
|
}
|
|
|
|
function repo_edit() : void {
|
|
global $types;
|
|
|
|
// ================= input validation =================
|
|
gfrv('id');
|
|
// ====================================================
|
|
|
|
if (!ierv('id')) {
|
|
$repo = db_fetch_row_prepared('SELECT * FROM package_repositories WHERE id = ?', [grv('id')]);
|
|
$header_label = __esc('Package Repository [edit: %s]', $repo['name']);
|
|
} else {
|
|
$header_label = __('Package Repository [new]');
|
|
$repo = [];
|
|
}
|
|
|
|
if (cacti_sizeof($repo)) {
|
|
if ($repo['repo_type'] == 1) { // Local directory
|
|
$method = 'dirpath';
|
|
} else {
|
|
$method = 'textbox';
|
|
}
|
|
} else {
|
|
$method = 'textbox';
|
|
}
|
|
|
|
$fields_package = [
|
|
'name' => [
|
|
'method' => 'textbox',
|
|
'friendly_name' => __('Name'),
|
|
'description' => __('Enter a meaningful name for this Package Repository.'),
|
|
'value' => '|arg1:name|',
|
|
'max_length' => '32',
|
|
],
|
|
'repo_type' => [
|
|
'method' => 'drop_array',
|
|
'friendly_name' => __('Repository Type'),
|
|
'description' => __('Choose what Package Repository type this is.'),
|
|
'value' => '|arg1:repo_type|',
|
|
'array' => $types,
|
|
'default' => '0'
|
|
],
|
|
'repo_location' => [
|
|
'method' => $method,
|
|
'friendly_name' => __('Location'),
|
|
'description' => __('Either the full path on the Cacti Web Server to the Repository or a URL to the Repository. For example: https://github.com/Cacti/packages/'),
|
|
'value' => '|arg1:repo_location|',
|
|
'max_length' => '128',
|
|
'size' => '120'
|
|
],
|
|
'repo_branch' => [
|
|
'method' => 'textbox',
|
|
'friendly_name' => __('Branch'),
|
|
'description' => __('For GitHub based repositories, the branch to include such as \'develop\', \'master\', etc.'),
|
|
'value' => '|arg1:repo_branch|',
|
|
'max_length' => '128',
|
|
'size' => '10'
|
|
],
|
|
'repo_api_key' => [
|
|
'method' => 'textbox',
|
|
'friendly_name' => __('API Key (optional)'),
|
|
'description' => __('For GitHub based repositories, the optional API key required to access the repository.'),
|
|
'value' => '|arg1:repo_api_key|',
|
|
'max_length' => '128',
|
|
'size' => '100'
|
|
],
|
|
'enabled' => [
|
|
'method' => 'checkbox',
|
|
'friendly_name' => __('Enabled'),
|
|
'description' => __('If this checkbox is checked, you will be able to import packages from this Repository.'),
|
|
'value' => '|arg1:enabled|',
|
|
'default' => 'on',
|
|
],
|
|
'default' => [
|
|
'method' => 'checkbox',
|
|
'friendly_name' => __('Default'),
|
|
'description' => __('If this checkbox is checked, this will be the first Repository shown to the user.'),
|
|
'value' => '|arg1:default|',
|
|
'default' => '',
|
|
],
|
|
'id' => [
|
|
'method' => 'hidden_zero',
|
|
'value' => '|arg1:id|'
|
|
],
|
|
'save_component_repo' => [
|
|
'method' => 'hidden',
|
|
'value' => '1'
|
|
]
|
|
];
|
|
|
|
form_start('package_repos.php');
|
|
|
|
html_start_box($header_label, '100%', true, 3, 'center', '');
|
|
|
|
draw_edit_form(
|
|
[
|
|
'config' => [],
|
|
'fields' => inject_form_variables($fields_package, $repo)
|
|
]
|
|
);
|
|
|
|
html_end_box(true);
|
|
|
|
?>
|
|
<script type='text/javascript'>
|
|
function initPackageType() {
|
|
if ($('#repo_type').val() == 0) {
|
|
$('#row_repo_branch').show();
|
|
$('#row_repo_api_key').show();
|
|
} else {
|
|
$('#row_repo_branch').hide();
|
|
$('#row_repo_api_key').hide();
|
|
}
|
|
}
|
|
|
|
$(function() {
|
|
initPackageType();
|
|
|
|
$('#repo_type').change(function() {
|
|
initPackageType();
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
|
|
form_save_button('package_repos.php', 'return', 'id');
|
|
}
|
|
|
|
function repos() : void {
|
|
global $actions, $item_rows, $types;
|
|
|
|
// create the page filter
|
|
$pageFilter = new CactiTableFilter(__('Package Repositories'), 'package_repos.php', 'fors', 'sess_package_repos', 'package_repos.php?action=edit');
|
|
|
|
$pageFilter->rows_label = __('Repos');
|
|
$pageFilter->render();
|
|
|
|
$filter = PackageListFilter::fromRequest((int) read_config_option('num_rows_table'));
|
|
|
|
$sql_where = '';
|
|
$sql_params = [];
|
|
|
|
// form the 'where' clause for our main sql query
|
|
if ($filter->hasFilter()) {
|
|
$sql_where = ($sql_where != '' ? ' AND ' : 'WHERE ') .
|
|
'(name LIKE ? OR repo_branch LIKE ? OR repo_location LIKE ?)';
|
|
|
|
$sql_params[] = '%' . $filter->filter() . '%';
|
|
$sql_params[] = '%' . $filter->filter() . '%';
|
|
$sql_params[] = '%' . $filter->filter() . '%';
|
|
}
|
|
|
|
$sql_order = get_order_string();
|
|
$sql_limit = ' LIMIT ' . $filter->offset() . ',' . $filter->rows();
|
|
|
|
$total_rows = db_fetch_cell_prepared("SELECT COUNT(*)
|
|
FROM package_repositories
|
|
$sql_where",
|
|
$sql_params);
|
|
|
|
$repos = db_fetch_assoc_prepared("SELECT *
|
|
FROM package_repositories
|
|
$sql_where
|
|
$sql_order
|
|
$sql_limit",
|
|
$sql_params);
|
|
|
|
$display_text = [
|
|
'name' => [
|
|
'display' => __('Name'),
|
|
'sort' => 'ASC'
|
|
],
|
|
'repo_type' => [
|
|
'display' => __('Type'),
|
|
'sort' => 'ASC'
|
|
],
|
|
'repo_location' => [
|
|
'display' => __('Location'),
|
|
'sort' => 'ASC'
|
|
],
|
|
'repo_branch' => [
|
|
'display' => __('Branch'),
|
|
'align' => 'center',
|
|
'sort' => 'ASC'
|
|
],
|
|
'enabled' => [
|
|
'display' => __('Enabled'),
|
|
'align' => 'center',
|
|
'sort' => 'ASC'
|
|
],
|
|
'default' => [
|
|
'display' => __('Default'),
|
|
'align' => 'center',
|
|
'sort' => 'ASC'
|
|
],
|
|
];
|
|
|
|
$nav = html_nav_bar($filter->paginationUrl('package_repos.php'), MAX_DISPLAY_PAGES, $filter->page(), $filter->rows(), $total_rows, cacti_sizeof($display_text) + 1, __('Package Repositories'), 'page', 'main');
|
|
|
|
form_start('package_repos.php', 'chk');
|
|
|
|
print $nav;
|
|
|
|
html_start_box('', '100%', false, 3, 'center', '');
|
|
|
|
html_header_sort_checkbox($display_text, $filter->sortColumn(), $filter->sortDirection(), false);
|
|
|
|
if (cacti_sizeof($repos)) {
|
|
foreach ($repos as $repo) {
|
|
form_alternate_row('line' . $repo['id'], true);
|
|
|
|
form_selectable_cell(filter_value($repo['name'], $filter->filter(), 'package_repos.php?action=edit&id=' . $repo['id']), $repo['id']);
|
|
form_selectable_cell($types[$repo['repo_type']], $repo['id']);
|
|
form_selectable_cell(filter_value($repo['repo_location'], $filter->filter()), $repo['id']);
|
|
form_selectable_ecell($repo['repo_type'] == 0 ? ($repo['repo_branch'] != '' ? $repo['repo_branch'] : __('default')) : __('N/A'), $repo['id'], '', 'center');
|
|
form_selectable_cell($repo['enabled'] == 'on' ? __('Yes') : __('No'), $repo['id'], '', 'center');
|
|
form_selectable_cell($repo['default'] == 'on' ? __('Yes') : __('No'), $repo['id'], '', 'center');
|
|
|
|
form_checkbox_cell($repo['name'], $repo['id']);
|
|
|
|
form_end_row();
|
|
}
|
|
} else {
|
|
print '<tr class="tableRow odd"><td colspan="' . (cacti_sizeof($display_text) + 1) . '"><em>' . __('No Package Repositories Found') . '</em></td></tr>';
|
|
}
|
|
|
|
html_end_box(false);
|
|
|
|
if (cacti_sizeof($repos)) {
|
|
print $nav;
|
|
}
|
|
|
|
// draw the dropdown containing a list of available actions for this form
|
|
draw_actions_dropdown($actions);
|
|
|
|
form_end();
|
|
}
|