BUGFIX: non-secret variables
This commit is contained in:
parent
a3efea0e83
commit
1ea40525f9
|
@ -1,7 +1,7 @@
|
||||||
$(function() {
|
$(function() {
|
||||||
initDatePickers();
|
initDatePickers();
|
||||||
initCronType();
|
initCronType();
|
||||||
initSecretInputs();
|
initVarInputs();
|
||||||
initDelayPattern();
|
initDelayPattern();
|
||||||
bsCustomFileInput.init()
|
bsCustomFileInput.init()
|
||||||
});
|
});
|
||||||
|
@ -25,11 +25,21 @@ function initCronType()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSecretInputs()
|
function initVarInputs()
|
||||||
{
|
{
|
||||||
$('.addsecret-btn').on('click', function() {
|
$('.addvar-btn').on('click', function() {
|
||||||
$('.secret-group:first-child').clone().appendTo('.secrets').removeClass('hidden');
|
let index = $('.var-group').length;
|
||||||
$('.secrets-description').removeClass('hidden');
|
$('.var-group:first-child').clone().appendTo('.vars').removeClass('hidden');
|
||||||
|
$('.var-group:last-child').data({index: index});
|
||||||
|
$('.var-group:last-child .var-issecret').prop('name', 'var-issecret[' + index + ']');
|
||||||
|
$('.var-group:last-child .var-id').prop('name', 'var-id[' + index + ']');
|
||||||
|
$('.var-group:last-child .var-value').prop('name', 'var-value[' + index + ']');
|
||||||
|
$('.vars-description').removeClass('hidden');
|
||||||
|
})
|
||||||
|
$(document).on('click', '.var-issecret', function() {
|
||||||
|
let ischecked = $(this).prop('checked');
|
||||||
|
$(this).parents('.var-group').find('.var-value').prop('type', ischecked ? 'password' : 'text');
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,17 @@ class Job
|
||||||
case 'ssh':
|
case 'ssh':
|
||||||
$data['host'] = $values['host'];
|
$data['host'] = $values['host'];
|
||||||
$data['user'] = $values['user'];
|
$data['user'] = $values['user'];
|
||||||
|
if(!empty($values['privkey-password'])) {
|
||||||
|
$newsecretkey = count($values['var-value']);
|
||||||
|
$values['var-id'][$newsecretkey] = 'privkey-password';
|
||||||
|
$values['var-issecret'][$newsecretkey] = true;
|
||||||
|
$values['var-value'][$newsecretkey] = $values['privkey-password'];
|
||||||
|
}
|
||||||
if(!empty($_FILES['privkey']['tmp_name'])) {
|
if(!empty($_FILES['privkey']['tmp_name'])) {
|
||||||
$newsecretkey = count($values['secretval']);
|
$newsecretkey = count($values['var-value']);
|
||||||
$values['secretid'][$newsecretkey] = 'ssh-privkey';
|
$values['var-id'][$newsecretkey] = 'ssh-privkey';
|
||||||
$values['secretval'][$newsecretkey] = base64_encode(file_get_contents($_FILES['privkey']['tmp_name']));
|
$values['var-issecret'][$newsecretkey] = true;
|
||||||
|
$values['var-value'][$newsecretkey] = base64_encode(file_get_contents($_FILES['privkey']['tmp_name']));
|
||||||
}
|
}
|
||||||
$data['command'] = $values['command'];
|
$data['command'] = $values['command'];
|
||||||
break;
|
break;
|
||||||
|
@ -70,13 +77,27 @@ class Job
|
||||||
if(empty($parsedUrl['host'])) {
|
if(empty($parsedUrl['host'])) {
|
||||||
return ['success' => false, 'message' => 'Some data was invalid'];
|
return ['success' => false, 'message' => 'Some data was invalid'];
|
||||||
}
|
}
|
||||||
|
if(!empty($values['basicauth-password'])) {
|
||||||
|
$newsecretkey = count($values['var-value']);
|
||||||
|
$values['var-id'][$newsecretkey] = 'basicauth-password';
|
||||||
|
$values['var-issecret'][$newsecretkey] = true;
|
||||||
|
$values['var-value'][$newsecretkey] = $values['basicauth-password'];
|
||||||
|
}
|
||||||
$data['host'] = $parsedUrl['host'];
|
$data['host'] = $parsedUrl['host'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($values['secretval'])) {
|
if(!empty($values['var-value'])) {
|
||||||
foreach($values['secretval'] as $key => $name) {
|
foreach($values['var-value'] as $key => $name) {
|
||||||
if(!empty($name)) $data['secrets'][$values['secretid'][$key]] = base64_encode(Secret::encrypt($values['secretval'][$key]));
|
if(!empty($name)) {
|
||||||
|
if(isset($values['var-issecret'][$key])) {
|
||||||
|
$data['vars'][$values['var-id'][$key]]['issecret'] = true;
|
||||||
|
$data['vars'][$values['var-id'][$key]]['value'] = base64_encode(Secret::encrypt($values['var-value'][$key]));
|
||||||
|
} else {
|
||||||
|
$data['vars'][$values['var-id'][$key]]['issecret'] = false;
|
||||||
|
$data['vars'][$values['var-id'][$key]]['value'] = $values['var-value'][$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +116,11 @@ class Job
|
||||||
$jobRslt = $jobStmt->execute([':id' => $id])->fetchAssociative();
|
$jobRslt = $jobStmt->execute([':id' => $id])->fetchAssociative();
|
||||||
|
|
||||||
$jobRslt['data'] = json_decode($jobRslt['data'], true);
|
$jobRslt['data'] = json_decode($jobRslt['data'], true);
|
||||||
if(!empty($jobRslt['data']['secrets'])) {
|
if(!empty($jobRslt['data']['vars'])) {
|
||||||
foreach ($jobRslt['data']['secrets'] as $key => &$value) {
|
foreach ($jobRslt['data']['vars'] as $key => &$value) {
|
||||||
$value = ($withSecrets) ? Secret::decrypt(base64_decode($value)) : '';
|
if ($value['issecret']) {
|
||||||
|
$value['value'] = ($withSecrets) ? Secret::decrypt(base64_decode($value['value'])) : '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,7 @@
|
||||||
|
|
||||||
<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="hidden" name="secretid[]" value="privkey-password">
|
<input type="password" name="privkey-password" class="form-control" placeholder="correct horse battery staple">
|
||||||
<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" 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>
|
||||||
|
@ -107,27 +106,33 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="basicauth-password">Password for Basic-Auth</label>
|
<label for="basicauth-password">Password for Basic-Auth</label>
|
||||||
<input type="hidden" name="secretid[]" value="basicauth-password">
|
<input type="password" name="basicauth-password" class="form-control" placeholder="correct horse battery staple">
|
||||||
<input type="password" name="secretval[]" class="form-control" placeholder="correct horse battery staple">
|
|
||||||
<small id="basicauth-password-help" class="form-text text-muted">This field is being saved as a secret</small>
|
<small id="basicauth-password-help" class="form-text text-muted">This field is being saved as a secret</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>Secrets</h3>
|
<h3>Variables</h3>
|
||||||
<div class="secrets mb-3">
|
<div class="vars mb-3">
|
||||||
<div class="input-group secret-group hidden">
|
<div class="input-group var-group hidden">
|
||||||
<input type="text" name="secretid[]" class="form-control" placeholder="name">
|
<div class="input-group-prepend">
|
||||||
<input type="password" name="secretval[]" class="form-control" placeholder="value">
|
<div class="input-group-text border-right-0">
|
||||||
|
<input type="checkbox" name="var-issecret[0]" class="var-issecret" placeholder="value" value="true">
|
||||||
|
</div>
|
||||||
|
<span class="input-group-text border-left-0">Secret</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" name="var-id[0]" class="form-control var-id" placeholder="name">
|
||||||
|
<input type="text" name="var-value[0]" class="form-control var-value" placeholder="value">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="secrets-description mb-3 hidden">
|
<div class="vars-description mb-3 hidden">
|
||||||
<p>
|
<p>
|
||||||
You can add secrets by using {secret-name} in job details
|
You can add variables by using {variable-name} in job details
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<a href="#" class="btn btn-outline-primary addsecret-btn">Add secret</a>
|
<a href="#" class="btn btn-outline-primary addvar-btn">Add variable</a>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="type" class="crontype" value=""><button type="submit" class="btn btn-outline-primary">Submit</button>
|
<input type="hidden" name="type" class="crontype" value=""><button type="submit" class="btn btn-outline-primary">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue