�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: BotDataConverter.php Size: 21.21 KB
/home2/astrociv/public_html/avitours.in/wp-content/plugins/imunify-security/inc/App/Bot/BotDataConverter.php
<?php
/**
 * Copyright (с) Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * https://www.cloudlinux.com/legal/
 *
 * phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen
 * phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite
 * phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fclose
 * phpcs:disable WordPress.WP.AlternativeFunctions.rename_rename
 * phpcs:disable WordPress.WP.AlternativeFunctions.unlink_unlink
 * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export
 * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
 */

namespace CloudLinux\Imunify\App\Bot;

/**
 * Converts structured bot-protection data into OPcache-friendly PHP bundle files.
 *
 * WordPress-agnostic: no wp_* calls. All write failures throw RuntimeException
 * so callers (CLI scripts and wp-cron) can choose their own error surface.
 *
 * @since 4.1.0
 */
class BotDataConverter {

	/**
	 * Absolute path to the output directory.
	 *
	 * @var string
	 */
	private $output_dir;

	/**
	 * Longest `generated_at` accepted from all.json. The value is republished in
	 * every daily bot-stats export, so an oversized one would bloat each file.
	 */
	const MAX_GENERATED_AT_LENGTH = 64;

	/**
	 * `generated_at` of the last all.json passed to convert(), '' before the
	 * first call or when the payload omitted it.
	 *
	 * @var string
	 */
	private $generated_at = '';

	/**
	 * Source name → relative PHP path under the output directory.
	 *
	 * @var array<string,string>
	 */
	private static $source_relpath_map = array(
		'cloudflare'                 => 'cdn-ip-ranges/cloudflare.php',
		'fastly'                     => 'cdn-ip-ranges/fastly.php',
		'cloudfront'                 => 'cdn-ip-ranges/cloudfront.php',
		'akamai'                     => 'cdn-ip-ranges/akamai.php',
		'sucuri'                     => 'cdn-ip-ranges/sucuri.php',
		'imperva'                    => 'cdn-ip-ranges/imperva.php',
		'quic-cloud'                 => 'cdn-ip-ranges/quic-cloud.php',
		'aws'                        => 'datacenter-ip-ranges/aws.php',
		'gcp'                        => 'datacenter-ip-ranges/gcp.php',
		'azure'                      => 'datacenter-ip-ranges/azure.php',
		'ovh'                        => 'datacenter-ip-ranges/ovh.php',
		'hetzner'                    => 'datacenter-ip-ranges/hetzner.php',
		'digitalocean'               => 'datacenter-ip-ranges/digitalocean.php',
		'anthropic'                  => 'bot-ip-ranges/anthropic.php',
		'anthropic-outbound'         => 'bot-ip-ranges/anthropic-outbound.php',
		'openai'                     => 'bot-ip-ranges/openai.php',
		'google'                     => 'bot-ip-ranges/google.php',
		'bing'                       => 'bot-ip-ranges/bing.php',
		'apple'                      => 'bot-ip-ranges/apple.php',
		'meta'                       => 'bot-ip-ranges/meta.php',
		'duckduckgo'                 => 'bot-ip-ranges/duckduckgo.php',
		'duckassistbot'              => 'bot-ip-ranges/duckassistbot.php',
		'perplexity'                 => 'bot-ip-ranges/perplexity.php',
		'ahrefs'                     => 'bot-ip-ranges/ahrefs.php',
		'barkrowler'                 => 'bot-ip-ranges/barkrowler.php',
		'ua-ai-crawlers'             => 'signatures/ua-ai-crawlers.php',
		'ua-search-engines'          => 'signatures/ua-search-engines.php',
		'ua-seo-crawlers'            => 'signatures/ua-seo-crawlers.php',
		'ua-malicious'               => 'signatures/ua-malicious.php',
		'ua-rdns-suffixes'           => 'signatures/ua-rdns-suffixes.php',
		'ua-ai-rdns-suffixes'        => 'signatures/ua-ai-rdns-suffixes.php',
		'ua-seo-rdns-suffixes'       => 'signatures/ua-seo-rdns-suffixes.php',
		'ua-search-engine-providers' => 'signatures/ua-search-engine-providers.php',
		'ua-ai-crawler-providers'    => 'signatures/ua-ai-crawler-providers.php',
		'ua-seo-crawler-providers'   => 'signatures/ua-seo-crawler-providers.php',
		'rest-namespaces'            => 'signatures/rest-namespaces.php',
	);

