Commit 02d4dc55 authored by Eric - kg6wxc's avatar Eric - kg6wxc
Browse files

changing default distance to kilometers the conversion to miles will be done later in the code

next step: checking for and changing the sql trigger.
parent 0b6e74f5
...@@ -201,7 +201,7 @@ END IF; ...@@ -201,7 +201,7 @@ END IF;
-- figure out distance and bearing -- figure out distance and bearing
SET NEW.bearing = round(mod(degrees(atan2(sin(radians(NEW.linklon)-radians(NEW.nodelon))*cos(radians(NEW.linklat)), cos(radians(NEW.nodelat))*sin(radians(NEW.linklat))-sin(radians(NEW.nodelat))*cos(radians(NEW.linklat))*cos(radians(NEW.linklon)-radians(NEW.nodelon)))) + 360,360),1); SET NEW.bearing = round(mod(degrees(atan2(sin(radians(NEW.linklon)-radians(NEW.nodelon))*cos(radians(NEW.linklat)), cos(radians(NEW.nodelat))*sin(radians(NEW.linklat))-sin(radians(NEW.nodelat))*cos(radians(NEW.linklat))*cos(radians(NEW.linklon)-radians(NEW.nodelon)))) + 360,360),1);
SET NEW.distance = round(2*asin(sqrt(pow(sin((radians(NEW.linklat)-radians(NEW.nodelat))/2),2)+cos(radians(NEW.nodelat))*cos(radians(NEW. linklat))*pow(sin((radians(NEW.linklon)-radians(NEW.nodelon))/2),2)))*3959,2); SET NEW.distance = round(2*asin(sqrt(pow(sin((radians(NEW.linklat)-radians(NEW.nodelat))/2),2)+cos(radians(NEW.nodelat))*cos(radians(NEW. linklat))*pow(sin((radians(NEW.linklon)-radians(NEW.nodelon))/2),2)))*6371,2);
END// END//
DELIMITER ; DELIMITER ;
......
<?php
function wxc_checkDB () {
//this function should probably be in it's own file
//removing the olsrinfo_json binary blob from the database tables
//it's just taking up space and never getting used...
$olsrinfoQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'olsrinfo_json'";
$jsonBlobs = mysqli_query($GLOBALS['sql_connection'], $olsrinfoQuery);
$olsrinfojsonBlobsNum = mysqli_num_rows($jsonBlobs);
if ($olsrinfojsonBlobsNum != 0) {
//$jsonBlobs = wxc_getMySql($sysinfoQuery);
//var_dump($jsonBlobs);
foreach ($jsonBlobs as $table) {
foreach ($table as $table_name) {
$alterQuery = 'alter table ' . $table_name . ' drop column olsrinfo_json';
wxc_putMySql($alterQuery);
$mesg = "olsrinfo_json binary blob removed from database table: " . $table_name . "!";
wxc_echoWithColor($mesg, "red");
echo "\n";
}
}
unset($jsonBlobs);
unset($olsrinfojsonBlobsNum);
unset($olsrinfoQuery);
wxc_echoWithColor("You had an old version of the Database tables. ", "orange");
wxc_echoWithColor("Fixed now...", "green");
echo "\nThis will make the database a lot smaller!\n";
echo "\n";
}else {
unset($jsonBlobs);
unset($olsrinfojsonBlobsNum);
unset($olsrinfoQuery);
}
//removing the sysinfo_json binary blob from the database tables
//it's just taking up space and never getting used...
$sysinfoQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'sysinfo_json'";
$jsonBlobs = mysqli_query($GLOBALS['sql_connection'], $sysinfoQuery);
$sysinfojsonBlobsNum = mysqli_num_rows($jsonBlobs);
if ($sysinfojsonBlobsNum != 0) {
//$jsonBlobs = wxc_getMySql($sysinfoQuery);
//var_dump($jsonBlobs);
foreach ($jsonBlobs as $table) {
foreach ($table as $table_name) {
$alterQuery = 'alter table ' . $table_name . ' drop column sysinfo_json';
wxc_putMySql($alterQuery);
$mesg = "sysinfo_json binary blob removed from database table: " . $table_name . "!";
wxc_echoWithColor($mesg, "red");
echo "\n";
}
}
unset($jsonBlobs);
unset($sysinfojsonBlobsNum);
unset($sysinfoQuery);
wxc_echoWithColor("This is a good thing! It was just taking up space", "green");
echo "\nThis will make the database smaller!\n";
echo "\n";
}else {
unset($jsonBlobs);
unset($sysinfojsonBlobsNum);
unset($sysinfoQuery);
}
//people use the longest dang names for their nodes!
//it's like they want to make you type for a long time just to get to their node. :)
//$columnNodeNames = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'], $query))
$nodeFieldsQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'node' and character_maximum_length <= 69";
$nodeFields = mysqli_query($GLOBALS['sql_connection'], $nodeFieldsQuery);
$nodeFieldsNum = mysqli_num_rows($nodeFields);
if ($nodeFieldsNum != 0) {
foreach ($nodeFields as $table) {
foreach ($table as $table_name) {
//if ($nodeFields['size'] <= 50) {
//echo "\n\nFirst ECHO - Key: " .$key . " Value: " . $value . "\n\n";
//echo "Table: " . $key['table_name'] . "\n";
//echo "size: " . $key['size'] . "\n";
wxc_putMySql("alter table $table_name modify column node varchar(70)");
$mesg = "Altered column \"node\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
//need to change this one too, it has a different name, but it's the same thing.
if ($table_name == "topology") {
wxc_putMySql("alter table topology modify column linkto varchar(70)");
$mesg = "... also altered column \"linkto\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "orange");
echo "\n";
}
//}
}
}
echo "\n";
unset($nodeFields);
unset($nodeFieldsQuery);
unset($nodeFieldsNum);
}else {
unset($nodeFields);
unset($nodeFieldsQuery);
unset($nodeFieldsNum);
}
//Just like above (and for the same reasons)
//there are 1 or 2 columns called "name" that are used also
//This will also allow for longer names in the non-mesh markers area
$nameFieldsQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'name' and character_maximum_length <= 69";
$nameFields = mysqli_query($GLOBALS['sql_connection'], $nameFieldsQuery);
$nameFieldsNum = mysqli_num_rows($nameFields);
if ($nameFieldsNum != 0){
foreach ($nameFields as $table) {
foreach ($table as $table_name) {
//if ($nameFields['size'] <= 50) {
if ($table_name == "marker_info") {
//$query = ;
wxc_putMySql("alter table $table_name modify column name varchar(128)");
$mesg = "Altered column \"name\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
}else {
wxc_putMySql("alter table $table_name modify column name varchar(70)");
$mesg = "Altered column \"name\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
//}
}
}
echo "\n";
unset($nameFields);
unset($nameFieldsQuery);
unset($nameFieldsNum);
}else {
unset($nameFields);
unset($nameFieldsQuery);
unset($nameFieldsNum);
}
//new columns in the main database table
//these new columns are for the additions to the sysinfo.json file
//that are in the newer AREDN firmware builds.
//this might be only the beginning for these
$newColumns1dot2 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " where field='uptime'"));
if ($newColumns1dot2 == 0) {
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column uptime varchar(50) after last_seen");
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column loadavg varchar(128) after uptime");
$mesg = "Added new columns to " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " for api_version 1.2";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
$newColumns1dot2 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from removed_nodes where field='uptime'"));
if ($newColumns1dot2 == 0) {
wxc_putMySql("alter table removed_nodes add column uptime varchar(50) after last_seen");
wxc_putMySql("alter table removed_nodes add column loadavg varchar(128) after uptime");
$mesg = "Added new columns to removed_nodes for api_version 1.2";
wxc_echoWithColor($mesg, "green");
echo "\n\n";
}
$newColumns1dot3 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " where field='services'"));
if ($newColumns1dot3 == 0) {
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column services varchar(2048) after lan_ip");
$mesg = "Added new columns to " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " for api_version 1.3";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
$newColumns1dot3 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from removed_nodes where field='services'"));
if ($newColumns1dot3 == 0) {
wxc_putMySql("alter table removed_nodes add column services varchar(2048) after lan_ip");
$mesg = "Added new columns to removed_nodes for api_version 1.3";
wxc_echoWithColor($mesg, "green");
echo "\n\n";
}
unset($newColumns1dot2);
unset($newColumns1dot3);
}
?>
\ No newline at end of file
...@@ -55,6 +55,7 @@ if (file_exists($INCLUDE_DIR . "/scripts/user-settings.ini")) { ...@@ -55,6 +55,7 @@ if (file_exists($INCLUDE_DIR . "/scripts/user-settings.ini")) {
//kg6wxc's functions. (ALWAYS REQUIRED!, change path if you moved it!) //kg6wxc's functions. (ALWAYS REQUIRED!, change path if you moved it!)
require $INCLUDE_DIR . "/scripts/wxc_functions.inc"; require $INCLUDE_DIR . "/scripts/wxc_functions.inc";
require $INCLUDE_DIR . "/scripts/checkDB.inc";
//the custom include file //the custom include file
//the "@" just suppresses any errors if the file is not found, the file is optional //the "@" just suppresses any errors if the file is not found, the file is optional
......
...@@ -76,6 +76,11 @@ numParallelThreads = "2" ...@@ -76,6 +76,11 @@ numParallelThreads = "2"
map_center_coordinates = "34.35, -119.6" map_center_coordinates = "34.35, -119.6"
map_initial_zoom_level = "10" map_initial_zoom_level = "10"
;;Prefer Kilometers over Miles?
;change to 1 to flip the preference
;the map page will then show 1km (1.62mi)
kilometers = "0"
;;If you have map tiles or a mesh tile server of your own (or on your mesh network) put it here. ;;If you have map tiles or a mesh tile server of your own (or on your mesh network) put it here.
;these map tiles will be used when there is no internet access available ;these map tiles will be used when there is no internet access available
;if you use a directory name, it must be relative to the webroot. ;if you use a directory name, it must be relative to the webroot.
......
...@@ -120,188 +120,6 @@ function wxc_checkConfigs () { ...@@ -120,188 +120,6 @@ function wxc_checkConfigs () {
// } // }
// } // }
} }
function wxc_checkDB () {
//this function should probably be in it's own file
//removing the olsrinfo_json binary blob from the database tables
//it's just taking up space and never getting used...
$olsrinfoQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'olsrinfo_json'";
$jsonBlobs = mysqli_query($GLOBALS['sql_connection'], $olsrinfoQuery);
$olsrinfojsonBlobsNum = mysqli_num_rows($jsonBlobs);
if ($olsrinfojsonBlobsNum != 0) {
//$jsonBlobs = wxc_getMySql($sysinfoQuery);
//var_dump($jsonBlobs);
foreach ($jsonBlobs as $table) {
foreach ($table as $table_name) {
$alterQuery = 'alter table ' . $table_name . ' drop column olsrinfo_json';
wxc_putMySql($alterQuery);
$mesg = "olsrinfo_json binary blob removed from database table: " . $table_name . "!";
wxc_echoWithColor($mesg, "red");
echo "\n";
}
}
unset($jsonBlobs);
unset($olsrinfojsonBlobsNum);
unset($olsrinfoQuery);
wxc_echoWithColor("You had an old version of the Database tables. ", "orange");
wxc_echoWithColor("Fixed now...", "green");
echo "\nThis will make the database a lot smaller!\n";
echo "\n";
}else {
unset($jsonBlobs);
unset($olsrinfojsonBlobsNum);
unset($olsrinfoQuery);
}
//removing the sysinfo_json binary blob from the database tables
//it's just taking up space and never getting used...
$sysinfoQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'sysinfo_json'";
$jsonBlobs = mysqli_query($GLOBALS['sql_connection'], $sysinfoQuery);
$sysinfojsonBlobsNum = mysqli_num_rows($jsonBlobs);
if ($sysinfojsonBlobsNum != 0) {
//$jsonBlobs = wxc_getMySql($sysinfoQuery);
//var_dump($jsonBlobs);
foreach ($jsonBlobs as $table) {
foreach ($table as $table_name) {
$alterQuery = 'alter table ' . $table_name . ' drop column sysinfo_json';
wxc_putMySql($alterQuery);
$mesg = "sysinfo_json binary blob removed from database table: " . $table_name . "!";
wxc_echoWithColor($mesg, "red");
echo "\n";
}
}
unset($jsonBlobs);
unset($sysinfojsonBlobsNum);
unset($sysinfoQuery);
wxc_echoWithColor("This is a good thing! It was just taking up space", "green");
echo "\nThis will make the database smaller!\n";
echo "\n";
}else {
unset($jsonBlobs);
unset($sysinfojsonBlobsNum);
unset($sysinfoQuery);
}
//people use the longest dang names for their nodes!
//it's like they want to make you type for a long time just to get to their node. :)
//$columnNodeNames = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'], $query))
$nodeFieldsQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'node' and character_maximum_length <= 69";
$nodeFields = mysqli_query($GLOBALS['sql_connection'], $nodeFieldsQuery);
$nodeFieldsNum = mysqli_num_rows($nodeFields);
if ($nodeFieldsNum != 0) {
foreach ($nodeFields as $table) {
foreach ($table as $table_name) {
//if ($nodeFields['size'] <= 50) {
//echo "\n\nFirst ECHO - Key: " .$key . " Value: " . $value . "\n\n";
//echo "Table: " . $key['table_name'] . "\n";
//echo "size: " . $key['size'] . "\n";
wxc_putMySql("alter table $table_name modify column node varchar(70)");
$mesg = "Altered column \"node\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
//need to change this one too, it has a different name, but it's the same thing.
if ($table_name == "topology") {
wxc_putMySql("alter table topology modify column linkto varchar(70)");
$mesg = "... also altered column \"linkto\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "orange");
echo "\n";
}
//}
}
}
echo "\n";
unset($nodeFields);
unset($nodeFieldsQuery);
unset($nodeFieldsNum);
}else {
unset($nodeFields);
unset($nodeFieldsQuery);
unset($nodeFieldsNum);
}
//Just like above (and for the same reasons)
//there are 1 or 2 columns called "name" that are used also
//This will also allow for longer names in the non-mesh markers area
$nameFieldsQuery = "select table_name from information_schema.columns where table_schema = '" .
$GLOBALS['USER_SETTINGS']['sql_db'] . "' and column_name = 'name' and character_maximum_length <= 69";
$nameFields = mysqli_query($GLOBALS['sql_connection'], $nameFieldsQuery);
$nameFieldsNum = mysqli_num_rows($nameFields);
if ($nameFieldsNum != 0){
foreach ($nameFields as $table) {
foreach ($table as $table_name) {
//if ($nameFields['size'] <= 50) {
if ($table_name == "marker_info") {
//$query = ;
wxc_putMySql("alter table $table_name modify column name varchar(128)");
$mesg = "Altered column \"name\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
}else {
wxc_putMySql("alter table $table_name modify column name varchar(70)");
$mesg = "Altered column \"name\" to hold more characters in table: $table_name!";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
//}
}
}
echo "\n";
unset($nameFields);
unset($nameFieldsQuery);
unset($nameFieldsNum);
}else {
unset($nameFields);
unset($nameFieldsQuery);
unset($nameFieldsNum);
}
//new columns in the main database table
//these new columns are for the additions to the sysinfo.json file
//that are in the newer AREDN firmware builds.
//this might be only the beginning for these
$newColumns1dot2 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " where field='uptime'"));
if ($newColumns1dot2 == 0) {
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column uptime varchar(50) after last_seen");
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column loadavg varchar(128) after uptime");
$mesg = "Added new columns to " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " for api_version 1.2";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
$newColumns1dot2 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from removed_nodes where field='uptime'"));
if ($newColumns1dot2 == 0) {
wxc_putMySql("alter table removed_nodes add column uptime varchar(50) after last_seen");
wxc_putMySql("alter table removed_nodes add column loadavg varchar(128) after uptime");
$mesg = "Added new columns to removed_nodes for api_version 1.2";
wxc_echoWithColor($mesg, "green");
echo "\n\n";
}
$newColumns1dot3 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " where field='services'"));
if ($newColumns1dot3 == 0) {
wxc_putMySql("alter table " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " add column services varchar(2048) after lan_ip");
$mesg = "Added new columns to " . $GLOBALS['USER_SETTINGS']['sql_db_tbl_node'] . " for api_version 1.3";
wxc_echoWithColor($mesg, "green");
echo "\n";
}
$newColumns1dot3 = mysqli_num_rows(mysqli_query($GLOBALS['sql_connection'],
"show columns from removed_nodes where field='services'"));
if ($newColumns1dot3 == 0) {
wxc_putMySql("alter table removed_nodes add column services varchar(2048) after lan_ip");
$mesg = "Added new columns to removed_nodes for api_version 1.3";
wxc_echoWithColor($mesg, "green");
echo "\n\n";
}
unset($newColumns1dot2);
unset($newColumns1dot3);
}
function wxc_checkErrorMessage ($error, $nodeName) { function wxc_checkErrorMessage ($error, $nodeName) {
//deal with different problems and try to keep track of why and when. //deal with different problems and try to keep track of why and when.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment