Exceptions
6 days ago
apache.php
6 days ago
apcu.php
6 days ago
array.php
6 days ago
bzip2.php
6 days ago
calendar.php
6 days ago
classobj.php
6 days ago
com.php
6 days ago
cubrid.php
6 days ago
curl.php
6 days ago
datetime.php
6 days ago
dir.php
6 days ago
eio.php
6 days ago
errorfunc.php
6 days ago
exec.php
6 days ago
fileinfo.php
6 days ago
filesystem.php
6 days ago
filter.php
6 days ago
fpm.php
6 days ago
ftp.php
6 days ago
funchand.php
6 days ago
functionsList.php
6 days ago
gmp.php
6 days ago
gnupg.php
6 days ago
hash.php
6 days ago
ibase.php
6 days ago
ibmDb2.php
6 days ago
iconv.php
6 days ago
image.php
6 days ago
imap.php
6 days ago
info.php
6 days ago
ingres-ii.php
6 days ago
inotify.php
6 days ago
json.php
6 days ago
ldap.php
6 days ago
libxml.php
6 days ago
lzf.php
6 days ago
mailparse.php
6 days ago
mbstring.php
6 days ago
misc.php
6 days ago
msql.php
6 days ago
mysql.php
6 days ago
mysqli.php
6 days ago
mysqlndMs.php
6 days ago
mysqlndQc.php
6 days ago
network.php
6 days ago
oci8.php
6 days ago
opcache.php
6 days ago
openssl.php
6 days ago
outcontrol.php
6 days ago
password.php
6 days ago
pcntl.php
6 days ago
pcre.php
6 days ago
pdf.php
6 days ago
pgsql.php
6 days ago
posix.php
6 days ago
ps.php
6 days ago
pspell.php
6 days ago
readline.php
6 days ago
rpminfo.php
6 days ago
rrd.php
6 days ago
sem.php
6 days ago
session.php
6 days ago
shmop.php
6 days ago
simplexml.php
6 days ago
sockets.php
6 days ago
sodium.php
6 days ago
solr.php
6 days ago
spl.php
6 days ago
sqlsrv.php
6 days ago
ssdeep.php
6 days ago
ssh2.php
6 days ago
stream.php
6 days ago
strings.php
6 days ago
swoole.php
6 days ago
uodbc.php
6 days ago
uopz.php
6 days ago
url.php
6 days ago
var.php
6 days ago
xdiff.php
6 days ago
xml.php
6 days ago
xmlrpc.php
6 days ago
yaml.php
6 days ago
yaz.php
6 days ago
zip.php
6 days ago
zlib.php
6 days ago
network.php
621 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\NetworkException; |
| 6 | /** |
| 7 | * closelog closes the descriptor being used to write to |
| 8 | * the system logger. The use of closelog is optional. |
| 9 | * |
| 10 | * @throws NetworkException |
| 11 | * |
| 12 | */ |
| 13 | function closelog(): void |
| 14 | { |
| 15 | error_clear_last(); |
| 16 | $result = \closelog(); |
| 17 | if ($result === \false) { |
| 18 | throw NetworkException::createFromPhpError(); |
| 19 | } |
| 20 | } |
| 21 | /** |
| 22 | * Fetch DNS Resource Records associated with the given |
| 23 | * hostname. |
| 24 | * |
| 25 | * @param string $hostname hostname should be a valid DNS hostname such |
| 26 | * as "www.example.com". Reverse lookups can be generated |
| 27 | * using in-addr.arpa notation, but |
| 28 | * gethostbyaddr is more suitable for |
| 29 | * the majority of reverse lookups. |
| 30 | * |
| 31 | * Per DNS standards, email addresses are given in user.host format (for |
| 32 | * example: hostmaster.example.com as opposed to hostmaster@example.com), |
| 33 | * be sure to check this value and modify if necessary before using it |
| 34 | * with a functions such as mail. |
| 35 | * @param int $type By default, dns_get_record will search for any |
| 36 | * resource records associated with hostname. |
| 37 | * To limit the query, specify the optional type |
| 38 | * parameter. May be any one of the following: |
| 39 | * DNS_A, DNS_CNAME, |
| 40 | * DNS_HINFO, DNS_CAA, |
| 41 | * DNS_MX, DNS_NS, |
| 42 | * DNS_PTR, DNS_SOA, |
| 43 | * DNS_TXT, DNS_AAAA, |
| 44 | * DNS_SRV, DNS_NAPTR, |
| 45 | * DNS_A6, DNS_ALL |
| 46 | * or DNS_ANY. |
| 47 | * |
| 48 | * Because of eccentricities in the performance of libresolv |
| 49 | * between platforms, DNS_ANY will not |
| 50 | * always return every record, the slower DNS_ALL |
| 51 | * will collect all records more reliably. |
| 52 | * |
| 53 | * DNS_CAA is not supported on Windows. |
| 54 | * @param array|null $authns Passed by reference and, if given, will be populated with Resource |
| 55 | * Records for the Authoritative Name Servers. |
| 56 | * @param array|null $addtl Passed by reference and, if given, will be populated with any |
| 57 | * Additional Records. |
| 58 | * @param bool $raw The type will be interpreted as a raw DNS type ID |
| 59 | * (the DNS_* constants cannot be used). |
| 60 | * The return value will contain a data key, which needs |
| 61 | * to be manually parsed. |
| 62 | * @return array This function returns an array of associative arrays. Each associative array contains |
| 63 | * at minimum the following keys: |
| 64 | * |
| 65 | * Basic DNS attributes |
| 66 | * |
| 67 | * |
| 68 | * |
| 69 | * Attribute |
| 70 | * Meaning |
| 71 | * |
| 72 | * |
| 73 | * |
| 74 | * |
| 75 | * host |
| 76 | * |
| 77 | * The record in the DNS namespace to which the rest of the associated data refers. |
| 78 | * |
| 79 | * |
| 80 | * |
| 81 | * class |
| 82 | * |
| 83 | * dns_get_record only returns Internet class records and as |
| 84 | * such this parameter will always return IN. |
| 85 | * |
| 86 | * |
| 87 | * |
| 88 | * type |
| 89 | * |
| 90 | * String containing the record type. Additional attributes will also be contained |
| 91 | * in the resulting array dependant on the value of type. See table below. |
| 92 | * |
| 93 | * |
| 94 | * |
| 95 | * ttl |
| 96 | * |
| 97 | * "Time To Live" remaining for this record. This will not equal |
| 98 | * the record's original ttl, but will rather equal the original ttl minus whatever |
| 99 | * length of time has passed since the authoritative name server was queried. |
| 100 | * |
| 101 | * |
| 102 | * |
| 103 | * |
| 104 | * |
| 105 | * |
| 106 | * |
| 107 | * Other keys in associative arrays dependant on 'type' |
| 108 | * |
| 109 | * |
| 110 | * |
| 111 | * Type |
| 112 | * Extra Columns |
| 113 | * |
| 114 | * |
| 115 | * |
| 116 | * |
| 117 | * A |
| 118 | * |
| 119 | * ip: An IPv4 addresses in dotted decimal notation. |
| 120 | * |
| 121 | * |
| 122 | * |
| 123 | * MX |
| 124 | * |
| 125 | * pri: Priority of mail exchanger. |
| 126 | * Lower numbers indicate greater priority. |
| 127 | * target: FQDN of the mail exchanger. |
| 128 | * See also dns_get_mx. |
| 129 | * |
| 130 | * |
| 131 | * |
| 132 | * CNAME |
| 133 | * |
| 134 | * target: FQDN of location in DNS namespace to which |
| 135 | * the record is aliased. |
| 136 | * |
| 137 | * |
| 138 | * |
| 139 | * NS |
| 140 | * |
| 141 | * target: FQDN of the name server which is authoritative |
| 142 | * for this hostname. |
| 143 | * |
| 144 | * |
| 145 | * |
| 146 | * PTR |
| 147 | * |
| 148 | * target: Location within the DNS namespace to which |
| 149 | * this record points. |
| 150 | * |
| 151 | * |
| 152 | * |
| 153 | * TXT |
| 154 | * |
| 155 | * txt: Arbitrary string data associated with this record. |
| 156 | * |
| 157 | * |
| 158 | * |
| 159 | * HINFO |
| 160 | * |
| 161 | * cpu: IANA number designating the CPU of the machine |
| 162 | * referenced by this record. |
| 163 | * os: IANA number designating the Operating System on |
| 164 | * the machine referenced by this record. |
| 165 | * See IANA's Operating System |
| 166 | * Names for the meaning of these values. |
| 167 | * |
| 168 | * |
| 169 | * |
| 170 | * CAA |
| 171 | * |
| 172 | * flags: A one-byte bitfield; currently only bit 0 is defined, |
| 173 | * meaning 'critical'; other bits are reserved and should be ignored. |
| 174 | * tag: The CAA tag name (alphanumeric ASCII string). |
| 175 | * value: The CAA tag value (binary string, may use subformats). |
| 176 | * For additional information see: RFC 6844 |
| 177 | * |
| 178 | * |
| 179 | * |
| 180 | * SOA |
| 181 | * |
| 182 | * mname: FQDN of the machine from which the resource |
| 183 | * records originated. |
| 184 | * rname: Email address of the administrative contact |
| 185 | * for this domain. |
| 186 | * serial: Serial # of this revision of the requested |
| 187 | * domain. |
| 188 | * refresh: Refresh interval (seconds) secondary name |
| 189 | * servers should use when updating remote copies of this domain. |
| 190 | * retry: Length of time (seconds) to wait after a |
| 191 | * failed refresh before making a second attempt. |
| 192 | * expire: Maximum length of time (seconds) a secondary |
| 193 | * DNS server should retain remote copies of the zone data without a |
| 194 | * successful refresh before discarding. |
| 195 | * minimum-ttl: Minimum length of time (seconds) a |
| 196 | * client can continue to use a DNS resolution before it should request |
| 197 | * a new resolution from the server. Can be overridden by individual |
| 198 | * resource records. |
| 199 | * |
| 200 | * |
| 201 | * |
| 202 | * AAAA |
| 203 | * |
| 204 | * ipv6: IPv6 address |
| 205 | * |
| 206 | * |
| 207 | * |
| 208 | * A6(PHP >= 5.1.0) |
| 209 | * |
| 210 | * masklen: Length (in bits) to inherit from the target |
| 211 | * specified by chain. |
| 212 | * ipv6: Address for this specific record to merge with |
| 213 | * chain. |
| 214 | * chain: Parent record to merge with |
| 215 | * ipv6 data. |
| 216 | * |
| 217 | * |
| 218 | * |
| 219 | * SRV |
| 220 | * |
| 221 | * pri: (Priority) lowest priorities should be used first. |
| 222 | * weight: Ranking to weight which of commonly prioritized |
| 223 | * targets should be chosen at random. |
| 224 | * target and port: hostname and port |
| 225 | * where the requested service can be found. |
| 226 | * For additional information see: RFC 2782 |
| 227 | * |
| 228 | * |
| 229 | * |
| 230 | * NAPTR |
| 231 | * |
| 232 | * order and pref: Equivalent to |
| 233 | * pri and weight above. |
| 234 | * flags, services, regex, |
| 235 | * and replacement: Parameters as defined by |
| 236 | * RFC 2915. |
| 237 | * |
| 238 | * |
| 239 | * |
| 240 | * |
| 241 | * |
| 242 | * @throws NetworkException |
| 243 | * |
| 244 | */ |
| 245 | function dns_get_record(string $hostname, int $type = \DNS_ANY, ?array &$authns = null, ?array &$addtl = null, bool $raw = \false): array |
| 246 | { |
| 247 | error_clear_last(); |
| 248 | $result = \dns_get_record($hostname, $type, $authns, $addtl, $raw); |
| 249 | if ($result === \false) { |
| 250 | throw NetworkException::createFromPhpError(); |
| 251 | } |
| 252 | return $result; |
| 253 | } |
| 254 | /** |
| 255 | * Initiates a socket connection to the resource specified by |
| 256 | * hostname. |
| 257 | * |
| 258 | * PHP supports targets in the Internet and Unix domains as described in |
| 259 | * . A list of supported transports can also be |
| 260 | * retrieved using stream_get_transports. |
| 261 | * |
| 262 | * The socket will by default be opened in blocking mode. You can |
| 263 | * switch it to non-blocking mode by using |
| 264 | * stream_set_blocking. |
| 265 | * |
| 266 | * The function stream_socket_client is similar but |
| 267 | * provides a richer set of options, including non-blocking connection and the |
| 268 | * ability to provide a stream context. |
| 269 | * |
| 270 | * @param string $hostname If OpenSSL support is |
| 271 | * installed, you may prefix the hostname |
| 272 | * with either ssl:// or tls:// to |
| 273 | * use an SSL or TLS client connection over TCP/IP to connect to the |
| 274 | * remote host. |
| 275 | * @param int $port The port number. This can be omitted and skipped with |
| 276 | * -1 for transports that do not use ports, such as |
| 277 | * unix://. |
| 278 | * @param int|null $errno If provided, holds the system level error number that occurred in the |
| 279 | * system-level connect() call. |
| 280 | * |
| 281 | * If the value returned in errno is |
| 282 | * 0 and the function returned FALSE, it is an |
| 283 | * indication that the error occurred before the |
| 284 | * connect() call. This is most likely due to a |
| 285 | * problem initializing the socket. |
| 286 | * @param string|null $errstr The error message as a string. |
| 287 | * @param float $timeout The connection timeout, in seconds. |
| 288 | * |
| 289 | * If you need to set a timeout for reading/writing data over the |
| 290 | * socket, use stream_set_timeout, as the |
| 291 | * timeout parameter to |
| 292 | * fsockopen only applies while connecting the |
| 293 | * socket. |
| 294 | * @return resource fsockopen returns a file pointer which may be used |
| 295 | * together with the other file functions (such as |
| 296 | * fgets, fgetss, |
| 297 | * fwrite, fclose, and |
| 298 | * feof). If the call fails, it will return FALSE |
| 299 | * @throws NetworkException |
| 300 | * |
| 301 | */ |
| 302 | function fsockopen(string $hostname, int $port = -1, ?int &$errno = null, ?string &$errstr = null, float $timeout = null) |
| 303 | { |
| 304 | error_clear_last(); |
| 305 | if ($timeout !== null) { |
| 306 | $result = \fsockopen($hostname, $port, $errno, $errstr, $timeout); |
| 307 | } else { |
| 308 | $result = \fsockopen($hostname, $port, $errno, $errstr); |
| 309 | } |
| 310 | if ($result === \false) { |
| 311 | throw NetworkException::createFromPhpError(); |
| 312 | } |
| 313 | return $result; |
| 314 | } |
| 315 | /** |
| 316 | * gethostname gets the standard host name for |
| 317 | * the local machine. |
| 318 | * |
| 319 | * @return string Returns a string with the hostname on success, otherwise FALSE is |
| 320 | * returned. |
| 321 | * @throws NetworkException |
| 322 | * |
| 323 | */ |
| 324 | function gethostname(): string |
| 325 | { |
| 326 | error_clear_last(); |
| 327 | $result = \gethostname(); |
| 328 | if ($result === \false) { |
| 329 | throw NetworkException::createFromPhpError(); |
| 330 | } |
| 331 | return $result; |
| 332 | } |
| 333 | /** |
| 334 | * getprotobyname returns the protocol number |
| 335 | * associated with the protocol name as per |
| 336 | * /etc/protocols. |
| 337 | * |
| 338 | * @param string $name The protocol name. |
| 339 | * @return int Returns the protocol number. |
| 340 | * @throws NetworkException |
| 341 | * |
| 342 | */ |
| 343 | function getprotobyname(string $name): int |
| 344 | { |
| 345 | error_clear_last(); |
| 346 | $result = \getprotobyname($name); |
| 347 | if ($result === \false) { |
| 348 | throw NetworkException::createFromPhpError(); |
| 349 | } |
| 350 | return $result; |
| 351 | } |
| 352 | /** |
| 353 | * getprotobynumber returns the protocol name |
| 354 | * associated with protocol number as per |
| 355 | * /etc/protocols. |
| 356 | * |
| 357 | * @param int $number The protocol number. |
| 358 | * @return string Returns the protocol name as a string. |
| 359 | * @throws NetworkException |
| 360 | * |
| 361 | */ |
| 362 | function getprotobynumber(int $number): string |
| 363 | { |
| 364 | error_clear_last(); |
| 365 | $result = \getprotobynumber($number); |
| 366 | if ($result === \false) { |
| 367 | throw NetworkException::createFromPhpError(); |
| 368 | } |
| 369 | return $result; |
| 370 | } |
| 371 | /** |
| 372 | * Registers a function that will be called when PHP starts sending output. |
| 373 | * |
| 374 | * The callback is executed just after PHP prepares all |
| 375 | * headers to be sent, and before any other output is sent, creating a window |
| 376 | * to manipulate the outgoing headers before being sent. |
| 377 | * |
| 378 | * @param callable $callback Function called just before the headers are sent. It gets no parameters |
| 379 | * and the return value is ignored. |
| 380 | * @throws NetworkException |
| 381 | * |
| 382 | */ |
| 383 | function header_register_callback(callable $callback): void |
| 384 | { |
| 385 | error_clear_last(); |
| 386 | $result = \header_register_callback($callback); |
| 387 | if ($result === \false) { |
| 388 | throw NetworkException::createFromPhpError(); |
| 389 | } |
| 390 | } |
| 391 | /** |
| 392 | * |
| 393 | * |
| 394 | * @param string $in_addr A 32bit IPv4, or 128bit IPv6 address. |
| 395 | * @return string Returns a string representation of the address. |
| 396 | * @throws NetworkException |
| 397 | * |
| 398 | */ |
| 399 | function inet_ntop(string $in_addr): string |
| 400 | { |
| 401 | error_clear_last(); |
| 402 | $result = \inet_ntop($in_addr); |
| 403 | if ($result === \false) { |
| 404 | throw NetworkException::createFromPhpError(); |
| 405 | } |
| 406 | return $result; |
| 407 | } |
| 408 | /** |
| 409 | * openlog opens a connection to the system |
| 410 | * logger for a program. |
| 411 | * |
| 412 | * The use of openlog is optional. It |
| 413 | * will automatically be called by syslog if |
| 414 | * necessary, in which case ident will default |
| 415 | * to FALSE. |
| 416 | * |
| 417 | * @param string $ident The string ident is added to each message. |
| 418 | * @param int $option The option argument is used to indicate |
| 419 | * what logging options will be used when generating a log message. |
| 420 | * |
| 421 | * openlog Options |
| 422 | * |
| 423 | * |
| 424 | * |
| 425 | * Constant |
| 426 | * Description |
| 427 | * |
| 428 | * |
| 429 | * |
| 430 | * |
| 431 | * LOG_CONS |
| 432 | * |
| 433 | * if there is an error while sending data to the system logger, |
| 434 | * write directly to the system console |
| 435 | * |
| 436 | * |
| 437 | * |
| 438 | * LOG_NDELAY |
| 439 | * |
| 440 | * open the connection to the logger immediately |
| 441 | * |
| 442 | * |
| 443 | * |
| 444 | * LOG_ODELAY |
| 445 | * |
| 446 | * (default) delay opening the connection until the first |
| 447 | * message is logged |
| 448 | * |
| 449 | * |
| 450 | * |
| 451 | * LOG_PERROR |
| 452 | * print log message also to standard error |
| 453 | * |
| 454 | * |
| 455 | * LOG_PID |
| 456 | * include PID with each message |
| 457 | * |
| 458 | * |
| 459 | * |
| 460 | * |
| 461 | * You can use one or more of these options. When using multiple options |
| 462 | * you need to OR them, i.e. to open the connection |
| 463 | * immediately, write to the console and include the PID in each message, |
| 464 | * you will use: LOG_CONS | LOG_NDELAY | LOG_PID |
| 465 | * @param int $facility The facility argument is used to specify what |
| 466 | * type of program is logging the message. This allows you to specify |
| 467 | * (in your machine's syslog configuration) how messages coming from |
| 468 | * different facilities will be handled. |
| 469 | * |
| 470 | * openlog Facilities |
| 471 | * |
| 472 | * |
| 473 | * |
| 474 | * Constant |
| 475 | * Description |
| 476 | * |
| 477 | * |
| 478 | * |
| 479 | * |
| 480 | * LOG_AUTH |
| 481 | * |
| 482 | * security/authorization messages (use |
| 483 | * LOG_AUTHPRIV instead |
| 484 | * in systems where that constant is defined) |
| 485 | * |
| 486 | * |
| 487 | * |
| 488 | * LOG_AUTHPRIV |
| 489 | * security/authorization messages (private) |
| 490 | * |
| 491 | * |
| 492 | * LOG_CRON |
| 493 | * clock daemon (cron and at) |
| 494 | * |
| 495 | * |
| 496 | * LOG_DAEMON |
| 497 | * other system daemons |
| 498 | * |
| 499 | * |
| 500 | * LOG_KERN |
| 501 | * kernel messages |
| 502 | * |
| 503 | * |
| 504 | * LOG_LOCAL0 ... LOG_LOCAL7 |
| 505 | * reserved for local use, these are not available in Windows |
| 506 | * |
| 507 | * |
| 508 | * LOG_LPR |
| 509 | * line printer subsystem |
| 510 | * |
| 511 | * |
| 512 | * LOG_MAIL |
| 513 | * mail subsystem |
| 514 | * |
| 515 | * |
| 516 | * LOG_NEWS |
| 517 | * USENET news subsystem |
| 518 | * |
| 519 | * |
| 520 | * LOG_SYSLOG |
| 521 | * messages generated internally by syslogd |
| 522 | * |
| 523 | * |
| 524 | * LOG_USER |
| 525 | * generic user-level messages |
| 526 | * |
| 527 | * |
| 528 | * LOG_UUCP |
| 529 | * UUCP subsystem |
| 530 | * |
| 531 | * |
| 532 | * |
| 533 | * |
| 534 | * |
| 535 | * LOG_USER is the only valid log type under Windows |
| 536 | * operating systems |
| 537 | * @throws NetworkException |
| 538 | * |
| 539 | */ |
| 540 | function openlog(string $ident, int $option, int $facility): void |
| 541 | { |
| 542 | error_clear_last(); |
| 543 | $result = \openlog($ident, $option, $facility); |
| 544 | if ($result === \false) { |
| 545 | throw NetworkException::createFromPhpError(); |
| 546 | } |
| 547 | } |
| 548 | /** |
| 549 | * syslog generates a log message that will be |
| 550 | * distributed by the system logger. |
| 551 | * |
| 552 | * For information on setting up a user defined log handler, see the |
| 553 | * syslog.conf |
| 554 | * 5 Unix manual page. More |
| 555 | * information on the syslog facilities and option can be found in the man |
| 556 | * pages for syslog |
| 557 | * 3 on Unix machines. |
| 558 | * |
| 559 | * @param int $priority priority is a combination of the facility and |
| 560 | * the level. Possible values are: |
| 561 | * |
| 562 | * syslog Priorities (in descending order) |
| 563 | * |
| 564 | * |
| 565 | * |
| 566 | * Constant |
| 567 | * Description |
| 568 | * |
| 569 | * |
| 570 | * |
| 571 | * |
| 572 | * LOG_EMERG |
| 573 | * system is unusable |
| 574 | * |
| 575 | * |
| 576 | * LOG_ALERT |
| 577 | * action must be taken immediately |
| 578 | * |
| 579 | * |
| 580 | * LOG_CRIT |
| 581 | * critical conditions |
| 582 | * |
| 583 | * |
| 584 | * LOG_ERR |
| 585 | * error conditions |
| 586 | * |
| 587 | * |
| 588 | * LOG_WARNING |
| 589 | * warning conditions |
| 590 | * |
| 591 | * |
| 592 | * LOG_NOTICE |
| 593 | * normal, but significant, condition |
| 594 | * |
| 595 | * |
| 596 | * LOG_INFO |
| 597 | * informational message |
| 598 | * |
| 599 | * |
| 600 | * LOG_DEBUG |
| 601 | * debug-level message |
| 602 | * |
| 603 | * |
| 604 | * |
| 605 | * |
| 606 | * @param string $message The message to send, except that the two characters |
| 607 | * %m will be replaced by the error message string |
| 608 | * (strerror) corresponding to the present value of |
| 609 | * errno. |
| 610 | * @throws NetworkException |
| 611 | * |
| 612 | */ |
| 613 | function syslog(int $priority, string $message): void |
| 614 | { |
| 615 | error_clear_last(); |
| 616 | $result = \syslog($priority, $message); |
| 617 | if ($result === \false) { |
| 618 | throw NetworkException::createFromPhpError(); |
| 619 | } |
| 620 | } |
| 621 |