Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default [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

    PHP Code:
    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 Code:
    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 Code:
    // 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,]+/'$output5);}
        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,
                     );
      } 

  2. #2
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default Re: version link > CGI application misbehaved...

    Sorry, I made a minor error:
    PHP Code:
    // should be == 'true'
    if(DISPLAY_SERVER_UPTIME == 'true') { 
    PHP Code:
    // 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,]+/'$output5);}
        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,
                     );
      } 

  3. #3
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: 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.
    Last edited by CJPinder; 24 Jul 2010 at 08:01 PM.

  4. #4
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default Re: version link > CGI application misbehaved...

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

  5. #5
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: version link > CGI application misbehaved...

    Quote Originally Posted by glenara View Post
    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.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default Re: version link > CGI application misbehaved...

    Quote Originally Posted by CJPinder View Post
    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.

    Quote Originally Posted by CJPinder View Post
    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.

    PHP Code:
        // Corrected code 
        
    $error 1
        @
    exec('uname -a 2>&1',$output,$error); 
        if(!
    $error) { list($system$host$kernel) = preg_split('/[\s,]+/'$output5);} 
        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!

  8. #8
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: version link > CGI application misbehaved...

    Quote Originally Posted by glenara View Post
    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.

    Quote Originally Posted by glenara View Post
    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.

 

 

Similar Threads

  1. Replies: 6
    Last Post: 4 Aug 2010, 05:48 PM
  2. Reciprocal link exchange manager application?
    By omerhanif in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 25 Oct 2009, 11:53 PM
  3. Replies: 5
    Last Post: 8 Jul 2009, 01:58 AM
  4. PHP as CGI application
    By ecw in forum Installing on a Linux/Unix Server
    Replies: 4
    Last Post: 12 Apr 2007, 09:58 AM
  5. Replies: 3
    Last Post: 23 Jul 2006, 03:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR