• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    API Error with PHP 8.1

    Scheduled Pinned Locked Moved
    General
    2
    8
    836
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MarkG
      last edited by

      Just upgraded to Ubuntu 22.04 with PHP 8.1 (from 20.04 with PHP 7.4), also updated FOG from 1.5.9 to 1.5.10 - so I’m not sure quite where this error lies, it might be my code.

      I have an application that uses the FOG API. I haven’t changed anything in this and it has always worked before the upgrade.

      Specifically, when I use the ‘edit’ path to assign an image to a host:

      PUT request
      URL host/[host ID]/edit
      JSON ["imageID": int]
      

      I get the following in the PHP error log:

      [proxy_fcgi:error] [pid 1166] [client 127.0.0.1:42750] AH01071: Got error '
      PHP message: 
      PHP Warning:  Undefined property: stdClass::$name in /var/www/fog/lib/router/route.class.php on line 623
      PHP message: 
      PHP Warning:  Undefined property: stdClass::$name in /var/www/fog/lib/router/route.class.php on line 626'
      

      Looking quickly at the code it seems to be something to do with not having a ‘name’ parameter in the JSON, but Ive never needed that before and I’ve no idea what I would set it to. The request does seem to work, but clearly something is wrong somewhere.

      1 Reply Last reply Reply Quote 0
      • M
        MarkG
        last edited by

        If I set a ‘name’ field to an empty string it deletes the hostname for the host.
        If I set a ‘name’ field to the hostname of the host, the check it’s trying to do matches and gives me an ‘Already created’ error.
        So it looks like there is no parameter I can set ‘name’ to that doesn’t cause me a problem. I might be misunderstanding the code, but having a check which fails if the host already exists on an endpoint called ‘edit’ seems backwards?

        Tom ElliottT 1 Reply Last reply Reply Quote 0
        • Tom ElliottT
          Tom Elliott @MarkG
          last edited by Tom Elliott

          @MarkG The issue is if you change the name to another host that already exists:

          SO let’s just use the example case here:

          Say you have host named abc with id 1
          Say you have a host named def with id 2

          You are trying to edit id 2:

          You decide to change the hostname to abc… Which thing should we do, delete the existing abc host, delete the existing host? Instead we error out.

          That said, I believe I see and have pushed what I think will fix this issue for you.

          Please repull dev-branch, and you shouldn’t be required to have the name value in the json payload.

          The other piece, while it was a warning, it definitely wasn’t an issue.

          Now when you add the name parameter, if you set as nothing it should fail, so I’m not sure if there is a host in yoru database with that name?

          If so, please let me know. I suspect you now have 2 hosts in your host table, one with an empty name and one with the original name?

          SELECT * from hosts where host in ('', '<original_hostname_here>');

          From a MYSQL prompt. I will likely want to ensure a name field is properly set in the router code

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          Tom ElliottT M 2 Replies Last reply Reply Quote 0
          • Tom ElliottT
            Tom Elliott @Tom Elliott
            last edited by

            @Tom-Elliott Router code should now expect a name item for the edit param if you’re passing in a name property as part of the json payload.

            Basically

            ‘name’ = ‘’ will fail

            A payload completely missing name should work just like it did before without the warning messages.

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            M 1 Reply Last reply Reply Quote 0
            • M
              MarkG @Tom Elliott
              last edited by

              @Tom-Elliott said in API Error with PHP 8.1:

              You decide to change the hostname to abc… Which thing should we do, delete the existing abc host, delete the existing host? Instead we error out.

              Oh that’s a very good point, I had not considered that.

              The issue I’m seeing is essentially that it fails when I’m trying to set ‘name’ to the value it already has, so if I have to send ‘name’ I have to change it, which isn’t useful. (eg I try to edit host id 1 and include a name of abc, that fails).

              Happy to try pulling dev branch but it’ll take a few days, I’m running the release so I need to switch a few things around.

              When I set name to “”, it did set the hostname to “”. I immediately corrected it in the database so I’m afraid I can’t provide the output you’re looking for.

              1 Reply Last reply Reply Quote 0
              • M
                MarkG @Tom Elliott
                last edited by

                @Tom-Elliott The change on dev-branch has fixed one of the warnings but not both. I’m still getting

                [proxy_fcgi:error] [pid 5049] [client 127.0.0.1:59748] AH01071: Got error '
                PHP message: 
                PHP Warning:  Undefined property: stdClass::$name in /var/www/fog/lib/router/route.class.php on line 629'
                

                Swapping lines 629 and 630 fixed that warning for me. Thanks.

                Tom ElliottT 1 Reply Last reply Reply Quote 0
                • Tom ElliottT
                  Tom Elliott @MarkG
                  last edited by

                  @MarkG Can you describe more?

                  Here’s what I see in dev-branch:

                          $var_name = false;
                          if (property_exists($vars, 'name')) {
                              $exists = self::getClass($classname)
                                  ->getManager()
                                  ->exists($vars->name);
                              $var_name = strtolower($vars->name);
                              if (!$var_name) {
                                  self::setErrorMessage(
                                      _('A name must be defined if using the "name" property'),
                                      HTTPResponseCodes::HTTP_FORBIDDEN
                                  );
                              }
                          }
                  

                  629 is the start of the self::setErrorMessage

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    MarkG @Tom Elliott
                    last edited by

                    @Tom-Elliott Apologies, I don’t know what went wrong there but somehow I got an incomplete version of your changes. git is a confusing beast to me :). I’ve now checked again that I’m running dev-branch and I can confirm that all the warnings have gone.

                    Thanks again.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post

                    227

                    Online

                    12.0k

                    Users

                    17.3k

                    Topics

                    155.2k

                    Posts
                    Copyright © 2012-2024 FOG Project