api key test button in station location

This commit is contained in:
HB9HIL
2024-04-30 23:35:05 +02:00
parent da352f4c21
commit 50789da43b
4 changed files with 84 additions and 2 deletions

View File

@@ -21,6 +21,45 @@ class Qrz extends CI_Controller {
$this->config->load('config');
}
/*
* API Key Status Test
*/
public function qrz_apitest() {
$apikey = xss_clean($this->input->post('APIKEY'));
$url = 'http://logbook.qrz.com/api'; // TODO: Move this to database
$post_data['KEY'] = $apikey;
$post_data['ACTION'] = 'STATUS';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
if ($content){
if (stristr($content,'RESULT=OK')) {
$result['status'] = 'OK';
$result['message'] = $content;
}
else {
$result['status'] = 'Failed';
$result['message'] = $content;
}
}
if(curl_errno($ch)){
$result['status'] = 'error';
$result['message'] = 'Curl error: '. curl_errno($ch);
}
header('Content-Type: application/json');
echo json_encode($result);
}
/*
* Upload QSO to QRZ.com
* When called from the url wavelog/qrz/upload, the function loops through all station_id's with a qrz api key defined.

View File

@@ -227,7 +227,11 @@
<div class="row">
<div class="mb-3 col-sm-6">
<label for="qrzApiKey">QRZ.com Logbook API Key</label> <!-- This does not need Multilanguage Support -->
<input type="text" class="form-control" name="qrzapikey" pattern="^([A-F0-9]{4}-){3}[A-F0-9]{4}$" id="qrzApiKey" aria-describedby="qrzApiKeyHelp">
<div class="input-group">
<input type="text" class="form-control" name="qrzapikey" pattern="^([A-F0-9]{4}-){3}[A-F0-9]{4}$" id="qrzApiKey" aria-describedby="qrzApiKeyHelp">
<button class="btn btn-secondary" type="button" id="qrz_apitest_btn">Test API-Key</button>
</div>
<div class="alert mt-3" style="display: none;" id="qrz_apitest_msg"></div>
<small id="qrzApiKeyHelp" class="form-text text-muted"><?php echo lang("station_location_qrz_hint"); ?></a></small>
</div>
<div class="mb-3 col-sm-6">

View File

@@ -298,7 +298,11 @@
<div class="card-body">
<div class="mb-3">
<label for="qrzApiKey">QRZ.com Logbook API Key</label> <!-- This does not need Multilanguage Support -->
<input type="text" class="form-control" name="qrzapikey" pattern="^([A-F0-9]{4}-){3}[A-F0-9]{4}$" id="qrzApiKey" aria-describedby="qrzApiKeyHelp" value="<?php if(set_value('qrzapikey') != "") { echo set_value('qrzapikey'); } else { echo $my_station_profile->qrzapikey; } ?>">
<div class="input-group">
<input type="text" class="form-control" name="qrzapikey" pattern="^([A-F0-9]{4}-){3}[A-F0-9]{4}$" id="qrzApiKey" aria-describedby="qrzApiKeyHelp" value="<?php if(set_value('qrzapikey') != "") { echo set_value('qrzapikey'); } else { echo $my_station_profile->qrzapikey; } ?>">
<button class="btn btn-secondary" type="button" id="qrz_apitest_btn">Test API-Key</button>
</div>
<div class="alert mt-3" style="display: none;" id="qrz_apitest_msg"></div>
<small id="qrzApiKeyHelp" class="form-text text-muted"><?php echo lang("station_location_qrz_hint"); ?></a></small>
</div>

View File

@@ -12,6 +12,41 @@ $(document).ready(function () {
$("#dxcc_id").change(function () {
updateStateDropdown('#dxcc_id', '#stateInputLabel', '#location_us_county', '#stationCntyInputEdit');
});
$('#qrz_apitest_btn').click(function(){
var apikey = $('#qrzApiKey').val();
var msg_div = $('#qrz_apitest_msg');
msg_div.hide();
msg_div.removeClass('alert-success alert-danger')
$.ajax({
url: base_url+'index.php/qrz/qrz_apitest',
type: 'POST',
data: {
'APIKEY': apikey
},
success: function(res) {
if(res.status == 'OK') {
msg_div.addClass('alert-success');
msg_div.text('Your API Key works. You are good to go!');
msg_div.show();
} else {
msg_div.addClass('alert-danger');
msg_div.text('Your API Key failed. Are you sure you have a valid QRZ subsription?');
msg_div.show();
$('#qrzrealtime').val(-1);
}
},
error: function(res) {
msg_div.addClass('alert-danger');
msg_div.text('ERROR: Something went wrong on serverside. We\'re sorry..');
msg_div.show();
},
});
});
}
});