2
################################################################################
3
# IRM - The Information Resource Manager
4
# Copyright (C) 2003 Yann Ramin
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
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 (in file COPYING) for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
################################################################################
21
class ports extends IRMMain
25
commonHeader(_("Networking Connector Wizard"));
26
if($_REQUEST['connect']){
29
$this->pID=$_REQUEST['pID'];
30
$this->device=$_REQUEST['device'];
31
$this->device_name=$_REQUEST['device_name'];
32
$this->selectDeviceType();
33
if($this->device != NULL){
34
$this->selectDevice();
36
if($this->device_name != NULL){
45
$query = "SELECT * FROM networking_ports WHERE (device_on = $this->device_name) AND (device_type =\"$this->device\") ORDER BY logical_number";
46
$DB = Config::Database();
47
$data = $DB->getAll($query);
48
PRINT "<table class=networking>";
50
PRINT "<th>" .("ID") . "</th>";
51
PRINT "<th>" .("Port Name") . "</th>";
52
PRINT "<th>" .("Type") . "</th>";
53
PRINT "<th>" .("IP Address") . "</th>";
54
PRINT "<th>" .("MAC Address") . "</th>";
55
PRINT "<th>" .("Port Name") . "</th>";
58
foreach($data as $port){
59
PRINT "<form type=post method=$_SELF>";
62
PRINT "<td class=networkingdetail>";
63
PRINT "<input type=hidden name=pID value=" . $port['ID']. ">";
64
PRINT "<input type=hidden name=pID1 value=$this->pID>";
65
PRINT "<input type=hidden name=connect value=true>";
66
PRINT "<input type=submit value=" . _("Connect") . ">";
69
PRINT "<td class=networkingdetail>" . $port['logical_number'] . "</td>";
70
PRINT "<td class=networkingdetail>" . $port['name'] . "</td>";
71
PRINT "<td class=networkingdetail>" . $port['iface'] . "</td>";
72
PRINT "<td class=networkingdetail>" . $port['ifaddr'] . "</td>";
73
PRINT "<td class=networkingdetail>" . $port['ifmac'] . "</td>";
80
function updateWires()
83
'end1' => $_REQUEST[pID],
84
'end2' => $_REQUEST[pID1]
86
$DB = Config::Database();
87
$DB->InsertQuery('networking_wire', $vals);
88
PRINT _("You have now connected two devices");
94
function portsTableHead()
96
PRINT '<table class="networking">';
97
PRINT '<tr class="networkingheader">';
98
PRINT "<th>"._("Port #")."</th>";
99
PRINT "<th>"._("Name")."</th>";
100
PRINT "<th>"._("Interface")."</th>";
101
PRINT "<th>"._("IP Address")."</th>";
102
PRINT "<th>"._("MAC/Network Address")."</th>";
104
if(Config::Get('mrtg')== "1"){
105
PRINT "<th>"._("MRTG Graph")."</th>";
107
PRINT "<th>"._("Connected to...")."</th>";
112
function getPortsOnDevice($device, $device_type)
114
$DB = Config::Database();
115
$qdevice = $DB->getTextValue($device);
116
$qdevice_type = $DB->getTextValue($device_type);
117
$query = "SELECT * FROM networking_ports WHERE (device_on = $qdevice AND device_type = $qdevice_type) ORDER BY logical_number";
119
$data = $DB->getAll($query);
123
function getWires($ID)
125
$DB = Config::Database();
126
$qID = $DB->getTextValue($ID);
127
$wquery = "SELECT * FROM networking_wire WHERE (end1 = $qID OR end2 = $qID)";
128
$wire = $DB->getRow($wquery);
132
function showPortRow($data, $ip)
134
$DB = Config::Database();
135
$userbase = Config::AbsLoc('users');
137
foreach ($data as $result)
143
$name = $result["name"];
144
$logical_number = $result["logical_number"];
145
$iface = $result["iface"];
146
$ifaddr = $result["ifaddr"];
147
$ifmac = $result["ifmac"];
149
$wire = getWires($ID);
151
if (count($wire) > 0)
154
$wend1 = $wire["end1"];
155
$wend2 = $wire["end2"];
158
$qend = $DB->getTextValue($wend2);
160
$qend = $DB->getTextValue($wend1);
163
$pquery = "SELECT * FROM networking_ports WHERE (ID = $qend)";
164
$farend = $DB->getRow($pquery);
166
$pID = $farend["ID"];
167
$pNum = $farend["logical_number"];
168
$pOn = $farend["device_on"];
169
$pName = $farend["name"];
170
$pType = $farend["device_type"];
171
$qOn = $DB->getTextValue($pOn);
176
$portOnDeviceType = "computers";
179
$portOnDeviceType = "networking";
182
$portOnDeviceType = $pType;
185
$nquery = "SELECT ID,name FROM $portOnDeviceType WHERE (ID = $qOn) order by name";
187
$nresult = $DB->getRow($nquery);
188
$nname = $nresult["name"];
189
$nID = $nresult["ID"];
198
PRINT '<tr class="networkingdetail">';
199
PRINT "<td><a href=\"$userbase/networking-port.php?ID=$ID\">$logical_number</a></td>\n";
200
PRINT "<td>$name</td>\n";
201
PRINT "<td>$iface</td>\n";
202
PRINT "<td>$ifaddr</td>\n";
203
PRINT "<td>$ifmac</td>\n";
205
//TODO MRTG Graph of port
207
if(Config::Get('mrtg')== "1"){
208
$url = Config::Get('mrtglocation');
210
if($ifaddr && $ifaddr != "127.0.0.1"){
211
PRINT "<td><img src=" . $url . $ifaddr . "_" . $logical_number . "-day.png></td>\n";
212
}elseif ($ip != null && $ifaddr != "127.0.0.1"){
213
PRINT "<td><img src=http://192.168.1.11/~budgester/mrtg/" . $ip . "_" . $logical_number . "-day.png></td>\n";
222
PRINT _("Nothing Connected.")." <a href=\"$userbase/ports.php?pID=$ID\">"._("Connect")."</a>\n";
227
PRINTF(_("Connected to port %s on computer %s"),
228
"<a href=\"$userbase/networking-port.php?ID=$pID\">$pNum ($pName)</a>\n",
229
"<a href=\"$userbase/computers-index.php?action=info&ID=$nID\">$nname ($nID)</a>\n"
231
PRINT " | <a href=\"$userbase/networking-port-discon.php?ID=$ID\">"._("Disconnect")."</a>.\n";
234
PRINTF(_("Connected to port %s on network device %s"),
235
"<a href=\"$userbase/networking-port.php?ID=$pID\">$pNum ($pName)</a>\n",
236
"<a href=\"$userbase/networking-index.php?devicetype=networking&action=info&ID=$nID\">$nname ($nID)</a>\n"
238
PRINT " | <a href=\"$userbase/networking-port-discon.php?ID=$ID\">"._("Disconnect")."</a>.\n";
241
PRINTF(_("Connected to port %s on %s device %s"),
242
"<a href=\"$userbase/networking-port.php?ID=$pID\">$pNum $pName</a>\n",
244
"<a href=\"$userbase/device-info.php?ID=$nID&devicetype=$pType\">$nname ($nID)</a>\n"
246
PRINT " | <a href=\"$userbase/networking-port-discon.php?ID=$ID\">"._("Disconnect")."</a>.\n";
254
function showPortsOnDevice($device, $device_type)
256
# 1 is computer, 2 networking device
258
$userbase = Config::AbsLoc('users');
259
$data = getPortsOnDevice($device, $device_type);
263
if(Config::Get('snmp')== "1"){
264
$deviceConnection = new DeviceConnection;
265
$ip = $deviceConnection->ID2IP($device, $device_type);
268
if (count($data) < 1){
269
PRINT "<TR><td colspan=6>"._("Looks like a lonely device to me. No ports found.")."</TD></TR>\n";
271
showPortRow($data, $ip);
274
PRINT '<tr class="networkingupdate">';
275
PRINT "<td colspan=6 align=right><A HREF=\"$userbase/networking-port-add-form.php?device=$device&device_type=$device_type\">"._("Add Port")."</a></td>\n";