Skip to content

Commit

Permalink
changed the controllers/Repo/Mirror/Rpm.php to check /repodata/repomd…
Browse files Browse the repository at this point in the history
….xml instead of the /repodata directory. Some RPM servers are configured to prohibit access to the directory itself
  • Loading branch information
hyung-hwan authored and lbr38 committed Nov 7, 2023
1 parent d48c2e5 commit fa14625
Show file tree
Hide file tree
Showing 21 changed files with 242 additions and 141 deletions.
8 changes: 4 additions & 4 deletions www/controllers/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct()
* Check if authentication is valid from data sent
*/
if (!$this->authenticationController->valid($this->authHeader, $this->data)) {
self::returnError(401, 'Bad credentials.');
self::returnError(401, 'Bad credentials');
}

/**
Expand All @@ -98,10 +98,10 @@ public function __construct()
* Check if method and URI are specified
*/
if (empty($_SERVER['REQUEST_METHOD'])) {
throw new Exception('No method specified.');
throw new Exception('No method specified');
}
if (empty($_SERVER['REQUEST_URI'])) {
throw new Exception('No route specified.');
throw new Exception('No route specified');
}
}

Expand All @@ -124,7 +124,7 @@ public function run()
* Check if route is valid by checking if corresponding controller exists
*/
if (!file_exists(ROOT . '/controllers/Api/' . ucfirst($this->route) . '/' . ucfirst($this->route) . '.php')) {
throw new Exception('No matching route.');
throw new Exception('No matching route');
}

$apiControllerPath = '\Controllers\Api\\' . ucfirst($this->route) . '\\' . ucfirst($this->route);
Expand Down
62 changes: 55 additions & 7 deletions www/controllers/Api/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,67 @@ public function getHostAuthenticationStatus()
public function valid(string $authHeader = null, object $data = null)
{
/**
* If API key is specified through the Authorization header
* e.g. "Authorization: Bearer <API_KEY>"
* New authentication method
*/
if (!empty($authHeader) && strpos($authHeader, 'Bearer ') === 0) {

/**
* If API key or host Id+token is specified through the Authorization header
* e.g.
* "Authorization: Bearer <API_KEY>"
* "Authorization: Host <HOST_ID>:<HOST_TOKEN>"
*/
if (!empty($authHeader)) {
if (strpos($authHeader, 'Bearer ') === 0) {
/**
* Extract the token
* Remove "Bearer " from the header
*/
$apiKey = substr($authHeader, 7);
}

/**
* Extract the token
* Remove "Bearer " from the header
* If host Id+token are specified through the Authorization header
*/
$apiKey = substr($authHeader, 7);
if (strpos($authHeader, 'Host ') === 0) {
/**
* Extract the host Id and token
* Remove "Host " from the header
*/
$authIdToken = substr($authHeader, 5);

/**
* Split the host Id and token
*/
$authIdToken = explode(':', $authIdToken);

/**
* Check if host Id and token are specified
*/
if (count($authIdToken) != 2) {
return false;
}

/**
* Set host authId and token
*/
$id = $authIdToken[0];
$token = $authIdToken[1];
}
}

/**
* Old authentication method
*/

/**
* If API key is specified in data
*/
if (!empty($data->apikey)) {
$apiKey = $data->apikey;
}

/**
* If host authId and token are specified
* If host authId and token are specified in data
*/
if (!empty($data->id)) {
$id = $data->id;
Expand Down
32 changes: 31 additions & 1 deletion www/controllers/Api/Snapshot/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,37 @@ public function execute()
* Reconstruct a snapshot
* https://repomanager.mydomain.net/api/v2/snapshot/$this->snapId/reconstruct
*/
if ($this->action == 'reconstruct') {
if ($this->action == 'rebuild' and !empty($this->data->gpgSign)) {
/**
* Same code as controllers/ajax/browse.php
* TODO : find a way to not duplicate code
*/
$myoperation = new \Controllers\Operation\Operation();

if ($myrepo->existsSnapId($this->snapId) !== true) {
throw new Exception('Invalid repo snapshot ID');
}

if ($this->data->gpgSign != 'yes' and $this->data->gpgSign != 'no') {
throw new Exception('Invalid GPG Resign value');
}

/**
* Create a json file that defines the operation to execute
*/
$params = array();
$params['action'] = 'reconstruct';
$params['snapId'] = $this->snapId;
$params['targetGpgResign'] = $this->data->gpgSign;

/**
* Execute the operation
*/
$myoperation->execute(array($params));

unset($myoperation);

return array('results' => 'Snapshot metadata rebuild started');
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions www/controllers/Operation/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public function validateForm(array $operations_params)
Param\Name::check($targetName);
Param\GpgCheck::check($operation_params['targetGpgCheck']);
Param\GpgResign::check($operation_params['targetGpgResign']);
// Param\SourcePackageInc::check($operation_params['targetSourcePackage']);

if ($packageType == 'deb') {
if (!empty($operation_params['targetPackageTranslation'])) {
Expand Down Expand Up @@ -317,7 +316,6 @@ public function validateForm(array $operations_params)
}

Param\Arch::check($operation_params['targetArch']);
// Param\SourcePackageInc::check($operation_params['targetSourcePackage']);

if ($packageType == 'deb') {
if (!empty($operation_params['targetPackageTranslation'])) {
Expand Down
19 changes: 0 additions & 19 deletions www/controllers/Operation/Param/SourcePackageInc.php

This file was deleted.

2 changes: 0 additions & 2 deletions www/controllers/Planification.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ public function exec()
'targetGpgResign' => $this->targetGpgResign,
'targetEnv' => $this->targetEnv,
'targetArch' => $this->repo->getArch(),
// 'targetSourcePackage' => $this->repo->getSourcePackage(),
'onlySyncDifference' => $this->onlySyncDifference
);

Expand Down Expand Up @@ -609,7 +608,6 @@ public function exec()
'targetGpgResign' => $this->targetGpgResign,
'targetEnv' => $this->targetEnv,
'targetArch' => $this->repo->getArch(),
// 'targetSourcePackage' => $this->repo->getSourcePackage(),
'onlySyncDifference' => $this->onlySyncDifference
);

Expand Down
2 changes: 1 addition & 1 deletion www/controllers/Repo/Mirror/Rpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function mirror()
*/
foreach ($this->archUrls as $arch => $archUrls) {
foreach ($archUrls as $url) {
if (!\Controllers\Common::urlFileExists($url . '/repodata', $this->sslCustomCertificate, $this->sslCustomPrivateKey)) {
if (!\Controllers\Common::urlFileExists($url . '/repodata/repomd.xml', $this->sslCustomCertificate, $this->sslCustomPrivateKey)) {
// $this->logOutput(' - ' . $url . ' (unreachable or nothing here?)' . PHP_EOL);

/**
Expand Down
1 change: 0 additions & 1 deletion www/controllers/Repo/Operation/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __construct(string $poolId, array $operationParams)
$requiredParams[] = 'source';
$requiredParams[] = 'targetGpgCheck';
$requiredParams[] = 'targetGpgResign';
// $requiredParams[] = 'targetSourcePackage';
}

/**
Expand Down
1 change: 0 additions & 1 deletion www/controllers/Repo/Operation/Duplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct(string $poolId, array $operationParams)
*/
$operationParams['targetGpgResign'] = $this->repo->getSigned();
$operationParams['targetArch'] = $this->repo->getArch();
// $operationParams['targetSourcePackage'] = $this->repo->getSourcePackage();
$operationParams['targetPackageTranslation'] = $this->repo->getPackageTranslation();

/**
Expand Down
1 change: 0 additions & 1 deletion www/controllers/Repo/Operation/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(string $poolId, array $operationParams)
* Check and set others operation parameters
*/
$requiredParams = array('targetGpgCheck', 'targetGpgResign', 'targetArch', 'onlySyncDifference');
// $optionnalParams = array('targetEnv', 'targetSourcePackage', 'targetPackageTranslation');
$optionnalParams = array('targetEnv', 'targetPackageTranslation');
$this->operationParamsCheck('Update repo', $operationParams, $requiredParams);
$this->operationParamsSet($operationParams, $requiredParams, $optionnalParams);
Expand Down
6 changes: 3 additions & 3 deletions www/models/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function getHostWithKernel(string $kernel)
$hosts = array();

try {
$stmt = $this->db->prepare("SELECT Hostname, Ip, Os, Os_family FROM hosts
$stmt = $this->db->prepare("SELECT Id, Hostname, Ip, Os, Os_family FROM hosts
WHERE Kernel = :kernel
AND Status = 'active'
ORDER BY Hostname ASC");
Expand All @@ -449,7 +449,7 @@ public function getHostWithProfile(string $profile)
$hosts = array();

try {
$stmt = $this->db->prepare("SELECT Hostname, Ip, Os, Os_family FROM hosts
$stmt = $this->db->prepare("SELECT Id, Hostname, Ip, Os, Os_family FROM hosts
WHERE Profile = :profile
AND Status = 'active'
ORDER BY Hostname ASC");
Expand Down Expand Up @@ -749,7 +749,7 @@ public function listRebootRequired()
{
$hosts = array();

$result = $this->db->query("SELECT Hostname, Ip, Os, Os_family FROM hosts WHERE Status = 'active' AND Reboot_required = 'true' ORDER BY Hostname ASC");
$result = $this->db->query("SELECT Id, Hostname, Ip, Os, Os_family FROM hosts WHERE Status = 'active' AND Reboot_required = 'true' ORDER BY Hostname ASC");

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$hosts[] = $row;
Expand Down
40 changes: 32 additions & 8 deletions www/public/resources/js/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ $(document).on('mouseenter',".hosts-charts-list-label[chart-type=kernel]",functi
/**
* Create a new <div> hosts-charts-list-label-hosts-list
*/
$('footer').append('<div class="hosts-charts-list-label-hosts-list">Loading<img src="/assets/images/loading.gif" class="icon"/></div>');
$('footer').append('<div class="hosts-charts-list-label-hosts-list"><span>Loading<img src="/assets/images/loading.gif" class="icon"/></span></div>');

$('.hosts-charts-list-label-hosts-list').css({
top: e.pageY - $('.hosts-charts-list-label-hosts-list').height() / 2,
left: e.pageX - $('.hosts-charts-list-label-hosts-list').width() / 2
});

$('.hosts-charts-list-label-hosts-list').show();
$('.hosts-charts-list-label-hosts-list').css('display', 'flex');

getHostWithKernel(kernel);
});
Expand All @@ -389,14 +389,14 @@ $(document).on('mouseenter',".hosts-charts-list-label[chart-type=profile]",funct
/**
* Create a new <div> hosts-charts-list-label-hosts-list
*/
$('footer').append('<div class="hosts-charts-list-label-hosts-list">Loading<img src="/assets/images/loading.gif" class="icon"/></div>');
$('footer').append('<div class="hosts-charts-list-label-hosts-list"><span>Loading<img src="/assets/images/loading.gif" class="icon"/></span></div>');

$('.hosts-charts-list-label-hosts-list').css({
top: e.pageY - $('.hosts-charts-list-label-hosts-list').height() / 2,
left: e.pageX - $('.hosts-charts-list-label-hosts-list').width() / 2
});

$('.hosts-charts-list-label-hosts-list').show();
$('.hosts-charts-list-label-hosts-list').css('display', 'flex');

getHostWithProfile(profile);
});
Expand All @@ -405,6 +405,12 @@ $(document).on('mouseenter',".hosts-charts-list-label[chart-type=profile]",funct
* Event: Remove all hosts list <div> from the DOM when mouse has leave
*/
$(document).on('mouseleave',".hosts-charts-list-label",function () {
if ($('.hosts-charts-list-label-hosts-list:hover').length == 0) {
$('.hosts-charts-list-label-hosts-list').remove();
}
});

$(document).on('mouseleave',".hosts-charts-list-label-hosts-list",function () {
$('.hosts-charts-list-label-hosts-list').remove();
});

Expand Down Expand Up @@ -1028,6 +1034,9 @@ function getHostWithKernel(kernel)
hostsArray = jQuery.parseJSON(jsonValue.message);
hostsArray.forEach(obj => {
Object.entries(obj).forEach(([key, value]) => {
if (key == 'Id') {
id = value;
}
if (key == 'Hostname') {
hostname = value;
}
Expand All @@ -1041,10 +1050,16 @@ function getHostWithKernel(kernel)
os_family = value;
}
});
hosts += '<div>' + printOsIcon(os, os_family) + '<span>' + hostname + ' (' + ip + ') </span></div>';

hosts += '<div class="flex align-item-center column-gap-10 div-generic-blue margin-bottom-0">';
hosts += '<div>' + printOsIcon(os, os_family) + '</div>';
hosts += '<div class="flex flex-direction-column row-gap-4">';
hosts += '<span class="copy"><a href="/host?id=' + id + '" target="_blank" rel="noopener noreferrer">' + hostname + '</a></span>';
hosts += '<span class="copy font-size-12 lowopacity-cst">' + ip + '</span>';
hosts += '</div></div>';
});

$('.hosts-charts-list-label-hosts-list').html('<div class="grid row-gap-4">' + hosts + '</div>');
$('.hosts-charts-list-label-hosts-list').html(hosts);
},
error: function (jqXHR, textStatus, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
Expand Down Expand Up @@ -1075,6 +1090,9 @@ function getHostWithProfile(profile)
hostsArray = jQuery.parseJSON(jsonValue.message);
hostsArray.forEach(obj => {
Object.entries(obj).forEach(([key, value]) => {
if (key == 'Id') {
id = value;
}
if (key == 'Hostname') {
hostname = value;
}
Expand All @@ -1088,10 +1106,16 @@ function getHostWithProfile(profile)
os_family = value;
}
});
hosts += '<div>' + printOsIcon(os, os_family) + '<span>' + hostname + ' (' + ip + ') </span></div>';

hosts += '<div class="flex align-item-center column-gap-10 div-generic-blue margin-bottom-0">';
hosts += '<div>' + printOsIcon(os, os_family) + '</div>';
hosts += '<div class="flex flex-direction-column row-gap-4">';
hosts += '<span class="copy"><a href="/host?id=' + id + '" target="_blank" rel="noopener noreferrer">' + hostname + '</a></span>';
hosts += '<span class="copy font-size-12 lowopacity-cst">' + ip + '</span>';
hosts += '</div></div>';
});

$('.hosts-charts-list-label-hosts-list').html('<div class="grid row-gap-4">' + hosts + '</div>');
$('.hosts-charts-list-label-hosts-list').html(hosts);
},
error: function (jqXHR, textStatus, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
Expand Down
Loading

0 comments on commit fa14625

Please sign in to comment.