From f4b6f899591160177be7bccffe93961fbb1f0016 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Tue, 30 Jul 2024 21:15:16 +0200 Subject: [PATCH] catch case if exec() is not usable --- application/controllers/Debug.php | 95 +++++++++++-------- .../migrations/210_process_deprecated.php | 27 +++--- application/views/debug/index.php | 2 +- .../includes/interface_assets/triggers.php | 3 +- 4 files changed, 70 insertions(+), 57 deletions(-) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index c83e3e6b7..62d9e7d49 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -171,65 +171,78 @@ class Debug extends CI_Controller $stashfile = realpath(APPPATH.'../').'/.updater'; $maintenancefile = realpath(APPPATH.'../').'/.maintenance'; - if (file_exists('.git')) { - try { - // enter maintenance mode - exec('touch '.$maintenancefile); - log_message('debug', 'Updater: Entered Maintenance mode by creating .maintenance file'); + if (function_usable('exec')) { + if (file_exists('.git')) { + try { + // enter maintenance mode + exec('touch '.$maintenancefile); + log_message('debug', 'Updater: Entered Maintenance mode by creating .maintenance file'); - // we need atleast one file which gets stashed. this file should NOT be in .gitignore - exec('touch '.$stashfile); - log_message('debug', 'Updater: Created stashfile'); + // we need atleast one file which gets stashed. this file should NOT be in .gitignore + exec('touch '.$stashfile); + log_message('debug', 'Updater: Created stashfile'); - // stash everything else - exec('git stash push --include-untracked'); - log_message('debug', 'Updater: Stash everything'); + // stash everything else + exec('git stash push --include-untracked'); + log_message('debug', 'Updater: Stash everything'); - // perform the pull - exec('git fetch'); - exec('git pull'); - log_message('debug', 'Updater: git fetch and git pull'); + // perform the pull + exec('git fetch'); + exec('git pull'); + log_message('debug', 'Updater: git fetch and git pull'); - // we can now pop all other changes - exec('git stash pop'); - log_message('debug', 'Updater: Pop stashed changes'); + // we can now pop all other changes + exec('git stash pop'); + log_message('debug', 'Updater: Pop stashed changes'); - // Show success message - $this->session->set_flashdata('success', __("Wavelog was updated successfully!")); - - } catch (\Throwable $th) { - log_message("Error","Error at selfupdating"); + // Show success message + $this->session->set_flashdata('success', __("Wavelog was updated successfully!")); + + } catch (\Throwable $th) { + log_message("Error","Error at selfupdating"); + } } - } - // delete the stash file - if(file_exists($stashfile)) { - exec('rm '.$stashfile); - log_message('debug', 'Updater: Delete stashfile'); - } - // exit maintenance mode - if(file_exists($maintenancefile)) { - exec('rm '.$maintenancefile); - log_message('debug', 'Updater: Delete .maintenance file to exit Maintenance Mode'); + // delete the stash file + if(file_exists($stashfile)) { + exec('rm '.$stashfile); + log_message('debug', 'Updater: Delete stashfile'); + } + // exit maintenance mode + if(file_exists($maintenancefile)) { + exec('rm '.$maintenancefile); + log_message('debug', 'Updater: Delete .maintenance file to exit Maintenance Mode'); + } + } else { + log_message('error', 'function exec() not available. Debug Controller selfupdate()'); + $this->session->set_flashdata('error', __("Selfupdate() not available. Check the Error Log.")); } redirect('debug'); } public function wavelog_fetch() { $a_versions=[]; - try { - $st=exec('git fetch'); // Fetch latest things from Repo. ONLY Fetch. Doesn't hurt since it isn't a pull! - $versions['branch'] = trim(exec('git rev-parse --abbrev-ref HEAD')); // Get ONLY Name of the Branch we're on - $versions['latest_commit_hash']=substr(trim(exec('git log --pretty="%H" -n1 origin'.'/'.$versions['branch'])),0,8); // fetch latest commit-hash from repo - } catch (Exception $e) { - $versions['latest_commit_hash']=''; - $versions['branch']=''; + if (function_usable('exec')) { + try { + $st=exec('git fetch'); // Fetch latest things from Repo. ONLY Fetch. Doesn't hurt since it isn't a pull! + $versions['branch'] = trim(exec('git rev-parse --abbrev-ref HEAD')); // Get ONLY Name of the Branch we're on + $versions['latest_commit_hash']=substr(trim(exec('git log --pretty="%H" -n1 origin'.'/'.$versions['branch'])),0,8); // fetch latest commit-hash from repo + } catch (Exception $e) { + $versions['latest_commit_hash']=''; + $versions['branch']=''; + } + } else { + log_message('error', 'wavelog_fetch() not available. Function exec() not usable.'); } header('Content-Type: application/json'); echo json_encode($versions); } public function wavelog_version() { - $commit_hash=substr(trim(exec('git log --pretty="%H" -n1 HEAD')),0,8); // Get latest LOCAL Hash + if (function_usable('exec')) { + $commit_hash=substr(trim(exec('git log --pretty="%H" -n1 HEAD')),0,8); // Get latest LOCAL Hash + } else { + log_message('error', 'wavelog_version() not available. Function exec() not usable.'); + } header('Content-Type: application/json'); echo json_encode($commit_hash); } diff --git a/application/migrations/210_process_deprecated.php b/application/migrations/210_process_deprecated.php index a276413bf..d1e8c49ae 100644 --- a/application/migrations/210_process_deprecated.php +++ b/application/migrations/210_process_deprecated.php @@ -8,24 +8,25 @@ class Migration_process_deprecated extends CI_Migration if (file_exists('.git')) { try { - if (function_exists('exec')) { - exec('git reset assets/json/dok.txt'); - exec('git reset assets/json/pota.txt'); - exec('git reset assets/resources/sota.txt'); - exec('git reset assets/resources/wwff.txt'); + if (function_usable('exec')) { + exec('git reset assets/json/dok.txt'); + exec('git reset assets/json/pota.txt'); + exec('git reset assets/resources/sota.txt'); + exec('git reset assets/resources/wwff.txt'); - exec('rm assets/json/dok.txt'); - exec('rm assets/json/pota.txt'); - exec('git restore assets/resources/sota.txt'); - exec('git restore assets/resources/wwff.txt'); - } + exec('rm assets/json/dok.txt'); + exec('rm assets/json/pota.txt'); + exec('git restore assets/resources/sota.txt'); + exec('git restore assets/resources/wwff.txt'); + } } catch (\Throwable $th) { - $branch = trim(exec('git rev-parse --abbrev-ref HEAD')); - log_message("Error","Mig: Error at Migrate txt files. Run manually: git reset --hard origin/$branch"); + log_message("Error","Mig: Error at Mig 210 for txt files. Run manually a git reset."); } - } + } else { + log_message("Error","Mig: Error at Mig 210 for txt files. Function exec() not usable. Run manually a git reset."); + } } diff --git a/application/views/debug/index.php b/application/views/debug/index.php index 658073d47..7b46f50da 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -359,7 +359,7 @@ - +