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.hidden input').prop('disabled', true);
|
||||
})
|
||||
|
||||
$('.privkey-keep').on('click', function() {
|
||||
$('#privkey').prop('disabled', $(this).prop('checked'));
|
||||
})
|
||||
}
|
||||
|
||||
function initVarInputs()
|
||||
|
|
|
@ -57,7 +57,6 @@ class Job
|
|||
) {
|
||||
throw new \InvalidArgumentException('Some fields are empty');
|
||||
}
|
||||
|
||||
$data = $this->prepareJob($values);
|
||||
$data['data'] = json_encode($data['data']);
|
||||
$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'])) {
|
||||
$values['lastrun'] = NULL;
|
||||
} 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']['hosttype'] = $values['hosttype'];
|
||||
$values['data']['containertype'] = $values['containertype'];
|
||||
|
||||
if(empty($values['data']['crontype'])) {
|
||||
throw new \InvalidArgumentException("Crontype cannot be empty");
|
||||
}
|
||||
switch($values['data']['crontype'])
|
||||
{
|
||||
case 'command':
|
||||
|
@ -122,6 +124,8 @@ class Job
|
|||
}
|
||||
|
||||
switch($values['data']['hosttype']) {
|
||||
default:
|
||||
$values['data']['hosttype'] = $values['data']['crontype'] == 'http' ? '' : 'local';
|
||||
case 'local':
|
||||
$values['data']['host'] = 'localhost';
|
||||
break;
|
||||
|
@ -134,20 +138,34 @@ class Job
|
|||
$values['var-issecret'][$newsecretkey] = true;
|
||||
$values['var-value'][$newsecretkey] = $values['privkey-password'];
|
||||
}
|
||||
$privkeyid = NULL;
|
||||
if(!empty($_FILES['privkey']['tmp_name'])) {
|
||||
$newsecretkey = count($values['var-value']);
|
||||
$privkeyid = $newsecretkey;
|
||||
$values['var-id'][$newsecretkey] = 'ssh-privkey';
|
||||
$values['var-issecret'][$newsecretkey] = true;
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
switch($values['data']['containertype']) {
|
||||
default:
|
||||
$values['data']['containertype'] = $values['data']['crontype'] == 'http' ? '' :'none';
|
||||
case 'none':
|
||||
// No options for no container
|
||||
break;
|
||||
case 'docker':
|
||||
$values['data']['service'] = $values['service'];
|
||||
$values['data']['user'] = $values['user'];
|
||||
$values['data']['container-user'] = $values['container-user'];
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -189,6 +207,24 @@ class Job
|
|||
unset($jobRslt['data']['vars']['basicauth-password']);
|
||||
}
|
||||
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') {
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@
|
|||
|
||||
<div class="mb-3">
|
||||
<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>
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
|
||||
<div class="mb-3">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
@ -154,26 +154,35 @@
|
|||
<h4>SSH host details</h4>
|
||||
<div class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<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 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 class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<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>
|
||||
<small id="custom-file-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="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-2" class="form-text text-muted">This field is being saved as a secret</small>
|
||||
</div>
|
||||
|
@ -186,12 +195,12 @@
|
|||
<h4>Docker container details</h4>
|
||||
<div class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<label for="user">Username</label>
|
||||
<input type="text" name="user" class="form-control" id="user" placeholder="larry">
|
||||
<label for="container-user">Username</label>
|
||||
<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>
|
||||
|
||||
|
|
Loading…
Reference in New Issue