Bug 218351 - net-mgmt/librenms: validate.php fails in fresh FreeBSD 11 Jail
Summary: net-mgmt/librenms: validate.php fails in fresh FreeBSD 11 Jail
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Muhammad Moinur Rahman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-04 12:32 UTC by Jonathan Price
Modified: 2017-04-11 22:43 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (bofh)


Attachments
Proposed patch (3.42 KB, patch)
2017-04-07 12:36 UTC, Jonathan Price
no flags Details | Diff
Revised patch (3.43 KB, patch)
2017-04-11 10:14 UTC, Jonathan Price
no flags Details | Diff
Patch V3 (8.57 KB, patch)
2017-04-11 18:03 UTC, Jonathan Price
no flags Details | Diff
Patch V4 (10.66 KB, patch)
2017-04-11 18:58 UTC, Jonathan Price
freebsd: maintainer-approval?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Price 2017-04-04 12:32:47 UTC
I created a new FreeBSD 11.0-RELEASE jail, changed the pkg repo to latest and ran "pkg install librenms".

When I run validate.php I get the following error:

PHP Warning:  require(/usr/local/www/librenms/vendor/autoload.php): failed to open stream: No such file or directory in /usr/local/www/librenms/includes/init.php on line 40
PHP Fatal error:  require(): Failed opening required '/usr/local/www/librenms/vendor/autoload.php' (include_path='.:/usr/local/share/pear') in /usr/local/www/librenms/includes/init.php on line 40

If I perform a git clone of the original repo and run validate.php I get:

[FAIL]  config.php does not exist, please copy config.php.default to config.php

The latter error is just because it's a blank installation and hasn't been configured yet, but the point is that I am only seeing the first error with the FreeBSD port.

Strangely, the offending line "require $install_dir . '/vendor/autoload.php';" exists in both the FreeBSD port and the git clone, but only causes an issue with the port.

I have tried loading /install.php and it gives a HTTP 500. There is no error output to the nginx error log. I tried adding /debug=true/ and this did not help.]

When I switch nginx to point to the git clone'd copy of librenms, it loads correctly at the installation web UI.

It should be fairly simple to recreate as all I did was create a blank FreeBSD 11 Jail and then install the librenms package, but nonetheless I am able to test any suggestions to resolve this issue. I have had a brief look, but my PHP knowledge is holding me back in debugging thsi.

Thanks,
Jonathan
Comment 1 Jonathan Price 2017-04-04 13:39:24 UTC
Adding some further information now I've looked more carefully.

The problem is that vendor/autoload.php does not exist for the FreeBSD port install (as the error mentions), but for some reason I hadn't previously spotted that this directly actually DOES exist in the git repository.

I am going to build the port from source and see if I can see why that directory is not being pulled in as part of the install.
Comment 2 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2017-04-04 14:12:42 UTC
Besides ports installation just copy the vendor directory from ${WRKDIR}. I missed it while updating. Will fix it on next update. Hopefully in this weekend. :)
Comment 3 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2017-04-04 14:13:26 UTC
Besides ports installation just copy the vendor directory from ${WRKDIR}. I missed it while updating. Will fix it on next update. Hopefully in this weekend. :)
Comment 4 Jonathan Price 2017-04-04 17:49:19 UTC
Hi, and thanks for getting back to me so quickly!

Now i've got past that I have a few more minor things:
- SQL schema patch 169 and 170 failed. It turns out it's because the line in 169.sql:
ALTER TABLE `users`  ADD `remeber_token` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `modified_at`;

was later updated to be:
ALTER TABLE `users`  ADD `remeber_token` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `updated_at`;

This is fixed upstream, so you may want to just ignore this until you update the port. I applied the schema updates manually for my install.

---------

I was then seeing:
root@librenms:/usr/local/www/librenms#php validate.php
PHP Fatal error:  Call to undefined function curl_init() in /usr/local/www/librenms/includes/common.php on line 1091

I fixed this by installing php56-curl

---------

I was then seeing:
PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character' in /usr/local/www/librenms/validate.php:113

I think this particular one might just be something wrong with my timezone in PHP. I can get around it for now by uninstalling git in the VM

---------

I finally was then seeing:

[WARN]  openssl_random_pseudo_bytes is not being used for user password hashing._bytes)

I fixed this by installing php56-openssl
Comment 5 Jonathan Price 2017-04-04 18:04:53 UTC
The following line in /etc/crontab seems a bit broken:  
15      0       *       *       *       www     sh /usr/local/www/librenms/daily.sh >> /dev/null 2>&1
  
