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