Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP error Invalid argument supplied for foreach() #168

Closed
tuxmaster5000 opened this issue Jan 1, 2020 · 23 comments · Fixed by #411
Closed

PHP error Invalid argument supplied for foreach() #168

tuxmaster5000 opened this issue Jan 1, 2020 · 23 comments · Fixed by #411

Comments

@tuxmaster5000
Copy link

tuxmaster5000 commented Jan 1, 2020

Steps to reproduce

  1. Click on system information

Expected behaviour

That no error will get logged.

Actual behaviour

On every call this error will be logged:
"message":"Invalid argument supplied for foreach() at /var/www/html/owncloud/apps/serverinfo/lib/OperatingSystems/DefaultOs.php#120"

Server configuration

Operating system: CentOS 7.7

Web server: Apache

Database: MariaDB

PHP version: 7.2

Nextcloud version: 17.0.2

Updated from an older Nextcloud/ownCloud or fresh install:
Updated from older

Where did you install Nextcloud from:
From the nextcloud web site

Signing status:

Signing status ``` No errors have been found. ```

List of activated apps:

App list
Enabled:
  - activity: 2.10.1
  - bruteforcesettings: 1.4.0
  - calendar: 1.7.1
  - cloud_federation_api: 1.0.0
  - dav: 1.13.0
  - dicomviewer: 1.2.1
  - federatedfilesharing: 1.7.0
  - files: 1.12.0
  - files_pdfviewer: 1.6.0
  - files_rightclick: 0.15.1
  - files_sharing: 1.9.0
  - files_videoplayer: 1.6.0
  - gallery: 18.4.0
  - logreader: 2.2.0
  - lookup_server_connector: 1.5.0
  - nextcloud_announcements: 1.6.0
  - notifications: 2.5.0
  - oauth2: 1.5.0
  - password_policy: 1.7.0
  - piwik: 0.5.3
  - privacy: 1.1.0
  - provisioning_api: 1.7.0
  - recommendations: 0.5.0
  - serverinfo: 1.7.0
  - sharebymail: 1.7.0
  - socialsharing_email: 1.0.6
  - support: 1.0.1
  - text: 1.1.1
  - theming: 1.8.0
  - twofactor_backupcodes: 1.6.0
  - twofactor_u2f: 5.0.1
  - updatenotification: 1.7.0
  - viewer: 1.2.0
  - workflowengine: 1.7.0
Disabled:
  - accessibility
  - admin_audit
  - comments
  - encryption
  - federation
  - files_external
  - files_trashbin
  - files_versions
  - firstrunwizard
  - survey_client
  - systemtags
  - user_ldap

Nextcloud configuration:

Config report
{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "speicher.terrortux.de"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "17.0.2.1",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "forcessl": true,
        "maxZipInputSize": 83886080,
        "allowZipDownload": true,
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "25",
        "log_type": "file",
        "loglevel": "1",
        "logfile": "data\/nextcloud.log",
        "logtimezone": "Europe\/Berlin",
        "log_authfailip": true,
        "theme": "",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "forceSSLforSubdomains": true,
        "maintenance": false,
        "asset-pipeline.enabled": true,
        "updatechecker": false,
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "memcache.locking": "\\OC\\Memcache\\APCu",
        "mysql.utf8mb4": true,
        "overwrite.cli.url": "https:\/\/XXXXXXXXX",
        "updater.release.channel": "stable"
    }
}

Are you using external storage, if yes which one: local/smb/sftp/...
no

Are you using encryption: yes/no
no

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...
no



@kesselb kesselb transferred this issue from nextcloud/server Jan 1, 2020
@kesselb
Copy link
Collaborator

kesselb commented Jan 1, 2020

$interfaces = glob('/sys/class/net/*');
is the code in question. Nextcloud is not able to retrieve a list of interfaces. Probably not readable or does not exist?

@tuxmaster5000
Copy link
Author

It exits and it will be readable by the php process:
ps axu |grep php | grep owncloud

