Files
wavelog/application/models/Api_model.php
HB9HIL 2df091f891 Release v1.1 (#120)
* config file for directory userdata

* userdir for eqsl

* change name to userdata

* userdata for qsl

* fix name on comment

* add generic function file

* remove model class on view, use generic function

* Re-added forum link

* add stations_id to eqsl functions

* remove 'v' in Version Dialog

* Update README.md

added Link to demo instance

* Update index.php

* We should be MIT Conform

* [Debug] Added information about when files were last updated, and links to update

* Added custom data format

* Remove leftover-index

* Migration

* Check if index is there

* [LBA] Can disable maidenhead overlay

* paths libary

* Dev (#2)

* Added Windows, MariaDB and PHP-Versions

* Release 1.0

* Re-added forum link

* add stations_id to eqsl functions

* remove 'v' in Version Dialog

* Update README.md

added Link to demo instance

* Update index.php

* We should be MIT Conform

* [Debug] Added information about when files were last updated, and links to update

* Added custom data format

* Remove leftover-index

* Migration

* Check if index is there

* [LBA] Can disable maidenhead overlay

---------

Co-authored-by: int2001 <joerg@dj7nt.de>
Co-authored-by: Joerg (DJ7NT) <int2001@users.noreply.github.com>
Co-authored-by: Andreas <6977712+AndreasK79@users.noreply.github.com>
Co-authored-by: Christoph Kottke <dg0tm@darc.de>
Co-authored-by: Florian (DF2ET) <github@florian-wolters.de>

* [eQSL] only locations with a eQSL nickname should be displayed (#74)

* only locations with a eQSL nickname should be displayed in the dropdown under eQSL Import

* add proper error message

* improve usability

---------

Co-authored-by: Christoph Kottke <dg0tm@darc.de>

* html fixes

* show flashdata if no station has eqsl nick

* removed openssl check, not required

* accumulate stats language

* multilanguage support

* prettier

* Prevent leaking data out of other station_location

* moved qrg to first tab

* Fix a PHP 8.1 deprecated bug.

* [Contesting] Fix for table qso count

* Fixed error when data was empty. Also clear table before inserting again.

* Refactor to get the table to load

* Need to clear datatable when session is deleted

* Prevent Racecondition

* Fixed a few null-checks which will fail on fresh accounts

* Allow for longer gridsquare in station profile

* Show IOTA/SOTA ref on station location tab

* [LBA] Fixed mapping of selected QSOs

* Trying to convert the QSO-Post to an ajax call PHP/Part

* JS Part

* Dev (#3)

* Added Windows, MariaDB and PHP-Versions

* Release 1.0

* Re-added forum link

* add stations_id to eqsl functions

* remove 'v' in Version Dialog

* Update README.md

added Link to demo instance

* Update index.php

* We should be MIT Conform

* [Debug] Added information about when files were last updated, and links to update

* Added custom data format

* Remove leftover-index

* Migration

* Check if index is there

* [LBA] Can disable maidenhead overlay

* [eQSL] only locations with a eQSL nickname should be displayed (#74)

* only locations with a eQSL nickname should be displayed in the dropdown under eQSL Import

* add proper error message

* improve usability

---------

Co-authored-by: Christoph Kottke <dg0tm@darc.de>

* html fixes

* show flashdata if no station has eqsl nick

* removed openssl check, not required

* accumulate stats language

* multilanguage support

* prettier

* Prevent leaking data out of other station_location

* moved qrg to first tab

* Fix a PHP 8.1 deprecated bug.

* [Contesting] Fix for table qso count

* Fixed error when data was empty. Also clear table before inserting again.

* Refactor to get the table to load

* Need to clear datatable when session is deleted

* Prevent Racecondition

* Fixed a few null-checks which will fail on fresh accounts

* Allow for longer gridsquare in station profile

* Show IOTA/SOTA ref on station location tab

* [LBA] Fixed mapping of selected QSOs

---------

Co-authored-by: int2001 <joerg@dj7nt.de>
Co-authored-by: Joerg (DJ7NT) <int2001@users.noreply.github.com>
Co-authored-by: Andreas <6977712+AndreasK79@users.noreply.github.com>
Co-authored-by: Christoph Kottke <dg0tm@darc.de>
Co-authored-by: Florian (DF2ET) <github@florian-wolters.de>
Co-authored-by: dg0tm <schieberjunge@gmx.net>

* First POC

* Handling of AJAX result (started)

* Change qso-save to ajax-return

* Added notification and reloading of QSO-Table

* JS-Part

* Set Focus to qso after (successful) log

* Resetting timers (successful)

* Info is now shown / faded

* Small adjustments

* More Beauty

* Make consequent use of SIG-References from station_profile

* Delete application/views/welcome directory

Leftovers. Security Flaw!

* Update Dashboard.php

Remove redir to welcome

* Delete application/controllers/Welcome.php

security flaw

* Hint for 8.3. friendly Usertest

* Update config.sample.php

default should be commented out

* [LBA] Checkbox to turn on/off path lines in map

* Styling for pathlines-checkbox

* [LBA] Checkbox tweaks

* updated comment in config.php (sample and installer)

* Removed popup regarding unsaved changes (wasn't functional at all)

* Added locking for sending a qso twice

* added spinner to save button

* Also include SIG and SIG_INFO

* [Logbook] Removed profiler

* [LBA] Added fitbounds to map

* [LBA] Added CQ Zone overlay

* Make clearer that overview filters on logbook rather than locations

* baesURL has a trailing slash already

* active logbook hint

* Update .gitignore

added userdata

* [LBA] ITU zone overlay

* Minor wording

* [LBA] Added custom mapping icons

* [LBA] Path line follows icon color

* [LBA] Added icon anchoring

* [LBA] Added easyprint for easy map saving

* [LBA] Added default colors when icon settings does not exist in db

* Check refs before trimming them

* [LBA] Fixed another default issue with markers and colors

* Removed dangerous functions where User can accidently shift profiles

* Rmoeve more unused leftovers from 1.0 to 2.0.

* Header refactoring (#110)

* splitted up header

* resorted header menu

* main rebuild

* header behaviour hover

* dropdown toggle rotate

* fix case where landscape is small menu and portrait normal view

* submenu thirdparty services

* removed custom maps from the header

* matching search bar

* border

* matched border to themes

* [Custom Map] Removed code

* [Gridmap] Broke map by accident. Thanks @phl0 for poke.

* Optical support for SAT directions and elevation

* [LBA] Added coordinates at the bottom of the map

* Align numbers and arrows

* Reset RST after saving via AJAX

* Cfd export (#117)

* Added CFD Export for toplist.darc.de to Wavelog

---------

Co-authored-by: phl0 <github@florian-wolters.de>

* special thx to contributors

* tag 1.1

* typo

---------

Co-authored-by: abarrau <hesky378@gmail.com>
Co-authored-by: Andreas <6977712+AndreasK79@users.noreply.github.com>
Co-authored-by: Christoph Kottke <dg0tm@darc.de>
Co-authored-by: Joerg (DJ7NT) <int2001@users.noreply.github.com>
Co-authored-by: int2001 <joerg@dj7nt.de>
Co-authored-by: Florian (DF2ET) <github@florian-wolters.de>
Co-authored-by: dg0tm <schieberjunge@gmx.net>
2024-02-09 18:12:28 +01:00

307 lines
14 KiB
PHP

<?php
/* api_model.php
*
* Provides API functions to the web frontend
*
*/
class API_Model extends CI_Model {
// GET API Keys
function keys() {
$this->db->where('user_id', $this->session->userdata('user_id'));
return $this->db->get('api');
}
function CountKeysWithNoUserID() {
$this->db->where('user_id =', NULL);
$query = $this->db->get('api');
return $query->num_rows();
}
function key_description($key) {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', $key);
$query = $this->db->get('api');
return $query->result_array()[0];
}
function key_userid($key) {
$this->db->where('key', $key);
$query = $this->db->get('api');
return $query->result_array()[0]['user_id'];
}
function update_key_description($key, $description) {
$data = array(
'description' => xss_clean($description),
);
$this->db->where('key', xss_clean($key));
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->update('api', xss_clean($data));
}
function delete_key($key) {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', xss_clean($key));
$this->db->delete('api');
}
// Generate API Key
function generate_key($rights) {
// Expects either rw (Read, Write) or r (read only)
// Generate Unique Key
$data['key'] = uniqid("wl");
$data['rights'] = $rights;
// Set API key to active
$data['status'] = "active";
$data['user_id'] = $this->session->userdata('user_id');
$this->db->insert('api', $data);
}
function access($key) {
// No key = no access, mate
if(!$key) {
return $status = "No Key Found";
}
// Check that the key is valid
$this->db->where('key', $key);
$query = $this->db->get('api');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
if($row->status == "active") {
return $status = $row->rights;
} else {
return $status = "Key Disabled";
}
}
} else {
return $status = "No Key Found";
}
}
function authorize($key) {
$r = $this->access($key);
if($r == "rw") {
return 2;
} else if($r == "r") {
return 1;
} else {
return 0;
}
}
function update_last_used($key) {
$this->db->set('last_used', 'NOW()', FALSE);
$this->db->where('key', xss_clean($key));
$this->db->update('api');
// Also update last_seen in user table
$user_id = $this->key_userid($key);
$this->load->model('user_model');
$this->user_model->set_last_seen($user_id);
}
// FUNCTION: string name(string $column)
// Converts a MySQL column name to a more friendly name
function name($col)
{
if($this->_columnName[$col])
{
return $this->_columnName[$col]['Name'];
}
else
{
return 0;
}
}
// FUNCTION: string description(string $column)
// Returns the description for a MySQL column name
function description($col)
{
if($this->_columnName[$col])
{
if($this->_columnName[$col]['Description'] != "")
{
return $this->_columnName[$col]['Description'];
}
else
{
return "No description available";
}
}
else
{
return 0;
}
}
// FUNCTION: string name(string $name)
// Converts a friendly name to a MySQL column name
function column($name)
{
while ($column = current($this->_columnName))
{
if($this->_columnName[key($this->_columnName)]['Name'] == $name)
{
$a = key($this->_columnName);
reset($this->_columnName);
return $a;
}
next($this->_columnName);
}
reset($this->_columnName);
return 0;
}
// ARRAY: $_columnName
// An array matching MySQL column names to friendly names, descriptions and types
private $_columnName = array(
'COL_PRIMARY_KEY' => array('Name' => 'ID', 'Description' => 'Unique QSO ID', 'Type' => 'I'),
'COL_ADDRESS' => array('Name' => 'Address', 'Description' => 'Operator\'s address', 'Type' => 'S'),
'COL_AGE' => array('Name' => 'Age', 'Description' => 'Operator\'s age', 'Type' => 'I'),
'COL_A_INDEX' => array('Name' => 'AIndex', 'Description' => 'Solar A Index', 'Type' => 'I'),
'COL_ANT_AZ' => array('Name' => 'AntennaAzimuth', 'Description' => 'Antenna azimuth', 'Type' => 'I'),
'COL_ANT_EL' => array('Name' => 'AntennaElevation', 'Description' => 'Antenna elevation', 'Type' => 'I'),
'COL_ANT_PATH' => array('Name' => 'AntennaPath', 'Description' => 'Antenna path', 'Type' => ''),
'COL_ARRL_SECT' => array('Name' => 'ARRLSection', 'Description' => 'ARRL Section', 'Type' => ''),
'COL_BAND' => array('Name' => 'Band', 'Description' => 'Band', 'Type' => ''),
'COL_BAND_RX' => array('Name' => 'BandRX', 'Description' => '', 'Type' => ''),
'COL_BIOGRAPHY' => array('Name' => 'Biography', 'Description' => '', 'Type' => ''),
'COL_CALL' => array('Name' => 'Call', 'Description' => '', 'Type' => ''),
'COL_CHECK' => array('Name' => 'UNK_CHECK', 'Description' => '', 'Type' => ''),
'COL_CLASS' => array('Name' => 'Class', 'Description' => '', 'Type' => ''),
'COL_CNTY' => array('Name' => 'County', 'Description' => '', 'Type' => ''),
'COL_COMMENT' => array('Name' => 'Comment', 'Description' => '', 'Type' => ''),
'COL_CONT' => array('Name' => 'Continent', 'Description' => '', 'Type' => ''),
'COL_CONTACTED_OP' => array('Name' => 'UNK_CONTACTED_OP', 'Description' => '', 'Type' => ''),
'COL_CONTEST_ID' => array('Name' => 'ContestID', 'Description' => '', 'Type' => ''),
'COL_COUNTRY' => array('Name' => 'Country', 'Description' => '', 'Type' => ''),
'COL_CQZ' => array('Name' => 'CQZone', 'Description' => '', 'Type' => ''),
'COL_DARC_DOK' => array('Name' => 'DOK', 'Description' => '', 'Type' => ''),
'COL_DISTANCE' => array('Name' => 'Distance', 'Description' => '', 'Type' => ''),
'COL_DXCC' => array('Name' => 'DXCC', 'Description' => '', 'Type' => ''),
'COL_EMAIL' => array('Name' => 'EMail', 'Description' => '', 'Type' => ''),
'COL_EQ_CALL' => array('Name' => 'UNK_EQ_CALL', 'Description' => '', 'Type' => ''),
'COL_EQSL_QSLRDATE' => array('Name' => 'EQSLRecievedDate', 'Description' => '', 'Type' => ''),
'COL_EQSL_QSLSDATE' => array('Name' => 'EQSLSentDate', 'Description' => '', 'Type' => ''),
'COL_EQSL_QSL_RCVD' => array('Name' => 'EQSLRecieved', 'Description' => '', 'Type' => ''),
'COL_EQSL_QSL_SENT' => array('Name' => 'EQSLSent', 'Description' => '', 'Type' => ''),
'COL_EQSL_STATUS' => array('Name' => 'EQSLStatus', 'Description' => '', 'Type' => ''),
'COL_FORCE_INIT' => array('Name' => 'UNK_FORCE_INIT', 'Description' => '', 'Type' => ''),
'COL_FREQ' => array('Name' => 'Frequency', 'Description' => '', 'Type' => ''),
'COL_FREQ_RX' => array('Name' => 'FrequencyRX', 'Description' => '', 'Type' => ''),
'COL_GRIDSQUARE' => array('Name' => 'Locator', 'Description' => '', 'Type' => ''),
'COL_HEADING' => array('Name' => 'Heading', 'Description' => '', 'Type' => ''),
'COL_IOTA' => array('Name' => 'IOTA', 'Description' => '', 'Type' => ''),
'COL_ITUZ' => array('Name' => 'ITUZone', 'Description' => '', 'Type' => ''),
'COL_K_INDEX' => array('Name' => 'KIndex', 'Description' => '', 'Type' => ''),
'COL_LAT' => array('Name' => 'Latitude', 'Description' => '', 'Type' => ''),
'COL_LON' => array('Name' => 'Longitude', 'Description' => '', 'Type' => ''),
'COL_LOTW_QSLRDATE' => array('Name' => 'LOTWRecievedDate', 'Description' => '', 'Type' => ''),
'COL_LOTW_QSLSDATE' => array('Name' => 'LOTWSentDate', 'Description' => '', 'Type' => ''),
'COL_LOTW_QSL_RCVD' => array('Name' => 'LOTWRecieved', 'Description' => '', 'Type' => ''),
'COL_LOTW_QSL_SENT' => array('Name' => 'LOTWSent', 'Description' => '', 'Type' => ''),
'COL_LOTW_STATUS' => array('Name' => 'LOTWStatus', 'Description' => '', 'Type' => ''),
'COL_MAX_BURSTS' => array('Name' => 'MaxBursts', 'Description' => '', 'Type' => ''),
'COL_MODE' => array('Name' => 'Mode', 'Description' => '', 'Type' => ''),
'COL_MS_SHOWER' => array('Name' => 'MSShower', 'Description' => '', 'Type' => ''),
'COL_MY_CITY' => array('Name' => 'MyCity', 'Description' => '', 'Type' => ''),
'COL_MY_CNTY' => array('Name' => 'MyCounty', 'Description' => '', 'Type' => ''),
'COL_MY_COUNTRY' => array('Name' => 'MyCountry', 'Description' => '', 'Type' => ''),
'COL_MY_CQ_ZONE' => array('Name' => 'MyCQZone', 'Description' => '', 'Type' => ''),
'COL_MY_GRIDSQUARE' => array('Name' => 'MyLocator', 'Description' => '', 'Type' => ''),
'COL_MY_IOTA' => array('Name' => 'MyIOTA', 'Description' => '', 'Type' => ''),
'COL_MY_ITU_ZONE' => array('Name' => 'MyITUZone', 'Description' => '', 'Type' => ''),
'COL_MY_LAT' => array('Name' => 'MyLatitude', 'Description' => '', 'Type' => ''),
'COL_MY_LON' => array('Name' => 'MyLongitude', 'Description' => '', 'Type' => ''),
'COL_MY_NAME' => array('Name' => 'MyName', 'Description' => '', 'Type' => ''),
'COL_MY_POSTAL_CODE' => array('Name' => 'MyPostalCode', 'Description' => '', 'Type' => ''),
'COL_MY_RIG' => array('Name' => 'MyRig', 'Description' => '', 'Type' => ''),
'COL_MY_SIG' => array('Name' => 'MySig', 'Description' => '', 'Type' => ''),
'COL_MY_SIG_INFO' => array('Name' => 'MySigInfo', 'Description' => '', 'Type' => ''),
'COL_MY_STATE' => array('Name' => 'MyState', 'Description' => '', 'Type' => ''),
'COL_MY_STREET' => array('Name' => 'MyStreet', 'Description' => '', 'Type' => ''),
'COL_NAME' => array('Name' => 'Name', 'Description' => '', 'Type' => ''),
'COL_NOTES' => array('Name' => 'Notes', 'Description' => '', 'Type' => ''),
'COL_NR_BURSTS' => array('Name' => 'NumBursts', 'Description' => '', 'Type' => ''),
'COL_NR_PINGS' => array('Name' => 'NumPings', 'Description' => '', 'Type' => ''),
'COL_OPERATOR' => array('Name' => 'Operator', 'Description' => '', 'Type' => ''),
'COL_OWNER_CALLSIGN' => array('Name' => 'OwnerCallsign', 'Description' => '', 'Type' => ''),
'COL_PFX' => array('Name' => 'Prefix', 'Description' => '', 'Type' => ''),
'COL_PRECEDENCE' => array('Name' => 'Precedence', 'Description' => '', 'Type' => ''),
'COL_PROP_MODE' => array('Name' => 'PropMode', 'Description' => '', 'Type' => ''),
'COL_PUBLIC_KEY' => array('Name' => 'PublicKey', 'Description' => '', 'Type' => ''),
'COL_QSLMSG' => array('Name' => 'QSLMessage', 'Description' => '', 'Type' => ''),
'COL_QSLRDATE' => array('Name' => 'QSLRecievedDate', 'Description' => '', 'Type' => ''),
'COL_QSLSDATE' => array('Name' => 'QSLSentDate', 'Description' => '', 'Type' => ''),
'COL_QSL_RCVD' => array('Name' => 'QSLRecieved', 'Description' => '', 'Type' => ''),
'COL_QSL_RCVD_VIA' => array('Name' => 'QSLRecievedVia', 'Description' => '', 'Type' => ''),
'COL_QSL_SENT' => array('Name' => 'QSLSent', 'Description' => '', 'Type' => ''),
'COL_QSL_SENT_VIA' => array('Name' => 'QSLSentVia', 'Description' => '', 'Type' => ''),
'COL_QSL_VIA' => array('Name' => 'QSLVia', 'Description' => '', 'Type' => ''),
'COL_QSO_COMPLETE' => array('Name' => 'QSOComplete', 'Description' => '', 'Type' => ''),
'COL_QSO_RANDOM' => array('Name' => 'QSORandom', 'Description' => '', 'Type' => ''),
'COL_QTH' => array('Name' => 'QTH', 'Description' => '', 'Type' => ''),
'COL_RIG' => array('Name' => 'Rig', 'Description' => '', 'Type' => ''),
'COL_RST_RCVD' => array('Name' => 'ReportRecieved', 'Description' => '', 'Type' => ''),
'COL_RST_SENT' => array('Name' => 'ReportSent', 'Description' => '', 'Type' => ''),
'COL_RX_PWR' => array('Name' => 'RXPower', 'Description' => '', 'Type' => ''),
'COL_SAT_MODE' => array('Name' => 'SatMode', 'Description' => '', 'Type' => ''),
'COL_SAT_NAME' => array('Name' => 'SatName', 'Description' => '', 'Type' => ''),
'COL_SFI' => array('Name' => 'SFI', 'Description' => '', 'Type' => ''),
'COL_SIG' => array('Name' => 'Sig', 'Description' => '', 'Type' => ''),
'COL_SIG_INFO' => array('Name' => 'SigInfo', 'Description' => '', 'Type' => ''),
'COL_SRX' => array('Name' => 'UNK_SRX', 'Description' => '', 'Type' => ''),
'COL_STX' => array('Name' => 'UNK_STX', 'Description' => '', 'Type' => ''),
'COL_SRX_STRING' => array('Name' => 'UNK_SRX_STRING', 'Description' => '', 'Type' => ''),
'COL_STX_STRING' => array('Name' => 'UNK_STX_STRING', 'Description' => '', 'Type' => ''),
'COL_STATE' => array('Name' => 'State', 'Description' => '', 'Type' => ''),
'COL_STATION_CALLSIGN' => array('Name' => 'StationCall', 'Description' => '', 'Type' => ''),
'COL_SWL' => array('Name' => 'SWL', 'Description' => '', 'Type' => ''),
'COL_TEN_TEN' => array('Name' => 'TenTen', 'Description' => '', 'Type' => ''),
'COL_TIME_OFF' => array('Name' => 'TimeOff', 'Description' => '', 'Type' => ''),
'COL_TIME_ON' => array('Name' => 'TimeOn', 'Description' => '', 'Type' => ''),
'COL_TX_PWR' => array('Name' => 'TXPower', 'Description' => '', 'Type' => ''),
'COL_WEB' => array('Name' => 'Website', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_0' => array('Name' => 'UNK_USER_DEFINED_0', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_1' => array('Name' => 'UNK_USER_DEFINED_1', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_2' => array('Name' => 'UNK_USER_DEFINED_2', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_3' => array('Name' => 'UNK_USER_DEFINED_3', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_4' => array('Name' => 'UNK_USER_DEFINED_4', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_5' => array('Name' => 'UNK_USER_DEFINED_5', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_6' => array('Name' => 'UNK_USER_DEFINED_6', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_7' => array('Name' => 'UNK_USER_DEFINED_7', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_8' => array('Name' => 'UNK_USER_DEFINED_8', 'Description' => '', 'Type' => ''),
'COL_USER_DEFINED_9' => array('Name' => 'UNK_USER_DEFINED_9', 'Description' => '', 'Type' => ''),
'COL_CREDIT_GRANTED' => array('Name' => 'UNK_CREDIT_GRANTED', 'Description' => '', 'Type' => ''),
'COL_CREDIT_SUBMITTED' => array('Name' => 'UNK_CREDIT_SUBMITTED', 'Description' => '', 'Type' => ''),
);
}
?>