diff options
-rw-r--r-- | config.php | 21 | ||||
-rw-r--r-- | data.php | 145 | ||||
-rw-r--r-- | db.class.php | 61 | ||||
-rw-r--r-- | ipmatch.php | 17 |
4 files changed, 244 insertions, 0 deletions
diff --git a/config.php b/config.php new file mode 100644 index 0000000..063a41f --- /dev/null +++ b/config.php @@ -0,0 +1,21 @@ +<?php + +$conf['db']['user'] = 'ffscript'; +$conf['db']['password'] = 'woasinid'; +$conf['db']['host'] = 'localhost'; +$conf['db']['database'] = 'mappe'; + +$conf['topo']['file'] = 'topology.dot.plain'; + +/* neue eintraege bitte kommentieren !!!! */ +$conf['acl']['range'] = array( + "10.0.0.0/8", // Funkfeuer Graz Private + "83.64.208.18/32", // Funkfeuer Graz Nat + "193.33.150.0/23", // Funkfeuer Graz Public + "193.238.156.0/22", // Funkfeuer Wien + "89.106.208.0/21", // mur.at +// "84.119.56.63/32", // equinox home test + "212.17.113.195/32" // roland home wien +); + +?> diff --git a/data.php b/data.php new file mode 100644 index 0000000..97e59b4 --- /dev/null +++ b/data.php @@ -0,0 +1,145 @@ +<?php
+/*
+ * Copyright (C) 2006 Gaubatz Patrick <patrick@gaubatz.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+require_once("db.class.php");
+require_once("ipmatch.php");
+require_once("config.php");
+
+header("Content-Type: text/xml");
+header("Cache-Control: no-cache, must-revalidate");
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+
+$db = new DB($conf['db']['user'], $conf['db']['password'], $conf['db']['host'], $conf['db']['database']);
+$conf['acl']['auth'] = match_network($conf['acl']['range'],$_SERVER[REMOTE_ADDR]);
+
+$x_startpoint = 4080;
+$lng_startpoint = 15.43844103813;
+$dx_dLng = 50675.5176;
+$y_startpoint = 4806;
+$lat_startpoint= 47.07177327969;
+$dy_dLat = 75505.521;
+
+$locations = array();
+$locids = array();
+$nodename = array();
+$links = array();
+$already = array();
+$count = array();
+
+$db->query("SELECT ip, location.id as locid,location.name as locname, node.name as nodename FROM ip, node, location WHERE ip.node_id = node.id and node.location_id=location.id");
+while ($data = $db->getNextObject()) {
+ $locids[$data->ip]= $data->locid;
+ $nodename[$data->ip]= $data->nodename;
+}
+
+if($conf['acl']['auth'])
+ $db->query("SELECT id as locid, name as locname, pixel_x, pixel_y, gallery_link, location.hastinc as hastinc FROM location ORDER BY name ASC");
+else
+ $db->query("SELECT id as locid, name as locname, pixel_x, pixel_y, gallery_link, location.hastinc as hastinc FROM location WHERE location.hidden = 0 ORDER BY name ASC");
+
+while ($data = $db->getNextObject()) {
+ if ($data->pixel_x == "0")
+ continue;
+
+ $data->lng = $lng_startpoint + ($data->pixel_x - $x_startpoint) / $dx_dLng;
+ $data->lat = $lat_startpoint + ($y_startpoint - $data->pixel_y) / $dy_dLat;
+ $locations[$data->locid] = $data;
+}
+
+$regmatch = '#\"(.+)\" -> \"(.+)\"\[label=\"([0-9]+.[0-9]+)\"]#';
+$lines = file($conf['topo']['file']);
+
+$linecnt=0;
+$i =0;
+foreach ($lines as $num => $line)
+{
+ $linecnt++;
+ preg_match($regmatch,$line,$matches);
+ list( , $ipfromLoc, $iptoLoc, $label) = $matches;
+
+ if (empty($ipfromLoc) || empty($iptoLoc) || empty($label))
+ continue;
+
+ if(empty($locations[$locids[$ipfromLoc]]->locid) || empty($locations[$locids[$iptoLoc]]->locid))
+ continue;
+
+ if($locations[$locids[$ipfromLoc]]->locid == $locations[$locids[$iptoLoc]]->locid)
+ continue;
+
+ if($already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used == true) {
+ $jot = $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i;
+ $links[$jot]->label = ($links[$jot]->label + $label)/2;
+ }
+ elseif($already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->used == true) {
+ $jot = $already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->i;
+ $links[$jot]->label = ($links[$jot]->label + $label)/2;
+ }
+ else {
+ $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used =true;
+ $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i = $i;
+
+ $links[$i]->ipfromLoc = $ipfromLoc;
+ $links[$i]->iptoLoc = $iptoLoc;
+ $links[$i]->label = $label;
+ $i++;
+ }
+}
+
+
+echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
+echo "<root>\n";
+
+echo "<nodes>\n";
+foreach ($locations as $location) {
+ $data = $locations[$location->locid];
+ printf("\t" . '<node id="%s" name="%s" lat="%s" lng="%s" pixel_x="%s" pixel_y="%s" gallery_link="%s"/>' . "\n",
+ $data->locid, $data->locname, $data->lat, $data->lng, $data->pixel_x, $data->pixel_y, $data->gallery_link);
+}
+echo "</nodes>\n";
+
+echo "<links>\n";
+foreach ($links as $link)
+{
+ if (($nodename[$link->ipfromLoc] == "tunnel" && $locations[$locids[$link->ipfromLoc]]->locname=="housing") ||
+ ($nodename[$link->iptoLoc] == "tunnel" && $locations[$locids[$link->iptoLoc]]->locname=="housing" ))
+ $link->label = -1;
+
+ if ($locations[$locids[$link->iptoLoc]]->hastinc && $locations[$locids[$link->ipfromLoc]]->hastinc)
+ $link->label = -1;
+
+ $data1 = $locations[$locids[$link->ipfromLoc]];
+ $data2 = $locations[$locids[$link->iptoLoc]];
+
+ $count[$data1->locid]=true;
+ $count[$data2->locid]=true;
+
+ printf("\t" . '<link fromid="%s" from="%s" latfrom="%s" lngfrom="%s" toid="%s" to="%s" latto="%s" lngto="%s" color="%s" />' . "\n",
+ $data1->locid, $data1->locname, $data1->lat,$data1->lng,$data2->locid, $data2->locname, $data2->lat, $data2->lng, $link->label);
+}
+echo "</links>\n";
+
+echo "<count>\n";
+printf("\t" . '<count number="');
+echo sizeof($count);
+printf('" />' . "\n");
+echo "</count>\n";
+
+echo "</root>";
+
+?>
diff --git a/db.class.php b/db.class.php new file mode 100644 index 0000000..6603804 --- /dev/null +++ b/db.class.php @@ -0,0 +1,61 @@ +<?php
+/*
+ * Copyright (C) 2006 Gaubatz Patrick <patrick@gaubatz.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+class DB {
+ var $user, $pass, $host, $dbname;
+ var $db;
+ var $res;
+
+ function DB($user, $pass, $host, $dbname) {
+ $this->user = $user;
+ $this->pass = $pass;
+ $this->host = $host;
+ $this->dbname = $dbname;
+
+ $this->connect();
+ }
+
+ function connect() {
+ $this->db = mysql_connect($this->host, $this->user, $this->pass)
+ or $this->error("Verbindungsaufbau fehlgeschlagen");
+
+ mysql_select_db($this->dbname);
+ }
+
+ function error($msg) {
+ die($msg . ": " . @mysql_error());
+ }
+
+ function query($query) {
+ $this->res = mysql_query($query, $this->db)
+ or $this->error("Fehler bei Datenbankanfrage");
+ }
+
+ function numObjects() {
+ return mysql_num_rows($this->res);
+ }
+
+ function getNextObject() {
+ if (!$this->res) {
+ return;
+ }
+ return mysql_fetch_object($this->res);
+ }
+}
+?>
diff --git a/ipmatch.php b/ipmatch.php new file mode 100644 index 0000000..058f878 --- /dev/null +++ b/ipmatch.php @@ -0,0 +1,17 @@ +<?php +function match_network ($nets, $ip) { + foreach ($nets as $net) { + $ip_arr = explode('/', $net); + if (!$ip_arr[1]) + $ip_arr[1] = '32'; + + $net_long = ip2long($ip_arr[0]); + $x = ip2long($ip_arr[1]); + $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); + $ip_long = ip2long($ip); + + if (($ip_long & $mask) == ($net_long & $mask)) return true; + } + return false; +} +?> |