~budgester/irm/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
################################################################################
#    IRM - The Information Resource Manager
#    Copyright (C) 2003 Yann Ramin
#
#    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 (in file COPYING) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
################################################################################

class networking
{
	function networking()
	{
		$this->networking_fields = array(
			'name'			 => _("Name"),
			'ID'			 => _("IRM ID"),
			'location'		 => _("Location"),
			'type'			 => _("Type"),
			'ram'			 => _("RAM Amount (in MB)"),
			'serial'		 => _("Serial Number"),
			'otherserial'		 => _("Other Number"),
			'ip'			 => _("IP Address"),
			'mac'			 => _("MAC/Network Address"),
			'comments'		 => _("Comments"),
			'contact'		 => _("Contact Person"),
			'contact_num'		 => _("Contact Number"),
			'date_mod'		 => _("Date Last Modified")
			);


		$this->ID = $_REQUEST['ID'];

		switch($_REQUEST['action'])
		{
			case 'delete':
				AuthCheck("tech");
				$this->deleteNetworking();
				break;
			case 'info':
				$this->showNetworking();
				break;
			case 'select-add':
				AuthCheck("tech");
				$this->addNetworking();
				break;
			case 'add':
				AuthCheck("tech");
				$this->saveNetworking();
				break;
			case 'update';
				AuthCheck("tech");
				$this->updateNetworking();
				break;
			case 'all';
				AuthCheck("tech");
				$this->addAllPorts();
				break;	

			case 'addPort';
				AuthCheck("tech");
				$this->addPort();
				break;	

			case 'deletePort';
				AuthCheck("tech");
				$this->deletePort();
				break;	


			default:	
				$this->search();
		}
	}

	function deletePort()
	{
		$port = new DeviceConnection();
		$port->deletePort();
	}

	function addPort()
	{
		$port = new DeviceConnection();
		$port->addPort();
	}

	function addAllPorts()
	{
		$port = new DeviceConnection();
		$port->addAllPorts();
	}

	function deleteNetworking()
	{
		commonHeader(_("Networking") . " - " . _("Device Deleted"));

		$DB = Config::Database();
		$qID = $DB->getTextValue($_REQUEST['ID']);
		$query = "SELECT id FROM networking_ports WHERE (device_on = $qID AND device_type = 2)";
		$ports = $DB->getCol($query);
		foreach ($ports as $portid)
		{
			$qport = $DB->getTextValue($portid);
			$query = "DELETE FROM networking_wire WHERE end1=$qport OR end2=$qport";
			$DB->query($query);
		} 
		 
		$query = "DELETE FROM networking WHERE (ID = $qID)";
		$DB->query($query);
		$query = "DELETE FROM networking_ports WHERE (device_on = $qID AND device_type = 2)";
		$DB->query($query);

		__("I have deleted that networking device and all associated ports.");

		commonFooter();
	}


	function updateNetworking()
	{
		$vals = array(
			'name' => $_REQUEST['name'],
			'type' => $_REQUEST['type'],
			'ram' => $_REQUEST['ram'],
			'ip' => $_REQUEST['ip'],
			'mac' => $_REQUEST['mac'],
			'location' => $_REQUEST['location'],
			'serial' => $_REQUEST['serial'],
			'otherserial' => $_REQUEST['otherserial'],
			'contact' => $_REQUEST['contact'],
			'contact_num' => $_REQUEST['contact_num'],
			'datemod' => date('Y-m-d H:i:s'),
			'comments' => $_REQUEST['comments']
			);

		$DB = Config::Database();
		$ID = $DB->getTextValue($_REQUEST['ID']);
		$DB->UpdateQuery('networking', $vals, "ID=$ID");

		logevent($ID, _("networking"), 4, _("database"), sprintf(_("%s updated record"),$IRMName));
		header("Location: ".$_SESSION['_sess_pagehistory']->Previous());
	}

	function saveNetworking()
	{
		AuthCheck("tech");

		$new_date = date("Y-m-d H:i:s");
		$DB = Config::Database();

		$ID = $DB->nextId('networking__ID');
		$vals = array(
			'ID' => $ID,
			'name' => $_REQUEST['name'],
			'type' => $_REQUEST['type'],
			'ram' => $_REQUEST['ram'],
			'ip' => $_REQUEST['ip'],
			'mac' => $_REQUEST['mac'],
			'location' => $_REQUEST['location'],
			'serial' => $_REQUEST['serial'],
			'otherserial' => $_REQUEST['otherserial'],
			'contact' => $_REQUEST['contact'],
			'contact_num' => $_REQUEST['contact_num'],
			'datemod' => $new_date,
			'comments' => $_REQUEST['comments']
			);
		$DB->InsertQuery('networking', $vals);

		for ($i = 1; $i <= $_REQUEST['numports']; $i++)
		{
			$vals = array(
				'device_on' => $ID,
				'device_type' => 2,
				'iface' => $_REQIEST['ifacetype'],
				'ifaddr' => $_REQUEST['ip'],
				'ifmac' => $_REQUEST['mac'],
				'logical_number' => $i,
				'name' => "Port $i"
				);
			$DB->InsertQuery('networking_ports', $vals);
		}
		logevent($ID, "networking", 4, "database", sprintf(_("%s added record"), $IRMName));

		header("Location: ".$_SESSION['_sess_pagehistory']->Previous());
	}

