PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/ext/standard/info.c

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