Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

PHP web page fails when error message contains quotes

Discussion and questions about Cumulus weather station software version 1. This section is the main place to get help with Cumulus 1 software developed by Steve Loft that ceased development in November 2014.
Post Reply
NFLD.Republic
Posts: 27
Joined: Wed 03 Aug 2011 10:14 pm
Weather Station: Davis Vantage Pro2
Operating System: Cumulus MX on Ubuntu 18.04
Location: Paradise, NL, CANADA
Contact:

PHP web page fails when error message contains quotes

Post by NFLD.Republic »

Hi folks,

I think that I just found a bug with Cumulus 1.9.4.1085. My antivirus had a Cumulus data file locked during a full scan which caused Cumulus not be able to write to the file in the $LatestError variable. Cumulus put the error into the file uploaded to my website as it should have. However, the file name was double quoted which caused PHP to choke with the error

Code: Select all

PHP Parse error:  syntax error, unexpected T_STRING in [directory_path]/cumuluswebtags.php on line 528
Is there any way to send out the error without double quotes?

Thanks
Mike
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: PHP web page fails when error message contains quotes

Post by steve »

I'm not a PHP expert, so you'll have to help me by explaining where Cumulus comes into this. Is it the <#LatestError> web tag? If so, what did the web tag actually contain?

The error message probably came from Windows, with the double quotes already included. But even if Cumulus did put the double quotes in, it's not clear to me why you think that it's a bug in Cumulus? Perhaps all will be clear when I see the actual text.

If the problem is that your PHP string has double quotes in it, then can you not use single quotes for the string delimiter?
Steve
User avatar
SpaceWalker
Posts: 67
Joined: Sun 04 Mar 2012 2:54 am
Weather Station: Davis Vantage
Operating System: Windows XP
Location: Eastern-Canada
Contact:

Re: PHP web page fails when error message contains quotes

Post by SpaceWalker »

It might be useful to other if you would attache the source file used to produce the 'cumuluswebtags.php' file or at the very least post the code (webtags) used in lines 527-529 of the 'cumuluswebtags.php' source file.
NFLD.Republic
Posts: 27
Joined: Wed 03 Aug 2011 10:14 pm
Weather Station: Davis Vantage Pro2
Operating System: Cumulus MX on Ubuntu 18.04
Location: Paradise, NL, CANADA
Contact:

Re: PHP web page fails when error message contains quotes

Post by NFLD.Republic »

I do not have the actual error from the PHP file (clearing the error in Cumulus and restarting Cumulus updates the web tag "fixing" the problem).

These are the lines with the before and after tags; the error was with the $LatestError tag. It looked something like this (the position of the quotes is the important part for PHP

Code: Select all

$ErrorLight           = "1";  // 1 if the 'error' light is flashing, 0 if not
$LatestError          = "Latest Error: "Some filename was locked" recorded";  // The latest error logged to the error log window. Cleared to an empty string when the error light is clicked, and when Cumulus is restarted
$LatestErrorDate      = "120513";  // The date of the latest error logged to the error log window, using the system short date format. Gives dashes when latest error is reset
So, when the PHP interpreter parsed the line it read "Latest Error: " as text and then tried to interpret the "Some filename was locked" as PHP code.

The error is (was?) correct. It was just the quoting in the string.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP web page fails when error message contains quotes

Post by mcrossley »

So the quick fix is to use single quotes in the PHP file that uses the web tag...

Code: Select all

$LatestError          = '<#LatestError>';
And hope none of the error messages contain a single quote :roll:
User avatar
SpaceWalker
Posts: 67
Joined: Sun 04 Mar 2012 2:54 am
Weather Station: Davis Vantage
Operating System: Windows XP
Location: Eastern-Canada
Contact:

Re: PHP web page fails when error message contains quotes

Post by SpaceWalker »

And to make Mark's 'hope' more 'hopeful', you could use the following:

Code: Select all

$LatestError = str_replace("'", '"', '<#LatestError>');
Thus producing a webtags such as :

Code: Select all

$LatestError = 'Latest Error: "Some filename was locked" recorded';
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP web page fails when error message contains quotes

Post by mcrossley »

SpaceWalker wrote:

Code: Select all

$LatestError = str_replace("'", '"', '<#LatestError>');
Hmm, think about it... ;)
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: PHP web page fails when error message contains quotes

Post by steve »

Come on, Mark, enlighten us. I can't see anything wrong with Ray's suggestion.

Edit: Ah, hold on... you're back with the same problem you started with.
Steve
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP web page fails when error message contains quotes

Post by mcrossley »

Yeah, the problem is Cumulus is in effect directly editing the source code and producing a syntax error, rather than a variable being set with some content we want to change.

So the code would become (as a synthetic example)...

Code: Select all

$LatestError = str_replace("'", '"', 'Latest Error: 'Some filename was locked' recorded');
The string is now 'Latest Error: ' followed by some invalid PHP code >> Some filename was locked << followed by another string ' recorded'. So the str_replace() would not find anything to replace in the first string even if the line passed the PHP parser.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP web page fails when error message contains quotes

Post by mcrossley »

So use this syntax (if you have PHP v5.3.0 or later)...

Code: Select all

$LatestError = <<<'EOT'
<#LatestError>
EOT;
Edit: Actually another quick Google shows the heredoc syntax which is support prior to 5.3.0...

Code: Select all

$LatestError = <<<EOT
<#LatestError>
EOT;
Note in both of them the text must not be indented on the line, nor the terminating character string ('EOT' in this case).

Edit2: Spooky, I was using just this syntax today when writing some scripts to configure the iLO management processors on a customers blade servers via a SSH command line. I didn't know PHP supported it as well.
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: PHP web page fails when error message contains quotes

Post by beteljuice »

Surely there is something 'wrong' with the initial contruct ?

"Latest Error: "Some filename was locked" recorded"

I would have expected it to be:

"Latest Error: Some filename was locked"
OR
"Latest Error recorded: Some filename was locked"

Is this really the output of <#LatestError> or is it constructed from code together with the <#webtag> ?
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: PHP web page fails when error message contains quotes

Post by steve »

This is the output of <#LatestError> when I lock a data file by opening it in MS Word while Cumulus is trying to write a log entry:

05/12/2013 08:56:00 Error closing data file: C:\Users\steve\Documents\RAD Studio\Projects\Cumulus\Release\Win32\data\Dec13log.txt. I/O error 103

The bit in red is the Windows error message which gets tacked on the end of the message generated by Cumulus. I'm assuming that this was not the type of error message which caused the original issue, but I don't know what the actual error message would have been.
Steve
Post Reply