diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 76b0cca1..ff809020 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -820,18 +820,25 @@ class Logbook extends CI_Controller { $html .= ""; return $html; } else { - if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { + // if session data callbook_type is qrz + if ($this->session->userdata('callbook_type') == "QRZ") { // Lookup using QRZ $this->load->library('qrz'); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + if(!$this->session->userdata('qrz_session_key')) { - $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('qrz_session_key', $qrz_session_key); } $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); if (empty($callsign['callsign']['callsign'])) { - $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('qrz_session_key', $qrz_session_key); $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); } @@ -840,12 +847,19 @@ class Logbook extends CI_Controller { $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); $callsign['callsign']['dxcc_name'] = $entity['name']; } - } else if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { + } elseif ($this->session->userdata('callbook_type') == "HamQTH") { // Load the HamQTH library $this->load->library('hamqth'); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('hamqth_session_key')) { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); } @@ -853,7 +867,7 @@ class Logbook extends CI_Controller { // If HamQTH session has expired, start a new session and retry the search. if($callsign['callsign']['error'] == "Session does not exist or expired") { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); $callsign['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); } @@ -873,13 +887,6 @@ class Logbook extends CI_Controller { $callsign['error'] = 'Lookup not configured. Please review configuration.'; } - // There's no hamli integration? Disabled for now. - /*else { - // Lookup using hamli - $this->load->library('hamli'); - - $callsign['callsign'] = $this->hamli->callsign($id); - }*/ if (isset($callsign['callsign']['gridsquare'])) { $this->load->model('logbook_model'); @@ -929,65 +936,72 @@ class Logbook extends CI_Controller { $this->load->view('view_log/partial/log_ajax.php', $data); } else { - if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { + // if session data callbook_type is qrz + if ($this->session->userdata('callbook_type') == "QRZ") { // Lookup using QRZ $this->load->library('qrz'); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + if(!$this->session->userdata('qrz_session_key')) { - $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('qrz_session_key', $qrz_session_key); } + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - $data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - if (isset($data['callsign']['gridsquare'])) { + if (empty($callsign['callsign']['callsign'])) { + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); + $this->session->set_userdata('qrz_session_key', $qrz_session_key); + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); + } + if (isset($callsign['callsign']['dxcc'])) { $this->load->model('logbook_model'); - $data['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + $callsign['callsign']['dxcc_name'] = $entity['name']; } - if (isset($data['callsign']['dxcc'])) { - $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($data['callsign']['dxcc']); - $data['callsign']['dxcc_name'] = $entity['name']; - } - if (isset($data['callsign']['error'])) { - $data['error'] = $data['callsign']['error']; - } - } else if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { + } elseif ($this->session->userdata('callbook_type') == "HamQTH") { // Load the HamQTH library $this->load->library('hamqth'); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('hamqth_session_key')) { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); } - $data['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + $callsign['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); // If HamQTH session has expired, start a new session and retry the search. - if($data['callsign']['error'] == "Session does not exist or expired") { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + if($callsign['callsign']['error'] == "Session does not exist or expired") { + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); - $data['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + $callsign['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); } if (isset($data['callsign']['gridsquare'])) { $this->load->model('logbook_model'); - $data['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + $callsign['grid_worked'] = $this->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); } - if (isset($data['callsign']['dxcc'])) { + if (isset($callsign['callsign']['dxcc'])) { $this->load->model('logbook_model'); - $entity = $this->logbook_model->get_entity($data['callsign']['dxcc']); - $data['callsign']['dxcc_name'] = $entity['name']; + $entity = $this->logbook_model->get_entity($callsign['callsign']['dxcc']); + $callsign['callsign']['dxcc_name'] = $entity['name']; } - if (isset($data['callsign']['error'])) { - $data['error'] = $data['callsign']['error']; + if (isset($callsign['callsign']['error'])) { + $callsign['error'] = $callsign['callsign']['error']; } } else { - $data['error'] = 'Lookup not configured. Please review configuration.'; - } /*else { - // Lookup using hamli - $this->load->library('hamli'); - - $data['callsign'] = $this->hamli->callsign($id); - }*/ + $callsign['error'] = 'Lookup not configured. Please review configuration.'; + } $data['id'] = strtoupper($id); diff --git a/application/controllers/User.php b/application/controllers/User.php index 9ec6ffe9..5cb9da11 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -210,7 +210,10 @@ class User extends CI_Controller $this->input->post('user_quicklog_enter'), $this->input->post('language'), $this->input->post('user_hamsat_key'), - $this->input->post('user_hamsat_workable_only') + $this->input->post('user_hamsat_workable_only'), + $this->input->post('user_callbook_type'), + $this->input->post('user_callbook_username'), + $this->input->post('user_callbook_password') )) { // Check for errors case EUSERNAMEEXISTS: @@ -228,6 +231,8 @@ class User extends CI_Controller redirect('user'); return; } + + $data['page_title'] = "Users"; $this->load->view('interface_assets/header', $data); @@ -571,6 +576,43 @@ class User extends CI_Controller $data['user_winkey'] = $q->winkey; } + $this->load->model('user_options_model'); + $callbook_type_object = $this->user_options_model->get_options('callbook')->result(); + + if ($this->input->post('user_callbook_type', true)) { + $data['user_callbook_type'] = $this->input->post('user_callbook_type', true); + } else { + if (isset($callbook_type_object[1]->option_value)) { + $data['user_callbook_type'] = $callbook_type_object[1]->option_value; + } else { + $data['user_callbook_type'] = ""; + } + } + + + // Handle user_callbook_username + if ($this->input->post('user_callbook_username', true)) { + $data['user_callbook_username'] = $this->input->post('user_callbook_username', true); + } else { + if (isset($callbook_type_object[2]->option_value)) { + $data['user_callbook_username'] = $callbook_type_object[2]->option_value; + } else { + $data['user_callbook_username'] = ""; + } + } + + // Handle user_callbook_password + if ($this->input->post('user_callbook_password', true)) { + $data['user_callbook_password'] = $this->input->post('user_callbook_password', true); + } else { + if (isset($callbook_type_object[0]->option_value)) { + $data['user_callbook_password'] = $callbook_type_object[0]->option_value; + } else { + $data['user_callbook_password'] = ""; + } + } + + $this->load->model('user_options_model'); $hamsat_user_object = $this->user_options_model->get_options('hamsat')->result(); @@ -595,8 +637,6 @@ class User extends CI_Controller } } - // Get Settings for Dashboard - // Set defaults $data['dashboard_upcoming_dx_card'] = false; $data['dashboard_qslcard_card'] = false; @@ -715,6 +755,33 @@ class User extends CI_Controller $this->input->set_cookie($cookie); } if ($this->session->userdata('user_id') == $this->input->post('id', true)) { + + // Handle user_callbook_type + if (isset($_POST['user_callbook_type'])) { + $this->user_options_model->set_option('callbook', 'callbook_type', array('value' => $_POST['user_callbook_type'])); + } else { + $this->user_options_model->set_option('callbook', 'callbook_type', array('value' => '')); + } + + // Handle user_callbook_username + if (isset($_POST['user_callbook_username'])) { + $this->user_options_model->set_option('callbook', 'callbook_username', array('value' => $_POST['user_callbook_username'])); + } else { + $this->user_options_model->set_option('callbook', 'callbook_username', array('value' => '')); + } + + // Handle user_callbook_password + if (isset($_POST['user_callbook_password']) && !empty($_POST['user_callbook_password'])) { + // Load the encryption library + $this->load->library('encryption'); + + // Encrypt the password + $encrypted_password = $this->encryption->encrypt($_POST['user_callbook_password']); + + // Save the encrypted password + $this->user_options_model->set_option('callbook', 'callbook_password', array('value' => $encrypted_password)); + } + if (isset($_POST['user_dashboard_enable_dxpedition_card'])) { $this->user_options_model->set_option('dashboard', 'dashboard_upcoming_dx_card', array('enabled' => 'true')); } else { @@ -958,7 +1025,6 @@ class User extends CI_Controller 'secure' => FALSE ); - $this->input->set_cookie($cookie); // Create a remember me cookie if ($this->input->post('remember_me') == '1') { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 1c38fcdc..02dae33f 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4437,30 +4437,38 @@ class Logbook_model extends CI_Model if ($r->num_rows() > 0) { foreach ($r->result_array() as $row) { $callsign = $row['COL_CALL']; - if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { - // Lookup using QRZ - if (!$this->load->is_loaded('qrz')) { - $this->load->library('qrz'); - } + if ($this->session->userdata('callbook_type') == "QRZ") { + // Lookup using QRZ + $this->load->library('qrz'); - if (!$this->session->userdata('qrz_session_key')) { - $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); - $this->session->set_userdata('qrz_session_key', $qrz_session_key); - } + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('qrz_session_key')) { + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); + $this->session->set_userdata('qrz_session_key', $qrz_session_key); + } $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key')); } - if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { - // Load the HamQTH library - if (!$this->load->is_loaded('hamqth')) { - $this->load->library('hamqth'); - } + if ($this->session->userdata('callbook_type') == "HamQTH") { + // Load the HamQTH library + $this->load->library('hamqth'); - if (!$this->session->userdata('hamqth_session_key')) { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); - $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); - } + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('hamqth_session_key')) { + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); + $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); + } $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); @@ -4572,12 +4580,18 @@ class Logbook_model extends CI_Model { $callbook = null; try { - if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { + if ($this->session->userdata('callbook_type') == "QRZ") { // Lookup using QRZ $this->load->library('qrz'); - if (!$this->session->userdata('qrz_session_key')) { - $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('qrz_session_key')) { + $qrz_session_key = $this->qrz->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('qrz_session_key', $qrz_session_key); } @@ -4595,12 +4609,18 @@ class Logbook_model extends CI_Model } } - if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { + if ($this->session->userdata('callbook_type') == "HamQTH") { // Load the HamQTH library $this->load->library('hamqth'); - if (!$this->session->userdata('hamqth_session_key')) { - $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); + // Load the encryption library + $this->load->library('encryption'); + + // Decrypt the password + $decrypted_password = $this->encryption->decrypt($this->session->userdata('callbook_password')); + + if(!$this->session->userdata('hamqth_session_key')) { + $hamqth_session_key = $this->hamqth->session($this->session->userdata('callbook_username'), $decrypted_password); $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); } diff --git a/application/models/User_model.php b/application/models/User_model.php index b25d4d0d..43c9466b 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -150,7 +150,7 @@ class User_Model extends CI_Model { $user_pota_lookup, $user_show_notes, $user_column1, $user_column2, $user_column3, $user_column4, $user_column5, $user_show_profile_image, $user_previous_qsl_type, $user_amsat_status_upload, $user_mastodon_url, $user_default_band, $user_default_confirmation, $user_qso_end_times, $user_quicklog, $user_quicklog_enter, - $language, $user_hamsat_key, $user_hamsat_workable_only) { + $language, $user_hamsat_key, $user_hamsat_workable_only, $callbook_type, $callbook_username, $callbook_password) { // Check that the user isn't already used if(!$this->exists($username)) { $data = array( @@ -206,6 +206,19 @@ class User_Model extends CI_Model { $this->db->query("insert into paper_types (user_id,paper_name,metric,width,orientation,height) SELECT ".$insert_id.", paper_name, metric, width, orientation,height FROM paper_types where user_id = -1;"); $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'hamsat','hamsat_key','api','".xss_clean($user_hamsat_key)."');"); $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'hamsat','hamsat_key','workable','".xss_clean($user_hamsat_workable_only)."');"); + + $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'callbook','callbook_type','value','".xss_clean($callbook_type)."');"); + $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'callbook','callbook_username','value','".xss_clean($callbook_username)."');"); + + // Load the encryption library + $this->load->library('encryption'); + + // Encrypt the password + $encrypted_password = $this->encryption->encrypt($callbook_password); + + // Insert the encrypted password into the database + $this->db->query("INSERT INTO user_options (user_id, option_type, option_name, option_key, option_value) VALUES (" . $insert_id . ", 'callbook', 'callbook_password', 'password', '" . xss_clean($encrypted_password) . "');"); + return OK; } else { return EUSERNAMEEXISTS; @@ -348,6 +361,31 @@ class User_Model extends CI_Model { // TODO: This should return bool TRUE/FALSE or 0/1 function update_session($id) { + $CI =& get_instance(); + $CI->load->model('user_options_model'); + $callbook_type_object = $CI->user_options_model->get_options('callbook')->result(); + + // Get the callbook type + if (isset($callbook_type_object[1]->option_value)) { + $callbook_type = $callbook_type_object[1]->option_value; + } else { + $callbook_type = "None"; + } + + // Get the callbook type + if (isset($callbook_type_object[2]->option_value)) { + $callbook_username = $callbook_type_object[2]->option_value; + } else { + $callbook_username = ""; + } + + // Get the callbook type + if (isset($callbook_type_object[0]->option_value)) { + $callbook_password = $callbook_type_object[0]->option_value; + } else { + $callbook_password = ""; + } + $u = $this->get_by_id($id); $userdata = array( @@ -388,7 +426,10 @@ class User_Model extends CI_Model { 'active_station_logbook' => $u->row()->active_station_logbook, 'language' => isset($u->row()->language) ? $u->row()->language: 'english', 'isWinkeyEnabled' => $u->row()->winkey, - 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id) + 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id), + 'callbook_type' => $callbook_type, + 'callbook_username' => $callbook_username, + 'callbook_password' => $callbook_password, ); $this->session->set_userdata($userdata); diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 1cecafa6..1e20e791 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -1001,6 +1001,49 @@ + +
+
+
Callbook
+
+
+ + + " . $callbook_type_error . ""; + } ?> +
+ +
+ + + " . $callbook_username_error . ""; + } ?> +
+ +
+ +
+ + +
+ " . $callbook_password_error . ""; + } else { ?> + + +
+
+
+
+
@@ -1031,7 +1074,9 @@
+ +