apache 23965 0.2 1.3 1086552 56564 ? S 2019 59:36 php-fpm: pool owncloud
apache 23966 0.2 1.0 1083056 43916 ? S 2019 58:50 php-fpm: pool owncloud
apache 23967 0.2 1.1 1081784 48324 ? S 2019 57:38 php-fpm: pool owncloud
apache 23968 0.2 1.3 1083380 54620 ? S 2019 57:26 php-fpm: pool owncloud
apache 23969 0.2 1.2 1081300 48992 ? S 2019 59:05 php-fpm: pool owncloud
apache 23985 0.2 1.2 1083644 51480 ? S 2019 58:13 php-fpm: pool owncloud
apache 24066 0.2 1.3 1086768 54772 ? S 2019 58:36 php-fpm: pool owncloud
apache 24072 0.2 1.3 1081844 55088 ? S 2019 57:58 php-fpm: pool owncloud
apache 24087 0.2 1.2 1081632 52444 ? S 2019 58:26 php-fpm: pool owncloud
apache 25940 0.2 1.1 1081752 44792 ? S 2019 58:06 php-fpm: pool owncloud
apache 26633 0.2 1.2 1080896 51988 ? S 2019 58:15 php-fpm: pool owncloud
apache 26644 0.2 1.4 1087712 57344 ? S 2019 57:32 php-fpm: pool owncloud
apache 28145 0.2 1.3 1080860 55020 ? S 2019 57:44 php-fpm: pool owncloud

