getUlimitValues() function sending linux commands to windows
6 posts by 2 authors in: Forums > CMS Builder
Last Post: August 16, 2011 (RSS)
By ITI - August 11, 2011
function: getUlimitValues()
When CMSB is installed on Windows the following can appear pretty much any where on the "Admin > General Settings" page:
'sh' is not recognized as an internal or external command, operable program or batch file.
This line of text will appear (but not always) anywhere on the page or as the value of input field etc...
In some cases the error isn't actually visible but it's enough to prevent some actions like clicking on buttons.
Partial snippet:
if ($type == 'soft') { $cmd = 'sh -c "ulimit -a -S"'; }
...
// get output
$output = @shell_exec($cmd);
Since "shell_exec()" is succeeding correctly, suppressing the error with the "@" symbol doesn't work because this isn't a php error.
You know its a Linux command so it shouldn't be sent to a Windows interpreter.
To correct this could you add some form of platform validation?
Here is what I have done to temporarily correct till you fix in the next release :)
function getUlimitValues($type = 'soft') {
$maxCpuSeconds = '';
$memoryLimitKbytes = '';
$maxProcessLimit = '';
$output = '';
// get shell command
if ($type == 'soft') { $cmd = 'sh -c "ulimit -a -S"'; }
elseif ($type == 'hard') { $cmd = 'sh -c "ulimit -a -H"'; }
else { die(__FUNCTION__ . ": type must be either hard or soft"); }
if(stripos($_SERVER['SERVER_SOFTWARE'],"Microsoft") === false){
// get output
$output = @shell_exec($cmd);
// parse output
if (preg_match("/^(time|cpu time).*?\s(\S*)$/m", $output, $matches))
{ $maxCpuSeconds = $matches[2]; }
if (preg_match("/^(data|data seg).*?\s(\S*)$/m", $output, $matches))
{ $dataSegLimit = $matches[2]; }
if (preg_match("/^(vmemory|virtual mem).*?\s(\S*)$/m", $output, $matches))
{ $vmemoryLimit = $matches[2]; }
if (preg_match("/^(concurrency|max user processes).*?\s(\S*)$/m", $output, $matches))
{ $maxProcessLimit = $matches[2]; }
if (@$vmemoryLimit > @$dataSegLimit) { $memoryLimitKbytes = @$vmemoryLimit; }
else { $memoryLimitKbytes = @$dataSegLimit; }
}
//
return array($maxCpuSeconds, $memoryLimitKbytes, $maxProcessLimit, $output);
}
http://www.CanadianDomainRegistry.ca
ITI Internetworking Technologies Inc.
Re: [ITI] getUlimitValues() function sending linux commands to windows
By Dave - August 11, 2011
Thanks for the bug report! What PHP version and windows version are you running? We develop on Windows but haven't seen that error to date.
interactivetools.com
Re: [Dave] getUlimitValues() function sending linux commands to windows
By ITI - August 11, 2011 - edited: August 11, 2011
What PHP version and windows version are you running?
Operating System: Windows Server 2003 R2 Standard Edition
PHP Version: PHP v5.2.12
ps. A lot of times the error text is not visible but I would guess that it appears about 30% of the time and as I mentioned its not always the same place. The last time that it occured before I decided to investigate and fix it was when it showed up in the edit list of the "Restore Backup"
Select 'sh' is not recognized as an internal or external command, operable program or batch file. Select version to restore
http://www.CanadianDomainRegistry.ca
ITI Internetworking Technologies Inc.
Re: [ITI] getUlimitValues() function sending linux commands to windows
By Dave - August 15, 2011
That's really odd. shell_exec() actually shouldn't output any errors at all. It's only suppose to return any output and not even return error output unless STDERR is redirected to STDOUT.
I found a few PHP bugs that looked related but nothing conclusive:
https://bugs.php.net/bug.php?id=21065
https://bugs.php.net/bug.php?id=46399
Are you running anything particularly unique or different on the server?
Can you try the attached script and let me know what the output is? Maybe try refreshing a few times to see if you can get the extra error output to appear in the page somewhere.
I'm thinking the simple fix may be to just add 2>&1 to the end of the command to capture any error output. Even though it shouldn't be being output anyways maybe that would prevent the issue.
Let me know what you find out, thanks!
interactivetools.com
Re: [Dave] getUlimitValues() function sending linux commands to windows
By ITI - August 15, 2011 - edited: August 16, 2011
There are no abnormal server settings.
I ran the script independent of CMSB as well as, as a Notice() from within the General Settings page.
The results were as one would expect.
The error message seems to want to appear around the Data Base Section but not consistently in the same places.
Some times beside the button, once as the button text, then as a select item in the Restore Data Base list etc... but I've also had it appear near the top of the page as well.
Anyway, adding the redirection "2>&1" does seem to solve the problem.
I've tested it as many ways as I can and do not see the error appearing anywhere.
I think you have the right solution with the redirection. The redirection certainly doesn't affect anything since the error message doesn't match any of the regex expressions.
I'll leave my system running with the redirection and should the error re-appear I'll let you know but I think it's safe to say you solved it.
For those that are experiencing this problem, this is where Dave as put the redirection.
// get shell command
if ($type == 'soft') { $cmd = 'sh -c "ulimit -a -S" 2>&1'; }
elseif ($type == 'hard') { $cmd = 'sh -c "ulimit -a -H" 2>&1'; }
I have another bazar issue but I'll post it as a new item.
http://www.CanadianDomainRegistry.ca
ITI Internetworking Technologies Inc.
Re: [ITI] getUlimitValues() function sending linux commands to windows
By Dave - August 16, 2011
Thanks!
interactivetools.com