Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Thu May 23, 2019 4:51 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Sun Jan 13, 2019 12:06 pm 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
I just ran the modified cli_test.php from the command line and it's generating an error:

Code:
$ /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 7
PHP Parse error:  syntax error, unexpected '{' in /home/blah/public_html/cacti/install/cli_test.php on line 29

The unmodified cli_test.php still runs without error.


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Sun Jan 13, 2019 12:12 pm 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
I corrected the syntax errors and now get the following result:

Code:
Input: 37
Output:
ERROR 2 - This script is only meant to run at the command line.
Status: Invalid
Command: /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 37

Updated cli_test.php, which now runs without error from the command line:

Code:
#!/usr/bin/php -q
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2018 The Cacti Group                                 |
|                                                                         |
| This program is free software; you can redistribute it and/or           |
| modify it under the terms of the GNU General Public License             |
| as published by the Free Software Foundation; either version 2          |
| of the License, or (at your option) any later version.                  |
|                                                                         |
| This program is distributed in the hope that it will be useful,         |
| but WITHOUT ANY WARRANTY; without even the implied warranty of          |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
| GNU General Public License for more details.                            |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution                     |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See  |
| about.php and/or the AUTHORS file for specific developer information.   |
+-------------------------------------------------------------------------+
| http://www.cacti.net/                                                   |
+-------------------------------------------------------------------------+
*/

/* do NOT run this script through a web browser */
if (!isset($_SERVER['argv'][0])) {
        die('<br><strong>ERROR 1 - This script is only meant to run at the command line.</strong>');
} elseif (isset($_SERVER['REQUEST_METHOD'])) {
        die('<br><strong>ERROR 2 - This script is only meant to run at the command line.</strong>');
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
        die('<br><strong>ERROR 3 - This script is only meant to run at the command line.</strong>');
}

if ($argv !== false && sizeof($argv)) {
   $value = intval($argv[1]);
   print $value * $value;
}


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Sun Jan 13, 2019 12:18 pm 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
Just out of curiosity, I reversed the #2 and #3 tests and the script is also dying at #3:

Code:
Input: 60
Output:
ERROR 3 - This script is only meant to run at the command line.
Status: Invalid
Command: /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 60


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Sun Jan 13, 2019 12:31 pm 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
If I delete all 3 of those tests, the file executes successfully:

Code:
Input: 58
Output: 3364
Status: Valid
Command: /usr/local/bin/php -q /home/blah/public_html/cacti/install/cli_test.php 58

Updated, working cli_test.php file:

Code:
#!/usr/bin/php -q
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2018 The Cacti Group                                 |
|                                                                         |
| This program is free software; you can redistribute it and/or           |
| modify it under the terms of the GNU General Public License             |
| as published by the Free Software Foundation; either version 2          |
| of the License, or (at your option) any later version.                  |
|                                                                         |
| This program is distributed in the hope that it will be useful,         |
| but WITHOUT ANY WARRANTY; without even the implied warranty of          |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
| GNU General Public License for more details.                            |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution                     |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See  |
| about.php and/or the AUTHORS file for specific developer information.   |
+-------------------------------------------------------------------------+
| http://www.cacti.net/                                                   |
+-------------------------------------------------------------------------+
*/

/* do NOT run this script through a web browser */

if ($argv !== false && sizeof($argv)) {
   $value = intval($argv[1]);
   print $value * $value;
}

With those tests removed, the PHP check no longer fails and I can proceed with the upgrade installation.


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Sun Jan 13, 2019 9:09 pm 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
OK that is strange, you are running a new instance of php with the -q option so you should not have request headers.

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Mon Jan 14, 2019 6:20 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
Can you update the cli_test.php to the following so I can see what's occurring:
Code:
/* do NOT run this script through a web browser */
if (php_sapi_name() != 'cli') {
        die('<br><strong>This script is only meant to run at the command line.</strong>');
}

if ($argv !== false && sizeof($argv)) {
        $value = intval($argv[1]);
        print $value * $value . ' - ' . php_sapi_name();
}

print "\n";
print htmlspecialchars(var_export($_SERVER, true));

Because this will contain sensitive info and I need to see everything, please email a copy of that content to [email protected]

I think this is boiling down to, when is PHP CLI not PHP CLI? Also, can you remind me what OS and PHP version you are on?

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Mon Jan 14, 2019 11:37 am 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
I just ran the modified script and emailed you the results.

My setup is as follows:

Code:
Apache version: Apache/2.4.37
PHP version: 5.6.39
MySQL version: 10.1.37-MariaDB
Distro Name: CentOS Linux release 7.6.1810 (Core)
Kernel Version: 3.10.0-957.1.3.el7.x86_64