	/**
	 * Signature bundles that are not User-Agent tokens, so the UA sanitizer (which would drop `wc/`) skips them.
	 *
	 * @var string[]
	 */
	private static $non_ua_signature_relpaths = array(
		'signatures/rest-namespaces.php',
	);

	/**
	 * Build a converter bound to an output directory.
	 *
	 * @param string $output_dir Absolute path to the output directory.
	 */
	public function __construct( $output_dir ) {
		$this->output_dir = rtrim( (string) $output_dir, '/' );
	}

	/**
	 * Parse all.json and write PHP bundle files to the output directory.
	 *
	 * All-or-nothing: every bundle is built and staged to a .tmp file first; only
	 * once all sources stage successfully are they committed (renamed) into place.
	 * A failure on any source leaves the existing bundle files untouched, so a
	 * site never runs on a half-applied overlay.
	 *
	 * @param string $json   Raw all.json content.
	 * @param bool   $strict When true a source with no $source_relpath_map entry
	 *                       throws instead of being skipped. Off by default: the
	 *                       mirror is shared by every installed version, so an
	 *                       older plugin must keep refreshing when a new source
	 *                       appears. CLI callers pass true so a source the map
	 *                       does not know fails the job that builds the ZIP.
	 * @return int Number of bundle files written.
	 * @throws \RuntimeException On schema mismatch or any write failure.
	 */
	public function convert( $json, $strict = false ) {
		AtomicFileWriter::ensureDirectoryProtection( $this->output_dir );
		$data = json_decode( $json, true );
		if ( ! is_array( $data )
			|| ! isset( $data['schema_version'] )
			|| '1' !== (string) $data['schema_version'] ) {
			throw new \RuntimeException( 'BotDataConverter: invalid or unsupported schema_version in all.json' );
		}
		if ( ! isset( $data['sources'] ) || ! is_array( $data['sources'] ) ) {
			throw new \RuntimeException( 'BotDataConverter: missing sources object in all.json' );
		}

		$this->generated_at = isset( $data['generated_at'] )
			&& is_string( $data['generated_at'] )
			&& strlen( $data['generated_at'] ) <= self::MAX_GENERATED_AT_LENGTH
				? $data['generated_at']
				: '';

		$planned = array();
		foreach ( $data['sources'] as $name => $source ) {
			if ( ! isset( self::$source_relpath_map[ $name ] ) ) {
				if ( $strict ) {
					throw new \RuntimeException( 'BotDataConverter: no output path for source ' . $name . '; add it to $source_relpath_map' );
				}
				continue;
			}
			$relpath    = self::$source_relpath_map[ $name ];
			$source_url = isset( $source['source_url'] ) ? (string) $source['source_url'] : 'mirror';
			$fetched_at = isset( $source['fetched_at'] ) ? (string) $source['fetched_at'] : gmdate( 'c' );
			$type       = isset( $source['type'] ) ? $source['type'] : '';
			// The bundles are the authored form; this JSON is derived from them.
			// Passing the note back, and keeping the order the JSON already
			// carries, is what makes the round trip byte-exact — see
			// tests/unit/App/Bot/BundleRoundTripTest.php.
			$extra = isset( $source['note'] ) && is_string( $source['note'] )
				? array( 'note' => $source['note'] )
				: array();
			try {
				if ( 'ranges' === $type ) {
					if ( isset( $source['ranges'] ) && is_array( $source['ranges'] ) && ! empty( $source['ranges'] ) ) {
						$this->assertSafeRelpath( $relpath );
						$planned[ $relpath ] = $this->buildRangesPayload( $source_url, $fetched_at, $source['ranges'], $extra );
					}
				} elseif ( 'signatures' === $type ) {
					if ( isset( $source['signatures'] ) && is_array( $source['signatures'] ) && ! empty( $source['signatures'] ) ) {
						$this->assertSafeRelpath( $relpath );
						$payload = $this->buildSignaturesPayload( $relpath, $source_url, $fetched_at, $source['signatures'], $extra, false );
						if ( ! empty( $payload['signatures'] ) ) {
							$planned[ $relpath ] = $payload;
						}
					}
				} elseif ( 'providers' === $type ) {
					if ( isset( $source['providers'] ) && is_array( $source['providers'] ) && ! empty( $source['providers'] ) ) {
						$this->assertSafeRelpath( $relpath );
						$payload = $this->buildProvidersPayload( $source_url, $fetched_at, $source['providers'], $extra, false );
						if ( ! empty( $payload['providers'] ) ) {
							$planned[ $relpath ] = $payload;
						}
					}
				}
			} catch ( \Exception $e ) {
				throw new \RuntimeException( 'BotDataConverter: failed to build ' . $name . ': ' . $e->getMessage(), 0, $e );
			}
		}

		$written = $this->writeBatch( $planned );
		AtomicFileWriter::ensureDirectoryProtection( $this->output_dir );

		if ( ! empty( $planned ) ) {
			foreach ( self::$source_relpath_map as $relpath ) {
				if ( isset( $planned[ $relpath ] ) ) {
					continue;
				}
				$abs = $this->output_dir . '/' . ltrim( $relpath, '/' );
				if ( is_file( $abs ) ) {
					@unlink( $abs );
				}
			}
		}

		return $written;
	}

	/**
	 * The `generated_at` of the all.json the last convert() call parsed — the
	 * only version identifier the dataset carries, and one the per-source bundle
	 * files do not keep.
	 *
	 * @return string ISO-8601 timestamp, or '' when absent or over-long.
	 */
	public function generatedAt() {
		return $this->generated_at;
	}

	/**
	 * Write a ranges bundle file with sorted CIDRs and sorted-set checksum.
	 *
	 * @param string   $relpath    Relative path under output_dir.
	 * @param string   $source_url Source identifier (URL or "MANUAL").
	 * @param string   $fetched_at ISO-8601 fetch timestamp.
	 * @param string[] $ranges     Flat list of CIDR strings.
	 * @param array    $extra      Optional extra metadata merged into payload.
	 * @throws \RuntimeException On path traversal or write failure.
	 */
	public function writeRanges( $relpath, $source_url, $fetched_at, $ranges, $extra = array() ) {
		$this->assertSafeRelpath( $relpath );
		$this->writePhpFile( $relpath, $this->buildRangesPayload( $source_url, $fetched_at, $ranges, $extra ) );
	}

	/**
	 * Write a signatures bundle file with sanitised tokens.
	 *
	 * @param string   $relpath    Relative path under output_dir.
	 * @param string   $source_url Source identifier.
	 * @param string   $fetched_at ISO-8601 fetch timestamp.
	 * @param string[] $signatures Raw signature tokens.
	 * @param array    $extra      Optional extra metadata merged into payload.
	 * @param bool     $sort       When true (default) the stored list is sorted
	 *                             alphabetically. Pass false for hand-curated lists
	 *                             to preserve the authored order; the checksum is
	 *                             always computed from the sorted set regardless.
	 * @throws \RuntimeException On path traversal or write failure.
	 */
	public function writeSignatures( $relpath, $source_url, $fetched_at, $signatures, $extra = array(), $sort = true ) {
		$this->assertSafeRelpath( $relpath );
		$this->writePhpFile( $relpath, $this->buildSignaturesPayload( $relpath, $source_url, $fetched_at, $signatures, $extra, $sort ) );
	}

	/**
	 * Write a providers bundle file with sorted-set checksum.
	 *
	 * @param string $relpath    Relative path under output_dir.
	 * @param string $source_url Source identifier.
	 * @param string $fetched_at ISO-8601 fetch timestamp.
	 * @param array  $providers  Map of provider name => {tokens:[], suffixes?:[]}.
	 * @param array  $extra      Optional extra metadata merged into payload.
	 * @param bool   $sort       When true (default) the provider map is stored in
	 *                           alphabetical key order. Pass false for hand-curated
	 *                           maps to preserve the authored order; the checksum is
	 *                           always computed from the sorted map regardless.
	 * @throws \RuntimeException On path traversal or write failure.
	 */
	public function writeProviders( $relpath, $source_url, $fetched_at, $providers, $extra = array(), $sort = true ) {
		$this->assertSafeRelpath( $relpath );
		$this->writePhpFile( $relpath, $this->buildProvidersPayload( $source_url, $fetched_at, $providers, $extra, $sort ) );
	}

	/**
	 * Build a ranges payload (sorted CIDRs, octet-bucketed, sorted-set checksum).
	 *
	 * @param string   $source_url Source identifier.
	 * @param string   $fetched_at ISO-8601 fetch timestamp.
	 * @param string[] $ranges     Flat list of CIDR strings.
	 * @param array    $extra      Optional extra metadata.
	 * @return array
	 */
	private function buildRangesPayload( $source_url, $fetched_at, $ranges, $extra = array() ) {
		sort( $ranges );
		$bucketed = SignatureRefresher::bucketRanges( $ranges );
		return array_merge(
			array(
				'source_url'      => $source_url,
				'fetched_at'      => $fetched_at,
				'checksum'        => 'sha256:' . hash( 'sha256', implode( "\n", $ranges ) ),
				'ranges_by_octet' => $bucketed['ranges_by_octet'],
				'ranges_broad'    => $bucketed['ranges_broad'],
			),
			$extra
		);
	}

	/**
	 * Build a signatures payload (sanitised, sorted-set checksum).
	 *
	 * @param string   $relpath    Relative path of the bundle; picks the sanitizer.
	 * @param string   $source_url Source identifier.
	 * @param string   $fetched_at ISO-8601 fetch timestamp.
	 * @param string[] $signatures Raw signature tokens.
	 * @param array    $extra      Optional extra metadata.
	 * @param bool     $sort       Whether to store the list in sorted order.
	 * @return array
	 */
	private function buildSignaturesPayload( $relpath, $source_url, $fetched_at, $signatures, $extra = array(), $sort = true ) {
		$signatures = in_array( $relpath, self::$non_ua_signature_relpaths, true )
			? array_values( array_filter( $signatures, 'is_string' ) )
			: SignatureRefresher::sanitizeSignatures( $signatures );
		$sorted     = $signatures;
		sort( $sorted );
		return array_merge(
			array(
				'source_url' => $source_url,
				'fetched_at' => $fetched_at,
				'checksum'   => 'sha256:' . hash( 'sha256', implode( "\n", $sorted ) ),
				'signatures' => $sort ? $sorted : $signatures,
			),
			$extra
		);
	}

	/**
	 * Build a providers payload (sorted-set checksum).
	 *
	 * @param string $source_url Source identifier.
	 * @param string $fetched_at ISO-8601 fetch timestamp.
	 * @param array  $providers  Map of provider name => {tokens:[], suffixes:[]}.
	 * @param array  $extra      Optional extra metadata.
	 * @param bool   $sort       Whether to store the provider map in sorted key order.
	 * @return array
	 */
	private function buildProvidersPayload( $source_url, $fetched_at, $providers, $extra = array(), $sort = true ) {
		$clean = array();
		foreach ( $providers as $name => $info ) {
			if ( ! is_string( $name ) || '' === $name || ! is_array( $info ) ) {
				continue;
			}
			$tokens   = isset( $info['tokens'] ) && is_array( $info['tokens'] )
				? array_values( array_filter( $info['tokens'], 'is_string' ) )
				: array();
			$suffixes = isset( $info['suffixes'] ) && is_array( $info['suffixes'] )
				? array_values( array_filter( $info['suffixes'], 'is_string' ) )
				: array();
			if ( empty( $tokens ) ) {
				continue;
			}
			$clean[ $name ] = array( 'tokens' => $tokens );
			// Suffixes are optional: the rDNS files bind tokens to a PTR
			// namespace, the token-to-provider maps bind them to an IP-range
			// provider and carry none.
			if ( ! empty( $suffixes ) ) {
				$clean[ $name ]['suffixes'] = $suffixes;
			}
		}

		$sorted_clean = $clean;
		ksort( $sorted_clean );

		$digest_lines = array();
		foreach ( $sorted_clean as $name => $info ) {
			$t = $info['tokens'];
			sort( $t );
			$s = isset( $info['suffixes'] ) ? $info['suffixes'] : array();
			sort( $s );
			$digest_lines[] = $name . ':tokens=' . implode( ',', $t ) . ';suffixes=' . implode( ',', $s );
		}

		return array_merge(
			array(
				'source_url' => $source_url,
				'fetched_at' => $fetched_at,
				'checksum'   => 'sha256:' . hash( 'sha256', implode( "\n", $digest_lines ) ),
			),
			$extra,
			array( 'providers' => $sort ? $sorted_clean : $clean )
		);
	}

