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 glob error in DefaultOs.php #157

Closed
jamesstout opened this issue Oct 3, 2019 · 3 comments
Closed

php glob error in DefaultOs.php #157

jamesstout opened this issue Oct 3, 2019 · 3 comments

Comments

@jamesstout
Copy link

jamesstout commented Oct 3, 2019

Steps to reproduce

  1. Install nextcloud 17.0.0
  2. Go to Admin->System, then to Logging
  3. Check for this error:
[PHP] Error: Invalid argument supplied for foreach() at /var/www/html/nextcloud/apps/serverinfo/lib/OperatingSystems/DefaultOs.php#120

GET /settings/admin/serverinfo
from xxxxxxxx by james at 2019-10-03T13:02:56+08:00

Expected behaviour

No error, and System page should show full network status of all interfaces.

Actual behaviour

get the error and System page doesn not show full network status. e.g.:
Screen Shot 2019-10-03 at 4 57 42 PM

Server configuration

Operating system: Ubuntu 18.04.3 LTS
Web server: nginx/1.16.1
Database: mysqld Ver 5.7.27-0ubuntu0.18.04.1

PHP version: PHP 7.2.19-0ubuntu0.18.04.2

Nextcloud version: Nextcloud 17.0.0

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

Where did you install Nextcloud from: https://download.nextcloud.com/server/releases/nextcloud-17.0.0.tar.bz2

Signing status:

Signing status
No errors have been found.

List of activated apps:

App list
Enabled:
  - accessibility: 1.3.0
  - activity: 2.10.1
  - admin_audit: 1.7.0
  - bruteforcesettings: 1.4.0
  - cloud_federation_api: 1.0.0
  - comments: 1.7.0
  - dav: 1.13.0
  - federatedfilesharing: 1.7.0
  - federation: 1.7.0
  - files: 1.12.0
  - files_downloadactivity: 1.6.0
  - files_external: 1.8.0
  - files_pdfviewer: 1.6.0
  - files_rightclick: 0.15.1
  - files_sharing: 1.9.0
  - files_trashbin: 1.7.0
  - files_versions: 1.10.0
  - files_videoplayer: 1.6.0
  - firstrunwizard: 2.6.0
  - gallery: 18.4.0
  - logreader: 2.2.0
  - lookup_server_connector: 1.5.0
  - maps: 0.1.2
  - nextcloud_announcements: 1.6.0
  - notifications: 2.5.0
  - oauth2: 1.5.0
  - password_policy: 1.7.0
  - privacy: 1.1.0
  - provisioning_api: 1.7.0
  - recommendations: 0.5.0
  - serverinfo: 1.7.0
  - sharebymail: 1.7.0
  - support: 1.0.1
  - systemtags: 1.7.0
  - text: 1.1.0
  - theming: 1.8.0
  - twofactor_backupcodes: 1.6.0
  - updatenotification: 1.7.0
  - viewer: 1.1.0
  - workflowengine: 1.7.0

Nextcloud configuration:

Config report
{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "cloud.stouty.xyz"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "17.0.0.9",
        "overwrite.cli.url": "https:\/\/cloud.stouty.xyz",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "maintenance": false,
        "updater.release.channel": "stable",
        "appcodechecker": true,
        "logtimezone": "Asia\/Hong_Kong",
        "theme": "",
        "loglevel": 2,
        "enable_previews": true,
        "enabledPreviewProviders": [
            "OC\\Preview\\PNG",
            "OC\\Preview\\JPEG",
            "OC\\Preview\\GIF",
            "OC\\Preview\\BMP",
            "OC\\Preview\\XBitmap",
            "OC\\Preview\\Movie",
            "OC\\Preview\\PDF",
            "OC\\Preview\\MP3",
            "OC\\Preview\\TXT",
            "OC\\Preview\\MarkDown"
        ],
        "filesystem_check_changes": 0,
        "filelocking.enabled": "true",
        "overwriteprotocol": "https",
        "preview_max_x": 1024,
        "preview_max_y": 768,
        "preview_max_scale_factor": 1,
        "mail_smtpmode": "smtp",
        "mail_smtpsecure": "tls",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauth": 1,
        "mail_smtpauthtype": "LOGIN",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "587",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***"
    }
}

