Files
wavelog/application/controllers/Update.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

553 lines
16 KiB
PHP

<?php
class Update extends CI_Controller {
/*
Controls Updating Elements of Wavelog
Functions:
dxcc - imports the latest clublog cty.xml data
lotw_users - imports lotw users
*/
public function index()
{
$data['page_title'] = "Updates";
$this->load->view('interface_assets/header', $data);
$this->load->view('update/index');
$this->load->view('interface_assets/footer');
}
/*
* Create a path to a file in the updates folder, respecting the datadir
* configuration option.
*/
private function make_update_path($path) {
$path = "updates/" . $path;
$datadir = $this->config->item('datadir');
if(!$datadir) {
return $path;
}
return $datadir . "/" . $path;
}
/*
* Load the dxcc entities
*/
public function dxcc_entities() {
// Load Database connectors
$this->load->model('dxcc_entities');
// Load the cty file
$xml_data = simplexml_load_file($this->make_update_path("cty.xml"));
//$xml_data->entities->entity->count();
$count = 0;
$a_data=[];
foreach ($xml_data->entities->entity as $entity) {
$startinfo = strtotime($entity->start);
$endinfo = strtotime($entity->end);
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : null;
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : null;
if(!$entity->cqz) {
$data = array(
'prefix' => (string) $entity->call,
'name' => (string) $entity->entity,
);
} else {
$data = array(
'adif' => (int) $entity->adif,
'name' => (string) $entity->name,
'prefix' => (string) $entity->prefix,
'ituz' => (float) $entity->ituz,
'cqz' => (int) $entity->cqz,
'cont' => (string) $entity->cont,
'long' => (float) $entity->long,
'lat' => (float) $entity->lat,
'start' => $start_date,
'end' => $end_date,
);
}
array_push($a_data,$data);
$count += 1;
if ($count % 10 == 0)
$this->update_status("Preparing DXCC-Entries: ".$count);
}
$this->db->insert_batch('dxcc_entities', $a_data);
$this->update_status();
return $count;
}
/*
* Load the dxcc exceptions
*/
public function dxcc_exceptions() {
// Load Database connectors
$this->load->model('dxcc_exceptions');
// Load the cty file
$xml_data = simplexml_load_file($this->make_update_path("cty.xml"));
$count = 0;
$a_data=[];
foreach ($xml_data->exceptions->exception as $record) {
$startinfo = strtotime($record->start);
$endinfo = strtotime($record->end);
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : null;
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : null;
$data = array(
'record' => (int) $record->attributes()->record,
'call' => (string) $record->call,
'entity' => (string) $record->entity,
'adif' => (int) $record->adif,
'cqz' => (int) $record->cqz,
'cont' => (string) $record->cont,
'long' => (float) $record->long,
'lat' => (float) $record->lat,
'start' => $start_date,
'end' => $end_date,
);
array_push($a_data,$data);
$count += 1;
if ($count % 10 == 0)
$this->update_status("Preparing DXCC Exceptions: ".$count);
}
$this->db->insert_batch('dxcc_exceptions', $a_data);
$this->update_status();
return $count;
}
/*
* Load the dxcc prefixes
*/
public function dxcc_prefixes() {
// Load Database connectors
$this->load->model('dxcc_prefixes');
// Load the cty file
$xml_data = simplexml_load_file($this->make_update_path("cty.xml"));
$count = 0;
$a_data=[];
foreach ($xml_data->prefixes->prefix as $record) {
$startinfo = strtotime($record->start);
$endinfo = strtotime($record->end);
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : null;
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : null;
$data = array(
'record' => (int) $record->attributes()->record,
'call' => (string) $record->call,
'entity' => (string) $record->entity,
'adif' => (int) $record->adif,
'cqz' => (int) $record->cqz,
'cont' => (string) $record->cont,
'long' => (float) $record->long,
'lat' => (float) $record->lat,
'start' => $start_date,
'end' => $end_date,
);
array_push($a_data,$data);
$count += 1;
if ($count % 10 == 0)
$this->update_status("Preparing DXCC Prefixes: ".$count);
}
$this->db->insert_batch('dxcc_prefixes', $a_data);
//print("$count prefixes processed");
$this->update_status();
return $count;
}
// Updates the DXCC & Exceptions from the Club Log Cty.xml file.
public function dxcc() {
$this->update_status("Downloading file");
// give it 10 minutes...
set_time_limit(600);
// Load Migration data if any.
$this->load->library('migration');
$this->fix_migrations();
$this->migration->latest();
// Download latest file.
$url = "https://cdn.clublog.org/cty.php?api=608df94896cb9c5421ae748235492b43815610c9";
$gz = gzopen($url, 'r');
if ($gz === FALSE) {
$this->update_status("FAILED: Could not download from clublog.org");
log_message('error', 'FAILED: Could not download exceptions from clublog.org');
return;
}
$data = "";
while (!gzeof($gz)) {
$data .= gzgetc($gz);
}
gzclose($gz);
if (file_put_contents($this->make_update_path("cty.xml"), $data) === FALSE) {
$this->update_status("FAILED: Could not write to cty.xml file");
return;
}
// Clear the tables, ready for new data
$this->db->empty_table("dxcc_entities");
$this->db->empty_table("dxcc_exceptions");
$this->db->empty_table("dxcc_prefixes");
$this->update_status();
// Parse the three sections of the file and update the tables
$this->db->trans_start();
$this->dxcc_entities();
$this->dxcc_exceptions();
$this->dxcc_prefixes();
$this->db->trans_complete();
$this->update_status("DONE");
}
public function update_status($done=""){
if ($done != "Downloading file"){
// Check that everything is done?
if ($done == ""){
$done = "Updating...";
}
$html = $done."<br/>";
$html .= "Dxcc Entities: ".$this->db->count_all('dxcc_entities')."<br/>";
$html .= "Dxcc Exceptions: ".$this->db->count_all('dxcc_exceptions')."<br/>";
$html .= "Dxcc Prefixes: ".$this->db->count_all('dxcc_prefixes')."<br/>";
} else {
$html = $done."....<br/>";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('dxcc_clublog_update', $datetime , 'no');
}
file_put_contents($this->make_update_path("status.html"), $html);
}
private function fix_migrations(){
$res = $this->db->query("select version from migrations");
if ($res->num_rows() >0){
$row = $res->row();
$version = $row->version;
if ($version < 7){
$this->db->query("update migrations set version=7");
}
}
}
public function check_missing_dxcc($all = false){
$this->load->model('logbook_model');
$this->logbook_model->check_missing_dxcc_id($all);
}
public function check_missing_continent() {
$this->load->model('logbook_model');
$this->logbook_model->check_missing_continent();
}
public function update_distances() {
$this->load->model('logbook_model');
$this->logbook_model->update_distances();
}
public function check_missing_grid($all = false){
$this->load->model('logbook_model');
$this->logbook_model->check_missing_grid_id($all);
}
public function update_clublog_scp() {
$strFile = $this->make_update_path("clublog_scp.txt");
$url = "https://cdn.clublog.org/clublog.scp.gz";
set_time_limit(300);
echo "Downloading Club Log SCP file...<br>";
$gz = gzopen($url, 'r');
if ($gz)
{
$data = "";
while (!gzeof($gz)) {
$data .= gzgetc($gz);
}
gzclose($gz);
if (file_put_contents($strFile, $data) !== FALSE)
{
$nCount = count(file($strFile));
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " callsigns loaded";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('scp_update', $datetime , 'no');
} else {
echo "FAILED: Empty file";
}
} else {
echo "FAILED: Could not write to Club Log SCP file";
}
} else {
echo "FAILED: Could not connect to Club Log";
}
}
public function download_lotw_users() {
$contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true);
if($contents === FALSE) {
echo "Something went wrong with fetching the LoTW users file.";
} else {
$file = './updates/lotw_users.csv';
if (file_put_contents($file, $contents) !== FALSE) { // Save our content to the file.
echo "LoTW User Data Saved.";
} else {
echo "FAILED: Could not write to LoTW users file";
}
}
}
public function lotw_users() {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$file = 'https://lotw.arrl.org/lotw-user-activity.csv';
$handle = fopen($file, "r");
if ($handle === FALSE) {
echo "Something went wrong with fetching the LoTW uses file";
return;
}
$this->db->empty_table("lotw_users");
$i = 0;
$data = fgetcsv($handle,1000,",");
do {
if ($data[0]) {
$lotwdata[$i]['callsign'] = $data[0];
$lotwdata[$i]['lastupload'] = $data[1] . ' ' . $data[2];
if (($i % 2000) == 0) {
$this->db->insert_batch('lotw_users', $lotwdata);
unset($lotwdata);
// echo 'Record ' . $i . '<br />';
}
$i++;
}
} while ($data = fgetcsv($handle,1000,","));
fclose($handle);
$this->db->insert_batch('lotw_users', $lotwdata);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds <br />";
echo "Records inserted: " . $i . " <br/>";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('lotw_users_update', $datetime , 'no');
}
public function lotw_check() {
$f = fopen('./updates/lotw_users.csv', "r");
$result = false;
while ($row = fgetcsv($f)) {
if ($row[0] == '4W7EST/MM') {
$result = $row[0];
echo "found";
break;
}
}
fclose($f);
}
/*
* Used for autoupdating the DOK file which is used in the QSO entry dialog for autocompletion.
*/
public function update_dok() {
$contents = file_get_contents('https://www.df2et.de/cqrlog/dok_and_sdok.txt', true);
if($contents === FALSE) {
echo "Something went wrong with fetching the DOK file.";
} else {
$file = './assets/json/dok.txt';
if (file_put_contents($file, $contents) !== FALSE) { // Save our content to the file.
$nCount = count(file($file));
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " DOKs and SDOKs saved";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('dok_file_update', $datetime , 'no');
} else {
echo"FAILED: Empty file";
}
} else {
echo"FAILED: Could not write to dok.txt file";
}
}
}
/*
* Used for autoupdating the SOTA file which is used in the QSO entry dialog for autocompletion.
*/
public function update_sota() {
$csvfile = 'https://www.sotadata.org.uk/summitslist.csv';
$sotafile = './assets/json/sota.txt';
$csvhandle = fopen($csvfile,"r");
if ($csvhandle === FALSE) {
echo "Something went wrong with fetching the SOTA file";
return;
}
$data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in
$data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in
$data = fgetcsv($csvhandle,1000,",");
$sotafilehandle = fopen($sotafile, 'w');
if ($sotafilehandle === FALSE) {
echo"FAILED: Could not write to sota.txt file";
return;
}
$nCount = 0;
do {
if ($data[0]) {
fwrite($sotafilehandle, $data[0].PHP_EOL);
$nCount++;
}
} while ($data = fgetcsv($csvhandle,1000,","));
fclose($csvhandle);
fclose($sotafilehandle);
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " SOTA's saved";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('sota_file_update', $datetime , 'no');
} else {
echo"FAILED: Empty file";
}
}
/*
* Pulls the WWFF directory for autocompletion in QSO dialogs
*/
public function update_wwff() {
$csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv';
$wwfffile = './assets/json/wwff.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $csvfile);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$csv = curl_exec($ch);
curl_close($ch);
if ($csv === FALSE) {
echo "Something went wrong with fetching the WWFF file";
return;
}
$wwfffilehandle = fopen($wwfffile, 'w');
if ($wwfffilehandle === FALSE) {
echo"FAILED: Could not write to wwff.txt file";
return;
}
$data = str_getcsv($csv,"\n");
$nCount = 0;
foreach ($data as $idx => $row) {
if ($idx == 0) continue; // Skip line we are not interested in
$row = str_getcsv($row, ',');
if ($row[0]) {
fwrite($wwfffilehandle, $row[0].PHP_EOL);
$nCount++;
}
}
fclose($wwfffilehandle);
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " WWFF's saved";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('wwff_file_update', $datetime , 'no');
} else {
echo"FAILED: Empty file";
}
}
public function update_pota() {
$csvfile = 'https://pota.app/all_parks.csv';
$potafile = './assets/json/pota.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $csvfile);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$csv = curl_exec($ch);
curl_close($ch);
if ($csv === FALSE) {
echo "Something went wrong with fetching the POTA file";
return;
}
$potafilehandle = fopen($potafile, 'w');
if ($potafilehandle === FALSE) {
echo"FAILED: Could not write to pota.txt file";
return;
}
$data = str_getcsv($csv,"\n");
$nCount = 0;
foreach ($data as $idx => $row) {
if ($idx == 0) continue; // Skip line we are not interested in
$row = str_getcsv($row, ',');
if ($row[0]) {
fwrite($potafilehandle, $row[0].PHP_EOL);
$nCount++;
}
}
fclose($potafilehandle);
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " POTA's saved";
$datetime = new DateTime("now", new DateTimeZone('UTC'));
$datetime = $datetime->format('Ymd h:i');
$this->optionslib->update('pota_file_update', $datetime , 'no');
} else {
echo"FAILED: Empty file";
}
}
}
?>