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_record.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_editor($window_name, $form)
7 //
8 // Description:
9 // Displays a form for creating/editing a DNS record.
10 //
11 // Input:
12 // $window_name the name of the "window" to use.
13 // $form A string-based-array or an array or a dns record ID.
14 // The string-based-array would usually look something like this:
15 // dns_record_id=>123,js=>some('javascript');
16 // If $form is a valid record ID, it is used to display and edit
17 // that record. Otherwise the form will let you add a new record.
18 // The "Save" button calls the ws_save() function in this file.
19 // Notes:
20 // If there is a "js" field passed in that contains javascript it will be
21 // sent to the browser after the ws_save() function is called.
23 function ws_editor($window_name, $form='') {
24  global $conf, $self, $onadb;
26  $window = array();
27  $window['js'] = '';
28  $typedisable = '';
29 
30  // Check permissions
31  if (! (auth('dns_record_modify') and auth('dns_record_add')) ) {
32  $response = new xajaxResponse();
33  $response->addScript("alert('Permission denied!');");
34  return($response->getXML());
35  }
36 
37  // If an array in a string was provided, build the array and store it in $form
38  $form = parse_options_string($form);
39 
40  // Load an existing DNS record (and associated info) if $form is a dns_record_id
41  $host = array('fqdn' => '.');
42  $interface = array();
43  if (is_numeric($form['dns_record_id'])) {
44  list($status, $rows, $dns_record) = ona_get_dns_record(array('id' => $form['dns_record_id']));
45  if ($rows) {
46  // Load associated INTERFACE record(s)
47  list($status, $interfaces, $interface) = ona_get_interface_record(array('id' => $dns_record['interface_id']));
48  $interface['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted');
49  list($status, $rows, $domain) = ona_get_domain_record(array('id' => $dns_record['domain_id']));
50  $dns_record['domain_fqdn'] = $domain['fqdn'];
51  }
52  }
53 
54  // Load a domain record if we got passed a domain_id
55  if ($form['domain_id']) {
56  list($status, $rows, $domain) = ona_get_domain_record(array('id' => $form['domain_id']));
57  $dns_record['domain_fqdn'] = $domain['fqdn'];
58  }
59 
60  // Load a interface record if we got passed a interface_id
61  if ($form['interface_id']) {
62  list($status, $rows, $int) = ona_get_interface_record(array('id' => $form['interface_id']));
63  $interface['ip_addr'] = $int['ip_addr_text'];
64  $window['js'] .= "el('set_ip_{$window_name}').value = '{$int['ip_addr_text']}'";
65  $form['js'] = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host=>{$int['host_id']}\', \'display\')');";
66  }
67 
68 
69  // Escape data for display in html
70  foreach(array_keys((array)$dns_record) as $key) { $dns_record[$key] = htmlentities($dns_record[$key], ENT_QUOTES, $conf['php_charset']); }
71  foreach(array_keys((array)$interface) as $key) { $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']); }
72 
73  // set the type to AAAA if it is an ipv6 address
74  if ($dns_record['type'] == 'A' and strstr($interface['ip_addr'],':')) { $dns_record['type'] = 'AAAA'; }
75 
76  // If its a CNAME, get the dns name for the A record it points to
77  if ($dns_record['type'] == 'CNAME' or $dns_record['type'] == 'MX' or $dns_record['type'] == 'PTR' or $dns_record['type'] == 'NS' or $dns_record['type'] == 'SRV') {
78  list($status, $rows, $existinga_data) = ona_get_dns_record(array('id' => $dns_record['dns_id']));
79  $dns_record['existinga_data'] = $existinga_data['fqdn'];
80  }
81 
82  // If its a PTR we need to build the hostname part
83  if ($dns_record['type'] == 'PTR') {
84 
85  // Flip the IP address
86  $dns_record['name'] = ip_mangle($interface['ip_addr'],'flip');
87 
88  // strip down the IP to just the "host" part as it relates to the domain its in
89  $domain_part = preg_replace("/.in-addr.arpa$/", '', $dns_record['domain_fqdn']);
90  $dns_record['name'] = preg_replace("/.$domain_part$/", '', $dns_record['name']);
91 
92  // Disable the edit boxes related to the A record info
93  $window['js'] .= "el('set_hostname_{$window_name}').disabled='1';el('set_domain_{$window_name}').disabled='1';el('set_a_record_{$window_name}').disabled='1';el('set_ip_{$window_name}').disabled='1';";
94  }
95 
96 
97  // If its an A record,check to se if it has a PTR associated with it
98  //FIXME: MP dont forget that if you change the ip of an A record that you must also update any PTR records reference to that interface
99  $ptr_readonly = '';
100  if ($dns_record['type'] == 'A' or $dns_record['type'] == 'AAAA') {
101  list($status, $rows, $hasptr) = ona_get_dns_record(array('interface_id' => $dns_record['interface_id'],'type' => 'PTR'));
102  if ($rows) {
103  $hasptr_msg = '<- Already has PTR record';
104  $ptr_readonly = 'disabled="1"';
105  }
106  }
107 
108  $ttl_style = '';
109  $editdisplay = '';
110  $record_types = array();
111 
112  // Set the window title:
113  if ($dns_record['id']) {
114  $typedisable = 'disabled="1"';
115  if ($dns_record['dns_id']) $viewdisable = 'disabled="1"';
116  $auto_ptr_checked = '';
117  $window['title'] = "Edit DNS Record";
118  $window['js'] .= "el('record_type_select').onchange('fake event');updatednsinfo('{$window_name}');el('set_hostname_{$window_name}').focus();";
119  // If you are editing and there is no ttl set, use the one from the domain.
120  if (!$dns_record['ttl']) {
121  $ttl_style = 'style="font-style: italic;" title="Using TTL from domain"';
122  }
123  // add PTR type as an editable option to the record_types array
124  array_push($record_types, "PTR");
125  // if we are passing in default values for a record, set them here from form data.
126  if (strlen($form['ip_addr']) > 1) $interface['ip_addr'] = ip_mangle($form['ip_addr'], 'dotted');
127  if (strlen($form['hostname']) > 1) $dns_record['name'] = $form['hostname'];
128  } else {
129  $auto_ptr_checked = 'checked="1"';
130  $window['title'] = "Add DNS Record";
131  $dns_record['srv_pri'] = 0;
132  $dns_record['srv_weight'] = 0;
133  $dns_record['ebegin']=date('Y-m-j G:i:s',time());
134  $window['js'] .= "el('record_type_select').onchange('fake event');updatednsinfo('{$window_name}');el('set_hostname_{$window_name}').focus();";
135  // if we are passing in default values for a new record, set them here from form data.
136  if (strlen($form['ip_addr']) > 1) $interface['ip_addr'] = ip_mangle($form['ip_addr'], 'dotted');
137  if (strlen($form['hostname']) > 1) $dns_record['name'] = $form['hostname'];
138  }
139 
140  // Set up the types of records we can edit with this form
141  //$record_types = array('A','CNAME','TXT','NS','MX','AAAA','SRV');
142  // FIXME: MP cool idea here-- support the loc record and have a google map popup to search for the location then have it populate the coords from that.
143  // FIXME: MP it would probably be much better to use ajax to pull back the right form content than all this other javascript crap.
144  array_push($record_types,'A','AAAA','CNAME','MX','NS','SRV','TXT','PTR');
145  foreach (array_keys((array)$record_types) as $id) {
146  $record_types[$id] = htmlentities($record_types[$id]);
147  $selected = '';
148  if ($record_types[$id] == $dns_record['type']) { $selected = 'SELECTED'; }
149  $record_type_list .= "<option value=\"{$record_types[$id]}\" {$selected}>{$record_types[$id]}</option>\n";
150  }
151 
152 
153  //Get the list of DNS views
154  if ($conf['dns_views']) {
155  list($status, $rows, $dnsviews) = db_get_records($onadb, 'dns_views','id >= 0', 'name');
156 
157  foreach ($dnsviews as $entry) {
158  $selected = '';
159  $dnsviews['name'] = htmlentities($dnsviews['name']);
160  // If this entry matches the record you are editing, set it to selected
161  if ($dns_record['id'] and $entry['id'] == $dns_record['dns_view_id']) {
162  $selected = "SELECTED=\"selected\"";
163  } elseif (!$dns_record['id'] and $entry['id'] == 0) {
164  // Otherwise use the default record if we are adding a new entry
165  $selected = "SELECTED=\"selected\"";
166  }
167  $dns_view_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['name']}</option>\n";
168  }
169  }
170 
171 
172 
173  // Javascript to run after the window is built
174  $window['js'] .= <<<EOL
175  /* Put a minimize icon in the title bar */
176  el('{$window_name}_title_r').innerHTML =
177  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
178  el('{$window_name}_title_r').innerHTML;
179 
180  /* Put a help icon in the title bar */
181  el('{$window_name}_title_r').innerHTML =
182  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
183  el('{$window_name}_title_r').innerHTML;
184 
185  suggest_setup('set_domain_{$window_name}', 'suggest_set_domain_{$window_name}');
186  suggest_setup('set_a_record_{$window_name}', 'suggest_set_a_record_{$window_name}');
187 
188  el('set_hostname_{$window_name}').focus();
189 EOL;
190 
191  // Define the window's inner html
192  $window['html'] = <<<EOL
193 
194  <!-- DNS Record Edit Form -->
195  <form id="{$window_name}_edit_form" onSubmit="return false;">
196  <input type="hidden" name="dns_id" value="{$dns_record['id']}">
197  <input type="hidden" name="name" value="{$host['fqdn']}">
198  <input type="hidden" name="js" value="{$form['js']}">
199 EOL;
200 
201  // If we are editing and thus disabling the type selector, we need to put a hidden input field
202  if ($typedisable) {
203  $window['html'] .= "<input type=\"hidden\" name=\"set_type\" value=\"{$dns_record['type']}\">";
204  }
205 
206  // If we are editing and thus disabling the view selector, we need to put a hidden input field
207  if ($viewdisable) {
208  $window['html'] .= "<input type=\"hidden\" name=\"set_view\" value=\"{$dns_record['dns_view_id']}\">";
209  }
210 
211 
212  $window['html'] .= <<<EOL
213  <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;" width="100%">
214  <!-- DNS RECORD -->
215  <tr>
216  <td align="right" nowrap="true">
217  <b><u>DNS Record</u></b>&nbsp;
218  </td>
219  <td class="padding" align="left" width="100%">
220  &nbsp;
221  </td>
222  </tr>
223 
224  </table>
225 
226  <!-- RECORD TYPE CONTAINER -->
227  <div id="type_container">
228  <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;" width="100%">
229 EOL;
230 
231  // Print a dns view selector
232  if ($conf['dns_views']) {
233  $window['html'] .= <<<EOL
234  <tr>
235  <td align="right" nowrap="true">
236  DNS View
237  </td>
238  <td class="padding" align="left" width="100%">
239  <select {$viewdisable}
240  id="dns_view_select"
241  name="set_view"
242  alt="DNS View"
243  class="edit"
244  >{$dns_view_list}</select>
245  </td>
246  </tr>
247 
248 EOL;
249  }
250 
251  $window['html'] .= <<<EOL
252  <tr>
253  <td class="input_required" align="right" nowrap="true">
254  DNS Record Type
255  </td>
256  <td class="padding" align="left" width="100%">
257  <select {$typedisable}
258  id="record_type_select"
259  name="set_type"
260  alt="Record type"
261  class="edit"
262  onchange="var selectBox = el('record_type_select');
263  el('info_{$window_name}').innerHTML = '';
264  el('ptr_info_{$window_name}').innerHTML = '';
265  el('a_container').style.display = (selectBox.value == 'AAAA' || selectBox.value == 'A' || selectBox.value == 'PTR') ? '' : 'none';
266  el('autoptr_container').style.display = (selectBox.value == 'AAAA' || selectBox.value == 'A') ? '' : 'none';
267  el('mx_container').style.display = (selectBox.value == 'MX') ? '' : 'none';
268  el('srv_container').style.display = (selectBox.value == 'SRV') ? '' : 'none';
269  el('txt_container').style.display = (selectBox.value == 'TXT') ? '' : 'none';
270  el('name_container').style.display = (selectBox.value == 'NS' || selectBox.value == 'PTR') ? 'none' : '';
271  el('domain_name_container').style.display = (selectBox.value == 'PTR') ? 'none' : '';
272  el('existing_a_container').style.display = (selectBox.value == 'MX' || selectBox.value == 'PTR'|| selectBox.value == 'CNAME' || selectBox.value == 'NS' || selectBox.value == 'SRV') ? '' : 'none';"
273  >{$record_type_list}</select>
274  </td>
275  </tr>
276 
277  </table>
278  </div>
279 
280  <!-- COMMON CONTAINER -->
281  <div id="common_container" style="background-color: #F2F2F2;">
282  <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;">
283  <tr id="name_container">
284  <td class="input_required" align="right" nowrap="true">
285  Host Name
286  </td>
287  <td class="padding" align="left" width="100%">
288  <input
289  id="set_hostname_{$window_name}"
290  name="set_name"
291  alt="Hostname"
292  value="{$dns_record['name']}"
293  class="edit"
294  type="text"
295  size="25" maxlength="64"
296  onblur="updatednsinfo('{$window_name}');"
297  />
298  </td>
299  </tr>
300 
301  <tr id="domain_name_container">
302  <td class="input_required" align="right" nowrap="true">
303  Domain
304  </td>
305  <td class="padding" align="left" width="100%">
306  <input
307  id="set_domain_{$window_name}"
308  name="set_domain"
309  alt="Domain name"
310  value="{$dns_record['domain_fqdn']}"
311  class="edit"
312  type="text"
313  size="25" maxlength="64"
314  onblur="updatednsinfo('{$window_name}');"
315  />
316  <div id="suggest_set_domain_{$window_name}" class="suggest"></div>
317  </td>
318  </tr>
319 EOL;
320 
321  // If there is a ttl in the record then display it instead of the domain setting message
322  $ttlrow_style = '';
323  if ($dns_record['ttl'] == 0) {
324  $ttlrow_style = 'style="display:none;"';
325  $window['html'] .= <<<EOL
326 
327  <tr id="ttlrowdesc">
328  <td align="right" nowrap="true">
329  TTL
330  </td>
331  <td class="padding" align="left" width="100%" nowrap="true">
332  &nbsp;Defaults to domain setting,&nbsp;
333  <a onclick="el('ttlrowdesc').style.display = 'none';el('ttlrow').style.display = '';">override</a>
334  </td>
335  </tr>
336 EOL;
337  }
338 
339 
340  $window['html'] .= <<<EOL
341  <tr id="ttlrow" {$ttlrow_style}>
342  <td align="right" nowrap="true">
343  TTL
344  </td>
345  <td class="padding" align="left" width="100%">
346  <input {$ttl_style}
347  id="set_ttl"
348  name="set_ttl"
349  alt="TTL"
350  value="{$dns_record['ttl']}"
351  class="edit"
352  type="text"
353  size="20" maxlength="20"
354  onblur="updatednsinfo('{$window_name}');"
355  onfocus="updatednsinfo('{$window_name}');"
356  />
357  </td>
358  </tr>
359 
360  <tr id="ebeginrow">
361  <td align="right" nowrap="true">
362  Begin
363  </td>
364  <td class="padding" align="left" width="100%">
365 EOL;
366 
367  if ((strtotime($dns_record['ebegin']) < time()) && (strtotime($dns_record['ebegin']) > 1)) {
368  $window['html'] .= <<<EOL
369  <input id="ebegin_input" style="display:none;"
370  id="set_ebegin"
371  name="set_ebegin"
372  alt="Set a future begin time"
373  value="{$dns_record['ebegin']}"
374  class="edit"
375  type="text"
376  size="16" maxlength="30"
377  />
378  <img
379  id="ebegin_clock"
380  style="margin-top: -6px;"
381  src='{$images}/silk/clock.png'
382  border='0'
383  title="Set a future begin time"
384  onclick="el('ebegin_clock').style.display = 'none';el('ebegin_input').style.display = '';"
385  > -or-
386  <input
387  name="disable"
388  alt="Disable this DNS entry"
389  type="checkbox"
390  > Disable
391 EOL;
392  } else {
393  $ebegin_clockstyle = '';
394  $ebegin_style = 'style="display:none;"';
395  // If record is disabled, then check the box and hide the input box. Also set up a fake ebegin for now() in case they re-enable
396  if (strtotime($dns_record['ebegin']) < 0) {
397  $ebegin_disabled = 'checked="1"';
398  $dns_record['ebegin']=date('Y-m-j G:i:s',time());
399  }
400  if (strtotime($dns_record['ebegin']) > time()) {
401  $ebegin_clockstyle = 'display:none;';
402  $ebegin_style = '';
403  }
404  $window['html'] .= <<<EOL
405  <input id="ebegin_input"
406  {$ebegin_style}
407  id="set_ebegin"
408  name="set_ebegin"
409  alt="TTL"
410  value="{$dns_record['ebegin']}"
411  class="edit"
412  type="text"
413  size="16" maxlength="30"
414  />
415  <img
416  id="ebegin_clock"
417  style="margin-top: -6px;{$ebegin_clockstyle}"
418  src='{$images}/silk/clock.png'
419  border='0'
420  title="Set a future begin time"
421  onclick="el('ebegin_clock').style.display = 'none';el('ebegin_input').style.display = '';"
422  > -or-
423  <input
424  name="disable"
425  alt="Disable this DNS entry"
426  type="checkbox"
427  {$ebegin_disabled}
428  > Disable
429 EOL;
430  }
431 
432  $window['html'] .= <<<EOL
433  </td>
434  </tr>
435 
436  <!-- A RECORD CONTAINER -->
437  <tr id="a_container">
438  <td class="input_required" align="right" nowrap="true">
439  IP Address
440  </td>
441  <td class="padding" align="left" width="100%" nowrap="true">
442  <input
443  id="set_ip_{$window_name}"
444  name="set_ip"
445  alt="IP Address"
446  value="{$interface['ip_addr']}"
447  class="edit"
448  type="text"
449  size="45" maxlength="64"
450  onblur="updatednsinfo('{$window_name}');"
451  />
452  </td>
453  </tr>
454 
455  <tr id="autoptr_container">
456  <td align="right" nowrap="true">
457  Create PTR
458  </td>
459  <td class="padding" align="left" width="100%" nowrap>
460  <input
461  id="set_auto_ptr"
462  name="set_addptr"
463  alt="Automaticaly create PTR record"
464  type="checkbox"
465  {$auto_ptr_checked}
466  {$ptr_readonly}
467  onchange="updatednsinfo('{$window_name}');"
468  />{$hasptr_msg}
469  </td>
470  </tr>
471 
472  <!-- TXT CONTAINER -->
473  <tr id="txt_container" style="display:none;">
474  <td class="input_required" align="right" nowrap="true">
475  TXT value
476  </td>
477  <td class="padding" align="left" width="100%">
478  <input
479  id="set_txt_{$window_name}"
480  name="set_txt"
481  alt="TXT value"
482  value="{$dns_record['txt']}"
483  class="edit"
484  type="text"
485  size="25" maxlength="255"
486  onblur="updatednsinfo('{$window_name}');"
487  />
488  </td>
489  </tr>
490 
491  <!-- MX CONTAINER -->
492  <tr id="mx_container" style="display:none;">
493  <td class="input_required" align="right" nowrap="true">
494  MX Preference
495  </td>
496  <td class="padding" align="left" width="100%">
497  <input
498  id="set_mx_preference_{$window_name}"
499  name="set_mx_preference"
500  alt="MX preference"
501  value="{$dns_record['mx_preference']}"
502  class="edit"
503  type="text"
504  size="5" maxlength="5"
505  onblur="updatednsinfo('{$window_name}');"
506  />
507  </td>
508  </tr>
509 
510  <!-- SRV CONTAINER -->
511  <tr id="srv_container" style="display:none;">
512  <td class="input_required" align="right" nowrap="true">
513  Priority<br>Weight<br>Port
514  </td>
515  <td class="padding" align="left" width="100%">
516  <input
517  style="margin-bottom:3px;"
518  id="set_srv_pri_{$window_name}"
519  name="set_srv_pri"
520  alt="SRV Priority"
521  value="{$dns_record['srv_pri']}"
522  class="edit"
523  type="text"
524  size="5" maxlength="5"
525  onblur="updatednsinfo('{$window_name}');"
526  /><br />
527  <input
528  style="margin-bottom:3px;"
529  id="set_srv_weight_{$window_name}"
530  name="set_srv_weight"
531  alt="SRV Weight"
532  value="{$dns_record['srv_weight']}"
533  class="edit"
534  type="text"
535  size="5" maxlength="5"
536  onblur="updatednsinfo('{$window_name}');"
537  /><br />
538  <input
539  id="set_srv_port_{$window_name}"
540  name="set_srv_port"
541  alt="SRV Port"
542  value="{$dns_record['srv_port']}"
543  class="edit"
544  type="text"
545  size="5" maxlength="5"
546  onblur="updatednsinfo('{$window_name}');"
547  />
548  </td>
549  </tr>
550 
551  <!-- CNAME CONTAINER -->
552  <tr id="existing_a_container" style="display:none;">
553  <td class="input_required" align="right" nowrap="true">
554  Existing A record
555  </td>
556  <td class="padding" align="left" width="100%">
557  <input
558  id="set_a_record_{$window_name}"
559  name="set_pointsto"
560  alt="Points to existing A record"
561  value="{$dns_record['existinga_data']}"
562  class="edit"
563  type="text"
564  size="25" maxlength="64"
565  onblur="updatednsinfo('{$window_name}');"
566  />
567  <div id="suggest_set_a_record_{$window_name}" class="suggest"></div>
568  </td>
569  </tr>
570 
571  <!-- NOTES CONTAINER -->
572  <tr id="notes_container">
573  <td align="right" nowrap="true">
574  Notes
575  </td>
576  <td class="padding" align="left" width="100%">
577  <input
578  id="set_notes_{$window_name}"
579  name="set_notes"
580  alt="Notes"
581  value="{$dns_record['notes']}"
582  class="edit"
583  type="text"
584  size="45" maxlength="64"
585  />
586  </td>
587  </tr>
588 
589  <!-- RECORD INFO -->
590  <tr>
591  <td colspan="2" class="padding" align="center" width="100%" nowrap="true">
592  <span id="info_{$window_name}" style="color: green;font-family: monospace;"></span>
593  </td>
594  </tr>
595  <tr>
596  <td colspan="2" class="padding" align="center" width="100%" nowrap="true">
597  <span id="ptr_info_{$window_name}" style="color: green;font-family: monospace;"></span>
598  </td>
599  </tr>
600 
601  </table>
602  </div>
603 
604 
605 
606 
607  <table cellspacing="0" border="0" cellpadding="0" width="100%" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">
608 
609 EOL;
610 
611 
612  if (!$dns_record['id']) {
613  $window['html'] .= <<<EOL
614  <tr>
615  <td align="right" nowrap="true">
616  &nbsp;
617  </td>
618  <td class="padding" align="left" width="100%" nowrap="true">
619  <input
620  name="keepadding"
621  alt="Keep adding more DNS records"
622  type="checkbox"
623  onfocus="updatednsinfo('{$window_name}');"
624  > Keep adding more DNS records
625  </td>
626  </tr>
627 
628  <tr>
629  <td colspan="2" class="padding" align="center" width="100%">
630  <span id="statusinfo_{$window_name}" style="color: green;" ></span>
631  </td>
632  </tr>
633 
634 EOL;
635  }
636 
637  $window['html'] .= <<<EOL
638 
639  <tr>
640  <td align="right" valign="top" nowrap="true">
641  &nbsp;
642  </td>
643  <td colspan="2" class="padding" align="right" width="100%">
644  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
645  <input class="edit" type="button"
646  name="submit"
647  value="Save"
648  accesskey=" "
649  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_edit_form'), 'save');"
650  >
651  </td>
652  </tr>
653 
654  </table>
655 
656  </form>
657 EOL;
658 
659  return(window_open($window_name, $window));
660 }
661 
662 
663 
664 
665 
666 
667 
668 
670 // Function:
671 // Save Form
672 //
673 // Description:
674 // Creates/updates a dns record.
676 function ws_save($window_name, $form='') {
677  global $include, $conf, $self, $onadb;
678 
679  // Check permissions
680  if (! (auth('dns_record_modify') and auth('dns_record_add')) ) {
681  $response = new xajaxResponse();
682  $response->addScript("alert('Permission denied!');");
683  return($response->getXML());
684  }
685 
686  // Instantiate the xajaxResponse object
687  $response = new xajaxResponse();
688  $js = '';
689 
690 
691 
692  // Validate input
693 // if ($form['set_domain'] == '' or
694 // $form['set_type'] == ''
695 // ) {
696 // $response->addScript("alert('Please complete all fields to continue!');");
697 // return($response->getXML());
698 // }
699 
700  // we need to do a little validation here to make sure things
701  // have a good chance of working!
702 
703  // If the name we were passed has a leading . in it then remove the dot.
704  $form['set_name'] = preg_replace("/^\./", '', trim($form['set_name']));
705  $form['set_ip'] = trim($form['set_ip']);
706 
707  // Validate the "set_name" name is valid
708  if ($form['set_name'] and ($form['set_type'] != 'NS')) {
709  $form['set_name'] = sanitize_hostname($form['set_name']);
710  if (!$form['set_name']) {
711  $response->addScript("alert('Invalid hostname!');");
712  return($response->getXML());
713  }
714  }
715 
716  // Make sure the IP address specified is valid
717  if ($form['set_name'] != '.' and $form['set_ip']) {
718  $form['set_ip'] = ip_mangle($form['set_ip'], 'dotted');
719  if ($form['set_ip'] == -1) {
720  $response->addScript("alert('{$self['error']}');");
721  return($response->getXML());
722  }
723  }
724 
725  $form['set_addptr'] = sanitize_YN($form['set_addptr'], 'N');
726 
727  // Set the effective date to 0 to disable
728  if ($form['disable']) $form['set_ebegin'] = 0;
729 
730  // Decide if we're editing or adding
731  $module = 'modify';
732  // If we're adding, re-map some the array names to match what the "add" module wants
733  if (!$form['dns_id']) {
734  $module = 'add';
735 
736  // options
737  $form['domain'] = $form['set_domain'];
738  $form['name'] = $form['set_name'] . '.' . $form['set_domain']; unset($form['set_name']); unset($form['set_domain']);
739  $form['type'] = $form['set_type']; unset($form['set_type']);
740  $form['ebegin'] = $form['set_ebegin']; unset($form['set_ebegin']);
741  $form['notes'] = $form['set_notes']; unset($form['set_notes']);
742  $form['ip'] = $form['set_ip']; unset($form['set_ip']);
743  $form['ttl'] = $form['set_ttl']; unset($form['set_ttl']);
744  $form['addptr'] = $form['set_addptr']; unset($form['set_addptr']);
745  $form['view'] = $form['set_view']; unset($form['set_view']);
746 
747  // if this is a cname. then set the pointsto option
748  if ($form['type'] == 'CNAME' or $form['type'] == 'MX' or $form['type'] == 'NS' or $form['type'] == 'SRV') $form['pointsto'] = $form['set_pointsto'];
749  if ($form['type'] == 'MX') $form['mx_preference'] = $form['set_mx_preference'];
750  if ($form['type'] == 'TXT') $form['txt'] = $form['set_txt'];
751 
752  if ($form['type'] == 'SRV') $form['srv_pri'] = $form['set_srv_pri'];
753  if ($form['type'] == 'SRV') $form['srv_weight'] = $form['set_srv_weight'];
754  if ($form['type'] == 'SRV') $form['srv_port'] = $form['set_srv_port'];
755 
756  // If it is an NS record, blank the name out
757  //if ($form['type'] == 'NS') $form['name'] = $form['set_domain'];
758 
759  // If we are adding a PTR.. switch existing a record to name
760  if ($form['type'] == 'PTR') $form['name'] = $form['set_pointsto'];
761 
762  // If there's no "refresh" javascript, add a command to view the new dns record
763  if (!preg_match('/\w/', $form['js'])) $form['js'] = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host=>{$form['name']}\', \'display\')');";
764  }
765  else {
766  $form['set_name'] .= '.' . $form['set_domain'];
767  //FIXME: MP temporary kludge to get around not having a proper find_dns_record module.. ID is the only way to find a record now and it is done via the name field
768  $form['name'] = $form['dns_id'];
769 
770  // if this is a cname. then set the pointsto option
771  if ($form['set_type'] != 'CNAME') $form['set_pointsto'] == '';
772  }
773 
774  // Run the module to ADD the DNS record, or MODIFY THE DNS record.
775  list($status, $output) = run_module('dns_record_'.$module, $form);
776 
777  // If the module returned an error code display a popup warning
778  if ($status)
779  $js .= "alert('Save failed.\\n". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
780  else {
781  // if they have checked the keep adding records box then dont remove the window
782  if (!$form['keepadding'])
783  $js .= "removeElement('{$window_name}');";
784  else {
785  $js .= "el('statusinfo_{$window_name}').innerHTML = 'Previously added:<br>{$form['name']} Type: {$form['type']}';";
786  }
787 
788  if ($form['js']) $js .= $form['js'];
789  }
790 
791  // Insert the new table into the window
792  $response->addScript($js);
793  return($response->getXML());
794 }
795 
796 
797 
798 
799 
800 
801 
803 // Function:
804 // Delete Form
805 //
806 // Description:
807 // Deletes a dns record. $form should be an array with a 'dns_record_id'
808 // key defined and optionally a 'js' key with javascript to have the
809 // browser run after a successful delete.
811 function ws_delete($window_name, $form='') {
812  global $include, $conf, $self, $onadb, $onadb;
813 
814  // Check permissions
815  if (!auth('dns_record_del')) {
816  $response = new xajaxResponse();
817  $response->addScript("alert('Permission denied!');");
818  return($response->getXML());
819  }
820 
821  // If an array in a string was provided, build the array and store it in $form
822  $form = parse_options_string($form);
823 
824  // Instantiate the xajaxResponse object
825  $response = new xajaxResponse();
826  $js = '';
827 
828  // Run the module
829  list($status, $output) = run_module('dns_record_del', array('name' => $form['dns_record_id'], 'commit' => $form['commit']));
830 
831  // If commit was N, display the confirmation dialog box
832  if (!$form['commit']) {
833  $build_commit_html = 1;
834  $commit_function = 'delete';
835  include(window_find_include('module_results'));
836  return(window_open("{$window_name}_results", $window));
837  }
838 
839  // If the module returned an error code display a popup warning
840  if ($status)
841  $js .= "alert('Delete failed. " . preg_replace('/[\s\']+/', ' ', $output) . "');";
842  else if ($form['js'])
843  $js .= $form['js']; // usually js will refresh the window we got called from
844 
845  // Return an XML response
846  $response->addScript($js);
847  return($response->getXML());
848 }
849 
850 
851 
852 
854 // Function:
855 // Make primary dns function
856 //
857 // Description:
858 // makes a dns record primary for the given host. $form should be an array with a 'dns_record_id'
859 // key defined and optionally a 'js' key with javascript to have the
860 // browser run after a successful update.
862 function ws_makeprimary($window_name, $form='') {
863  global $include, $conf, $self, $onadb;
864 
865  // Check permissions
866  if (!auth('dns_record_modify')) {
867  $response = new xajaxResponse();
868  $response->addScript("alert('Permission denied!');");
869  return($response->getXML());
870  }
871 
872  // If an array in a string was provided, build the array and store it in $form
873  $form = parse_options_string($form);
874 
875  // Instantiate the xajaxResponse object
876  $response = new xajaxResponse();
877  $js = '';
878 
879  $SET = array();
880  $SET['primary_dns_id'] = $form['dns_record_id'];
881 
882  // Do the actual update
883  list($status, $rows) = db_update_record($onadb, 'hosts', array('id' => $form['host_id']), $SET);
884  if ($status or !$rows) {
885  $self['error'] = "ERROR => makeprimary() SQL Query failed to update host: " . $self['error'];
886  printmsg($self['error'], 0);
887  $js .= "alert('Makeprimary failed. " . preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
888  } else if ($form['js']) {
889  // Hardcoding so that it always refreshes the display host page.
890  $js .= "xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\',\'host_id=>{$form['host_id']}\', \'display\')');";
891  }
892 
893  // Return an XML response
894  $response->addScript($js);
895  return($response->getXML());
896 }
897 
898 
899 
900 
901 
902 
904 // Function:
905 // Make primary dns function
906 //
907 // Description:
908 // makes a dns record primary for the given host. $form should be an array with a 'dns_record_id'
909 // key defined and optionally a 'js' key with javascript to have the
910 // browser run after a successful update.
912 function ws_enablerecord($window_name, $form='') {
913  global $include, $conf, $self, $onadb;
914 
915  // Check permissions
916  if (!auth('dns_record_modify')) {
917  $response = new xajaxResponse();
918  $response->addScript("alert('Failed to enable record: Permission denied!');");
919  return($response->getXML());
920  }
921 
922  // If an array in a string was provided, build the array and store it in $form
923  $form = parse_options_string($form);
924 
925  // Instantiate the xajaxResponse object
926  $response = new xajaxResponse();
927  $js = '';
928 
929  $SET = array();
930  $SET['ebegin'] = date('Y-m-j G:i:s',time());
931 
932  // Do the actual update
933  list($status, $rows) = db_update_record($onadb, 'dns', array('id' => $form['dns_record_id']), $SET);
934  if ($status or !$rows) {
935  $self['error'] = "ERROR => enablerecord() SQL Query failed to update dnsrecord: " . $self['error'];
936  printmsg($self['error'], 0);
937  $js .= "alert('Enable DNS record failed. " . preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
938  } else if ($form['js']) {
939  // Hardcoding so that it always refreshes the display host page.
940  //$js .= "xajax_window_submit('work_space', 'xajax_window_submit(\'{$window_name}\',\'host_id=>{$form['host_id']}\', \'display\')');";
941  $js .= $form['js'];
942  }
943 
944  // Return an XML response
945  $response->addScript($js);
946  return($response->getXML());
947 }
948 
949 
950 
951 
952 ?>
sanitize_YN
sanitize_YN($string="", $default="Y")
Definition: functions_general.inc.php:1637
ws_enablerecord
ws_enablerecord($window_name, $form='')
Definition: edit_record.inc.php:912
onclick
_button onclick
Definition: app_advanced_search.inc.php:50
ws_editor
ws_editor($window_name, $form='')
Definition: edit_record.inc.php:23
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
window_find_include
window_find_include($window_name)
Definition: webwin.inc.php:204
ws_makeprimary
ws_makeprimary($window_name, $form='')
Definition: edit_record.inc.php:862
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
$window
$window['title']
Definition: install.php:26
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.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
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
$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
sanitize_hostname
sanitize_hostname($string="")
Definition: functions_general.inc.php:900
$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
ona_get_domain_record
ona_get_domain_record($array='', $order='')
Definition: functions_db.inc.php:1134
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
ws_delete
ws_delete($window_name, $form='')
Definition: edit_record.inc.php:811
ws_save
ws_save($window_name, $form='')
Definition: edit_record.inc.php:676
$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
ona_get_dns_record
ona_get_dns_record($array='', $order='')
Definition: functions_db.inc.php:1142