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)  

display_dhcp_server.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_display()
7 //
8 // Description:
9 // Displays a DHCP server record and all associated info in the work_space div.
11 function ws_display($window_name, $form='') {
12  global $conf, $self, $onadb;
13  global $images, $color, $style;
14  $html = '';
15  $js = '';
16  $debug_val = 3; // used in the auth() calls to supress logging
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  // Load the server record
22  list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id']));
23  if ($status or !$rows) {
24  array_pop($_SESSION['ona']['work_space']['history']);
25  $html .= "<br><center><font color=\"red\"><b>Server doesn't exist!</b></font></center>";
26  $response = new xajaxResponse();
27  $response->addAssign("work_space_content", "innerHTML", $html);
28  return($response->getXML());
29  }
30 
31  // Pick up host information
32  list($status, $rows, $host) = ona_find_host($form['host_id']);
33  $record['fqdn'] = $host['fqdn'];
34 
35  // Update History Title
36  $history = array_pop($_SESSION['ona']['work_space']['history']);
37  $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');";
38  if ($history['title'] == $window_name) {
39  $history['title'] = "DHCP server - ". $record['name'];
40  array_push($_SESSION['ona']['work_space']['history'], $history);
41  }
42 
43  // Create some javascript to refresh the current page
44  $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
45  $refresh = "xajax_window_submit('work_space', '{$refresh}');";
46 
47 
48  // extra stuff to pass to ws_plugins
49  $extravars['refresh']=$refresh;
50  $extravars['window_name']=$window_name;
51 
52 
53  $style['content_box'] = <<<EOL
54  margin: 10px 20px;
55  padding: 2px 4px;
56  background-color: #FFFFFF;
57  vertical-align: top;
58 EOL;
59 
60  $style['label_box'] = <<<EOL
61  font-weight: bold;
62  padding: 2px 4px;
63  border: solid 1px {$color['border']};
64  background-color: {$color['window_content_bg']};
65 EOL;
66 
67  // Escape data for display in html
68  foreach(array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); }
69 
70  $html .= <<<EOL
71  <!-- FORMATTING TABLE -->
72  <div style="{$style['content_box']}">
73  <table cellspacing="0" border="0" cellpadding="0"><tr>
74 
75  <!-- START OF FIRST COLUMN OF SMALL BOXES -->
76  <td nowrap="true" valign="top" style="padding-right: 15px;">
77 EOL;
78 
79 
80  // SERVER INFORMATION
81  $html .= <<<EOL
82  <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">
83  <!-- LABEL -->
84  <tr><td colspan="99" nowrap="true" style="{$style['label_box']}">
85  DHCP server <a title="View host"
86  class="nav"
87  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$record['id']}\', \'display\')');"
88  >{$record['name']}</a>.<a title="View domain. ID: {$record['domain_id']}"
89  class="domain"
90  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_domain\', \'domain_id=>{$record['domain_id']}\', \'display\')');"
91  >{$record['domain_fqdn']}</a>
92  </td></tr>
93  </table>
94 EOL;
95  // END SERVER INFORMATION
96 
97 
98  $html .= <<<EOL
99  <!-- END OF FIRST COLUMN OF SMALL BOXES -->
100  </td>
101 
102  <!-- START OF SECOND COLUMN OF SMALL BOXES -->
103  <td valign="top" style="padding-right: 15px;">
104 
105 EOL;
106 
107 
108 
109  // FAILOVER GROUP INFO BOX
110  // get failover group information
111  list($status, $rows, $failover_groups) = db_get_records($onadb, 'dhcp_failover_groups', "primary_server_id = {$record['id']} or secondary_server_id = {$record['id']}");
112 
113  if ($rows) {
114  $html .= <<<EOL
115  <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">
116 
117  <!-- LABEL -->
118  <tr><td colspan="2" nowrap="true" style="{$style['label_box']}">Failover groups</td></tr>
119 EOL;
120 
121  foreach ($failover_groups as $failover) {
122  // Get DNS name for primary and secondary servers
123  list($status, $rows, $fail_pri_host) = ona_get_host_record(array('id' => $failover['primary_server_id']));
124  list($status, $rows, $fail_sec_host) = ona_get_host_record(array('id' => $failover['secondary_server_id']));
125 
126 
127  $html .= <<<EOL
128  <tr onMouseOver="this.className='row-highlight';"
129  onMouseOut="this.className='row-normal';">
130  <td align="left">GROUP_ID-{$failover['id']}&#058;&nbsp;{$fail_pri_host['name']}<img src="{$images}/silk/link.png" border="0">{$fail_sec_host['name']}&nbsp;</td>
131  <td align="right">
132  <a title="Edit failover group. ID: {$failover['id']}"
133  class="act"
134  onClick="xajax_window_submit('edit_dhcp_failover_group', '{$failover['id']}', 'editor');"
135  ><img src="{$images}/silk/page_edit.png" border="0"></a>
136  </td>
137  </tr>
138  </table>
139 EOL;
140  }
141  }
142  // END FAILOVER GROUP INFO BOX
143 
144  $html .= <<<EOL
145  <!-- END OF SECOND COLUMN OF SMALL BOXES -->
146  </td>
147 
148  <!-- START OF THRID COLUMN OF SMALL BOXES -->
149  <td valign="top" style="padding-right: 15px;">
150 
151 EOL;
152  // Start displaying all the ws plugins
153  $wspl = workspace_plugin_loader('dhcp_entries',$record,$extravars);
154  $html .= $wspl[0]; $js .= $wspl[1]; //DONT add the, not needed $wsmenu{}=$wspl[2];
155 
156 
157  // This will display the server level, not global level
158  $extravars['dhcpserver_id'] = $host['id'];
159  $wspl = workspace_plugin_loader('dhcp_entries',$record,$extravars);
160  $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[]=$wspl[2];
161 
162  $wsmenuhtml = build_workspace_menu($wsmenu);
163 
164  $html .= <<<EOL
165  </td>
166  <!-- END OF THIRD COLUMN OF SMALL BOXES -->
167  </tr></table>
168  </div>
169  <form id="form_server_{$record['id']}"
170  ><input type="hidden" name="server_id" value="{$host['id']}"
171  ><input type="hidden" name="js" value="{$refresh}"
172  ></form>
173  <form id="form_global_{$record['id']}"
174  ><input type="hidden" name="global_id" value="0"
175  ><input type="hidden" name="js" value="{$refresh}"
176  ></form>
177  <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div>
178  <!-- END OF TOP SECTION -->
179 EOL;
180 
181 
182 
183 
184  // SUBNET LIST
185  $tab = 'dhcp_server';
186  $submit_window = "list_{$tab}";
187  $form_id = "{$submit_window}_filter_form";
188  $_SESSION['ona'][$form_id]['tab'] = $tab;
189  $content_id = "{$window_name}_{$submit_window}";
190  $html .= <<<EOL
191  <!-- SUBNET LIST -->
192  <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">
193 
194  <!-- Tab & Quick Filter -->
195  <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
196  <tr>
197  <td id="{$form_id}_subnets_tab" class="table-tab-active">
198  Assigned Subnets <span id="{$form_id}_{$tab}_count"></span>
199  </td>
200 
201  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
202  <form id="{$form_id}" onSubmit="return false;">
203  <input id="{$form_id}_page" name="page" value="1" type="hidden">
204  <input name="content_id" value="{$content_id}" type="hidden">
205  <input name="form_id" value="{$form_id}" type="hidden">
206  <input name="server_id" value="{$record['id']}" type="hidden">
207  <div id="{$form_id}_filter_overlay"
208  style="position: relative;
209  display: inline;
210  color: #CACACA;
211  cursor: text;"
212  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
213  >Filter</div>
214  <input
215  id="{$form_id}_filter"
216  name="filter"
217  class="filter"
218  type="text"
219  value=""
220  size="10"
221  maxlength="20"
222  alt="Quick Filter"
223  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
224  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
225  onKeyUp="
226  if (typeof(timer) != 'undefined') clearTimeout(timer);
227  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
228  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
229  ' document.getElementById(\'{$form_id}_page\').value = 1;' +
230  ' xajax_window_submit(\'{$submit_window}\', xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
231  '}';
232  timer = setTimeout(code, 700);"
233  >
234  </form>
235  </td>
236 
237  </tr>
238  </table>
239 
240  <div id='{$content_id}'>
241  {$conf['loading_icon']}
242  </div>
243 
244 EOL;
245  if (auth('advanced',$debug_val)) {
246  $html .= <<<EOL
247  <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}">
248  <form id="form_dhcp_server_{$record['id']}"
249  ><input type="hidden" name="server" value="{$record['id']}"
250  ><input type="hidden" name="js" value="{$refresh}"
251  ></form>
252  <!-- ADD SUBNET LINK -->
253  <a title="Assign subnet to DHCP server"
254  class="act"
255  onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');"
256  ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
257 
258  <a title="Assign subnet to DHCP server"
259  class="act"
260  onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');"
261  >Assign subnet</a>&nbsp;
262  </div>
263 EOL;
264  }
265 
266  $html .= <<<EOL
267  </div>
268 EOL;
269 
270  // If we have a build type set, then display the output div
271  if ($conf['build_dhcp_type'] && auth('advanced',$debug_val)) {
272  $html .= <<<EOL
273  <div id="confoutputdiv" style="border: 1px solid rgb(26, 26, 26); margin: 10px 20px;padding-left: 8px;overflow:hidden;width: 100px;"><pre style='font-family: monospace;overflow-y:auto;' id="confoutput"><center>Generating configuration...</center><br>{$conf['loading_icon']}</pre></div>
274 EOL;
275 
276  $js .= "xajax_window_submit('{$window_name}', 'fqdn=>{$record['fqdn']}', 'display_config');";
277  }
278 
279  $js .= <<<EOL
280  /* Setup the quick filter */
281  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
282  {$form_id}_last_search = '';
283 
284  /* Tell the browser to load/display the list */
285  xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
286 
287  setTimeout('el(\'confoutputdiv\').style.width = el(\'{$form_id}_table\').offsetWidth-8+\'px\';',900);
288 EOL;
289 
290 
291 
292  // Insert the new html into the window
293  // Instantiate the xajaxResponse object
294  $response = new xajaxResponse();
295  $response->addAssign("work_space_content", "innerHTML", $html);
296  if ($js) { $response->addScript($js); }
297  return($response->getXML());
298 
299 
300 
301 }
302 
303 
304 
305 
306 
307 
308 
309 
311 // Function: ws_display_config()
312 //
313 // Description:
314 // generates the configuration from the database.
316 function ws_display_config($window_name, $form='') {
317  global $conf;
318  $html = '';
319  $js = '';
320 
321  // If the user supplied an array in a string, transform it into an array
322  $form = parse_options_string($form);
323 
324  // MP: This could be slow depending on the size of the database. maybe make it a button.. having no build_dhcp_type turns it off
325  // It expects to be passed the server name as server= to the module
326  if ($conf['build_dhcp_type'] && auth('advanced',$debug_val)) {
327  switch (strtolower($conf['build_dhcp_type'])) {
328  case "isc":
329  $dhcp_module_name = 'build_dhcpd_conf';
330  break;
331  case "dhcpd":
332  $dhcp_module_name = 'build_dhcpd_conf';
333  break;
334  }
335 
336  list($status, $output) = run_module("{$dhcp_module_name}", array('server' => $form['fqdn']));
337  // Display the config if it ran ok
338  if (!$status) {
339  $html .= $output;
340  } else {
341  $html .= "There was a problem generating the configuration.<br>{$output}";
342  }
343  }
344 
345  // Insert the new html into the window
346  // Instantiate the xajaxResponse object
347  $response = new xajaxResponse();
348  $response->addAssign("confoutput", "innerHTML", $html);
349  if ($js) { $response->addScript($js); }
350  return($response->getXML());
351 }
352 
353 
354 
355 
356 
357 
358 
359 
360 
361 
362 ?>
ona_get_host_record
ona_get_host_record($array='', $order='')
Definition: functions_db.inc.php:1106
workspace_plugin_loader
workspace_plugin_loader($modulename, $record=array(), $extravars=array())
Definition: functions_gui.inc.php:140
ws_display_config
ws_display_config($window_name, $form='')
Definition: display_dhcp_server.inc.php:316
ws_display
ws_display($window_name, $form='')
Definition: display_dhcp_server.inc.php:11
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
build_workspace_menu
build_workspace_menu($menuarray=array())
Definition: functions_gui.inc.php:16
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
xajax
$tab
$tab
Definition: app_config_type_list.inc.php:29
$host
$host
Definition: collate-convert.php:19
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
$form_id
$form_id
Definition: app_config_type_list.inc.php:28
$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
$submit_window
$submit_window
Definition: app_config_type_list.inc.php:30
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$content_id
$content_id
Definition: app_config_type_list.inc.php:31
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
$wspl
$wspl
Definition: main.inc.php:113
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