ENHANCEMENT: added demo mode
This commit is contained in:
parent
c5aa2b3fe0
commit
417521d497
20
.env.sample
20
.env.sample
@ -15,6 +15,20 @@ DATABASE_URL="mysql://root:letmein@localhost:3306/webcron?charset=UTF8"
|
||||
## Sqlite sample
|
||||
DATABASE_URL="sqlite:///storage/database.sqlite"
|
||||
|
||||
#################
|
||||
### DEMO-MODE ###
|
||||
#################
|
||||
|
||||
## Demo mode is used for showcasing the application. Demo mode will create a warning on every page and won't run your cronjobs
|
||||
## As this will also display credentials on the login page, you should avoid enabling this on production environmnents
|
||||
## Why would you want to do that anyway?
|
||||
DEMO_MODE=false
|
||||
|
||||
## The username and password of the demo mode cannot be read from the database. Therefore we are putting these in plain-text here.
|
||||
## They should be available anyway
|
||||
DEMO_USER=example@example.com
|
||||
DEMO_PASS=password
|
||||
|
||||
##################
|
||||
### ENCRYPTION ###
|
||||
##################
|
||||
@ -27,10 +41,8 @@ SECRET=ImNotThatSecretSoPleaseChangeMe0123456789
|
||||
## Please see https://www.php.net/openssl-get-cipher-methods for possible values
|
||||
ENCRYPTION_METHOD="AES-256-CBC"
|
||||
|
||||
## Hashing methods algorithms to save passwords.
|
||||
## By saving a hash instead of plain-text password your password is kept safe as hashing is considered to be irreversable
|
||||
## Additionally when saving a secret variable, a hash of the secret value is calculated as well to ensure
|
||||
## the encrypted data is not tampered
|
||||
## Encryption can only be secure if you are sure it is not tampered.
|
||||
## The value below is the hashing algorithm that is used to verify the encrypted date
|
||||
HASHING_METHOD="sha256"
|
||||
|
||||
###################
|
||||
|
@ -13,6 +13,8 @@ use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
use phpseclib3\Net\SSH2;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -185,6 +187,14 @@ class JobRepository extends EntityRepository
|
||||
*/
|
||||
private function runHttpJob(Job &$job): array
|
||||
{
|
||||
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
|
||||
$exitcodes = [...array_fill(0,120, $job->getData('http-status')[0]), ...array_keys(Response::$statusTexts)];
|
||||
$return['exitcode'] = $exitcodes[random_int(0, 181)];
|
||||
$return['failed'] = !in_array($return['exitcode'], $job->getData('http-status'));
|
||||
$return['output'] = 'Demo mode!';
|
||||
|
||||
return $return;
|
||||
}
|
||||
$client = new Client();
|
||||
|
||||
$url = $job->getData('url');
|
||||
@ -218,6 +228,14 @@ class JobRepository extends EntityRepository
|
||||
*/
|
||||
private function runCommandJob(Job &$job): array
|
||||
{
|
||||
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
|
||||
$exitcodes = [...array_fill(0,400, $job->getData('response')), ...range(0, 255)];
|
||||
$return['exitcode'] = $exitcodes[random_int(0, 655)];
|
||||
$return['failed'] = !in_array($return['exitcode'], $job->getData('response'));
|
||||
$return['output'] = 'Demo mode!';
|
||||
|
||||
return $return;
|
||||
}
|
||||
$command = $job->getData('command');
|
||||
if(!empty($job->getData('vars'))) {
|
||||
foreach ($job->getData('vars') as $key => $var) {
|
||||
@ -303,6 +321,13 @@ class JobRepository extends EntityRepository
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
if($job->getRunning() == 1) {
|
||||
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
|
||||
$job->setRunning(time() + $job->getData('reboot-delay-secs') + ($job->getData('reboot-duration') * 60));
|
||||
$em->persist($job);
|
||||
$em->flush();
|
||||
|
||||
return ['status' => 'deferred'];
|
||||
}
|
||||
$this->setTempVar($job, 'starttime', $starttime);
|
||||
$this->setTempVar($job, 'manual', $manual);
|
||||
$rebootcommand = $job->getData('reboot-command');
|
||||
@ -337,6 +362,16 @@ class JobRepository extends EntityRepository
|
||||
if($job->getRunning() > time()) {
|
||||
return ['status' => 'deferred'];
|
||||
}
|
||||
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
|
||||
$exitcodes = [...array_fill(0,400, $job->getData('getservices-response')), ...range(0, 255)];
|
||||
$return['exitcode'] = $exitcodes[random_int(0, 655)];
|
||||
$return['failed'] = !in_array($return['exitcode'], $job->getData('getservices-response'));
|
||||
$return['output'] = 'Demo mode!';
|
||||
$job->setRunning(1);
|
||||
$em->persist($job);
|
||||
$em->flush();
|
||||
return $return;
|
||||
}
|
||||
$starttime = (float)$this->getTempVar($job, 'starttime');
|
||||
$this->deleteTempVar($job, 'starttime');
|
||||
$manual = $this->getTempVar($job, 'manual');
|
||||
|
@ -7,3 +7,10 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% if app.request.server.get('DEMO_MODE') %}
|
||||
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
||||
{{ 'demomode.flashnotice' | trans }}
|
||||
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
@ -16,7 +16,7 @@
|
||||
{{ include('flashes.html.twig') }}
|
||||
{% if error %}
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
{{ error.messageKey|trans(error.messageData, 'security') }}
|
||||
{{ error.messageKey | trans(error.messageData, 'security') }}
|
||||
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
@ -37,8 +37,16 @@
|
||||
<label class="from-check-label" for="autologin">{{ 'security.login.remember.label' | trans }}</label>
|
||||
</div>
|
||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
|
||||
<button type="submit" class="btn btn-outline-primary">{{ 'security.login.submit-btn.label' | trans }}</button>
|
||||
<button type="submit" class="mb-3 btn btn-outline-primary">{{ 'security.login.submit-btn.label' | trans }}</button>
|
||||
</form>
|
||||
{% if app.request.server.get('DEMO_MODE') %}
|
||||
{# Demo mode credentials #}
|
||||
<div class="mb-3 text-muted small">
|
||||
<p class="mb-0">{{ 'demomode.credentials.header' | trans }}</p>
|
||||
<p class="mb-0">{{ 'demomode.credentials.username' | trans }}: {{ app.request.server.get('DEMO_USER') }}</p>
|
||||
<p class="mb-0">{{ 'demomode.credentials.password' | trans }}: {{ app.request.server.get('DEMO_PASS') }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,5 +1,11 @@
|
||||
title: "W3bcr0n m4n4g3m3nt"
|
||||
header: "W3bcr0n m4n4g3m3nt"
|
||||
demomode:
|
||||
flashnotice: "d1z 4ppL1c4t10n b 1n d3m0 m0d3. Ch4ng3z 1z p3rs1st3d 1n t3h d4t4b4s3, but j0bz 1z n0t b31n' 3x3cut3d"
|
||||
credentials:
|
||||
header: "L0g1n 4 d3m0 m0d3"
|
||||
username: "Us3rn4m3"
|
||||
password: "P4ssw0rd"
|
||||
menu:
|
||||
overview: "0v3rv13w"
|
||||
add: "4dd @ n3w cr0nj0b"
|
||||
|
@ -1,5 +1,11 @@
|
||||
title: "Webcron management"
|
||||
header: "Webcron management"
|
||||
demomode:
|
||||
flashnotice: "This application is in demo mode. Changes are persisted in the database, but jobs are not being executed"
|
||||
credentials:
|
||||
header: "Login for demo mode"
|
||||
username: "Username"
|
||||
password: "Password"
|
||||
menu:
|
||||
overview: "Overview"
|
||||
add: "Add a new cronjob"
|
||||
|
@ -1,5 +1,12 @@
|
||||
title: "Webcron management"
|
||||
header: "Webcron management"
|
||||
demomode:
|
||||
flashnotice: "Deze applicatie is in demo modus. Alle functies zijn actief, maar taken worden niet uitgevoerd"
|
||||
credentials:
|
||||
header: "Aanmeldgegevens voor demo modus:"
|
||||
username: "Gebruikersnaam"
|
||||
password: "Wachtwoord"
|
||||
|
||||
menu:
|
||||
overview: "Overzicht"
|
||||
add: "Taak toevoegen"
|
||||
|
Loading…
x
Reference in New Issue
Block a user