Secure calltester so that it can only run when logged in and you are admin

这个提交包含在:
Andreas 2023-08-01 13:25:36 +02:00
父节点 57a5e2ae85
当前提交 41d535b805

查看文件

@ -1,12 +1,23 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <?php
use Cloudlog\Dxcc\Dxcc;
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Calltester extends CI_Controller { class Calltester extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('user_model');
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
public function db() { public function db() {
set_time_limit(3600); set_time_limit(3600);
// Starting clock time in seconds // Starting clock time in seconds
$start_time = microtime(true); $start_time = microtime(true);
$this->load->model('logbook_model'); $this->load->model('logbook_model');
$sql = 'select distinct col_country, col_call, col_dxcc, date(col_time_on) date from ' . $this->config->item('table_name'); $sql = 'select distinct col_country, col_call, col_dxcc, date(col_time_on) date from ' . $this->config->item('table_name');
@ -15,7 +26,7 @@ class Calltester extends CI_Controller {
$callarray = $query->result(); $callarray = $query->result();
$result = array(); $result = array();
$i = 0; $i = 0;
foreach ($callarray as $call) { foreach ($callarray as $call) {
@ -24,24 +35,24 @@ class Calltester extends CI_Controller {
$dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0; $dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0;
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0; $dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0;
if ($call->col_dxcc != $dxcc['adif']) { if ($call->col_dxcc != $dxcc['adif']) {
$result[] = array( $result[] = array(
'Callsign' => $call->col_call, 'Callsign' => $call->col_call,
'Expected country' => $call->col_country, 'Expected country' => $call->col_country,
'Expected adif' => $call->col_dxcc, 'Expected adif' => $call->col_dxcc,
'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"), 'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"),
'Result adif' => $dxcc['adif'], 'Result adif' => $dxcc['adif'],
); );
} }
} }
// End clock time in seconds // End clock time in seconds
$end_time = microtime(true); $end_time = microtime(true);
// Calculate script execution time // Calculate script execution time
$execution_time = ($end_time - $start_time); $execution_time = ($end_time - $start_time);
echo " Execution time of script = ".$execution_time." sec <br/>"; echo " Execution time of script = ".$execution_time." sec <br/>";
echo $i . " calls tested. <br/>"; echo $i . " calls tested. <br/>";
$count = 0; $count = 0;
@ -49,11 +60,11 @@ class Calltester extends CI_Controller {
if ($result) { if ($result) {
$this->array_to_table($result); $this->array_to_table($result);
} }
} }
function array_to_table($table) { function array_to_table($table) {
echo '<style> echo '<style>
table { table {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
@ -80,20 +91,20 @@ class Calltester extends CI_Controller {
</style> '; </style> ';
echo '<table>'; echo '<table>';
// Table header // Table header
foreach ($table[0] as $key=>$value) { foreach ($table[0] as $key=>$value) {
echo "<th>".$key."</th>"; echo "<th>".$key."</th>";
} }
// Table body // Table body
foreach ($table as $value) { foreach ($table as $value) {
echo "<tr>"; echo "<tr>";
foreach ($value as $val) { foreach ($value as $val) {
echo "<td>".$val."</td>"; echo "<td>".$val."</td>";
} }
echo "</tr>"; echo "</tr>";
} }
echo "</table>"; echo "</table>";
} }
@ -102,17 +113,17 @@ class Calltester extends CI_Controller {
// Starting clock time in seconds // Starting clock time in seconds
$start_time = microtime(true); $start_time = microtime(true);
$this->load->model('logbook_model'); $this->load->model('logbook_model');
$file = 'uploads/calls.csv'; $file = 'uploads/calls.csv';
$handle = fopen($file,"r"); $handle = fopen($file,"r");
$data = fgetcsv($handle,1000,","); // Skips firsts line, usually that is the header $data = fgetcsv($handle,1000,","); // Skips firsts line, usually that is the header
$data = fgetcsv($handle,1000,","); $data = fgetcsv($handle,1000,",");
$result = array(); $result = array();
$i = 0; $i = 0;
do { do {
@ -126,12 +137,12 @@ class Calltester extends CI_Controller {
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0; $dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0;
$data[1] = $data[1] == "NULL" ? 0 : $data[1]; $data[1] = $data[1] == "NULL" ? 0 : $data[1];
if ($data[1] != $dxcc['adif']) { if ($data[1] != $dxcc['adif']) {
$result[] = array( $result[] = array(
'Callsign' => $data[0], 'Callsign' => $data[0],
'Expected country' => '', 'Expected country' => '',
'Expected adif' => $data[1], 'Expected adif' => $data[1],
'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"), 'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"),
'Result adif' => $dxcc['adif'], 'Result adif' => $dxcc['adif'],
); );
@ -144,7 +155,7 @@ class Calltester extends CI_Controller {
// Calculate script execution time // Calculate script execution time
$execution_time = ($end_time - $start_time); $execution_time = ($end_time - $start_time);
echo " Execution time of script = ".$execution_time." sec <br/>"; echo " Execution time of script = ".$execution_time." sec <br/>";
echo $i . " calls tested. <br/>"; echo $i . " calls tested. <br/>";
$count = 0; $count = 0;
@ -162,17 +173,17 @@ class Calltester extends CI_Controller {
// Starting clock time in seconds // Starting clock time in seconds
$start_time = microtime(true); $start_time = microtime(true);
$this->load->model('logbook_model'); $this->load->model('logbook_model');
$file = 'uploads/calls.csv'; $file = 'uploads/calls.csv';
$handle = fopen($file,"r"); $handle = fopen($file,"r");
$data = fgetcsv($handle,1000,","); // Skips firsts line, usually that is the header $data = fgetcsv($handle,1000,","); // Skips firsts line, usually that is the header
$data = fgetcsv($handle,1000,","); $data = fgetcsv($handle,1000,",");
$result = array(); $result = array();
$i = 0; $i = 0;
do { do {
@ -183,12 +194,12 @@ class Calltester extends CI_Controller {
$dxcc = $this->logbook_model->check_dxcc_table($data[0], $data[2]); $dxcc = $this->logbook_model->check_dxcc_table($data[0], $data[2]);
$data[1] = $data[1] == "NULL" ? 0 : $data[1]; $data[1] = $data[1] == "NULL" ? 0 : $data[1];
if ($data[1] != $dxcc[0]) { if ($data[1] != $dxcc[0]) {
$result[] = array( $result[] = array(
'Callsign' => $data[0], 'Callsign' => $data[0],
'Expected country' => '', 'Expected country' => '',
'Expected adif' => $data[1], 'Expected adif' => $data[1],
'Result country' => ucwords(strtolower($dxcc[1]), "- (/"), 'Result country' => ucwords(strtolower($dxcc[1]), "- (/"),
'Result adif' => $dxcc[0], 'Result adif' => $dxcc[0],
); );
@ -201,7 +212,7 @@ class Calltester extends CI_Controller {
// Calculate script execution time // Calculate script execution time
$execution_time = ($end_time - $start_time); $execution_time = ($end_time - $start_time);
echo " Execution time of script = ".$execution_time." sec <br/>"; echo " Execution time of script = ".$execution_time." sec <br/>";
echo $i . " calls tested. <br/>"; echo $i . " calls tested. <br/>";
$count = 0; $count = 0;
@ -216,232 +227,253 @@ class Calltester extends CI_Controller {
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VE3EY/VP9', 'Callsign' => 'VE3EY/VP9',
'Country' => 'Bermuda', 'Country' => 'Bermuda',
'Adif' => 64, 'Adif' => 64,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VP2MDG', 'Callsign' => 'VP2MDG',
'Country' => 'Montserrat', 'Country' => 'Montserrat',
'Adif' => 96, 'Adif' => 96,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VP2EY', 'Callsign' => 'VP2EY',
'Country' => 'Anguilla', 'Country' => 'Anguilla',
'Adif' => 12, 'Adif' => 12,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VP2VI', 'Callsign' => 'VP2VI',
'Country' => 'British Virgin Islands.', 'Country' => 'British Virgin Islands.',
'Adif' => 65, 'Adif' => 65,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VP2V/AA7V', 'Callsign' => 'VP2V/AA7V',
'Country' => 'British Virgin Islands', 'Country' => 'British Virgin Islands',
'Adif' => 65, 'Adif' => 65,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'W8LR/R', 'Callsign' => 'W8LR/R',
'Country' => 'United States Of America', 'Country' => 'United States Of America',
'Adif' => 291, 'Adif' => 291,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'SO1FH', 'Callsign' => 'SO1FH',
'Country' => 'Poland', 'Country' => 'Poland',
'Adif' => 269, 'Adif' => 269,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'KZ1H/PP', 'Callsign' => 'KZ1H/PP',
'Country' => 'Brazil', 'Country' => 'Brazil',
'Adif' => 108, 'Adif' => 108,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'K1KW/AM', 'Callsign' => 'K1KW/AM',
'Country' => 'None', 'Country' => 'None',
'Adif' => 0, 'Adif' => 0,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'K1KW/MM', 'Callsign' => 'K1KW/MM',
'Country' => 'None', 'Country' => 'None',
'Adif' => 0, 'Adif' => 0,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'TF/DL2NWK/P', 'Callsign' => 'TF/DL2NWK/P',
'Country' => 'Iceland', 'Country' => 'Iceland',
'Adif' => 242, 'Adif' => 242,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'OZ1ALS/A', 'Callsign' => 'OZ1ALS/A',
'Country' => 'Denmark', 'Country' => 'Denmark',
'Adif' => 221, 'Adif' => 221,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'LA1K', 'Callsign' => 'LA1K',
'Country' => 'Norway', 'Country' => 'Norway',
'Adif' => 266, 'Adif' => 266,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'K1KW/M', 'Callsign' => 'K1KW/M',
'Country' => 'United States Of America', 'Country' => 'United States Of America',
'Adif' => 291, 'Adif' => 291,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'TF/DL2NWK/M', 'Callsign' => 'TF/DL2NWK/M',
'Country' => 'Iceland', 'Country' => 'Iceland',
'Adif' => 242, 'Adif' => 242,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'TF/DL2NWK/MM', 'Callsign' => 'TF/DL2NWK/MM',
'Country' => 'None', 'Country' => 'None',
'Adif' => 0, 'Adif' => 0,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'TF/DL2NWK/P', 'Callsign' => 'TF/DL2NWK/P',
'Country' => 'Iceland', 'Country' => 'Iceland',
'Adif' => 242, 'Adif' => 242,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => '2M0SQL/P', 'Callsign' => '2M0SQL/P',
'Country' => 'Scotland', 'Country' => 'Scotland',
'Adif' => 279, 'Adif' => 279,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'FT8WW', 'Callsign' => 'FT8WW',
'Country' => 'Crozet Island', 'Country' => 'Crozet Island',
'Adif' => 41, 'Adif' => 41,
'Date' => $date = date('Ymd', time()) 'Date' => 20230314
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'RV0AL/0/P', 'Callsign' => 'RV0AL/0/P',
'Country' => 'Asiatic Russia', 'Country' => 'Asiatic Russia',
'Adif' => 15, 'Adif' => 15,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'OH/DJ1YFK', 'Callsign' => 'OH/DJ1YFK',
'Country' => 'Finland', 'Country' => 'Finland',
'Adif' => 224, 'Adif' => 224,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'N6TR/7', 'Callsign' => 'N6TR/7',
'Country' => 'United States Of America', 'Country' => 'United States Of America',
'Adif' => 291, 'Adif' => 291,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'KH0CW', 'Callsign' => 'KH0CW',
'Country' => 'United States Of America', 'Country' => 'United States Of America',
'Adif' => 291, 'Adif' => 291,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'R2FM/P', 'Callsign' => 'R2FM/P',
'Country' => 'kaliningrad', 'Country' => 'kaliningrad',
'Adif' => 126, 'Adif' => 126,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'R2FM', 'Callsign' => 'R2FM',
'Country' => 'kaliningrad', 'Country' => 'kaliningrad',
'Adif' => 126, 'Adif' => 126,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'FT5XO', 'Callsign' => 'FT5XO',
'Country' => 'Kerguelen Island', 'Country' => 'Kerguelen Island',
'Adif' => 131, 'Adif' => 131,
'Date' => 20050320 'Date' => 20050320
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'VP8CTR', 'Callsign' => 'VP8CTR',
'Country' => 'Antarctica', 'Country' => 'Antarctica',
'Adif' => 13, 'Adif' => 13,
'Date' => 19970207 'Date' => 19970207
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'FO0AAA', 'Callsign' => 'FO0AAA',
'Country' => 'Clipperton', 'Country' => 'Clipperton',
'Adif' => 36, 'Adif' => 36,
'Date' => '20000302' 'Date' => '20000302'
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'CX/PR8KW', 'Callsign' => 'CX/PR8KW',
'Country' => 'Uruguay', 'Country' => 'Uruguay',
'Adif' => 144, 'Adif' => 144,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'IQ3MV/LH', 'Callsign' => 'IQ3MV/LH',
'Country' => 'Italy', 'Country' => 'Italy',
'Adif' => 248, 'Adif' => 248,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'LA1K/QRP', 'Callsign' => 'LA1K/QRP',
'Country' => 'Norway', 'Country' => 'Norway',
'Adif' => 266, 'Adif' => 266,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'LA1K/LGT', 'Callsign' => 'LA1K/LGT',
'Country' => 'Norway', 'Country' => 'Norway',
'Adif' => 266, 'Adif' => 266,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
$testarray[] = array( $testarray[] = array(
'Callsign' => 'SM1K/LH', 'Callsign' => 'SM1K/LH',
'Country' => 'Sweden', 'Country' => 'Sweden',
'Adif' => 284, 'Adif' => 284,
'Date' => $date = date('Ymd', time())
);
$testarray[] = array(
'Callsign' => 'KG4W',
'Country' => 'United States Of America',
'Adif' => 291,
'Date' => $date = date('Ymd', time())
);
$testarray[] = array(
'Callsign' => 'KG4WW',
'Country' => 'Guantanamo Bay',
'Adif' => 105,
'Date' => $date = date('Ymd', time())
);
$testarray[] = array(
'Callsign' => 'KG4WWW',
'Country' => 'United States Of America',
'Adif' => 291,
'Date' => $date = date('Ymd', time()) 'Date' => $date = date('Ymd', time())
); );
@ -449,11 +481,11 @@ class Calltester extends CI_Controller {
// Starting clock time in seconds // Starting clock time in seconds
$start_time = microtime(true); $start_time = microtime(true);
$this->load->model('logbook_model'); $this->load->model('logbook_model');
$result = array(); $result = array();
$i = 0; $i = 0;
foreach ($testarray as $call) { foreach ($testarray as $call) {
@ -462,24 +494,24 @@ class Calltester extends CI_Controller {
$dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0; $dxcc['adif'] = (isset($dxcc['adif'])) ? $dxcc['adif'] : 0;
$dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0; $dxcc['entity'] = (isset($dxcc['entity'])) ? $dxcc['entity'] : 0;
if ($call['Adif'] != $dxcc['adif']) { if ($call['Adif'] != $dxcc['adif']) {
$result[] = array( $result[] = array(
'Callsign' => $call['Callsign'], 'Callsign' => $call['Callsign'],
'Expected country' => $call['Country'], 'Expected country' => $call['Country'],
'Expected adif' => $call['Adif'], 'Expected adif' => $call['Adif'],
'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"), 'Result country' => ucwords(strtolower($dxcc['entity']), "- (/"),
'Result adif' => $dxcc['adif'], 'Result adif' => $dxcc['adif'],
); );
} }
} }
// End clock time in seconds // End clock time in seconds
$end_time = microtime(true); $end_time = microtime(true);
// Calculate script execution time // Calculate script execution time
$execution_time = ($end_time - $start_time); $execution_time = ($end_time - $start_time);
echo " Execution time of script = ".$execution_time." sec <br/>"; echo " Execution time of script = ".$execution_time." sec <br/>";
echo $i . " calls tested. <br/>"; echo $i . " calls tested. <br/>";
$count = 0; $count = 0;
@ -488,4 +520,4 @@ class Calltester extends CI_Controller {
$this->array_to_table($result); $this->array_to_table($result);
} }
} }
} }