mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Added keyauth and flags to lookup-api and removed bugs
This commit is contained in:
@@ -473,74 +473,65 @@ class API extends CI_Controller {
|
||||
}
|
||||
|
||||
function lookup() {
|
||||
// start benchmarking
|
||||
$this->output->enable_profiler(TRUE);
|
||||
/*
|
||||
*
|
||||
* Callsign lookup function for Wavelogs logging page or thirdparty systems
|
||||
* which want to show previous QSO data on their system.
|
||||
*
|
||||
* TODO
|
||||
* - Local data make one database call ONLY
|
||||
* - Add eQSL status
|
||||
* - Add Callbook returned data
|
||||
* - Add QSO before data array
|
||||
* - Add options for checking based on band/mode/sat
|
||||
*
|
||||
*/
|
||||
*
|
||||
* Callsign lookup function for Wavelogs logging page or thirdparty systems
|
||||
* which want to show previous QSO data on their system.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Make sure users logged in
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
|
||||
if (!( ((isset($obj['key'])) && ($this->api_model->authorize($obj['key']) > 0) ) || ($this->user_model->authorize($this->config->item('auth_mode'))) )) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "missing api key or session"]);
|
||||
die();
|
||||
}
|
||||
|
||||
$raw_input = json_decode(file_get_contents("php://input"), true);
|
||||
$lookup_callsign = strtoupper($raw_input['callsign'] ?? '');
|
||||
if ($lookup_callsign ?? '' != '') {
|
||||
|
||||
|
||||
$this->load->model("logbook_model");
|
||||
$date = date("Y-m-d");
|
||||
$this->load->model("logbook_model");
|
||||
$date = date("Y-m-d");
|
||||
|
||||
// Return Array
|
||||
$return = [
|
||||
"callsign" => "",
|
||||
"dxcc" => false,
|
||||
"dxcc_lat" => "",
|
||||
"dxcc_long" => "",
|
||||
"dxcc_cqz" => "",
|
||||
"name" => "",
|
||||
"gridsquare" => "",
|
||||
"location" => "",
|
||||
"iota_ref" => "",
|
||||
"state" => "",
|
||||
"us_county" => "",
|
||||
"qsl_manager" => "",
|
||||
"bearing" => "",
|
||||
"workedBefore" => false,
|
||||
"lotw_member" => false,
|
||||
"suffix_slash" => "", // Suffix Slash aka Portable
|
||||
];
|
||||
// Return Array
|
||||
$return = [
|
||||
"callsign" => "",
|
||||
"dxcc" => false,
|
||||
"dxcc_id" => -1,
|
||||
"dxcc_lat" => "",
|
||||
"dxcc_long" => "",
|
||||
"dxcc_cqz" => "",
|
||||
"dxcc_flag" => "",
|
||||
"name" => "",
|
||||
"gridsquare" => "",
|
||||
"location" => "",
|
||||
"iota_ref" => "",
|
||||
"state" => "",
|
||||
"us_county" => "",
|
||||
"qsl_manager" => "",
|
||||
"bearing" => "",
|
||||
"workedBefore" => false,
|
||||
"lotw_member" => false,
|
||||
"suffix_slash" => "", // Suffix Slash aka Portable
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Handle POST data being sent to check lookups
|
||||
*
|
||||
*/
|
||||
$raw_input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$lookup_callsign = strtoupper($raw_input['callsign']);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Handle Callsign field
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Handle Callsign field
|
||||
*
|
||||
*/
|
||||
$return['callsign'] = $lookup_callsign;
|
||||
|
||||
/*
|
||||
*
|
||||
* Lookup DXCC and Suffix information
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Lookup DXCC and Suffix information
|
||||
*
|
||||
*/
|
||||
|
||||
$callsign_dxcc_lookup = $this->logbook_model->dxcc_lookup($lookup_callsign, $date);
|
||||
|
||||
@@ -549,18 +540,18 @@ class API extends CI_Controller {
|
||||
if(isset($last_slash_pos) && $last_slash_pos > 4) {
|
||||
$suffix_slash = $last_slash_pos === false ? $lookup_callsign : substr($lookup_callsign, $last_slash_pos + 1);
|
||||
switch ($suffix_slash) {
|
||||
case "P":
|
||||
$suffix_slash_item = "Portable";
|
||||
break;
|
||||
case "M":
|
||||
$suffix_slash_item = "Mobile";
|
||||
case "MM":
|
||||
$suffix_slash_item = "Maritime Mobile";
|
||||
break;
|
||||
default:
|
||||
// If its not one of the above suffix slashes its likely dxcc
|
||||
$ans2 = $this->logbook_model->dxcc_lookup($suffix_slash, $date);
|
||||
$suffix_slash_item = null;
|
||||
case "P":
|
||||
$suffix_slash_item = "Portable";
|
||||
break;
|
||||
case "M":
|
||||
$suffix_slash_item = "Mobile";
|
||||
case "MM":
|
||||
$suffix_slash_item = "Maritime Mobile";
|
||||
break;
|
||||
default:
|
||||
// If its not one of the above suffix slashes its likely dxcc
|
||||
$ans2 = $this->logbook_model->dxcc_lookup($suffix_slash, $date);
|
||||
$suffix_slash_item = null;
|
||||
}
|
||||
|
||||
$return['suffix_slash'] = $suffix_slash_item;
|
||||
@@ -568,22 +559,24 @@ class API extends CI_Controller {
|
||||
|
||||
// If the final slash is a DXCC then find it!
|
||||
if (isset($ans2['call'])) {
|
||||
$return['dxcc_id'] = $ans2['adif'];
|
||||
$return['dxcc'] = $ans2['entity'];
|
||||
$return['dxcc_lat'] = $ans2['lat'];
|
||||
$return['dxcc_long'] = $ans2['long'];
|
||||
$return['dxcc_cqz'] = $ans2['cqz'];
|
||||
} else {
|
||||
$return['dxcc_id'] = $callsign_dxcc_lookup['adif'];
|
||||
$return['dxcc'] = $callsign_dxcc_lookup['entity'];
|
||||
$return['dxcc_lat'] = $callsign_dxcc_lookup['lat'];
|
||||
$return['dxcc_long'] = $callsign_dxcc_lookup['long'];
|
||||
$return['dxcc_cqz'] = $callsign_dxcc_lookup['cqz'];
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Pool any local data we have for a callsign
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Pool any local data we have for a callsign
|
||||
*
|
||||
*/
|
||||
$call_lookup_results = $this->logbook_model->call_lookup_result($lookup_callsign);
|
||||
|
||||
if($call_lookup_results != null)
|
||||
@@ -595,6 +588,7 @@ class API extends CI_Controller {
|
||||
$return['qsl_manager'] = $call_lookup_results->COL_QSL_VIA;
|
||||
$return['state'] = $call_lookup_results->COL_STATE;
|
||||
$return['us_county'] = $call_lookup_results->COL_CNTY;
|
||||
$return['dxcc_id'] = $call_lookup_results->COL_DXCC;
|
||||
|
||||
if ($return['gridsquare'] != "") {
|
||||
$return['latlng'] = $this->qralatlng($return['gridsquare']);
|
||||
@@ -602,24 +596,27 @@ class API extends CI_Controller {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Check if callsign is active on LoTW
|
||||
*
|
||||
*/
|
||||
if ($return['dxcc'] ?? '' != '') {
|
||||
$this->load->library('DxccFlag');
|
||||
$return['dxcc_flag']=$this->dxccflag->get($return['dxcc_id']);
|
||||
}
|
||||
/*
|
||||
*
|
||||
* Check if callsign is active on LoTW
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Output Returned data
|
||||
*
|
||||
*/
|
||||
echo json_encode($return, JSON_PRETTY_PRINT);
|
||||
/*
|
||||
*
|
||||
* Output Returned data
|
||||
*
|
||||
*/
|
||||
echo json_encode($return, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo '{"error":"callsign to lookup not given"}';
|
||||
}
|
||||
return;
|
||||
|
||||
// End benchmarking
|
||||
$this->output->enable_profiler(FALSE);
|
||||
}
|
||||
|
||||
function qralatlng($qra) {
|
||||
|
||||
@@ -1281,7 +1281,7 @@ class Logbook_model extends CI_Model {
|
||||
*
|
||||
*/
|
||||
function call_lookup_result($callsign) {
|
||||
$this->db->select('COL_CALL, COL_NAME, COL_QSL_VIA, COL_GRIDSQUARE, COL_QTH, COL_IOTA, COL_TIME_ON, COL_STATE, COL_CNTY');
|
||||
$this->db->select('COL_CALL, COL_NAME, COL_QSL_VIA, COL_GRIDSQUARE, COL_QTH, COL_IOTA, COL_TIME_ON, COL_STATE, COL_CNTY, COL_DXCC');
|
||||
$this->db->where('COL_CALL', $callsign);
|
||||
$where = "COL_NAME != \"\"";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user