/
home
/
clp
/
htdocs
/
app
/
files
/
src
/
Command
/
up file
home
<?php namespace App\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Psr7\Request; use App\Command\Command as BaseCommand; use App\System\Command\WriteFileCommand; use App\System\Command\ServiceReloadCommand; use App\System\CommandExecutor; class CloudflareUpdateIpsCommand extends BaseCommand { private const CLOUDFLARE_IPV4_REQUEST_URL = "\150\164\x74\x70\163\72\x2f\57\167\167\x77\x2e\x63\x6c\x6f\x75\x64\x66\154\x61\162\x65\56\x63\157\155\57\x69\160\163\x2d\x76\64"; private const CLOUDFLARE_IPV6_REQUEST_URL = "\x68\x74\164\x70\163\x3a\x2f\57\x77\167\167\x2e\x63\x6c\157\x75\144\x66\154\141\x72\x65\56\x63\x6f\155\x2f\x69\x70\x73\55\166\x36"; private const NGINX_CLOUDFLARE_FILE = "\x2f\145\164\143\x2f\x6e\147\x69\156\x78\57\x63\x6c\157\165\x64\x66\x6c\x61\162\x65\x2f\151\x70\x73"; private const HTTP_CLIENT_TIMEOUT = 10; private ?HttpClient $httpClient = null; protected function configure() : void { goto Dace4; Dace4: $this->setName("\x63\154\157\x75\x64\146\x6c\141\x72\x65\x3a\165\160\144\x61\x74\145\72\x69\160\163"); goto A7bdc; ec1d9: $this->addOption("\x64\145\x6c\x61\x79", null, InputOption::VALUE_OPTIONAL, false); goto E624e; A7bdc: $this->setDescription("\x63\154\x70\143\164\x6c\40\143\154\x6f\165\x64\x66\154\x61\162\x65\72\165\x70\x64\x61\164\145\72\151\160\163"); goto ec1d9; E624e: } protected function execute(InputInterface $input, OutputInterface $output) : int { try { goto E4982; d181c: return BaseCommand::SUCCESS; goto A54cf; E4982: $delay = (bool) $input->getOption("\x64\x65\x6c\x61\x79"); goto a646f; B7fc4: Ed5bd: goto B69c7; a646f: if (!(true === $delay)) { goto Ed5bd; } goto F1d81; Cbf7c: $output->writeln("\x3c\x69\x6e\x66\157\x3e\x43\x6c\x6f\165\x64\x66\154\x61\x72\145\x20\111\x50\x73\40\x68\x61\166\145\40\x62\145\x65\156\40\x75\x70\144\x61\x74\145\x64\56\x3c\57\x69\156\x66\157\76"); goto d181c; B69c7: $this->updateIps(); goto Cbf7c; F1d81: sleep(rand(15, 180)); goto B7fc4; A54cf: } catch (\Exception $e) { goto e85f8; C4d58: return BaseCommand::FAILURE; goto Ed500; dbf91: $output->writeln(sprintf("\74\145\x72\162\157\162\x3e\x25\x73\74\57\x65\162\x72\157\x72\x3e", $errorMessage)); goto C4d58; D8e89: $logger->exception($e); goto a285b; a285b: $errorMessage = $e->getMessage(); goto dbf91; e85f8: $logger = $this->getLogger(); goto D8e89; Ed500: } } private function updateIps() : void { goto a915b; B130e: ec583: goto cbec0; ab42c: $requestUrls = [self::CLOUDFLARE_IPV4_REQUEST_URL, self::CLOUDFLARE_IPV6_REQUEST_URL]; goto Be79b; ecb2b: if (!(false === empty($ips))) { goto ec583; } goto ff5a4; ff5a4: $this->writeIpsToFile($ips); goto F0096; Fc8c9: foreach ($requestUrls as $requestUrl) { goto D86bf; A8481: b6e65: goto da5a9; ff902: if (!(false === empty($cloudflareIps) && true === is_array($cloudflareIps))) { goto e4bdc; } goto f343b; E6287: e4bdc: goto Ffb17; ac622: $cloudflareIps = explode(PHP_EOL, $responseData); goto ff902; D516f: if (!(false === empty($responseData))) { goto C664f; } goto ac622; D86bf: $request = new Request("\107\x45\124", $requestUrl); goto Ea4d9; f343b: $this->validateIps($cloudflareIps); goto d5fc2; d5fc2: $ips = array_merge($ips, $cloudflareIps); goto E6287; da5a9: f8d9c: goto dc050; Ea4d9: $response = $httpClient->send($request); goto a6ec0; Fe43d: if (!(200 == $responseStatusCode)) { goto b6e65; } goto Ae07a; Ffb17: C664f: goto A8481; Ae07a: $responseData = trim((string) $response->getBody()); goto D516f; a6ec0: $responseStatusCode = $response->getStatusCode(); goto Fe43d; dc050: } goto E0f35; E0f35: A38c1: goto ecb2b; Be79b: $ips = []; goto Fc8c9; F0096: $this->reloadNginxService(); goto B130e; a915b: $httpClient = $this->getHttpClient(); goto ab42c; cbec0: } private function writeIpsToFile(array $ips) : void { goto Aa27b; Bdd68: $writeFileCommand->setContent($fileContent); goto Bc2f7; B93ba: foreach ($ips as $ip) { $fileContent .= sprintf("\x61\154\x6c\157\x77\40\45\163\x3b", $ip) . PHP_EOL; Afd53: } goto ad6ed; Aa27b: $commandExecutor = new CommandExecutor(); goto c6aaa; c6aaa: $fileContent = ''; goto B93ba; Bc2f7: $commandExecutor->execute($writeFileCommand); goto a8eac; a97cf: $writeFileCommand = new WriteFileCommand(); goto Fb4d3; B1d59: $fileContent .= "\x64\145\x6e\171\x20\x61\x6c\154\73"; goto a97cf; ad6ed: c1d47: goto B1d59; Fb4d3: $writeFileCommand->setFile(self::NGINX_CLOUDFLARE_FILE); goto Bdd68; a8eac: } private function reloadNginxService() { goto E3f8b; E861d: Da01d: goto B3d2e; c983c: $commandExecutor = new CommandExecutor(); goto d2fe5; Afe3c: $reloadServiceCommand->setServiceName("\156\147\151\156\x78"); goto Bcd18; Bcd18: $commandExecutor->execute($reloadServiceCommand); goto E861d; E3f8b: if (!("\144\x65\x76" != $_ENV["\101\120\x50\x5f\105\116\126"])) { goto Da01d; } goto c983c; d2fe5: $reloadServiceCommand = new ServiceReloadCommand(); goto Afe3c; B3d2e: } private function validateIps(array $ips) : void { foreach ($ips as $ip) { goto E70ac; Efdce: E2d65: goto c8d57; ae6c3: Ae8eb: goto Efdce; a4647: throw new \Exception(sprintf("\111\120\40\x22\45\163\x22\x20\x69\163\40\x6e\x6f\x74\40\x76\141\154\151\x64\x2e", $ip)); goto ae6c3; C0a06: if (!(false === $isValidIp)) { goto Ae8eb; } goto a4647; E70ac: $isValidIp = $this->validateIp($ip); goto C0a06; c8d57: } C5a57: } private function validateIp(string $ip) : bool { goto f1276; Fa680: $isValidIp = false; goto Fe9a1; E94a8: f0989: goto acfe5; cc49c: $isNetmaskValid = $netmask <= 128; goto C0ceb; Fe9a1: Fb35c: goto d9405; Bfbbe: Cb888: goto E7c36; E7c36: goto a9f32; goto E94a8; C6af5: $isNetmaskValid = false; goto D4164; fbbe9: if (true === $isIpv6) { goto Fc4f1; } goto ca81b; Cbf37: if (true === $isIpv6) { goto f0989; } goto Ff501; ca81b: $isNetmaskValid = $netmask <= 32; goto b5952; F630b: Fc4f1: goto cc49c; acfe5: if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { goto Ba716; } goto D2618; B1135: $ipParts = explode("\x2f", $ipAddress); goto Acbff; f1276: $ipAddress = $ip; goto B1135; c9ce8: if (!(true === $isValidIp && false === empty($netmask))) { goto a098b; } goto E4f89; b5952: goto c5031; goto F630b; D2618: $isValidIp = true; goto Ed482; Feb1d: return $isValidIp; goto b4661; d9405: a098b: goto Feb1d; Ed482: Ba716: goto C8f61; ef866: if (!($netmask < 0)) { goto e2d45; } goto C6af5; C0ceb: c5031: goto ad6c1; E4f89: $netmask = (int) $netmask; goto Eb45a; D1ac0: $isIpv6 = substr_count($ipAddress, "\72") ? true : false; goto Cca27; Cca27: $isValidIp = false; goto Cbf37; bfc97: $netmask = $ipParts[1] ?? ''; goto D1ac0; C8f61: a9f32: goto c9ce8; D4164: e2d45: goto fbbe9; Acbff: $ip = $ipParts[0] ?? ''; goto bfc97; ad6c1: if (!(false === $isNetmaskValid)) { goto Fb35c; } goto Fa680; Db0a4: $isValidIp = true; goto Bfbbe; Ff501: if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { goto Cb888; } goto Db0a4; Eb45a: $isNetmaskValid = false; goto ef866; b4661: } private function getHttpClient() : HttpClient { goto a4116; d987a: a9c76: goto D8076; E99c7: $this->httpClient = new HttpClient($config); goto d987a; D8076: return $this->httpClient; goto c280b; a3c30: $config = ["\x74\151\x6d\145\157\165\x74" => self::HTTP_CLIENT_TIMEOUT, "\166\x65\x72\151\x66\171" => false]; goto E99c7; a4116: if (!(true === is_null($this->httpClient))) { goto a9c76; } goto a3c30; c280b: } }