sudo -u apache ls /sys/class/net/*

/sys/class/net/eth0:
addr_assign_type broadcast device dormant gro_flush_timeout iflink netdev_group phys_port_name proto_down statistics type
address carrier dev_id duplex ifalias link_mode operstate phys_switch_id queues subsystem uevent
addr_len carrier_changes dev_port flags ifindex mtu phys_port_id power speed tx_queue_len

/sys/class/net/lo:
addr_assign_type carrier dormant ifalias mtu phys_port_name queues tx_queue_len
address carrier_changes duplex ifindex netdev_group phys_switch_id speed type
addr_len dev_id flags iflink operstate power statistics uevent
broadcast dev_port gro_flush_timeout link_mode phys_port_id proto_down subsystem

But selinux will forbids it, because of the system call "df". And the call don't catch an empty array as
result.

type=AVC msg=audit(1577896399.482:87125): avc: denied { getattr } for pid=16337 comm="df" path="/sys/kernel/config" dev="configfs" ino=8161 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:configfs_t:s0 tclass=dir permissive=0
type=SYSCALL msg=audit(1577896399.482:87125): arch=c000003e syscall=4 success=no exit=-13 a0=25a6600 a1=7ffd91817b70 a2=7ffd91817b70 a3=2 items=0 ppid=23968 pid=16337 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="df" exe="/usr/bin/df" subj=system_u:system_r:httpd_t:s0 key=(null)
type=PROCTITLE msg=audit(1577896399.482:87125): proctitle=6466002D54

@kesselb
Copy link
Collaborator

kesselb commented Jan 1, 2020

OK. But the df -T call is happening later. So the line number from the message don't match. Could you share the output of php -r "var_dump(glob('/sys/class/net/*'));"?

@solracsf
Copy link
Member

solracsf commented Jan 8, 2020

Having same issue here.

@kesselb :

sudo -u www-data php -r "var_dump(glob('/sys/class/net/*'));"
array(3) {
  [0]=>
  string(20) "/sys/class/net/ens10"
  [1]=>
  string(19) "/sys/class/net/eth0"
  [2]=>
  string(17) "/sys/class/net/lo"
}

@HigH-HawK
Copy link
Contributor

HigH-HawK commented Mar 13, 2020

@kesselb

Having the same issue in Debian 9.12 (stretch) - PHP 7.2.28 - NC 18.0.2

My output of php -r "var_dump(glob('/sys/class/net/*'));" as the webserver user:

array(2) {
  [0]=>
  string(19) "/sys/class/net/eth0"
  [1]=>
  string(17) "/sys/class/net/lo"
}

I fixed it temporary by adding /sys/class/net/eth0 and /sys/class/net/lo in the open_basedir parameter. But that should not be the final fix.

@kesselb
Copy link
Collaborator

kesselb commented Mar 13, 2020

But that should not be the final fix.

Why not?

@solracsf
Copy link
Member

In my case open_basedir is not used.

@HigH-HawK
Copy link
Contributor

But that should not be the final fix.

Why not?

In my opinion a software should be created as open minded as possible, so it can handle different situations on its own. The user should not be pushed into fiddling with too many configurations.

Best example is from @acs-ferreira since he is not using open_basedir, so my "temporary" fix for me, wouldn't work for him.

@kesselb
Copy link
Collaborator

kesselb commented Mar 13, 2020

Feel free to submit a patch with your suggested solution.

@tuxmaster5000
Copy link
Author

I my case it will result in this:
sudo -u apache scl enable php72 "php -r "var_dump(glob('/sys/class/net/*'));""
array(2) {
[0]=>
string(19) "/sys/class/net/eth0"
[1]=>
string(17) "/sys/class/net/lo"
}
open_basedir is set to:
/var/www/html/owncloud:/tmp/:/dev/urandom:/proc/meminfo

@deajan
Copy link

deajan commented Sep 3, 2020

You need to add the following paths to your open_basedir to work:

/proc/uptime:/proc/cpuinfo:/proc/meminfo:/sys/class/net

A resulting open_basedir directive could look like

php_admin_value[open_basedir] = /var/www/$pool:/dev/urandom:/data:/proc/uptime:/proc/cpuinfo:/proc/meminfo:/sys/class/net```

@tuxmaster5000
Copy link
Author

tuxmaster5000 commented Sep 4, 2020

In my case I have the line:
php_value[open_basedir] = /var/www/html/owncloud:/tmp/:/dev/urandom:/proc/meminfo:/proc/uptime:/proc/cpuinfo:/sys/class/net
But the error comes again.

@deajan
Copy link

deajan commented Sep 4, 2020

@tuxmaster5000 For whatever reason, allowing /sys/class/net isn't recursive to the network interfaces.

I had to adapt my open_basedirl to give it my network adapters:

php_admin_value[open_basedir] = /var/www/$pool:/dev/urandom:/data:/proc/uptime:/proc/cpuinfo:/proc/meminfo:/sys/class/net/eth0:/sys/class/net/lo0```

This made the error go away. Can you confirm ?
You should see more details on the network interfaces GUI in supervision. Please adjust to your network interface names ;)

@HigH-HawK
Copy link
Contributor

As @deajan already mentioned, in some cases allowing /sys/class/net isn't recursive to the network interfaces.

You need to check the content of /sys/class/net to see what adapters are available and then add the full path to your PHP open_basedir parameter.

Examples of full paths:

/sys/class/net/eth0
/sys/class/net/lo
/sys/class/net/lo0
/sys/class/net/en0
/sys/class/net/ensXXX (XXX = digits)

@tuxmaster5000
Copy link
Author

I think the problem is much deeper, because all files under /sys/class/net are symlinks.
In my case:

readlink -f /sys/class/net/eth0
/sys/devices/pci0000:00/0000:00:03.0/virtio0/net/eth0
readlink -f /sys/class/net/lo
/sys/devices/virtual/net/lo

And add /sys/devices/ to open_basedir is an security nightmare I think.

For testing In have added the path, then no error will shown, but php call access all devices. :(

@ozzi-
Copy link

ozzi- commented Oct 1, 2021

For me it was on line 152 (NC 22.1.1)

Error: foreach() argument must be of type array|object, bool given at /var/www/vhosts/XXXXX/XXXXXX/apps/serverinfo/lib/OperatingSystems/DefaultOs.php#152

My "Patch" fixes the error, thus the system tab loads again.
apps/serverinfo/lib/OperatingSystems/DefaultOS.php in getNetworkInterfaces, adding a simple check:

public function getNetworkInterfaces(): array {
	$interfaces = glob('/sys/class/net/*');
	$result = [];
	if(is_bool($interfaces)){  // add this
		return $result;
	}
       . . . 

@RMuetterlein
Copy link

Hello
We have the same problems. When the server info page is called, NC simply crashes with an error page.
System data:
Ubuntu 20.04.3 LTS
PHP 7.4.23
Plesk Obsidian Version 18.0.37 Update #2
Memory limit: 512M
OpenBaseDir: {WEBSPACEROOT}{/}{:}{TMP}{/}:/dev/urandom:/data:/proc/uptime:/proc/cpuinfo:/proc/meminfo:/sys/class/net
Stack-Traces:

{
    "reqId": "YVw@g5CkrUk0I3kQpeGrmgAAAA8",
    "level": 3,
    "time": "2021-10-05T12:01:08+00:00",
    "remoteAddr": "xx.xx.xx.xx",
    "user": "admin",
    "app": "PHP",
    "method": "GET",
    "url": "/index.php/settings/admin/serverinfo",
    "message": {
        "Exception": "Error",
        "Message": "Invalid argument supplied for foreach() at /<<path_to_nc>>/apps/serverinfo/lib/OperatingSystems/DefaultOs.php#149",
        "Code": 0,
        "Trace": [{
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/OperatingSystems/DefaultOs.php",
                "line": 149,
                "function": "onError",
                "class": "OC\\Log\\ErrorHandler",
                "type": "::"
            }, {
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/Os.php",
                "line": 124,
                "function": "getNetworkInterfaces",
                "class": "OCA\\ServerInfo\\OperatingSystems\\DefaultOs",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/Settings/AdminSettings.php",
                "line": 111,
                "function": "getNetworkInterfaces",
                "class": "OCA\\ServerInfo\\Os",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                "line": 138,
                "function": "getForm",
                "class": "OCA\\ServerInfo\\Settings\\AdminSettings",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                "line": 83,
                "function": "formatSettings",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                "line": 149,
                "function": "getSettings",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                "line": 68,
                "function": "getIndexResponse",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 218,
                "function": "index",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 127,
                "function": "executeController",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/App.php",
                "line": 157,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/Route/Router.php",
                "line": 302,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            }, {
                "file": "/<<path_to_nc>>/lib/base.php",
                "line": 993,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/index.php",
                "line": 37,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/<<path_to_nc>>/lib/private/Log/ErrorHandler.php",
        "Line": 92,
        "CustomMessage": "--"
    },
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0",
    "version": "21.0.5.1"
}{
    "reqId": "YVw@g5CkrUk0I3kQpeGrmgAAAA8",
    "level": 3,
    "time": "2021-10-05T12:01:08+00:00",
    "remoteAddr": "xx.xx.xx.xx",
    "user": "admin",
    "app": "PHP",
    "method": "GET",
    "url": "/index.php/settings/admin/serverinfo",
    "message": {
        "Exception": "Error",
        "Message": "opcache_get_status() has been disabled for security reasons at /<<path_to_nc>>/apps/serverinfo/lib/PhpStatistics.php#68",
        "Code": 0,
        "Trace": [{
                "function": "onError",
                "class": "OC\\Log\\ErrorHandler",
                "type": "::"
            }, {
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/PhpStatistics.php",
                "line": 68,
                "function": "opcache_get_status"
            }, {
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/PhpStatistics.php",
                "line": 50,
                "function": "getOPcacheStatus",
                "class": "OCA\\ServerInfo\\PhpStatistics",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/serverinfo/lib/Settings/AdminSettings.php",
                "line": 115,
                "function": "getPhpStatistics",
                "class": "OCA\\ServerInfo\\PhpStatistics",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                "line": 138,
                "function": "getForm",
                "class": "OCA\\ServerInfo\\Settings\\AdminSettings",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                "line": 83,
                "function": "formatSettings",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                "line": 149,
                "function": "getSettings",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                "line": 68,
                "function": "getIndexResponse",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 218,
                "function": "index",
                "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 127,
                "function": "executeController",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/AppFramework/App.php",
                "line": 157,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/Route/Router.php",
                "line": 302,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            }, {
                "file": "/<<path_to_nc>>/lib/base.php",
                "line": 993,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/index.php",
                "line": 37,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/<<path_to_nc>>/lib/private/Log/ErrorHandler.php",
        "Line": 92,
        "CustomMessage": "--"
    },
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0",
    "version": "21.0.5.1"
}{
    "reqId": "YVw@g5CkrUk0I3kQpeGrmgAAAA8",
    "level": 3,
    "time": "2021-10-05T12:01:08+00:00",
    "remoteAddr": "xx.xx.xx.xx",
    "user": "admin",
    "app": "index",
    "method": "GET",
    "url": "/index.php/settings/admin/serverinfo",
    "message": {
        "Exception": "Exception",
        "Message": "Return value of OCA\\ServerInfo\\PhpStatistics::getOPcacheStatus() must be of the type array, null returned",
        "Code": 0,
        "Trace": [{
                "file": "/<<path_to_nc>>/lib/private/AppFramework/App.php",
                "line": 157,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/lib/private/Route/Router.php",
                "line": 302,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            }, {
                "file": "/<<path_to_nc>>/lib/base.php",
                "line": 993,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            }, {
                "file": "/<<path_to_nc>>/index.php",
                "line": 37,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 159,
        "Previous": {
            "Exception": "TypeError",
            "Message": "Return value of OCA\\ServerInfo\\PhpStatistics::getOPcacheStatus() must be of the type array, null returned",
            "Code": 0,
            "Trace": [{
                    "file": "/<<path_to_nc>>/apps/serverinfo/lib/PhpStatistics.php",
                    "line": 50,
                    "function": "getOPcacheStatus",
                    "class": "OCA\\ServerInfo\\PhpStatistics",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/apps/serverinfo/lib/Settings/AdminSettings.php",
                    "line": 115,
                    "function": "getPhpStatistics",
                    "class": "OCA\\ServerInfo\\PhpStatistics",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                    "line": 138,
                    "function": "getForm",
                    "class": "OCA\\ServerInfo\\Settings\\AdminSettings",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                    "line": 83,
                    "function": "formatSettings",
                    "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/apps/settings/lib/Controller/CommonSettingsTrait.php",
                    "line": 149,
                    "function": "getSettings",
                    "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/apps/settings/lib/Controller/AdminSettingsController.php",
                    "line": 68,
                    "function": "getIndexResponse",
                    "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 218,
                    "function": "index",
                    "class": "OCA\\Settings\\Controller\\AdminSettingsController",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 127,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/lib/private/AppFramework/App.php",
                    "line": 157,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/lib/private/Route/Router.php",
                    "line": 302,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::"
                }, {
                    "file": "/<<path_to_nc>>/lib/base.php",
                    "line": 993,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->"
                }, {
                    "file": "/<<path_to_nc>>/index.php",
                    "line": 37,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::"
                }
            ],
            "File": "/<<path_to_nc>>/apps/serverinfo/lib/PhpStatistics.php",
            "Line": 75
        },
        "CustomMessage": "--"
    },
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0",
    "version": "21.0.5.1"
}

@magicsunday
Copy link

For me it was on line 152 (NC 22.1.1)

Error: foreach() argument must be of type array|object, bool given at /var/www/vhosts/XXXXX/XXXXXX/apps/serverinfo/lib/OperatingSystems/DefaultOs.php#152

My "Patch" fixes the error, thus the system tab loads again. apps/serverinfo/lib/OperatingSystems/DefaultOS.php in getNetworkInterfaces, adding a simple check:

public function getNetworkInterfaces(): array {
	$interfaces = glob('/sys/class/net/*');
	$result = [];
	if(is_bool($interfaces)){  // add this
		return $result;
	}
       . . . 

Maybe create a pull request with this fix?

@klodr
Copy link

klodr commented Dec 29, 2022

public function getNetworkInterfaces(): array {
	$interfaces = glob('/sys/class/net/*');
	$result = [];
	if(is_bool($interfaces)){  // add this
		return $result;
	}

This patch works but imho the code should be simplified using the new php function net_get_interfaces()

@kesselb
Copy link
Collaborator

kesselb commented Dec 30, 2022

net-get-interfaces is a good idea.

Could you run php -r "var_export(net_get_interfaces());" to export the network interfaces on your server?
I would like to write tests and need more real world examples.
Don't forget to replace your public ip address with a private one if necessary.
And let me know if you are using Linux or FreeBSD.

Thanks

@tuxmaster5000
Copy link
Author

On my server CentOS8 PHP 8.0 it will work.

array (
  'lo' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 65609,
        'family' => 17,
      ),
      1 => 
      array (
        'flags' => 65609,
        'family' => 2,
        'address' => '127.0.0.1',
        'netmask' => '255.0.0.0',
      ),
      2 => 
      array (
        'flags' => 65609,
        'family' => 10,
        'address' => '::1',
        'netmask' => 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      ),
    ),
    'up' => true,
  ),
  'eth0' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 69699,
        'family' => 17,
      ),
      1 => 
      array (
        'flags' => 69699,
        'family' => 2,
        'address' => 'XXXXXX',
        'netmask' => '255.255.248.0',
        'broadcast' => 'XX',
      ),
      2 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      3 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      4 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      5 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      6 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      7 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      8 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'xxxxx',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      9 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      10 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      11 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      12 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      13 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      14 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      15 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXXXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      16 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => 'XXXX',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
    ),
    'up' => true,
  ),
)

@kesselb
Copy link
Collaborator

kesselb commented Jan 2, 2023

Looks good on my FreeBSD test vm too 🎉

array (
  'em0' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 34915,
        'family' => 18,
      ),
      1 => 
      array (
        'flags' => 34915,
        'family' => 28,
        'address' => 'fe80::a00:27ff:fe91:f84b',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      2 => 
      array (
        'flags' => 34915,
        'family' => 2,
        'address' => '10.0.2.15',
        'netmask' => '255.255.255.0',
        'broadcast' => '10.0.2.255',
      ),
    ),
    'up' => true,
  ),
  'lo0' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 32841,
        'family' => 18,
      ),
      1 => 
      array (
        'flags' => 32841,
        'family' => 28,
        'address' => '::1',
        'netmask' => 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      ),
      2 => 
      array (
        'flags' => 32841,
        'family' => 28,
        'address' => 'fe80::1',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
      3 => 
      array (
        'flags' => 32841,
        'family' => 2,
        'address' => '127.0.0.1',
        'netmask' => '255.0.0.0',
      ),
    ),
    'up' => true,
  ),
)

@kesselb kesselb linked a pull request Jan 4, 2023 that will close this issue
@klodr
Copy link

klodr commented Jan 5, 2023

Looks good on my Ubuntu test vm too 🎉

array (
  'lo' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 65609,
        'family' => 17,
      ),
      1 => 
      array (
        'flags' => 65609,
        'family' => 2,
        'address' => '127.0.0.1',
        'netmask' => '255.0.0.0',
      ),
      2 => 
      array (
        'flags' => 65609,
        'family' => 10,
        'address' => '::1',
        'netmask' => 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      ),
    ),
    'up' => true,
  ),
  'ens4' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 69699,
        'family' => 17,
      ),
      1 => 
      array (
        'flags' => 69699,
        'family' => 2,
        'address' => '[redacted]'',
        'netmask' => '255.255.255.255',
        'broadcast' => '10.154.0.3',
      ),
      2 => 
      array (
        'flags' => 69699,
        'family' => 10,
        'address' => '[redacted]',
        'netmask' => 'ffff:ffff:ffff:ffff::',
      ),
    ),
    'up' => true,
  ),
  'docker0' => 
  array (
    'unicast' => 
    array (
      0 => 
      array (
        'flags' => 4099,
        'family' => 17,
      ),
      1 => 
      array (
        'flags' => 4099,
        'family' => 2,
        'address' => '172.17.0.1',
        'netmask' => '255.255.0.0',
        'broadcast' => '172.17.255.255',
      ),
    ),
    'up' => true,
  ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants