LibreBooking / docker

Librebooking as a docker container
GNU General Public License v3.0
11 stars 9 forks source link

Accessing REST API #52

Closed ayuser123 closed 1 year ago

ayuser123 commented 1 year ago

Hi,

Running docker build 2.8.6-2.1.0 (https://hub.docker.com/layers/librebooking/librebooking/2.8.6-2.1.0/images/sha256-32b6cbd1641d6e78b80ca8f259b3051edb5e744f0f83a8b88db4f2d879bdfb73?context=explore), I'm trying to use the REST API to manage librebooking, but my requests are getting an "HTTP 500 Internal Server Error" reply.

Logs show "/var/www/html/Web/Services/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration"

colisee commented 1 year ago

Hi @ayuser123,

could you share with me:

  1. Your docker-compose.yml file
  2. The full logs
  3. The way you invoke the REST API (I am not familiar with them)
ayuser123 commented 1 year ago
  1. yml: docker-compose.yml.txt

  2. log produced from API request: 172.29.0.1 - - [31/Jul/2023:17:59:31 -0400] "POST /Web/Services/index.php/Authentication/Authenticate/ HTTP/1.1" 500 805 "-" "-" [Mon Jul 31 17:59:31.328416 2023] [core:alert] [pid 49] [client 172.29.0.1:53546] /var/www/html/Web/Services/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

  3. Request/Reply (invoked using Postman): image

colisee commented 1 year ago

Hi @ayuser123,

I believe that the module headers is not enabled in the image/container.

Could you please try the following command:

sudo docker exec -t librebooking bash -c "a2enmod headers && service apache2 restart"

If you confirm it works, then I will make the changes and issue a new image release.

ayuser123 commented 1 year ago

Hi,

Yes enabling the headers in the apache server helped with the 500 error. Note that I had to edit the config.php file manually to enable the API, it is not enabled by default (and not configurable from the web GUI).

However now the reply is returned with an empty body. image

logs from the terminal show the following error: [Wed Aug 02 14:31:10.182660 2023] [php:warn] [pid 44] [client 172.29.0.1:44208] PHP Warning: Undefined array key "request" in /var/www/html/lib/WebService/Slim/SlimServiceRegistration.php on line 120

colisee commented 1 year ago

Work in progress

Docker project

Bug:

Upstream project

Bug:

Investigation:

colisee commented 1 year ago

Hi @ayuser123 ,

I found an issue/bug with the program lib/Common/Date.php as shown above. Once I fixed the line:

Capture d’écran 2023-08-03 163957

Could you try to make the same program modification inside your running container?

ayuser123 commented 1 year ago

Hi,

Thanks for all your help with this!

Local changes summarized:

I am able to get the /Web/Services description page, but note that this was working for me earlier as well.

Unfortunately, I'm still getting the same "empty" reply body with the "Undefined array key" warning as described earlier.

What build of the docker image are you testing with?

colisee commented 1 year ago

Hi,

I am using the image: librebooking/librebooking:develop-2.1.0. I just confirmed that the authentication does not work with the stable version librebooking/librebooking:2.8.6-2.1.0. A fix was brought to the upstream project after the release 2.8.6 was published.

Here are the steps that I am following:

  1. Stop any running instance and delete the existing volumes
    docker compose down -v
  2. Start a new instance from scratch
    docker compose up -d
  3. Once the containers are ready, initialize the application by pointing your web browser to http://localhost/Web/install
  4. Enable the headers module
    docker exec -t librebooking a2enmod headers
    docker exec -t librebooking service apache2 restart
  5. Enable the librebooking api service
    docker exec -t -u www-data librebooking sed -E 's:(.*api.*enabled.* = .)false:\1true:' -i config/config.php
  6. Fix lib/Common/Date.php
    docker exec -t -u www-data librebooking sed -i lib/Common/Date.php -e 's:minutes = intval((\$this->seconds / 60) % 60);:minutes = intval(\$this->seconds / 60) % 60;:'
  7. Authenticate with the api (in my case: user = admin and password = LibrebookinG)
    curl -X POST http://localhost/Web/Services/Authentication/Authenticate -H 'Content-Type: application/json' -d '{"username":"admin","password":"LibrebookinG"}'

If you confirm the above works for you as well, then I will:

  1. Create a fix release for the apache headers (librebooking/librebooking:develop-2.1.1)
  2. Submit a pull-request to the upstream project in order to fix Date.php
ayuser123 commented 1 year ago

yes, thanks, we are now able to authenticate on a different docker instance using the above steps! :)

 {
    "links": [
        {
            "href": "[http://x.x.x.x:8080/Web/Services/Authentication/SignOut"](http://x.x.x.x:8080/Web/Services/Authentication/SignOut%22),
            "title": "logout"
        }
    ],
    "message": null,
    "sessionToken": "d107894fd92d46821cc641cfdc7c1fc94e80059ad31cccb321",
    "sessionExpires": "2023-08-04T20:56:17+0000",
    "userId": "2",
    "isAuthenticated": true,
    "version": "2.8"
}

Is there a way to do this without deleting the existing volumes? If I destroy only the librebooking_html volume, will the user/reservation/schedules/resources/etc. data be lost?

colisee commented 1 year ago

Well done @ayuser123 !

The reason I wanted you to delete the 2 volumes was to make sure the fix worked on a "clean" environment.

At this stage, I believe that you can keep your 2 volumes, as long as you perform steps 4 through 6 on your running librebooking instance.

This issue will be closed, when I create the docker release 2.1.1 (with the Dockerfile fix). New images will be available on the docker hub, but the api won't work since the bug comes from the upstream project. Eventually, the bug (Date.php) will be fixed in upstream and made available on a future docker image.