Are you using external storage, if yes which one: No

Are you using encryption: No

Are you using an external user-backend, if yes which one: Webdav

Client configuration

Browser: Chrome Version 77.0.3865.90

Operating system: macOS 10.13.6 (17G8037)

Logs

Web server error log

Web server error log
- log is silent -

Nextcloud log (data/nextcloud.log)

Nextcloud log
{"reqId":"rn5TIaXKqIF1IDTBojLS","level":3,"time":"2019-10-02T21:42:22+08:00","remoteAddr":"***.**.**.***","user":"james","app":"PHP","method":"GET","url":"\/settings\/admin\/serverinfo","message":"Invalid argument supplied for foreach() at \/var\/www\/html\/nextcloud\/apps\/serverinfo\/lib\/OperatingSystems\/DefaultOs.php#120","userAgent":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/77.0.3865.90 Safari\/537.36","version":"17.0.0.9"}

Browser log

Browser log
HTTP/2 200

The cause of the error is the glob() on line 117. It returns false so the foreach() blows up:

public function getNetworkInterfaces() {
$interfaces = glob('/sys/class/net/*');
$result = [];
foreach ($interfaces as $interface) {

I wrote a test script to try other patterns, and also on Ubuntu 16.04.6/PHP 7.0.33-0ubuntu0.16.04.6/nginx/1.15.8. Other patterns didn't work, but it did work on Ubuntu 16.04.6 etc. So I've spent quite a while checking for diffs between php/nginx configs, but can't see anything significant so far...

Strangely, it works ok on the command line as the www-data user:

$ sudo su -s /bin/bash www-data
www-data@cloud:~$ php -a
Interactive mode enabled

php > var_dump(glob("/sys/class/net/*"));
array(2) {
  [0]=>
  string(19) "/sys/class/net/eth0"
  [1]=>
  string(17) "/sys/class/net/lo"
}
@jamesstout jamesstout changed the title php glob error in php glob error in DefaultOs.php Oct 3, 2019
@jamesstout
Copy link
Author

Spotted a config difference between cli and fpm:

root@cloud: /etc/php/7.2
$ diff cli/php.ini fpm/php.ini
310c310,311
< ;open_basedir =
---
> open_basedir = /tmp/:/var/www/html/nextcloud:/xxx/nextcloud_data/:/dev/urandom

I'd set open_basedir based on this advice.

So I added /sys/class/net:

open_basedir = /sys/class/net:/tmp/:/var/www/html/nextcloud:/xxx/nextcloud_data/:/dev/urandom

No luck 👎

If I add my known interfaces...

open_basedir = /sys/class/net/lo:/sys/class/net/eth0:/sys/class/net:/tmp/:/var/www/html/nextcloud:/xxx/nextcloud_data/:/dev/urandom

It works:

Screen Shot 2019-10-03 at 5 15 54 PM

But that's no use. I could unset open_basedir, but I don't really want to...

If I just add /sys/class/net to open_basedir, then this code works:

$path = realpath('/sys/class/net');
$interfaces = [];
$result = [];
        
$dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);

foreach($dir as $name){
    $interfaces[] = $name->getPathname();
}

@linuxmangr
Copy link

Hi,
I follow you steps and interfaces is work well.
All other info is work except Memory usage and Shared resource graph is to small.
Have you some idea how show up memory usage and Shared resource graph worked?
Some other graph like disks(partitions) is worked and Active users is worked.

@J0WI
Copy link
Contributor

J0WI commented May 10, 2020

Duplicate of #168

@J0WI J0WI marked this as a duplicate of #168 May 10, 2020
@J0WI J0WI closed this as completed May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants