chore: prevent corner case issue and fix php warning

* Update remoteerror in flashback.ini if it gets out of sync with gitratelimit (can happen during testing if you delete flashbackup.ini)
* Fix php warning for retry_after
This commit is contained in:
ljm42
2024-09-05 17:26:31 -07:00
parent 3f84b6bbfd
commit fd4605b956

View File

@@ -331,8 +331,10 @@ if (file_exists($rateLimitFile)) {
$rateLimitRetryTimestamp = (int)@file_get_contents($rateLimitFile);
$rateLimitRetryAfter = $rateLimitRetryTimestamp - time();
if ($rateLimitRetryAfter > 0) {
$msg = !empty($arrState['remoteerror']) ? $arrState['remoteerror'] : 'You are being rate limited - try again in '.$rateLimitRetryAfter.' seconds.';
response_complete(406, array('error' => $msg));
if (empty($arrState['remoteerror'])) {
$arrState['remoteerror'] = 'You are being rate limited - try again in '.$rateLimitRetryAfter.' seconds.';
}
response_complete(406, array('error' => $arrState['remoteerror']));
} else {
unlink($rateLimitFile);
$arrState['remoteerror'] = "";
@@ -431,13 +433,15 @@ if (!empty($json['warn'])) {
}
// check if being rate limited by keyserver
if ($json['retry_after']) {
if (!empty($json['retry_after'])) {
// add five minute margin to ensure remote rate limit is cleared
$rateLimitRetryAfter = $json['retry_after'] + 5*60;
$rateLimitRetryTimestamp = time() + $rateLimitRetryAfter;
file_put_contents($rateLimitFile, $rateLimitRetryTimestamp);
$msg = !empty($arrState['remoteerror']) ? $arrState['remoteerror'] : 'You are being rate limited - try again in '.$rateLimitRetryAfter.' seconds.';
response_complete(406, array('error' => $msg));
if (empty($arrState['remoteerror'])) {
$arrState['remoteerror'] = 'You are being rate limited - try again in '.$rateLimitRetryAfter.' seconds.';
}
response_complete(406, array('error' => $arrState['remoteerror']));
}
if (empty($json['ssh_privkey']) || empty($json['ssh_pubkey'])) {