root@librenms:/usr/local/www/librenms#sudo -u www sh daily.sh
daily.sh: 91: Syntax error: "(" unexpected (expecting "}")

This is because it's a bash script, rather than a bourne shell script

root@librenms:/usr/local/www/librenms#sudo -u www bash daily.sh
daily.sh: line 132: git: command not found
Updating to latest codebase                       daily.sh: line 60: /usr/local/www/librenms/logs/daily.log: Permission denied
daily.sh: line 63: /usr/local/www/librenms/logs/daily.log: Permission denied
daily.sh: line 64: /usr/local/www/librenms/logs/daily.log: Permission denied
 FAIL
daily.sh: line 134: git: command not found
daily.sh: line 157: /usr/local/www/librenms/daily.sh: Permission denied

It looks like there's some work to be done here with permissions.
Comment 6 Jonathan Price 2017-04-07 12:36:15 UTC
Created attachment 181565 [details]
Proposed patch

Further to my previous remarks I decided to put together a draft of a patch that would correct some of these issues. Below is a brief summary of the changes:

- Removed a couple of files from the shebang list as they now use env, will see if I can get others to do so upstream
- Updated cron entries with missing entries and corrected one entry using sh instead of bash
- Added missing entries to ROOT_FILES and ROOT_DIRS
- Updated version number to 1.26
- Added missing PHP dependencies

It is likely that the patch requires further work before it can be committed, but hopefully it saves you some work!
Comment 7 Jonathan Price 2017-04-11 10:14:26 UTC
Created attachment 181682 [details]
Revised patch

I have made some progress on fixing daily.sh under FreeBSD.

su: no directory
Fixed by replacing:
su -l "$LIBRENMS_USER" -c "$DAILY_SCRIPT $@"
with:
sudo -u "$LIBRENMS_USER" "$DAILY_SCRIPT"
(I don't think FreeBSD's 'su' can be used to execute a command, but I could be wrong)

I haven't yet proposed a patch to fix this as I haven't yet looked at how to patch files in ports 

PHP Fatal error:  Call to undefined function simplexml_load_string() in /usr/local/www/librenms/includes/notifications.php on line 35
Fixed by installing php56-simplexml

PHP Fatal error:  Call to undefined function hash() in /usr/local/www/librenms/includes/notifications.php on line 83
Fixed by installing php56-hash
Comment 8 Jonathan Price 2017-04-11 18:03:02 UTC
Created attachment 181691 [details]
Patch V3

- Created logs dir, used by daily.php
- fixed daily.sh to use sudo (replaces GNU su command)
- made daily.sh executable
- Disabled update checks in daily.sh, as they try to use git
- Updated the username in config.php to www
Comment 9 Jonathan Price 2017-04-11 18:58:22 UTC
Created attachment 181693 [details]
Patch V4

- validate.php no longer exceptions and also doesn't show irrelevant git errors

TODO:
- For some strange reason, everything in the list ROOT_DIRS is not having it's ownership set to www:www like it should. Everything looks correct in work/.PLIST.mktmp

Otherwise, with my latest patch the port seems to be working very nicely. I apologise for the flurry of comments on this bug in the past 24 hours, but I didn't expect to keep coming back to it.
Comment 10 commit-hook freebsd_committer freebsd_triage 2017-04-11 22:11:51 UTC
A commit references this bug:

Author: bofh
Date: Tue Apr 11 22:11:39 UTC 2017
New revision: 438321
URL: https://svnweb.freebsd.org/changeset/ports/438321

Log:
  net-mgmt/librenms: Update version 1.25=>1.26

  - Fix validate.php
  - Created logs dir, used by daily.php
  - fixed daily.sh to use sudo (replaces GNU su command)
  - made daily.sh executable
  - Disabled update checks in daily.sh, as they try to use git
  - Updated the username in config.php to www

  PR:		218351
  Submitted by:	freebsd@jonathanprice.org

Changes:
  head/net-mgmt/librenms/Makefile
  head/net-mgmt/librenms/distinfo
  head/net-mgmt/librenms/files/patch-config.php.default
  head/net-mgmt/librenms/files/patch-daily.sh
  head/net-mgmt/librenms/files/pkg-message.in
Comment 11 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2017-04-11 22:43:36 UTC
Committed with minor changes.