Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace App\Command; use Symfony\Component\Console\Input\InputInterface; use Symf..
Decoded Output download
<?php
namespace App\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; use Aws\Ec2\Ec2Client; use Aws\Credentials\Credentials as AwsCredentials; use App\Command\Command as BaseCommand; use App\CloudPanel\Environment as CloudPanelEnvironment; use App\Aws\Instance as AwsInstance; use App\Aws\Ami as AwsAmi; use App\Entity\Notification; use App\Notification\NotificationQueue; class AwsImageCreateCommand extends BaseCommand { private ?Ec2Client $ec2Client = null; protected function configure() : void { goto Ec3b6; A60d9: $this->setDescription("clpctl aws:image:create --frequency=3"); goto B9295; Ec3b6: $this->setName("aws:image:create"); goto A60d9; B9295: $this->addOption("frequency", null, InputOption::VALUE_REQUIRED); goto D6c55; D6c55: } protected function execute(InputInterface $input, OutputInterface $output) : int { try { goto eaa29; ac2b5: $awsImagesFrequency = (int) $this->getConfigValue("aws_images_frequency"); goto ab730; db3c9: $cloud = $this->getConfigValue("cloud"); goto bd3ad; fc134: $imageCreated = $this->createImage(); goto fb0be; bc793: $this->cleanImages(); goto cebcd; D8148: Fe6e7: goto A46e7; f9c5e: if (!(CloudPanelEnvironment::CLOUD_PROVIDER_AWS == $cloud && true === $awsAutomaticImages && false === empty($awsAccessKey) && $awsImagesFrequency == $frequency)) { goto Fe6e7; } goto fc134; cebcd: bde9b: goto D8148; fb0be: if (!(true === $imageCreated)) { goto bde9b; } goto bc793; ab730: $awsAccessKey = $this->getConfigValue("aws_access_key"); goto f9c5e; bd3ad: $awsAutomaticImages = (bool) $this->getConfigValue("aws_automatic_images"); goto ac2b5; A46e7: return BaseCommand::SUCCESS; goto e6ee8; Ea3d9: $frequency = (int) $input->getOption("frequency"); goto db3c9; eaa29: $this->validateInput($input); goto Ea3d9; e6ee8: } catch (\Exception $e) { goto A2292; A2292: $errorMessage = $e->getMessage(); goto cb935; cb935: $output->writeln(sprintf("<error>%s</error>", $errorMessage)); goto e25ad; e25ad: return BaseCommand::FAILURE; goto fe219; fe219: } } private function createImage() : bool { try { goto de9cf; Eccbc: $imageConfiguration = ["InstanceId" => $instanceId, "Name" => $imageName, "NoReboot" => true]; goto B0351; afe58: $instances = $result["Reservations"][0]["Instances"] ?? []; goto d8507; d1e64: $awsInstance->setTags($tags); goto a761d; a761d: $instanceName = $awsInstance->getInstanceName(); goto cceff; f44ee: $instanceId = $instance->getInstanceId(); goto a7093; c1794: $awsInstance = new AwsInstance(); goto E2db8; A7446: $imageName = sprintf("%s_clp_%s", strtolower($instanceName), $dateTime->getTimestamp()); goto F6af8; E86cf: $instance = $this->getInstance(); goto f44ee; Bcf13: if (!(false == empty($instance))) { goto F8301; } goto c1794; D4b47: $imageName = sprintf("%s_clp_%s", $instanceId, $dateTime->getTimestamp()); goto d3dc9; B0351: $imageId = $this->retry(function () use($ec2Client, $imageConfiguration) { goto c21a9; c21a9: $result = $ec2Client->createImage($imageConfiguration); goto Ea9e6; Ea9e6: $imageId = $result["ImageId"] ?? ''; goto f58dd; f58dd: return $imageId; goto a846e; a846e: }); goto ba1db; F6af8: eec9b: goto Eccbc; E2db8: $tags = (array) $instance["Tags"] ?? []; goto d1e64; de9cf: $instanceUid = $this->getConfigValue("instance_uid"); goto E86cf; f5c63: return true; goto c880a; E7a4d: $result = $ec2Client->describeInstances(["InstanceIds" => [$instanceId]]); goto afe58; a8fed: if (false === empty($instanceName)) { goto C0f48; } goto D4b47; d3dc9: goto eec9b; goto b0062; Aef13: F8301: goto f5c63; a7093: $ec2Client = $this->getEc2Client(); goto E7a4d; b0062: C0f48: goto A7446; d8507: $instance = $instances[0] ?? []; goto Bcf13; ba1db: $this->retry(function () use($instanceUid, $imageId, $ec2Client) { $ec2Client->createTags(["Resources" => [$imageId], "Tags" => [["Key" => "InstanceUid", "Value" => $instanceUid], ["Key" => "Type", "Value" => AwsAmi::TYPE_AUTOMATED], ["Key" => "CreatedBy", "Value" => "CloudPanel"]]]); }); goto Aef13; cceff: $dateTime = new \DateTime(); goto a8fed; c880a: } catch (\Exception $e) { $errorMessage = $e->getMessage(); $this->addNotification("Creating an AWS image failed", $errorMessage); } return false; } private function addNotification(string $subject, string $errorMessage) : void { goto ebc1f; e39bf: NotificationQueue::addNotification($notification); goto a5d50; ebc1f: $notification = new Notification(); goto D49e5; C3304: $notification->setMessage($errorMessage); goto f8b46; D49e5: $notification->setSubject($subject); goto C3304; f8b46: $notification->setSeverity(Notification::SEVERITY_CRITICAL); goto e39bf; a5d50: } private function cleanImages() : void { try { goto e980f; Eb406: $imageDeleteDateTime->setTimezone(new \DateTimeZone("UTC")); goto C3dbe; d1485: $result = $ec2Client->describeImages(["Filters" => $filters]); goto E47ce; ac40d: $imageDeleteDateTime->modify(sprintf("-%s days", $awsBackupRetentionPeriod)); goto Bec79; E47ce: $images = (array) $result->get("Images"); goto Fc2f8; Db60b: Dc4f5: goto d8b67; A3f4d: $filters = [["Name" => "tag:InstanceUid", "Values" => [$instanceUid]], ["Name" => "tag:Type", "Values" => [AwsAmi::TYPE_AUTOMATED]], ["Name" => "state", "Values" => [AwsAmi::STATE_AVAILABLE, AwsAmi::STATE_FAILED]]]; goto d1485; F1ab7: $awsBackupRetentionPeriod = (int) $this->getConfigValue("aws_images_retention_period"); goto fa3bf; fa3bf: $ec2Client = $this->getEc2Client(); goto A3f4d; C3dbe: foreach ($images as $image) { goto E6c3f; B192d: $this->retry(function () use($ec2Client, $amiId) { $ec2Client->deregisterImage(["ImageId" => $amiId]); }); goto F585b; c5b66: $amiId = $image["ImageId"] ?? null; goto A8438; F7708: fd7e4: goto bd7b5; A26cf: foreach ($blockDeviceMappings as $blockDevice) { goto e3d41; e3d41: $snapshotId = $blockDevice["Ebs"]["SnapshotId"] ?? null; goto De1d5; c907f: $this->retry(function () use($ec2Client, $snapshotId) { $ec2Client->deleteSnapshot(["SnapshotId" => $snapshotId]); }); goto D13b5; De1d5: if (!(false === is_null($snapshotId))) { goto a376f; } goto c907f; c0a61: b489d: goto E372c; D13b5: a376f: goto c0a61; E372c: } goto f6a07; bd7b5: fc99e: goto Ad260; A9fad: $imageCreationDate->setTimezone(new \DateTimeZone("UTC")); goto c5b66; A8438: if (!(false === is_null($amiId) && false === is_null($imageCreationDate) && $imageCreationDate < $imageDeleteDateTime)) { goto fc99e; } goto B192d; f6a07: C04a4: goto F7708; E6c3f: $imageCreationDate = true === isset($image["CreationDate"]) ? new \DateTime($image["CreationDate"]) : null; goto A9fad; Ad260: dfaef: goto d2294; F585b: $blockDeviceMappings = $image["BlockDeviceMappings"] ?? []; goto c71a9; c71a9: if (!(false == empty($blockDeviceMappings) && true === is_array($blockDeviceMappings))) { goto fd7e4; } goto A26cf; d2294: } goto Db60b; e980f: $instanceUid = $this->getConfigValue("instance_uid"); goto F1ab7; e36b3: $imageDeleteDateTime = clone $dateTime; goto ac40d; Bec79: $imageDeleteDateTime->modify("+5 minutes"); goto Eb406; Fc2f8: $dateTime = new \DateTime(); goto e36b3; d8b67: } catch (\Exception $e) { $errorMessage = $e->getMessage(); $this->addNotification("Cleaning old AWS images failed", $errorMessage); } } private function getEc2Client() : Ec2Client { goto f8137; D5130: ac8cb: goto A2145; f8137: if (!(true === is_null($this->ec2Client))) { goto ac8cb; } goto cfaf0; d41a1: $credentials = new AwsCredentials($accessKey, $secretAccessKey); goto A5afd; a237c: $secretAccessKey = $this->getConfigValue("aws_secret_access_key"); goto d41a1; Faa1a: $region = $instance->getRegion(); goto C7c79; cfaf0: $instance = $this->getInstance(); goto Faa1a; A5afd: $this->ec2Client = new Ec2Client(["version" => "latest", "region" => $region, "credentials" => $credentials]); goto D5130; C7c79: $accessKey = $this->getConfigValue("aws_access_key"); goto a237c; A2145: return $this->ec2Client; goto adc2a; adc2a: } }
?>
Did this file decode correctly?
Original Code
<?php
namespace App\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; use Aws\Ec2\Ec2Client; use Aws\Credentials\Credentials as AwsCredentials; use App\Command\Command as BaseCommand; use App\CloudPanel\Environment as CloudPanelEnvironment; use App\Aws\Instance as AwsInstance; use App\Aws\Ami as AwsAmi; use App\Entity\Notification; use App\Notification\NotificationQueue; class AwsImageCreateCommand extends BaseCommand { private ?Ec2Client $ec2Client = null; protected function configure() : void { goto Ec3b6; A60d9: $this->setDescription("\143\154\x70\x63\x74\x6c\x20\141\x77\x73\72\151\x6d\x61\x67\145\72\143\162\145\141\x74\145\40\55\55\146\162\145\x71\x75\145\156\143\171\75\63"); goto B9295; Ec3b6: $this->setName("\141\x77\x73\x3a\151\x6d\141\x67\145\72\143\162\145\x61\x74\145"); goto A60d9; B9295: $this->addOption("\146\162\x65\161\x75\145\x6e\x63\171", null, InputOption::VALUE_REQUIRED); goto D6c55; D6c55: } protected function execute(InputInterface $input, OutputInterface $output) : int { try { goto eaa29; ac2b5: $awsImagesFrequency = (int) $this->getConfigValue("\141\167\163\137\151\x6d\141\147\x65\x73\x5f\146\162\145\x71\165\145\x6e\143\171"); goto ab730; db3c9: $cloud = $this->getConfigValue("\143\x6c\157\165\x64"); goto bd3ad; fc134: $imageCreated = $this->createImage(); goto fb0be; bc793: $this->cleanImages(); goto cebcd; D8148: Fe6e7: goto A46e7; f9c5e: if (!(CloudPanelEnvironment::CLOUD_PROVIDER_AWS == $cloud && true === $awsAutomaticImages && false === empty($awsAccessKey) && $awsImagesFrequency == $frequency)) { goto Fe6e7; } goto fc134; cebcd: bde9b: goto D8148; fb0be: if (!(true === $imageCreated)) { goto bde9b; } goto bc793; ab730: $awsAccessKey = $this->getConfigValue("\141\167\x73\x5f\x61\143\x63\x65\x73\x73\x5f\153\145\x79"); goto f9c5e; bd3ad: $awsAutomaticImages = (bool) $this->getConfigValue("\141\167\x73\137\141\165\164\157\155\141\164\x69\143\x5f\151\x6d\141\x67\x65\x73"); goto ac2b5; A46e7: return BaseCommand::SUCCESS; goto e6ee8; Ea3d9: $frequency = (int) $input->getOption("\146\162\145\x71\165\145\156\x63\171"); goto db3c9; eaa29: $this->validateInput($input); goto Ea3d9; e6ee8: } catch (\Exception $e) { goto A2292; A2292: $errorMessage = $e->getMessage(); goto cb935; cb935: $output->writeln(sprintf("\74\145\x72\x72\x6f\162\76\45\x73\x3c\57\x65\x72\162\x6f\162\76", $errorMessage)); goto e25ad; e25ad: return BaseCommand::FAILURE; goto fe219; fe219: } } private function createImage() : bool { try { goto de9cf; Eccbc: $imageConfiguration = ["\111\x6e\163\164\x61\156\143\x65\x49\x64" => $instanceId, "\116\141\155\x65" => $imageName, "\116\x6f\122\145\x62\157\157\164" => true]; goto B0351; afe58: $instances = $result["\x52\145\163\145\162\x76\x61\x74\151\157\156\163"][0]["\111\156\x73\164\141\156\143\x65\x73"] ?? []; goto d8507; d1e64: $awsInstance->setTags($tags); goto a761d; a761d: $instanceName = $awsInstance->getInstanceName(); goto cceff; f44ee: $instanceId = $instance->getInstanceId(); goto a7093; c1794: $awsInstance = new AwsInstance(); goto E2db8; A7446: $imageName = sprintf("\x25\x73\137\x63\154\160\137\45\163", strtolower($instanceName), $dateTime->getTimestamp()); goto F6af8; E86cf: $instance = $this->getInstance(); goto f44ee; Bcf13: if (!(false == empty($instance))) { goto F8301; } goto c1794; D4b47: $imageName = sprintf("\45\163\137\x63\x6c\160\x5f\x25\x73", $instanceId, $dateTime->getTimestamp()); goto d3dc9; B0351: $imageId = $this->retry(function () use($ec2Client, $imageConfiguration) { goto c21a9; c21a9: $result = $ec2Client->createImage($imageConfiguration); goto Ea9e6; Ea9e6: $imageId = $result["\111\x6d\141\147\145\x49\144"] ?? ''; goto f58dd; f58dd: return $imageId; goto a846e; a846e: }); goto ba1db; F6af8: eec9b: goto Eccbc; E2db8: $tags = (array) $instance["\124\141\147\163"] ?? []; goto d1e64; de9cf: $instanceUid = $this->getConfigValue("\x69\x6e\163\x74\x61\156\x63\145\137\165\x69\x64"); goto E86cf; f5c63: return true; goto c880a; E7a4d: $result = $ec2Client->describeInstances(["\x49\156\163\164\x61\x6e\x63\145\x49\144\163" => [$instanceId]]); goto afe58; a8fed: if (false === empty($instanceName)) { goto C0f48; } goto D4b47; d3dc9: goto eec9b; goto b0062; Aef13: F8301: goto f5c63; a7093: $ec2Client = $this->getEc2Client(); goto E7a4d; b0062: C0f48: goto A7446; d8507: $instance = $instances[0] ?? []; goto Bcf13; ba1db: $this->retry(function () use($instanceUid, $imageId, $ec2Client) { $ec2Client->createTags(["\122\x65\x73\157\165\x72\143\x65\163" => [$imageId], "\x54\x61\x67\163" => [["\113\x65\171" => "\x49\156\x73\x74\141\x6e\x63\x65\125\x69\x64", "\x56\x61\x6c\x75\145" => $instanceUid], ["\113\x65\171" => "\x54\171\160\145", "\126\141\x6c\165\145" => AwsAmi::TYPE_AUTOMATED], ["\x4b\x65\x79" => "\103\x72\145\x61\x74\145\144\102\171", "\126\141\154\165\145" => "\103\x6c\157\x75\144\120\x61\156\145\154"]]]); }); goto Aef13; cceff: $dateTime = new \DateTime(); goto a8fed; c880a: } catch (\Exception $e) { $errorMessage = $e->getMessage(); $this->addNotification("\x43\162\145\x61\164\151\156\147\40\x61\156\x20\101\127\x53\40\151\x6d\141\147\x65\40\146\x61\x69\154\x65\144", $errorMessage); } return false; } private function addNotification(string $subject, string $errorMessage) : void { goto ebc1f; e39bf: NotificationQueue::addNotification($notification); goto a5d50; ebc1f: $notification = new Notification(); goto D49e5; C3304: $notification->setMessage($errorMessage); goto f8b46; D49e5: $notification->setSubject($subject); goto C3304; f8b46: $notification->setSeverity(Notification::SEVERITY_CRITICAL); goto e39bf; a5d50: } private function cleanImages() : void { try { goto e980f; Eb406: $imageDeleteDateTime->setTimezone(new \DateTimeZone("\x55\x54\103")); goto C3dbe; d1485: $result = $ec2Client->describeImages(["\x46\x69\154\x74\x65\x72\163" => $filters]); goto E47ce; ac40d: $imageDeleteDateTime->modify(sprintf("\x2d\x25\x73\x20\x64\141\171\x73", $awsBackupRetentionPeriod)); goto Bec79; E47ce: $images = (array) $result->get("\111\155\141\x67\x65\x73"); goto Fc2f8; Db60b: Dc4f5: goto d8b67; A3f4d: $filters = [["\116\141\155\x65" => "\164\141\147\x3a\x49\156\163\x74\x61\x6e\x63\x65\125\x69\x64", "\126\141\154\165\x65\x73" => [$instanceUid]], ["\116\x61\x6d\x65" => "\164\x61\x67\72\124\171\160\145", "\126\141\x6c\x75\145\163" => [AwsAmi::TYPE_AUTOMATED]], ["\116\141\x6d\145" => "\163\x74\141\164\x65", "\x56\141\154\x75\x65\163" => [AwsAmi::STATE_AVAILABLE, AwsAmi::STATE_FAILED]]]; goto d1485; F1ab7: $awsBackupRetentionPeriod = (int) $this->getConfigValue("\x61\167\x73\137\x69\155\141\x67\x65\163\x5f\162\145\x74\x65\x6e\x74\151\157\156\x5f\160\x65\162\x69\157\144"); goto fa3bf; fa3bf: $ec2Client = $this->getEc2Client(); goto A3f4d; C3dbe: foreach ($images as $image) { goto E6c3f; B192d: $this->retry(function () use($ec2Client, $amiId) { $ec2Client->deregisterImage(["\111\155\141\147\145\111\144" => $amiId]); }); goto F585b; c5b66: $amiId = $image["\111\x6d\x61\147\145\111\144"] ?? null; goto A8438; F7708: fd7e4: goto bd7b5; A26cf: foreach ($blockDeviceMappings as $blockDevice) { goto e3d41; e3d41: $snapshotId = $blockDevice["\x45\142\x73"]["\x53\156\x61\x70\163\150\157\164\x49\x64"] ?? null; goto De1d5; c907f: $this->retry(function () use($ec2Client, $snapshotId) { $ec2Client->deleteSnapshot(["\123\x6e\141\160\163\x68\157\164\x49\144" => $snapshotId]); }); goto D13b5; De1d5: if (!(false === is_null($snapshotId))) { goto a376f; } goto c907f; c0a61: b489d: goto E372c; D13b5: a376f: goto c0a61; E372c: } goto f6a07; bd7b5: fc99e: goto Ad260; A9fad: $imageCreationDate->setTimezone(new \DateTimeZone("\125\124\103")); goto c5b66; A8438: if (!(false === is_null($amiId) && false === is_null($imageCreationDate) && $imageCreationDate < $imageDeleteDateTime)) { goto fc99e; } goto B192d; f6a07: C04a4: goto F7708; E6c3f: $imageCreationDate = true === isset($image["\x43\162\145\141\164\x69\x6f\156\x44\141\x74\145"]) ? new \DateTime($image["\103\162\x65\141\164\151\x6f\156\104\141\x74\145"]) : null; goto A9fad; Ad260: dfaef: goto d2294; F585b: $blockDeviceMappings = $image["\102\x6c\157\x63\x6b\x44\145\166\x69\x63\145\x4d\141\160\160\x69\156\x67\x73"] ?? []; goto c71a9; c71a9: if (!(false == empty($blockDeviceMappings) && true === is_array($blockDeviceMappings))) { goto fd7e4; } goto A26cf; d2294: } goto Db60b; e980f: $instanceUid = $this->getConfigValue("\x69\x6e\163\x74\141\x6e\x63\x65\137\x75\x69\144"); goto F1ab7; e36b3: $imageDeleteDateTime = clone $dateTime; goto ac40d; Bec79: $imageDeleteDateTime->modify("\x2b\x35\x20\x6d\151\156\165\x74\x65\163"); goto Eb406; Fc2f8: $dateTime = new \DateTime(); goto e36b3; d8b67: } catch (\Exception $e) { $errorMessage = $e->getMessage(); $this->addNotification("\103\x6c\145\141\156\x69\156\x67\x20\157\154\144\40\x41\127\123\x20\x69\155\x61\x67\x65\x73\x20\146\141\151\154\145\x64", $errorMessage); } } private function getEc2Client() : Ec2Client { goto f8137; D5130: ac8cb: goto A2145; f8137: if (!(true === is_null($this->ec2Client))) { goto ac8cb; } goto cfaf0; d41a1: $credentials = new AwsCredentials($accessKey, $secretAccessKey); goto A5afd; a237c: $secretAccessKey = $this->getConfigValue("\x61\167\x73\137\163\145\x63\x72\145\164\137\x61\143\143\145\163\163\x5f\x6b\145\171"); goto d41a1; Faa1a: $region = $instance->getRegion(); goto C7c79; cfaf0: $instance = $this->getInstance(); goto Faa1a; A5afd: $this->ec2Client = new Ec2Client(["\166\x65\162\163\x69\157\156" => "\x6c\x61\x74\x65\163\164", "\162\x65\x67\151\157\156" => $region, "\143\162\x65\x64\145\x6e\164\x69\141\154\x73" => $credentials]); goto D5130; C7c79: $accessKey = $this->getConfigValue("\x61\167\163\x5f\x61\143\143\x65\163\163\137\153\x65\171"); goto a237c; A2145: return $this->ec2Client; goto adc2a; adc2a: } }
Function Calls
None |
Stats
MD5 | 23953011f35abfc379f58a254f5a4700 |
Eval Count | 0 |
Decode Time | 81 ms |