xref: /PHP-5.4/ext/standard/info.c (revision ae745492)
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
43 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
44 typedef 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 
60 PHPAPI extern char *php_ini_opened_path;
61 PHPAPI extern char *php_ini_scanned_path;
62 PHPAPI extern char *php_ini_scanned_files;
63 
php_info_print_html_esc(const char * str,int len)64 static 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 
php_info_printf(const char * fmt,...)78 static 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 
php_info_print_request_uri(TSRMLS_D)95 static 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 
php_info_print(const char * str)103 static int php_info_print(const char *str) /* {{{ */
104 {
105 	TSRMLS_FETCH();
106 	return php_output_write(str, strlen(str) TSRMLS_CC);
107 }
108 /* }}} */
109 
php_info_print_stream_hash(const char * name,HashTable * ht TSRMLS_DC)110 static 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 
php_info_print_module(zend_module_entry * zend_module TSRMLS_DC)155 PHPAPI 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 
_display_module_info_func(zend_module_entry * module TSRMLS_DC)183 static 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 
_display_module_info_def(zend_module_entry * module TSRMLS_DC)192 static 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  */
php_print_gpcse_array(char * name,uint name_length TSRMLS_DC)203 static 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  */
php_info_print_style(TSRMLS_D)285 void 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  */
php_info_html_esc(char * string TSRMLS_DC)295 PHPAPI 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 
php_get_windows_name()305 char* 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 /* {{{  */
php_get_windows_cpu(char * buf,int bufsize)520 void 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  */
php_get_uname(char mode)561 PHPAPI 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 
604 		/* Windows "version" 6.2 could be Windows 8/Windows Server 2012, but also Windows 8.1/Windows Server 2012 R2 */
605 		if (dwWindowsMajorVersion == 6 && dwWindowsMinorVersion == 2) {
606 			if (strncmp(winver, "Windows 8.1", 11) == 0 || strncmp(winver, "Windows Server 2012 R2", 22) == 0) {
607 				dwWindowsMinorVersion = 3;
608 			}
609 		}
610 
611 		snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d (%s) %s",
612 				 "Windows NT", ComputerName,
613 				 dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild, winver?winver:"unknown", wincpu);
614 		if(winver) {
615 			efree(winver);
616 		}
617 		php_uname = tmp_uname;
618 	}
619 #else
620 #ifdef HAVE_SYS_UTSNAME_H
621 	struct utsname buf;
622 	if (uname((struct utsname *)&buf) == -1) {
623 		php_uname = PHP_UNAME;
624 	} else {
625 #ifdef NETWARE
626 		if (mode == 's') {
627 			php_uname = buf.sysname;
628 		} else if (mode == 'r') {
629 			snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d",
630 					 buf.netware_major, buf.netware_minor, buf.netware_revision);
631 			php_uname = tmp_uname;
632 		} else if (mode == 'n') {
633 			php_uname = buf.servername;
634 		} else if (mode == 'v') {
635 			snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d",
636 					 buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold);
637 			php_uname = tmp_uname;
638 		} else if (mode == 'm') {
639 			php_uname = buf.machine;
640 		} else { /* assume mode == 'a' */
641 			snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s",
642 					 buf.sysname, buf.servername,
643 					 buf.netware_major, buf.netware_minor, buf.netware_revision,
644 					 buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold,
645 					 buf.machine);
646 			php_uname = tmp_uname;
647 		}
648 #else
649 		if (mode == 's') {
650 			php_uname = buf.sysname;
651 		} else if (mode == 'r') {
652 			php_uname = buf.release;
653 		} else if (mode == 'n') {
654 			php_uname = buf.nodename;
655 		} else if (mode == 'v') {
656 			php_uname = buf.version;
657 		} else if (mode == 'm') {
658 			php_uname = buf.machine;
659 		} else { /* assume mode == 'a' */
660 			snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
661 					 buf.sysname, buf.nodename, buf.release, buf.version,
662 					 buf.machine);
663 			php_uname = tmp_uname;
664 		}
665 #endif /* NETWARE */
666 	}
667 #else
668 	php_uname = PHP_UNAME;
669 #endif
670 #endif
671 	return estrdup(php_uname);
672 }
673 /* }}} */
674 
675 /* {{{ php_print_info_htmlhead
676  */
php_print_info_htmlhead(TSRMLS_D)677 PHPAPI void php_print_info_htmlhead(TSRMLS_D)
678 {
679 	php_info_print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
680 	php_info_print("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
681 	php_info_print("<head>\n");
682 	php_info_print_style(TSRMLS_C);
683 	php_info_print("<title>phpinfo()</title>");
684 	php_info_print("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
685 	php_info_print("</head>\n");
686 	php_info_print("<body><div class=\"center\">\n");
687 }
688 /* }}} */
689 
690 /* {{{ module_name_cmp */
module_name_cmp(const void * a,const void * b TSRMLS_DC)691 static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
692 {
693 	Bucket *f = *((Bucket **) a);
694 	Bucket *s = *((Bucket **) b);
695 
696 	return strcasecmp(((zend_module_entry *)f->pData)->name,
697 				  ((zend_module_entry *)s->pData)->name);
698 }
699 /* }}} */
700 
701 /* {{{ php_print_info
702  */
php_print_info(int flag TSRMLS_DC)703 PHPAPI void php_print_info(int flag TSRMLS_DC)
704 {
705 	char **env, *tmp1, *tmp2;
706 	char *php_uname;
707 	int expose_php = INI_INT("expose_php");
708 
709 	if (!sapi_module.phpinfo_as_text) {
710 		php_print_info_htmlhead(TSRMLS_C);
711 	} else {
712 		php_info_print("phpinfo()\n");
713 	}
714 
715 	if (flag & PHP_INFO_GENERAL) {
716 		char *zend_version = get_zend_version();
717 		char temp_api[10];
718 		char *logo_guid;
719 
720 		php_uname = php_get_uname('a');
721 
722 		if (!sapi_module.phpinfo_as_text) {
723 			php_info_print_box_start(1);
724 		}
725 
726 		if (expose_php && !sapi_module.phpinfo_as_text) {
727 			php_info_print("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
728 			php_info_print_request_uri(TSRMLS_C);
729 			php_info_print("?=");
730 			logo_guid = php_logo_guid();
731 			php_info_print(logo_guid);
732 			efree(logo_guid);
733 			php_info_print("\" alt=\"PHP Logo\" /></a>");
734 		}
735 
736 		if (!sapi_module.phpinfo_as_text) {
737 			php_info_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
738 		} else {
739 			php_info_print_table_row(2, "PHP Version", PHP_VERSION);
740 		}
741 		php_info_print_box_end();
742 		php_info_print_table_start();
743 		php_info_print_table_row(2, "System", php_uname );
744 		php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ );
745 #ifdef COMPILER
746 		php_info_print_table_row(2, "Compiler", COMPILER);
747 #endif
748 #ifdef ARCHITECTURE
749 		php_info_print_table_row(2, "Architecture", ARCHITECTURE);
750 #endif
751 #ifdef CONFIGURE_COMMAND
752 		php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
753 #endif
754 
755 		if (sapi_module.pretty_name) {
756 			php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
757 		}
758 
759 #ifdef VIRTUAL_DIR
760 		php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
761 #else
762 		php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
763 #endif
764 
765 		php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
766 		php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
767 		php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
768 		php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
769 
770 		snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
771 		php_info_print_table_row(2, "PHP API", temp_api);
772 
773 		snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO);
774 		php_info_print_table_row(2, "PHP Extension", temp_api);
775 
776 		snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO);
777 		php_info_print_table_row(2, "Zend Extension", temp_api);
778 
779 		php_info_print_table_row(2, "Zend Extension Build", ZEND_EXTENSION_BUILD_ID);
780 		php_info_print_table_row(2, "PHP Extension Build", ZEND_MODULE_BUILD_ID);
781 
782 #if ZEND_DEBUG
783 		php_info_print_table_row(2, "Debug Build", "yes" );
784 #else
785 		php_info_print_table_row(2, "Debug Build", "no" );
786 #endif
787 
788 #ifdef ZTS
789 		php_info_print_table_row(2, "Thread Safety", "enabled" );
790 #else
791 		php_info_print_table_row(2, "Thread Safety", "disabled" );
792 #endif
793 
794 #ifdef ZEND_SIGNALS
795 		php_info_print_table_row(2, "Zend Signal Handling", "enabled" );
796 #else
797 		php_info_print_table_row(2, "Zend Signal Handling", "disabled" );
798 #endif
799 
800 		php_info_print_table_row(2, "Zend Memory Manager", is_zend_mm(TSRMLS_C) ? "enabled" : "disabled" );
801 
802 		{
803 			const zend_multibyte_functions *functions = zend_multibyte_get_functions(TSRMLS_C);
804 			char *descr;
805 			if (functions) {
806 				spprintf(&descr, 0, "provided by %s", functions->provider_name);
807 			} else {
808 				descr = estrdup("disabled");
809 			}
810             php_info_print_table_row(2, "Zend Multibyte Support", descr);
811 			efree(descr);
812 		}
813 
814 #if HAVE_IPV6
815 		php_info_print_table_row(2, "IPv6 Support", "enabled" );
816 #else
817 		php_info_print_table_row(2, "IPv6 Support", "disabled" );
818 #endif
819 
820 #if HAVE_DTRACE
821 		php_info_print_table_row(2, "DTrace Support", "enabled" );
822 #else
823 		php_info_print_table_row(2, "DTrace Support", "disabled" );
824 #endif
825 
826 		php_info_print_stream_hash("PHP Streams",  php_stream_get_url_stream_wrappers_hash() TSRMLS_CC);
827 		php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash() TSRMLS_CC);
828 		php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash() TSRMLS_CC);
829 
830 		php_info_print_table_end();
831 
832 		/* Zend Engine */
833 		php_info_print_box_start(0);
834 		if (expose_php && !sapi_module.phpinfo_as_text) {
835 			php_info_print("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
836 			php_info_print_request_uri(TSRMLS_C);
837 			php_info_print("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n");
838 		}
839 		php_info_print("This program makes use of the Zend Scripting Language Engine:");
840 		php_info_print(!sapi_module.phpinfo_as_text?"<br />":"\n");
841 		if (sapi_module.phpinfo_as_text) {
842 			php_info_print(zend_version);
843 		} else {
844 			zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
845 		}
846 		php_info_print_box_end();
847 		efree(php_uname);
848 	}
849 
850 	if ((flag & PHP_INFO_CREDITS) && expose_php && !sapi_module.phpinfo_as_text) {
851 		php_info_print_hr();
852 		php_info_print("<h1><a href=\"");
853 		php_info_print_request_uri(TSRMLS_C);
854 		php_info_print("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">");
855 		php_info_print("PHP Credits");
856 		php_info_print("</a></h1>\n");
857 	}
858 
859 	zend_ini_sort_entries(TSRMLS_C);
860 
861 	if (flag & PHP_INFO_CONFIGURATION) {
862 		php_info_print_hr();
863 		if (!sapi_module.phpinfo_as_text) {
864 			php_info_print("<h1>Configuration</h1>\n");
865 		} else {
866 			SECTION("Configuration");
867 		}
868 		if (!(flag & PHP_INFO_MODULES)) {
869 			SECTION("PHP Core");
870 			display_ini_entries(NULL);
871 		}
872 	}
873 
874 	if (flag & PHP_INFO_MODULES) {
875 		HashTable sorted_registry;
876 		zend_module_entry tmp;
877 
878 		zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
879 		zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
880 		zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
881 
882 		zend_hash_apply(&sorted_registry, (apply_func_t) _display_module_info_func TSRMLS_CC);
883 
884 		SECTION("Additional Modules");
885 		php_info_print_table_start();
886 		php_info_print_table_header(1, "Module Name");
887 		zend_hash_apply(&sorted_registry, (apply_func_t) _display_module_info_def TSRMLS_CC);
888 		php_info_print_table_end();
889 
890 		zend_hash_destroy(&sorted_registry);
891 	}
892 
893 	if (flag & PHP_INFO_ENVIRONMENT) {
894 		SECTION("Environment");
895 		php_info_print_table_start();
896 		php_info_print_table_header(2, "Variable", "Value");
897 		for (env=environ; env!=NULL && *env !=NULL; env++) {
898 			tmp1 = estrdup(*env);
899 			if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
900 				efree(tmp1);
901 				continue;
902 			}
903 			*tmp2 = 0;
904 			tmp2++;
905 			php_info_print_table_row(2, tmp1, tmp2);
906 			efree(tmp1);
907 		}
908 		php_info_print_table_end();
909 	}
910 
911 	if (flag & PHP_INFO_VARIABLES) {
912 		zval **data;
913 
914 		SECTION("PHP Variables");
915 
916 		php_info_print_table_start();
917 		php_info_print_table_header(2, "Variable", "Value");
918 		if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE && Z_TYPE_PP(data) == IS_STRING) {
919 			php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_PP(data));
920 		}
921 		if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE && Z_TYPE_PP(data) == IS_STRING) {
922 			php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_PP(data));
923 		}
924 		if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE && Z_TYPE_PP(data) == IS_STRING) {
925 			php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_PP(data));
926 		}
927 		if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE && Z_TYPE_PP(data) == IS_STRING) {
928 			php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_PP(data));
929 		}
930 		php_print_gpcse_array(ZEND_STRL("_REQUEST") TSRMLS_CC);
931 		php_print_gpcse_array(ZEND_STRL("_GET") TSRMLS_CC);
932 		php_print_gpcse_array(ZEND_STRL("_POST") TSRMLS_CC);
933 		php_print_gpcse_array(ZEND_STRL("_FILES") TSRMLS_CC);
934 		php_print_gpcse_array(ZEND_STRL("_COOKIE") TSRMLS_CC);
935 		php_print_gpcse_array(ZEND_STRL("_SERVER") TSRMLS_CC);
936 		php_print_gpcse_array(ZEND_STRL("_ENV") TSRMLS_CC);
937 		php_info_print_table_end();
938 	}
939 
940 	if (flag & PHP_INFO_LICENSE) {
941 		if (!sapi_module.phpinfo_as_text) {
942 			SECTION("PHP License");
943 			php_info_print_box_start(0);
944 			php_info_print("<p>\n");
945 			php_info_print("This program is free software; you can redistribute it and/or modify ");
946 			php_info_print("it under the terms of the PHP License as published by the PHP Group ");
947 			php_info_print("and included in the distribution in the file:  LICENSE\n");
948 			php_info_print("</p>\n");
949 			php_info_print("<p>");
950 			php_info_print("This program is distributed in the hope that it will be useful, ");
951 			php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
952 			php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
953 			php_info_print("</p>\n");
954 			php_info_print("<p>");
955 			php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
956 			php_info_print("PHP licensing, please contact license@php.net.\n");
957 			php_info_print("</p>\n");
958 			php_info_print_box_end();
959 		} else {
960 			php_info_print("\nPHP License\n");
961 			php_info_print("This program is free software; you can redistribute it and/or modify\n");
962 			php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
963 			php_info_print("and included in the distribution in the file:  LICENSE\n");
964 			php_info_print("\n");
965 			php_info_print("This program is distributed in the hope that it will be useful,\n");
966 			php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
967 			php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
968 			php_info_print("\n");
969 			php_info_print("If you did not receive a copy of the PHP license, or have any\n");
970 			php_info_print("questions about PHP licensing, please contact license@php.net.\n");
971 		}
972 	}
973 	if (!sapi_module.phpinfo_as_text) {
974 		php_info_print("</div></body></html>");
975 	}
976 }
977 /* }}} */
978 
php_info_print_table_start(void)979 PHPAPI void php_info_print_table_start(void) /* {{{ */
980 {
981 	if (!sapi_module.phpinfo_as_text) {
982 		php_info_print("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n");
983 	} else {
984 		php_info_print("\n");
985 	}
986 }
987 /* }}} */
988 
php_info_print_table_end(void)989 PHPAPI void php_info_print_table_end(void) /* {{{ */
990 {
991 	if (!sapi_module.phpinfo_as_text) {
992 		php_info_print("</table><br />\n");
993 	}
994 
995 }
996 /* }}} */
997 
php_info_print_box_start(int flag)998 PHPAPI void php_info_print_box_start(int flag) /* {{{ */
999 {
1000 	php_info_print_table_start();
1001 	if (flag) {
1002 		if (!sapi_module.phpinfo_as_text) {
1003 			php_info_print("<tr class=\"h\"><td>\n");
1004 		}
1005 	} else {
1006 		if (!sapi_module.phpinfo_as_text) {
1007 			php_info_print("<tr class=\"v\"><td>\n");
1008 		} else {
1009 			php_info_print("\n");
1010 		}
1011 	}
1012 }
1013 /* }}} */
1014 
php_info_print_box_end(void)1015 PHPAPI void php_info_print_box_end(void) /* {{{ */
1016 {
1017 	if (!sapi_module.phpinfo_as_text) {
1018 		php_info_print("</td></tr>\n");
1019 	}
1020 	php_info_print_table_end();
1021 }
1022 /* }}} */
1023 
php_info_print_hr(void)1024 PHPAPI void php_info_print_hr(void) /* {{{ */
1025 {
1026 	if (!sapi_module.phpinfo_as_text) {
1027 		php_info_print("<hr />\n");
1028 	} else {
1029 		php_info_print("\n\n _______________________________________________________________________\n\n");
1030 	}
1031 }
1032 /* }}} */
1033 
php_info_print_table_colspan_header(int num_cols,char * header)1034 PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
1035 {
1036 	int spaces;
1037 
1038 	if (!sapi_module.phpinfo_as_text) {
1039 		php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
1040 	} else {
1041 		spaces = (74 - strlen(header));
1042 		php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
1043 	}
1044 }
1045 /* }}} */
1046 
1047 /* {{{ php_info_print_table_header
1048  */
php_info_print_table_header(int num_cols,...)1049 PHPAPI void php_info_print_table_header(int num_cols, ...)
1050 {
1051 	int i;
1052 	va_list row_elements;
1053 	char *row_element;
1054 
1055 	va_start(row_elements, num_cols);
1056 	if (!sapi_module.phpinfo_as_text) {
1057 		php_info_print("<tr class=\"h\">");
1058 	}
1059 	for (i=0; i<num_cols; i++) {
1060 		row_element = va_arg(row_elements, char *);
1061 		if (!row_element || !*row_element) {
1062 			row_element = " ";
1063 		}
1064 		if (!sapi_module.phpinfo_as_text) {
1065 			php_info_print("<th>");
1066 			php_info_print(row_element);
1067 			php_info_print("</th>");
1068 		} else {
1069 			php_info_print(row_element);
1070 			if (i < num_cols-1) {
1071 				php_info_print(" => ");
1072 			} else {
1073 				php_info_print("\n");
1074 			}
1075 		}
1076 	}
1077 	if (!sapi_module.phpinfo_as_text) {
1078 		php_info_print("</tr>\n");
1079 	}
1080 
1081 	va_end(row_elements);
1082 }
1083 /* }}} */
1084 
1085 /* {{{ php_info_print_table_row_internal
1086  */
php_info_print_table_row_internal(int num_cols,const char * value_class,va_list row_elements)1087 static void php_info_print_table_row_internal(int num_cols,
1088 		const char *value_class, va_list row_elements)
1089 {
1090 	int i;
1091 	char *row_element;
1092 
1093 	if (!sapi_module.phpinfo_as_text) {
1094 		php_info_print("<tr>");
1095 	}
1096 	for (i=0; i<num_cols; i++) {
1097 		if (!sapi_module.phpinfo_as_text) {
1098 			php_info_printf("<td class=\"%s\">",
1099 			   (i==0 ? "e" : value_class )
1100 			);
1101 		}
1102 		row_element = va_arg(row_elements, char *);
1103 		if (!row_element || !*row_element) {
1104 			if (!sapi_module.phpinfo_as_text) {
1105 				php_info_print( "<i>no value</i>" );
1106 			} else {
1107 				php_info_print( " " );
1108 			}
1109 		} else {
1110 			if (!sapi_module.phpinfo_as_text) {
1111 				php_info_print_html_esc(row_element, strlen(row_element));
1112 			} else {
1113 				php_info_print(row_element);
1114 				if (i < num_cols-1) {
1115 					php_info_print(" => ");
1116 				}
1117 			}
1118 		}
1119 		if (!sapi_module.phpinfo_as_text) {
1120 			php_info_print(" </td>");
1121 		} else if (i == (num_cols - 1)) {
1122 			php_info_print("\n");
1123 		}
1124 	}
1125 	if (!sapi_module.phpinfo_as_text) {
1126 		php_info_print("</tr>\n");
1127 	}
1128 }
1129 /* }}} */
1130 
1131 /* {{{ php_info_print_table_row
1132  */
php_info_print_table_row(int num_cols,...)1133 PHPAPI void php_info_print_table_row(int num_cols, ...)
1134 {
1135 	va_list row_elements;
1136 
1137 	va_start(row_elements, num_cols);
1138 	php_info_print_table_row_internal(num_cols, "v", row_elements);
1139 	va_end(row_elements);
1140 }
1141 /* }}} */
1142 
1143 /* {{{ php_info_print_table_row_ex
1144  */
php_info_print_table_row_ex(int num_cols,const char * value_class,...)1145 PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class,
1146 		...)
1147 {
1148 	va_list row_elements;
1149 
1150 	va_start(row_elements, value_class);
1151 	php_info_print_table_row_internal(num_cols, value_class, row_elements);
1152 	va_end(row_elements);
1153 }
1154 /* }}} */
1155 
1156 /* {{{ register_phpinfo_constants
1157  */
register_phpinfo_constants(INIT_FUNC_ARGS)1158 void register_phpinfo_constants(INIT_FUNC_ARGS)
1159 {
1160 	REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
1161 	REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
1162 	REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
1163 	REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
1164 	REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
1165 	REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
1166 	REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
1167 	REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
1168 	REGISTER_LONG_CONSTANT("CREDITS_GROUP",	PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
1169 	REGISTER_LONG_CONSTANT("CREDITS_GENERAL",	PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
1170 	REGISTER_LONG_CONSTANT("CREDITS_SAPI",	PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
1171 	REGISTER_LONG_CONSTANT("CREDITS_MODULES",	PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
1172 	REGISTER_LONG_CONSTANT("CREDITS_DOCS",	PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
1173 	REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",	PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
1174 	REGISTER_LONG_CONSTANT("CREDITS_QA",	PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
1175 	REGISTER_LONG_CONSTANT("CREDITS_ALL",	PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
1176 }
1177 /* }}} */
1178 
1179 /* {{{ proto void phpinfo([int what])
1180    Output a page of useful information about PHP and the current request */
PHP_FUNCTION(phpinfo)1181 PHP_FUNCTION(phpinfo)
1182 {
1183 	long flag = PHP_INFO_ALL;
1184 
1185 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1186 		return;
1187 	}
1188 
1189 	/* Andale!  Andale!  Yee-Hah! */
1190 	php_output_start_default(TSRMLS_C);
1191 	php_print_info(flag TSRMLS_CC);
1192 	php_output_end(TSRMLS_C);
1193 
1194 	RETURN_TRUE;
1195 }
1196 
1197 /* }}} */
1198 
1199 /* {{{ proto string phpversion([string extension])
1200    Return the current PHP version */
PHP_FUNCTION(phpversion)1201 PHP_FUNCTION(phpversion)
1202 {
1203 	char *ext_name = NULL;
1204 	int ext_name_len = 0;
1205 
1206 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ext_name, &ext_name_len) == FAILURE) {
1207 		return;
1208 	}
1209 
1210 	if (!ext_name) {
1211 		RETURN_STRING(PHP_VERSION, 1);
1212 	} else {
1213 		const char *version;
1214 		version = zend_get_module_version(ext_name);
1215 		if (version == NULL) {
1216 			RETURN_FALSE;
1217 		}
1218 		RETURN_STRING(version, 1);
1219 	}
1220 }
1221 /* }}} */
1222 
1223 /* {{{ proto void phpcredits([int flag])
1224    Prints the list of people who've contributed to the PHP project */
PHP_FUNCTION(phpcredits)1225 PHP_FUNCTION(phpcredits)
1226 {
1227 	long flag = PHP_CREDITS_ALL;
1228 
1229 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1230 		return;
1231 	}
1232 
1233 	php_print_credits(flag TSRMLS_CC);
1234 	RETURN_TRUE;
1235 }
1236 /* }}} */
1237 
1238 /* {{{ php_logo_guid
1239  */
php_logo_guid(void)1240 PHPAPI char *php_logo_guid(void)
1241 {
1242 	char *logo_guid;
1243 
1244 	time_t the_time;
1245 	struct tm *ta, tmbuf;
1246 
1247 	the_time = time(NULL);
1248 	ta = php_localtime_r(&the_time, &tmbuf);
1249 
1250 	if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {
1251 		logo_guid = PHP_EGG_LOGO_GUID;
1252 	} else {
1253 		logo_guid = PHP_LOGO_GUID;
1254 	}
1255 
1256 	return estrdup(logo_guid);
1257 
1258 }
1259 /* }}} */
1260 
1261 /* {{{ proto string php_logo_guid(void)
1262    Return the special ID used to request the PHP logo in phpinfo screens*/
PHP_FUNCTION(php_logo_guid)1263 PHP_FUNCTION(php_logo_guid)
1264 {
1265 	if (zend_parse_parameters_none() == FAILURE) {
1266 		return;
1267 	}
1268 
1269 	RETURN_STRING(php_logo_guid(), 0);
1270 }
1271 /* }}} */
1272 
1273 /* {{{ proto string php_real_logo_guid(void)
1274    Return the special ID used to request the PHP logo in phpinfo screens*/
PHP_FUNCTION(php_real_logo_guid)1275 PHP_FUNCTION(php_real_logo_guid)
1276 {
1277 	if (zend_parse_parameters_none() == FAILURE) {
1278 		return;
1279 	}
1280 
1281 	RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1);
1282 }
1283 /* }}} */
1284 
1285 /* {{{ proto string php_egg_logo_guid(void)
1286    Return the special ID used to request the PHP logo in phpinfo screens*/
PHP_FUNCTION(php_egg_logo_guid)1287 PHP_FUNCTION(php_egg_logo_guid)
1288 {
1289 	if (zend_parse_parameters_none() == FAILURE) {
1290 		return;
1291 	}
1292 
1293 	RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1);
1294 }
1295 /* }}} */
1296 
1297 /* {{{ proto string zend_logo_guid(void)
1298    Return the special ID used to request the Zend logo in phpinfo screens*/
PHP_FUNCTION(zend_logo_guid)1299 PHP_FUNCTION(zend_logo_guid)
1300 {
1301 	if (zend_parse_parameters_none() == FAILURE) {
1302 		return;
1303 	}
1304 
1305 	RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1);
1306 }
1307 /* }}} */
1308 
1309 /* {{{ proto string php_sapi_name(void)
1310    Return the current SAPI module name */
PHP_FUNCTION(php_sapi_name)1311 PHP_FUNCTION(php_sapi_name)
1312 {
1313 	if (zend_parse_parameters_none() == FAILURE) {
1314 		return;
1315 	}
1316 
1317 	if (sapi_module.name) {
1318 		RETURN_STRING(sapi_module.name, 1);
1319 	} else {
1320 		RETURN_FALSE;
1321 	}
1322 }
1323 
1324 /* }}} */
1325 
1326 /* {{{ proto string php_uname(void)
1327    Return information about the system PHP was built on */
PHP_FUNCTION(php_uname)1328 PHP_FUNCTION(php_uname)
1329 {
1330 	char *mode = "a";
1331 	int modelen = sizeof("a")-1;
1332 
1333 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) {
1334 		return;
1335 	}
1336 	RETURN_STRING(php_get_uname(*mode), 0);
1337 }
1338 
1339 /* }}} */
1340 
1341 /* {{{ proto string php_ini_scanned_files(void)
1342    Return comma-separated string of .ini files parsed from the additional ini dir */
PHP_FUNCTION(php_ini_scanned_files)1343 PHP_FUNCTION(php_ini_scanned_files)
1344 {
1345 	if (zend_parse_parameters_none() == FAILURE) {
1346 		return;
1347 	}
1348 
1349 	if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
1350 		RETURN_STRING(php_ini_scanned_files, 1);
1351 	} else {
1352 		RETURN_FALSE;
1353 	}
1354 }
1355 /* }}} */
1356 
1357 /* {{{ proto string php_ini_loaded_file(void)
1358    Return the actual loaded ini filename */
PHP_FUNCTION(php_ini_loaded_file)1359 PHP_FUNCTION(php_ini_loaded_file)
1360 {
1361 	if (zend_parse_parameters_none() == FAILURE) {
1362 		return;
1363 	}
1364 
1365 	if (php_ini_opened_path) {
1366 		RETURN_STRING(php_ini_opened_path, 1);
1367 	} else {
1368 		RETURN_FALSE;
1369 	}
1370 }
1371 /* }}} */
1372 
1373 /*
1374  * Local variables:
1375  * tab-width: 4
1376  * c-basic-offset: 4
1377  * End:
1378  * vim600: sw=4 ts=4 fdm=marker
1379  * vim<600: sw=4 ts=4
1380  */
1381