1/*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
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@viebrock.ca>                          |
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#include "url.h"
41#include "php_string.h"
42
43#ifdef PHP_WIN32
44typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
45typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
46# include "winver.h"
47
48#endif
49
50#define SECTION(name)   if (!sapi_module.phpinfo_as_text) { \
51                            php_info_print("<h2>" name "</h2>\n"); \
52                        } else { \
53                            php_info_print_table_start(); \
54                            php_info_print_table_header(1, name); \
55                            php_info_print_table_end(); \
56                        } \
57
58PHPAPI extern char *php_ini_opened_path;
59PHPAPI extern char *php_ini_scanned_path;
60PHPAPI extern char *php_ini_scanned_files;
61
62static int php_info_print_html_esc(const char *str, size_t len) /* {{{ */
63{
64    size_t written;
65    zend_string *new_str;
66
67    new_str = php_escape_html_entities((unsigned char *) str, len, 0, ENT_QUOTES, "utf-8");
68    written = php_output_write(new_str->val, new_str->len);
69    zend_string_free(new_str);
70    return written;
71}
72/* }}} */
73
74static int php_info_printf(const char *fmt, ...) /* {{{ */
75{
76    char *buf;
77    size_t len, written;
78    va_list argv;
79
80    va_start(argv, fmt);
81    len = vspprintf(&buf, 0, fmt, argv);
82    va_end(argv);
83
84    written = php_output_write(buf, len);
85    efree(buf);
86    return written;
87}
88/* }}} */
89
90static int php_info_print(const char *str) /* {{{ */
91{
92    return php_output_write(str, strlen(str));
93}
94/* }}} */
95
96static void php_info_print_stream_hash(const char *name, HashTable *ht) /* {{{ */
97{
98    zend_string *key;
99
100    if (ht) {
101        if (zend_hash_num_elements(ht)) {
102            int first = 1;
103
104            if (!sapi_module.phpinfo_as_text) {
105                php_info_printf("<tr><td class=\"e\">Registered %s</td><td class=\"v\">", name);
106            } else {
107                php_info_printf("\nRegistered %s => ", name);
108            }
109
110            ZEND_HASH_FOREACH_STR_KEY(ht, key) {
111                if (key) {
112                    if (first) {
113                        first = 0;
114                    } else {
115                        php_info_print(", ");
116                    }
117                    if (!sapi_module.phpinfo_as_text) {
118                        php_info_print_html_esc(key->val, key->len);
119                    } else {
120                        php_info_print(key->val);
121                    }
122                }
123            } ZEND_HASH_FOREACH_END();
124
125            if (!sapi_module.phpinfo_as_text) {
126                php_info_print("</td></tr>\n");
127            }
128        } else {
129            char reg_name[128];
130            snprintf(reg_name, sizeof(reg_name), "Registered %s", name);
131            php_info_print_table_row(2, reg_name, "none registered");
132        }
133    } else {
134        php_info_print_table_row(2, name, "disabled");
135    }
136}
137/* }}} */
138
139PHPAPI void php_info_print_module(zend_module_entry *zend_module) /* {{{ */
140{
141    if (zend_module->info_func || zend_module->version) {
142        if (!sapi_module.phpinfo_as_text) {
143            zend_string *url_name = php_url_encode(zend_module->name, strlen(zend_module->name));
144
145            php_strtolower(url_name->val, url_name->len);
146            php_info_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", url_name->val, zend_module->name);
147
148            efree(url_name);
149        } else {
150            php_info_print_table_start();
151            php_info_print_table_header(1, zend_module->name);
152            php_info_print_table_end();
153        }
154        if (zend_module->info_func) {
155            zend_module->info_func(zend_module);
156        } else {
157            php_info_print_table_start();
158            php_info_print_table_row(2, "Version", zend_module->version);
159            php_info_print_table_end();
160            DISPLAY_INI_ENTRIES();
161        }
162    } else {
163        if (!sapi_module.phpinfo_as_text) {
164            php_info_printf("<tr><td class=\"v\">%s</td></tr>\n", zend_module->name);
165        } else {
166            php_info_printf("%s\n", zend_module->name);
167        }
168    }
169}
170/* }}} */
171
172static int _display_module_info_func(zval *el) /* {{{ */
173{
174    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
175    if (module->info_func || module->version) {
176        php_info_print_module(module);
177    }
178    return ZEND_HASH_APPLY_KEEP;
179}
180/* }}} */
181
182static int _display_module_info_def(zval *el) /* {{{ */
183{
184    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
185    if (!module->info_func && !module->version) {
186        php_info_print_module(module);
187    }
188    return ZEND_HASH_APPLY_KEEP;
189}
190/* }}} */
191
192/* {{{ php_print_gpcse_array
193 */
194static void php_print_gpcse_array(char *name, uint name_length)
195{
196    zval *data, *tmp, tmp2;
197    zend_string *string_key;
198    zend_ulong num_key;
199    zend_string *key;
200
201    key = zend_string_init(name, name_length, 0);
202    zend_is_auto_global(key);
203
204    if ((data = zend_hash_find(&EG(symbol_table), key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) {
205        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) {
206            if (!sapi_module.phpinfo_as_text) {
207                php_info_print("<tr>");
208                php_info_print("<td class=\"e\">");
209            }
210
211            php_info_print("$");
212            php_info_print(name);
213            php_info_print("['");
214
215            if (string_key != NULL) {
216                if (!sapi_module.phpinfo_as_text) {
217                    php_info_print_html_esc(string_key->val, string_key->len);
218                } else {
219                    php_info_print(string_key->val);
220                }
221            } else {
222                php_info_printf(ZEND_ULONG_FMT, num_key);
223            }
224            php_info_print("']");
225            if (!sapi_module.phpinfo_as_text) {
226                php_info_print("</td><td class=\"v\">");
227            } else {
228                php_info_print(" => ");
229            }
230            if (Z_TYPE_P(tmp) == IS_ARRAY) {
231                if (!sapi_module.phpinfo_as_text) {
232                    php_info_print("<pre>");
233                    zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, tmp, 0);
234                    php_info_print("</pre>");
235                } else {
236                    zend_print_zval_r(tmp, 0);
237                }
238            } else {
239                ZVAL_COPY_VALUE(&tmp2, tmp);
240                if (Z_TYPE(tmp2) != IS_STRING) {
241                    tmp = NULL;
242                    zval_copy_ctor(&tmp2);
243                    convert_to_string(&tmp2);
244                }
245
246                if (!sapi_module.phpinfo_as_text) {
247                    if (Z_STRLEN(tmp2) == 0) {
248                        php_info_print("<i>no value</i>");
249                    } else {
250                        php_info_print_html_esc(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
251                    }
252                } else {
253                    php_info_print(Z_STRVAL(tmp2));
254                }
255
256                if (!tmp) {
257                    zval_dtor(&tmp2);
258                }
259            }
260            if (!sapi_module.phpinfo_as_text) {
261                php_info_print("</td></tr>\n");
262            } else {
263                php_info_print("\n");
264            }
265        } ZEND_HASH_FOREACH_END();
266    }
267    zend_string_free(key);
268}
269/* }}} */
270
271/* {{{ php_info_print_style
272 */
273void php_info_print_style(void)
274{
275    php_info_printf("<style type=\"text/css\">\n");
276    php_info_print_css();
277    php_info_printf("</style>\n");
278}
279/* }}} */
280
281/* {{{ php_info_html_esc
282 */
283PHPAPI zend_string *php_info_html_esc(char *string)
284{
285    return php_escape_html_entities((unsigned char *) string, strlen(string), 0, ENT_QUOTES, NULL);
286}
287/* }}} */
288
289#ifdef PHP_WIN32
290/* {{{  */
291
292char* php_get_windows_name()
293{
294    OSVERSIONINFOEX osvi = EG(windows_version_info);
295    SYSTEM_INFO si;
296    PGNSI pGNSI;
297    PGPI pGPI;
298    DWORD dwType;
299    char *major = NULL, *sub = NULL, *retval;
300
301    ZeroMemory(&si, sizeof(SYSTEM_INFO));
302
303    pGNSI = (PGNSI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
304    if(NULL != pGNSI) {
305        pGNSI(&si);
306    } else {
307        GetSystemInfo(&si);
308    }
309
310    if (VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion >= 6 ) {
311        if (osvi.dwMajorVersion == 6) {
312            if( osvi.dwMinorVersion == 0 ) {
313                if( osvi.wProductType == VER_NT_WORKSTATION ) {
314                    major = "Windows Vista";
315                } else {
316                    major = "Windows Server 2008";
317                }
318            } else if ( osvi.dwMinorVersion == 1 ) {
319                if( osvi.wProductType == VER_NT_WORKSTATION )  {
320                    major = "Windows 7";
321                } else {
322                    major = "Windows Server 2008 R2";
323                }
324            } else if ( osvi.dwMinorVersion == 2 ) {
325                /* could be Windows 8/Windows Server 2012, could be Windows 8.1/Windows Server 2012 R2 */
326                OSVERSIONINFOEX osvi81;
327                DWORDLONG dwlConditionMask = 0;
328                int op = VER_GREATER_EQUAL;
329
330                ZeroMemory(&osvi81, sizeof(OSVERSIONINFOEX));
331                osvi81.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
332                osvi81.dwMajorVersion = 6;
333                osvi81.dwMinorVersion = 3;
334                osvi81.wServicePackMajor = 0;
335
336                VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
337                VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
338                VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR, op);
339
340                if (VerifyVersionInfo(&osvi81,
341                    VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
342                    dwlConditionMask)) {
343                    osvi.dwMinorVersion = 3; /* Windows 8.1/Windows Server 2012 R2 */
344                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
345                        major = "Windows 8.1";
346                    } else {
347                        major = "Windows Server 2012 R2";
348                    }
349                } else {
350                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
351                        major = "Windows 8";
352                    } else {
353                        major = "Windows Server 2012";
354                    }
355                }
356            } else {
357                major = "Unknown Windows version";
358            }
359
360            pGPI = (PGPI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo");
361            pGPI(6, 0, 0, 0, &dwType);
362
363            switch (dwType) {
364                case PRODUCT_ULTIMATE:
365                    sub = "Ultimate Edition";
366                    break;
367                case PRODUCT_HOME_PREMIUM:
368                    sub = "Home Premium Edition";
369                    break;
370                case PRODUCT_HOME_BASIC:
371                    sub = "Home Basic Edition";
372                    break;
373                case PRODUCT_ENTERPRISE:
374                    sub = "Enterprise Edition";
375                    break;
376                case PRODUCT_BUSINESS:
377                    sub = "Business Edition";
378                    break;
379                case PRODUCT_STARTER:
380                    sub = "Starter Edition";
381                    break;
382                case PRODUCT_CLUSTER_SERVER:
383                    sub = "Cluster Server Edition";
384                    break;
385                case PRODUCT_DATACENTER_SERVER:
386                    sub = "Datacenter Edition";
387                    break;
388                case PRODUCT_DATACENTER_SERVER_CORE:
389                    sub = "Datacenter Edition (core installation)";
390                    break;
391                case PRODUCT_ENTERPRISE_SERVER:
392                    sub = "Enterprise Edition";
393                    break;
394                case PRODUCT_ENTERPRISE_SERVER_CORE:
395                    sub = "Enterprise Edition (core installation)";
396                    break;
397                case PRODUCT_ENTERPRISE_SERVER_IA64:
398                    sub = "Enterprise Edition for Itanium-based Systems";
399                    break;
400                case PRODUCT_SMALLBUSINESS_SERVER:
401                    sub = "Small Business Server";
402                    break;
403                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
404                    sub = "Small Business Server Premium Edition";
405                    break;
406                case PRODUCT_STANDARD_SERVER:
407                    sub = "Standard Edition";
408                    break;
409                case PRODUCT_STANDARD_SERVER_CORE:
410                    sub = "Standard Edition (core installation)";
411                    break;
412                case PRODUCT_WEB_SERVER:
413                    sub = "Web Server Edition";
414                    break;
415            }
416        }
417    } else {
418        return NULL;
419    }
420
421    spprintf(&retval, 0, "%s%s%s%s%s", major, sub?" ":"", sub?sub:"", osvi.szCSDVersion[0] != '\0'?" ":"", osvi.szCSDVersion);
422    return retval;
423}
424/* }}}  */
425
426/* {{{  */
427void php_get_windows_cpu(char *buf, int bufsize)
428{
429    SYSTEM_INFO SysInfo;
430    GetSystemInfo(&SysInfo);
431    switch (SysInfo.wProcessorArchitecture) {
432        case PROCESSOR_ARCHITECTURE_INTEL :
433            snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
434            break;
435        case PROCESSOR_ARCHITECTURE_MIPS :
436            snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
437            break;
438        case PROCESSOR_ARCHITECTURE_ALPHA :
439            snprintf(buf, bufsize, "Alpha %d", SysInfo.wProcessorLevel);
440            break;
441        case PROCESSOR_ARCHITECTURE_PPC :
442            snprintf(buf, bufsize, "PPC 6%02d", SysInfo.wProcessorLevel);
443            break;
444        case PROCESSOR_ARCHITECTURE_IA64 :
445            snprintf(buf, bufsize,  "IA64");
446            break;
447#if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64)
448        case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 :
449            snprintf(buf, bufsize, "IA32");
450            break;
451#endif
452#if defined(PROCESSOR_ARCHITECTURE_AMD64)
453        case PROCESSOR_ARCHITECTURE_AMD64 :
454            snprintf(buf, bufsize, "AMD64");
455            break;
456#endif
457        case PROCESSOR_ARCHITECTURE_UNKNOWN :
458        default:
459            snprintf(buf, bufsize, "Unknown");
460            break;
461    }
462}
463/* }}}  */
464#endif
465
466/* {{{ php_get_uname
467 */
468PHPAPI zend_string *php_get_uname(char mode)
469{
470    char *php_uname;
471    char tmp_uname[256];
472#ifdef PHP_WIN32
473    DWORD dwBuild=0;
474    DWORD dwVersion = GetVersion();
475    DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
476    DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
477    DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
478    char ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
479
480    GetComputerName(ComputerName, &dwSize);
481
482    if (mode == 's') {
483        php_uname = "Windows NT";
484    } else if (mode == 'r') {
485        snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
486        php_uname = tmp_uname;
487    } else if (mode == 'n') {
488        php_uname = ComputerName;
489    } else if (mode == 'v') {
490        char *winver = php_get_windows_name();
491        dwBuild = (DWORD)(HIWORD(dwVersion));
492        if(winver == NULL) {
493            snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild);
494        } else {
495            snprintf(tmp_uname, sizeof(tmp_uname), "build %d (%s)", dwBuild, winver);
496        }
497        php_uname = tmp_uname;
498        if(winver) {
499            efree(winver);
500        }
501    } else if (mode == 'm') {
502        php_get_windows_cpu(tmp_uname, sizeof(tmp_uname));
503        php_uname = tmp_uname;
504    } else { /* assume mode == 'a' */
505        char *winver = php_get_windows_name();
506        char wincpu[20];
507
508        ZEND_ASSERT(winver != NULL);
509
510        php_get_windows_cpu(wincpu, sizeof(wincpu));
511        dwBuild = (DWORD)(HIWORD(dwVersion));
512
513        /* Windows "version" 6.2 could be Windows 8/Windows Server 2012, but also Windows 8.1/Windows Server 2012 R2 */
514        if (dwWindowsMajorVersion == 6 && dwWindowsMinorVersion == 2) {
515            if (strncmp(winver, "Windows 8.1", 11) == 0 || strncmp(winver, "Windows Server 2012 R2", 22) == 0) {
516                dwWindowsMinorVersion = 3;
517            }
518        }
519
520        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d (%s) %s",
521                 "Windows NT", ComputerName,
522                 dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild, winver?winver:"unknown", wincpu);
523        if(winver) {
524            efree(winver);
525        }
526        php_uname = tmp_uname;
527    }
528#else
529#ifdef HAVE_SYS_UTSNAME_H
530    struct utsname buf;
531    if (uname((struct utsname *)&buf) == -1) {
532        php_uname = PHP_UNAME;
533    } else {
534#ifdef NETWARE
535        if (mode == 's') {
536            php_uname = buf.sysname;
537        } else if (mode == 'r') {
538            snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d",
539                     buf.netware_major, buf.netware_minor, buf.netware_revision);
540            php_uname = tmp_uname;
541        } else if (mode == 'n') {
542            php_uname = buf.servername;
543        } else if (mode == 'v') {
544            snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d",
545                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold);
546            php_uname = tmp_uname;
547        } else if (mode == 'm') {
548            php_uname = buf.machine;
549        } else { /* assume mode == 'a' */
550            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s",
551                     buf.sysname, buf.servername,
552                     buf.netware_major, buf.netware_minor, buf.netware_revision,
553                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold,
554                     buf.machine);
555            php_uname = tmp_uname;
556        }
557#else
558        if (mode == 's') {
559            php_uname = buf.sysname;
560        } else if (mode == 'r') {
561            php_uname = buf.release;
562        } else if (mode == 'n') {
563            php_uname = buf.nodename;
564        } else if (mode == 'v') {
565            php_uname = buf.version;
566        } else if (mode == 'm') {
567            php_uname = buf.machine;
568        } else { /* assume mode == 'a' */
569            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
570                     buf.sysname, buf.nodename, buf.release, buf.version,
571                     buf.machine);
572            php_uname = tmp_uname;
573        }
574#endif /* NETWARE */
575    }
576#else
577    php_uname = PHP_UNAME;
578#endif
579#endif
580    return zend_string_init(php_uname, strlen(php_uname), 0);
581}
582/* }}} */
583
584/* {{{ php_print_info_htmlhead
585 */
586PHPAPI void php_print_info_htmlhead(void)
587{
588    php_info_print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
589    php_info_print("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
590    php_info_print("<head>\n");
591    php_info_print_style();
592    php_info_print("<title>phpinfo()</title>");
593    php_info_print("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
594    php_info_print("</head>\n");
595    php_info_print("<body><div class=\"center\">\n");
596}
597/* }}} */
598
599/* {{{ module_name_cmp */
600static int module_name_cmp(const void *a, const void *b)
601{
602    Bucket *f = (Bucket *) a;
603    Bucket *s = (Bucket *) b;
604
605    return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name,
606                  ((zend_module_entry *)Z_PTR(s->val))->name);
607}
608/* }}} */
609
610/* {{{ php_print_info
611 */
612PHPAPI void php_print_info(int flag)
613{
614    char **env, *tmp1, *tmp2;
615    zend_string *php_uname;
616
617    if (!sapi_module.phpinfo_as_text) {
618        php_print_info_htmlhead();
619    } else {
620        php_info_print("phpinfo()\n");
621    }
622
623    if (flag & PHP_INFO_GENERAL) {
624        char *zend_version = get_zend_version();
625        char temp_api[10];
626
627        php_uname = php_get_uname('a');
628
629        if (!sapi_module.phpinfo_as_text) {
630            php_info_print_box_start(1);
631        }
632
633        if (!sapi_module.phpinfo_as_text) {
634            time_t the_time;
635            struct tm *ta, tmbuf;
636
637            the_time = time(NULL);
638            ta = php_localtime_r(&the_time, &tmbuf);
639
640            php_info_print("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
641            if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {
642                php_info_print(PHP_EGG_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
643            } else {
644                php_info_print(PHP_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
645            }
646        }
647
648        if (!sapi_module.phpinfo_as_text) {
649            php_info_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
650        } else {
651            php_info_print_table_row(2, "PHP Version", PHP_VERSION);
652        }
653        php_info_print_box_end();
654        php_info_print_table_start();
655        php_info_print_table_row(2, "System", php_uname->val);
656        php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
657#ifdef COMPILER
658        php_info_print_table_row(2, "Compiler", COMPILER);
659#endif
660#ifdef ARCHITECTURE
661        php_info_print_table_row(2, "Architecture", ARCHITECTURE);
662#endif
663#ifdef CONFIGURE_COMMAND
664        php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
665#endif
666
667        if (sapi_module.pretty_name) {
668            php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
669        }
670
671#ifdef VIRTUAL_DIR
672        php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
673#else
674        php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
675#endif
676
677        php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
678        php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
679        php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
680        php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
681
682        snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
683        php_info_print_table_row(2, "PHP API", temp_api);
684
685        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO);
686        php_info_print_table_row(2, "PHP Extension", temp_api);
687
688        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO);
689        php_info_print_table_row(2, "Zend Extension", temp_api);
690
691        php_info_print_table_row(2, "Zend Extension Build", ZEND_EXTENSION_BUILD_ID);
692        php_info_print_table_row(2, "PHP Extension Build", ZEND_MODULE_BUILD_ID);
693
694#if ZEND_DEBUG
695        php_info_print_table_row(2, "Debug Build", "yes" );
696#else
697        php_info_print_table_row(2, "Debug Build", "no" );
698#endif
699
700#ifdef ZTS
701        php_info_print_table_row(2, "Thread Safety", "enabled" );
702#else
703        php_info_print_table_row(2, "Thread Safety", "disabled" );
704#endif
705
706#ifdef ZEND_SIGNALS
707        php_info_print_table_row(2, "Zend Signal Handling", "enabled" );
708#else
709        php_info_print_table_row(2, "Zend Signal Handling", "disabled" );
710#endif
711
712        php_info_print_table_row(2, "Zend Memory Manager", is_zend_mm() ? "enabled" : "disabled" );
713
714        {
715            const zend_multibyte_functions *functions = zend_multibyte_get_functions();
716            char *descr;
717            if (functions) {
718                spprintf(&descr, 0, "provided by %s", functions->provider_name);
719            } else {
720                descr = estrdup("disabled");
721            }
722            php_info_print_table_row(2, "Zend Multibyte Support", descr);
723            efree(descr);
724        }
725
726#if HAVE_IPV6
727        php_info_print_table_row(2, "IPv6 Support", "enabled" );
728#else
729        php_info_print_table_row(2, "IPv6 Support", "disabled" );
730#endif
731
732#if HAVE_DTRACE
733        php_info_print_table_row(2, "DTrace Support", "enabled" );
734#else
735        php_info_print_table_row(2, "DTrace Support", "disabled" );
736#endif
737
738        php_info_print_stream_hash("PHP Streams",  php_stream_get_url_stream_wrappers_hash());
739        php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash());
740        php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash());
741
742        php_info_print_table_end();
743
744        /* Zend Engine */
745        php_info_print_box_start(0);
746        if (!sapi_module.phpinfo_as_text) {
747            php_info_print("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
748            php_info_print(ZEND_LOGO_DATA_URI "\" alt=\"Zend logo\" /></a>\n");
749        }
750        php_info_print("This program makes use of the Zend Scripting Language Engine:");
751        php_info_print(!sapi_module.phpinfo_as_text?"<br />":"\n");
752        if (sapi_module.phpinfo_as_text) {
753            php_info_print(zend_version);
754        } else {
755            zend_html_puts(zend_version, strlen(zend_version));
756        }
757        php_info_print_box_end();
758        zend_string_free(php_uname);
759    }
760
761    zend_ini_sort_entries();
762
763    if (flag & PHP_INFO_CONFIGURATION) {
764        php_info_print_hr();
765        if (!sapi_module.phpinfo_as_text) {
766            php_info_print("<h1>Configuration</h1>\n");
767        } else {
768            SECTION("Configuration");
769        }
770        if (!(flag & PHP_INFO_MODULES)) {
771            SECTION("PHP Core");
772            display_ini_entries(NULL);
773        }
774    }
775
776    if (flag & PHP_INFO_MODULES) {
777        HashTable sorted_registry;
778
779        zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
780        zend_hash_copy(&sorted_registry, &module_registry, NULL);
781        zend_hash_sort(&sorted_registry, module_name_cmp, 0);
782
783        zend_hash_apply(&sorted_registry, _display_module_info_func);
784
785        SECTION("Additional Modules");
786        php_info_print_table_start();
787        php_info_print_table_header(1, "Module Name");
788        zend_hash_apply(&sorted_registry, _display_module_info_def);
789        php_info_print_table_end();
790
791        zend_hash_destroy(&sorted_registry);
792    }
793
794    if (flag & PHP_INFO_ENVIRONMENT) {
795        SECTION("Environment");
796        php_info_print_table_start();
797        php_info_print_table_header(2, "Variable", "Value");
798        for (env=environ; env!=NULL && *env !=NULL; env++) {
799            tmp1 = estrdup(*env);
800            if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
801                efree(tmp1);
802                continue;
803            }
804            *tmp2 = 0;
805            tmp2++;
806            php_info_print_table_row(2, tmp1, tmp2);
807            efree(tmp1);
808        }
809        php_info_print_table_end();
810    }
811
812    if (flag & PHP_INFO_VARIABLES) {
813        zval *data;
814
815        SECTION("PHP Variables");
816
817        php_info_print_table_start();
818        php_info_print_table_header(2, "Variable", "Value");
819        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
820            php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_P(data));
821        }
822        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
823            php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_P(data));
824        }
825        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
826            php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_P(data));
827        }
828        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
829            php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_P(data));
830        }
831        php_print_gpcse_array(ZEND_STRL("_REQUEST"));
832        php_print_gpcse_array(ZEND_STRL("_GET"));
833        php_print_gpcse_array(ZEND_STRL("_POST"));
834        php_print_gpcse_array(ZEND_STRL("_FILES"));
835        php_print_gpcse_array(ZEND_STRL("_COOKIE"));
836        php_print_gpcse_array(ZEND_STRL("_SERVER"));
837        php_print_gpcse_array(ZEND_STRL("_ENV"));
838        php_info_print_table_end();
839    }
840
841
842    if ((flag & PHP_INFO_CREDITS) && !sapi_module.phpinfo_as_text) {
843        php_info_print_hr();
844        php_print_credits(PHP_CREDITS_ALL & ~PHP_CREDITS_FULLPAGE);
845    }
846
847    if (flag & PHP_INFO_LICENSE) {
848        if (!sapi_module.phpinfo_as_text) {
849            SECTION("PHP License");
850            php_info_print_box_start(0);
851            php_info_print("<p>\n");
852            php_info_print("This program is free software; you can redistribute it and/or modify ");
853            php_info_print("it under the terms of the PHP License as published by the PHP Group ");
854            php_info_print("and included in the distribution in the file:  LICENSE\n");
855            php_info_print("</p>\n");
856            php_info_print("<p>");
857            php_info_print("This program is distributed in the hope that it will be useful, ");
858            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
859            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
860            php_info_print("</p>\n");
861            php_info_print("<p>");
862            php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
863            php_info_print("PHP licensing, please contact license@php.net.\n");
864            php_info_print("</p>\n");
865            php_info_print_box_end();
866        } else {
867            php_info_print("\nPHP License\n");
868            php_info_print("This program is free software; you can redistribute it and/or modify\n");
869            php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
870            php_info_print("and included in the distribution in the file:  LICENSE\n");
871            php_info_print("\n");
872            php_info_print("This program is distributed in the hope that it will be useful,\n");
873            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
874            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
875            php_info_print("\n");
876            php_info_print("If you did not receive a copy of the PHP license, or have any\n");
877            php_info_print("questions about PHP licensing, please contact license@php.net.\n");
878        }
879    }
880
881    if (!sapi_module.phpinfo_as_text) {
882        php_info_print("</div></body></html>");
883    }
884}
885/* }}} */
886
887PHPAPI void php_info_print_table_start(void) /* {{{ */
888{
889    if (!sapi_module.phpinfo_as_text) {
890        php_info_print("<table>\n");
891    } else {
892        php_info_print("\n");
893    }
894}
895/* }}} */
896
897PHPAPI void php_info_print_table_end(void) /* {{{ */
898{
899    if (!sapi_module.phpinfo_as_text) {
900        php_info_print("</table>\n");
901    }
902
903}
904/* }}} */
905
906PHPAPI void php_info_print_box_start(int flag) /* {{{ */
907{
908    php_info_print_table_start();
909    if (flag) {
910        if (!sapi_module.phpinfo_as_text) {
911            php_info_print("<tr class=\"h\"><td>\n");
912        }
913    } else {
914        if (!sapi_module.phpinfo_as_text) {
915            php_info_print("<tr class=\"v\"><td>\n");
916        } else {
917            php_info_print("\n");
918        }
919    }
920}
921/* }}} */
922
923PHPAPI void php_info_print_box_end(void) /* {{{ */
924{
925    if (!sapi_module.phpinfo_as_text) {
926        php_info_print("</td></tr>\n");
927    }
928    php_info_print_table_end();
929}
930/* }}} */
931
932PHPAPI void php_info_print_hr(void) /* {{{ */
933{
934    if (!sapi_module.phpinfo_as_text) {
935        php_info_print("<hr />\n");
936    } else {
937        php_info_print("\n\n _______________________________________________________________________\n\n");
938    }
939}
940/* }}} */
941
942PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
943{
944    int spaces;
945
946    if (!sapi_module.phpinfo_as_text) {
947        php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
948    } else {
949        spaces = (int)(74 - strlen(header));
950        php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
951    }
952}
953/* }}} */
954
955/* {{{ php_info_print_table_header
956 */
957PHPAPI void php_info_print_table_header(int num_cols, ...)
958{
959    int i;
960    va_list row_elements;
961    char *row_element;
962
963    va_start(row_elements, num_cols);
964    if (!sapi_module.phpinfo_as_text) {
965        php_info_print("<tr class=\"h\">");
966    }
967    for (i=0; i<num_cols; i++) {
968        row_element = va_arg(row_elements, char *);
969        if (!row_element || !*row_element) {
970            row_element = " ";
971        }
972        if (!sapi_module.phpinfo_as_text) {
973            php_info_print("<th>");
974            php_info_print(row_element);
975            php_info_print("</th>");
976        } else {
977            php_info_print(row_element);
978            if (i < num_cols-1) {
979                php_info_print(" => ");
980            } else {
981                php_info_print("\n");
982            }
983        }
984    }
985    if (!sapi_module.phpinfo_as_text) {
986        php_info_print("</tr>\n");
987    }
988
989    va_end(row_elements);
990}
991/* }}} */
992
993/* {{{ php_info_print_table_row_internal
994 */
995static void php_info_print_table_row_internal(int num_cols,
996        const char *value_class, va_list row_elements)
997{
998    int i;
999    char *row_element;
1000
1001    if (!sapi_module.phpinfo_as_text) {
1002        php_info_print("<tr>");
1003    }
1004    for (i=0; i<num_cols; i++) {
1005        if (!sapi_module.phpinfo_as_text) {
1006            php_info_printf("<td class=\"%s\">",
1007               (i==0 ? "e" : value_class )
1008            );
1009        }
1010        row_element = va_arg(row_elements, char *);
1011        if (!row_element || !*row_element) {
1012            if (!sapi_module.phpinfo_as_text) {
1013                php_info_print( "<i>no value</i>" );
1014            } else {
1015                php_info_print( " " );
1016            }
1017        } else {
1018            if (!sapi_module.phpinfo_as_text) {
1019                php_info_print_html_esc(row_element, strlen(row_element));
1020            } else {
1021                php_info_print(row_element);
1022                if (i < num_cols-1) {
1023                    php_info_print(" => ");
1024                }
1025            }
1026        }
1027        if (!sapi_module.phpinfo_as_text) {
1028            php_info_print(" </td>");
1029        } else if (i == (num_cols - 1)) {
1030            php_info_print("\n");
1031        }
1032    }
1033    if (!sapi_module.phpinfo_as_text) {
1034        php_info_print("</tr>\n");
1035    }
1036}
1037/* }}} */
1038
1039/* {{{ php_info_print_table_row
1040 */
1041PHPAPI void php_info_print_table_row(int num_cols, ...)
1042{
1043    va_list row_elements;
1044
1045    va_start(row_elements, num_cols);
1046    php_info_print_table_row_internal(num_cols, "v", row_elements);
1047    va_end(row_elements);
1048}
1049/* }}} */
1050
1051/* {{{ php_info_print_table_row_ex
1052 */
1053PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class,
1054        ...)
1055{
1056    va_list row_elements;
1057
1058    va_start(row_elements, value_class);
1059    php_info_print_table_row_internal(num_cols, value_class, row_elements);
1060    va_end(row_elements);
1061}
1062/* }}} */
1063
1064/* {{{ register_phpinfo_constants
1065 */
1066void register_phpinfo_constants(INIT_FUNC_ARGS)
1067{
1068    REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
1069    REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
1070    REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
1071    REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
1072    REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
1073    REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
1074    REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
1075    REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
1076    REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
1077    REGISTER_LONG_CONSTANT("CREDITS_GENERAL",   PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
1078    REGISTER_LONG_CONSTANT("CREDITS_SAPI",  PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
1079    REGISTER_LONG_CONSTANT("CREDITS_MODULES",   PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
1080    REGISTER_LONG_CONSTANT("CREDITS_DOCS",  PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
1081    REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",  PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
1082    REGISTER_LONG_CONSTANT("CREDITS_QA",    PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
1083    REGISTER_LONG_CONSTANT("CREDITS_ALL",   PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
1084}
1085/* }}} */
1086
1087/* {{{ proto void phpinfo([int what])
1088   Output a page of useful information about PHP and the current request */
1089PHP_FUNCTION(phpinfo)
1090{
1091    zend_long flag = PHP_INFO_ALL;
1092
1093    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flag) == FAILURE) {
1094        return;
1095    }
1096
1097    /* Andale!  Andale!  Yee-Hah! */
1098    php_output_start_default();
1099    php_print_info((int)flag);
1100    php_output_end();
1101
1102    RETURN_TRUE;
1103}
1104
1105/* }}} */
1106
1107/* {{{ proto string phpversion([string extension])
1108   Return the current PHP version */
1109PHP_FUNCTION(phpversion)
1110{
1111    char *ext_name = NULL;
1112    size_t ext_name_len = 0;
1113
1114    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ext_name, &ext_name_len) == FAILURE) {
1115        return;
1116    }
1117
1118    if (!ext_name) {
1119        RETURN_STRING(PHP_VERSION);
1120    } else {
1121        const char *version;
1122        version = zend_get_module_version(ext_name);
1123        if (version == NULL) {
1124            RETURN_FALSE;
1125        }
1126        RETURN_STRING(version);
1127    }
1128}
1129/* }}} */
1130
1131/* {{{ proto void phpcredits([int flag])
1132   Prints the list of people who've contributed to the PHP project */
1133PHP_FUNCTION(phpcredits)
1134{
1135    zend_long flag = PHP_CREDITS_ALL;
1136
1137    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flag) == FAILURE) {
1138        return;
1139    }
1140
1141    php_print_credits((int)flag);
1142    RETURN_TRUE;
1143}
1144/* }}} */
1145
1146/* {{{ proto string php_sapi_name(void)
1147   Return the current SAPI module name */
1148PHP_FUNCTION(php_sapi_name)
1149{
1150    if (zend_parse_parameters_none() == FAILURE) {
1151        return;
1152    }
1153
1154    if (sapi_module.name) {
1155        RETURN_STRING(sapi_module.name);
1156    } else {
1157        RETURN_FALSE;
1158    }
1159}
1160
1161/* }}} */
1162
1163/* {{{ proto string php_uname(void)
1164   Return information about the system PHP was built on */
1165PHP_FUNCTION(php_uname)
1166{
1167    char *mode = "a";
1168    size_t modelen = sizeof("a")-1;
1169
1170    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &mode, &modelen) == FAILURE) {
1171        return;
1172    }
1173    RETURN_STR(php_get_uname(*mode));
1174}
1175
1176/* }}} */
1177
1178/* {{{ proto string php_ini_scanned_files(void)
1179   Return comma-separated string of .ini files parsed from the additional ini dir */
1180PHP_FUNCTION(php_ini_scanned_files)
1181{
1182    if (zend_parse_parameters_none() == FAILURE) {
1183        return;
1184    }
1185
1186    if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
1187        RETURN_STRING(php_ini_scanned_files);
1188    } else {
1189        RETURN_FALSE;
1190    }
1191}
1192/* }}} */
1193
1194/* {{{ proto string php_ini_loaded_file(void)
1195   Return the actual loaded ini filename */
1196PHP_FUNCTION(php_ini_loaded_file)
1197{
1198    if (zend_parse_parameters_none() == FAILURE) {
1199        return;
1200    }
1201
1202    if (php_ini_opened_path) {
1203        RETURN_STRING(php_ini_opened_path);
1204    } else {
1205        RETURN_FALSE;
1206    }
1207}
1208/* }}} */
1209
1210/*
1211 * Local variables:
1212 * tab-width: 4
1213 * c-basic-offset: 4
1214 * End:
1215 * vim600: sw=4 ts=4 fdm=marker
1216 * vim<600: sw=4 ts=4
1217 */
1218