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_dhcp_server.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 subnets assigned to DHCP server 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  $debug_val = 3; // used in the auth() calls to supress logging
18 
19  // If the user supplied an array in a string, build the array and store it in $form
20  $form = parse_options_string($form);
21 
22  // Find the "tab" we're on
23  $tab = $_SESSION['ona'][$form['form_id']]['tab'];
24 
25  // Build js to refresh this list
26  $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
27 
28  // If it's not a new query, load the previous query from the session
29  // into $form and save the current page and filter in the session.
30  // Also find/set the "page" we're viewing
31  $page = 1;
32  if ($form['page'] and is_numeric($form['page'])) {
33  $form = array_merge($form, (array)$_SESSION['ona'][$form['form_id']][$tab]['q']);
34  $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
35  $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
36  }
37 
38  // Calculate the SQL query offset (based on the page being displayed)
39  $offset = ($conf['search_results_per_page'] * ($page - 1));
40  if ($offset == 0) { $offset = -1; }
41 
42  // Search results go in here
43  $results = array();
44  $count = 0;
45 
46 
47 
48 
49  //
50  // FIND RESULT SET
51  //
52 
53  // Start building the "where" clause for the sql query to find the subnets to display
54  $where = "";
55  $and = "";
56 
57 
58  // SERVER ID
59  if ($form['server_id']) {
60  $where .= $and . 'id IN (SELECT subnet_id
61  FROM dhcp_server_subnets
62  WHERE host_id = '. $onadb->qstr($form['server_id']).'
63  UNION
64  SELECT subnet_id
65  FROM dhcp_pools
66  WHERE dhcp_failover_group_id IN (SELECT id
67  FROM dhcp_failover_groups
68  WHERE primary_server_id = '. $onadb->qstr($form['server_id']) .'
69  OR secondary_server_id = '. $onadb->qstr($form['server_id']) .'))';
70 
71 
72  $and = " AND ";
73  }
74 
75 
76 
77 
78 
79  // Do the SQL Query
80  $filter = '';
81  if ($form['filter']) {
82  // Subnet descriptions are always upper case
83  $form['filter'] = strtoupper($form['filter']);
84  $filter = $and . ' name LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
85  }
86  list ($status, $rows, $results) =
88  $onadb,
89  'subnets',
90  $where . $filter,
91  'ip_addr',
92  $conf['search_results_per_page'],
93  $offset
94  );
95 
96  // If we got less than serach_results_per_page, add the current offset to it
97  // so that if we're on the last page $rows still has the right number in it.
98  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
99  $rows += ($conf['search_results_per_page'] * ($page - 1));
100  }
101 
102  // If there were more than $conf['search_results_per_page'] find out how many records there really are
103  else if ($rows >= $conf['search_results_per_page']) {
104  list ($status, $rows, $records) =
106  $onadb,
107  'subnets',
108  $where . $filter,
109  "",
110  0
111  );
112  }
113  $count = $rows;
114 
115 
116  //
117  // *** BUILD HTML LIST ***
118  //
119  $html .= <<<EOL
120  <!-- Subnet Results -->
121  <table id="{$form['form_id']}_dhcp_server_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
122 
123  <!-- Table Header -->
124  <tr>
125  <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
126  <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
127  <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
128  <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
129  <td class="list-header" align="center">&nbsp;</td>
130  </tr>
131 EOL;
132 
133  // Loop and display each record
134  foreach($results as $record) {
135  // Get additional info about eash subnet record //
136 
137  // Convert IP and Netmask to a presentable format
138  $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
139  $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
140  $record['ip_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr');
141 
142  list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id']));
143  $record['type'] = $type['display_name'];
144 
145  // Calculate the percentage of the subnet that's used (total size - allocated hosts - dhcp pool size)
147 
148  // Escape data for display in html
149  foreach(array_keys($record) as $key) {
150  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
151  }
152 
153  $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_subnet\', \'subnet_id=>{$record['id']}\', \'display\')');";
154  $html .= <<<EOL
155  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
156 
157  <td class="list-row">
158  <a title="View subnet. ID: {$record['id']}"
159  class="nav"
160  onClick="{$primary_object_js}"
161  >{$record['name']}</a>
162  </td>
163 
164  <td class="list-row" align="left">
165  {$record['ip_addr']} <span title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span>&nbsp;
166  </td>
167 
168  <td class="list-row" align="center" style="vertical-align: middle;">
169  {$usage_html}
170  </td>
171 
172  <td class="list-row" align="right">
173  {$record['type']}&nbsp;
174  </td>
175 
176  <td class="list-row" align="right">
177  <form id="{$form['form_id']}_list_dhcp_server_{$record['id']}"
178  ><input type="hidden" name="subnet_id" value="{$record['id']}"
179  ><input type="hidden" name="server_id" value="{$form['server_id']}"
180  ><input type="hidden" name="js" value="{$refresh}"
181  ></form>
182 
183  <a title="Display subnet map"
184  class="act"
185  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_block_map\', \'ip_block_start=>{$record['ip_addr']}\', \'display\');');"
186  ><img src="{$images}/silk/shape_align_left.png" border="0"></a>&nbsp;
187 EOL;
188  if (auth('subnet_modify',$debug_val)) {
189  $html .= <<<EOL
190 
191  <a title="Edit subnet"
192  class="act"
193  onClick="xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_dhcp_server_{$record['id']}'), 'editor');"
194  ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
195 EOL;
196  }
197  // check if the subnet listed is from a failover group or an actual dhcp server subnet assignment
198  list($dhcpsubnetstatus, $dhcpsubnetrows, $dhcpserver) = ona_get_dhcp_server_subnet_record(array('subnet_id' => $record['id'],'host_id' => $form['server_id']));
199  if (auth('subnet_del',$debug_val) && $dhcpsubnetrows == 1) {
200  $html .= <<<EOL
201 
202  <a title="Remove subnet association with server."
203  class="act"
204  onClick="var doit=confirm('Are you sure you want to remove this subnet from this DHCP server?');
205  if (doit == true)
206  xajax_window_submit('edit_dhcp_server', xajax.getFormValues('{$form['form_id']}_list_dhcp_server_{$record['id']}'), 'delete');"
207  ><img src="{$images}/silk/page_delete.png" border="0"></a>&nbsp;
208 EOL;
209  }
210  else {
211  $html .= <<<EOL
212  <span title="You must change the failover group assignment on the pool to remove this entry."><img src="{$images}/silk/comment.png" border="0"></span>&nbsp;
213 EOL;
214  }
215  $html .= <<<EOL
216 
217  </td>
218 
219  </tr>
220 EOL;
221  }
222 
223  $html .= <<<EOL
224  </table>
225 EOL;
226 
227  // Build page links if there are any
228  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
229 
230  // If there was only 1 result, and we're about to display results in the "Search Results" window, display it.
231  if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '')
232  $js .= $primary_object_js;
233 
234  // Insert the new html into the content div specified
235  // Instantiate the xajaxResponse object
236  $response = new xajaxResponse();
237  $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
238  $response->addAssign($form['content_id'], "innerHTML", $html);
239  if ($js) { $response->addScript($js); }
240  return($response->getXML());
241 }
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 ?>
Name
Full Name
Definition: app_user_info.inc.php:101
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$usage_html
$usage_html
Definition: main.inc.php:6
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
$tab
$tab
Definition: app_config_type_list.inc.php:29
ws_display_list
ws_display_list($window_name, $form='')
Definition: list_dhcp_server.inc.php:12
$type
$type
Definition: dcm.php:17
get_subnet_usage_html
get_subnet_usage_html($subnet_id, $width=30, $height=8)
Definition: functions_gui.inc.php:294
$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
ona_get_subnet_type_record
ona_get_subnet_type_record($array)
Definition: functions_db.inc.php:1237
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
ona_get_dhcp_server_subnet_record
ona_get_dhcp_server_subnet_record($array)
Definition: functions_db.inc.php:1280
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$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