diff --git a/application/controllers/Clublog.php b/application/controllers/Clublog.php index 74fa0cc5e..5aa2b630d 100644 --- a/application/controllers/Clublog.php +++ b/application/controllers/Clublog.php @@ -6,6 +6,16 @@ class Clublog extends CI_Controller { + function __construct() + { + parent::__construct(); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } + } + // Show frontend if there is one public function index() { $this->config->load('config'); @@ -13,16 +23,12 @@ class Clublog extends CI_Controller { // Upload ADIF to Clublog public function upload() { - if (ENVIRONMENT != 'maintenance') { - $this->load->model('clublog_model'); + $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); - } - } else { - echo "Maintenance Mode is active. Try again later."; + foreach ($users as $user) { + $this->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); } } diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 385597705..f82a1d9c8 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -4,8 +4,15 @@ class eqsl extends CI_Controller { /* Controls who can access the controller and its functions */ function __construct() { + parent::__construct(); + $this->load->helper(array('form', 'url')); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } } // Default view when loading controller. @@ -704,19 +711,15 @@ class eqsl extends CI_Controller { * Used for CRON job */ public function sync() { - if (ENVIRONMENT != 'maintenance') { - ini_set('memory_limit', '-1'); - set_time_limit(0); - $this->load->model('eqslmethods_model'); + 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); - } - } else { - echo "Maintenance Mode is active. Try again later."; + 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); } } diff --git a/application/controllers/Hrdlog.php b/application/controllers/Hrdlog.php index 41d27fd52..2b3182b49 100644 --- a/application/controllers/Hrdlog.php +++ b/application/controllers/Hrdlog.php @@ -11,32 +11,39 @@ class Hrdlog extends CI_Controller { * When called from the url wavelog/hrdlog/upload, the function loops through all station_id's with a hrdlog code defined. * All QSOs not previously uploaded, will then be uploaded, one at a time */ + + function __construct() + { + parent::__construct(); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } + } + public function upload() { - if (ENVIRONMENT != 'maintenance') { - $this->setOptions(); + $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 "Maintenance Mode is active. Try again later."; + echo "No station profiles with a hrdlog Code found."; + log_message('error', "No station profiles with a hrdlog Code found."); } } diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index bbdc2bb24..ffdea9090 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -26,6 +26,11 @@ class Lotw extends CI_Controller { // Load language files $this->lang->load('lotw'); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } } /* @@ -184,186 +189,182 @@ 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"; - } + // 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'); + // 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
"; - } - 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, '')) { - // 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, ""); - - if ($pos === false) { - // Upload of TQ8 Failed for unknown reason - echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."
"; - } else { - // Upload of TQ8 was successfull - - echo "Upload Successful - ".$filename_for_saving."
"; - - $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 "

"; - $sync_user_id=$this->session->userdata('user_id'); - } else { - $sync_user_id=null; - } - echo $this->lotw_download($sync_user_id); + 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 { - echo "Maintenance Mode is active. Try again later."; - } + $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
"; + } + 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, '')) { + // 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, ""); + + if ($pos === false) { + // Upload of TQ8 Failed for unknown reason + echo $station_profile->station_callsign." (".$station_profile->station_profile_name.") Upload Failed"."
"; + } else { + // Upload of TQ8 was successfull + + echo "Upload Successful - ".$filename_for_saving."
"; + + $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 "

"; + $sync_user_id=$this->session->userdata('user_id'); + } else { + $sync_user_id=null; + } + echo $this->lotw_download($sync_user_id); } /* diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index e5e670a20..a4507bdd9 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -6,6 +6,16 @@ class Qrz extends CI_Controller { + function __construct() + { + parent::__construct(); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } + } + // Show frontend if there is one public function index() { $this->config->load('config'); @@ -17,30 +27,26 @@ class Qrz extends CI_Controller { * All QSOs not previously uploaded, will then be uploaded, one at a time */ public function upload() { - if (ENVIRONMENT != 'maintenance') { - $this->setOptions(); + $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 "Maintenance Mode is active. Try again later."; + echo "No station profiles with a QRZ API Key found."; + log_message('error', "No station profiles with a QRZ API Key found."); } } @@ -203,58 +209,54 @@ class Qrz extends CI_Controller { } // end function function download($user_id_to_load = null, $lastqrz = null, $show_views = false) { - if (ENVIRONMENT != 'maintenance') { - $this->load->model('user_model'); - $this->load->model('logbook_model'); + $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); } - } 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'].=''; - } - 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'); + $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 { - return ''; + $data['table']=$result['table']; } - } else { - echo "Downloaded QRZ report contains no matches."; } } } else { - echo "Maintenance Mode is active. Try again later."; - } + 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'].=''; + } + 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."; + } + } } function mass_download_qsos($qrz_api_key = '', $lastqrz = '1900-01-01', $trusted = false) { diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 6c14c9131..6ff666e4a 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -8,6 +8,16 @@ class Update extends CI_Controller { lotw_users - imports lotw users */ + function __construct() + { + parent::__construct(); + + if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { + echo "Maintenance Mode is active. Try again later.\n"; + redirect('user/login'); + } + } + public function index() { $data['page_title'] = "Updates"; @@ -272,39 +282,35 @@ class Update extends CI_Controller { } public function update_clublog_scp() { - 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...
"; - $gz = gzopen($url, 'r'); - if ($gz) + $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...
"; + $gz = gzopen($url, 'r'); + if ($gz) + { + $data = ""; + while (!gzeof($gz)) { + $data .= gzgetc($gz); + } + gzclose($gz); + if (file_put_contents($strFile, $data) !== FALSE) { - $data = ""; - while (!gzeof($gz)) { - $data .= gzgetc($gz); - } - gzclose($gz); - if (file_put_contents($strFile, $data) !== FALSE) + $nCount = count(file($strFile)); + if ($nCount > 0) { - $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"; - } + 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: Could not write to Club Log SCP file"; + echo "FAILED: Empty file"; } } else { - echo "FAILED: Could not connect to Club Log"; + echo "FAILED: Could not write to Club Log SCP file"; } } else { - echo "Maintenance Mode is active. Try again later."; + echo "FAILED: Could not connect to Club Log"; } } @@ -326,51 +332,47 @@ class Update extends CI_Controller { } public function lotw_users() { - if (ENVIRONMENT != 'maintenance') { - $mtime = microtime(); - $mtime = explode(" ",$mtime); - $mtime = $mtime[1] + $mtime[0]; - $starttime = $mtime; + $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 . '
'; - } - $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
"; - echo "Records inserted: " . $i . "
"; - $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."; + $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 . '
'; + } + $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
"; + echo "Records inserted: " . $i . "
"; + $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() { @@ -390,31 +392,27 @@ 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() { - if (ENVIRONMENT != 'maintenance') { - $contents = file_get_contents('https://www.df2et.de/cqrlog/dok_and_sdok.txt', true); + $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"; - } - } + if($contents === FALSE) { + echo "Something went wrong with fetching the DOK file."; } else { - echo "Maintenance Mode is active. Try again later."; + $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"; + } } } @@ -422,49 +420,45 @@ 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() { - if (ENVIRONMENT != 'maintenance') { - $csvfile = 'https://www.sotadata.org.uk/summitslist.csv'; + $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; + $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,",")); - $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'); + fclose($csvhandle); + fclose($sotafilehandle); - 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"; - } + 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 "Maintenance Mode is active. Try again later."; + echo"FAILED: Empty file"; } } @@ -472,103 +466,95 @@ class Update extends CI_Controller { * Pulls the WWFF directory for autocompletion in QSO dialogs */ public function update_wwff() { - if (ENVIRONMENT != 'maintenance') { - $csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv'; + $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'); - } else { - echo"FAILED: Empty file"; - } + 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 "Maintenance Mode is active. Try again later."; + echo"FAILED: Empty file"; } } public function update_pota() { - if (ENVIRONMENT != 'maintenance') { - $csvfile = 'https://pota.app/all_parks.csv'; + $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'); - } else { - echo"FAILED: Empty file"; - } + 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 "Maintenance Mode is active. Try again later."; + echo"FAILED: Empty file"; } }