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