From b45cfda3eb3e6bf134bb61a14f16ec2f9bd31ecd Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 1 May 2023 15:25:30 +0200 Subject: [PATCH 1/6] [ADIF Backup] Added so that ADIF can be backed up with cron and api key --- application/controllers/Backup.php | 4 ++-- application/models/Adif_data.php | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/application/controllers/Backup.php b/application/controllers/Backup.php index 9859c6ab..00d01193 100644 --- a/application/controllers/Backup.php +++ b/application/controllers/Backup.php @@ -20,14 +20,14 @@ class Backup extends CI_Controller { } /* Gets all QSOs and Dumps them to logbook.adi */ - public function adif(){ + public function adif($key){ $this->load->helper('file'); // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); $this->load->model('adif_data'); - $data['qsos'] = $this->adif_data->export_all(); + $data['qsos'] = $this->adif_data->export_all($key); if ( ! write_file('backup/logbook.adi', $this->load->view('backup/exportall', $data, true))) { diff --git a/application/models/Adif_data.php b/application/models/Adif_data.php index 294bdcf3..4043bc2c 100644 --- a/application/models/Adif_data.php +++ b/application/models/Adif_data.php @@ -2,13 +2,25 @@ class adif_data extends CI_Model { - function export_all() { - $this->load->model('stations'); - $active_station_id = $this->stations->find_active(); + function export_all($api_key = null) { + if ($api_key != null) { + $CI =& get_instance(); + $CI->load->model('api_model'); + if (strpos($this->api_model->access($api_key), 'r') !== false) { + $CI->load->model('logbooks_model'); + $this->api_model->update_last_used($api_key); + $user_id = $this->api_model->key_userid($api_key); + $active_station_logbook = $CI->logbooks_model->find_active_station_logbook_from_userid($user_id); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($active_station_logbook); + } + } else { + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } + $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country'); - $this->db->where($this->config->item('table_name').'.station_id', $active_station_id); $this->db->order_by("COL_TIME_ON", "ASC"); $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->where_in('station_profile.station_id', $logbooks_locations_array); $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif'); $query = $this->db->get($this->config->item('table_name')); From ebe01d938cd37efd6ddbb42e61b98fda8755a772 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 1 May 2023 17:21:20 +0200 Subject: [PATCH 2/6] [ADIF Backup] Added unique name to the backup file. --- application/controllers/Backup.php | 5 ++++- application/views/backup/adif_view.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/application/controllers/Backup.php b/application/controllers/Backup.php index 00d01193..794a6f8c 100644 --- a/application/controllers/Backup.php +++ b/application/controllers/Backup.php @@ -29,7 +29,9 @@ class Backup extends CI_Controller { $data['qsos'] = $this->adif_data->export_all($key); - if ( ! write_file('backup/logbook.adi', $this->load->view('backup/exportall', $data, true))) + $data['filename'] = 'backup/logbook'. date('_Y_m_d_H_i_s') .'.adi'; + + if ( ! write_file($data['filename'], $this->load->view('backup/exportall', $data, true))) { $data['status'] = false; } @@ -39,6 +41,7 @@ class Backup extends CI_Controller { } $data['page_title'] = "ADIF - Backup"; + $this->load->view('interface_assets/header', $data); $this->load->view('backup/adif_view'); diff --git a/application/views/backup/adif_view.php b/application/views/backup/adif_view.php index c5fb651d..d9541203 100644 --- a/application/views/backup/adif_view.php +++ b/application/views/backup/adif_view.php @@ -4,7 +4,7 @@ -

The backup of your log completed successfully. The output can be found at: backup/logbook.adi

+

The backup of your log completed successfully. The output can be found at:

You could automate this process by making it a cronjob.

From efb44b1d65b56544c9d3c88e1f515eb253843587 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 1 May 2023 21:23:30 +0200 Subject: [PATCH 3/6] [ADIF Backup] Fix when running backup from inside Cloudlog --- application/controllers/Backup.php | 2 +- application/models/Adif_data.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/controllers/Backup.php b/application/controllers/Backup.php index 794a6f8c..e73306f7 100644 --- a/application/controllers/Backup.php +++ b/application/controllers/Backup.php @@ -20,7 +20,7 @@ class Backup extends CI_Controller { } /* Gets all QSOs and Dumps them to logbook.adi */ - public function adif($key){ + public function adif($key = null){ $this->load->helper('file'); // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); diff --git a/application/models/Adif_data.php b/application/models/Adif_data.php index 4043bc2c..c01a6103 100644 --- a/application/models/Adif_data.php +++ b/application/models/Adif_data.php @@ -3,11 +3,11 @@ class adif_data extends CI_Model { function export_all($api_key = null) { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); if ($api_key != null) { - $CI =& get_instance(); $CI->load->model('api_model'); if (strpos($this->api_model->access($api_key), 'r') !== false) { - $CI->load->model('logbooks_model'); $this->api_model->update_last_used($api_key); $user_id = $this->api_model->key_userid($api_key); $active_station_logbook = $CI->logbooks_model->find_active_station_logbook_from_userid($user_id); From a7473a44a87df533f7e414711279e13d04a7bcb6 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 1 May 2023 21:31:40 +0200 Subject: [PATCH 4/6] Fix download link --- application/views/backup/adif_view.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/views/backup/adif_view.php b/application/views/backup/adif_view.php index d9541203..00590cfa 100644 --- a/application/views/backup/adif_view.php +++ b/application/views/backup/adif_view.php @@ -4,7 +4,7 @@ -

The backup of your log completed successfully. The output can be found at:

+

The backup of your log completed successfully. The output can be found at:

You could automate this process by making it a cronjob.

@@ -14,4 +14,4 @@ - \ No newline at end of file + From d6529890b2acd17eaf78ee9664a553f4fcc2cb63 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 1 May 2023 21:34:13 +0200 Subject: [PATCH 5/6] Delete stray a tag --- application/views/backup/adif_view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/backup/adif_view.php b/application/views/backup/adif_view.php index 00590cfa..d1ab0fdb 100644 --- a/application/views/backup/adif_view.php +++ b/application/views/backup/adif_view.php @@ -4,7 +4,7 @@ -

The backup of your log completed successfully. The output can be found at:

+

The backup of your log completed successfully. The output can be found at:

You could automate this process by making it a cronjob.

From a2f29c67a41ca98c6e0f947fb7b3203a4c67044c Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 2 May 2023 08:04:21 +0200 Subject: [PATCH 6/6] If no API key is supplied we should check for a valid session and otherwise just redirect to login. --- application/controllers/Backup.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application/controllers/Backup.php b/application/controllers/Backup.php index e73306f7..ba6f928a 100644 --- a/application/controllers/Backup.php +++ b/application/controllers/Backup.php @@ -21,6 +21,11 @@ class Backup extends CI_Controller { /* Gets all QSOs and Dumps them to logbook.adi */ public function adif($key = null){ + if ($key == null) { + $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->helper('file'); // Set memory limit to unlimited to allow heavy usage ini_set('memory_limit', '-1'); @@ -74,4 +79,4 @@ class Backup extends CI_Controller { } } -/* End of file Backup.php */ \ No newline at end of file +/* End of file Backup.php */