Commit c87fb1d7 authored by Eric - kg6wxc's avatar Eric - kg6wxc
Browse files

Merge branch 'kilometers' into 'master'

Change Default Distance to Kilometers

Closes #11

See merge request !9
parents d47b65a8 e300cde7
To contribute to this project, please just create an account here:
https://gitlab.kg6wxc.net/users/sign_in
Anyone is free to contribute.
Create your own fork if you like and submit merge requests,
or just use the issues area to suggest new ideas.
GitLab is basically just like GitHub,
if you know how to use that you should be fine.
@kg6wxc retains the right to approve new code to the "main" branch.
Anyone is free to contribute.
@kg6wxc trys to retain the right to approve new code to the "main" branch.
Go ahead and create new fork with additional options/settings/maps, etc...
Fork this off to github if you like even, it is here for everyone!
......@@ -201,7 +201,7 @@ END IF;
-- 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.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//
DELIMITER ;
......
<?php
function wxc_checkDB () {
//this function is now in its 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);
//check for old trigger based on miles and update to new trigger based on kilometers.
//the conversion to miles will be done later in the code.
$oldDistanceTriggerQuery = "select action_statement from information_schema.triggers where action_statement like '%3959%'";
if ($oldDistanceTriggerQuery) {
$sql = "drop trigger topology_get_latlons_brg_dist";
mysqli_query($GLOBALS['sql_connection'], $sql)
or die(wxc_addColor("Could not drop SQL Trigger!", "red") . "\n" .
"Please try to use the \"" . wxc_addColor("updateDBtoKilometers.sql", "bold") . "\" file.\n" .
"Example: " . wxc_addColor("sudo mysql -D node_map < /home/pi/meshmap/updateDBtoKilometers.sql", "bold") . "\n\n" .
"or... try to fix the following,\n" .
wxc_addColor("SQL Error:", "red") . "\n" .
mysqli_error($GLOBALS['sql_connection']) . "\n\n");
$sql = "CREATE TRIGGER `topology_get_latlons_brg_dist` BEFORE INSERT ON `topology` FOR EACH ROW BEGIN
-- get locations and names for each end of the link
IF NEW.node IS NOT NULL THEN
SET NEW.nodelat = (SELECT lat FROM node_info WHERE wlan_ip = NEW.node AND (lat IS NOT NULL && lat != 0 && lat != 0.00));
SET NEW.nodelon = (SELECT lon FROM node_info WHERE wlan_ip = NEW.node AND (lon IS NOT NULL && lon != 0 && lon != 0.00));
SET NEW.node = (SELECT node FROM node_info WHERE wlan_ip = NEW.node);
END IF;
IF NEW.linkto IS NOT NULL THEN
SET NEW.linklat = (SELECT lat FROM node_info WHERE wlan_ip = NEW.linkto AND (lat IS NOT NULL && lat != 0 && lat != 0.00));
SET NEW.linklon = (SELECT lon FROM node_info WHERE wlan_ip = NEW.linkto AND (lon IS NOT NULL && lon != 0 && lon != 0.00));
SET NEW.linkto = (SELECT node FROM node_info WHERE wlan_ip = NEW.linkto);
END IF;
-- 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.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;";
mysqli_query($GLOBALS['sql_connection'], $sql)
or die(wxc_addColor("Could not recreate SQL Trigger to use Kilometers.", "red") . "\n" .
wxc_addColor("The Trigger may have already been dropped as well!", "redBold") . "\n" .
"Please try to use the \"". wxc_addColor("updateDBtoKilometers.sql", "bold") . "\" file.\n" .
"Example: " . wxc_addColor("sudo mysql -D node_map < /home/pi/meshmap/updateDBtoKilometers.sql", "bold") . "\n\n" .
"or... try to fix the following,\n" .
wxc_addColor("SQL Error:", "red") . "\n" .
mysqli_error($GLOBALS['sql_connection']) . "\n");
unset($oldDistanceTriggerQuery);
unset($sql);
$mesg = "Changed database to have default distance in Kilometers.";
wxc_echoWithColor($mesg, "green");
echo "\n\n";
}
}
?>
......@@ -55,6 +55,7 @@ if (file_exists($INCLUDE_DIR . "/scripts/user-settings.ini")) {
//kg6wxc's functions. (ALWAYS REQUIRED!, change path if you moved it!)
require $INCLUDE_DIR . "/scripts/wxc_functions.inc";
require $INCLUDE_DIR . "/scripts/checkDB.inc";
//the custom include file
//the "@" just suppresses any errors if the file is not found, the file is optional
......
......@@ -391,6 +391,10 @@ function load_LinkedTO($node_info, $TopoList)
}
//now take all that info back out and put into a properly formatted string variable that we'll use later
//this part of the function reformatted by kg6wxc.
//the "kilometers" setting will default to "0"
if (!isset($GLOBALS['USER_SETTINGS']['kilometers'])) {
$GLOBALS['USER_SETTINGS']['kilometers'] = "0";
}
foreach ($linkInfoForStationPopups as $nodeNameLinkArray => $linktoArray) {
if (!empty($linktoArray)) {
foreach ($linktoArray as $linkedNodeName => $costArray) {
......@@ -402,7 +406,11 @@ function load_LinkedTO($node_info, $TopoList)
}else {
$display_cost = ' (' . $costArray['costTo'] . '/' . $costArray['costFrom'] . ') ';
}
$linkedToList .= $linkedNodeName . $display_cost . $costArray['distance'] . ' mi ' . $costArray['bearing'] . '&deg;<br>';
if ($GLOBALS['USER_SETTINGS']['kilometers']) {
$linkedToList .= $linkedNodeName . $display_cost . $costArray['distance'] . 'km (' . round($costArray['distance'] * 0.62137, 2) . 'mi) ' . $costArray['bearing'] . '&deg;<br>';
}else {
$linkedToList .= $linkedNodeName . $display_cost . round($costArray['distance'] * 0.62137, 2) . 'mi (' . $costArray['distance'] . 'km) ' . $costArray['bearing'] . '&deg;<br>';
}
}
}
}
......@@ -526,7 +534,7 @@ function build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_Fir
//var_dump($loadavgs);
$markerList .= 'LoadAvg: 1 min ' . $loadavgs[0] . ', 5 min ' . $loadavgs[1] . ', 15 min ' . $loadavgs[2] . "<br>";
}
$markerList .= $node_ServiceList . $node_LinkedList . "\").addTo(" . $AssignedLayer . ") ,\n"; // Close out this node
$markerList .= $node_ServiceList . $node_LinkedList . "\",{ maxWidth: 500 } ).addTo(" . $AssignedLayer . ") ,\n"; // Close out this node
/*
* If Upgrade Suggested add Node to that layer
*/
......
......@@ -76,6 +76,11 @@ numParallelThreads = "2"
map_center_coordinates = "34.35, -119.6"
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.
;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.
......
......@@ -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) {
//deal with different problems and try to keep track of why and when.
......@@ -646,6 +464,32 @@ function wxc_echoWithColor ($text, $color) {
if ($color == 'alert') {
echo "\033[41m\033[30m\033[1m" . $text . "\033[0m";
}
if ($color == 'bold') {
echo "\033[1m" . $text . "\033[0m";
}
}
function wxc_addColor ($text, $color) {
if ($color == "red") {
return "\33[31m" . $text . "\033[0m";
}
if ($color == "purple") {
return "\033[35m" . $text . "\033[0m";
}
if ($color == "orange") {
return "\033[33m" . $text . "\033[0m";
}
if ($color == "green") {
return "\033[32m" . $text . "\033[0m";
}
if ($color == 'redBold') {
return "\033[1m\33[31m" . $text . "\033[0m";
}
if ($color == 'alert') {
return "\033[41m\033[30m\033[1m" . $text . "\033[0m";
}
if ($color == 'bold') {
return "\033[1m" . $text . "\033[0m";
}
}
//may use this at some point
......
-- drop old trigger
DROP TRIGGER topology_get_latlons_brg_dist;
-- create new trigger based on Km instead of miles.
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='';
DELIMITER //
CREATE TRIGGER `topology_get_latlons_brg_dist` BEFORE INSERT ON `topology` FOR EACH ROW BEGIN
-- get locations and names for each end of the link
IF NEW.node IS NOT NULL THEN
SET NEW.nodelat = (SELECT lat FROM node_info WHERE wlan_ip = NEW.node AND (lat IS NOT NULL && lat != 0 && lat != 0.00));
SET NEW.nodelon = (SELECT lon FROM node_info WHERE wlan_ip = NEW.node AND (lon IS NOT NULL && lon != 0 && lon != 0.00));
SET NEW.node = (SELECT node FROM node_info WHERE wlan_ip = NEW.node);
END IF;
IF NEW.linkto IS NOT NULL THEN
SET NEW.linklat = (SELECT lat FROM node_info WHERE wlan_ip = NEW.linkto AND (lat IS NOT NULL && lat != 0 && lat != 0.00));
SET NEW.linklon = (SELECT lon FROM node_info WHERE wlan_ip = NEW.linkto AND (lon IS NOT NULL && lon != 0 && lon != 0.00));
SET NEW.linkto = (SELECT node FROM node_info WHERE wlan_ip = NEW.linkto);
END IF;
-- 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.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//
DELIMITER ;
SET SQL_MODE=@OLDTMP_SQL_MODE;
Markdown is supported
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