/** * Add an autoRun entry. * * @param array $run * @param string $workspace * @string file * @return bool * @throws \Error */ protected function addautoRun(array $run, string $workspace, string $file) : bool { static $db_tpl = null; if ($db_tpl === null) { $db_tpl = \file_get_contents(\dirname(HANGAR_ROOT) . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'index.php.tmp'); } $hash = Util::hash($file); switch ($run['type']) { case 'php': \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', Base64::decode($run['data'])); \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . "' . $hash . '.php";' . "\n", FILE_APPEND); return true; case 'mysql': case 'pgsql': $exec = \str_replace(['@_QUERY_@', '@_DRIVER_@'], [\str_replace('"', '\\"', Base64::decode($run['data'])), $run['type']], $db_tpl); // Save the template file: \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', $exec); // Add the autoRun script to the autoRun list: \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . $hash . ".php";' . "\n", FILE_APPEND); return true; default: throw new \Error('Unknown type: ' . $run['type']); } }
/** * Get a hash of the data (defaults to hex encoded) * * @param bool $raw * * These two aren't really meant to be used externally: * @param int $outputSize * @param string $personalization * * @return string */ public function getHash(bool $raw = false, int $outputSize = \Sodium\CRYPTO_GENERICHASH_BYTES, string $personalization = '') : string { if ($raw) { return Util::raw_hash($personalization . $this->data, $outputSize); } return Util::hash($personalization . $this->data, $outputSize); }