From 667661769318fa7af88464b080e44a55f22cbfa1 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 28 Aug 2002 22:31:51 +0000 Subject: - add phpinfo() support for CLI. @phpinfo() support for CLI (jan) --- ext/standard/info.c | 295 +++++++++++++++++++++++++++++++++++++--------------- main/php_ini.c | 34 +++--- 2 files changed, 232 insertions(+), 97 deletions(-) diff --git a/ext/standard/info.c b/ext/standard/info.c index b9134861e6..a190fbe821 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -48,7 +48,13 @@ ZEND_EXTERN_MODULE_GLOBALS(mbstring) ZEND_EXTERN_MODULE_GLOBALS(iconv) #endif -#define SECTION(name) PUTS("

" name "

\n") +#define SECTION(name) if (PG(html_errors)) { \ + PUTS("

" name "

\n"); \ + } else { \ + php_info_print_table_start(); \ + php_info_print_table_header(1, name); \ + php_info_print_table_end(); \ + } \ PHPAPI extern char *php_ini_opened_path; @@ -59,13 +65,23 @@ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC) int show_info_func = *((int *) arg); if (show_info_func && module->info_func) { - php_printf("

%s

\n", module->name, module->name); + if (PG(html_errors)) { + php_printf("

%s

\n", module->name, module->name); + } else { + php_info_print_table_start(); + php_info_print_table_header(1, module->name); + php_info_print_table_end(); + } module->info_func(module TSRMLS_CC); } else if (!show_info_func && !module->info_func) { - php_printf(""); - php_printf(""); - php_printf("%s", module->name); - php_printf("\n"); + if (PG(html_errors)) { + php_printf(""); + php_printf(""); + php_printf("%s", module->name); + php_printf("\n"); + } else { + php_printf(module->name); + } } return 0; } @@ -76,7 +92,7 @@ static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC) static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) { zval **data, **tmp, tmp2; - char *string_key; + char *string_key, *entry; uint string_len; ulong num_key; @@ -84,33 +100,63 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) && (Z_TYPE_PP(data)==IS_ARRAY)) { zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) { - PUTS(""); - PUTS(""); + if (PG(html_errors)) { + PUTS(""); + PUTS(""); + + } + PUTS(name); PUTS("[\""); + switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) { case HASH_KEY_IS_STRING: - zend_html_puts(string_key, string_len-1); + if (PG(html_errors)) { + zend_html_puts(string_key, string_len-1); + } else { + PUTS(string_key); + } break; case HASH_KEY_IS_LONG: php_printf("%ld", num_key); break; } - PUTS("\"]"); + PUTS("\"]"); + if (PG(html_errors)) { + PUTS(""); + } else { + PUTS(" => "); + } if (Z_TYPE_PP(tmp) == IS_ARRAY) { - PUTS("
");
+				if (PG(html_errors)) {
+					PUTS("
");
+				}
 				zend_print_zval_r(*tmp, 0);
-				PUTS("
"); + if (PG(html_errors)) { + PUTS("
"); + } } else if (Z_TYPE_PP(tmp) != IS_STRING) { tmp2 = **tmp; zval_copy_ctor(&tmp2); convert_to_string(&tmp2); - zend_html_puts(Z_STRVAL(tmp2), Z_STRLEN(tmp2)); + if (PG(html_errors)) { + zend_html_puts(Z_STRVAL(tmp2), Z_STRLEN(tmp2)); + } else { + PUTS(Z_STRVAL(tmp2)); + } zval_dtor(&tmp2); } else { - zend_html_puts(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + if (PG(html_errors)) { + zend_html_puts(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + } else { + PUTS(Z_STRVAL_PP(tmp)); + } } - PUTS(" \n"); + if (PG(html_errors)) { + PUTS(" \n"); + } else { + PUTS("\n"); + } zend_hash_move_forward(Z_ARRVAL_PP(data)); } } @@ -223,22 +269,23 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) the_time = time(NULL); ta = php_localtime_r(&the_time, &tmbuf); - - PUTS("\n\n"); - PUTS(""); - php_info_print_style(); - if (SG(default_charset)) { - charset = SG(default_charset); - } + if (PG(html_errors)) { + PUTS("\n\n"); + PUTS(""); + php_info_print_style(); + if (SG(default_charset)) { + charset = SG(default_charset); + } #if HAVE_MBSTRING - if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) { - if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) { - charset = "US-ASCII"; - } else { - charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding)); + if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) { + if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) { + charset = "US-ASCII"; + } else { + charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding)); + } } - } -#endif +#endif + } #if HAVE_ICONV if (php_ob_handler_used("ob_iconv_handler" TSRMLS_CC)) { charset = ICONVG(output_encoding); @@ -250,14 +297,18 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) php_printf("phpinfo()", charset); PUTS(""); + if (flag & PHP_INFO_GENERAL) { char *zend_version = get_zend_version(); char *api_numbers; php_uname = php_get_uname('a'); + + if (PG(html_errors)) { + php_info_print_box_start(1); + } - php_info_print_box_start(1); - if (expose_php) { + if (expose_php && PG(html_errors)) { PUTS("\"PHP"); } } - php_printf("

PHP Version %s

\n", PHP_VERSION); + + if (PG(html_errors)) { + php_printf("

PHP Version %s

\n", PHP_VERSION); + } else { + php_info_print_table_row(2, "PHP Version", PHP_VERSION); + } php_info_print_box_end(); php_info_print_table_start(); php_info_print_table_row(2, "System", php_uname ); @@ -319,7 +375,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) break; } memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len); - stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = '\n'; + stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ' '; stream_protocols_buf_len += stream_protocol_len + 1; } if (stream_protocols_buf) { @@ -340,20 +396,21 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) /* Zend Engine */ php_info_print_box_start(0); - if (expose_php) { + if (expose_php && PG(html_errors)) { PUTS("\"Zend\n"); } - php_printf("This program makes use of the Zend Scripting Language Engine:
"); - zend_html_puts(zend_version, strlen(zend_version)); + PUTS("This program makes use of the Zend Scripting Language Engine:"); + PUTS(PG(html_errors)?"
":"\n"); + PUTS(zend_version); php_info_print_box_end(); efree(php_uname); } - if ((flag & PHP_INFO_CREDITS) && expose_php) { + if ((flag & PHP_INFO_CREDITS) && expose_php && PG(html_errors)) { php_info_print_hr(); PUTS("

Configuration

\n"); + if (PG(html_errors)) { + PUTS("

Configuration

\n"); + } else { + SECTION("Configuration"); + } SECTION("PHP Core\n"); display_ini_entries(NULL); } @@ -417,7 +478,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_PP(data)); } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { + if (zend_hash_find(&EG(symbol_table), "PHP_AUblTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_PP(data)); } if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) { @@ -434,38 +495,59 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) } if (flag & PHP_INFO_LICENSE) { - SECTION("PHP License"); - php_info_print_box_start(0); - PUTS("

\n"); - PUTS("This program is free software; you can redistribute it and/or modify "); - PUTS("it under the terms of the PHP License as published by the PHP Group "); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("

\n"); - PUTS("

"); - PUTS("This program is distributed in the hope that it will be useful, "); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("

\n"); - PUTS("

"); - PUTS("If you did not receive a copy of the PHP license, or have any questions about "); - PUTS("PHP licensing, please contact license@php.net.\n"); - PUTS("

\n"); - php_info_print_box_end(); + if (PG(html_errors)) { + SECTION("PHP License"); + php_info_print_box_start(0); + PUTS("

\n"); + PUTS("This program is free software; you can redistribute it and/or modify "); + PUTS("it under the terms of the PHP License as published by the PHP Group "); + PUTS("and included in the distribution in the file: LICENSE\n"); + PUTS("

\n"); + PUTS("

"); + PUTS("This program is distributed in the hope that it will be useful, "); + PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); + PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); + PUTS("

\n"); + PUTS("

"); + PUTS("If you did not receive a copy of the PHP license, or have any questions about "); + PUTS("PHP licensing, please contact license@php.net.\n"); + PUTS("

\n"); + php_info_print_box_end(); + } else { + PUTS("\nPHP License\n"); + PUTS("This program is free software; you can redistribute it and/or modify\n"); + PUTS("it under the terms of the PHP License as published by the PHP Group\n"); + PUTS("and included in the distribution in the file: LICENSE\n"); + PUTS("\n"); + PUTS("This program is distributed in the hope that it will be useful,\n"); + PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); + PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); + PUTS("\n"); + PUTS("If you did not receive a copy of the PHP license, or have any\n"); + PUTS("questions about PHP licensing, please contact license@php.net.\n"); + } } - - PUTS(""); + if (PG(html_errors)) { + PUTS(""); + } } /* }}} */ PHPAPI void php_info_print_table_start() { - php_printf("\n"); + if (PG(html_errors)) { + php_printf("
\n"); + } else { + php_printf("\n"); + } } PHPAPI void php_info_print_table_end() -{ - php_printf("

\n"); +{ + if (PG(html_errors)) { + php_printf("
\n"); + } } @@ -473,26 +555,45 @@ PHPAPI void php_info_print_box_start(int flag) { php_info_print_table_start(); if (flag) { - php_printf("\n"); + if (PG(html_errors)) { + php_printf("\n"); + } } else { - php_printf("\n"); + if (PG(html_errors)) { + php_printf("\n"); + } else { + php_printf("\n"); + } } } PHPAPI void php_info_print_box_end() { - php_printf("\n"); + if (PG(html_errors)) { + php_printf("\n"); + } php_info_print_table_end(); } PHPAPI void php_info_print_hr() { - php_printf("
\n"); + if (PG(html_errors)) { + php_printf("
\n"); + } else { + php_printf("\n\n _______________________________________________________________________\n\n"); + } } PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) { - php_printf("%s\n", num_cols, header ); + int spaces; + + if (PG(html_errors)) { + php_printf("%s\n", num_cols, header ); + } else { + spaces = (74 - strlen(header)); + php_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " "); + } } /* {{{ php_info_print_table_header @@ -504,16 +605,28 @@ PHPAPI void php_info_print_table_header(int num_cols, ...) char *row_element; va_start(row_elements, num_cols); - - php_printf(""); + if (PG(html_errors)) { + php_printf(""); + } for (i=0; i%s", row_element); + if (PG(html_errors)) { + php_printf("%s", row_element); + } else { + PUTS(row_element); + if (i < num_cols-1) { + PUTS(" => "); + } else { + PUTS("\n"); + } + } } - php_printf("\n"); + if (PG(html_errors)) { + php_printf("\n"); + } va_end(row_elements); } @@ -529,24 +642,38 @@ PHPAPI void php_info_print_table_row(int num_cols, ...) TSRMLS_FETCH(); va_start(row_elements, num_cols); - - php_printf(""); + if (PG(html_errors)) { + php_printf(""); + } for (i=0; i%s", - (i==0?"bgcolor=\"" PHP_ENTRY_NAME_COLOR "\" ":"align=\"left\""), - (i==0?"":"")); - + if (PG(html_errors)) { + php_printf("%s", + (i==0?"bgcolor=\"" PHP_ENTRY_NAME_COLOR "\" ":"align=\"left\""), + (i==0?"":"")); + } row_element = va_arg(row_elements, char *); if (!row_element || !*row_element) { - php_printf(" "); + PUTS(PG(html_errors)?" ":" "); } else { - zend_html_puts(row_element, strlen(row_element)); + if (PG(html_errors)) { + zend_html_puts(row_element, strlen(row_element)); + } else { + PUTS(row_element); + if (i < num_cols-1) { + PUTS(" => "); + } else { + PUTS("\n"); + } + } } - - php_printf("%s", (i==0?"":"")); + if (PG(html_errors)) { + php_printf("%s", (i==0?"":"")); + } } - php_printf("\n"); - + if (PG(html_errors)) { + php_printf("\n"); + } + va_end(row_elements); } /* }}} */ diff --git a/main/php_ini.c b/main/php_ini.c index 715f30e596..5f468608ae 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -62,16 +62,16 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) display_string_length = ini_entry->orig_value_length; esc_html=1; } else { - display_string = "no value"; - display_string_length = sizeof("no value")-1; + display_string = (PG(html_errors))?"no value":"no value"; + display_string_length = sizeof((PG(html_errors))?"no value":"no value")-1; } } else if (ini_entry->value && ini_entry->value[0]) { display_string = ini_entry->value; display_string_length = ini_entry->value_length; esc_html=1; } else { - display_string = "no value"; - display_string_length = sizeof("no value")-1; + display_string = (PG(html_errors))?"no value":"no value"; + display_string_length = sizeof((PG(html_errors))?"no value":"no value")-1; } if(esc_html) { php_html_puts(display_string, display_string_length TSRMLS_CC); @@ -89,15 +89,23 @@ static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS if (ini_entry->module_number != module_number) { return 0; } - - PUTS(""); - PUTS(""); - PHPWRITE(ini_entry->name, ini_entry->name_length-1); - PUTS("
"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS(""); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("\n"); + if (PG(html_errors)) { + PUTS(""); + PUTS(""); + PHPWRITE(ini_entry->name, ini_entry->name_length-1); + PUTS("
"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + PUTS(""); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("\n"); + } else { + PHPWRITE(ini_entry->name, ini_entry->name_length-1); + PUTS(" => "); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + PUTS(" => "); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("\n"); + } return 0; } /* }}} */ -- cgit v1.2.1