Zen Cart Logo
Forums / Bug Reports / [Done v1.3.9e] version link > CGI application misbehaved...

[Done v1.3.9e] version link > CGI application misbehaved...

Locked

Views: 1,451

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
24 Jul 2010, 6:24 PM
#1
glenara avatar

glenara

New Zenner

Join Date:
Jul 2010
Location:
Edmonton, Alberta, Canada
Posts:
13
Plugin Contributions:
0

[Done v1.3.9e] version link > CGI application misbehaved...

zen version 1.3.9d but issue exists since at least 1.3.6

Widows platforms. In my case win 2003 server.

Clinking on "Version" link or "Tools>Server/Version Info" Returns:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

This is because you are passing unix commands to windows with-out error detection/redirection.

File: admin\includes\functions*general.php*

function zen_get_system_information() {
...
list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);
...
}

You must provide error redirection to prevent CGI Error by adding 2>&1 ```php
list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a 2>&1'), 5);


While this prevents the CGI Error, no meaning full information will be displayed on a windows platform.

Commenting out the entire line will display correct server info.
//list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a 2>&1'), 5);

While you may have your own ideas on how to fix this, here is how I have done it which is still cross platform friendly.
```php
// Retreive server information
  function zen_get_system_information() {
    global $db;

    // determine database size stats
    $indsize = 0;
    $datsize = 0;
    $result = $db->Execute("SHOW TABLE STATUS" . (DB_PREFIX == '' ? '' : " LIKE '" . str_replace('_', '\_', DB_PREFIX) . "%'"));
    while (!$result->EOF) {
      $datsize += $result->fields['Data_length'];
      $indsize += $result->fields['Index_length'];
      $result->MoveNext();
    }
    $mysql_in_strict_mode = false;
    $result = $db->Execute("SHOW VARIABLES LIKE 'sql\_mode'");
    while (!$result->EOF) {
      if (strstr($result->fields['Value'], 'strict_')) $mysql_in_strict_mode = true;
      $result->MoveNext();
    }

    $db_query = $db->Execute("select now() as datetime");
    // Problem code
    //list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);
    //if ($host == '') list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());
    // Corrected code
    $error = 0;
    @exec('uname -a 2>&1',$output,$error);
    if(!$error) { list($system, $host, $kernel) = preg_split('/[\s,]+/', $output, 5);}
    else { list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());}
    // Also check the uptime return value (which also fails on Windows)
    if(DISPLAY_SERVER_UPTIME) { 
      @exec('uptime 2>&1',$uptime,$error);
      if ($error) $uptime = "Not Available";
    }else { $uptime = "Unchecked";}
    // End of corrected code
    
    return array('date' => zen_datetime_short(date('Y-m-d H:i:s')),
                 'system' => $system,
                 'kernel' => $kernel,
                 'host' => $host,
                 'ip' => gethostbyname($host),
                 // uptime will always have a value.
                 //'uptime' => (DISPLAY_SERVER_UPTIME == 'true' ? @exec('uptime 2>&1') : 'Unchecked'),
                 'uptime' => $uptime,
                 //
                 'http_server' => $_SERVER['SERVER_SOFTWARE'],
                 'php' => PHP_VERSION,
                 'zend' => (function_exists('zend_version') ? zend_version() : ''),
                 'db_server' => DB_SERVER,
                 'db_ip' => gethostbyname(DB_SERVER),
                 'db_version' => 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : ''),
                 'db_date' => zen_datetime_short($db_query->fields['datetime']),
                 'php_memlimit' => @ini_get('memory_limit'),
                 'php_safemode' => strtolower(@ini_get('safe_mode')),
                 'php_file_uploads' => strtolower(@ini_get('file_uploads')),
                 'php_uploadmaxsize' => @ini_get('upload_max_filesize'),
                 'php_postmaxsize' => @ini_get('post_max_size'),
                 'database_size' => $datsize,
                 'index_size' => $indsize,
                 'mysql_strict_mode' => $mysql_in_strict_mode,
                 );
  }
24 Jul 2010, 6:58 PM
#2
glenara avatar

glenara

New Zenner

Join Date:
Jul 2010
Location:
Edmonton, Alberta, Canada
Posts:
13
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

Sorry, I made a minor error:

// should be == 'true'
if(DISPLAY_SERVER_UPTIME == 'true') { 
// Retreive server information
  function zen_get_system_information() {
    global $db;

    // determine database size stats
    $indsize = 0;
    $datsize = 0;
    $result = $db->Execute("SHOW TABLE STATUS" . (DB_PREFIX == '' ? '' : " LIKE '" . str_replace('_', '\_', DB_PREFIX) . "%'"));
    while (!$result->EOF) {
      $datsize += $result->fields['Data_length'];
      $indsize += $result->fields['Index_length'];
      $result->MoveNext();
    }
    $mysql_in_strict_mode = false;
    $result = $db->Execute("SHOW VARIABLES LIKE 'sql\_mode'");
    while (!$result->EOF) {
      if (strstr($result->fields['Value'], 'strict_')) $mysql_in_strict_mode = true;
      $result->MoveNext();
    }

    $db_query = $db->Execute("select now() as datetime");
    // Problem code
    //list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);
    //if ($host == '') list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());
    // Corrected code
    $error = 0;
    @exec('uname -a 2>&1',$output,$error);
    if(!$error) { list($system, $host, $kernel) = preg_split('/[\s,]+/', $output, 5);}
    else { list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());}
    // Also check the uptime return value (which also fails on Windows)
    if(DISPLAY_SERVER_UPTIME == 'true') { 
      @exec('uptime 2>&1',$uptime,$error);
      if ($error) $uptime = "Not Available";
    }else { $uptime = "Unchecked";}
    // End corrected code
    
    return array('date' => zen_datetime_short(date('Y-m-d H:i:s')),
                 'system' => $system,
                 'kernel' => $kernel,
                 'host' => $host,
                 'ip' => gethostbyname($host),
                 // uptime will always have a value.
                 //'uptime' => (DISPLAY_SERVER_UPTIME == 'true' ? @exec('uptime 2>&1') : 'Unchecked'),
                 'uptime' => $uptime,
                 //
                 'http_server' => $_SERVER['SERVER_SOFTWARE'],
                 'php' => PHP_VERSION,
                 'zend' => (function_exists('zend_version') ? zend_version() : ''),
                 'db_server' => DB_SERVER,
                 'db_ip' => gethostbyname(DB_SERVER),
                 'db_version' => 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : ''),
                 'db_date' => zen_datetime_short($db_query->fields['datetime']),
                 'php_memlimit' => @ini_get('memory_limit'),
                 'php_safemode' => strtolower(@ini_get('safe_mode')),
                 'php_file_uploads' => strtolower(@ini_get('file_uploads')),
                 'php_uploadmaxsize' => @ini_get('upload_max_filesize'),
                 'php_postmaxsize' => @ini_get('post_max_size'),
                 'database_size' => $datsize,
                 'index_size' => $indsize,
                 'mysql_strict_mode' => $mysql_in_strict_mode,
                 );
  }
24 Jul 2010, 6:58 PM
#3
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

Hi,

The easiest solution to your problem, is to go into the Admin then under the Configuration menu select My Store. From there set the 'Server Uptime' setting to False.

Edit: Sorry, I got that wrong, the above setting will fix one of the exec calls but not the uname one.

Regards,
Christian.

24 Jul 2010, 7:06 PM
#4
glenara avatar

glenara

New Zenner

Join Date:
Jul 2010
Location:
Edmonton, Alberta, Canada
Posts:
13
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

Well CJPinder, if you are going to trap the one error why not catch the other as well.

24 Jul 2010, 9:21 PM
#5
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

glenara:

Well CJPinder, if you are going to trap the one error why not catch the other as well.
It probably should be dealt with in a more elegant way, i.e. deal with exec() not working or the commands not present. The admin side of the code is quite old and a lot of it hasn't been touched since the oscommerce days. I haven't looked at that particular bit of code in detail which was why I mistakenly thought it was uptime that was causing the problem. All of the Admin code is all due for a re-write in a future version.

Regards,
Christian.

25 Jul 2010, 4:23 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9e] version link > CGI application misbehaved...

As you can see by the notation in the thread's subject line, a variation of the suggested fix has been incorporated into the upcoming v1.3.9e.

25 Jul 2010, 3:34 PM
#7
glenara avatar

glenara

New Zenner

Join Date:
Jul 2010
Location:
Edmonton, Alberta, Canada
Posts:
13
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

CJPinder:

It probably should be dealt with in a more elegant way,

If it should be dealt with in a more elegant way, then do as I did, offer the project developers a solution. If there is a more elegant way then I'm sure they would like to know about, as I would, and it would save them time having figuring it out.

CJPinder:

i.e. deal with exec() not working or the commands not present.

What's wrong with the exec() command? It's doing exactly what its supposed to. What the initial line wasn't doing is utilizing the the optional parameters that are available to the function.

However a correction to my suggestion would be to initialize the $error as an error instead. If the server settings have the exec() command disabled then the alternative results would be used.

    // Corrected code 
    $error = 1; 
    @exec('uname -a 2>&1',$output,$error); 
    if(!$error) { list($system, $host, $kernel) = preg_split('/[\s,]+/', $output, 5);} 
    else { list($system, $host, $kernel) = array('', $_SERVER['SERVER_NAME'], php_uname());} 
    // Also check the uptime return value (which also fails on Windows) 
    if(DISPLAY_SERVER_UPTIME == 'true') {  
      $error = 1; 
      @exec('uptime 2>&1',$uptime,$error); 
      if ($error) $uptime = "Not Available"; 
    }else { $uptime = "Unchecked";} 
    // End corrected code

I guess now its more elegant!

25 Jul 2010, 6:20 PM
#8
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: [Done v1.3.9e] version link > CGI application misbehaved...

glenara:

If it should be dealt with in a more elegant way, then do as I did, offer the project developers a solution. If there is a more elegant way then I'm sure they would like to know about, as I would, and it would save them time having figuring it out.
I didn't say I had a more elegant way, I was just making a comment.

glenara:

What's wrong with the exec() command?
Nothing wrong with it. Some hosts (including at least one Zen Cart certified host) have it disabled though.

Regards,
Christian.