Compare commits
4 Commits
02a14ad587
...
8cb306882c
Author | SHA1 | Date | |
---|---|---|---|
8cb306882c | |||
67df2666a6 | |||
4b3c4f1755 | |||
cd5a80b33b |
@ -18,8 +18,8 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
#[AsCommand(name: 'webcron:cleanup', description: 'Cleanup runs')]
|
||||
class CleanupCommand extends Command
|
||||
{
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
||||
{
|
||||
|
@ -16,8 +16,8 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
#[AsCommand(name: 'webcron:daemon', description: 'The master script of Webcron Management')]
|
||||
class DaemonCommand extends Command
|
||||
{
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
||||
{
|
||||
|
@ -19,9 +19,9 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
#[AsCommand(name: 'webcron:demodata', description: 'Install demo data')]
|
||||
class DemoInstallCommand extends Command
|
||||
{
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
protected $passwordHasher;
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
protected UserPasswordHasherInterface $passwordHasher;
|
||||
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine, UserPasswordHasherInterface $passwordHasher)
|
||||
{
|
||||
|
@ -23,10 +23,10 @@ use Twig\Environment;
|
||||
#[AsCommand(name: 'webcron:mail-failed-runs', description: 'Sends email about failed runs')]
|
||||
class MailFailedRunsCommand extends Command
|
||||
{
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
protected $templating;
|
||||
protected $mailer;
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
protected Environment $templating;
|
||||
protected MailerInterface $mailer;
|
||||
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine, Environment $templating, MailerInterface $mailer)
|
||||
{
|
||||
|
@ -14,8 +14,8 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
#[AsCommand(name: 'webcron:run', description: 'Run a single cronjob')]
|
||||
class RunCommand extends Command
|
||||
{
|
||||
protected $kernel;
|
||||
protected $doctrine;
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
|
||||
public function __construct(KernelInterface $kernel, ManagerRegistry $doctrine)
|
||||
{
|
||||
|
@ -25,7 +25,6 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
#[AsCommand(name: 'webcron:user', description: 'User stuff')]
|
||||
class UserCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'webcron:user';
|
||||
protected KernelInterface $kernel;
|
||||
protected ManagerRegistry $doctrine;
|
||||
protected UserPasswordHasherInterface $passwordHasher;
|
||||
|
@ -5,7 +5,14 @@ namespace App\Service;
|
||||
|
||||
class Secret
|
||||
{
|
||||
static function encrypt($plaintext) {
|
||||
/**
|
||||
* Encrypt plaintext string based with password string
|
||||
*
|
||||
* @param $plaintext
|
||||
* @return string
|
||||
*/
|
||||
static function encrypt($plaintext): string
|
||||
{
|
||||
$password = $_ENV['APP_SECRET'];
|
||||
$method = $_ENV['ENCRYPTION_METHOD'];
|
||||
$key = hash($_ENV['HASHING_METHOD'], $password, true);
|
||||
@ -17,7 +24,14 @@ class Secret
|
||||
return $iv . $hash . $ciphertext;
|
||||
}
|
||||
|
||||
static function decrypt($ivHashCiphertext) {
|
||||
/**
|
||||
* Decrypt encrypted message
|
||||
*
|
||||
* @param $ivHashCiphertext
|
||||
* @return string
|
||||
*/
|
||||
static function decrypt($ivHashCiphertext): string
|
||||
{
|
||||
$password = $_ENV['APP_SECRET'];
|
||||
$method = $_ENV['ENCRYPTION_METHOD'];
|
||||
$iv = substr($ivHashCiphertext, 0, 16);
|
||||
|
@ -8,7 +8,7 @@ use Twig\TwigTest;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFilters()
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('interval', [$this, 'parseInterval']),
|
||||
@ -18,14 +18,20 @@ class AppExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
public function getTests(): array
|
||||
{
|
||||
return [
|
||||
new TwigTest('ondisk', [$this, 'onDisk'])
|
||||
];
|
||||
}
|
||||
|
||||
function parseInterval(int|float $time)
|
||||
/**
|
||||
* Converts seconds to days, hours, minutes and seconds
|
||||
*
|
||||
* @param int|float $time
|
||||
* @return string
|
||||
*/
|
||||
function parseInterval(int|float $time): string
|
||||
{
|
||||
$return = '';
|
||||
|
||||
@ -47,26 +53,37 @@ class AppExtension extends AbstractExtension
|
||||
return (!empty($return)) ? trim($return) : '0.000s';
|
||||
}
|
||||
|
||||
function parseTags(string $text)
|
||||
/**
|
||||
* Converts [tag] to a HTML span element with background color based on the md5 hash of the tag and text color based on whether background color is light or dark
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function parseTags(string $text): string
|
||||
{
|
||||
$results = [];
|
||||
preg_match_all('/\[([A-Za-z0-9 \-]+)\]/', $text, $results);
|
||||
foreach ($results[0] as $key=>$result) {
|
||||
$background = substr(md5($results[0][$key]), 0, 6);
|
||||
$color = $this->lightOrDark($background) == 'dark' ? 'ffffff' : '000000';
|
||||
$background = substr(hash('murmur3a', $results[0][$key]), 0, 6);
|
||||
$color = $this->isDark($background) ? 'ffffff' : '000000';
|
||||
$text = str_replace($results[0][$key], '<span class="tag" data-background-color="#' . $background . '" data-color="#' . $color . '">' . $results[1][$key] . '</span>', $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function lightOrDark ($color)
|
||||
/**
|
||||
* Returns true if the color is considered to be dark
|
||||
*
|
||||
* @param string $color
|
||||
* @return bool
|
||||
*/
|
||||
private function isDark(string $color): bool
|
||||
{
|
||||
$color = str_split($color, 2);
|
||||
foreach($color as &$value) {
|
||||
$value = hexdec($value);
|
||||
}
|
||||
|
||||
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
|
||||
// HSP equation from http://alienryderflex.com/hsp.html
|
||||
$hsp = sqrt(
|
||||
0.299 * ($color[0] * $color[0]) +
|
||||
0.587 * ($color[1] * $color[1]) +
|
||||
@ -75,24 +92,36 @@ class AppExtension extends AbstractExtension
|
||||
|
||||
|
||||
// Using the HSP value, determine whether the color is light or dark
|
||||
if ($hsp>140) {
|
||||
return 'light';
|
||||
} else {
|
||||
return 'dark';
|
||||
}
|
||||
return ($hsp<150);
|
||||
}
|
||||
|
||||
function decryptSecret(string $text)
|
||||
/**
|
||||
* Returns decrypted cipher text
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function decryptSecret(string $text): string
|
||||
{
|
||||
return Secret::decrypt(base64_decode($text));
|
||||
}
|
||||
|
||||
function getContents(string $file)
|
||||
/**
|
||||
* Returns the content of a file
|
||||
*
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
function getContents(string $file): string
|
||||
{
|
||||
return file_get_contents($file);
|
||||
}
|
||||
|
||||
public function onDisk(string $file)
|
||||
/**
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
public function onDisk(string $file): string
|
||||
{
|
||||
return file_exists($file);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user