Annotation of embedaddon/php/ext/standard/info.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:    +----------------------------------------------------------------------+
                      3:    | PHP Version 5                                                        |
                      4:    +----------------------------------------------------------------------+
                      5:    | Copyright (c) 1997-2012 The PHP Group                                |
                      6:    +----------------------------------------------------------------------+
                      7:    | This source file is subject to version 3.01 of the PHP license,      |
                      8:    | that is bundled with this package in the file LICENSE, and is        |
                      9:    | available through the world-wide-web at the following url:           |
                     10:    | http://www.php.net/license/3_01.txt                                  |
                     11:    | If you did not receive a copy of the PHP license and are unable to   |
                     12:    | obtain it through the world-wide-web, please send a note to          |
                     13:    | license@php.net so we can mail you a copy immediately.               |
                     14:    +----------------------------------------------------------------------+
                     15:    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
                     16:    |          Zeev Suraski <zeev@zend.com>                                |
                     17:    |          Colin Viebrock <colin@easydns.com>                          |
                     18:    +----------------------------------------------------------------------+
                     19: */
                     20: 
                     21: /* $Id: info.c 321634 2012-01-01 13:15:04Z felipe $ */
                     22: 
                     23: #include "php.h"
                     24: #include "php_ini.h"
                     25: #include "php_globals.h"
                     26: #include "ext/standard/head.h"
                     27: #include "ext/standard/html.h"
                     28: #include "info.h"
                     29: #include "credits.h"
                     30: #include "css.h"
                     31: #include "SAPI.h"
                     32: #include <time.h>
                     33: #include "php_main.h"
                     34: #include "zend_globals.h"              /* needs ELS */
                     35: #include "zend_extensions.h"
                     36: #include "zend_highlight.h"
                     37: #ifdef HAVE_SYS_UTSNAME_H
                     38: #include <sys/utsname.h>
                     39: #endif
                     40: 
                     41: #ifdef PHP_WIN32
                     42: typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
                     43: typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
                     44: 
                     45: # include "winver.h"
                     46: 
                     47: #if _MSC_VER < 1300
                     48: # define OSVERSIONINFOEX php_win_OSVERSIONINFOEX
                     49: #endif
                     50: 
                     51: #endif
                     52: 
                     53: #if HAVE_MBSTRING
                     54: #include "ext/mbstring/mbstring.h"
                     55: ZEND_EXTERN_MODULE_GLOBALS(mbstring)
                     56: #endif
                     57: 
                     58: #if HAVE_ICONV
                     59: #include "ext/iconv/php_iconv.h"
                     60: ZEND_EXTERN_MODULE_GLOBALS(iconv)
                     61: #endif
                     62: 
                     63: #define SECTION(name)  if (!sapi_module.phpinfo_as_text) { \
                     64:                                                        PUTS("<h2>" name "</h2>\n"); \
                     65:                                                } else { \
                     66:                                                        php_info_print_table_start(); \
                     67:                                                        php_info_print_table_header(1, name); \
                     68:                                                        php_info_print_table_end(); \
                     69:                                                } \
                     70: 
                     71: PHPAPI extern char *php_ini_opened_path;
                     72: PHPAPI extern char *php_ini_scanned_path;
                     73: PHPAPI extern char *php_ini_scanned_files;
                     74:        
                     75: static int php_info_write_wrapper(const char *str, uint str_length)
                     76: {
                     77:        int new_len, written;
                     78:        char *elem_esc;
                     79: 
                     80:        TSRMLS_FETCH();
                     81: 
                     82:        elem_esc = php_escape_html_entities((unsigned char *)str, str_length, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
                     83: 
                     84:        written = php_body_write(elem_esc, new_len TSRMLS_CC);
                     85: 
                     86:        efree(elem_esc);
                     87: 
                     88:        return written;
                     89: }
                     90: 
                     91: 
                     92: PHPAPI void php_info_print_module(zend_module_entry *zend_module TSRMLS_DC) /* {{{ */
                     93: {
                     94:        if (zend_module->info_func || zend_module->version) {
                     95:                if (!sapi_module.phpinfo_as_text) {
                     96:                        php_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", zend_module->name, zend_module->name);
                     97:                } else {
                     98:                        php_info_print_table_start();
                     99:                        php_info_print_table_header(1, zend_module->name);
                    100:                        php_info_print_table_end();
                    101:                }
                    102:                if (zend_module->info_func) {
                    103:                        zend_module->info_func(zend_module TSRMLS_CC);
                    104:                } else {
                    105:                        php_info_print_table_start();
                    106:                        php_info_print_table_row(2, "Version", zend_module->version);
                    107:                        php_info_print_table_end();
                    108:                        DISPLAY_INI_ENTRIES();
                    109:                }
                    110:        } else {
                    111:                if (!sapi_module.phpinfo_as_text) {
                    112:                        php_printf("<tr><td>%s</td></tr>\n", zend_module->name);
                    113:                } else {
                    114:                        php_printf("%s\n", zend_module->name);
                    115:                }       
                    116:        }
                    117: }
                    118: /* }}} */
                    119: 
                    120: static int _display_module_info_func(zend_module_entry *module TSRMLS_DC) /* {{{ */
                    121: {
                    122:        if (module->info_func || module->version) {
                    123:                php_info_print_module(module TSRMLS_CC);
                    124:        }
                    125:        return ZEND_HASH_APPLY_KEEP;
                    126: }
                    127: /* }}} */
                    128: 
                    129: static int _display_module_info_def(zend_module_entry *module TSRMLS_DC) /* {{{ */
                    130: {
                    131:        if (!module->info_func && !module->version) {
                    132:                php_info_print_module(module TSRMLS_CC);
                    133:        }
                    134:        return ZEND_HASH_APPLY_KEEP;
                    135: }
                    136: /* }}} */
                    137: 
                    138: /* {{{ php_print_gpcse_array
                    139:  */
                    140: static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
                    141: {
                    142:        zval **data, **tmp, tmp2;
                    143:        char *string_key;
                    144:        uint string_len;
                    145:        ulong num_key;
                    146: 
                    147:        zend_is_auto_global(name, name_length TSRMLS_CC);
                    148: 
                    149:        if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE
                    150:                && (Z_TYPE_PP(data)==IS_ARRAY)) {
                    151:                zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
                    152:                while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) {
                    153:                        if (!sapi_module.phpinfo_as_text) {
                    154:                                PUTS("<tr>");
                    155:                                PUTS("<td class=\"e\">");
                    156: 
                    157:                        }
                    158: 
                    159:                        PUTS(name);
                    160:                        PUTS("[\"");
                    161:                        
                    162:                        switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) {
                    163:                                case HASH_KEY_IS_STRING:
                    164:                                        if (!sapi_module.phpinfo_as_text) {
                    165:                                                php_info_html_esc_write(string_key, string_len - 1 TSRMLS_CC);
                    166:                                        } else {
                    167:                                                PHPWRITE(string_key, string_len - 1);
                    168:                                        }       
                    169:                                        break;
                    170:                                case HASH_KEY_IS_LONG:
                    171:                                        php_printf("%ld", num_key);
                    172:                                        break;
                    173:                        }
                    174:                        PUTS("\"]");
                    175:                        if (!sapi_module.phpinfo_as_text) {
                    176:                                PUTS("</td><td class=\"v\">");
                    177:                        } else {
                    178:                                PUTS(" => ");
                    179:                        }
                    180:                        if (Z_TYPE_PP(tmp) == IS_ARRAY) {
                    181:                                if (!sapi_module.phpinfo_as_text) {
                    182:                                        PUTS("<pre>");
                    183:                                        zend_print_zval_r_ex((zend_write_func_t) php_info_write_wrapper, *tmp, 0 TSRMLS_CC);
                    184:                                        PUTS("</pre>");
                    185:                                } else {
                    186:                                        zend_print_zval_r(*tmp, 0 TSRMLS_CC);
                    187:                                }
                    188:                        } else if (Z_TYPE_PP(tmp) != IS_STRING) {
                    189:                                tmp2 = **tmp;
                    190:                                zval_copy_ctor(&tmp2);
                    191:                                convert_to_string(&tmp2);
                    192:                                if (!sapi_module.phpinfo_as_text) {
                    193:                                        if (Z_STRLEN(tmp2) == 0) {
                    194:                                                PUTS("<i>no value</i>");
                    195:                                        } else {
                    196:                                                php_info_html_esc_write(Z_STRVAL(tmp2), Z_STRLEN(tmp2) TSRMLS_CC);
                    197:                                        } 
                    198:                                } else {
                    199:                                        PHPWRITE(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
                    200:                                }       
                    201:                                zval_dtor(&tmp2);
                    202:                        } else {
                    203:                                if (!sapi_module.phpinfo_as_text) {
                    204:                                        if (Z_STRLEN_PP(tmp) == 0) {
                    205:                                                PUTS("<i>no value</i>");
                    206:                                        } else {
                    207:                                                php_info_html_esc_write(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) TSRMLS_CC);
                    208:                                        }
                    209:                                } else {
                    210:                                        PHPWRITE(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
                    211:                                }       
                    212:                        }
                    213:                        if (!sapi_module.phpinfo_as_text) {
                    214:                                PUTS("</td></tr>\n");
                    215:                        } else {
                    216:                                PUTS("\n");
                    217:                        }       
                    218:                        zend_hash_move_forward(Z_ARRVAL_PP(data));
                    219:                }
                    220:        }
                    221: }
                    222: /* }}} */
                    223: 
                    224: /* {{{ php_info_print_style
                    225:  */
                    226: void php_info_print_style(TSRMLS_D)
                    227: {
                    228:        php_printf("<style type=\"text/css\">\n");
                    229:        php_info_print_css(TSRMLS_C);
                    230:        php_printf("</style>\n");
                    231: }
                    232: /* }}} */
                    233: 
                    234: /* {{{ php_info_html_esc_write
                    235:  */
                    236: PHPAPI void php_info_html_esc_write(char *string, int str_len TSRMLS_DC)
                    237: {
                    238:        int new_len;
                    239:        char *ret = php_escape_html_entities((unsigned char *)string, str_len, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
                    240: 
                    241:        PHPWRITE(ret, new_len);
                    242:        efree(ret);
                    243: }
                    244: /* }}} */
                    245: 
                    246: /* {{{ php_info_html_esc
                    247:  */
                    248: PHPAPI char *php_info_html_esc(char *string TSRMLS_DC)
                    249: {
                    250:        int new_len;
                    251:        return php_escape_html_entities((unsigned char *)string, strlen(string), &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC);
                    252: }
                    253: /* }}} */
                    254: 
                    255: 
                    256: #ifdef PHP_WIN32
                    257: /* {{{  */
                    258: char* php_get_windows_name()
                    259: {
                    260:        OSVERSIONINFOEX osvi;
                    261:        SYSTEM_INFO si;
                    262:        PGNSI pGNSI;
                    263:        PGPI pGPI;
                    264:        BOOL bOsVersionInfoEx;
                    265:        DWORD dwType;
                    266:        char *major = NULL, *sub = NULL, *retval;
                    267: 
                    268:        ZeroMemory(&si, sizeof(SYSTEM_INFO));
                    269:        ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
                    270:        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
                    271: 
                    272:        if (!(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi))) {
                    273:                return NULL;
                    274:        }
                    275: 
                    276:        pGNSI = (PGNSI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
                    277:        if(NULL != pGNSI) {
                    278:                pGNSI(&si);
                    279:        } else {
                    280:                GetSystemInfo(&si);
                    281:        }
                    282: 
                    283:        if (VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) {
                    284:                if (osvi.dwMajorVersion == 6) {
                    285:                        if( osvi.dwMinorVersion == 0 ) {
                    286:                                if( osvi.wProductType == VER_NT_WORKSTATION ) {
                    287:                                        major = "Windows Vista";
                    288:                                } else {
                    289:                                        major = "Windows Server 2008";
                    290:                                }
                    291:                        } else
                    292:                        if ( osvi.dwMinorVersion == 1 ) {
                    293:                                if( osvi.wProductType == VER_NT_WORKSTATION )  {
                    294:                                        major = "Windows 7";
                    295:                                } else {
                    296:                                        major = "Windows Server 2008 R2";
                    297:                                }
                    298:                        } else {
                    299:                                major = "Unknow Windows version";
                    300:                        }
                    301: 
                    302:                        pGPI = (PGPI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo");
                    303:                        pGPI(6, 0, 0, 0, &dwType);
                    304: 
                    305:                        switch (dwType) {
                    306:                                case PRODUCT_ULTIMATE:
                    307:                                        sub = "Ultimate Edition";
                    308:                                        break;
                    309:                                case PRODUCT_HOME_PREMIUM:
                    310:                                        sub = "Home Premium Edition";
                    311:                                        break;
                    312:                                case PRODUCT_HOME_BASIC:
                    313:                                        sub = "Home Basic Edition";
                    314:                                        break;
                    315:                                case PRODUCT_ENTERPRISE:
                    316:                                        sub = "Enterprise Edition";
                    317:                                        break;
                    318:                                case PRODUCT_BUSINESS:
                    319:                                        sub = "Business Edition";
                    320:                                        break;
                    321:                                case PRODUCT_STARTER:
                    322:                                        sub = "Starter Edition";
                    323:                                        break;
                    324:                                case PRODUCT_CLUSTER_SERVER:
                    325:                                        sub = "Cluster Server Edition";
                    326:                                        break;
                    327:                                case PRODUCT_DATACENTER_SERVER:
                    328:                                        sub = "Datacenter Edition";
                    329:                                        break;
                    330:                                case PRODUCT_DATACENTER_SERVER_CORE:
                    331:                                        sub = "Datacenter Edition (core installation)";
                    332:                                        break;
                    333:                                case PRODUCT_ENTERPRISE_SERVER:
                    334:                                        sub = "Enterprise Edition";
                    335:                                        break;
                    336:                                case PRODUCT_ENTERPRISE_SERVER_CORE:
                    337:                                        sub = "Enterprise Edition (core installation)";
                    338:                                        break;
                    339:                                case PRODUCT_ENTERPRISE_SERVER_IA64:
                    340:                                        sub = "Enterprise Edition for Itanium-based Systems";
                    341:                                        break;
                    342:                                case PRODUCT_SMALLBUSINESS_SERVER:
                    343:                                        sub = "Small Business Server";
                    344:                                        break;
                    345:                                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                    346:                                        sub = "Small Business Server Premium Edition";
                    347:                                        break;
                    348:                                case PRODUCT_STANDARD_SERVER:
                    349:                                        sub = "Standard Edition";
                    350:                                        break;
                    351:                                case PRODUCT_STANDARD_SERVER_CORE:
                    352:                                        sub = "Standard Edition (core installation)";
                    353:                                        break;
                    354:                                case PRODUCT_WEB_SERVER:
                    355:                                        sub = "Web Server Edition";
                    356:                                        break;
                    357:                        }
                    358:                }
                    359: 
                    360:                if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )     {
                    361:                        if (GetSystemMetrics(SM_SERVERR2))
                    362:                                major = "Windows Server 2003 R2";
                    363:                        else if (osvi.wSuiteMask == VER_SUITE_STORAGE_SERVER)
                    364:                                major = "Windows Storage Server 2003";
                    365:                        else if (osvi.wSuiteMask == VER_SUITE_WH_SERVER)
                    366:                                major = "Windows Home Server";
                    367:                        else if (osvi.wProductType == VER_NT_WORKSTATION &&
                    368:                                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
                    369:                                major = "Windows XP Professional x64 Edition";
                    370:                        } else {
                    371:                                major = "Windows Server 2003";
                    372:                        }
                    373: 
                    374:                        /* Test for the server type. */
                    375:                        if ( osvi.wProductType != VER_NT_WORKSTATION ) {
                    376:                                if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 ) {
                    377:                                        if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    378:                                                sub = "Datacenter Edition for Itanium-based Systems";
                    379:                                        else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    380:                                                sub = "Enterprise Edition for Itanium-based Systems";
                    381:                                }
                    382: 
                    383:                                else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) {
                    384:                                        if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    385:                                                sub = "Datacenter x64 Edition";
                    386:                                        else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    387:                                                sub = "Enterprise x64 Edition";
                    388:                                        else sub = "Standard x64 Edition";
                    389:                                } else {
                    390:                                        if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
                    391:                                                sub = "Compute Cluster Edition";
                    392:                                        else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    393:                                                sub = "Datacenter Edition";
                    394:                                        else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    395:                                                sub = "Enterprise Edition";
                    396:                                        else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
                    397:                                                sub = "Web Edition";
                    398:                                        else sub = "Standard Edition";
                    399:                                }
                    400:                        } 
                    401:                }
                    402: 
                    403:                if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )     {
                    404:                        major = "Windows XP";
                    405:                        if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                    406:                                sub = "Home Edition";
                    407:                        else sub = "Professional";
                    408:                }
                    409: 
                    410:                if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
                    411:                        major = "Windows 2000";
                    412: 
                    413:                        if (osvi.wProductType == VER_NT_WORKSTATION ) {
                    414:                                sub = "Professional";
                    415:                        } else {
                    416:                                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    417:                                        sub = "Datacenter Server";
                    418:                                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    419:                                        sub = "Advanced Server";
                    420:                                else sub = "Server";
                    421:                        }
                    422:                }
                    423:        } else {
                    424:                return NULL;
                    425:        }
                    426: 
                    427:        spprintf(&retval, 0, "%s%s%s%s%s", major, sub?" ":"", sub?sub:"", osvi.szCSDVersion[0] != '\0'?" ":"", osvi.szCSDVersion);
                    428:        return retval;
                    429: }
                    430: /* }}}  */
                    431: 
                    432: /* {{{  */
                    433: void php_get_windows_cpu(char *buf, int bufsize)
                    434: {
                    435:        SYSTEM_INFO SysInfo;
                    436:        GetSystemInfo(&SysInfo);
                    437:        switch (SysInfo.wProcessorArchitecture) {
                    438:                case PROCESSOR_ARCHITECTURE_INTEL :
                    439:                        snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
                    440:                        break;
                    441:                case PROCESSOR_ARCHITECTURE_MIPS :
                    442:                        snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
                    443:                        break;
                    444:                case PROCESSOR_ARCHITECTURE_ALPHA :
                    445:                        snprintf(buf, bufsize, "Alpha %d", SysInfo.wProcessorLevel);
                    446:                        break;
                    447:                case PROCESSOR_ARCHITECTURE_PPC :
                    448:                        snprintf(buf, bufsize, "PPC 6%02d", SysInfo.wProcessorLevel);
                    449:                        break;
                    450:                case PROCESSOR_ARCHITECTURE_IA64 :
                    451:                        snprintf(buf, bufsize,  "IA64");
                    452:                        break;
                    453: #if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64)
                    454:                case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 :
                    455:                        snprintf(buf, bufsize, "IA32");
                    456:                        break;
                    457: #endif
                    458: #if defined(PROCESSOR_ARCHITECTURE_AMD64)
                    459:                case PROCESSOR_ARCHITECTURE_AMD64 :
                    460:                        snprintf(buf, bufsize, "AMD64");
                    461:                        break;
                    462: #endif
                    463:                case PROCESSOR_ARCHITECTURE_UNKNOWN :
                    464:                default:
                    465:                        snprintf(buf, bufsize, "Unknown");
                    466:                        break;
                    467:        }
                    468: }
                    469: /* }}}  */
                    470: #endif
                    471: 
                    472: /* {{{ php_get_uname
                    473:  */
                    474: PHPAPI char *php_get_uname(char mode)
                    475: {
                    476:        char *php_uname;
                    477:        char tmp_uname[256];
                    478: #ifdef PHP_WIN32
                    479:        DWORD dwBuild=0;
                    480:        DWORD dwVersion = GetVersion();
                    481:        DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
                    482:        DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
                    483:        DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
                    484:        char ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
                    485:        
                    486:        GetComputerName(ComputerName, &dwSize);
                    487: 
                    488:        if (mode == 's') {
                    489:                if (dwVersion < 0x80000000) {
                    490:                        php_uname = "Windows NT";
                    491:                } else {
                    492:                        php_uname = "Windows 9x";
                    493:                }
                    494:        } else if (mode == 'r') {
                    495:                snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
                    496:                php_uname = tmp_uname;
                    497:        } else if (mode == 'n') {
                    498:                php_uname = ComputerName;
                    499:        } else if (mode == 'v') {
                    500:                char *winver = php_get_windows_name();
                    501:                dwBuild = (DWORD)(HIWORD(dwVersion));
                    502:                if(winver == NULL) {
                    503:                        snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild);
                    504:                } else {
                    505:                        snprintf(tmp_uname, sizeof(tmp_uname), "build %d (%s)", dwBuild, winver);
                    506:                }
                    507:                php_uname = tmp_uname;
                    508:                if(winver) {
                    509:                        efree(winver);
                    510:                }
                    511:        } else if (mode == 'm') {
                    512:                php_get_windows_cpu(tmp_uname, sizeof(tmp_uname));
                    513:                php_uname = tmp_uname;
                    514:        } else { /* assume mode == 'a' */
                    515:                /* Get build numbers for Windows NT or Win95 */
                    516:                if (dwVersion < 0x80000000){
                    517:                        char *winver = php_get_windows_name();
                    518:                        char wincpu[20];
                    519: 
                    520:                        php_get_windows_cpu(wincpu, sizeof(wincpu));
                    521:                        dwBuild = (DWORD)(HIWORD(dwVersion));
                    522:                        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d (%s) %s",
                    523:                                         "Windows NT", ComputerName,
                    524:                                         dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild, winver?winver:"unknown", wincpu);
                    525:                        if(winver) {
                    526:                                efree(winver);
                    527:                        }
                    528:                } else {
                    529:                        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d",
                    530:                                         "Windows 9x", ComputerName,
                    531:                                         dwWindowsMajorVersion, dwWindowsMinorVersion);
                    532:                }
                    533:                php_uname = tmp_uname;
                    534:        }
                    535: #else
                    536: #ifdef HAVE_SYS_UTSNAME_H
                    537:        struct utsname buf;
                    538:        if (uname((struct utsname *)&buf) == -1) {
                    539:                php_uname = PHP_UNAME;
                    540:        } else {
                    541: #ifdef NETWARE
                    542:                if (mode == 's') {
                    543:                        php_uname = buf.sysname;
                    544:                } else if (mode == 'r') {
                    545:                        snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d", 
                    546:                                         buf.netware_major, buf.netware_minor, buf.netware_revision);
                    547:                        php_uname = tmp_uname;
                    548:                } else if (mode == 'n') {
                    549:                        php_uname = buf.servername;
                    550:                } else if (mode == 'v') {
                    551:                        snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d",
                    552:                                         buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold);
                    553:                        php_uname = tmp_uname;
                    554:                } else if (mode == 'm') {
                    555:                        php_uname = buf.machine;
                    556:                } else { /* assume mode == 'a' */
                    557:                        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s",
                    558:                                         buf.sysname, buf.servername,
                    559:                                         buf.netware_major, buf.netware_minor, buf.netware_revision,
                    560:                                         buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold,
                    561:                                         buf.machine);
                    562:                        php_uname = tmp_uname;
                    563:                }
                    564: #else
                    565:                if (mode == 's') {
                    566:                        php_uname = buf.sysname;
                    567:                } else if (mode == 'r') {
                    568:                        php_uname = buf.release;
                    569:                } else if (mode == 'n') {
                    570:                        php_uname = buf.nodename;
                    571:                } else if (mode == 'v') {
                    572:                        php_uname = buf.version;
                    573:                } else if (mode == 'm') {
                    574:                        php_uname = buf.machine;
                    575:                } else { /* assume mode == 'a' */
                    576:                        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
                    577:                                         buf.sysname, buf.nodename, buf.release, buf.version,
                    578:                                         buf.machine);
                    579:                        php_uname = tmp_uname;
                    580:                }
                    581: #endif /* NETWARE */
                    582:        }
                    583: #else
                    584:        php_uname = PHP_UNAME;
                    585: #endif
                    586: #endif
                    587:        return estrdup(php_uname);
                    588: }
                    589: /* }}} */
                    590: 
                    591: 
                    592: /* {{{ php_print_info_htmlhead
                    593:  */
                    594: PHPAPI void php_print_info_htmlhead(TSRMLS_D)
                    595: {
                    596: 
                    597: /*** none of this is needed now ***
                    598: 
                    599:        const char *charset = NULL;
                    600: 
                    601:        if (SG(default_charset)) {
                    602:                charset = SG(default_charset);
                    603:        }
                    604: 
                    605: #if HAVE_MBSTRING
                    606:        if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) {
                    607:                if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) {
                    608:                        charset = "US-ASCII";
                    609:                } else {
                    610:                        charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding));
                    611:                }
                    612:        }
                    613: #endif   
                    614: 
                    615: #if HAVE_ICONV
                    616:        if (php_ob_handler_used("ob_iconv_handler" TSRMLS_CC)) {
                    617:                charset = ICONVG(output_encoding);
                    618:        }
                    619: #endif
                    620: 
                    621:        if (!charset || !charset[0]) {
                    622:                charset = "US-ASCII";
                    623:        }
                    624: 
                    625: *** none of that is needed now ***/
                    626: 
                    627: 
                    628:        PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
                    629:        PUTS("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                    630:        PUTS("<head>\n");
                    631:        php_info_print_style(TSRMLS_C);
                    632:        PUTS("<title>phpinfo()</title>");
                    633:        PUTS("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
                    634: /*
                    635:        php_printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n", charset);
                    636: */
                    637:        PUTS("</head>\n");
                    638:        PUTS("<body><div class=\"center\">\n");
                    639: }
                    640: /* }}} */
                    641: 
                    642: /* {{{ module_name_cmp */
                    643: static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
                    644: {
                    645:        Bucket *f = *((Bucket **) a);
                    646:        Bucket *s = *((Bucket **) b);
                    647: 
                    648:        return strcasecmp(((zend_module_entry *)f->pData)->name,
                    649:                                  ((zend_module_entry *)s->pData)->name);
                    650: }
                    651: /* }}} */
                    652: 
                    653: /* {{{ php_print_info
                    654:  */
                    655: PHPAPI void php_print_info(int flag TSRMLS_DC)
                    656: {
                    657:        char **env, *tmp1, *tmp2;
                    658:        char *php_uname;
                    659:        int expose_php = INI_INT("expose_php");
                    660: 
                    661:        if (!sapi_module.phpinfo_as_text) {
                    662:                php_print_info_htmlhead(TSRMLS_C);
                    663:        } else {
                    664:                PUTS("phpinfo()\n");
                    665:        }       
                    666: 
                    667:        if (flag & PHP_INFO_GENERAL) {
                    668:                char *zend_version = get_zend_version();
                    669:                char temp_api[10];
                    670:                char *logo_guid;
                    671: 
                    672:                php_uname = php_get_uname('a');
                    673:                
                    674:                if (!sapi_module.phpinfo_as_text) {
                    675:                        php_info_print_box_start(1);
                    676:                }
                    677: 
                    678:                if (expose_php && !sapi_module.phpinfo_as_text) {
                    679:                        PUTS("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
                    680:                        if (SG(request_info).request_uri) {
                    681:                                char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
                    682:                                PUTS(elem_esc);
                    683:                                efree(elem_esc);
                    684:                        }
                    685:                        PUTS("?=");
                    686:                        logo_guid = php_logo_guid();
                    687:                        PUTS(logo_guid);
                    688:                        efree(logo_guid);
                    689:                        PUTS("\" alt=\"PHP Logo\" /></a>");
                    690:                }
                    691: 
                    692:                if (!sapi_module.phpinfo_as_text) {
                    693:                        php_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
                    694:                } else {
                    695:                        php_info_print_table_row(2, "PHP Version", PHP_VERSION);
                    696:                }       
                    697:                php_info_print_box_end();
                    698:                php_info_print_table_start();
                    699:                php_info_print_table_row(2, "System", php_uname );
                    700:                php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ );
                    701: #ifdef COMPILER
                    702:                php_info_print_table_row(2, "Compiler", COMPILER);
                    703: #endif
                    704: #ifdef ARCHITECTURE
                    705:                php_info_print_table_row(2, "Architecture", ARCHITECTURE);
                    706: #endif
                    707: #ifdef CONFIGURE_COMMAND
                    708:                php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
                    709: #endif
                    710: 
                    711:                if (sapi_module.pretty_name) {
                    712:                        php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
                    713:                }
                    714: 
                    715: #ifdef VIRTUAL_DIR
                    716:                php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
                    717: #else
                    718:                php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
                    719: #endif
                    720: 
                    721:                php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
                    722:                php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
                    723:                php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
                    724:                php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
                    725: 
                    726:                snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
                    727:                php_info_print_table_row(2, "PHP API", temp_api);
                    728: 
                    729:                snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO);
                    730:                php_info_print_table_row(2, "PHP Extension", temp_api);
                    731: 
                    732:                snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO);
                    733:                php_info_print_table_row(2, "Zend Extension", temp_api);
                    734: 
                    735:                php_info_print_table_row(2, "Zend Extension Build", ZEND_EXTENSION_BUILD_ID);
                    736:                php_info_print_table_row(2, "PHP Extension Build", ZEND_MODULE_BUILD_ID);
                    737: 
                    738: #if ZEND_DEBUG
                    739:                php_info_print_table_row(2, "Debug Build", "yes" );
                    740: #else
                    741:                php_info_print_table_row(2, "Debug Build", "no" );
                    742: #endif
                    743: 
                    744: #ifdef ZTS
                    745:                php_info_print_table_row(2, "Thread Safety", "enabled" );
                    746: #else
                    747:                php_info_print_table_row(2, "Thread Safety", "disabled" );
                    748: #endif
                    749: 
                    750:                php_info_print_table_row(2, "Zend Memory Manager", is_zend_mm(TSRMLS_C) ? "enabled" : "disabled" );
                    751: 
                    752: #ifdef ZEND_MULTIBYTE
                    753:                php_info_print_table_row(2, "Zend Multibyte Support", "enabled");
                    754: #else
                    755:                php_info_print_table_row(2, "Zend Multibyte Support", "disabled");
                    756: #endif
                    757: 
                    758: #if HAVE_IPV6
                    759:                php_info_print_table_row(2, "IPv6 Support", "enabled" );
                    760: #else
                    761:                php_info_print_table_row(2, "IPv6 Support", "disabled" );
                    762: #endif
                    763:                {
                    764:                        HashTable *url_stream_wrappers_hash;
                    765:                        char *stream_protocol, *stream_protocols_buf = NULL;
                    766:                        int stream_protocol_len, stream_protocols_buf_len = 0;
                    767:                        ulong num_key;
                    768: 
                    769:                        if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
                    770:                                HashPosition pos;
                    771:                                for (zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos);
                    772:                                                zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, (uint *)&stream_protocol_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
                    773:                                                zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
                    774:                                        stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1);
                    775:                                        memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len - 1);
                    776:                                        stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len - 1] = ',';
                    777:                                        stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ' ';
                    778:                                        stream_protocols_buf_len += stream_protocol_len + 1;
                    779:                                }
                    780:                                if (stream_protocols_buf) {
                    781:                                        stream_protocols_buf[stream_protocols_buf_len - 2] = ' ';
                    782:                                        stream_protocols_buf[stream_protocols_buf_len] = 0;
                    783:                                        php_info_print_table_row(2, "Registered PHP Streams", stream_protocols_buf);
                    784:                                        efree(stream_protocols_buf);
                    785:                                } else {
                    786:                                        /* Any chances we will ever hit this? */
                    787:                                        php_info_print_table_row(2, "Registered PHP Streams", "no streams registered");
                    788:                                }
                    789:                        } else {
                    790:                                /* Any chances we will ever hit this? */
                    791:                                php_info_print_table_row(2, "PHP Streams", "disabled"); /* ?? */
                    792:                        }
                    793:                }
                    794: 
                    795:                {
                    796:                        HashTable *stream_xport_hash;
                    797:                        char *xport_name, *xport_buf = NULL;
                    798:                        int xport_name_len, xport_buf_len = 0, xport_buf_size = 0;
                    799:                        ulong num_key;
                    800: 
                    801:                        if ((stream_xport_hash = php_stream_xport_get_hash())) {
                    802:                                HashPosition pos;
                    803:                                for(zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
                    804:                                        zend_hash_get_current_key_ex(stream_xport_hash, &xport_name, (uint *)&xport_name_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
                    805:                                        zend_hash_move_forward_ex(stream_xport_hash, &pos)) {
                    806:                                        if (xport_buf_len + xport_name_len + 2 > xport_buf_size) {
                    807:                                                while (xport_buf_len + xport_name_len + 2 > xport_buf_size) {
                    808:                                                        xport_buf_size += 256;
                    809:                                                }
                    810:                                                if (xport_buf) {
                    811:                                                        xport_buf = erealloc(xport_buf, xport_buf_size);
                    812:                                                } else {
                    813:                                                        xport_buf = emalloc(xport_buf_size);
                    814:                                                }
                    815:                                        }
                    816:                                        if (xport_buf_len > 0) {
                    817:                                                xport_buf[xport_buf_len++] = ',';
                    818:                                                xport_buf[xport_buf_len++] = ' ';
                    819:                                        }
                    820:                                        memcpy(xport_buf + xport_buf_len, xport_name, xport_name_len - 1);
                    821:                                        xport_buf_len += xport_name_len - 1;
                    822:                                        xport_buf[xport_buf_len] = '\0';
                    823:                                }
                    824:                                if (xport_buf) {
                    825:                                        php_info_print_table_row(2, "Registered Stream Socket Transports", xport_buf);
                    826:                                        efree(xport_buf);
                    827:                                } else {
                    828:                                        /* Any chances we will ever hit this? */
                    829:                                        php_info_print_table_row(2, "Registered Stream Socket Transports", "no transports registered");
                    830:                                }
                    831:                        } else {
                    832:                                /* Any chances we will ever hit this? */
                    833:                                php_info_print_table_row(2, "Stream Socket Transports", "disabled"); /* ?? */
                    834:                        }
                    835:                }
                    836: 
                    837:                {
                    838:                        HashTable *stream_filter_hash;
                    839:                        char *filter_name, *filter_buf = NULL;
                    840:                        int filter_name_len, filter_buf_len = 0, filter_buf_size = 0;
                    841:                        ulong num_key;
                    842: 
                    843:                        if ((stream_filter_hash = php_get_stream_filters_hash())) {
                    844:                                HashPosition pos;
                    845:                                for(zend_hash_internal_pointer_reset_ex(stream_filter_hash, &pos);
                    846:                                        zend_hash_get_current_key_ex(stream_filter_hash, &filter_name, (uint *)&filter_name_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
                    847:                                        zend_hash_move_forward_ex(stream_filter_hash, &pos)) {
                    848:                                        if (filter_buf_len + filter_name_len + 2 > filter_buf_size) {
                    849:                                                while (filter_buf_len + filter_name_len + 2 > filter_buf_size) {
                    850:                                                        filter_buf_size += 256;
                    851:                                                }
                    852:                                                if (filter_buf) {
                    853:                                                        filter_buf = erealloc(filter_buf, filter_buf_size);
                    854:                                                } else {
                    855:                                                        filter_buf = emalloc(filter_buf_size);
                    856:                                                }
                    857:                                        }
                    858:                                        if (filter_buf_len > 0) {
                    859:                                                filter_buf[filter_buf_len++] = ',';
                    860:                                                filter_buf[filter_buf_len++] = ' ';
                    861:                                        }
                    862:                                        memcpy(filter_buf + filter_buf_len, filter_name, filter_name_len - 1);
                    863:                                        filter_buf_len += filter_name_len - 1;
                    864:                                        filter_buf[filter_buf_len] = '\0';
                    865:                                }
                    866:                                if (filter_buf) {
                    867:                                        php_info_print_table_row(2, "Registered Stream Filters", filter_buf);
                    868:                                        efree(filter_buf);
                    869:                                } else {
                    870:                                        /* Any chances we will ever hit this? */
                    871:                                        php_info_print_table_row(2, "Registered Stream Filters", "no filters registered");
                    872:                                }
                    873:                        } else {
                    874:                                /* Any chances we will ever hit this? */
                    875:                                php_info_print_table_row(2, "Stream Filters", "disabled"); /* ?? */
                    876:                        }
                    877:                }
                    878:                
                    879:                php_info_print_table_end();
                    880: 
                    881:                /* Suhosin Patch */
                    882:                php_info_print_box_start(0);
                    883:                if (expose_php && !sapi_module.phpinfo_as_text) {
                    884:                        PUTS("<a href=\"http://www.suhosin.org\"><img border=\"0\" src=\"");
                    885:                        if (SG(request_info).request_uri) {
                    886:                                char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
                    887:                                PUTS(elem_esc);
                    888:                                efree(elem_esc);
                    889:                        }
                    890:                        PUTS("?="SUHOSIN_LOGO_GUID"\" alt=\"Suhosin logo\" /></a>\n");
                    891:                }
                    892:                PUTS("This server is protected with the Suhosin Patch ");
                    893:                if (sapi_module.phpinfo_as_text) {
                    894:                        PUTS(SUHOSIN_PATCH_VERSION);
                    895:                } else {
                    896:                        zend_html_puts(SUHOSIN_PATCH_VERSION, strlen(SUHOSIN_PATCH_VERSION) TSRMLS_CC);
                    897:                }
                    898:                PUTS(!sapi_module.phpinfo_as_text?"<br />":"\n");
                    899:                if (sapi_module.phpinfo_as_text) {
                    900:                        PUTS("Copyright (c) 2006-2007 Hardened-PHP Project\n");
                    901:                        PUTS("Copyright (c) 2007-2012 SektionEins GmbH\n");
                    902:                } else {
                    903:                        PUTS("Copyright (c) 2006-2007 <a href=\"http://www.hardened-php.net/\">Hardened-PHP Project</a>\n");
                    904:                        PUTS("Copyright (c) 2007-2012 <a href=\"http://www.sektioneins.de/\">SektionEins GmbH</a>\n");
                    905:                }
                    906:                php_info_print_box_end();
                    907: 
                    908:                /* Zend Engine */
                    909:                php_info_print_box_start(0);
                    910:                if (expose_php && !sapi_module.phpinfo_as_text) {
                    911:                        PUTS("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
                    912:                        if (SG(request_info).request_uri) {
                    913:                                char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
                    914:                                PUTS(elem_esc);
                    915:                                efree(elem_esc);
                    916:                        }
                    917:                        PUTS("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n");
                    918:                }
                    919:                PUTS("This program makes use of the Zend Scripting Language Engine:");
                    920:                PUTS(!sapi_module.phpinfo_as_text?"<br />":"\n");
                    921:                if (sapi_module.phpinfo_as_text) {
                    922:                        PUTS(zend_version);
                    923:                } else {
                    924:                        zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
                    925:                }
                    926:                php_info_print_box_end();
                    927:                efree(php_uname);
                    928:        }
                    929: 
                    930:        if ((flag & PHP_INFO_CREDITS) && expose_php && !sapi_module.phpinfo_as_text) {  
                    931:                php_info_print_hr();
                    932:                PUTS("<h1><a href=\"");
                    933:                if (SG(request_info).request_uri) {
                    934:                        char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
                    935:                        PUTS(elem_esc);
                    936:                        efree(elem_esc);
                    937:                }
                    938:                PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">");
                    939:                PUTS("PHP Credits");
                    940:                PUTS("</a></h1>\n");
                    941:        }
                    942: 
                    943:        zend_ini_sort_entries(TSRMLS_C);
                    944: 
                    945:        if (flag & PHP_INFO_CONFIGURATION) {
                    946:                php_info_print_hr();
                    947:                if (!sapi_module.phpinfo_as_text) {
                    948:                        PUTS("<h1>Configuration</h1>\n");
                    949:                } else {
                    950:                        SECTION("Configuration");
                    951:                }       
                    952:                if (!(flag & PHP_INFO_MODULES)) {
                    953:                        SECTION("PHP Core");
                    954:                        display_ini_entries(NULL);
                    955:                }
                    956:        }
                    957: 
                    958:        if (flag & PHP_INFO_MODULES) {
                    959:                HashTable sorted_registry;
                    960:                zend_module_entry tmp;
                    961: 
                    962:                zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
                    963:                zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
                    964:                zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
                    965: 
                    966:                zend_hash_apply(&sorted_registry, (apply_func_t) _display_module_info_func TSRMLS_CC);
                    967: 
                    968:                SECTION("Additional Modules");
                    969:                php_info_print_table_start();
                    970:                php_info_print_table_header(1, "Module Name");
                    971:                zend_hash_apply(&sorted_registry, (apply_func_t) _display_module_info_def TSRMLS_CC);
                    972:                php_info_print_table_end();
                    973: 
                    974:                zend_hash_destroy(&sorted_registry);
                    975:        }
                    976: 
                    977:        if (flag & PHP_INFO_ENVIRONMENT) {
                    978:                SECTION("Environment");
                    979:                php_info_print_table_start();
                    980:                php_info_print_table_header(2, "Variable", "Value");
                    981:                for (env=environ; env!=NULL && *env !=NULL; env++) {
                    982:                        tmp1 = estrdup(*env);
                    983:                        if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
                    984:                                efree(tmp1);
                    985:                                continue;
                    986:                        }
                    987:                        *tmp2 = 0;
                    988:                        tmp2++;
                    989:                        php_info_print_table_row(2, tmp1, tmp2);
                    990:                        efree(tmp1);
                    991:                }
                    992:                php_info_print_table_end();
                    993:        }
                    994: 
                    995:        if (flag & PHP_INFO_VARIABLES) {
                    996:                zval **data;
                    997: 
                    998:                SECTION("PHP Variables");
                    999: 
                   1000:                php_info_print_table_start();
                   1001:                php_info_print_table_header(2, "Variable", "Value");
                   1002:                if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) {
                   1003:                        php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_PP(data));
                   1004:                }
                   1005:                if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) {
                   1006:                        php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_PP(data));
                   1007:                }
                   1008:                if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) {
                   1009:                        php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_PP(data));
                   1010:                }
                   1011:                if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) {
                   1012:                        php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_PP(data));
                   1013:                }
                   1014:                php_print_gpcse_array("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC);
                   1015:                php_print_gpcse_array("_GET", sizeof("_GET")-1 TSRMLS_CC);
                   1016:                php_print_gpcse_array("_POST", sizeof("_POST")-1 TSRMLS_CC);
                   1017:                php_print_gpcse_array("_FILES", sizeof("_FILES")-1 TSRMLS_CC);
                   1018:                php_print_gpcse_array("_COOKIE", sizeof("_COOKIE")-1 TSRMLS_CC);
                   1019:                php_print_gpcse_array("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
                   1020:                php_print_gpcse_array("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
                   1021:                php_info_print_table_end();
                   1022:        }
                   1023: 
                   1024:        if (flag & PHP_INFO_LICENSE) {
                   1025:                if (!sapi_module.phpinfo_as_text) {
                   1026:                        SECTION("PHP License");
                   1027:                        php_info_print_box_start(0);
                   1028:                        PUTS("<p>\n");
                   1029:                        PUTS("This program is free software; you can redistribute it and/or modify ");
                   1030:                        PUTS("it under the terms of the PHP License as published by the PHP Group ");
                   1031:                        PUTS("and included in the distribution in the file:  LICENSE\n");
                   1032:                        PUTS("</p>\n");
                   1033:                        PUTS("<p>");
                   1034:                        PUTS("This program is distributed in the hope that it will be useful, ");
                   1035:                        PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
                   1036:                        PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
                   1037:                        PUTS("</p>\n");
                   1038:                        PUTS("<p>");
                   1039:                        PUTS("If you did not receive a copy of the PHP license, or have any questions about ");
                   1040:                        PUTS("PHP licensing, please contact license@php.net.\n");
                   1041:                        PUTS("</p>\n");
                   1042:                        php_info_print_box_end();
                   1043:                } else {
                   1044:                        PUTS("\nPHP License\n");
                   1045:                        PUTS("This program is free software; you can redistribute it and/or modify\n");
                   1046:                        PUTS("it under the terms of the PHP License as published by the PHP Group\n");
                   1047:                        PUTS("and included in the distribution in the file:  LICENSE\n");
                   1048:                        PUTS("\n");
                   1049:                        PUTS("This program is distributed in the hope that it will be useful,\n");
                   1050:                        PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
                   1051:                        PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
                   1052:                        PUTS("\n");
                   1053:                        PUTS("If you did not receive a copy of the PHP license, or have any\n");
                   1054:                        PUTS("questions about PHP licensing, please contact license@php.net.\n");
                   1055:                }
                   1056:        }
                   1057:        if (!sapi_module.phpinfo_as_text) {
                   1058:                PUTS("</div></body></html>");
                   1059:        }       
                   1060: }
                   1061: /* }}} */
                   1062: 
                   1063: 
                   1064: PHPAPI void php_info_print_table_start(void)
                   1065: {
                   1066:        if (!sapi_module.phpinfo_as_text) {
                   1067:                php_printf("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n");
                   1068:        } else {
                   1069:                php_printf("\n");
                   1070:        }       
                   1071: }
                   1072: 
                   1073: PHPAPI void php_info_print_table_end(void)
                   1074: {
                   1075:        if (!sapi_module.phpinfo_as_text) {
                   1076:                php_printf("</table><br />\n");
                   1077:        }
                   1078: 
                   1079: }
                   1080: 
                   1081: PHPAPI void php_info_print_box_start(int flag)
                   1082: {
                   1083:        php_info_print_table_start();
                   1084:        if (flag) {
                   1085:                if (!sapi_module.phpinfo_as_text) {
                   1086:                        php_printf("<tr class=\"h\"><td>\n");
                   1087:                }
                   1088:        } else {
                   1089:                if (!sapi_module.phpinfo_as_text) {
                   1090:                        php_printf("<tr class=\"v\"><td>\n");
                   1091:                } else {
                   1092:                        php_printf("\n");
                   1093:                }       
                   1094:        }
                   1095: }
                   1096: 
                   1097: PHPAPI void php_info_print_box_end(void)
                   1098: {
                   1099:        if (!sapi_module.phpinfo_as_text) {
                   1100:                php_printf("</td></tr>\n");
                   1101:        }
                   1102:        php_info_print_table_end();
                   1103: }
                   1104: 
                   1105: PHPAPI void php_info_print_hr(void)
                   1106: {
                   1107:        if (!sapi_module.phpinfo_as_text) {
                   1108:                php_printf("<hr />\n");
                   1109:        } else {
                   1110:                php_printf("\n\n _______________________________________________________________________\n\n");
                   1111:        }
                   1112: }
                   1113: 
                   1114: PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header)
                   1115: {
                   1116:        int spaces;
                   1117: 
                   1118:        if (!sapi_module.phpinfo_as_text) {
                   1119:                php_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
                   1120:        } else {
                   1121:                spaces = (74 - strlen(header));
                   1122:                php_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
                   1123:        }       
                   1124: }
                   1125: 
                   1126: /* {{{ php_info_print_table_header
                   1127:  */
                   1128: PHPAPI void php_info_print_table_header(int num_cols, ...)
                   1129: {
                   1130:        int i;
                   1131:        va_list row_elements;
                   1132:        char *row_element;
                   1133: 
                   1134:        TSRMLS_FETCH();
                   1135: 
                   1136:        va_start(row_elements, num_cols);
                   1137:        if (!sapi_module.phpinfo_as_text) {
                   1138:                php_printf("<tr class=\"h\">");
                   1139:        }       
                   1140:        for (i=0; i<num_cols; i++) {
                   1141:                row_element = va_arg(row_elements, char *);
                   1142:                if (!row_element || !*row_element) {
                   1143:                        row_element = " ";
                   1144:                }
                   1145:                if (!sapi_module.phpinfo_as_text) {
                   1146:                        PUTS("<th>");
                   1147:                        PUTS(row_element);
                   1148:                        PUTS("</th>");
                   1149:                } else {
                   1150:                        PUTS(row_element);
                   1151:                        if (i < num_cols-1) {
                   1152:                                PUTS(" => ");
                   1153:                        } else {
                   1154:                                PUTS("\n");
                   1155:                        }       
                   1156:                }       
                   1157:        }
                   1158:        if (!sapi_module.phpinfo_as_text) {
                   1159:                php_printf("</tr>\n");
                   1160:        }       
                   1161: 
                   1162:        va_end(row_elements);
                   1163: }
                   1164: /* }}} */
                   1165: 
                   1166: /* {{{ php_info_print_table_row_internal
                   1167:  */
                   1168: static void php_info_print_table_row_internal(int num_cols, 
                   1169:                const char *value_class, va_list row_elements)
                   1170: {
                   1171:        int i;
                   1172:        char *row_element;
                   1173:        char *elem_esc = NULL;
                   1174: /*
                   1175:        int elem_esc_len;
                   1176: */
                   1177: 
                   1178:        TSRMLS_FETCH();
                   1179: 
                   1180:        if (!sapi_module.phpinfo_as_text) {
                   1181:                php_printf("<tr>");
                   1182:        }       
                   1183:        for (i=0; i<num_cols; i++) {
                   1184:                if (!sapi_module.phpinfo_as_text) {
                   1185:                        php_printf("<td class=\"%s\">",
                   1186:                           (i==0 ? "e" : value_class )
                   1187:                        );
                   1188:                }       
                   1189:                row_element = va_arg(row_elements, char *);
                   1190:                if (!row_element || !*row_element) {
                   1191:                        if (!sapi_module.phpinfo_as_text) {
                   1192:                                PUTS( "<i>no value</i>" );
                   1193:                        } else {
                   1194:                                PUTS( " " );
                   1195:                        }
                   1196:                } else {
                   1197:                        if (!sapi_module.phpinfo_as_text) {
                   1198:                                elem_esc = php_info_html_esc(row_element TSRMLS_CC);
                   1199:                                PUTS(elem_esc);
                   1200:                                efree(elem_esc);
                   1201:                        } else {
                   1202:                                PUTS(row_element);
                   1203:                                if (i < num_cols-1) {
                   1204:                                        PUTS(" => ");
                   1205:                                }       
                   1206:                        }
                   1207:                }
                   1208:                if (!sapi_module.phpinfo_as_text) {
                   1209:                        php_printf(" </td>");
                   1210:                } else if (i == (num_cols - 1)) {
                   1211:                        PUTS("\n");
                   1212:                }
                   1213:        }
                   1214:        if (!sapi_module.phpinfo_as_text) {
                   1215:                php_printf("</tr>\n");
                   1216:        }
                   1217: }
                   1218: /* }}} */
                   1219: 
                   1220: /* {{{ php_info_print_table_row
                   1221:  */
                   1222: PHPAPI void php_info_print_table_row(int num_cols, ...)
                   1223: {
                   1224:        va_list row_elements;
                   1225:        
                   1226:        va_start(row_elements, num_cols);
                   1227:        php_info_print_table_row_internal(num_cols, "v", row_elements);
                   1228:        va_end(row_elements);
                   1229: }
                   1230: /* }}} */
                   1231: 
                   1232: /* {{{ php_info_print_table_row_ex
                   1233:  */
                   1234: PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class, 
                   1235:                ...)
                   1236: {
                   1237:        va_list row_elements;
                   1238:        
                   1239:        va_start(row_elements, value_class);
                   1240:        php_info_print_table_row_internal(num_cols, value_class, row_elements);
                   1241:        va_end(row_elements);
                   1242: }
                   1243: /* }}} */
                   1244: 
                   1245: /* {{{ register_phpinfo_constants
                   1246:  */
                   1247: void register_phpinfo_constants(INIT_FUNC_ARGS)
                   1248: {
                   1249:        REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
                   1250:        REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
                   1251:        REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
                   1252:        REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
                   1253:        REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
                   1254:        REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
                   1255:        REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
                   1256:        REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
                   1257:        REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
                   1258:        REGISTER_LONG_CONSTANT("CREDITS_GENERAL",       PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
                   1259:        REGISTER_LONG_CONSTANT("CREDITS_SAPI",  PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
                   1260:        REGISTER_LONG_CONSTANT("CREDITS_MODULES",       PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
                   1261:        REGISTER_LONG_CONSTANT("CREDITS_DOCS",  PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
                   1262:        REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",      PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
                   1263:        REGISTER_LONG_CONSTANT("CREDITS_QA",    PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
                   1264:        REGISTER_LONG_CONSTANT("CREDITS_ALL",   PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
                   1265: }
                   1266: /* }}} */
                   1267: 
                   1268: /* {{{ proto void phpinfo([int what])
                   1269:    Output a page of useful information about PHP and the current request */
                   1270: PHP_FUNCTION(phpinfo)
                   1271: {
                   1272:        long flag = PHP_INFO_ALL;
                   1273: 
                   1274:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
                   1275:                return;
                   1276:        }
                   1277: 
                   1278:        /* Andale!  Andale!  Yee-Hah! */
                   1279:        php_start_ob_buffer(NULL, 4096, 0 TSRMLS_CC);
                   1280:        php_print_info(flag TSRMLS_CC);
                   1281:        php_end_ob_buffer(1, 0 TSRMLS_CC);
                   1282: 
                   1283:        RETURN_TRUE;
                   1284: }
                   1285: 
                   1286: /* }}} */
                   1287: 
                   1288: /* {{{ proto string phpversion([string extension])
                   1289:    Return the current PHP version */
                   1290: PHP_FUNCTION(phpversion)
                   1291: {
                   1292:        zval **arg;
                   1293:        const char *version;
                   1294:        int argc = ZEND_NUM_ARGS();
                   1295: 
                   1296:        if (argc == 0) {
                   1297:                RETURN_STRING(PHP_VERSION, 1);
                   1298:        } else {
                   1299:                if (zend_parse_parameters(argc TSRMLS_CC, "Z", &arg) == FAILURE) {
                   1300:                        return;
                   1301:                }
                   1302:                        
                   1303:                convert_to_string_ex(arg);
                   1304:                version = zend_get_module_version(Z_STRVAL_PP(arg));
                   1305:                
                   1306:                if (version == NULL) {
                   1307:                        RETURN_FALSE;
                   1308:                }
                   1309:                RETURN_STRING(version, 1);
                   1310:        }
                   1311: }
                   1312: /* }}} */
                   1313: 
                   1314: /* {{{ proto void phpcredits([int flag])
                   1315:    Prints the list of people who've contributed to the PHP project */
                   1316: PHP_FUNCTION(phpcredits)
                   1317: {
                   1318:        long flag = PHP_CREDITS_ALL;
                   1319: 
                   1320:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
                   1321:                return;
                   1322:        }
                   1323: 
                   1324:        php_print_credits(flag TSRMLS_CC);
                   1325:        RETURN_TRUE;
                   1326: }
                   1327: /* }}} */
                   1328: 
                   1329: 
                   1330: /* {{{ php_logo_guid
                   1331:  */
                   1332: PHPAPI char *php_logo_guid(void)
                   1333: {
                   1334:        char *logo_guid;
                   1335: 
                   1336:        time_t the_time;
                   1337:        struct tm *ta, tmbuf;
                   1338: 
                   1339:        the_time = time(NULL);
                   1340:        ta = php_localtime_r(&the_time, &tmbuf);
                   1341: 
                   1342:        if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {
                   1343:                logo_guid = PHP_EGG_LOGO_GUID;
                   1344:        } else {
                   1345:                logo_guid = PHP_LOGO_GUID;
                   1346:        }
                   1347: 
                   1348:        return estrdup(logo_guid);
                   1349: 
                   1350: }
                   1351: /* }}} */
                   1352: 
                   1353: /* {{{ proto string php_logo_guid(void)
                   1354:    Return the special ID used to request the PHP logo in phpinfo screens*/
                   1355: PHP_FUNCTION(php_logo_guid)
                   1356: {
                   1357: 
                   1358:        if (zend_parse_parameters_none() == FAILURE) {
                   1359:                return;
                   1360:        }
                   1361: 
                   1362:        RETURN_STRING(php_logo_guid(), 0);
                   1363: }
                   1364: /* }}} */
                   1365: 
                   1366: /* {{{ proto string php_real_logo_guid(void)
                   1367:    Return the special ID used to request the PHP logo in phpinfo screens*/
                   1368: PHP_FUNCTION(php_real_logo_guid)
                   1369: {
                   1370: 
                   1371:        if (zend_parse_parameters_none() == FAILURE) {
                   1372:                return;
                   1373:        }
                   1374: 
                   1375:        RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1);
                   1376: }
                   1377: /* }}} */
                   1378: 
                   1379: /* {{{ proto string php_egg_logo_guid(void)
                   1380:    Return the special ID used to request the PHP logo in phpinfo screens*/
                   1381: PHP_FUNCTION(php_egg_logo_guid)
                   1382: {
                   1383:        if (zend_parse_parameters_none() == FAILURE) {
                   1384:                return;
                   1385:        }
                   1386: 
                   1387:        RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1);
                   1388: }
                   1389: /* }}} */
                   1390: 
                   1391: /* {{{ proto string zend_logo_guid(void)
                   1392:    Return the special ID used to request the Zend logo in phpinfo screens*/
                   1393: PHP_FUNCTION(zend_logo_guid)
                   1394: {
                   1395:        if (zend_parse_parameters_none() == FAILURE) {
                   1396:                return;
                   1397:        }
                   1398: 
                   1399:        RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1);
                   1400: }
                   1401: /* }}} */
                   1402: 
                   1403: /* {{{ proto string php_sapi_name(void)
                   1404:    Return the current SAPI module name */
                   1405: PHP_FUNCTION(php_sapi_name)
                   1406: {
                   1407:        if (zend_parse_parameters_none() == FAILURE) {
                   1408:                return;
                   1409:        }
                   1410: 
                   1411:        if (sapi_module.name) {
                   1412:                RETURN_STRING(sapi_module.name, 1);
                   1413:        } else {
                   1414:                RETURN_FALSE;
                   1415:        }
                   1416: }
                   1417: 
                   1418: /* }}} */
                   1419: 
                   1420: /* {{{ proto string php_uname(void)
                   1421:    Return information about the system PHP was built on */
                   1422: PHP_FUNCTION(php_uname)
                   1423: {
                   1424:        char *mode = "a";
                   1425:        int modelen = sizeof("a")-1;
                   1426:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) {
                   1427:                return;
                   1428:        }
                   1429:        RETURN_STRING(php_get_uname(*mode), 0);
                   1430: }
                   1431: 
                   1432: /* }}} */
                   1433: 
                   1434: /* {{{ proto string php_ini_scanned_files(void)
                   1435:    Return comma-separated string of .ini files parsed from the additional ini dir */
                   1436: PHP_FUNCTION(php_ini_scanned_files)
                   1437: {
                   1438:        if (zend_parse_parameters_none() == FAILURE) {
                   1439:                return;
                   1440:        }
                   1441:        
                   1442:        if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
                   1443:                RETURN_STRING(php_ini_scanned_files, 1);
                   1444:        } else {
                   1445:                RETURN_FALSE;
                   1446:        }
                   1447: }
                   1448: /* }}} */
                   1449: 
                   1450: /* {{{ proto string php_ini_loaded_file(void)
                   1451:    Return the actual loaded ini filename */
                   1452: PHP_FUNCTION(php_ini_loaded_file)
                   1453: {
                   1454:        if (zend_parse_parameters_none() == FAILURE) {
                   1455:                return;
                   1456:        }
                   1457:        
                   1458:        if (php_ini_opened_path) {
                   1459:                RETURN_STRING(php_ini_opened_path, 1);
                   1460:        } else {
                   1461:                RETURN_FALSE;
                   1462:        }
                   1463: }
                   1464: /* }}} */
                   1465: 
                   1466: /*
                   1467:  * Local variables:
                   1468:  * tab-width: 4
                   1469:  * c-basic-offset: 4
                   1470:  * End:
                   1471:  * vim600: sw=4 ts=4 fdm=marker
                   1472:  * vim<600: sw=4 ts=4
                   1473:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>