More job editing
This commit is contained in:
parent
4cf6c649b6
commit
00c5c548d6
|
@ -76,6 +76,10 @@ function initHostType()
|
||||||
$('.hosttype-inputs:not(.hidden) input').prop('disabled', false);
|
$('.hosttype-inputs:not(.hidden) input').prop('disabled', false);
|
||||||
$('.hosttype-inputs.hidden input').prop('disabled', true);
|
$('.hosttype-inputs.hidden input').prop('disabled', true);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$('.privkey-keep').on('click', function() {
|
||||||
|
$('#privkey').prop('disabled', $(this).prop('checked'));
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function initVarInputs()
|
function initVarInputs()
|
||||||
|
|
|
@ -57,7 +57,6 @@ class Job
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException('Some fields are empty');
|
throw new \InvalidArgumentException('Some fields are empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->prepareJob($values);
|
$data = $this->prepareJob($values);
|
||||||
$data['data'] = json_encode($data['data']);
|
$data['data'] = json_encode($data['data']);
|
||||||
$editJobSql = "UPDATE job set name = :name, data = :data, interval = :interval, nextrun = :nextrun, lastrun = :lastrun WHERE id = :id";
|
$editJobSql = "UPDATE job set name = :name, data = :data, interval = :interval, nextrun = :nextrun, lastrun = :lastrun WHERE id = :id";
|
||||||
|
@ -73,14 +72,17 @@ class Job
|
||||||
if(empty($values['lastrun'])) {
|
if(empty($values['lastrun'])) {
|
||||||
$values['lastrun'] = NULL;
|
$values['lastrun'] = NULL;
|
||||||
} else {
|
} else {
|
||||||
$values['lastrun'] = DateTime::createFromFormat('m/d/Y H:i:s',$values['lastrun'])->getTimestamp();
|
$values['lastrun'] = DateTime::createFromFormat('d/m/Y H:i:s',$values['lastrun'])->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
$values['nextrun'] = DateTime::createFromFormat('m/d/Y H:i:s', $values['nextrun'])->getTimestamp();
|
$values['nextrun'] = DateTime::createFromFormat('d/m/Y H:i:s', $values['nextrun'])->getTimestamp();
|
||||||
$values['data']['crontype'] = $values['crontype'];
|
$values['data']['crontype'] = $values['crontype'];
|
||||||
$values['data']['hosttype'] = $values['hosttype'];
|
$values['data']['hosttype'] = $values['hosttype'];
|
||||||
$values['data']['containertype'] = $values['containertype'];
|
$values['data']['containertype'] = $values['containertype'];
|
||||||
|
|
||||||
|
if(empty($values['data']['crontype'])) {
|
||||||
|
throw new \InvalidArgumentException("Crontype cannot be empty");
|
||||||
|
}
|
||||||
switch($values['data']['crontype'])
|
switch($values['data']['crontype'])
|
||||||
{
|
{
|
||||||
case 'command':
|
case 'command':
|
||||||
|
@ -122,6 +124,8 @@ class Job
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($values['data']['hosttype']) {
|
switch($values['data']['hosttype']) {
|
||||||
|
default:
|
||||||
|
$values['data']['hosttype'] = $values['data']['crontype'] == 'http' ? '' : 'local';
|
||||||
case 'local':
|
case 'local':
|
||||||
$values['data']['host'] = 'localhost';
|
$values['data']['host'] = 'localhost';
|
||||||
break;
|
break;
|
||||||
|
@ -134,20 +138,34 @@ class Job
|
||||||
$values['var-issecret'][$newsecretkey] = true;
|
$values['var-issecret'][$newsecretkey] = true;
|
||||||
$values['var-value'][$newsecretkey] = $values['privkey-password'];
|
$values['var-value'][$newsecretkey] = $values['privkey-password'];
|
||||||
}
|
}
|
||||||
|
$privkeyid = NULL;
|
||||||
if(!empty($_FILES['privkey']['tmp_name'])) {
|
if(!empty($_FILES['privkey']['tmp_name'])) {
|
||||||
$newsecretkey = count($values['var-value']);
|
$newsecretkey = count($values['var-value']);
|
||||||
|
$privkeyid = $newsecretkey;
|
||||||
$values['var-id'][$newsecretkey] = 'ssh-privkey';
|
$values['var-id'][$newsecretkey] = 'ssh-privkey';
|
||||||
$values['var-issecret'][$newsecretkey] = true;
|
$values['var-issecret'][$newsecretkey] = true;
|
||||||
$values['var-value'][$newsecretkey] = base64_encode(file_get_contents($_FILES['privkey']['tmp_name']));
|
$values['var-value'][$newsecretkey] = base64_encode(file_get_contents($_FILES['privkey']['tmp_name']));
|
||||||
}
|
}
|
||||||
|
if($values['privkey-keep'] == true) {
|
||||||
|
$privkeyid = ($privkeyid === NULL) ? count($values['var-value']) : $privkeyid ;
|
||||||
|
$values['var-id'][$privkeyid] = 'ssh-privkey';
|
||||||
|
$values['var-issecret'][$privkeyid] = true;
|
||||||
|
$values['var-value'][$privkeyid] = $values['privkey-orig'];
|
||||||
|
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch($values['data']['containertype']) {
|
switch($values['data']['containertype']) {
|
||||||
|
default:
|
||||||
|
$values['data']['containertype'] = $values['data']['crontype'] == 'http' ? '' :'none';
|
||||||
|
case 'none':
|
||||||
|
// No options for no container
|
||||||
|
break;
|
||||||
case 'docker':
|
case 'docker':
|
||||||
$values['data']['service'] = $values['service'];
|
$values['data']['service'] = $values['service'];
|
||||||
$values['data']['user'] = $values['user'];
|
$values['data']['container-user'] = $values['container-user'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +207,24 @@ class Job
|
||||||
unset($jobRslt['data']['vars']['basicauth-password']);
|
unset($jobRslt['data']['vars']['basicauth-password']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'reboot':
|
||||||
|
$jobRslt['data']['reboot-delay'] = $jobRslt['data']['vars']['reboot-delay']['value'];
|
||||||
|
unset($jobRslt['data']['vars']['reboot-delay']);
|
||||||
|
unset($jobRslt['data']['vars']['reboot-delay-secs']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($jobRslt['data']['hosttype']) {
|
||||||
|
case 'ssh':
|
||||||
|
if(isset($jobRslt['data']['vars']['ssh-privkey']['value'])) {
|
||||||
|
$jobRslt['data']['ssh-privkey'] = $jobRslt['data']['vars']['ssh-privkey']['value'];
|
||||||
|
unset($jobRslt['data']['vars']['ssh-privkey']);
|
||||||
|
}
|
||||||
|
if(isset($jobRslt['data']['vars']['privkey-password']['value'])) {
|
||||||
|
$jobRslt['data']['privkey-password'] = $jobRslt['data']['vars']['privkey-password']['value'];
|
||||||
|
unset($jobRslt['data']['vars']['privkey-password']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if($jobRslt['data']['crontype'] == 'http') {
|
if($jobRslt['data']['crontype'] == 'http') {
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="user">Username</label>
|
<label for="user">Username</label>
|
||||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry">
|
<input type="text" name="container-user" class="form-control" id="container-user" placeholder="larry">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="reboot-delay">Reboot delay (in minutes)</label>
|
<label for="reboot-delay">Reboot delay (in minutes)</label>
|
||||||
<input type="number" name="reboot-delay" class="form-control" placeholder="5" value="{% if attribute(data.vars, 'reboot-delay').value is not empty %}{{ attribute(data.vars, 'reboot-delay').value }}{% endif %}">
|
<input type="number" name="reboot-delay" class="form-control" placeholder="5" value="{% if attribute(data, 'reboot-delay') is not empty %}{{ attribute(data, 'reboot-delay') }}{% endif %}">
|
||||||
<small id="reboot-delay-help" class="form-text text-muted">Delay between triggering reboot and actual reboot</small>
|
<small id="reboot-delay-help" class="form-text text-muted">Delay between triggering reboot and actual reboot</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -154,26 +154,35 @@
|
||||||
<h4>SSH host details</h4>
|
<h4>SSH host details</h4>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="host">Hostname</label>
|
<label for="host">Hostname</label>
|
||||||
<input type="text" name="host" class="form-control" id="host" placeholder="ssh.abc.xyz">
|
<input type="text" name="host" class="form-control" id="host" placeholder="ssh.abc.xyz" value="{% if data.host is not empty %}{{ data.host }}{% endif %}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="user">Username</label>
|
<label for="user">Username</label>
|
||||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry">
|
<input type="text" name="user" class="form-control" id="user" placeholder="larry" value="{% if data.user is not empty %}{{ data.user }}{% endif %}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="privkey">Private key</label>
|
<label for="privkey">Private key</label>
|
||||||
<div class="custom-file">
|
<div class="input-group">
|
||||||
<input type="file" class="custom-file-input" id="privkey" name="privkey">
|
<div class="input-group-prepend">
|
||||||
<label class="custom-file-label" for="privkey">Choose file</label>
|
<div class="input-group-text border-right-0">
|
||||||
|
<input type="checkbox" name="privkey-keep" class="privkey-keep" value="true" data-privkey="{% if attribute(data, 'ssh-privkey') is not empty %}{{ attribute(data, 'ssh-privkey') }}{% endif %}" checked>
|
||||||
|
<input type="hidden" name="privkey-orig" class="privkey-orig" value="{% if attribute(data, 'ssh-privkey') is not empty %}{{ attribute(data, 'ssh-privkey') }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
<span class="input-group-text border-left-0">Keep</span>
|
||||||
|
</div>
|
||||||
|
<div class="custom-file input-group">
|
||||||
|
<input type="file" class="custom-file-input" id="privkey" name="privkey" disabled>
|
||||||
|
<label class="custom-file-label" for="privkey">Choose file</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<small id="custom-file-help" class="form-text text-muted">This file is being saved as a secret</small>
|
<small id="custom-file-help" class="form-text text-muted">This file is being saved as a secret</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="privkey-password">Password for private key</label>
|
<label for="privkey-password">Password for private key</label>
|
||||||
<input type="password" name="privkey-password" class="form-control" placeholder="correct horse battery staple">
|
<input type="password" name="privkey-password" class="form-control" placeholder="correct horse battery staple" value="{% if attribute(data, 'privkey-password') is not empty %}{{ attribute(data, 'privkey-password') }}{% endif %}">
|
||||||
<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" 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>
|
<small id="privkey-password-help-2" class="form-text text-muted">This field is being saved as a secret</small>
|
||||||
</div>
|
</div>
|
||||||
|
@ -186,12 +195,12 @@
|
||||||
<h4>Docker container details</h4>
|
<h4>Docker container details</h4>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="service">Service</label>
|
<label for="service">Service</label>
|
||||||
<input type="text" name="service" class="form-control" id="service" placeholder="mysql">
|
<input type="text" name="service" class="form-control" id="service" placeholder="mysql" value="{% if attribute(data, 'service') is not empty %}{{ attribute(data, 'service') }}{% endif %}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="user">Username</label>
|
<label for="container-user">Username</label>
|
||||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry">
|
<input type="text" name="container-user" class="form-control" id="container-user" placeholder="larry" value="{% if attribute(data, 'container-user') is not empty %}{{ attribute(data, 'container-user') }}{% endif %}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue