Fix Package Export (#6603)

* Fix Package Export

* Make package import work with an API key
This commit is contained in:
TheWitness authored and GitHub committed 2026-02-06 06:58:47 -05:00
1 parent cc683151e3
commit f440042e2a
6 files changed
+50 -14

No files matched your search

+2 -2
View File
@@ -83,8 +83,8 @@
"scripts": {
"lint": "phplint --no-cache --exclude=include/vendor",
"phpstan": "phpstan analyse --level 6 ",
"phpcsfixer": "php-cs-fixer fix --allow-unsupported-php-version=yes --dry-run --diff --config=./.php-cs-fixer.php --ansi",
"phpcsfixit": "php-cs-fixer fix --ansi"
"phpcsfixer": "php-cs-fixer fix --allow-unsupported-php-version=yes --dry-run --diff --config=./.php-cs-fixer.php ",
"phpcsfixit": "php-cs-fixer fix "
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.86",
+1 -1
View File
@@ -1196,6 +1196,6 @@ function get_item_xml(string $type, int $id, bool $follow_deps) : string {
return $xml_text;
}
function xml_character_encode(string $text) : string {
function xml_character_encode(mixed $text) : string {
return htmle($text);
}
+5 -5
View File
@@ -22,7 +22,7 @@
+-------------------------------------------------------------------------+
*/
function get_export_hash(string $export_type, int $export_item_id) : mixed {
function get_export_hash(string $export_type, mixed $export_item_id) : mixed {
switch($export_type) {
case 'host_template':
if (!empty($export_item_id)) {
@@ -167,7 +167,7 @@ function open_packager_metadata_table() : mixed {
return false;
}
function get_packager_metadata(string $hash) : bool {
function get_packager_metadata(string $hash) : mixed {
$cnn = open_packager_metadata_table();
if (is_object($cnn)) {
@@ -265,14 +265,14 @@ function get_package_contents(string $export_type, int $export_item_id, bool $in
$xml_data = get_item_xml($export_type, $export_item_id, $include_deps);
$files = [];
if ($export_errors > 0) { // @phpstan-ignore-line - This values is set as a global in get_item_xml
if ($export_errors == 0) { // @phpstan-ignore-line - This values is set as a global in get_item_xml
$files = find_dependent_files($xml_data, true);
// search xml files for scripts
if (cacti_sizeof($files)) {
foreach ($files as $file) {
if (str_contains($file['file'], '.xml')) {
$files = array_merge($files, find_dependent_files(file_get_contents($file['file']), $file));
$files = array_merge($files, find_dependent_files(file_get_contents($file['file']), true));
}
}
}
@@ -294,7 +294,7 @@ function get_package_contents(string $export_type, int $export_item_id, bool $in
if (cacti_sizeof($nfiles)) {
foreach ($nfiles as $file) {
if (str_contains($file['file'], '.xml')) {
$files = array_merge($files, find_dependent_files(file_get_contents($file['file']), $file));
$files = array_merge($files, find_dependent_files(file_get_contents($file['file']), true));
}
}
}
+2 -4
View File
@@ -450,8 +450,7 @@ function export() : void {
$(function() {
$('#export_type').change(function() {
strURL = urlPath+'package.php';
strURL += '?header=false';
strURL += '&export_type='+$('#export_type').val();
strURL += '?export_type='+$('#export_type').val();
strURL += '&author='+$('#author').val();
strURL += '&homepage='+escape($('#homepage').val());
strURL += '&email='+$('#email').val();
@@ -462,8 +461,7 @@ function export() : void {
$('#export_item_id').change(function() {
strURL = urlPath+'package.php';
strURL += '?header=false';
strURL += '&export_type='+$('#export_type').val();
strURL += '?export_type='+$('#export_type').val();
strURL += '&export_item_id='+$('#export_item_id').val();
strURL += '&author='+$('#author').val();
strURL += '&homepage='+escape($('#homepage').val());
+20 -1
View File
@@ -1893,7 +1893,26 @@ function get_repo_file(string $repo_id, string $filename = 'package.manifest', b
$repoloc = str_replace('github.com', 'raw.githubusercontent.com', $repo['repo_location']);
$file = $repoloc . '/' . $repo['repo_branch'] . '/' . $filename;
$data = file_get_contents($file);
if ($repo['repo_api_key'] != '') {
$options = [
'https' => [
'method' => 'GET',
'header' => 'Authorization: Bearer ' . $repo['repo_api_key']
]
];
$context = stream_context_create($options);
} else {
$options = [
'https' => [
'method' => 'GET',
]
];
$context = stream_context_create($options);
}
$data = file_get_contents($file, false, $context);
if ($data != '') {
return $data;
+20 -1
View File
@@ -96,7 +96,26 @@ function form_save() : void {
$file = $repoloc . '/' . $save['repo_branch'] . '/package.manifest';
$data = file_get_contents($file);
if ($save['repo_api_key'] != '') {
$options = [
'https' => [
'method' => 'GET',
'header' => 'Authorization: Bearer ' . $save['repo_api_key']
]
];
$context = stream_context_create($options);
} else {
$options = [
'https' => [
'method' => 'GET',
]
];
$context = stream_context_create($options);
}
$data = file_get_contents($file, false, $context);
if ($data != '') {
raise_message('repo_exists', __('The Repo \'%s\' is Reachable on GitHub.', $save['name']), MESSAGE_LEVEL_INFO);