ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

list_interfaces.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_display_list()
7 //
8 // Description:
9 // Displays A list of interfaces based on search criteria.
10 // Input: An array from xajaxGetFormValues() from a quick filter form.
12 function ws_display_list($window_name, $form='') {
13  global $conf, $self, $onadb;
14  global $images, $color, $style;
15  $html = '';
16  $js = '';
17 
18  // If the user supplied an array in a string, build the array and store it in $form
19  $form = parse_options_string($form);
20 
21  // Find the "tab" we're on
22  $tab = $_SESSION['ona'][$form['form_id']]['tab'];
23 
24  // Build js to refresh this list
25  $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
26 
27  // If this is the display_host screen that called, add refresh for DNS records too
28  if ($form['content_id'] == 'display_host_list_interfaces' )
29  $refresh .= "xajax_window_submit('list_records', xajax.getFormValues('list_records_filter_form'), 'display_list');";
30 
31  // If it's not a new query, load the previous query from the session
32  // into $form and save the current page and filter in the session.
33  // Also find/set the "page" we're viewing
34  $page = 1;
35  if ($form['page'] and is_numeric($form['page'])) {
36  $form = array_merge($form, (array)$_SESSION['ona'][$form['form_id']][$tab]['q']);
37  $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
38  $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
39  }
40 
41  // Calculate the SQL query offset (based on the page being displayed)
42  $offset = ($conf['search_results_per_page'] * ($page - 1));
43  if ($offset == 0) { $offset = -1; }
44 
45  // Search results go in here
46  $results = array();
47  $count = 0;
48 
49  // Start building the "where" clause for the sql query to find the interfaces to display
50  $where = "";
51  $and = "";
52 
53  // HOST ID
54  if ($form['host_id']) {
55  $where .= $and . "host_id = " . $onadb->qstr($form['host_id']). " OR id in (select interface_id from interface_clusters where host_id = ".$onadb->qstr($form['host_id']).")";
56  $and = " AND ";
57  }
58 
59  // Do the SQL Query
60  $filter = '';
61  if ($form['filter']) {
62  $form['filter'] = ip_mangle($form['filter']);
63  $filter = $and . ' ip_addr LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
64  }
65  list ($status, $rows, $results) =
67  $onadb,
68  'interfaces',
69  $where . $filter,
70  "ip_addr ASC",
71  $conf['search_results_per_page'],
72  $offset
73  );
74 
75  // If we got less than serach_results_per_page, add the current offset to it
76  // so that if we're on the last page $rows still has the right number in it.
77  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
78  $rows += ($conf['search_results_per_page'] * ($page - 1));
79  }
80 
81 
82  // Re-Count only "internal" interfaces, not nat interfaces
83  list ($status, $rows, $records) =
85  $onadb,
86  'interfaces',
87  'nat_interface_id = \'0\' and ' . $where . $filter,
88  "",
89  0
90  );
91  $count = $rows;
92 
93 
94 
95  $html .= <<<EOL
96  <!-- Interface List -->
97  <table id="{$form['form_id']}_interface_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
98 
99  <!-- Table Header -->
100  <tr>
101 
102  <td colspan="2" class="list-header" align="center" style="{$style['borderR']};">Interface</td>
103  <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
104  <td class="list-header" align="center" style="{$style['borderR']};">MAC</td>
105  <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
106  <td class="list-header" align="center" style="{$style['borderR']};">Description</td>
107  <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td>
108  <td class="list-header" align="center">&nbsp;</td>
109  </tr>
110 EOL;
111 
112  // Loop and display each record
113  foreach($results as $record) {
114  // Get additional info about each host record //
115 
116  // Check if this interface has an external NAT
117  unset($extnatint, $extnatdisplay, $extnatdisplay, $extnatsubdisplay);
118  if ($record['nat_interface_id'] > 0) {
119  list($status, $rows, $extnatint) = ona_get_interface_record(array('id' => $record['nat_interface_id']));
120  // GDO: get the subnet object of the NATing interface, display it in both Interface and Subnet columns
121  list($status, $rows, $extnatintsub) = ona_get_subnet_record(array('id' => $extnatint['subnet_id']));
122  $extnatint['ip_addr'] = ip_mangle($extnatint['ip_addr'], 'dotted');
123  //$extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']}'> &nbsp;&nbsp;=> &nbsp;{$extnatint['ip_addr']}</span>";
124  $extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']} (on {$extnatintsub['name']})'> &nbsp;&nbsp;=> &nbsp;{$extnatint['ip_addr']}</span>";
125  $extnatsubdisplay = " => <a title=\"View NATed subnet. ID: {$extnatintsub['id']}\"
126  class=\"nav\"
127  onClick=\"xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$extnatintsub['id']}\', \'display\')');\"
128  >{$extnatintsub['name']}</a>";
129  }
130 
131  // Check if this interface is an external NAT for another interface
132  list ($isnatstatus, $isnatrows, $isnat) = db_get_records($onadb, 'interfaces', "nat_interface_id = {$record['id']}", '', 0 );
133  // If the current interface is external NAT for another, dont display it in the list.
134  if ($isnatrows > 0) {
135  continue;
136  }
137 
138  list ($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$record['id']}");
139 
140  // Grab some info from the associated subnet record
141  list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $record['subnet_id']));
142  $record['ip_mask'] = $subnet['ip_mask'];
143  $record['subnet_id'] = $subnet['id'];
144  $record['subnet_description'] = $subnet['name'];
145 
146  // Convert IP and Netmask to a presentable format
147  $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
148  $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
149  $record['ip_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr');
150  if ($record['mac_addr']) { $record['mac_addr'] = mac_mangle($record['mac_addr']); }
151 
152  $record['description_short'] = truncate($record['description'], 40);
153 
154  // Escape data for display in html
155  foreach(array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); }
156 
157 
158  // Format the date and colorize if its older than 2 months
159  if ($record['last_response']) {
160  $record['last_response_fmt'] = date($conf['date_format'],strtotime($record['last_response']));
161  if (strtotime($record['last_response']) < strtotime('-2 month')) {
162  $record['last_response_fmt'] = "<span style=\"color: red;\">".$record['last_response_fmt']."</style>";
163  }
164  }
165 
166  $html .= <<<EOL
167  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
168 
169  <td nowrap="true" class="list-row" style="padding: 0px;" width="16px">
170 EOL;
171 
172  // Display cluster related information
173  $clusterhtml='&nbsp;';
174  $clusterstyle='';
175  $clusterscript='';
176 
177  if ($intclusterrows>0) {
178  $clusterstyle='font-weight: bold';
179  $clusterscript= "onMouseOver=\"wwTT(this, event,
180  'id', 'tt_interface_cluster_list_{$record['id']}',
181  'type', 'velcro',
182  'styleClass', 'wwTT_niceTitle',
183  'direction', 'south',
184  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$record['id']},interface_id=>{$record['id']}\');'
185  );\"";
186  $clusterhtml .= <<<EOL
187  <img src="{$images}/silk/sitemap.png" border="0" {$clusterscript} />
188 EOL;
189  }
190  $html .= $clusterhtml;
191 
192 
193 
194  $html .= <<<EOL
195  </td>
196 
197  <td class="list-row">
198 EOL;
199 
200  // MP: Disabling the display_interface link. I dont think this will be needed
201  if (1<0) {
202  $html .= <<<EOL
203  <a title="View interface. ID: {$record['id']}"
204  class="nav"
205  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_interface\',\'interface_id=>{$record['id']}\', \'display\')');">
206  {$record['ip_addr']}
207  </a>
208 EOL;
209  }
210  else {
211  $html .= "<span style='{$clusterstyle}' {$clusterscript}>{$record['ip_addr']}</span>";
212  }
213  $html .= <<<EOL
214  <span style="{$clusterstyle}" title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span> {$extnatdisplay}
215  </td>
216 
217  <td class="list-row" align="left">
218  <a title="View subnet. ID: {$subnet['id']}"
219  class="nav"
220  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$subnet['id']}\', \'display\')');"
221  >{$record['subnet_description']}</a> {$extnatsubdisplay}
222  </td>
223 
224  <td class="list-row" align="right">
225  {$record['mac_addr']}&nbsp;
226  </td>
227 
228  <td class="list-row" align="left">
229  {$record['name']}&nbsp;
230  </td>
231 
232  <td class="list-row" align="left" title="{$record['description']}">
233  {$record['description_short']}&nbsp;
234  </td>
235 
236  <td class="list-row" align="left" title="{$record['last_response']}">
237  {$record['last_response_fmt']}&nbsp;
238  </td>
239 
240  <td class="list-row" align="right">
241  <form id="{$form['form_id']}_list_interface_{$record['id']}"
242  ><input type="hidden" name="interface_id" value="{$record['id']}"
243  ><input type="hidden" name="js" value="{$refresh}"
244  ></form>&nbsp;
245 EOL;
246 
247  if (auth('interface_modify')) {
248  $html .= <<<EOL
249 
250  <a title="Interface Menu"
251  id="int_menu_button_{$record['id']}"
252  class="act"
253  onmouseover="wwTT(this, event,
254  'id', 'tt_quick_interface_menu_{$record['id']}',
255  'type', 'velcro',
256  'delay', 0,
257  'styleClass', 'wwTT_int_menu',
258  'lifetime', 1000,
259  'direction', 'west',
260  'javascript', 'xajax_window_submit(\'tooltips\', \'tooltip=>quick_interface_menu,id=>tt_quick_interface_menu_{$record['id']},interface_id=>{$record['id']},ip_addr=>{$record['ip_addr']},orig_host=>{$record['host_id']},form_id=>{$form['form_id']}_list_interface_{$record['id']},subnet_id=>{$subnet['id']},natip=>{$record['nat_interface_id']}\');'
261  );"
262  ><img src="{$images}/silk/add.png" border="0"></a>&nbsp;
263 EOL;
264  }
265 
266  if (auth('interface_modify')) {
267  $html .= <<<EOL
268 
269  <a title="Edit interface. ID: {$record['id']}"
270  class="act"
271  onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'editor');"
272  ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
273 EOL;
274  }
275 
276  if (auth('interface_del')) {
277  $html .= <<<EOL
278 
279  <a title="Delete interface"
280  class="act"
281  onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'delete');"
282  ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
283 EOL;
284  }
285  $html .= <<<EOL
286  </td>
287 
288  </tr>
289 EOL;
290  }
291 
292 
293 
294  if ($count == 0 and $form['host_id'] and !$form['filter']) {
295  $html .= <<<EOL
296  <tr><td colspan="99" align="center" style="color: red;">Please add an interface to this host, or delete the host</td></tr>
297 EOL;
298  }
299 
300  $html .= <<<EOL
301  </table>
302 EOL;
303  // Build page links if there are any
304  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
305 
306  // Insert the new html into the content div specified
307  // Instantiate the xajaxResponse object
308  $response = new xajaxResponse();
309  $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
310  $response->addAssign($form['content_id'], "innerHTML", $html);
311  if ($js) { $response->addScript($js); }
312  return($response->getXML());
313 }
314 
315 
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 ?>
Name
Full Name
Definition: app_user_info.inc.php:101
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ona_get_interface_record
ona_get_interface_record($array='', $order='')
Definition: functions_db.inc.php:1126
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
ws_display_list
ws_display_list($window_name, $form='')
Definition: list_interfaces.inc.php:12
mac_mangle
mac_mangle($input="", $format="default")
Definition: functions_general.inc.php:964
$tab
$tab
Definition: app_config_type_list.inc.php:29
truncate
truncate($msg="", $length=0)
Definition: functions_general.inc.php:209
$images
$images
Definition: config.inc.php:26
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
get_page_links
get_page_links($page=1, $per_page=1, $total=1, $window_name='', $form_id='')
Definition: xajax_setup.inc.php:115
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
ona_get_subnet_record
ona_get_subnet_record($array)
Definition: functions_db.inc.php:1226
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88