Coverage Report

Created: 2026-06-02 06:36

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