	function search()
	{
		commonHeader(_("Networking"));
		__("Welcome to the IRM Networking section.  This where you keep information about all of your networking devices.");
		$deviceType = "networking";
		deviceSearch($deviceType,$this->networking_fields);
		commonFooter();
	}
	function networkingForm($formtype,$result)
	{
		$this->page = new IrmFactory();

		if ($formtype == "show"){
			$name = $result["name"];
			$type = $result["type"];
			$ram = $result["ram"];
			$serial = $result["serial"];
			$otherserial = $result["otherserial"];
			$location = $result["location"];
			$ip = $result["ip"];
			$mac = $result["mac"];
			$contact = $result["contact"];
			$contact_num = $result["contact_num"];
			$comments = $result["comments"];

			$comments = stripslashes($comments);
		}

		$this->page->assign('name', _("Name"));
		$this->page->assign('nameName', "name");
		$this->page->assign('nameValue', $name);

		$this->page->assign('type', _("Type"));
		$this->page->assign('typeDropdown',Dropdown_value("dropdown_type", "type", $type));
		
		$this->page->assign('location', _("Location"));
		$this->page->assign('locationDropdown', Dropdown_value("dropdown_locations", "location", $location));
		
		$this->page->assign('ram', _("RAM Amount (in MB)"));
		$this->page->assign('nameRam', "ram");
		$this->page->assign('ramValue', $ram);

		$this->page->assign('serial',_("Serial Number"));
		$this->page->assign('nameSerial', "serial" );
		$this->page->assign('serialValue', $serial );

		$this->page->assign('otherSerial',_("Other Serial Number"));
		$this->page->assign('nameOtherSerial', "otherserial" );
		$this->page->assign('otherSerialValue', $otherserial );

		$this->page->assign('ip',_("IP"));
		$this->page->assign('nameIP', "ip" );
		$this->page->assign('ipValue', $ip);

		$this->page->assign('mac',_("MAC/Network Address"));
		$this->page->assign('nameMAC', "mac" );
		$this->page->assign('macValue', $mac );

		$this->page->assign('contact',_("Contact"));
		$this->page->assign('nameContact', "contact" );
		$this->page->assign('contactValue', $contact);

		$this->page->assign('contactNumber',_("Contact Number"));
		$this->page->assign('nameContactNumber', "contact_num" );
		$this->page->assign('contactNumberValue', $contact_num);

		$this->page->assign('comments',_("Comments"));
		$this->page->assign('nameComments', "comments" );
		$this->page->assign('commentsValue', $comments);

		$this->page->display('networkingForm.html.php');
	}

	function showNetworking()
	{
		commonHeader(_("Networking"));

		$ID = $this->ID;

		$DB = Config::Database();

		$qID = $DB->getTextValue($ID);
		$query = "SELECT * FROM networking WHERE (ID = $qID)";

		$result = $DB->getRow($query);

		$name = $result["name"];
		$ip = $result["ip"];
		$datemod = $result["datemod"];
		$new_date = date("Y-m-d H:i:s");
		
		PRINT '<table class="networking ">';
		PRINT '<form method=post action="'.Config::AbsLoc('users/networking-index.php').'">';
		PRINT "<input type=hidden name=ID value=\"$ID\">";
		PRINT "<input type=hidden name=action value=update>";
		PRINT '<tr class="networkingheader">';
		PRINT '<td colspan=2>';
		PRINT "$ip  ";
		PRINT SnmpStatus($ip,$ID, "networking");
		PRINT "<strong>$name ($ID)</strong></td>";
		PRINT "</tr>";

		$this->networkingForm("show", $result);	

		PRINT '<tr class="networkingheader">';
		PRINT "<td colspan=2 align=center>";
		PRINT _("Last Updated:")." $date_mod <input type=hidden name=date_mod value=\"$new_date\">";
		PRINT "</td>";
		PRINT "</tr>\n";
		PRINT "</table>";

		PRINT '<table class="networking ">';
		PRINT '<tr class="networkingupdate">';
		PRINT "<td>";
		PRINT "<input type=submit value=\""._("Update")."\"></form>";
		PRINT "</td>";
		PRINT "<td>";
		PRINT '<form method=post action="'.Config::AbsLoc('users/networking-index.php').'">';
		PRINT "<input type=hidden name=ID value=$ID>";
		PRINT "<input type=hidden name=action value=delete>";
		PRINT "<input type=submit value=\""._("Delete")."\"></form>";
		PRINT "</td>";
		PRINT "</tr>";
		PRINT "</table>";
	
		$ports = new ports();	
		$ports->showPortsOnDevice($ID, 2);

		$files = new Files();	
		$files->setDeviceType("networking");
		$files->setDeviceID($ID);
		$files->displayAttachedFiles();
		$files->displayFileUpload();

		commonFooter();
	}

	function addNetworking()
	{
		commonHeader(_("Networking"));
		__("Fill out this form to add a new networking device.");

		PRINT '<table class="networking">';
		PRINT '<form method=get action="'.Config::AbsLoc('users/networking-index.php').'">';
		PRINT '<tr class="networkingheader">';
		PRINT '<td colspan=2>';
		PRINT "<strong>" . _("New Device") . "</strong>";
		PRINT "</td>";
		PRINT "</tr>";

		$this->networkingForm("add","");	

		PRINT '<tr class="networkingupdate">';
		PRINT "<td><input type=submit value=\""._("Add")."\"></td>";
		PRINT "<td><input type=hidden name=action value=add></td>";
		PRINT "<td>";
		PRINT "<input type=reset value="._("Clear").">";
		PRINT "</td>";
		PRINT "</tr>";
		PRINT "</table>";
		
		PRINT "<br />";
		
		printf(_("Add %s initial ports of type %s to device."),
			"<input type=text name=numports size=3 value=8>",
			Dropdown("dropdown_iface", "ifacetype"));
		PRINT "</form>";
		commonFooter();
	}
}
?>