	/**
	 * Throw if $relpath could escape the output directory.
	 *
	 * @param string $relpath Relative path to validate.
	 * @throws \RuntimeException When the path contains traversal sequences.
	 */
	private function assertSafeRelpath( $relpath ) {
		if ( BundledData::isUnsafePath( $relpath ) ) {
			throw new \RuntimeException( 'BotDataConverter: unsafe relpath: ' . $relpath );
		}
	}

	/**
	 * Render a PHP return-array file body.
	 *
	 * @param array $payload Payload array to serialise.
	 * @return string
	 */
	private function renderPhp( $payload ) {
		return "<?php\ndefined( 'ABSPATH' ) || exit;\n// Auto-generated. Do not edit by hand.\n\nreturn " . self::phpExport( $payload ) . ";\n";
	}

	/**
	 * Recursively export a value as a PHP expression using array() long syntax.
	 *
	 * Sequential (0-based integer) arrays omit keys; all other arrays (associative
	 * or non-sequential integer) include them. This produces smaller output than
	 * var_export(), which always emits explicit integer keys.
	 *
	 * @param mixed $var   Value to export.
	 * @param int   $depth Current nesting depth (controls indentation).
	 * @return string
	 */
	public static function phpExport( $var, $depth = 0 ) {
		if ( ! is_array( $var ) ) {
			return var_export( $var, true );
		}
		if ( empty( $var ) ) {
			return 'array()';
		}
		$keys       = array_keys( $var );
		$sequential = range( 0, count( $var ) - 1 ) === $keys;
		$pad        = str_repeat( '    ', $depth + 1 );
		$close_pad  = str_repeat( '    ', $depth );
		$items      = array();
		foreach ( $var as $k => $v ) {
			$entry = $pad;
			if ( ! $sequential ) {
				$entry .= var_export( $k, true ) . ' => ';
			}
			$entry  .= self::phpExport( $v, $depth + 1 );
			$items[] = $entry;
		}
		return "array(\n" . implode( ",\n", $items ) . ",\n" . $close_pad . ')';
	}

	/**
	 * Atomically write a single PHP return-array file (tmp + rename).
	 *
	 * @param string $relpath Relative path under output_dir.
	 * @param array  $payload Payload array to serialise.
	 * @throws \RuntimeException On directory creation or write failure.
	 */
	private function writePhpFile( $relpath, $payload ) {
		$abs = $this->output_dir . '/' . ltrim( $relpath, '/' );
		$this->ensureParentDir( $abs );
		if ( ! AtomicFileWriter::write( $abs, $this->renderPhp( $payload ) ) ) {
			throw new \RuntimeException( 'BotDataConverter: failed to write ' . $abs );
		}
	}

	/**
	 * Create the parent directory of $abs if it is missing.
	 *
	 * @param string $abs Absolute file path.
	 * @throws \RuntimeException When the directory cannot be created.
	 */
	private function ensureParentDir( $abs ) {
		$dir = dirname( $abs );
		if ( ! is_dir( $dir ) && ! mkdir( $dir, 0755, true ) && ! is_dir( $dir ) ) {
			throw new \RuntimeException( 'BotDataConverter: mkdir failed for ' . $dir );
		}
	}

	/**
	 * Write all planned bundles atomically: stage every file to .tmp first, and
	 * only commit (rename) once they have all staged successfully. Any failure
	 * discards every staged .tmp and leaves the existing files untouched.
	 *
	 * @param array<string,array> $planned Map of relpath => payload.
	 * @return int Number of files written.
	 * @throws \RuntimeException On any staging or commit failure.
	 */
	private function writeBatch( array $planned ) {
		$staged = array();
		try {
			foreach ( $planned as $relpath => $payload ) {
				$abs            = $this->output_dir . '/' . ltrim( $relpath, '/' );
				$tmp            = $this->stageTmp( $abs, $this->renderPhp( $payload ) );
				$staged[ $tmp ] = $abs;
			}
		} catch ( \RuntimeException $e ) {
			foreach ( array_keys( $staged ) as $tmp ) {
				@unlink( $tmp );
			}
			throw $e;
		}

		$committed = array();
		foreach ( $staged as $tmp => $abs ) {
			$bak = null;
			if ( file_exists( $abs ) ) {
				$bak = $abs . '.bak';
				if ( ! rename( $abs, $bak ) ) {
					$bak = null;
				}
			}
			try {
				$this->commitTmp( $tmp, $abs );
				$committed[ $abs ] = $bak;
			} catch ( \RuntimeException $e ) {
				if ( null !== $bak ) {
					@rename( $bak, $abs );
				}
				foreach ( $committed as $c_abs => $c_bak ) {
					if ( null !== $c_bak ) {
						@rename( $c_bak, $c_abs );
					} else {
						@unlink( $c_abs );
					}
				}
				foreach ( array_keys( $staged ) as $s_tmp ) {
					@unlink( $s_tmp );
				}
				throw $e;
			}
		}
		foreach ( $committed as $c_abs => $c_bak ) {
			if ( null !== $c_bak ) {
				@unlink( $c_bak );
			}
		}
		return count( $planned );
	}

	/**
	 * Write $php to <abs>.tmp, creating the parent directory as needed.
	 *
	 * @param string $abs Absolute target path (the final, non-tmp path).
	 * @param string $php Rendered file contents.
	 * @return string The .tmp path written.
	 * @throws \RuntimeException On directory creation or write failure.
	 */
	private function stageTmp( $abs, $php ) {
		$this->ensureParentDir( $abs );
		// Deterministic, unlike AtomicFileWriter::write()'s pid-suffixed name:
		// writeBatch() has to be able to find and discard every staged file if a
		// later source fails.
		$tmp = $abs . '.tmp';
		if ( ! AtomicFileWriter::writeBody( $tmp, $php ) ) {
			throw new \RuntimeException( 'BotDataConverter: failed to stage ' . $tmp );
		}
		return $tmp;
	}

	/**
	 * Commit a staged .tmp into place via rename + opcache invalidation.
	 *
	 * @param string $tmp Staged .tmp path.
	 * @param string $abs Final target path.
	 * @throws \RuntimeException On rename failure.
	 */
	private function commitTmp( $tmp, $abs ) {
		if ( ! AtomicFileWriter::commit( $tmp, $abs ) ) {
			throw new \RuntimeException( 'BotDataConverter: rename failed for ' . $abs );
		}
	}
}

Directory Contents

Dirs: 1 × Files: 77
Name Size Perms Modified Actions
data DIR
- drwxr-xr-x 2026-11-03 01:06:25
Edit Download
11.48 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.43 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.38 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.45 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.01 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
21.21 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.34 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.81 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.38 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
13.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.77 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.67 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.53 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.25 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.72 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.58 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.55 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.00 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.58 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.99 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.88 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.53 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.61 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.73 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.86 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.97 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.76 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.06 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.26 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.64 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.68 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
10.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.09 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.51 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
12.60 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.46 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
835 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.71 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
22.44 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.65 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.33 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
892 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
924 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.69 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
18.57 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
6.92 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.87 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.94 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
18.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.48 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.80 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.84 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.45 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.28 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.27 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.90 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
15.82 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
20.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.61 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.80 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
30.46 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.72 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.60 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.05 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
6.56 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.16 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI