- Timestamp:
- Apr 15, 2010, 10:40:35 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/config.php
r7768 r7773 13 13 14 14 /* 15 * Global settings 16 * Don't change anything below this line if you don't know what you are doing 15 * Global root for uniform file calling. 17 16 */ 18 $config['folder_class'] = 'inc/'; 17 $config['root'] = dirname(__FILE__); 18 $config['root_class'] = $config['root'] . '/inc/'; 19 19 $config['file_init'] = 'init.php'; 20 20 … … 22 22 * Placemark settings. Which icons do you want to use 23 23 */ 24 $config['node_green'] = ' http://svn.wirelessleiden.nl/svn/projects/NodeMap2.0/trunk/src/img/sleutelGroen.png';24 $config['node_green'] = 'sleutelGroen.png'; 25 25 $config['node_orange'] = 'img/sleutelOranje.png'; 26 26 $config['node_red'] = 'img/sleutelRood.png'; … … 32 32 */ 33 33 $config['require'] = array(); 34 $config['require'][] = $config['folder_class'] . 'ErrorHandler.php'; 35 $config['require'][] = $config['folder_class'] . 'LogHandler.class.php'; 36 $config['require'][] = $config['folder_class'] . 'FileHandler.class.php'; 37 $config['require'][] = $config['folder_class'] . 'KMLFile.class.php'; 38 $config['require'][] = $config['folder_class'] . 'KMLNode.class.php'; 39 $config['require'][] = $config['folder_class'] . 'KMLLine.class.php'; 34 $config['require'][] = $config['root_class'] . 'ErrorHandler.php'; 35 $config['require'][] = $config['root_class'] . 'LogHandler.class.php'; 36 $config['require'][] = $config['root_class'] . 'FileHandler.class.php'; 37 $config['require'][] = $config['root_class'] . 'KMLFile.class.php'; 38 $config['require'][] = $config['root_class'] . 'KMLNode.class.php'; 39 $config['require'][] = $config['root_class'] . 'KMLLine.class.php'; 40 $config['require'][] = $config['root_class'] . 'Network.class.php'; 41 $config['require'][] = $config['root_class'] . 'NetworkList.class.php'; 40 42 41 43 $config['googlekey'] = array(); 42 44 $config['googlekey']['wirelessleiden.nl'] = 'ABQIAAAAKRiFs2kXKhTkKZkE_ms9rhTdBXm62xfhQU7Dk6ZBFSzYdmSteRQWjLqZhwX8afHvGpd4N3iKql6w8g'; 43 45 $config['googlekey']['default'] = 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA'; 44 45 /*46 * Global root for uniform file calling.47 */48 $config['root'] = dirname(__FILE__);49 46 50 47 /* -
trunk/src/inc/KMLFile.class.php
r7765 r7773 76 76 private $KMLNodes; 77 77 private $KMLLines; 78 78 private $NetworkList; 79 79 80 /* 80 81 * Function: __construct (constructor) … … 86 87 $this->KMLNodes = array(); 87 88 $this->KMLLines = array(); 89 $this->NetworkList = new NetworkList(); 88 90 } 89 91 … … 119 121 $toString = $this->template; 120 122 123 // Add all nodes to the string 121 124 $nodeString = ''; 122 125 $nodeCount = count($this->KMLNodes); … … 125 128 } 126 129 130 // Add all connected lines to the string 127 131 $lineString = ''; 128 132 $lineCount = count($this->KMLLines); 129 133 for ($i = 0; $i < $lineCount; $i++) { 130 $lineString .= $this->KMLLines[$i]->toString(); 134 // If longitude2 and latitude2 aren't set, ignore the lines 135 // This happens with all the connections that don't connect 2 nodes 136 if ($this->KMLLines[$i]->isConnected()) { 137 $lineString .= $this->KMLLines[$i]->toString(); 138 } 131 139 } 132 140 … … 137 145 $toString = str_replace('%NODESCONTENT%', $nodeString, $toString); 138 146 $toString = str_replace('%LINESCONTENT%', $lineString, $toString); 139 147 140 148 return $toString; 141 }142 143 /*144 * Function: write145 * Description: Write KMLFile to a KML file146 * Parameters: string $filename147 * Returns: true if we can write to the file, otherwise false148 */149 public function write($filename) {150 // TODO: David: Needs to be placed in FileHandler.class.php. Here we just want to call our file handler.151 152 trigger_log(SYSLOG_DEBUG, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);153 $file = new FileHandler($filename, 'w')154 or trigger_log(SYSLOG_ERR, 'Opening the file "' . $filename . '"', __FILE__, __LINE__);155 156 trigger_log(SYSLOG_DEBUG, 'Writing file "' . $filename . '"', __FILE__, __LINE__);157 $file->write($file,$this->toString());158 159 trigger_log(SYSLOG_DEBUG, 'Closing file "' . $filename . '"', __FILE__, __LINE__);160 fclose($file);161 149 } 162 150 … … 185 173 */ 186 174 public function parseLocationFile($file) { 175 // We want to find all the nodes in the location file and store information of the nodes... 187 176 $nodesCount = preg_match_all('/\[[a-zA-Z0-9]*\]/i', $file, $nodes, PREG_OFFSET_CAPTURE); 188 177 for ($i = 0; $i < $nodesCount; $i++) { 189 178 // Looking for "location" of the node 190 if (!$location = $this->findInLocationFile($file, 'location ', $nodes[0][$i][1])) {179 if (!$location = $this->findInLocationFile($file, 'location = ', $nodes[0][$i][1])) { 191 180 trigger_log(SYSLOG_WARNING, 'Could not find the "location" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 192 181 continue; 193 182 } 194 183 // Looking for "status" of the node 195 if (!$status = $this->findInLocationFile($file, 'status ', $nodes[0][$i][1])) {184 if (!$status = $this->findInLocationFile($file, 'status = ', $nodes[0][$i][1])) { 196 185 trigger_log(SYSLOG_WARNING, 'Could not find the "status" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 197 186 continue; 198 187 } 199 188 // Looking for "latitude" of the node 200 if (!$latitude = $this->findInLocationFile($file, 'latitude ', $nodes[0][$i][1])) {189 if (!$latitude = $this->findInLocationFile($file, 'latitude = ', $nodes[0][$i][1])) { 201 190 trigger_log(SYSLOG_WARNING, 'Could not find the "latitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 202 191 continue; 203 192 } 204 193 // Looking for "longitude" of the node 205 if (!$longitude = $this->findInLocationFile($file, 'longitude ', $nodes[0][$i][1])) {194 if (!$longitude = $this->findInLocationFile($file, 'longitude = ', $nodes[0][$i][1])) { 206 195 trigger_log(SYSLOG_WARNING, 'Could not find the "longitude" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 207 196 continue; 208 197 } 209 198 // Looking for "interfaces" of the node 210 if (!$interfaces = $this->findInLocationFile($file, 'interfaces ', $nodes[0][$i][1])) {199 if (!$interfaces = $this->findInLocationFile($file, 'interfaces = ', $nodes[0][$i][1])) { 211 200 trigger_log(SYSLOG_WARNING, 'Could not find the "interfaces" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 212 201 continue; 213 202 } 214 203 // Looking for "masterip" of the node 215 if (!$masterip = $this->findInLocationFile($file, 'masterip ', $nodes[0][$i][1])) {204 if (!$masterip = $this->findInLocationFile($file, 'masterip = ', $nodes[0][$i][1])) { 216 205 trigger_log(SYSLOG_WARNING, 'Could not find the "masterip" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 217 206 continue; 218 207 } 219 208 // Looking for "nodetype" of the node 220 if (!$nodetype = $this->findInLocationFile($file, 'nodetype ', $nodes[0][$i][1])) {209 if (!$nodetype = $this->findInLocationFile($file, 'nodetype = ', $nodes[0][$i][1])) { 221 210 trigger_log(SYSLOG_WARNING, 'Could not find the "nodetype" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 222 211 continue; 223 212 } 224 213 // Looking for "name" of the node 225 if (!$name = $this->findInLocationFile($file, 'name ', $nodes[0][$i][1])) {214 if (!$name = $this->findInLocationFile($file, 'name = ', $nodes[0][$i][1])) { 226 215 trigger_log(SYSLOG_WARNING, 'Could not find the "name" of node "' . $i . '", skipping to next', __FILE__, __LINE__); 227 216 continue; … … 246 235 $this->addNode($placemark); 247 236 } 237 238 // Now let's find all interlinks with this node 239 $position = $nodes[0][$i][1]; 240 while (($position = strpos($file, 'ip=', $position + 1)) && (isset($nodes[0][$i + 1][1]) && $position < $nodes[0][$i + 1][1])) { 241 $ipAddress = $this->findInLocationFile($file, 'ip=', $position); 242 $posSlash = strpos($ipAddress, '/'); 243 $ip = substr($ipAddress, 0, $posSlash); 244 $netmask = substr($ipAddress, $posSlash + 1); 245 246 $posNetwork = $this->NetworkList->find($ip); 247 if ($posNetwork) { 248 // Network already excists in list, just need to add longitude2 en latitude2 to KMLLine 249 // and add the node name to the name of the line. 250 // Position in network equals position in KMLLine array :-) 251 252 $this->KMLLines[$posNetwork]->setName($this->KMLLines[$posNetwork]->getName() . $name); 253 $this->KMLLines[$posNetwork]->setLongitude2($longitude); 254 $this->KMLLines[$posNetwork]->setLatitude2($latitude); 255 } else { 256 // Network doesn't excist. We create a new network and a new line. 257 258 $network = new Network($ip, $netmask); 259 $this->NetworkList->add($network); 260 261 $line = new KMLLine(); 262 $line->setID($network->networkDecimal); 263 $line->setName('Link: Van ' . $name . ' naar '); 264 $line->setDescription($network->toString()); 265 $line->setLongitude1($longitude); 266 $line->setLatitude1($latitude); 267 $this->KMLLines[] = $line; 268 } 269 } 248 270 } 249 271 } … … 256 278 */ 257 279 private function findInLocationFile($file, $keyword, $offset) { 258 $start = strpos($file, $keyword, $offset) + strlen($keyword . ' = ');280 $start = strpos($file, $keyword, $offset) + strlen($keyword); 259 281 $end = strpos($file, "\n", $start); 260 282 -
trunk/src/inc/KMLLine.class.php
r7765 r7773 19 19 </description> 20 20 <LookAt> 21 <longitude>%LONGITUDE %</longitude>22 <latitude>%LATITUDE %</latitude>21 <longitude>%LONGITUDE1%</longitude> 22 <latitude>%LATITUDE1%</latitude> 23 23 <altitude>0</altitude> 24 24 <heading>0</heading> … … 29 29 <LineString> 30 30 <coordinates> 31 % X1%, %Y1%, 0.32 % X2%, %Y2%, 0.31 %LONGITUDE1%, %LATITUDE1%, 0. 32 %LONGITUDE2%, %LATITUDE2%, 0. 33 33 </coordinates> 34 34 </LineString> … … 38 38 private $name; // Name of the line 39 39 private $description; // Description of the line 40 private $longitude; // Longitude of the line41 private $latitude; // Latitude of the line42 40 private $style; // Style of the line 43 private $ x1; // Start Xof line44 private $ y1; // Start Yof line45 private $ x2; // End Xof line46 private $ y2; // End Yof line41 private $longitude1; // Start longitude of line 42 private $latitude1; // Start latitude of line 43 private $longitude2; // End longitude of line 44 private $latitude2; // End latitude of line 47 45 48 46 /* … … 59 57 $this->latitude = 0; 60 58 $this->style = LINE_BLACK; 61 $this-> x1 = 0;62 $this-> y1 = 0;63 $this-> x2 = 0;64 $this-> y2 = 0;59 $this->longitude1 = 0; 60 $this->latitude1 = 0; 61 $this->longitude2 = 0; 62 $this->latitude2 = 0; 65 63 } 66 64 … … 106 104 107 105 /* 108 * Function: setLongitude109 * Description: Setting the longitude of the placemark110 * Parameters: double $newLongitude111 * Returns: -112 */113 function setLongitude($newLongitude) {114 $this->longitude = (double) $newLongitude;115 }116 117 /*118 * Function: setLatitude119 * Description: Setting the latitude of the placemark120 * Parameters: double $newLatitude121 * Returns: -122 */123 function setLatitude($newLatitude) {124 $this->latitude = (double) $newLatitude;125 }126 127 /*128 106 * Function: setStyle 129 107 * Description: Setting the style of the placemark … … 136 114 137 115 /* 138 * Function: set X1139 * Description: Setting the X1 of the placemark140 * Parameters: double $new X1116 * Function: setLongitude1 117 * Description: Setting the longitude1 of the placemark 118 * Parameters: double $newLongitude 141 119 * Returns: - 142 120 */ 143 function setX1($newX1) { 144 $this->x1 = (double) $newX1; 121 function setLongitude1($newLongitude) { 122 $this->longitude1 = (double) $newLongitude; 123 } 124 125 /* 126 * Function: setLatitude1 127 * Description: Setting the latitude1 of the placemark 128 * Parameters: double $newLatitude 129 * Returns: - 130 */ 131 function setLatitude1($newLatitude) { 132 $this->latitude1 = (double) $newLatitude; 145 133 } 146 134 147 135 /* 148 * Function: set Y1149 * Description: Setting the Y1of the placemark150 * Parameters: double $new Y1136 * Function: setLongitude2 137 * Description: Setting the longitude2 of the placemark 138 * Parameters: double $newLongitude 151 139 * Returns: - 152 140 */ 153 function set Y1($newY1) {154 $this-> y1 = (double) $newY1;141 function setLongitude2($newLongitude) { 142 $this->longitude2 = (double) $newLongitude; 155 143 } 156 144 157 145 /* 158 * Function: set X2159 * Description: Setting the X2 of the placemark160 * Parameters: double $new X2146 * Function: setLatitude2 147 * Description: Setting the latitude2 of the placemark 148 * Parameters: double $newLatitude 161 149 * Returns: - 162 150 */ 163 function set X2($newX2) {164 $this-> x2 = (double) $newX2;151 function setLatitude2($newLatitude) { 152 $this->latitude2 = (double) $newLatitude; 165 153 } 166 154 167 155 /* 168 * Function: setY2169 * Description: Setting the Y2 of the placemark170 * Parameters: double $newY2171 * Returns: -156 * Function: isConnected 157 * Description: Check if it is really a line or just a dot 158 * Parameters: - 159 * Returns: true if the line is connected, otherwise false 172 160 */ 173 function setY2($newY2) { 174 $this->y2 = (double) $newY2; 161 function isConnected() { 162 if (($this->latitude2 == 0) || ($this->longitude2 == 0)) { 163 return false; 164 } 165 166 // This is a line! 167 return true; 175 168 } 176 169 … … 187 180 $toString = str_replace('%NAME%', $this->name, $toString); 188 181 $toString = str_replace('%DESCRIPTION%', $this->description, $toString); 189 $toString = str_replace('%LONGITUDE%', $this->longitude, $toString);190 $toString = str_replace('%LATITUDE%', $this->latitude, $toString);191 182 $toString = str_replace('%STYLE%', $this->style, $toString); 192 $toString = str_replace('% X1%', $this->x1, $toString);193 $toString = str_replace('% Y1%', $this->y1, $toString);194 $toString = str_replace('% X2%', $this->x2, $toString);195 $toString = str_replace('% Y2%', $this->y2, $toString);183 $toString = str_replace('%LONGITUDE1%', $this->longitude1, $toString); 184 $toString = str_replace('%LATITUDE1%', $this->latitude1, $toString); 185 $toString = str_replace('%LONGITUDE2%', $this->longitude2, $toString); 186 $toString = str_replace('%LATITUDE2%', $this->latitude2, $toString); 196 187 197 188 return $toString; -
trunk/src/inc/LogHandler.class.php
r7765 r7773 36 36 37 37 class LogHandler { 38 private $logString; // For caching purposes 39 38 40 /* 39 41 * Function: __construct (constructor) … … 42 44 */ 43 45 public function __construct() { 46 $logString = ''; 44 47 } 45 48 … … 82 85 } 83 86 84 $time = date( "H:i.s m/d/y" ); 85 $errorString .= ' (' . $logno .' | '.$time .' | ): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n"; 87 $errorString .= ' (' . $logno . ' | ' . date('Y/d/m H:i:s') . '): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n"; 86 88 87 89 if ($logno <= LOG_LEVEL_ECHO) { 88 echo '<!-- ' . $errorString . ' -->';90 $this->logString .= $errorString; 89 91 } 90 92 if ((!defined('IGNORE_LOG_LEVEL_WRITE')) && ($logno <= LOG_LEVEL_WRITE)) { … … 118 120 } 119 121 } 122 123 function __destruct() { 124 echo '<!-- ' . $this->logString . ' -->'; 125 } 120 126 } 121 127 -
trunk/src/inc/Network.class.php
r7768 r7773 146 146 return $check; 147 147 } 148 149 /* 150 * Function: toString 151 * Description: Converts the data of the network to a string 152 * Parameters: - 153 * Returns: string with all data 154 */ 155 function toString() { 156 return ' 157 Netmask: ' . $this->netmaskDecimal . ' / ' . $this->netmaskBinary . '<br/> 158 Wildcard: ' . $this->wildcardDecimal . ' / ' . $this->wildcardBinary . '<br/> 159 Network: ' . $this->networkDecimal . ' / ' . $this->networkBinary . '<br/> 160 Broadcast: ' . $this->broadcastDecimal . ' / ' . $this->broadcastBinary . '<br/> 161 HostMin: ' . $this->hostminDecimal . ' / ' . $this->hostminBinary . '<br/> 162 HostMax: ' . $this->hostmaxDecimal . ' / ' . $this->hostmaxBinary . '<br/> 163 Hosts/Net: ' . $this->numberHosts . '<br/>'; 164 } 148 165 } 149 166 ?> -
trunk/src/logfile.txt
r7771 r7773 1 Debug (8 | 2 3:23.36 04/15/10 | ): Opening the file "D:\Werkplaats\NodeMap2.0\trunk\src/kml/nodemap-1271366400.kml"2 In file "D:\Werkplaats\NodeMap2.0\trunk\src\inc\FileHandler.class.php" on line " 22"1 Debug (8 | 2010/16/04 00:39:23): Reading from file "http://watch.wirelessleiden.nl/nagios/export/node-status.csv" 2 In file "D:\Werkplaats\NodeMap2.0\trunk\src\inc\FileHandler.class.php" on line "42" -
trunk/src/test/testNetwork.php
r7768 r7773 12 12 echo ' 13 13 Address: ' . $ip1 . ' / ' . Network::binIP($ip1) . '<br/> 14 Netmask: ' . $network1->netmaskDecimal . ' / ' . $network1->netmaskBinary . '<br/> 15 Wildcard: ' . $network1->wildcardDecimal . ' / ' . $network1->wildcardBinary . '<br/> 16 Network: ' . $network1->networkDecimal . ' / ' . $network1->networkBinary . '<br/> 17 Broadcast: ' . $network1->broadcastDecimal . ' / ' . $network1->broadcastBinary . '<br/> 18 HostMin: ' . $network1->hostminDecimal . ' / ' . $network1->hostminBinary . '<br/> 19 HostMax: ' . $network1->hostmaxDecimal . ' / ' . $network1->hostmaxBinary . '<br/> 20 Hosts/Net: ' . $network1->numberHosts . '<br/> 21 <br/> 14 ' . $network1->toString() . '<br/> 22 15 Address: ' . $ip2 . ' / ' . Network::binIP($ip2) . '<br/> 23 Netmask: ' . $network2->netmaskDecimal . ' / ' . $network2->netmaskBinary . '<br/> 24 Wildcard: ' . $network2->wildcardDecimal . ' / ' . $network2->wildcardBinary . '<br/> 25 Network: ' . $network2->networkDecimal . ' / ' . $network2->networkBinary . '<br/> 26 Broadcast: ' . $network2->broadcastDecimal . ' / ' . $network2->broadcastBinary . '<br/> 27 HostMin: ' . $network2->hostminDecimal . ' / ' . $network2->hostminBinary . '<br/> 28 HostMax: ' . $network2->hostmaxDecimal . ' / ' . $network2->hostmaxBinary . '<br/> 29 Hosts/Net: ' . $network2->numberHosts . '<br/> 30 <br/> 16 ' . $network2->toString() . '<br/> 31 17 Address: ' . $ip3 . ' / ' . Network::binIP($ip3) . '<br/> 32 Netmask: ' . $network3->netmaskDecimal . ' / ' . $network3->netmaskBinary . '<br/> 33 Wildcard: ' . $network3->wildcardDecimal . ' / ' . $network3->wildcardBinary . '<br/> 34 Network: ' . $network3->networkDecimal . ' / ' . $network3->networkBinary . '<br/> 35 Broadcast: ' . $network3->broadcastDecimal . ' / ' . $network3->broadcastBinary . '<br/> 36 HostMin: ' . $network3->hostminDecimal . ' / ' . $network3->hostminBinary . '<br/> 37 HostMax: ' . $network3->hostmaxDecimal . ' / ' . $network3->hostmaxBinary . '<br/> 38 Hosts/Net: ' . $network3->numberHosts . '<br/> 39 <br/> 18 ' . $network3->toString() . '<br/> 40 19 Compare network 1 by network 1: ' . $network1->compare($network1) . '<br/> 41 20 Compare network 1 by network 2: ' . $network1->compare($network2) . '<br/>
Note:
See TracChangeset
for help on using the changeset viewer.