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