From 042475a989ae2b1543adf1ec6541085f6d3dfddd Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 25 Aug 2020 17:50:52 +0100 Subject: [PATCH] ADIF Export for LOTW ready for signing --- application/controllers/Lotw.php | 16 ++- application/models/Logbook_model.php | 15 ++- .../lotw_views/adif_views/adif_export.php | 109 +++++++++++++++++- 3 files changed, 132 insertions(+), 8 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 24da35e3..a775dced 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -162,6 +162,12 @@ class Lotw extends CI_Controller { $this->load->model('Dxcc'); $data['station_profile_dxcc'] = $this->Dxcc->lookup_country($data['lotw_cert_info']->cert_dxcc); + // Get QSOs + + $this->load->model('Logbook_model'); + + $data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id); + $this->load->view('lotw_views/adif_views/adif_export', $data); } } else { @@ -626,13 +632,13 @@ class Lotw extends CI_Controller { } - function signlog() { + function signlog($sign_key, $string) { - $qso_string = "14IO87IPEU-0052770CM2MG0IIQ435.355562145.878136FMSAT2020-08-1212:10:53ZAO-92"; + $qso_string = $string; - $key = ""; + $key = $sign_key; - $pkeyid = openssl_pkey_get_private($key, 'peter'); + $pkeyid = openssl_pkey_get_private($key, 'cloudlog'); //openssl_sign($plaintext, $signature, $pkeyid, OPENSSL_ALGO_SHA1 ); //openssl_free_key($pkeyid); @@ -640,7 +646,7 @@ class Lotw extends CI_Controller { if(openssl_sign($qso_string, $signature, $pkeyid, OPENSSL_ALGO_SHA1)) { openssl_free_key($pkeyid); $signature_b64 = base64_encode($signature); - echo($signature_b64."\n"); + return $signature_b64; } diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ed5ff151..0825c732 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2157,7 +2157,20 @@ class Logbook_model extends CI_Model { return null; } } - + + function get_lotw_qsos_to_upload($station_id) { + + $this->db->select('COL_CALL, COL_BAND, COL_BAND_RX, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_FREQ, COL_FREQ_RX, COL_GRIDSQUARE, COL_SAT_NAME, COL_PROP_MODE'); + + $this->db->where("station_id", 1); + + $this->db->order_by("COL_TIME_ON", "desc"); + $this->db->limit(1); + $query = $this->db->get($this->config->item('table_name')); + + return $query; + } + } function validateADIFDate($date, $format = 'Ymd') diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index efc3edff..d0520a14 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -1,11 +1,16 @@ +cert_key); +$cert2 = str_replace("-----END ENCRYPTED PRIVATE KEY-----", "", $cert1); +?> TQSL V2.5.4 Lib: V2.5 Config: V11.12 AllowDupes: false tCERT 1 -cert_key); ?>>cert_key; ?> +> + tSTATION @@ -23,4 +28,104 @@ station_iota)) { ?>station_iota); ?>>station_iota; ?> - \ No newline at end of file + + +result() as $qso) { ?> +tCONTACT +1 +COL_CALL); ?>>COL_CALL; ?> + +COL_BAND); ?>>COL_BAND); ?> + +COL_MODE); ?>>COL_MODE); ?> + +COL_FREQ != "0") { ?>COL_FREQ / 1000000; ?>> + +COL_FREQ_RX) { ?>COL_FREQ_RX / 1000000; ?>> + +COL_PROP_MODE); ?>>COL_PROP_MODE); ?> + +COL_SAT_NAME); ?>>COL_SAT_NAME); ?> + +COL_BAND_RX) { ?>COL_BAND_RX); ?>>COL_BAND_RX); ?> + +COL_TIME_ON); $new_date = date('Y-m-d', $date_on); ?> +> + +COL_TIME_ON); $new_on = date('H:i:s', $time_on); ?> +> + +station_cq) { + $sign_string .= $station_profile->station_cq; +} + +// Add Gridsquare +if($station_profile->station_gridsquare) { + $sign_string .= strtoupper($station_profile->station_gridsquare); +} + +if($station_profile->station_iota) { + $sign_string .= strtoupper($station_profile->station_iota); +} + +if($station_profile->station_itu) { + $sign_string .= $station_profile->station_itu; +} + +if($qso->COL_BAND) { + $sign_string .= strtoupper($qso->COL_BAND); +} + +if($qso->COL_BAND_RX) { + $sign_string .= strtoupper($qso->COL_BAND_RX); +} + +if($qso->COL_CALL) { + $sign_string .= strtoupper($qso->COL_CALL); +} + +if($freq_in_mhz) { + $sign_string .= strtoupper($freq_in_mhz); +} + +if($freq_in_mhz_rx) { + $sign_string .= strtoupper($freq_in_mhz_rx); +} + +if($qso->COL_MODE) { + $sign_string .= strtoupper($qso->COL_MODE); +} + + +if($qso->COL_PROP_MODE) { + $sign_string .= strtoupper($qso->COL_PROP_MODE); +} + +$sign_string .= $new_date; + +$sign_string .= $new_on."Z"; + +if($qso->COL_SAT_NAME) { + $sign_string .= strtoupper($qso->COL_SAT_NAME); +} + + ?> +signlog($lotw_cert_info->cert_key, $sign_string); + +?> +:6> + +> + + + + +