From eedc38f57cb6b455b19033888038bc1a57ddbd8b Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 10 Oct 2025 15:43:59 +0200 Subject: [PATCH 1/5] Refactor LoTW signing code --- .../lotw_views/adif_views/adif_export.php | 170 +++++++++--------- 1 file changed, 83 insertions(+), 87 deletions(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 3198070c9..96f45fd6f 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -4,92 +4,85 @@ $clean_cert = trim($lotw_cert_info->cert); $cert1 = str_replace("-----BEGIN CERTIFICATE-----", "", $clean_cert); $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); ?> -TQSL V2.8.1 Lib: V2.6 Config: V11.34 AllowDupes: false +TQSL V2.8.2 Lib: V2.6 Config: V11.34 AllowDupes: false tCERT 1 > - + tSTATION 1 1 -callsign); ?>>callsign; ?> - -cert_dxcc_id); ?>>cert_dxcc_id; ?> - -station_gridsquare) { ?>station_gridsquare); ?>>station_gridsquare; } ?> - -station_itu) { ?>station_itu); ?>>station_itu; } ?> - -station_cq) { ?>station_cq); ?>>station_cq; } ?> - -station_iota) { ?>station_iota); ?>>station_iota; } ?> - cert_dxcc_id) { +print "callsign).">".$lotw_cert_info->callsign."\n"; +print "cert_dxcc_id).">".$lotw_cert_info->cert_dxcc_id."\n"; +if($station_profile->station_gridsquare) { + print "station_gridsquare).">".$station_profile->station_gridsquare."\n"; +} +if($station_profile->station_itu) { + print "station_itu).">".$station_profile->station_itu."\n"; +} +if($station_profile->station_cq) { + print "station_cq).">".$station_profile->station_cq."\n"; +} +if($station_profile->station_iota) { + print "station_iota).">".$station_profile->station_iota."\n"; +} + +switch ($lotw_cert_info->cert_dxcc_id) { case 6: // Alaska case 110: // Hawaii case 291: // Cont US - if($station_profile->state != "") { ?> -state); ?>>state; ?> - -station_cnty != "") { ?> -station_cnty); ?>>station_cnty; ?> - -state != "") { + print "state).">".$station_profile->state."\n"; + } + if($station_profile->station_cnty != "") { + print "station_cnty).">".$station_profile->station_cnty."\n"; + } break; case 1: // Canada - if($station_profile->state != "") { ?> -lotw_ca_province_map($station_profile->state)); ?>>lotw_ca_province_map($station_profile->state); ?> - - state != "") { + print "lotw_ca_province_map($station_profile->state)).">".$CI->lotw_ca_province_map($station_profile->state)."\n"; + } break; case 15: // Asiatic Russia case 54: // European Russia case 61: // FJL case 125: // Juan Fernandez case 151: // Malyj Vysotskij - if($station_profile->state != "") { ?> -lotw_ru_oblast_map($station_profile->state)); ?>>lotw_ru_oblast_map($station_profile->state); ?> - - state != "") { + print "lotw_ru_oblast_map($station_profile->state)).">".$CI->lotw_ru_oblast_map($station_profile->state)."\n"; + } break; case 318: // China - if($station_profile->state != "") { ?> -state); ?>>state; ?> - - state != "") { + print "state).">".$station_profile->state."\n"; + } break; case 150: // Australia - if($station_profile->state != "") { ?> -state); ?>>state; ?> - - state != "") { + print "state).">".$station_profile->state."\n"; + } break; case 339: // Japan - if($station_profile->state != "") { ?> -state); ?>>state; ?> - -station_cnty != "") { ?> -station_cnty); ?>>station_cnty; ?> - -state != "") { + print "state).">".$station_profile->state."\n"; + } + if($station_profile->station_cnty != "") { + print "station_cnty).">".$station_profile->station_cnty."\n"; + } break; case 5: // Aland Island case 224: // Finland - if($station_profile->state != "") { ?> -state); ?>>state; ?> - - state != "") { + print "state).">".$station_profile->state."\n"; + } break; } ?> - - + result() as $qso) { unset($freq_in_mhz); @@ -97,30 +90,33 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); ?> tCONTACT 1 -COL_CALL); ?>>COL_CALL; ?> - -COL_BAND); ?>>COL_BAND); ?> - -mode_map($qso->COL_MODE, $qso->COL_SUBMODE)); ?>>mode_map(($qso->COL_MODE == null ? '' : strtoupper($qso->COL_MODE)), ($qso->COL_SUBMODE == null ? '' : strtoupper($qso->COL_SUBMODE)))); ?> - -COL_FREQ != "" && $qso->COL_FREQ != "0") { $freq_in_mhz = $qso->COL_FREQ / 1000000; ?>> - -COL_FREQ_RX != "" && $qso->COL_FREQ_RX != "0") { $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; ?>> - -COL_PROP_MODE) { ?>COL_PROP_MODE); ?>>COL_PROP_MODE); } ?> - -COL_SAT_NAME) { ?>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); ?> -> - -COL_CALL).">".$qso->COL_CALL."\n"; +print "COL_BAND).">".strtoupper($qso->COL_BAND)."\n"; +print "mode_map($qso->COL_MODE, $qso->COL_SUBMODE)).">".strtoupper($CI->mode_map(($qso->COL_MODE == null ? '' : strtoupper($qso->COL_MODE)), ($qso->COL_SUBMODE == null ? '' : strtoupper($qso->COL_SUBMODE))))."\n"; +if($qso->COL_FREQ != "" && $qso->COL_FREQ != "0") { + $freq_in_mhz = $qso->COL_FREQ / 1000000; + print "".$freq_in_mhz."\n"; +} +if($qso->COL_FREQ_RX != "" && $qso->COL_FREQ_RX != "0") { + $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; + print "".$freq_in_mhz_rx."\n"; +} +if($qso->COL_PROP_MODE) { + print "COL_PROP_MODE).">".strtoupper($qso->COL_PROP_MODE)."\n"; +} +if($qso->COL_SAT_NAME) { + print "COL_SAT_NAME).">".strtoupper($qso->COL_SAT_NAME)."\n"; +} +if($qso->COL_BAND_RX) { + print "COL_BAND_RX).">".strtoupper($qso->COL_BAND_RX)."\n"; +} +$date_on = strtotime($qso->COL_TIME_ON); +$new_date = date('Y-m-d', $date_on); +print "".$new_date."\n"; +$time_on = strtotime($qso->COL_TIME_ON); +$new_on = date('H:i:s', $time_on); +print "".$new_on."Z\n"; $sign_string = ""; @@ -200,27 +196,27 @@ if($qso->COL_MODE) { $sign_string .= strtoupper($CI->mode_map($qso->COL_MODE, $qso->COL_SUBMODE)); } - 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); +$signed_item = $CI->signlog($lotw_cert_info->cert_key, $sign_string); +print ""; +for ($i=0; $i".$sign_string."\n"; ?> -:6> - -> - - + From 88b191185efaf1511a7c17b94039aa2476ae1acd Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 10 Oct 2025 16:02:11 +0200 Subject: [PATCH 2/5] Calc length of signature correctly --- application/views/lotw_views/adif_views/adif_export.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 96f45fd6f..e56d2ac31 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -207,8 +207,8 @@ if($qso->COL_SAT_NAME) { $sign_string .= strtoupper($qso->COL_SAT_NAME); } -$signed_item = $CI->signlog($lotw_cert_info->cert_key, $sign_string); -print ""; +$signed_item = trim($CI->signlog($lotw_cert_info->cert_key, $sign_string)); +print ""; for ($i=0; $i Date: Fri, 10 Oct 2025 16:48:52 +0200 Subject: [PATCH 3/5] Add other signing stuff and optimize re strtoupper --- .../lotw_views/adif_views/adif_export.php | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index e56d2ac31..67e4801e7 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -120,14 +120,22 @@ print "".$new_on."Z\n"; $sign_string = ""; -// Adds CA Province -if($station_profile->state != "" && $station_profile->station_country == "CANADA") { - $sign_string .= strtoupper($CI->lotw_ca_province_map($station_profile->state)); +if ($lotw_cert_info->cert_dxcc_id == 150) { // If state is Australia add AU state + if($station_profile->state != "") { + $sign_string .= $station_profile->state; + } } -// Adds CN Province -if($station_profile->state != "" && $station_profile->station_country == "CHINA") { - $sign_string .= strtoupper($station_profile->state); +if ($lotw_cert_info->cert_dxcc_id == 1) { // If state is Canada add CA province + if($station_profile->state != "") { + $sign_string .= $CI->lotw_ca_province_map($station_profile->state); + } +} + +if ($lotw_cert_info->cert_dxcc_id == 318) { // If state is China add CN province + if($station_profile->state != "") { + $sign_string .= $station_profile->state; + } } // Add CQ Zone @@ -135,86 +143,88 @@ if($station_profile->station_cq) { $sign_string .= $station_profile->station_cq; } +if ($lotw_cert_info->cert_dxcc_id == 224) { // If state is Finland add FI kunta + $sign_string .= $station_profile->state; +} + // Add Gridsquare if($station_profile->station_gridsquare) { - $sign_string .= strtoupper($station_profile->station_gridsquare); + $sign_string .= $station_profile->station_gridsquare; } if($station_profile->station_iota) { - $sign_string .= strtoupper($station_profile->station_iota); + $sign_string .= $station_profile->station_iota; } if($station_profile->station_itu) { $sign_string .= $station_profile->station_itu; } -if($station_profile->station_cnty != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") { - $sign_string .= strtoupper($station_profile->station_cnty); +if ($lotw_cert_info->cert_dxcc_id == 339) { // If state is Japan add JA city/gun/ku and prefecture + if($station_profile->station_cnty != "") { + $sign_string .= $station_profile->station_cnty; + } + if($station_profile->state != "") { + $sign_string .= $station_profile->state; + } } -if($station_profile->station_cnty != "" && $station_profile->station_country == "ALASKA") { - $sign_string .= strtoupper($station_profile->station_cnty); +if (in_array($lotw_cert_info->cert_dxcc_id, array(15, 54, 61, 125, 151))) { // If state is Russia add RU oblast + $sign_string .= $CI->lotw_ru_oblast_map($station_profile->state); } -if($station_profile->station_cnty != "" && $station_profile->station_country == "HAWAII") { - $sign_string .= strtoupper($station_profile->station_cnty); -} - -if($station_profile->state != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") { - $sign_string .= strtoupper($station_profile->state); -} - -if($station_profile->state != "" && $station_profile->station_country == "ALASKA") { - $sign_string .= strtoupper($station_profile->state); -} - -if($station_profile->state != "" && $station_profile->station_country == "HAWAII") { - $sign_string .= strtoupper($station_profile->state); +if (in_array($lotw_cert_info->cert_dxcc_id, array(6, 110, 291))) { // If state is US, Alaska or Hawaii add US cnty and state + if($station_profile->station_cnty != "") { + $sign_string .= $station_profile->station_cnty; + } + if($station_profile->state != "") { + $sign_string .= $station_profile->state; + } } if($qso->COL_BAND) { - $sign_string .= strtoupper($qso->COL_BAND); + $sign_string .= $qso->COL_BAND; } if($qso->COL_BAND_RX) { - $sign_string .= strtoupper($qso->COL_BAND_RX); + $sign_string .= $qso->COL_BAND_RX; } if($qso->COL_CALL) { - $sign_string .= strtoupper($qso->COL_CALL); + $sign_string .= $qso->COL_CALL; } if(isset($freq_in_mhz)) { - $sign_string .= strtoupper($freq_in_mhz); + $sign_string .= $freq_in_mhz; } if(isset($freq_in_mhz_rx)) { - $sign_string .= strtoupper($freq_in_mhz_rx); + $sign_string .= $freq_in_mhz_rx; } if($qso->COL_MODE) { - $sign_string .= strtoupper($CI->mode_map($qso->COL_MODE, $qso->COL_SUBMODE)); + $sign_string .= $CI->mode_map($qso->COL_MODE, $qso->COL_SUBMODE); } if($qso->COL_PROP_MODE) { - $sign_string .= strtoupper($qso->COL_PROP_MODE); + $sign_string .= $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); + $sign_string .= $qso->COL_SAT_NAME; } +$sign_string = strtoupper($sign_string); + $signed_item = trim($CI->signlog($lotw_cert_info->cert_key, $sign_string)); print ""; for ($i=0; $i".$sign_string."\n"; ?> From 921114205f438bef51d02c6d8a3ea37ef8bfbfda Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 10 Oct 2025 16:54:26 +0200 Subject: [PATCH 4/5] Some code beauty and more checks for empty values --- .../lotw_views/adif_views/adif_export.php | 132 +++++++++--------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 67e4801e7..17c86cbdb 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -19,68 +19,68 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); print "callsign).">".$lotw_cert_info->callsign."\n"; print "cert_dxcc_id).">".$lotw_cert_info->cert_dxcc_id."\n"; if($station_profile->station_gridsquare) { - print "station_gridsquare).">".$station_profile->station_gridsquare."\n"; + print "station_gridsquare).">".$station_profile->station_gridsquare."\n"; } if($station_profile->station_itu) { - print "station_itu).">".$station_profile->station_itu."\n"; + print "station_itu).">".$station_profile->station_itu."\n"; } if($station_profile->station_cq) { - print "station_cq).">".$station_profile->station_cq."\n"; + print "station_cq).">".$station_profile->station_cq."\n"; } if($station_profile->station_iota) { - print "station_iota).">".$station_profile->station_iota."\n"; + print "station_iota).">".$station_profile->station_iota."\n"; } switch ($lotw_cert_info->cert_dxcc_id) { - case 6: // Alaska - case 110: // Hawaii - case 291: // Cont US - if($station_profile->state != "") { - print "state).">".$station_profile->state."\n"; - } - if($station_profile->station_cnty != "") { - print "station_cnty).">".$station_profile->station_cnty."\n"; - } - break; - case 1: // Canada - if($station_profile->state != "") { - print "lotw_ca_province_map($station_profile->state)).">".$CI->lotw_ca_province_map($station_profile->state)."\n"; - } - break; - case 15: // Asiatic Russia - case 54: // European Russia - case 61: // FJL - case 125: // Juan Fernandez - case 151: // Malyj Vysotskij - if($station_profile->state != "") { - print "lotw_ru_oblast_map($station_profile->state)).">".$CI->lotw_ru_oblast_map($station_profile->state)."\n"; - } - break; - case 318: // China - if($station_profile->state != "") { - print "state).">".$station_profile->state."\n"; - } - break; - case 150: // Australia - if($station_profile->state != "") { - print "state).">".$station_profile->state."\n"; - } - break; - case 339: // Japan - if($station_profile->state != "") { - print "state).">".$station_profile->state."\n"; - } - if($station_profile->station_cnty != "") { - print "station_cnty).">".$station_profile->station_cnty."\n"; - } - break; - case 5: // Aland Island - case 224: // Finland - if($station_profile->state != "") { - print "state).">".$station_profile->state."\n"; - } - break; - } + case 6: // Alaska + case 110: // Hawaii + case 291: // Cont US + if($station_profile->state != "") { + print "state).">".$station_profile->state."\n"; + } + if($station_profile->station_cnty != "") { + print "station_cnty).">".$station_profile->station_cnty."\n"; + } + break; + case 1: // Canada + if($station_profile->state != "") { + print "lotw_ca_province_map($station_profile->state)).">".$CI->lotw_ca_province_map($station_profile->state)."\n"; + } + break; + case 15: // Asiatic Russia + case 54: // European Russia + case 61: // FJL + case 125: // Juan Fernandez + case 151: // Malyj Vysotskij + if($station_profile->state != "") { + print "lotw_ru_oblast_map($station_profile->state)).">".$CI->lotw_ru_oblast_map($station_profile->state)."\n"; + } + break; + case 318: // China + if($station_profile->state != "") { + print "state).">".$station_profile->state."\n"; + } + break; + case 150: // Australia + if($station_profile->state != "") { + print "state).">".$station_profile->state."\n"; + } + break; + case 339: // Japan + if($station_profile->state != "") { + print "state).">".$station_profile->state."\n"; + } + if($station_profile->station_cnty != "") { + print "station_cnty).">".$station_profile->station_cnty."\n"; + } + break; + case 5: // Aland Island + case 224: // Finland + if($station_profile->state != "") { + print "state).">".$station_profile->state."\n"; + } + break; +} ?> @@ -95,21 +95,21 @@ print "COL_CALL).">".$qso->COL_CALL."\n"; print "COL_BAND).">".strtoupper($qso->COL_BAND)."\n"; print "mode_map($qso->COL_MODE, $qso->COL_SUBMODE)).">".strtoupper($CI->mode_map(($qso->COL_MODE == null ? '' : strtoupper($qso->COL_MODE)), ($qso->COL_SUBMODE == null ? '' : strtoupper($qso->COL_SUBMODE))))."\n"; if($qso->COL_FREQ != "" && $qso->COL_FREQ != "0") { - $freq_in_mhz = $qso->COL_FREQ / 1000000; - print "".$freq_in_mhz."\n"; + $freq_in_mhz = $qso->COL_FREQ / 1000000; + print "".$freq_in_mhz."\n"; } if($qso->COL_FREQ_RX != "" && $qso->COL_FREQ_RX != "0") { - $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; - print "".$freq_in_mhz_rx."\n"; + $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; + print "".$freq_in_mhz_rx."\n"; } if($qso->COL_PROP_MODE) { - print "COL_PROP_MODE).">".strtoupper($qso->COL_PROP_MODE)."\n"; + print "COL_PROP_MODE).">".strtoupper($qso->COL_PROP_MODE)."\n"; } if($qso->COL_SAT_NAME) { - print "COL_SAT_NAME).">".strtoupper($qso->COL_SAT_NAME)."\n"; + print "COL_SAT_NAME).">".strtoupper($qso->COL_SAT_NAME)."\n"; } if($qso->COL_BAND_RX) { - print "COL_BAND_RX).">".strtoupper($qso->COL_BAND_RX)."\n"; + print "COL_BAND_RX).">".strtoupper($qso->COL_BAND_RX)."\n"; } $date_on = strtotime($qso->COL_TIME_ON); $new_date = date('Y-m-d', $date_on); @@ -143,8 +143,10 @@ if($station_profile->station_cq) { $sign_string .= $station_profile->station_cq; } -if ($lotw_cert_info->cert_dxcc_id == 224) { // If state is Finland add FI kunta - $sign_string .= $station_profile->state; +if (in_array($lotw_cert_info->cert_dxcc_id, array(5, 224))) { // If state is Finland add FI kunta + if($station_profile->state != "") { + $sign_string .= $station_profile->state; + } } // Add Gridsquare @@ -170,7 +172,9 @@ if ($lotw_cert_info->cert_dxcc_id == 339) { // If state is Japan add JA city/gun } if (in_array($lotw_cert_info->cert_dxcc_id, array(15, 54, 61, 125, 151))) { // If state is Russia add RU oblast - $sign_string .= $CI->lotw_ru_oblast_map($station_profile->state); + if($station_profile->state != "") { + $sign_string .= $CI->lotw_ru_oblast_map($station_profile->state); + } } if (in_array($lotw_cert_info->cert_dxcc_id, array(6, 110, 291))) { // If state is US, Alaska or Hawaii add US cnty and state @@ -222,7 +226,7 @@ $sign_string = strtoupper($sign_string); $signed_item = trim($CI->signlog($lotw_cert_info->cert_key, $sign_string)); print ""; for ($i=0; $i".$sign_string."\n"; From c68a8882a98266e5e13e4d906860d597862f1a2a Mon Sep 17 00:00:00 2001 From: phl0 Date: Fri, 10 Oct 2025 17:13:36 +0200 Subject: [PATCH 5/5] Wrap signature correctly --- application/views/lotw_views/adif_views/adif_export.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 17c86cbdb..6c47ec707 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -226,9 +226,8 @@ $sign_string = strtoupper($sign_string); $signed_item = trim($CI->signlog($lotw_cert_info->cert_key, $sign_string)); print ""; for ($i=0; $i".$sign_string."\n"; ?>