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 Grav\Common\Scheduler; use Closure; use Cron\CronExpression; use DateTime..

Decoded Output download

<?php
 namespace Grav\Common\Scheduler; use Closure; use Cron\CronExpression; use DateTime; use Grav\Common\Grav; use InvalidArgumentException; use RuntimeException; use Symfony\Component\Process\Process; use function call_user_func; use function call_user_func_array; use function count; use function is_array; use function is_callable; use function is_string; class Job { use IntervalTrait; private $id; private $enabled; private $command; private $at; private $args = array(); private $runInBackground = true; private $creationTime; private $executionTime; private $tempDir; private $lockFile; private $truthTest = true; private $output; private $returnCode = 0; private $outputTo = array(); private $emailTo = array(); private $emailConfig = array(); private $before; private $after; private $whenOverlapping; private $outputMode; private $process; private $successful = false; private $backlink; public function __construct($command, $args = array(), $id = null) { if (is_string($id)) { $this->id = Grav::instance()["inflector"]->hyphenize($id); } else { if (is_string($command)) { $this->id = md5($command); } else { $this->id = spl_object_hash($command); } } $this->creationTime = new DateTime("now"); $this->tempDir = sys_get_temp_dir(); $this->command = $command; $this->args = $args; $status = Grav::instance()["config"]->get("scheduler.status"); $this->enabled = !(isset($status[$id]) && $status[$id] === "disabled"); } public function getCommand() { return $this->command; } public function getAt() { return $this->at; } public function getEnabled() { return $this->enabled; } public function getArguments() { if (is_string($this->args)) { return $this->args; } return null; } public function getCronExpression() { return CronExpression::factory($this->at); } public function isSuccessful() { return $this->successful; } public function getId() { return $this->id; } public function isDue(DateTime $date = null) { if (!$this->executionTime) { $this->at("* * * * *"); } $date = $date ?? $this->creationTime; return $this->executionTime->isDue($date); } public function isOverlapping() { return $this->lockFile && file_exists($this->lockFile) && call_user_func($this->whenOverlapping, filemtime($this->lockFile)) === false; } public function inForeground() { $this->runInBackground = false; return $this; } public function backlink($link = null) { if ($link) { $this->backlink = $link; } return $this->backlink; } public function runInBackground() { return !(is_callable($this->command) || $this->runInBackground === false); } public function onlyOne($tempDir = null, callable $whenOverlapping = null) { if ($tempDir === null || !is_dir($tempDir)) { $tempDir = $this->tempDir; } $this->lockFile = implode("/", array(trim($tempDir), trim($this->id) . ".lock")); if ($whenOverlapping) { $this->whenOverlapping = $whenOverlapping; } else { $this->whenOverlapping = static function () { return false; }; } return $this; } public function configure(array $config = array()) { if (isset($config["tempDir"]) && is_dir($config["tempDir"])) { $this->tempDir = $config["tempDir"]; } return $this; } public function when(callable $fn) { $this->truthTest = $fn(); return $this; } public function run() { if ($this->truthTest !== true) { return false; } if ($this->isOverlapping()) { return false; } $this->createLockFile(); if (is_callable($this->before)) { call_user_func($this->before); } if (is_callable($this->command)) { $this->output = $this->exec(); } else { $args = is_string($this->args) ? explode(" ", $this->args) : $this->args; $command = array_merge(array($this->command), $args); $process = new Process($command); $this->process = $process; if ($this->runInBackground()) { $process->start(); } else { $process->run(); $this->finalize(); } } return true; } public function finalize() { $process = $this->process; if ($process) { $process->wait(); if ($process->isSuccessful()) { $this->successful = true; $this->output = $process->getOutput(); } else { $this->successful = false; $this->output = $process->getErrorOutput(); } $this->postRun(); unset($this->process); } } private function postRun() { if (count($this->outputTo) > 0) { foreach ($this->outputTo as $file) { $output_mode = $this->outputMode === "append" ? FILE_APPEND | LOCK_EX : LOCK_EX; $timestamp = (new DateTime("now"))->format("c"); $output = $timestamp . "
" . str_pad('', strlen($timestamp), ">") . "\xa" . $this->output; file_put_contents($file, $output, $output_mode); } } $this->emailOutput(); if (is_callable($this->after)) { call_user_func($this->after, $this->output, $this->returnCode); } $this->removeLockFile(); } private function createLockFile($content = null) { if ($this->lockFile) { if ($content === null || !is_string($content)) { $content = $this->getId(); } file_put_contents($this->lockFile, $content); } } private function removeLockFile() { if ($this->lockFile && file_exists($this->lockFile)) { unlink($this->lockFile); } } private function exec() { $return_data = ''; ob_start(); try { $return_data = call_user_func_array($this->command, $this->args); $this->successful = true; } catch (RuntimeException $e) { $return_data = $e->getMessage(); $this->successful = false; } $this->output = ob_get_clean() . (is_string($return_data) ? $return_data : ''); $this->postRun(); return $this->output; } public function output($filename, $append = false) { $this->outputTo = is_array($filename) ? $filename : array($filename); $this->outputMode = $append === false ? "overwrite" : "append"; return $this; } public function getOutput() { return $this->output; } public function email($email) { if (!is_string($email) && !is_array($email)) { throw new InvalidArgumentException("The email can be only string or array"); } $this->emailTo = is_array($email) ? $email : array($email); $this->inForeground(); return $this; } private function emailOutput() { if (!count($this->outputTo) || !count($this->emailTo)) { return false; } if (is_callable("Grav\Plugin\Email\Utils::sendEmail")) { $subject = "Grav Scheduled Job [" . $this->getId() . "]"; $content = "<h1>Output from Job ID: {$this->getId()}</h1>
<h4>Command: {$this->getCommand()}</h4><br /><pre style="font-size: 12px; font-family: Monaco, Consolas, monospace">
" . $this->getOutput() . "
</pre>"; $to = $this->emailTo; \Grav\Plugin\Email\Utils::sendEmail($subject, $content, $to); } return true; } public function before(callable $fn) { $this->before = $fn; return $this; } public function then(callable $fn, $runInBackground = false) { $this->after = $fn; if ($runInBackground === false) { $this->inForeground(); } return $this; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Grav\Common\Scheduler; use Closure; use Cron\CronExpression; use DateTime; use Grav\Common\Grav; use InvalidArgumentException; use RuntimeException; use Symfony\Component\Process\Process; use function call_user_func; use function call_user_func_array; use function count; use function is_array; use function is_callable; use function is_string; class Job { use IntervalTrait; private $id; private $enabled; private $command; private $at; private $args = array(); private $runInBackground = true; private $creationTime; private $executionTime; private $tempDir; private $lockFile; private $truthTest = true; private $output; private $returnCode = 0; private $outputTo = array(); private $emailTo = array(); private $emailConfig = array(); private $before; private $after; private $whenOverlapping; private $outputMode; private $process; private $successful = false; private $backlink; public function __construct($command, $args = array(), $id = null) { if (is_string($id)) { $this->id = Grav::instance()["\x69\156\146\154\x65\143\164\157\162"]->hyphenize($id); } else { if (is_string($command)) { $this->id = md5($command); } else { $this->id = spl_object_hash($command); } } $this->creationTime = new DateTime("\x6e\157\167"); $this->tempDir = sys_get_temp_dir(); $this->command = $command; $this->args = $args; $status = Grav::instance()["\143\x6f\156\x66\x69\x67"]->get("\x73\143\150\x65\144\x75\154\145\x72\x2e\163\x74\x61\x74\165\163"); $this->enabled = !(isset($status[$id]) && $status[$id] === "\x64\x69\x73\141\x62\154\145\x64"); } public function getCommand() { return $this->command; } public function getAt() { return $this->at; } public function getEnabled() { return $this->enabled; } public function getArguments() { if (is_string($this->args)) { return $this->args; } return null; } public function getCronExpression() { return CronExpression::factory($this->at); } public function isSuccessful() { return $this->successful; } public function getId() { return $this->id; } public function isDue(DateTime $date = null) { if (!$this->executionTime) { $this->at("\x2a\x20\x2a\x20\x2a\x20\x2a\40\x2a"); } $date = $date ?? $this->creationTime; return $this->executionTime->isDue($date); } public function isOverlapping() { return $this->lockFile && file_exists($this->lockFile) && call_user_func($this->whenOverlapping, filemtime($this->lockFile)) === false; } public function inForeground() { $this->runInBackground = false; return $this; } public function backlink($link = null) { if ($link) { $this->backlink = $link; } return $this->backlink; } public function runInBackground() { return !(is_callable($this->command) || $this->runInBackground === false); } public function onlyOne($tempDir = null, callable $whenOverlapping = null) { if ($tempDir === null || !is_dir($tempDir)) { $tempDir = $this->tempDir; } $this->lockFile = implode("\x2f", array(trim($tempDir), trim($this->id) . "\x2e\154\157\x63\153")); if ($whenOverlapping) { $this->whenOverlapping = $whenOverlapping; } else { $this->whenOverlapping = static function () { return false; }; } return $this; } public function configure(array $config = array()) { if (isset($config["\164\145\155\x70\104\x69\x72"]) && is_dir($config["\x74\145\x6d\160\104\x69\162"])) { $this->tempDir = $config["\x74\145\x6d\160\x44\151\x72"]; } return $this; } public function when(callable $fn) { $this->truthTest = $fn(); return $this; } public function run() { if ($this->truthTest !== true) { return false; } if ($this->isOverlapping()) { return false; } $this->createLockFile(); if (is_callable($this->before)) { call_user_func($this->before); } if (is_callable($this->command)) { $this->output = $this->exec(); } else { $args = is_string($this->args) ? explode("\x20", $this->args) : $this->args; $command = array_merge(array($this->command), $args); $process = new Process($command); $this->process = $process; if ($this->runInBackground()) { $process->start(); } else { $process->run(); $this->finalize(); } } return true; } public function finalize() { $process = $this->process; if ($process) { $process->wait(); if ($process->isSuccessful()) { $this->successful = true; $this->output = $process->getOutput(); } else { $this->successful = false; $this->output = $process->getErrorOutput(); } $this->postRun(); unset($this->process); } } private function postRun() { if (count($this->outputTo) > 0) { foreach ($this->outputTo as $file) { $output_mode = $this->outputMode === "\x61\x70\160\145\156\144" ? FILE_APPEND | LOCK_EX : LOCK_EX; $timestamp = (new DateTime("\x6e\157\167"))->format("\x63"); $output = $timestamp . "\12" . str_pad('', strlen($timestamp), "\76") . "\xa" . $this->output; file_put_contents($file, $output, $output_mode); } } $this->emailOutput(); if (is_callable($this->after)) { call_user_func($this->after, $this->output, $this->returnCode); } $this->removeLockFile(); } private function createLockFile($content = null) { if ($this->lockFile) { if ($content === null || !is_string($content)) { $content = $this->getId(); } file_put_contents($this->lockFile, $content); } } private function removeLockFile() { if ($this->lockFile && file_exists($this->lockFile)) { unlink($this->lockFile); } } private function exec() { $return_data = ''; ob_start(); try { $return_data = call_user_func_array($this->command, $this->args); $this->successful = true; } catch (RuntimeException $e) { $return_data = $e->getMessage(); $this->successful = false; } $this->output = ob_get_clean() . (is_string($return_data) ? $return_data : ''); $this->postRun(); return $this->output; } public function output($filename, $append = false) { $this->outputTo = is_array($filename) ? $filename : array($filename); $this->outputMode = $append === false ? "\157\x76\x65\x72\167\162\151\164\145" : "\x61\160\x70\x65\156\144"; return $this; } public function getOutput() { return $this->output; } public function email($email) { if (!is_string($email) && !is_array($email)) { throw new InvalidArgumentException("\124\x68\145\x20\145\x6d\x61\x69\154\x20\143\x61\x6e\40\x62\145\40\x6f\156\154\171\40\x73\x74\x72\151\156\x67\x20\157\162\x20\x61\162\162\141\171"); } $this->emailTo = is_array($email) ? $email : array($email); $this->inForeground(); return $this; } private function emailOutput() { if (!count($this->outputTo) || !count($this->emailTo)) { return false; } if (is_callable("\107\162\141\x76\134\x50\154\165\x67\151\x6e\x5c\x45\x6d\141\x69\x6c\x5c\x55\164\x69\x6c\163\72\x3a\x73\x65\156\144\x45\155\141\151\154")) { $subject = "\107\162\x61\166\40\123\143\150\145\144\165\x6c\145\x64\40\112\x6f\142\x20\x5b" . $this->getId() . "\x5d"; $content = "\x3c\x68\61\76\x4f\x75\164\x70\x75\x74\x20\x66\x72\157\x6d\x20\112\157\142\x20\x49\104\72\x20{$this->getId()}\74\x2f\150\61\x3e\12\x3c\150\64\x3e\103\x6f\155\x6d\141\x6e\x64\x3a\40{$this->getCommand()}\74\57\150\64\76\x3c\x62\162\x20\57\76\x3c\160\x72\145\x20\x73\164\x79\x6c\145\x3d\42\x66\x6f\156\x74\55\x73\151\x7a\x65\x3a\40\61\62\x70\x78\73\40\146\x6f\156\x74\55\146\141\x6d\x69\x6c\171\x3a\x20\x4d\157\x6e\141\143\157\54\40\103\157\x6e\x73\157\154\141\163\x2c\x20\x6d\157\x6e\157\x73\x70\x61\143\145\42\x3e\12" . $this->getOutput() . "\12\74\x2f\160\162\x65\x3e"; $to = $this->emailTo; \Grav\Plugin\Email\Utils::sendEmail($subject, $content, $to); } return true; } public function before(callable $fn) { $this->before = $fn; return $this; } public function then(callable $fn, $runInBackground = false) { $this->after = $fn; if ($runInBackground === false) { $this->inForeground(); } return $this; } }

Function Calls

None

Variables

None

Stats

MD5 e49bfb18ee668393a1ebe44c876cefbc
Eval Count 0
Decode Time 87 ms