kopia lustrzana https://github.com/magicbug/Cloudlog
commit
99213ed063
|
@ -1,3 +1,6 @@
|
|||
/application/config/database.php
|
||||
/application/config/config.php
|
||||
/uploads/*.adi
|
||||
/uploads/*.ADI
|
||||
/uploads/*.tq8
|
||||
/uploads/*.TQ8
|
||||
|
|
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
|||
| be upgraded / downgraded to.
|
||||
|
|
||||
*/
|
||||
$config['migration_version'] = 2;
|
||||
$config['migration_version'] = 3;
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -101,8 +101,10 @@ $mimes = array( 'hqx' => 'application/mac-binhex40',
|
|||
'json' => array('application/json', 'text/json'),
|
||||
'adi' => 'application/octet-stream',
|
||||
'ADI' => 'application/octet-stream',
|
||||
'tq8' => 'application/octet-stream',
|
||||
'TQ8' => 'application/octet-stream',
|
||||
);
|
||||
|
||||
|
||||
/* End of file mimes.php */
|
||||
/* Location: ./application/config/mimes.php */
|
||||
/* Location: ./application/config/mimes.php */
|
||||
|
|
|
@ -49,6 +49,23 @@ class adif extends CI_Controller {
|
|||
|
||||
}
|
||||
|
||||
public function export_lotw()
|
||||
{
|
||||
// Set memory limit to unlimited to allow heavy usage
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$this->load->model('adif_data');
|
||||
|
||||
$data['qsos'] = $this->adif_data->export_lotw();
|
||||
|
||||
$this->load->view('adif/data/exportall', $data);
|
||||
|
||||
foreach ($data['qsos']->result() as $qso)
|
||||
{
|
||||
$this->adif_data->mark_lotw_sent($qso->COL_PRIMARY_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
public function import() {
|
||||
$data['page_title'] = "ADIF Import";
|
||||
|
||||
|
|
|
@ -118,14 +118,11 @@ class Lotw extends CI_Controller {
|
|||
// TODO: We don't actually see the error message
|
||||
if ($data['user_lotw_name'] == '' || $data['user_lotw_password'] == '')
|
||||
{
|
||||
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('dashboard');
|
||||
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('lotw/import');
|
||||
}
|
||||
|
||||
// Query the logbook to determine when the last LoTW confirmation was
|
||||
$lotw_last_qsl_date = $this->logbook_model->lotw_last_qsl_date();
|
||||
|
||||
// TODO: Consolidate code
|
||||
// TODO: Specifiy in config file whether we want LoTW confirms as V or Y. Both are acceptable under ADIF specification. HRD seems to use V. Everyone else that I've used uses Y.
|
||||
|
||||
// Build URL for LoTW report file
|
||||
$lotw_url .= "?";
|
||||
|
@ -167,4 +164,128 @@ class Lotw extends CI_Controller {
|
|||
}
|
||||
}
|
||||
} // end function
|
||||
|
||||
public function export() {
|
||||
$data['page_title'] = "LoTW .TQ8 Upload";
|
||||
|
||||
$config['upload_path'] = './uploads/';
|
||||
$config['allowed_types'] = 'tq8|TQ8';
|
||||
|
||||
$this->load->library('upload', $config);
|
||||
|
||||
if ( ! $this->upload->do_upload())
|
||||
{
|
||||
$data['error'] = $this->upload->display_errors();
|
||||
|
||||
$this->load->view('layout/header', $data);
|
||||
$this->load->view('lotw/export');
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = array('upload_data' => $this->upload->data());
|
||||
|
||||
// Figure out how we should be marking QSLs confirmed via LoTW
|
||||
$query = $query = $this->db->query('SELECT lotw_login_url FROM config');
|
||||
$q = $query->row();
|
||||
$config['lotw_login_url'] = $q->lotw_login_url;
|
||||
|
||||
// Set some fields that we're going to need for ARRL login
|
||||
$query = $this->user_model->get_by_id($this->session->userdata('user_id'));
|
||||
$q = $query->row();
|
||||
$fields['login'] = $q->user_lotw_name;
|
||||
$fields['password'] = $q->user_lotw_password;
|
||||
$fields['acct_sel'] = "";
|
||||
|
||||
if ($fields['login'] == '' || $fields['password'] == '')
|
||||
{
|
||||
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('lotw/status');
|
||||
}
|
||||
|
||||
// Curl stuff goes here
|
||||
|
||||
// First we need to get a cookie
|
||||
|
||||
// options
|
||||
$cookie_file_path = "./uploads/cookies.txt";
|
||||
$agent = "Mozilla/4.0 (compatible;)";
|
||||
|
||||
// begin script
|
||||
$ch = curl_init();
|
||||
|
||||
// extra headers
|
||||
$headers[] = "Accept: */*";
|
||||
$headers[] = "Connection: Keep-Alive";
|
||||
|
||||
// basic curl options for all requests
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
|
||||
// TODO: These SSL things should probably be set to true :)
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
|
||||
|
||||
// Set login URL
|
||||
curl_setopt($ch, CURLOPT_URL, $config['lotw_login_url']);
|
||||
|
||||
// set postfields using what we extracted from the form
|
||||
$POSTFIELDS = http_build_query($fields);
|
||||
|
||||
// set post options
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
|
||||
|
||||
// perform login
|
||||
$result = curl_exec($ch);
|
||||
if (stristr($result, "Username/password incorrect"))
|
||||
{
|
||||
$this->session->set_flashdata('warning', 'Your ARRL username and/or password is incorrect.'); redirect('lotw/status');
|
||||
}
|
||||
|
||||
|
||||
// Now we need to use that cookie and upload the file
|
||||
// change URL to upload destination URL
|
||||
curl_setopt($ch, CURLOPT_URL, $config['lotw_login_url']);
|
||||
|
||||
// Grab the file
|
||||
$postfile = array(
|
||||
"upfile"=>"@./uploads/".$data['upload_data']['file_name'],
|
||||
);
|
||||
|
||||
//Upload it
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfile);
|
||||
$response = curl_exec($ch);
|
||||
if (stristr($response, "accepted"))
|
||||
{
|
||||
$this->session->set_flashdata('lotw_status', 'accepted');
|
||||
$data['page_title'] = "LoTW .TQ8 Sent";
|
||||
}
|
||||
elseif (stristr($response, "rejected"))
|
||||
{
|
||||
$this->session->set_flashdata('lotw_status', 'rejected');
|
||||
$data['page_title'] = "LoTW .TQ8 Sent";
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're here, we didn't find what we're looking for in the ARRL response
|
||||
// and LoTW is probably down or broken.
|
||||
$this->session->set_flashdata('warning', 'Did not receive proper response from LoTW. Try again later.');
|
||||
$data['page_title'] = "LoTW .TQ8 Not Sent";
|
||||
}
|
||||
|
||||
// Now we need to clean up
|
||||
unlink($cookie_file_path);
|
||||
unlink('./uploads/'.$data['upload_data']['file_name']);
|
||||
|
||||
$this->load->view('layout/header', $data);
|
||||
$this->load->view('lotw/status');
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
} // end class
|
|
@ -0,0 +1,21 @@
|
|||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_lotw_login_url extends CI_Migration {
|
||||
|
||||
public function up()
|
||||
{
|
||||
$fields = array('lotw_login_url VARCHAR(244) DEFAULT NULL');
|
||||
|
||||
$this->dbforge->add_column('config', $fields);
|
||||
|
||||
$sql = "UPDATE config SET lotw_login_url = 'https://p1k.arrl.org/lotwuser/default' WHERE id=1";
|
||||
|
||||
$this->db->query($sql);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->dbforge->drop_column('config', 'lotw_login_url');
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -23,6 +23,24 @@ class adif_data extends CI_Model {
|
|||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function export_lotw() {
|
||||
$this->db->where("COL_LOTW_QSL_SENT != 'Y'");
|
||||
$this->db->order_by("COL_TIME_ON", "ASC");
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function mark_lotw_sent($id) {
|
||||
$data = array(
|
||||
'COL_LOTW_QSL_SENT' => 'Y'
|
||||
);
|
||||
|
||||
$this->db->set('COL_LOTW_QSLSDATE', 'CURDATE()', FALSE);
|
||||
$this->db->where('COL_PRIMARY_KEY', $id);
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
<li><a href="<?php echo site_url('export');?>" title="Data Export">Data Export</a></li>
|
||||
<li><a href="<?php echo site_url('api/help');?>" title="API">API</a></li>
|
||||
<li><a href="<?php echo site_url('lotw/import');?>" title="LoTW Import">LoTW Import</a></li>
|
||||
<li><a href="<?php echo site_url('lotw/export');?>" title="LoTW Export">LoTW Export</a></li>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<div id="container">
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
<?php if($this->session->flashdata('warning')) { ?>
|
||||
<div id="message" >
|
||||
<?php echo $this->session->flashdata('warning'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<h4>Step 1</h4>
|
||||
<a href="<?php echo site_url('adif/export_lotw'); ?>" title="Export LoTW" target="_blank">Export an ADIF</a> file of QSOs that have not been uploaded to LoTW.
|
||||
|
||||
<h4>Step 2</h4>
|
||||
<p>Use Trusted QSL to sign the exported file.</p>
|
||||
|
||||
<h4>Step 3</h4>
|
||||
<p>Select the signed file and click "Upload". It will be sent to LoTW for processing.</p>
|
||||
|
||||
<?php echo form_open_multipart('lotw/export');?>
|
||||
<p><span class="label important">Important</span> Log files must have the file type .tq8</p>
|
||||
<input type="file" name="userfile" size="20" />
|
||||
|
||||
<p>Cloudlog will use the LoTW username an password stored in your user profile to download a report from LoTW for you. The report Cloudlog downloads will have all confirmations since your last LoTW confirmation, up until now.</p>
|
||||
|
||||
<input class="btn primary" type="submit" value="Upload" />
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
|
@ -0,0 +1,15 @@
|
|||
<div id="container">
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
<?php if($this->session->flashdata('warning')) { ?>
|
||||
<div id="message" >
|
||||
<?php echo $this->session->flashdata('warning'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if($this->session->flashdata('lotw_status')) { ?>
|
||||
<div id="message" >
|
||||
<?php echo $this->session->flashdata('lotw_status'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
Ładowanie…
Reference in New Issue