From 0a9ae6b93b7453a1beae2dc5d6ffa4dd17e74942 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 22 Mar 2024 15:50:54 +0000 Subject: [PATCH 1/8] Selfupdater 1st Version --- application/controllers/Debug.php | 290 +++++++++++++++--------------- 1 file changed, 149 insertions(+), 141 deletions(-) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index 0b341f016..6780b1ba7 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -2,176 +2,184 @@ class Debug extends CI_Controller { - function __construct() - { - parent::__construct(); + function __construct() { + parent::__construct(); - $this->load->model('user_model'); - if (!$this->user_model->authorize(2)) { - $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); - redirect('dashboard'); - } + $this->load->model('user_model'); + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } - $this->load->library('Permissions'); - } + $this->load->library('Permissions'); + } - /* User Facing Links to Backup URLs */ - public function index() - { - $this->load->helper('file'); + /* User Facing Links to Backup URLs */ + public function index() { + $this->load->helper('file'); - $this->load->model('MigrationVersion'); - $this->load->model('Logbook_model'); - $this->load->model('Stations'); + $this->load->model('MigrationVersion'); + $this->load->model('Logbook_model'); + $this->load->model('Stations'); - $footerData = []; - $footerData['scripts'] = ['assets/js/sections/debug.js']; + $footerData = []; + $footerData['scripts'] = ['assets/js/sections/debug.js']; - $data['stations'] = $this->Stations->all(); + $data['stations'] = $this->Stations->all(); - $data['qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id(); - if ($data['qsos_with_no_station_id']) { - $data['calls_wo_sid'] = $this->Logbook_model->calls_without_station_id(); - } + $data['qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id(); + if ($data['qsos_with_no_station_id']) { + $data['calls_wo_sid'] = $this->Logbook_model->calls_without_station_id(); + } - $data['migration_version'] = $this->MigrationVersion->getMigrationVersion(); + $data['migration_version'] = $this->MigrationVersion->getMigrationVersion(); - // Test writing to backup folder - $backup_folder = $this->permissions->is_really_writable('backup'); - $data['backup_folder'] = $backup_folder; + // Test writing to backup folder + $backup_folder = $this->permissions->is_really_writable('backup'); + $data['backup_folder'] = $backup_folder; - // Test writing to updates folder - $updates_folder = $this->permissions->is_really_writable('updates'); - $data['updates_folder'] = $updates_folder; + // Test writing to updates folder + $updates_folder = $this->permissions->is_really_writable('updates'); + $data['updates_folder'] = $updates_folder; - // Test writing to uploads folder - $uploads_folder = $this->permissions->is_really_writable('uploads'); - $data['uploads_folder'] = $uploads_folder; + // Test writing to uploads folder + $uploads_folder = $this->permissions->is_really_writable('uploads'); + $data['uploads_folder'] = $uploads_folder; - // Check if userdata config is enabled - $userdata_enabled = $this->config->item('userdata'); - $data['userdata_enabled'] = $userdata_enabled; + // Check if userdata config is enabled + $userdata_enabled = $this->config->item('userdata'); + $data['userdata_enabled'] = $userdata_enabled; - if (isset($userdata_enabled)) { - // Test writing to userdata folder if option is enabled - $userdata_folder = $this->permissions->is_really_writable('userdata'); - $data['userdata_folder'] = $userdata_folder; + if (isset($userdata_enabled)) { + // Test writing to userdata folder if option is enabled + $userdata_folder = $this->permissions->is_really_writable('userdata'); + $data['userdata_folder'] = $userdata_folder; - // run the status check and return the array to the view - $userdata_status = $this->check_userdata_status($userdata_folder); - $data['userdata_status'] = $userdata_status; - } + // run the status check and return the array to the view + $userdata_status = $this->check_userdata_status($userdata_folder); + $data['userdata_status'] = $userdata_status; + } - $data['page_title'] = "Debug"; + $data['page_title'] = "Debug"; - $this->load->view('interface_assets/header', $data); - $this->load->view('debug/index'); - $this->load->view('interface_assets/footer', $footerData); - } + $this->load->view('interface_assets/header', $data); + $this->load->view('debug/index'); + $this->load->view('interface_assets/footer', $footerData); + } - function check_userdata_status($userdata_folder) - { - $this->load->model('debug_model'); - - $status = array(); + function check_userdata_status($userdata_folder) { + $this->load->model('debug_model'); - // Check if the folder is writable - if ($userdata_folder === true) { + $status = array(); - // Check if the qsl and eqsl folders are accessible and if there is any data the user could migrate - $qsl_dir = $this->permissions->is_really_writable('assets/qslcard'); - $eqsl_dir = $this->permissions->is_really_writable('images/eqsl_card_images'); + // Check if the folder is writable + if ($userdata_folder === true) { - $flag_file = $this->debug_model->check_migrated_flag(); + // Check if the qsl and eqsl folders are accessible and if there is any data the user could migrate + $qsl_dir = $this->permissions->is_really_writable('assets/qslcard'); + $eqsl_dir = $this->permissions->is_really_writable('images/eqsl_card_images'); - if ($qsl_dir && $eqsl_dir) { + $flag_file = $this->debug_model->check_migrated_flag(); - // Check for content of the qsl card folder other than *.html files - $qsl_files = glob('assets/qslcard/*'); - $qsl_files_filtered = array_filter($qsl_files, function ($file) { - return !is_dir($file) && pathinfo($file, PATHINFO_EXTENSION) !== 'html'; - }); + if ($qsl_dir && $eqsl_dir) { - // Check for content of the eqsl card folder other than *.html files - $eqsl_files = glob('images/eqsl_card_images/*'); - $eqsl_files_filtered = array_filter($eqsl_files, function ($file) { - return !is_dir($file) && pathinfo($file, PATHINFO_EXTENSION) !== 'html'; - }); + // Check for content of the qsl card folder other than *.html files + $qsl_files = glob('assets/qslcard/*'); + $qsl_files_filtered = array_filter($qsl_files, function ($file) { + return !is_dir($file) && pathinfo($file, PATHINFO_EXTENSION) !== 'html'; + }); - // Set the status info - if (!empty($qsl_files_filtered) || !empty($eqsl_files_filtered)) { - if (!$flag_file) { - $status['btn_class'] = ''; - $status['btn_text'] = 'Migrate data now'; - } else { - $status['btn_class'] = ''; - $status['btn_text'] = 'Migration already done. Run again?'; - } - } else { - $status['btn_class'] = 'disabled'; - $status['btn_text'] = 'No data to migrate'; - } - } else { - $status['btn_class'] = 'disabled'; - $status['btn_text'] = 'No migration possible'; - } - } else { - // If the folder is not writable, we don't need to continue - $status['btn_class'] = 'disabled'; - $status['btn_text'] = 'No migration possible'; - } + // Check for content of the eqsl card folder other than *.html files + $eqsl_files = glob('images/eqsl_card_images/*'); + $eqsl_files_filtered = array_filter($eqsl_files, function ($file) { + return !is_dir($file) && pathinfo($file, PATHINFO_EXTENSION) !== 'html'; + }); - return $status; - } + // Set the status info + if (!empty($qsl_files_filtered) || !empty($eqsl_files_filtered)) { + if (!$flag_file) { + $status['btn_class'] = ''; + $status['btn_text'] = 'Migrate data now'; + } else { + $status['btn_class'] = ''; + $status['btn_text'] = 'Migration already done. Run again?'; + } + } else { + $status['btn_class'] = 'disabled'; + $status['btn_text'] = 'No data to migrate'; + } + } else { + $status['btn_class'] = 'disabled'; + $status['btn_text'] = 'No migration possible'; + } + } else { + // If the folder is not writable, we don't need to continue + $status['btn_class'] = 'disabled'; + $status['btn_text'] = 'No migration possible'; + } - public function reassign() - { - $this->load->model('Logbook_model'); - $this->load->model('Stations'); + return $status; + } - $call = xss_clean(($this->input->post('call'))); - $qsoids = xss_clean(($this->input->post('qsoids'))); - $station_profile_id = xss_clean(($this->input->post('station_id'))); + public function reassign() { + $this->load->model('Logbook_model'); + $this->load->model('Stations'); - log_message('debug', 'station_profile_id:', $station_profile_id); - // Check if target-station-id exists - $allowed = false; - $status = false; - $stations = $this->Stations->all(); - foreach ($stations->result() as $station) { - if ($station->station_id == $station_profile_id) { - $allowed = true; - } - } - if ($allowed) { - $status = $this->Logbook_model->update_station_ids($station_profile_id, $call, $qsoids); - } else { - $status = false; - } + $call = xss_clean(($this->input->post('call'))); + $qsoids = xss_clean(($this->input->post('qsoids'))); + $station_profile_id = xss_clean(($this->input->post('station_id'))); - header('Content-Type: application/json'); - echo json_encode(array('status' => $status)); - return; - } + log_message('debug', 'station_profile_id:', $station_profile_id); + // Check if target-station-id exists + $allowed = false; + $status = false; + $stations = $this->Stations->all(); + foreach ($stations->result() as $station) { + if ($station->station_id == $station_profile_id) { + $allowed = true; + } + } + if ($allowed) { + $status = $this->Logbook_model->update_station_ids($station_profile_id, $call, $qsoids); + } else { + $status = false; + } - public function migrate_userdata() - { - // Check if users logged in - $this->load->model('user_model'); - if ($this->user_model->validate_session() == 0) { - // user is not logged in - redirect('user/login'); - } else { - $this->load->model('debug_model'); - $migrate = $this->debug_model->migrate_userdata(); + header('Content-Type: application/json'); + echo json_encode(array('status' => $status)); + return; + } - if ($migrate == true) { - $this->session->set_flashdata('success', 'File Migration was successfull, but please check also manually. If everything seems right you can delete the folders "assets/qslcard" and "images/eqsl_card_images".'); - redirect('debug'); - } else { - $this->session->set_flashdata('error', 'File Migration failed. Please check the Error Log.'); - redirect('debug'); - } - } - } + public function selfupdate() { + if (file_exists('.git')) { + try { + $st=exec('git stash push --include-untracked'); + $st=exec('git pull --rebase'); + $st=exec('git stash pop'); + } catch (\Throwable $th) { + } + } + redirect('debug'); + } + + + public function migrate_userdata() { + // Check if users logged in + $this->load->model('user_model'); + if ($this->user_model->validate_session() == 0) { + // user is not logged in + redirect('user/login'); + } else { + $this->load->model('debug_model'); + $migrate = $this->debug_model->migrate_userdata(); + + if ($migrate == true) { + $this->session->set_flashdata('success', 'File Migration was successfull, but please check also manually. If everything seems right you can delete the folders "assets/qslcard" and "images/eqsl_card_images".'); + redirect('debug'); + } else { + $this->session->set_flashdata('error', 'File Migration failed. Please check the Error Log.'); + redirect('debug'); + } + } + } } From 2418b08a499338fc9d5d03142385b104b09f1ca2 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 22 Mar 2024 15:58:51 +0000 Subject: [PATCH 2/8] Added Button for selfupdate --- application/views/debug/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/views/debug/index.php b/application/views/debug/index.php index dba2c7f92..08857ad08 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -289,6 +289,10 @@ format(\DateTime::RFC850)); ?> + + Update Wavelog + Update + @@ -456,4 +460,4 @@ - \ No newline at end of file + From 815905fce6d1349dfd0576dc681e99112c6fe785 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 22 Mar 2024 16:12:23 +0000 Subject: [PATCH 3/8] Added Maintenance-Mode for updating --- application/controllers/Debug.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index 6780b1ba7..c3afa7b6b 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -153,9 +153,11 @@ class Debug extends CI_Controller public function selfupdate() { if (file_exists('.git')) { try { + $st=exec('touch ./.maintenance'); $st=exec('git stash push --include-untracked'); $st=exec('git pull --rebase'); $st=exec('git stash pop'); + $st=exec('rm ./.maintenance'); } catch (\Throwable $th) { } } From 1b9c4f8f796e4779dac036b75b2d4ea163cc94c9 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 22 Mar 2024 16:47:33 +0000 Subject: [PATCH 4/8] Disable Button while selfupgrading --- application/views/debug/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/debug/index.php b/application/views/debug/index.php index 08857ad08..8be457921 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -291,7 +291,7 @@ Update Wavelog - Update + Update From 47acab82d980903e43972c6dea28bde43b334756 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sat, 23 Mar 2024 06:03:03 +0000 Subject: [PATCH 5/8] use realpath for files --- application/controllers/Debug.php | 6 +++--- application/views/debug/index.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index c3afa7b6b..ac7fa568a 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -153,11 +153,11 @@ class Debug extends CI_Controller public function selfupdate() { if (file_exists('.git')) { try { - $st=exec('touch ./.maintenance'); + $st=exec('touch '.realpath(APPPATH.'../').'/.maintenance'); $st=exec('git stash push --include-untracked'); - $st=exec('git pull --rebase'); + $st=exec('git pull'); $st=exec('git stash pop'); - $st=exec('rm ./.maintenance'); + $st=exec('rm '.realpath(APPPATH.'../').'/.maintenance'); } catch (\Throwable $th) { } } diff --git a/application/views/debug/index.php b/application/views/debug/index.php index 8be457921..9262228cb 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -204,7 +204,7 @@ - + Date: Sat, 23 Mar 2024 06:10:46 +0000 Subject: [PATCH 6/8] Add a git fetch before pull. otherwise "FETCH_HEAD" is non-existant --- application/controllers/Debug.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index ac7fa568a..58b3f6fa3 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -155,6 +155,7 @@ class Debug extends CI_Controller try { $st=exec('touch '.realpath(APPPATH.'../').'/.maintenance'); $st=exec('git stash push --include-untracked'); + $st=exec('git fetch'); $st=exec('git pull'); $st=exec('git stash pop'); $st=exec('rm '.realpath(APPPATH.'../').'/.maintenance'); From 0d6d6d6eaa41a14097ec2484fb99a06068f7999d Mon Sep 17 00:00:00 2001 From: int2001 Date: Sat, 23 Mar 2024 06:24:14 +0000 Subject: [PATCH 7/8] Added uploads to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 27c58390c..01d66723d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /application/config/config.php /application/logs/*.php /application/cache/* +/uploads /uploads/*.adi /uploads/*.ADI /uploads/*.tq8 From 936a44fa984edc7cf35af17fb70ed5e5f845b8f0 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sat, 23 Mar 2024 06:30:30 +0000 Subject: [PATCH 8/8] Added Error --- application/controllers/Debug.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index 58b3f6fa3..f36a9864b 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -160,6 +160,7 @@ class Debug extends CI_Controller $st=exec('git stash pop'); $st=exec('rm '.realpath(APPPATH.'../').'/.maintenance'); } catch (\Throwable $th) { + log_message("Error","Error at selfupdating"); } } redirect('debug');