diff --git a/application/controllers/Visitor.php b/application/controllers/Visitor.php index da37e7bd..031af7ce 100644 --- a/application/controllers/Visitor.php +++ b/application/controllers/Visitor.php @@ -11,6 +11,9 @@ class Visitor extends CI_Controller { if($method == "config") { $this->$method(); } + elseif($method == "map") { + $this->map($method); + } else { $this->index($method); } @@ -22,26 +25,156 @@ class Visitor extends CI_Controller { public function index($public_slug = NULL) { - // If environment is set to development then show the debug toolbar - if(ENVIRONMENT == 'development') { - $this->output->enable_profiler(TRUE); - } + $this->load->model('user_model'); + + // Check if users logged in + if($this->user_model->validate_session() != 0) { + // If environment is set to development then show the debug toolbar + if(ENVIRONMENT == 'development') { + $this->output->enable_profiler(TRUE); + } + } // Check slug passed and is valid if ($this->security->xss_clean($public_slug, TRUE) === FALSE) { - // file failed the XSS test# + // Public Slug failed the XSS test log_message('error', '[Visitor] XSS Attack detected on public_slug '. $public_slug); show_404('Unknown Public Page.'); } else { // Checked slug passed and clean log_message('info', '[Visitor] public_slug '. $public_slug .' loaded'); - echo $public_slug = $this->security->xss_clean($public_slug); - // Check if the slug is contained in the station_logbooks table + $this->load->model('logbooks_model'); + if($this->logbooks_model->public_slug_exists($public_slug)) { + // Load the public view + if($logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($public_slug) != false) + { + // Get associated station locations for mysql queries + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); + } else { + log_message('error', $public_slug.' has no associated station locations'); + show_404('Unknown Public Page.'); + } + + $this->load->model('logbook_model'); + + // Public visitor so no QRA to setup + $data['qra'] = "none"; + + $this->load->model('cat'); + + $data['radio_status'] = $this->cat->recent_status(); + + // Store info + $data['todays_qsos'] = $this->logbook_model->todays_qsos($logbooks_locations_array); + $data['total_qsos'] = $this->logbook_model->total_qsos($logbooks_locations_array); + $data['month_qsos'] = $this->logbook_model->month_qsos($logbooks_locations_array); + $data['year_qsos'] = $this->logbook_model->year_qsos($logbooks_locations_array); + + // Load Countries Breakdown data into array + $CountriesBreakdown = $this->logbook_model->total_countries_confirmed($logbooks_locations_array); + + $data['total_countries'] = $CountriesBreakdown['Countries_Worked']; + $data['total_countries_confirmed_paper'] = $CountriesBreakdown['Countries_Worked_QSL']; + $data['total_countries_confirmed_eqsl'] = $CountriesBreakdown['Countries_Worked_EQSL']; + $data['total_countries_confirmed_lotw'] = $CountriesBreakdown['Countries_Worked_LOTW']; + + $QSLStatsBreakdownArray =$this->logbook_model->get_QSLStats($logbooks_locations_array); + + $data['total_qsl_sent'] = $QSLStatsBreakdownArray['QSL_Sent']; + $data['total_qsl_recv'] = $QSLStatsBreakdownArray['QSL_Received']; + $data['total_qsl_requested'] = $QSLStatsBreakdownArray['QSL_Requested']; + + $data['total_eqsl_sent'] = $QSLStatsBreakdownArray['eQSL_Sent']; + $data['total_eqsl_recv'] = $QSLStatsBreakdownArray['eQSL_Received']; + + $data['total_lotw_sent'] = $QSLStatsBreakdownArray['LoTW_Sent']; + $data['total_lotw_recv'] = $QSLStatsBreakdownArray['LoTW_Received']; + + $data['last_five_qsos'] = $this->logbook_model->get_last_qsos('18', $logbooks_locations_array); + + $data['page_title'] = "Dashboard"; + $data['slug'] = $public_slug; + + $this->load->model('dxcc'); + $dxcc = $this->dxcc->list_current(); + + $current = $this->logbook_model->total_countries_current($logbooks_locations_array); + + $data['total_countries_needed'] = count($dxcc->result()) - $current; + + $this->load->view('visitor/layout/header', $data); + $this->load->view('visitor/index'); + $this->load->view('visitor/layout/footer'); + } else { + // Show 404 + log_message('error', '[Visitor] XSS Attack detected on public_slug '. $public_slug); + show_404('Unknown Public Page.'); + } } } + public function map() { + $this->load->model('logbook_model'); + + $this->load->library('qra'); + + $slug = $this->security->xss_clean($this->uri->segment(3)); + + $this->load->model('logbooks_model'); + if($logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($slug) != false) + { + // Get associated station locations for mysql queries + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); + } else { + log_message('error', $slug.' has no associated station locations'); + show_404('Unknown Public Page.'); + } + + $qsos = $this->logbook_model->get_last_qsos('18', $logbooks_locations_array); + header('Content-Type: application/json; charset=utf-8'); + echo "{\"markers\": ["; + $count = 1; + foreach ($qsos->result() as $row) { + //print_r($row); + if($row->COL_GRIDSQUARE != null) { + $stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE); + if($count != 1) { + echo ","; + } + + if($row->COL_SAT_NAME != null) { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
SAT: ".$row->COL_SAT_NAME."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } else { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } + + $count++; + + } else { + $query = $this->db->query(' + SELECT * + FROM dxcc_entities + WHERE prefix = SUBSTRING( \''.$row->COL_CALL.'\', 1, LENGTH( prefix ) ) + ORDER BY LENGTH( prefix ) DESC + LIMIT 1 + '); + + foreach ($query->result() as $dxcc) { + if($count != 1) { + echo ","; + } + echo "{\"lat\":\"".$dxcc->lat."\",\"lng\":\"".$dxcc->long."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + $count++; + } + } + + } + echo "]"; + echo "}"; + + } } \ No newline at end of file diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index 772af86f..1357b704 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -124,12 +124,36 @@ class Logbooks_model extends CI_Model { } } + function public_slug_exists($slug) { + $this->db->where('public_slug', $this->security->xss_clean($slug)); + $query = $this->db->get('station_logbooks'); + + if ($query->num_rows() > 0){ + return true; + } + else{ + return false; + } + } + + function public_slug_exists_logbook_id($slug) { + $this->db->where('public_slug', $this->security->xss_clean($slug)); + $query = $this->db->get('station_logbooks'); + + if ($query->num_rows() > 0){ + foreach ($query->result() as $row) + { + return $row->logbook_id; + } + } + else{ + return false; + } + } function is_public_slug_available($slug) { // Clean public_slug $clean_slug = $this->security->xss_clean($slug); - - $this->db->where('public_slug', $clean_slug); $query = $this->db->get('station_logbooks'); diff --git a/application/views/visitor/index.php b/application/views/visitor/index.php new file mode 100644 index 00000000..c2f4621c --- /dev/null +++ b/application/views/visitor/index.php @@ -0,0 +1,266 @@ +'.$ctx->lang->line('gen_hamradio_mode').''; break; + case 'RSTS': echo ''.$ctx->lang->line('gen_hamradio_rsts').''; break; + case 'RSTR': echo ''.$ctx->lang->line('gen_hamradio_rstr').''; break; + case 'Country': echo ''.$ctx->lang->line('general_word_country').''; break; + case 'IOTA': echo ''.$ctx->lang->line('gen_hamradio_iota').''; break; + case 'SOTA': echo ''.$ctx->lang->line('gen_hamradio_sota').''; break; + case 'State': echo ''.$ctx->lang->line('gen_hamradio_state').''; break; + case 'Grid': echo ''.$ctx->lang->line('gen_hamradio_gridsquare').''; break; + case 'Band': echo ''.$ctx->lang->line('gen_hamradio_band').''; break; + case 'Operator': echo ''.$ctx->lang->line('gen_hamradio_operator').''; break; + } +} + +function echo_table_col($row, $name) { + switch($name) { + case 'Mode': echo ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE . ''; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo 'COL_CONTEST_ID:"n/a").'" class="badge badge-light">'; printf("%03d", $row->COL_STX); echo '';} if ($row->COL_STX_STRING) { echo 'COL_CONTEST_ID:"n/a").'" class="badge badge-light">' . $row->COL_STX_STRING . '';} echo ''; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo 'COL_CONTEST_ID:"n/a").'" class="badge badge-light">'; printf("%03d", $row->COL_SRX); echo '';} if ($row->COL_SRX_STRING) { echo 'COL_CONTEST_ID:"n/a").'" class="badge badge-light">' . $row->COL_SRX_STRING . '';} echo ''; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY))) . ''; break; + case 'IOTA': echo '' . ($row->COL_IOTA) . ''; break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF) . ''; break; + case 'Grid': echo ''; echoQrbCalcLink($row->station_gridsquare, $row->COL_VUCC_GRIDS, $row->COL_GRIDSQUARE); echo ''; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); } echo ''; break; + case 'State': echo '' . ($row->COL_STATE) . ''; break; + case 'Operator': echo '' . ($row->COL_OPERATOR) . ''; break; + } +} + +function echoQrbCalcLink($mygrid, $grid, $vucc) { + if (strlen($grid) != 0) { + echo $grid . ' '; + } else if (strlen($vucc) != 0) { + echo $vucc .' '; + } +} +?> +
+config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) { ?> + + = 1) { ?> + + + + + + + + + + +
+ + +
+ +
+ + +
+
+ +
+ + + + + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + + session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); + echo_table_header_col($this, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); + echo_table_header_col($this, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); + echo_table_header_col($this, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); + ?> + + + + 0) { + foreach ($last_five_qsos->result() as $row) { ?> + '; ?> + + session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/cloudlog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + + ?> + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + + + session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); + echo_table_col($row, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); + echo_table_col($row, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); + echo_table_col($row, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); + ?> + + +
lang->line('general_word_date'); ?>lang->line('general_word_time'); ?>lang->line('gen_hamradio_call'); ?>
COL_TIME_ON); echo date($custom_date_format, $timestamp); ?>COL_TIME_ON); echo date('H:i', $timestamp); ?> + COL_CALL)); ?> +
+
+
+ +
+
+ + num_rows()) { ?> + + + + + + + result_array() as $row) { ?> + + + + + + +
Radio Status
+ + + + frequency->hz_to_mhz($row['frequency']); ?> () + +
+ + + + + + + + + + + + + + + + + + + + + + +
lang->line('dashboard_qso_breakdown'); ?>
lang->line('general_word_total'); ?>
lang->line('general_word_year'); ?>
lang->line('general_word_month'); ?>
+ + + + + + + + + + + + + + + + + + + + + +
lang->line('dashboard_countries_breakdown'); ?>
lang->line('general_word_worked'); ?>
lang->line('general_word_confirmed'); ?> + / + / + +
lang->line('general_word_needed'); ?>
+ + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_qsl_sent != 0 || $total_qsl_recv != 0 || $total_qsl_requested != 0)) { ?> + + + + + + + + + + + + + + + + + + + +
lang->line('general_word_qslcards'); ?>
lang->line('general_word_sent'); ?>
lang->line('general_word_received'); ?>
lang->line('general_word_requested'); ?>
+ + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_eqsl_sent != 0 || $total_eqsl_recv != 0)) { ?> + + + + + + + + + + + + + + +
lang->line('general_word_eqslcards'); ?>
lang->line('general_word_sent'); ?>
lang->line('general_word_received'); ?>
+ + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_lotw_sent != 0 || $total_lotw_recv != 0)) { ?> + + + + + + + + + + + + + + +
lang->line('general_word_lotw'); ?>
lang->line('general_word_sent'); ?>
lang->line('general_word_received'); ?>
+ +
+
+
+ +
diff --git a/application/views/visitor/layout/footer.php b/application/views/visitor/layout/footer.php new file mode 100644 index 00000000..48d232b9 --- /dev/null +++ b/application/views/visitor/layout/footer.php @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/application/views/visitor/layout/header.php b/application/views/visitor/layout/header.php new file mode 100644 index 00000000..63e8cd57 --- /dev/null +++ b/application/views/visitor/layout/header.php @@ -0,0 +1,55 @@ + + + + + + + + + optionslib->get_theme()) { ?> + + + + + + + + + + + + + + + + + + + + + + '; } ?> + + + + <?php if(isset($page_title)) { echo $page_title; } ?> - Cloudlog + + + +