added flag to recommend cronjobs

This commit is contained in:
HB9HIL
2024-02-27 20:58:02 +01:00
parent c8fc397604
commit fbe5411251
6 changed files with 480 additions and 434 deletions

View File

@@ -13,12 +13,16 @@ class Clublog extends CI_Controller {
// Upload ADIF to Clublog
public function upload() {
$this->load->model('clublog_model');
if (ENVIRONMENT != 'maintenance') {
$this->load->model('clublog_model');
$users = $this->clublog_model->get_clublog_users();
$users = $this->clublog_model->get_clublog_users();
foreach ($users as $user) {
$this->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password);
foreach ($users as $user) {
$this->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password);
}
} else {
echo "Maintenance Mode is active. Try again later.";
}
}

View File

@@ -704,15 +704,19 @@ class eqsl extends CI_Controller {
* Used for CRON job
*/
public function sync() {
ini_set('memory_limit', '-1');
set_time_limit(0);
$this->load->model('eqslmethods_model');
if (ENVIRONMENT != 'maintenance') {
ini_set('memory_limit', '-1');
set_time_limit(0);
$this->load->model('eqslmethods_model');
$users = $this->eqslmethods_model->get_eqsl_users();
$users = $this->eqslmethods_model->get_eqsl_users();
foreach ($users as $user) {
$this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
$this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
foreach ($users as $user) {
$this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
$this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password);
}
} else {
echo "Maintenance Mode is active. Try again later.";
}
}

View File

@@ -12,29 +12,32 @@ class Hrdlog extends CI_Controller {
* All QSOs not previously uploaded, will then be uploaded, one at a time
*/
public function upload() {
$this->setOptions();
if (ENVIRONMENT != 'maintenance') {
$this->setOptions();
$this->load->model('logbook_model');
$this->load->model('logbook_model');
$station_ids = $this->logbook_model->get_station_id_with_hrdlog_code();
$station_ids = $this->logbook_model->get_station_id_with_hrdlog_code();
if ($station_ids) {
foreach ($station_ids as $station) {
$hrdlog_username = $station->hrdlog_username;
$hrdlog_code = $station->hrdlog_code;
if ($this->mass_upload_qsos($station->station_id, $hrdlog_username, $hrdlog_code)) {
echo "QSOs have been uploaded to hrdlog.net.";
log_message('info', 'QSOs have been uploaded to hrdlog.net.');
} else {
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
if ($station_ids) {
foreach ($station_ids as $station) {
$hrdlog_username = $station->hrdlog_username;
$hrdlog_code = $station->hrdlog_code;
if ($this->mass_upload_qsos($station->station_id, $hrdlog_username, $hrdlog_code)) {
echo "QSOs have been uploaded to hrdlog.net.";
log_message('info', 'QSOs have been uploaded to hrdlog.net.');
} else {
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
}
}
} else {
echo "No station profiles with a hrdlog Code found.";
log_message('error', "No station profiles with a hrdlog Code found.");
}
} else {
echo "No station profiles with a hrdlog Code found.";
log_message('error', "No station profiles with a hrdlog Code found.");
echo "Maintenance Mode is active. Try again later.";
}
}
function setOptions() {

View File

@@ -184,182 +184,186 @@ class Lotw extends CI_Controller {
|
*/
public function lotw_upload() {
if (ENVIRONMENT != 'maintenance') {
$this->load->model('user_model');
$this->user_model->authorize(2);
$this->load->model('user_model');
$this->user_model->authorize(2);
// Fire OpenSSL missing error if not found
if (!extension_loaded('openssl')) {
echo "You must install php OpenSSL for LoTW functions to work";
}
// Get Station Profile Data
$this->load->model('Stations');
if ($this->user_model->authorize(2)) {
$station_profiles = $this->Stations->all_of_user($this->session->userdata('user_id'));
$sync_user_id=$this->session->userdata('user_id');
} else {
$station_profiles = $this->Stations->all();
$sync_user_id=null;
}
// Array of QSO IDs being Uploaded
$qso_id_array = array();
// Build TQ8 Outputs
if ($station_profiles->num_rows() >= 1) {
foreach ($station_profiles->result() as $station_profile) {
// Get Certificate Data
$this->load->model('LotwCert');
$data['station_profile'] = $station_profile;
$data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc);
// If Station Profile has no LoTW Cert continue on.
if(!isset($data['lotw_cert_info']->cert_dxcc_id)) {
continue;
}
// Check if LoTW certificate itself is valid
// Validty of QSO dates will be checked later
$current_date = date('Y-m-d H:i:s');
if ($current_date <= $data['lotw_cert_info']->date_created) {
echo $data['lotw_cert_info']->callsign.": LoTW certificate not valid yet!";
continue;
}
if ($current_date >= $data['lotw_cert_info']->date_expires) {
echo $data['lotw_cert_info']->callsign.": LoTW certificate expired!";
continue;
}
// Get QSOs
$this->load->model('Logbook_model');
$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id, $data['lotw_cert_info']->qso_start_date, $data['lotw_cert_info']->qso_end_date);
// Nothing to upload
if(empty($data['qsos']->result())){
if ($this->user_model->authorize(2)) { // Only be verbose if we have a session
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") No QSOs to Upload <br>";
}
continue;
}
foreach ($data['qsos']->result() as $temp_qso) {
array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY);
}
// Build File to save
$adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE);
if (strpos($adif_to_save, '<SIGN_LOTW_V2.0:1:6>')) {
// Signing failed
echo "Signing failed.";
continue;
}
// create folder to store upload file
if (!file_exists('./uploads/lotw')) {
mkdir('./uploads/lotw', 0775, true);
}
// Build Filename
$filename_for_saving = './uploads/lotw/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['lotw_cert_info']->callsign))."-".date("Y-m-d-H-i-s")."-wavelog.tq8";
$gzdata = gzencode($adif_to_save, 9);
$fp = fopen($filename_for_saving, "w");
fwrite($fp, $gzdata);
fclose($fp);
//The URL that accepts the file upload.
$url = 'https://lotw.arrl.org/lotw/upload';
//The name of the field for the uploaded file.
$uploadFieldName = 'upfile';
//The full path to the file that you want to upload
$filePath = realpath($filename_for_saving);
//Initiate cURL
$ch = curl_init();
//Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
//Set the HTTP request to POST
curl_setopt($ch, CURLOPT_POST, true);
//Tell cURL to return the output as a string.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//If the function curl_file_create exists
if(function_exists('curl_file_create')){
//Use the recommended way, creating a CURLFile object.
$filePath = curl_file_create($filePath);
} else{
//Otherwise, do it the old way.
//Get the canonicalized pathname of our file and prepend
//the @ character.
$filePath = '@' . realpath($filePath);
//Turn off SAFE UPLOAD so that it accepts files
//starting with an @
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
//Setup our POST fields
$postFields = array(
$uploadFieldName => $filePath
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
//Execute the request
$result = curl_exec($ch);
//If an error occured, throw an exception
//with the error message.
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
$pos = strpos($result, "<!-- .UPL. accepted -->");
if ($pos === false) {
// Upload of TQ8 Failed for unknown reason
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."<br>";
} else {
// Upload of TQ8 was successfull
echo "Upload Successful - ".$filename_for_saving."<br>";
$this->LotwCert->last_upload($data['lotw_cert_info']->lotw_cert_id);
// Mark QSOs as Sent
foreach ($qso_id_array as $qso_number) {
$this->Logbook_model->mark_lotw_sent($qso_number);
}
}
// Delete TQ8 File - This is done regardless of whether upload was succcessful
unlink(realpath($filename_for_saving));
// Fire OpenSSL missing error if not found
if (!extension_loaded('openssl')) {
echo "You must install php OpenSSL for LoTW functions to work";
}
} else {
echo "No Station Profiles found to upload to LoTW";
}
/*
| Download QSO Matches from LoTW
*/
if ($this->user_model->authorize(2)) {
echo "<br><br>";
$sync_user_id=$this->session->userdata('user_id');
// Get Station Profile Data
$this->load->model('Stations');
if ($this->user_model->authorize(2)) {
$station_profiles = $this->Stations->all_of_user($this->session->userdata('user_id'));
$sync_user_id=$this->session->userdata('user_id');
} else {
$station_profiles = $this->Stations->all();
$sync_user_id=null;
}
// Array of QSO IDs being Uploaded
$qso_id_array = array();
// Build TQ8 Outputs
if ($station_profiles->num_rows() >= 1) {
foreach ($station_profiles->result() as $station_profile) {
// Get Certificate Data
$this->load->model('LotwCert');
$data['station_profile'] = $station_profile;
$data['lotw_cert_info'] = $this->LotwCert->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc);
// If Station Profile has no LoTW Cert continue on.
if(!isset($data['lotw_cert_info']->cert_dxcc_id)) {
continue;
}
// Check if LoTW certificate itself is valid
// Validty of QSO dates will be checked later
$current_date = date('Y-m-d H:i:s');
if ($current_date <= $data['lotw_cert_info']->date_created) {
echo $data['lotw_cert_info']->callsign.": LoTW certificate not valid yet!";
continue;
}
if ($current_date >= $data['lotw_cert_info']->date_expires) {
echo $data['lotw_cert_info']->callsign.": LoTW certificate expired!";
continue;
}
// Get QSOs
$this->load->model('Logbook_model');
$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id, $data['lotw_cert_info']->qso_start_date, $data['lotw_cert_info']->qso_end_date);
// Nothing to upload
if(empty($data['qsos']->result())){
if ($this->user_model->authorize(2)) { // Only be verbose if we have a session
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") No QSOs to Upload <br>";
}
continue;
}
foreach ($data['qsos']->result() as $temp_qso) {
array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY);
}
// Build File to save
$adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE);
if (strpos($adif_to_save, '<SIGN_LOTW_V2.0:1:6>')) {
// Signing failed
echo "Signing failed.";
continue;
}
// create folder to store upload file
if (!file_exists('./uploads/lotw')) {
mkdir('./uploads/lotw', 0775, true);
}
// Build Filename
$filename_for_saving = './uploads/lotw/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['lotw_cert_info']->callsign))."-".date("Y-m-d-H-i-s")."-wavelog.tq8";
$gzdata = gzencode($adif_to_save, 9);
$fp = fopen($filename_for_saving, "w");
fwrite($fp, $gzdata);
fclose($fp);
//The URL that accepts the file upload.
$url = 'https://lotw.arrl.org/lotw/upload';
//The name of the field for the uploaded file.
$uploadFieldName = 'upfile';
//The full path to the file that you want to upload
$filePath = realpath($filename_for_saving);
//Initiate cURL
$ch = curl_init();
//Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
//Set the HTTP request to POST
curl_setopt($ch, CURLOPT_POST, true);
//Tell cURL to return the output as a string.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//If the function curl_file_create exists
if(function_exists('curl_file_create')){
//Use the recommended way, creating a CURLFile object.
$filePath = curl_file_create($filePath);
} else{
//Otherwise, do it the old way.
//Get the canonicalized pathname of our file and prepend
//the @ character.
$filePath = '@' . realpath($filePath);
//Turn off SAFE UPLOAD so that it accepts files
//starting with an @
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
//Setup our POST fields
$postFields = array(
$uploadFieldName => $filePath
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
//Execute the request
$result = curl_exec($ch);
//If an error occured, throw an exception
//with the error message.
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
$pos = strpos($result, "<!-- .UPL. accepted -->");
if ($pos === false) {
// Upload of TQ8 Failed for unknown reason
echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."<br>";
} else {
// Upload of TQ8 was successfull
echo "Upload Successful - ".$filename_for_saving."<br>";
$this->LotwCert->last_upload($data['lotw_cert_info']->lotw_cert_id);
// Mark QSOs as Sent
foreach ($qso_id_array as $qso_number) {
$this->Logbook_model->mark_lotw_sent($qso_number);
}
}
// Delete TQ8 File - This is done regardless of whether upload was succcessful
unlink(realpath($filename_for_saving));
}
} else {
echo "No Station Profiles found to upload to LoTW";
}
/*
| Download QSO Matches from LoTW
*/
if ($this->user_model->authorize(2)) {
echo "<br><br>";
$sync_user_id=$this->session->userdata('user_id');
} else {
$sync_user_id=null;
}
echo $this->lotw_download($sync_user_id);
} else {
$sync_user_id=null;
}
echo $this->lotw_download($sync_user_id);
echo "Maintenance Mode is active. Try again later.";
}
}
/*

View File

@@ -17,28 +17,31 @@ class Qrz extends CI_Controller {
* All QSOs not previously uploaded, will then be uploaded, one at a time
*/
public function upload() {
$this->setOptions();
if (ENVIRONMENT != 'maintenance') {
$this->setOptions();
$this->load->model('logbook_model');
$this->load->model('logbook_model');
$station_ids = $this->logbook_model->get_station_id_with_qrz_api();
$station_ids = $this->logbook_model->get_station_id_with_qrz_api();
if ($station_ids) {
foreach ($station_ids as $station) {
$qrz_api_key = $station->qrzapikey;
if($this->mass_upload_qsos($station->station_id, $qrz_api_key, true)) {
echo "QSOs have been uploaded to QRZ.com.";
log_message('info', 'QSOs have been uploaded to QRZ.com.');
} else{
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
if ($station_ids) {
foreach ($station_ids as $station) {
$qrz_api_key = $station->qrzapikey;
if($this->mass_upload_qsos($station->station_id, $qrz_api_key, true)) {
echo "QSOs have been uploaded to QRZ.com.";
log_message('info', 'QSOs have been uploaded to QRZ.com.');
} else{
echo "No QSOs found for upload.";
log_message('info', 'No QSOs found for upload.');
}
}
} else {
echo "No station profiles with a QRZ API Key found.";
log_message('error', "No station profiles with a QRZ API Key found.");
}
} else {
echo "No station profiles with a QRZ API Key found.";
log_message('error', "No station profiles with a QRZ API Key found.");
echo "Maintenance Mode is active. Try again later.";
}
}
function setOptions() {
@@ -200,53 +203,57 @@ class Qrz extends CI_Controller {
} // end function
function download($user_id_to_load = null, $lastqrz = null, $show_views = false) {
$this->load->model('user_model');
$this->load->model('logbook_model');
if (ENVIRONMENT != 'maintenance') {
$this->load->model('user_model');
$this->load->model('logbook_model');
$api_keys = $this->logbook_model->get_qrz_apikeys();
$api_keys = $this->logbook_model->get_qrz_apikeys();
if ($api_keys) {
foreach ($api_keys as $station) {
if ((($user_id_to_load != null) && ($user_id_to_load != $station->user_id))) { // Skip User if we're called with a specific user_id
continue;
}
if ($lastqrz == null) {
$lastqrz = $this->logbook_model->qrz_last_qsl_date($station->user_id);
}
$qrz_api_key = $station->qrzapikey;
$result=($this->mass_download_qsos($qrz_api_key, $lastqrz));
if (isset($result['tableheaders'])) {
$data['tableheaders']=$result['tableheaders'];
if (isset($data['table'])) {
$data['table'].=$result['table'];
} else {
$data['table']=$result['table'];
if ($api_keys) {
foreach ($api_keys as $station) {
if ((($user_id_to_load != null) && ($user_id_to_load != $station->user_id))) { // Skip User if we're called with a specific user_id
continue;
}
if ($lastqrz == null) {
$lastqrz = $this->logbook_model->qrz_last_qsl_date($station->user_id);
}
$qrz_api_key = $station->qrzapikey;
$result=($this->mass_download_qsos($qrz_api_key, $lastqrz));
if (isset($result['tableheaders'])) {
$data['tableheaders']=$result['tableheaders'];
if (isset($data['table'])) {
$data['table'].=$result['table'];
} else {
$data['table']=$result['table'];
}
}
}
} else {
echo "No station profiles with a QRZ API Key found.";
log_message('error', "No station profiles with a QRZ API Key found.");
}
$this->load->model('user_model');
if ($this->user_model->authorize(2)) { // Only Output results if authorized User
if(isset($data['tableheaders'])) {
if ($data['table'] != '') {
$data['table'].='</table>';
}
if($show_views == TRUE) {
$data['page_title'] = "QRZ ADIF Information";
$this->load->view('interface_assets/header', $data);
$this->load->view('qrz/analysis');
$this->load->view('interface_assets/footer');
} else {
return '';
}
} else {
echo "Downloaded QRZ report contains no matches.";
}
}
} else {
echo "No station profiles with a QRZ API Key found.";
log_message('error', "No station profiles with a QRZ API Key found.");
}
$this->load->model('user_model');
if ($this->user_model->authorize(2)) { // Only Output results if authorized User
if(isset($data['tableheaders'])) {
if ($data['table'] != '') {
$data['table'].='</table>';
}
if($show_views == TRUE) {
$data['page_title'] = "QRZ ADIF Information";
$this->load->view('interface_assets/header', $data);
$this->load->view('qrz/analysis');
$this->load->view('interface_assets/footer');
} else {
return '';
}
} else {
echo "Downloaded QRZ report contains no matches.";
}
echo "Maintenance Mode is active. Try again later.";
}
}

View File

@@ -272,35 +272,39 @@ class Update extends CI_Controller {
}
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)
if (ENVIRONMENT != 'maintenance') {
$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)
{
$nCount = count(file($strFile));
if ($nCount > 0)
$data = "";
while (!gzeof($gz)) {
$data .= gzgetc($gz);
}
gzclose($gz);
if (file_put_contents($strFile, $data) !== FALSE)
{
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');
$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: Empty file";
echo "FAILED: Could not write to Club Log SCP file";
}
} else {
echo "FAILED: Could not write to Club Log SCP file";
echo "FAILED: Could not connect to Club Log";
}
} else {
echo "FAILED: Could not connect to Club Log";
echo "Maintenance Mode is active. Try again later.";
}
}
@@ -322,47 +326,51 @@ class Update extends CI_Controller {
}
public function lotw_users() {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
if (ENVIRONMENT != 'maintenance') {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$file = 'https://lotw.arrl.org/lotw-user-activity.csv';
$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++;
$handle = fopen($file, "r");
if ($handle === FALSE) {
echo "Something went wrong with fetching the LoTW uses file";
return;
}
} while ($data = fgetcsv($handle,1000,","));
fclose($handle);
$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);
$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');
$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');
} else {
echo "Maintenance Mode is active. Try again later.";
}
}
public function lotw_check() {
@@ -382,27 +390,31 @@ class Update extends CI_Controller {
* 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 (ENVIRONMENT != 'maintenance') {
$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";
}
if($contents === FALSE) {
echo "Something went wrong with fetching the DOK file.";
} else {
echo"FAILED: Could not write to dok.txt file";
$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";
}
}
} else {
echo "Maintenance Mode is active. Try again later.";
}
}
@@ -410,45 +422,49 @@ class Update extends CI_Controller {
* 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';
if (ENVIRONMENT != 'maintenance') {
$csvfile = 'https://www.sotadata.org.uk/summitslist.csv';
$sotafile = './assets/json/sota.txt';
$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++;
$csvhandle = fopen($csvfile,"r");
if ($csvhandle === FALSE) {
echo "Something went wrong with fetching the SOTA file";
return;
}
} while ($data = fgetcsv($csvhandle,1000,","));
fclose($csvhandle);
fclose($sotafilehandle);
$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 ($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');
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";
}
} else {
echo"FAILED: Empty file";
echo "Maintenance Mode is active. Try again later.";
}
}
@@ -456,95 +472,103 @@ class Update extends CI_Controller {
* Pulls the WWFF directory for autocompletion in QSO dialogs
*/
public function update_wwff() {
$csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv';
if (ENVIRONMENT != 'maintenance') {
$csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv';
$wwfffile = './assets/json/wwff.txt';
$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;
}
$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;
}
$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++;
}
}
$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);
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');
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";
}
} else {
echo"FAILED: Empty file";
echo "Maintenance Mode is active. Try again later.";
}
}
public function update_pota() {
$csvfile = 'https://pota.app/all_parks.csv';
if (ENVIRONMENT != 'maintenance') {
$csvfile = 'https://pota.app/all_parks.csv';
$potafile = './assets/json/pota.txt';
$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;
}
$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++;
}
}
$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);
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');
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";
}
} else {
echo"FAILED: Empty file";
echo "Maintenance Mode is active. Try again later.";
}
}