Browse Source

Added SSH jobs

main
Jeroen De Meerleer 4 weeks ago
parent
commit
874bbdf717
  1. 4
      public/resources/job/add.js
  2. 10
      src/Repository/Job.php
  3. 54
      templates/job/add.html.twig

4
public/resources/job/add.js

@ -3,6 +3,7 @@ $(function() {
initCronType();
initSecretInputs();
initDelayPattern();
bsCustomFileInput.init()
});
function initDatePickers()
@ -18,6 +19,9 @@ function initCronType()
$('.crontype').val(type);
$('.crontype-inputs:not(.hidden)').addClass('hidden');
$('.crontype-' + type).removeClass('hidden');
$('.crontype-inputs:not(.hidden) input').prop('disabled', false);
$('.crontype-inputs.hidden input').prop('disabled', true);
})
}

10
src/Repository/Job.php

@ -53,6 +53,16 @@ class Job
$data['command'] = $values['command'];
$data['host'] = 'localhost';
break;
case 'ssh':
$data['host'] = $values['host'];
$data['user'] = $values['user'];
if(!empty($_FILES['privkey']['tmp_name'])) {
$newsecretkey = count($values['secretval']);
$values['secretid'][$newsecretkey] = 'ssh-privkey';
$values['secretval'][$newsecretkey] = base64_encode(file_get_contents($_FILES['privkey']['tmp_name']));
}
$data['command'] = $values['command'];
break;
case 'http':
$parsedUrl = parse_url($values['url']);
$data['url'] = $values['url'];

54
templates/job/add.html.twig

@ -2,7 +2,7 @@
{% block title %}Add job{% endblock %}
{% block content %}
<h2>Add a cronjob</h2>
<form method="post" class="form-horizontal" action="{{ path('job_add') }}">
<form method="post" class="form-horizontal" enctype="multipart/form-data" action="{{ path('job_add') }}">
<h3>General info</h3>
<div class="mb-3">
@ -54,6 +54,48 @@
</div>
</div>
<div class="crontype-local crontype-inputs hidden">
<div class="mb-3">
<label for="command">Command</label>
<input type="text" name="command" class="form-control" id="command" placeholder="sudo apt update">
</div>
</div>
<div class="crontype-ssh crontype-inputs hidden">
<div class="mb-3">
<label for="host">Hostname</label>
<input type="text" name="host" class="form-control" id="host" placeholder="ssh.abc.xyz">
</div>
<div class="mb-3">
<label for="user">Username</label>
<input type="text" name="user" class="form-control" id="user" placeholder="larry">
</div>
<div class="mb-3">
<label for="privkey">Private key</label>
<div class="custom-file">
<input type="file" class="custom-file-input" id="privkey" name="privkey">
<label class="custom-file-label" for="privkey">Choose file</label>
</div>
<small id="basicauth-password-help" class="form-text text-muted">This file is being saved as a secret</small>
</div>
<div class="mb-3">
<label for="privkey-password">Password for private key</label>
<input type="hidden" name="secretid[]" value="privkey-password">
<input type="password" name="secretval[]" class="form-control" placeholder="correct horse battery staple">
<small id="privkey-password-help" class="form-text text-muted">If private key is empty this field is being used as ssh-password</small>
<small id="privkey-password-help-2" class="form-text text-muted">This field is being saved as a secret</small>
</div>
<div class="mb-3">
<label for="command">Command</label>
<input type="text" name="command" class="form-control" id="command" placeholder="sudo apt update">
</div>
</div>
<div class="crontype-http crontype-inputs hidden">
<div class="mb-3">
<label for="url">Url</label>
@ -71,13 +113,6 @@
</div>
</div>
<div class="crontype-local crontype-inputs hidden">
<div class="mb-3">
<label for="command">Command</label>
<input type="text" name="command" class="form-control" id="command" placeholder="sudo apt update">
</div>
</div>
<h3>Secrets</h3>
<div class="secrets mb-3">
<div class="input-group secret-group hidden">
@ -105,7 +140,8 @@
{% endblock %}
{% block extrascripts %}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.39.0/js/tempusdominus-bootstrap-4.min.js" integrity="sha512-k6/Bkb8Fxf/c1Tkyl39yJwcOZ1P4cRrJu77p83zJjN2Z55prbFHxPs9vN7q3l3+tSMGPDdoH51AEU8Vgo1cgAA==" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bs-custom-file-input/1.3.4/bs-custom-file-input.min.js" integrity="sha512-91BoXI7UENvgjyH31ug0ga7o1Ov41tOzbMM3+RPqFVohn1UbVcjL/f5sl6YSOFfaJp+rF+/IEbOOEwtBONMz+w==" crossorigin="anonymous"></script>
<script type="text/javascript" src="/resources/job/add.js"></script>
{% endblock %}
Loading…
Cancel
Save