Backup API script broke after upgrade

Started by pyrodex, July 26, 2024, 11:46:20 AM

Previous topic - Next topic
I use the backup api to pull a configuration file down and store it elsewhere as a precaution but this stopped working after the upgrade. Here is the command I am using to pull the backup config via API:


/usr/bin/curl -k -u "$key":"$secret" https://$HOST/api/core/backup/download/this -o $PFPATH/$(/bin/date +%Y%m%d).xml


I am getting an error back now:


{"errorMessage":"Unexpected error, check log for details"}


I can't find anything in any log on the OS level showing anything strange.

Thanks!


Quote from: franco on July 26, 2024, 11:47:13 AM
Likely https://github.com/opnsense/core/commit/897d3cce

# opnsense-patch 897d3cce


Cheers,
Franco

Same error after applying the patch. Do I need to restart any services for it to take affect?

Maybe applied twice? Worth checking the error log as it mentions... :)

Quote from: franco on July 26, 2024, 01:38:58 PM
Maybe applied twice? Worth checking the error log as it mentions... :)

This is the error reported by the CRASH reporter, there are no other errors in any other logs.


[26-Jul-2024 05:02:45 America/New_York] ArgumentCountError: Too few arguments to function OPNsense\Mvc\Response::setContentType(), 1 passed in /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php on line 200 and exactly 2 expected in /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Response.php:64
Stack trace:
#0 /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php(200): OPNsense\Mvc\Response->setContentType('application/oct...')
#1 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Dispatcher.php(165): OPNsense\Core\Api\BackupController->downloadAction('this')
#2 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(156): OPNsense\Mvc\Dispatcher->dispatch(Object(OPNsense\Mvc\Request), Object(OPNsense\Mvc\Response), Object(OPNsense\Mvc\Session))
#3 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(139): OPNsense\Mvc\Router->performRequest(Object(OPNsense\Mvc\Dispatcher))
#4 /usr/local/opnsense/www/api.php(36): OPNsense\Mvc\Router->routeRequest('/api/core/backu...', Array)
#5 {main}

Quote from: pyrodex on July 26, 2024, 01:40:53 PM
Quote from: franco on July 26, 2024, 01:38:58 PM
Maybe applied twice? Worth checking the error log as it mentions... :)

This is the error reported by the CRASH reporter, there are no other errors in any other logs.


[26-Jul-2024 05:02:45 America/New_York] ArgumentCountError: Too few arguments to function OPNsense\Mvc\Response::setContentType(), 1 passed in /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php on line 200 and exactly 2 expected in /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Response.php:64
Stack trace:
#0 /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php(200): OPNsense\Mvc\Response->setContentType('application/oct...')
#1 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Dispatcher.php(165): OPNsense\Core\Api\BackupController->downloadAction('this')
#2 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(156): OPNsense\Mvc\Dispatcher->dispatch(Object(OPNsense\Mvc\Request), Object(OPNsense\Mvc\Response), Object(OPNsense\Mvc\Session))
#3 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(139): OPNsense\Mvc\Router->performRequest(Object(OPNsense\Mvc\Dispatcher))
#4 /usr/local/opnsense/www/api.php(36): OPNsense\Mvc\Router->routeRequest('/api/core/backu...', Array)
#5 {main}

I have exactly the same CRASH report....

The crash report clearly says setContentType() second argument is missing which the patch sets to a default value if omitted. I can't test at the moment but I'd like to trust my colleuage on that patch for now.


Cheers,
Franco

July 26, 2024, 03:12:55 PM #7 Last Edit: July 26, 2024, 03:18:09 PM by jazix
Changing line 200 in /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php to this fixes the issue:

$this->response->setContentType('application/octet-stream', 'UTF-8');

Or just pulling that Git commit haha.

July 26, 2024, 03:59:42 PM #8 Last Edit: July 26, 2024, 04:26:19 PM by pyrodex
Quote from: jazix on July 26, 2024, 03:12:55 PM
Changing line 200 in /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php to this fixes the issue:

$this->response->setContentType('application/octet-stream', 'UTF-8');

Or just pulling that Git commit haha.

I did but it doesn't touch that file. Also this suggested change doesn't fix the error code I am reporting, I modified the file by hand for line 200 and still doesn't resolve it and throws the same issue. I wonder if my CURL for the backup call needs to be updated to 24.7 so asking that question again.


root@firewall:~ # opnsense-patch 897d3cce
Found local copy of 897d3cce, skipping fetch.
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|From 897d3cce3a0b5117450ff6c36db0635cf2e19591 Mon Sep 17 00:00:00 2001
|From: Ad Schellevis <ad@opnsense.org>
|Date: Fri, 26 Jul 2024 10:22:24 +0200
|Subject: [PATCH] MVC: Response->setContentType() default to empty,  closes
| https://github.com/opnsense/core/pull/7655
|
|---
| src/opnsense/mvc/app/library/OPNsense/Mvc/Response.php | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
|diff --git a/src/opnsense/mvc/app/library/OPNsense/Mvc/Response.php b/src/opnsense/mvc/app/library/OPNsense/Mvc/Response.php
|index 4efd7b6069..b003b25b54 100644
|--- a/src/opnsense/mvc/app/library/OPNsense/Mvc/Response.php
|+++ b/src/opnsense/mvc/app/library/OPNsense/Mvc/Response.php
--------------------------
Patching file opnsense/mvc/app/library/OPNsense/Mvc/Response.php using Plan A...
Reversed (or previously applied) patch detected!  Assuming -R.Hunk #1 succeeded at 61.
done
All patches have been applied successfully.  Have a nice day.
root@firewall:~ #