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)  

edit_dhcp_pool.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_editor()
7 //
8 // Description:
9 // Displays a form for creating/editing an dhcp pool record.
10 // If $form is a valid pool ID, it is used to display an existing
11 // record for editing. "Save" button calls the ws_save() function.
13 function ws_editor($window_name, $form='') {
14  global $conf, $self, $onadb;
16  $window = array();
17 
18  // Check permissions
19  if (!auth('advanced')) {
20  $response = new xajaxResponse();
21  $response->addScript("alert('Permission denied!');");
22  return($response->getXML());
23  }
24 
25  // If an array in a string was provided, build the array and store it in $form
26  $form = parse_options_string($form);
27 
28  if ($form['subnet_id']) $form['subnet'] = $form['subnet_id'];
29 
30  // if it is a new pool, setup some things
31  if (!$form['id']) {
32  list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet']));
33  // set start and end IP to subnet IP
34  $pool['start_ip'] = $pool['end_ip'] = ip_mangle($subnet['ip_addr'], 'dotted');
35  // setup defaults for form values-- FIXME use $conf['dhcp_pool'] stuff later
36  $pool['lease_length'] = '604800';
37  $pool['lease_grace_period'] = '0';
38  $pool['lease_rebind_time'] = '0';
39  $pool['lease_renewal_time'] = '0';
40 
41  $pool['server_name_text'] = 'None';
42  $window['title'] = "Add DHCP Pool";
43  } else {
44  list($status, $rows, $pool) = ona_get_dhcp_pool_record(array('id' => $form['id']));
45  $pool['start_ip'] = ip_mangle($pool['ip_addr_start']);
46  $pool['end_ip'] = ip_mangle($pool['ip_addr_end']);
47  $pool['server_name_text'] = 'None';
48 
49  // Load the subnet record and associated info.
50  if (is_numeric($form['subnet'])) {
51  list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet']));
52  }
53 
54 
55  // Load the server record and associated info.
56  if ($pool['dhcp_failover_group_id'] >= 1) {
57  list($status, $rows, $failover) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id']));
58 
59  list($status, $rows, $fail_host1) = ona_find_host($failover['primary_server_id']);
60  list($status, $rows, $fail_host2) = ona_find_host($failover['secondary_server_id']);
61  $pool['server_name_text'] = $fail_host1['fqdn'] . "/" . $fail_host2['fqdn'];
62  }
63 
64  $window['title'] = "Edit DHCP Pool";
65 
66  }
67 
68 
69  // Escape data for display in html
70  foreach(array_keys((array)$subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); }
71  foreach(array_keys((array)$failover) as $key) { $failover[$key] = htmlentities($failover[$key], ENT_QUOTES, $conf['php_charset']); }
72  foreach(array_keys((array)$zone) as $key) { $zone[$key] = htmlentities($zone[$key], ENT_QUOTES, $conf['php_charset']); }
73  foreach(array_keys((array)$host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); }
74  foreach(array_keys((array)$server) as $key) { $server[$key] = htmlentities($server[$key], ENT_QUOTES, $conf['php_charset']); }
75 
76 
77 
78 
79  // Javascript to run after the window is built
80  $window['js'] = <<<EOL
81  /* Put a minimize icon in the title bar */
82  el('{$window_name}_title_r').innerHTML =
83  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
84  el('{$window_name}_title_r').innerHTML;
85 
86  /* Put a help icon in the title bar */
87  el('{$window_name}_title_r').innerHTML =
88  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
89  el('{$window_name}_title_r').innerHTML;
90 
91  el('{$window_name}_form').onsubmit = function() { return false; };
92 
93  /* Setup the Quick Find pool server icon */
94  var _button = el('qf_pool_server_{$window_name}');
95  _button.style.cursor = 'pointer';
96  _button.onclick =
97  function(ev) {
98  if (!ev) ev = event;
99  /* Create the popup div */
100  wwTT(this, ev,
101  'id', 'tt_qf_pool_server_{$window_name}',
102  'type', 'static',
103  'direction', 'south',
104  'delay', 0,
105  'styleClass', 'wwTT_qf',
106  'javascript',
107  "xajax_window_submit('tooltips', '" +
108  "tooltip=>qf_pool_server," +
109  "id=>tt_qf_pool_server_{$window_name}," +
110  "text_id=>pool_server_text_{$window_name}," +
111  "server=>set_pool_server_{$window_name}," +
112  "server_name=>{$pool['server_name_text']}," +
113  "failover_group_id=>{$pool['dhcp_failover_group_id']}," +
114  "failover_group=>set_failover_group_{$window_name}');"
115  );
116  };
117 
118 
119 EOL;
120 
121 
122  // Define the window's inner html
123  $window['html'] = <<<EOL
124 
125  <!-- DHCP pool Edit Form -->
126  <form id="{$window_name}_form" onSubmit="return false;">
127  <input type="hidden" name="id" value="{$pool['id']}">
128  <input type="hidden" name="subnet_id" value="{$form['subnet']}">
129  <input type="hidden" name="js" value="{$form['js']}">
130  <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">
131 
132  <!-- DHCP POOL RECORD -->
133  <tr>
134  <td align="left" nowrap="true"><b><u>DHCP Pool</u></b>&nbsp;</td>
135  <td class="padding" align="left" width="100%">&nbsp;</td>
136  </tr>
137 
138  <tr>
139  <td align="right" nowrap="true">
140  Subnet:
141  </td>
142  <td class="padding" align="left" width="100%">
143  {$subnet['name']}
144  </td>
145  </tr>
146 
147 
148  <tr>
149  <td align="right" nowrap="true">
150  Failover Group
151  </td>
152  <td class="padding" align="left" width="100%" nowrap="true">
153  <input
154  type="hidden"
155  id="set_failover_group_{$window_name}"
156  name="failover_group"
157  value="{$pool['dhcp_failover_group_id']}">
158 
159  <span id="qf_pool_server_{$window_name}" title="DHCP Pool Server Quick Select">
160  <a id="pool_server_text_{$window_name}"
161  class="nav"
162  >{$pool['server_name_text']}</a>
163  <img src="{$images}/silk/find.png" border="0"
164  /></span>
165  </td>
166  </tr>
167 
168 
169  <!-- TODO: add a qf for IP addresses to list avail ips on subnet -->
170 
171 
172 
173  <tr>
174  <td class="input_required" align="right" nowrap="true">
175  IP Start
176  </td>
177  <td class="padding" align="left" width="100%">
178  <input
179  name="start"
180  alt="IP Start"
181  value="{$pool['start_ip']}"
182  class="edit"
183  type="text"
184  size="25" maxlength="255"
185  >
186  </td>
187  </tr>
188 
189  <tr>
190  <td class="input_required" align="right" nowrap="true">
191  IP End
192  </td>
193  <td class="padding" align="left" width="100%">
194  <input
195  name="end"
196  alt="IP End"
197  value="{$pool['end_ip']}"
198  class="edit"
199  type="text"
200  size="25" maxlength="255"
201  >
202  </td>
203  </tr>
204 
205  <tr>
206  <td align="right" nowrap="true">
207  Lease Length
208  </td>
209  <td class="padding" align="left" width="100%">
210  <input
211  name="llength"
212  alt="Lease Length"
213  value="{$pool['lease_length']}"
214  class="edit"
215  type="text"
216  size="10" maxlength="10"
217  >
218  </td>
219  </tr>
220 
221  <tr>
222  <td align="right" nowrap="true">
223  Lease Grace
224  </td>
225  <td class="padding" align="left" width="100%">
226  <input
227  name="lgrace"
228  alt="Lease Grace"
229  value="{$pool['lease_grace_period']}"
230  class="edit"
231  type="text"
232  size="10" maxlength="10"
233  >
234  </td>
235  </tr>
236 
237  <tr>
238  <td align="right" nowrap="true">
239  Lease Renewal
240  </td>
241  <td class="padding" align="left" width="100%">
242  <input
243  name="lrenewal"
244  alt="Lease Renewal"
245  value="{$pool['lease_renewal_time']}"
246  class="edit"
247  type="text"
248  size="10" maxlength="10"
249  >
250  </td>
251  </tr>
252 
253 
254  <tr>
255  <td align="right" nowrap="true">
256  Lease Rebind
257  </td>
258  <td class="padding" align="left" width="100%">
259  <input
260  name="lrebind"
261  alt="Lease Rebind"
262  value="{$pool['lease_rebind_time']}"
263  class="edit"
264  type="text"
265  size="10" maxlength="10"
266  >
267  </td>
268  </tr>
269 
270 
271 
272 
273  <tr>
274  <td align="right" valign="top" nowrap="true">
275  &nbsp;
276  </td>
277  <td class="padding" align="right" width="100%">
278  <input type="hidden" name="overwrite" value="{$overwrite}">
279  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
280  <input class="edit" type="button"
281  name="submit"
282  value="Save"
283  accesskey=" "
284  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_form'), 'save');"
285  >
286  </td>
287  </tr>
288 
289  </table>
290  </form>
291 EOL;
292 
293 
294  return(window_open($window_name, $window));
295 }
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312 
313 
315 // Function:
316 // Save Form
317 //
318 // Description:
319 // Creates/updates a dhcp pool record.
321 function ws_save($window_name, $form='') {
322  global $base, $include, $conf, $self, $onadb;
323 
324  // Check permissions
325  if (!auth('advanced')) {
326  $response = new xajaxResponse();
327  $response->addScript("alert('Permission denied!');");
328  return($response->getXML());
329  }
330 
331  // Instantiate the xajaxResponse object
332  $response = new xajaxResponse();
333  $js = '';
334 
335  // Validate input
336  if (!$form['start'] and !$form['end']) {
337  $response->addScript("alert('Please complete all fields to continue!');");
338  return($response->getXML());
339  }
340 
341  list($status, $rows, $subnet) = ona_find_subnet($form['subnet_id']);
342  $start_dec = ip_mangle($form['start'], 'numeric');
343  $end_dec = ip_mangle($form['end'], 'numeric');
344  $net_end = ((4294967295 - $subnet['ip_mask']) + $subnet['ip_addr']);
345 
346  // check the ips are part of the subnet you are on
347  if (($start_dec < $subnet['ip_addr'] or $start_dec > $net_end) or ($end_dec < $subnet['ip_addr'] or $end_dec > $net_end)) {
348  $response->addScript("alert('Save failed: ERROR => The pool range you specified is not part of the subnet: {$subnet['name']}!');");
349  return($response->getXML());
350  }
351 
352 
353  // Decide if we're editing or adding
354  $module = 'dhcp_pool_add';
355  if ($form['id']) {
356  $module = 'dhcp_pool_modify';
357  $form['pool'] = $form['id'];
358  $form['set_start'] = $form['start'];
359  $form['set_end'] = $form['end'];
360  $form['set_llength'] = $form['llength'];
361  $form['set_lgrace'] = $form['lgrace'];
362  $form['set_lrenewal'] = $form['lrenewal'];
363  $form['set_lrebind'] = $form['lrebind'];
364  $form['set_failover_group'] = $form['failover_group'];
365  }
366 
367  // Run the module
368  list($status, $output) = run_module($module, $form);
369 
370  // If the module returned an error code display a popup warning
371  if ($status) {
372  $js .= "alert('Save failed: ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
373  }
374  else {
375  $js .= "removeElement('{$window_name}');";
376  // If there's JS, add it to $js so we'll send it to the browser later.
377  if ($form['js']) { $js .= $form['js']; }
378  }
379 
380  // Insert the new table into the window
381  $response->addScript($js);
382  return($response->getXML());
383 
384 }
385 
386 
387 
388 
389 
390 
391 
392 
394 // Function:
395 // Delete Form
396 //
397 // Description:
398 // Deletes an alias record.
400 function ws_delete($window_name, $form='') {
401  global $base, $include, $conf, $self, $onadb;
402 
403  // Check permissions
404  if (!auth('advanced')) {
405  $response = new xajaxResponse();
406  $response->addScript("alert('Permission denied!');");
407  return($response->getXML());
408  }
409 
410  // If an array in a string was provided, build the array and store it in $form
411  $form = parse_options_string($form);
412 
413  // Instantiate the xajaxResponse object
414  $response = new xajaxResponse();
415  $js = '';
416 
417  // Run the module
418  list($status, $output) = run_module('dhcp_pool_del', array('id' => $form['id'], 'commit' => 'Y'));
419 
420  // If the module returned an error code display a popup warning
421  if ($status) { $js .= "alert('Delete failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');"; }
422  else {
423  // If there's JS, add it to $js so we'll send it to the browser later.
424  if ($form['js']) { $js .= $form['js']; }
425  }
426 
427  // Return an XML response
428  $response->addScript($js);
429  return($response->getXML());
430 
431 }
432 
433 
434 
435 ?>
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ona_find_subnet
ona_find_subnet($search="")
Definition: functions_db.inc.php:2003
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
ws_delete
ws_delete($window_name, $form='')
Definition: edit_dhcp_pool.inc.php:400
ws_save
ws_save($window_name, $form='')
Definition: edit_dhcp_pool.inc.php:321
$window
$window['title']
Definition: install.php:26
_button
_button
Definition: app_advanced_search.inc.php:48
$include
$include
Definition: 2-to-3.php:10
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
$host
$host
Definition: collate-convert.php:19
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
ona_get_dhcp_pool_record
ona_get_dhcp_pool_record($array)
Definition: functions_db.inc.php:1276
$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
$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
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
ws_editor
ws_editor($window_name, $form='')
Definition: edit_dhcp_pool.inc.php:13
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
ona_get_dhcp_failover_group_record
ona_get_dhcp_failover_group_record($array)
Definition: functions_db.inc.php:1175
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$base
$base
Definition: 2-to-3.php:8
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