Also, for what it's worth, I seem to be stuck in a loop during the final installation process. The following lines keep getting repeated every few seconds in the cacti.log:

Code:
2019/01/13 09:56:18 - INSTALL-JSON: notice: Start: {"Step":"97","Eula":"1"}
2019/01/13 09:56:18 - INSTALL-STEP: notice: Install Parameters: array ( 'Runtime' => 'Web', 'Step' => '97', 'Eula' => '1', )
2019/01/13 09:56:18 - INSTALL-STEP: notice: Initial: '97'
2019/01/13 09:56:18 - INSTALL-STEP: notice: Previously complete: NULL
2019/01/13 09:56:18 - INSTALL-STEP: notice: After: '97'
2019/01/13 09:56:18 - INSTALL-STEP: debug: setStep(): '97'
2019/01/13 09:56:18 - INSTALL-STEP: notice: setStep(): stepError array ( ) < '97'
2019/01/13 09:56:18 - INSTALL-LANGUAGE: info: getLanguage(): en-US
2019/01/13 09:56:18 - INSTALL-LANGUAGE: debug: setLanguage(): en-US
2019/01/13 09:56:18 - INSTALL-THEME: info: getTheme(): modern
2019/01/13 09:56:18 - INSTALL-THEME: info: Checking theme: modern
2019/01/13 09:56:18 - INSTALL-THEME: debug: setTheme(): modern
2019/01/13 09:56:18 - INSTALL-STEP: debug: Error: false
2019/01/13 09:56:18 - INSTALL-STEP: debug: Done: '97'
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundTime = 1547401153.5883
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundNeeded =
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: ---------------- Check Expire ----------------
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundDateStarted = 2019-01-13 17:39:13
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundLast = 1547401153.5883
2019/01/13 09:56:18 - INSTALL-BACKGROUND: notice: backgroundLast = 1547401153.5883 (Replaced)
2019/01/13 09:56:18 - INSTALL-BACKGROUND: debug: backgroundExpire = 1547400678
2019/01/13 09:56:19 - INSTALL-JSON: notice:   End: {"Mode":null,"Step":"97","Errors":[],"Eula":"1","Prev":{"Text":"Previous","Step":96,"Enabled":true,"Visible":false},"Next":{"Text":"Next","Step":98,"Enabled":true,"Visible":false},"Test":{"Text":"Test Connection","Step":-4,"Enabled":true,"Visible":false},"Theme":"modern","StepData":{"Current":0,"Total":100}}


The final install screen shows the progress bar heart beat ticking on the left but the completion status indicator on the right never goes past zero percent.


Last edited by Comenius on Mon Jan 14, 2019 12:38 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Mon Jan 14, 2019 12:37 pm 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
So it would appear that your version of PHP is doing something crazy.... It's populating a CLI program with environment variables which should only be applicable to the web.  We check for web-only keys such as REMOTE_ADDR and REQUEST_METHOD but these are populated in your case.

The good news is that the "cli" response to the php_sapi_name() function is likely to help with your scenario and is something we are looking at for a fix but it needs to be tested on multiple platforms since it could be quite a breaking change.

Later tonight, if I get a change, I'll post the fix that I intend to you so you can try it out.  It may be adapted in the future if we find it causes a conflict with other users but it should be enough to get your past the post.

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Mon Jan 14, 2019 12:47 pm 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
OK, cool, sounds good. I'll wait for a code update from you that will hopefully get me past the looping final step of the installation / upgrade. Fingers crossed. :)

Really appreciate all your help!


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Tue Jan 15, 2019 4:32 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
Can you do me a favour and open a GitHub issue for this so I can track it in the CHANGELOG?

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Tue Jan 15, 2019 8:34 am 
Offline

Joined: Sun Jul 24, 2016 11:28 am
Posts: 15
Done. :)

https://github.com/Cacti/cacti/issues/2311


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Tue Jan 15, 2019 9:15 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2474
Thanks, I'll be posting any further updates there. I have committed a fix because we needed to have it commited to test across platforms. There are a number of issues outstanding that will be corrected by the 1.2.1 patch which will need to happen as soon as possible things like this.

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: PHP did not return expected result / File not found
PostPosted: Tue Jan 15, 2019 10:15 pm 
Offline
Cacti Pro User
User avatar

Joined: Mon Jan 05, 2015 10:10 am
Posts: 753
Please ensure mod_security is not installed too. Let us know if you find it installed. It would definitely block the install from completing.

_________________
Before history, there was a paradise, now dust.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: nghiavv1st and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group