| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * WiND - Wireless Nodes Database |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2005 Nikolaos Nikalexis <winner@cube.gr> |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; version 2 dated June, 1991. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | * |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | $plot_path = $root_path."plot/"; |
|---|
| 23 | include $root_path."plot/elevation.php"; |
|---|
| 24 | |
|---|
| 25 | class nodes_view { |
|---|
| 26 | |
|---|
| 27 | var $tpl; |
|---|
| 28 | |
|---|
| 29 | function nodes_view() { |
|---|
| 30 | |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | function calculate_distance($a_node, $b_node) { |
|---|
| 34 | global $db; |
|---|
| 35 | $a_node_i = $db->get('latitude, longitude, elevation', 'nodes', "id = '".$a_node."'"); |
|---|
| 36 | $b_node_i = $db->get('latitude, longitude, elevation', 'nodes', "id = '".$b_node."'"); |
|---|
| 37 | |
|---|
| 38 | $lat1 = $a_node_i[0]['latitude']; |
|---|
| 39 | $lon1 = $a_node_i[0]['longitude']; |
|---|
| 40 | $lat2 = $b_node_i[0]['latitude']; |
|---|
| 41 | $lon2 = $b_node_i[0]['longitude']; |
|---|
| 42 | |
|---|
| 43 | $a_node_el = str_replace(",", ".", get_elevation($lat1, $lon1, FALSE)); |
|---|
| 44 | $b_node_el = str_replace(",", ".", get_elevation($lat2, $lon2, FALSE)); |
|---|
| 45 | |
|---|
| 46 | $dist = acos(sin(deg2rad($lat1)) |
|---|
| 47 | * sin(deg2rad($lat2)) |
|---|
| 48 | + cos(deg2rad($lat1)) |
|---|
| 49 | * cos(deg2rad($lat2)) |
|---|
| 50 | * cos(deg2rad($lon1 - $lon2))); |
|---|
| 51 | |
|---|
| 52 | $dist = rad2deg($dist); |
|---|
| 53 | |
|---|
| 54 | $miles = (float) $dist * 69; |
|---|
| 55 | |
|---|
| 56 | $meters = (float) $miles * 1610; |
|---|
| 57 | |
|---|
| 58 | if ($a_node_el != FALSE && $b_node_el != FALSE) { |
|---|
| 59 | $a_node_el += (integer)$a_node_i[0]['elevation']; |
|---|
| 60 | $b_node_el += (integer)$b_node_i[0]['elevation']; |
|---|
| 61 | $meters = sqrt( pow($meters, 2) + pow( abs($a_node_el - $b_node_el), 2 ) ); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | $km = (float) $meters / 1000; |
|---|
| 65 | |
|---|
| 66 | return $km; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | function table_ip_ranges() { |
|---|
| 70 | global $db; |
|---|
| 71 | $table_ip_ranges = new table(array('TABLE_NAME' => 'table_ip_ranges', 'FORM_NAME' => 'table_ip_ranges')); |
|---|
| 72 | $table_ip_ranges->db_data( |
|---|
| 73 | 'ip_ranges.id, "" AS ip_range, ip_ranges.ip_start, ip_ranges.ip_end, ip_ranges.date_in, ip_ranges.status, ip_ranges.delete_req', |
|---|
| 74 | 'ip_ranges', |
|---|
| 75 | 'ip_ranges.node_id = '.get('node')); |
|---|
| 76 | foreach( (array) $table_ip_ranges->data as $key => $value) { |
|---|
| 77 | if ($key != 0) { |
|---|
| 78 | $table_ip_ranges->data[$key]['ip_start'] = long2ip($table_ip_ranges->data[$key]['ip_start']); |
|---|
| 79 | $table_ip_ranges->data[$key]['ip_end'] = long2ip($table_ip_ranges->data[$key]['ip_end']); |
|---|
| 80 | $table_ip_ranges->data[$key]['ip_range'] = $table_ip_ranges->data[$key]['ip_start']." - ".$table_ip_ranges->data[$key]['ip_end']; |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | $table_ip_ranges->db_data_multichoice('ip_ranges', 'id'); |
|---|
| 84 | $table_ip_ranges->db_data_multichoice_checked('delete_req', 'Y'); |
|---|
| 85 | $table_ip_ranges->info['MULTICHOICE_LABEL'] = 'delete_request'; |
|---|
| 86 | $table_ip_ranges->db_data_remove('id', 'ip_start', 'ip_end', 'delete_req'); |
|---|
| 87 | $table_ip_ranges->db_data_translate('ip_ranges__status'); |
|---|
| 88 | return $table_ip_ranges; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | function table_dns() { |
|---|
| 92 | global $db, $vars; |
|---|
| 93 | $table_dns = new table(array('TABLE_NAME' => 'table_dns', 'FORM_NAME' => 'table_dns')); |
|---|
| 94 | $table_dns->db_data( |
|---|
| 95 | 'dns_zones.id, dns_zones.name, dns_zones.date_in, dns_zones.status, dns_zones.delete_req, dns_zones.type', |
|---|
| 96 | 'dns_zones', |
|---|
| 97 | 'dns_zones.node_id = '.get('node')); |
|---|
| 98 | $table_dns->db_data_multichoice('dns_zones', 'id'); |
|---|
| 99 | $table_dns->db_data_multichoice_checked('delete_req', 'Y'); |
|---|
| 100 | for($i=1;$i<count($table_dns->data);$i++) { |
|---|
| 101 | if (isset($table_dns->data[$i])) { |
|---|
| 102 | if ($table_dns->data[$i]['type'] == 'forward') $table_dns->data[$i]['name'] .= ".".$vars['dns']['root_zone']; |
|---|
| 103 | $table_dns->info['EDIT'][$i] = makelink(array("page" => "mynodes", "subpage" => "dnszone", "zone" => $table_dns->data[$i]['id'])); |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | $table_dns->info['EDIT_COLUMN'] = 'name'; |
|---|
| 107 | $table_dns->info['MULTICHOICE_LABEL'] = 'delete_request'; |
|---|
| 108 | $table_dns->db_data_remove('id', 'delete_req', 'type'); |
|---|
| 109 | $table_dns->db_data_translate('dns_zones__status'); |
|---|
| 110 | return $table_dns; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | function table_nameservers() { |
|---|
| 114 | global $db, $vars; |
|---|
| 115 | $table_nameservers = new table(array('TABLE_NAME' => 'table_nameservers', 'FORM_NAME' => 'table_nameservers')); |
|---|
| 116 | $table_nameservers->db_data( |
|---|
| 117 | 'dns_nameservers.id, dns_nameservers.name, dns_nameservers.ip, dns_nameservers.date_in, dns_nameservers.status, nodes.name_ns AS nodes_name_ns, dns_nameservers.delete_req', |
|---|
| 118 | 'dns_nameservers, nodes', |
|---|
| 119 | "nodes.id = '".get('node')."' AND dns_nameservers.node_id = nodes.id"); |
|---|
| 120 | foreach( (array) $table_nameservers->data as $key => $value) { |
|---|
| 121 | if ($key != 0) { |
|---|
| 122 | $table_nameservers->data[$key]['ip'] = long2ip($table_nameservers->data[$key]['ip']); |
|---|
| 123 | $table_nameservers->data[$key]['name'] = strtolower(($table_nameservers->data[$key]['name']!=''?$table_nameservers->data[$key]['name'].".":"").$table_nameservers->data[$key]['nodes_name_ns'].".".$vars['dns']['ns_zone']); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | $table_nameservers->db_data_multichoice('dns_nameservers', 'id'); |
|---|
| 127 | $table_nameservers->db_data_multichoice_checked('delete_req', 'Y'); |
|---|
| 128 | for($i=1;$i<count($table_nameservers->data);$i++) { |
|---|
| 129 | if (isset($table_nameservers->data[$i])) { |
|---|
| 130 | $table_nameservers->info['EDIT'][$i] = makelink(array("page" => "mynodes", "subpage" => "dnsnameserver", "nameserver" => $table_nameservers->data[$i]['id'])); |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | $table_nameservers->info['EDIT_COLUMN'] = 'name'; |
|---|
| 134 | $table_nameservers->info['MULTICHOICE_LABEL'] = 'delete_request'; |
|---|
| 135 | $table_nameservers->db_data_remove('id', 'nodes_name_ns', 'delete_req'); |
|---|
| 136 | $table_nameservers->db_data_translate('dns_nameservers__status'); |
|---|
| 137 | return $table_nameservers; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | function table_links_p2p() { |
|---|
| 141 | global $db; |
|---|
| 142 | $table_links = new table(array('TABLE_NAME' => 'table_links_p2p')); |
|---|
| 143 | $table_links->db_data( |
|---|
| 144 | '"" AS distance, n1.name AS node_name, n1.id AS node_id, n2.name AS peer_node_name, l1.type AS links__type, l1.info AS links__info, l1.peer_node_id AS links__peer_node_id, l1.date_in AS links__date_in, l1.ssid AS links__ssid, l1.protocol AS links__protocol, l1.channel AS links__channel, l1.equipment AS links__equipment, l1.status AS l1_status, l2.status AS l2_status, "" AS links__status', |
|---|
| 145 | 'links AS l1 |
|---|
| 146 | INNER JOIN links AS l2 ON l1.peer_node_id = l2.node_id |
|---|
| 147 | INNER JOIN nodes AS n1 ON l1.node_id = n1.id |
|---|
| 148 | INNER JOIN nodes AS n2 ON l2.node_id = n2.id', |
|---|
| 149 | "l1.node_id = '".get('node')."' AND l2.peer_node_id = l1.node_id AND l1.type ='p2p' AND l2.type = 'p2p'"); |
|---|
| 150 | foreach( (array) $table_links->data as $key => $value) { |
|---|
| 151 | $table_links->data[$key]['distance'] = $this->calculate_distance($table_links->data[$key]['node_id'], $table_links->data[$key]['links__peer_node_id']); |
|---|
| 152 | if ($key != 0) { |
|---|
| 153 | if ($table_links->data[$key]['l1_status'] == 'active' && $table_links->data[$key]['l2_status'] == 'active') { |
|---|
| 154 | $table_links->data[$key]['links__status'] = 'active'; |
|---|
| 155 | } else { |
|---|
| 156 | $table_links->data[$key]['links__status'] = 'inactive'; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | $table_links->db_data_translate('links__status', 'links__type'); |
|---|
| 161 | $table_links->db_data_hide('peer_node_name', 'links__info', 'links__peer_node_id', 'l1_status', 'l2_status'); |
|---|
| 162 | return $table_links; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | function table_links_ap($id) { |
|---|
| 166 | global $db; |
|---|
| 167 | $table_links = new table(array('TABLE_NAME' => 'table_links_ap_'.$id, 'FORM_NAME' => 'table_links_ap_'.$id)); |
|---|
| 168 | $table_links->db_data( |
|---|
| 169 | 'id, type, node_id, status', |
|---|
| 170 | 'links', |
|---|
| 171 | "type = 'client' AND peer_ap_id = '".$id."'"); |
|---|
| 172 | return $table_links; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | function table_subnets() { |
|---|
| 176 | global $construct, $db; |
|---|
| 177 | $table_subnets = new table(array('TABLE_NAME' => 'table_subnets', 'FORM_NAME' => 'table_subnets')); |
|---|
| 178 | $table_subnets->db_data( |
|---|
| 179 | 'subnets.id, subnets.ip_start, subnets.ip_end, subnets.type, n_l.name AS link_node_name, n_l.id AS link_node_id, n_c.name AS client_node_name, n_c.id AS client_node_id', |
|---|
| 180 | 'subnets |
|---|
| 181 | LEFT JOIN links ON links.id = subnets.link_id |
|---|
| 182 | LEFT JOIN nodes AS n_l ON n_l.id = links.peer_node_id |
|---|
| 183 | LEFT JOIN nodes AS n_c ON n_c.id = client_node_id', |
|---|
| 184 | 'subnets.node_id = '.get('node')); |
|---|
| 185 | foreach( (array) $table_subnets->data as $key => $value) { |
|---|
| 186 | if ($key != 0) { |
|---|
| 187 | $table_subnets->data[$key]['ip_start'] = long2ip($table_subnets->data[$key]['ip_start']); |
|---|
| 188 | $table_subnets->data[$key]['ip_end'] = long2ip($table_subnets->data[$key]['ip_end']); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | return $table_subnets; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | function table_ipaddr() { |
|---|
| 195 | global $construct, $db; |
|---|
| 196 | $table_ipaddr = new table(array('TABLE_NAME' => 'table_ipaddr', 'FORM_NAME' => 'table_ipaddr')); |
|---|
| 197 | $table_ipaddr->db_data( |
|---|
| 198 | 'ip_addresses.id, ip_addresses.date_in, ip_addresses.ip, ip_addresses.type, ip_addresses.always_on, ip_addresses.info', |
|---|
| 199 | 'ip_addresses', |
|---|
| 200 | 'ip_addresses.node_id = '.get('node')); |
|---|
| 201 | foreach( (array) $table_ipaddr->data as $key => $value) { |
|---|
| 202 | if ($key != 0) { |
|---|
| 203 | $table_ipaddr->data[$key]['ip'] = long2ip($table_ipaddr->data[$key]['ip']); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | return $table_ipaddr; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | function table_ipaddr_subnets() { |
|---|
| 210 | global $construct, $db; |
|---|
| 211 | $table_ipaddr_subnets = new table(array('TABLE_NAME' => 'table_ipaddr_subnets')); |
|---|
| 212 | $table_ipaddr_subnets->db_data( |
|---|
| 213 | 'ip_addresses.date_in, ip_addresses.hostname, ip_addresses.ip, ip_addresses.mac, ip_addresses.type AS ip_addresses__type, ip_addresses.always_on, ip_addresses.info, subnets.ip_start, subnets.ip_end, subnets.type', |
|---|
| 214 | 'ip_addresses, subnets', |
|---|
| 215 | "ip_addresses.node_id = '".get('node')."' AND subnets.node_id = '".get('node')."' AND subnets.ip_start <= ip_addresses.ip AND subnets.ip_end >= ip_addresses.ip", |
|---|
| 216 | "", |
|---|
| 217 | "subnets.type ASC, subnets.ip_start ASC"); |
|---|
| 218 | foreach( (array) $table_ipaddr_subnets->data as $key => $value) { |
|---|
| 219 | if ($key != 0) { |
|---|
| 220 | $table_ipaddr_subnets->data[$key]['ip'] = long2ip($table_ipaddr_subnets->data[$key]['ip']); |
|---|
| 221 | $table_ipaddr_subnets->data[$key]['ip_start'] = long2ip($table_ipaddr_subnets->data[$key]['ip_start']); |
|---|
| 222 | $table_ipaddr_subnets->data[$key]['ip_end'] = long2ip($table_ipaddr_subnets->data[$key]['ip_end']); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | $table_ipaddr_subnets->db_data_translate('ip_addresses__type', 'ip_addresses__always_on', 'subnets__type'); |
|---|
| 226 | $table_ipaddr_subnets->db_data_hide('subnets__ip_start', 'subnets__ip_end', 'subnets__type'); |
|---|
| 227 | return $table_ipaddr_subnets; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | function output() { |
|---|
| 231 | if ($_SERVER['REQUEST_METHOD'] == 'POST' && method_exists($this, 'output_onpost_'.$_POST['form_name'])) return call_user_func(array($this, 'output_onpost_'.$_POST['form_name'])); |
|---|
| 232 | global $construct, $db, $vars; |
|---|
| 233 | $this->tpl['node'] = $db->get( |
|---|
| 234 | 'nodes.id, nodes.name, nodes.date_in, nodes.latitude, nodes.longitude, nodes.elevation, nodes.info, areas.name as area_name, regions.name as region_name, users.username AS owner_username, users.email AS owner_email', |
|---|
| 235 | 'nodes |
|---|
| 236 | LEFT JOIN areas ON nodes.area_id = areas.id |
|---|
| 237 | LEFT JOIN regions ON areas.region_id = regions.id |
|---|
| 238 | LEFT JOIN users_nodes ON users_nodes.node_id = nodes.id |
|---|
| 239 | LEFT JOIN users ON users.id = users_nodes.user_id', |
|---|
| 240 | "nodes.id = '".get('node')."' AND (users_nodes.owner = 'Y' OR users_nodes.owner IS NULL)"); |
|---|
| 241 | $this->tpl['node'] = $this->tpl['node'][0]; |
|---|
| 242 | $this->tpl['table_ip_ranges'] = $construct->table($this->table_ip_ranges(), __FILE__); |
|---|
| 243 | $this->tpl['table_dns'] = $construct->table($this->table_dns(), __FILE__); |
|---|
| 244 | $this->tpl['table_nameservers'] = $construct->table($this->table_nameservers(), __FILE__); |
|---|
| 245 | $this->tpl['table_links_p2p'] = $construct->table($this->table_links_p2p(), __FILE__); |
|---|
| 246 | |
|---|
| 247 | $t = $db->get('id, type', 'links', "node_id = '".get('node')."'"); |
|---|
| 248 | foreach( (array) $t as $key => $value) { |
|---|
| 249 | if ($value['type'] == 'ap') $this->tpl['table_links_ap'][$value['id']] = $construct->table($this->table_links_ap($value['id']), __FILE__); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | $this->tpl['table_subnets'] = $construct->table($this->table_subnets(), __FILE__); |
|---|
| 253 | $this->tpl['table_ipaddr'] = $construct->table($this->table_ipaddr(), __FILE__); |
|---|
| 254 | $this->tpl['table_ipaddr_subnets'] = $construct->table($this->table_ipaddr_subnets(), __FILE__); |
|---|
| 255 | |
|---|
| 256 | $t = $db->get('id, date_in, view_point, info', 'photos', "node_id = '".get('node')."'"); |
|---|
| 257 | foreach( (array) $t as $key => $value) { |
|---|
| 258 | $this->tpl['photosview'][$value['view_point']] = $value; |
|---|
| 259 | $this->tpl['photosview'][$value['view_point']]['image_s'] = $vars['folders']['photos'].'photo-'.$this->tpl['photosview'][$value['view_point']]['id'].'-s.jpg'; |
|---|
| 260 | $this->tpl['photosview'][$value['view_point']]['image'] = $vars['folders']['photos'].'photo-'.$this->tpl['photosview'][$value['view_point']]['id'].'.jpg'; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | return template($this->tpl, __FILE__); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | ?> |
|---|