From 00c5c548d638c7cee33def28fe8ee5676f878c05 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 24 May 2021 12:28:47 +0200 Subject: [PATCH] More job editing --- public/resources/job/add.js | 4 ++++ src/Repository/Job.php | 44 ++++++++++++++++++++++++++++++++---- templates/job/add.html.twig | 2 +- templates/job/edit.html.twig | 29 ++++++++++++++++-------- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/public/resources/job/add.js b/public/resources/job/add.js index c605f94..82263c2 100644 --- a/public/resources/job/add.js +++ b/public/resources/job/add.js @@ -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() diff --git a/src/Repository/Job.php b/src/Repository/Job.php index f7f429e..7944d4f 100644 --- a/src/Repository/Job.php +++ b/src/Repository/Job.php @@ -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') { } diff --git a/templates/job/add.html.twig b/templates/job/add.html.twig index e91ec98..d5df190 100644 --- a/templates/job/add.html.twig +++ b/templates/job/add.html.twig @@ -177,7 +177,7 @@
- +
diff --git a/templates/job/edit.html.twig b/templates/job/edit.html.twig index 8ce98a4..6a93d00 100644 --- a/templates/job/edit.html.twig +++ b/templates/job/edit.html.twig @@ -112,7 +112,7 @@
- + Delay between triggering reboot and actual reboot
@@ -154,26 +154,35 @@

SSH host details

- +
- +
-
- - +
+
+
+ + +
+ Keep +
+
+ + +
This file is being saved as a secret
- + If private key is empty this field is being used as ssh-password This field is being saved as a secret
@@ -186,12 +195,12 @@

Docker container details

- +
- - + +