Skip to content

Commit e68fbf8

Browse files
committed
NAPTR dns record editor/support
1 parent 8681150 commit e68fbf8

File tree

10 files changed

+381
-14
lines changed

10 files changed

+381
-14
lines changed

interface/web/dns/dns_dkim_edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function onSubmit() {
126126
$this->dataRecord["stamp"] = date('Y-m-d H:i:s');
127127

128128
// check for duplicate entry
129+
// Should NOT include data in this check? it must be unique for zone/name (selector)/type, regardless of data
129130
$check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ? AND type = ? AND data = ? AND name = ?", $this->dataRecord["zone"], $this->dataRecord["type"], $this->dataRecord["data"], $this->dataRecord['name']);
130131
if ($check!='') $app->tform->errorMessage .= $app->tform->wordbook["record_exists_txt"];
131132
if (empty($this->dataRecord['data'])) $app->tform->errorMessage .= $app->tform->wordbook["dkim_disabled_txt"];

interface/web/dns/dns_edit_base.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ protected function checkDuplicate() {
4444
return false;
4545
}
4646

47+
protected function zoneFileEscape( $str ) {
48+
// escape backslash and double quotes
49+
$ret = str_replace( '\\', '\\\\', $str );
50+
$ret = str_replace( '"', '\\"', $ret );
51+
return $ret;
52+
}
53+
54+
protected function zoneFileUnescape( $str ) {
55+
// escape sequence can be rfc 1035 '\DDD' (backslash, 3 digits) or '\X' (backslash, non-digit char)
56+
return preg_replace_callback( '/\\\\(\d\d\d|\D)/',
57+
function( $Matches ) {
58+
if (preg_match( '/\d{3}/', $Matches[1] )) {
59+
return chr( $Matches[1] );
60+
} elseif (preg_match( '/\D/', $Matches[1])) {
61+
return $Matches[1];
62+
} else {
63+
return $Matches[0];
64+
}
65+
},
66+
$str
67+
);
68+
}
69+
4770
function onShowNew() {
4871
global $app, $conf;
4972

interface/web/dns/dns_import.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ function fqdn_name( $owner, $origin ) {
289289

290290
$line = rtrim($line);
291291
if ($line != ''){
292+
// this of course breaks TXT when it includes whitespace
292293
$sPattern = '/\s+/m';
293294
$sReplace = ' ';
294295
$new_lines[] = preg_replace($sPattern, $sReplace, $line);
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/******************************************
32+
* Begin Form configuration
33+
******************************************/
34+
35+
$tform_def_file = "form/dns_naptr.tform.php";
36+
37+
/******************************************
38+
* End Form configuration
39+
******************************************/
40+
41+
require_once '../../lib/config.inc.php';
42+
require_once '../../lib/app.inc.php';
43+
require_once './dns_edit_base.php';
44+
45+
// Loading classes
46+
class page_action extends dns_page_action {
47+
48+
function onSubmit() {
49+
// Combine and escape/format fields into the data to be saved
50+
$this->dataRecord['data'] = $this->dataRecord['pref'] .' '.
51+
'"'. $this->zoneFileEscape( $this->dataRecord['flags'] ) .'" '.
52+
'"'. $this->zoneFileEscape( $this->dataRecord['service'] ) .'" '.
53+
'"'. $this->zoneFileEscape( $this->dataRecord['regexp'] ) .'" '.
54+
$this->dataRecord['replacement'] . (substr( $this->dataRecord['replacement'], -1 ) == '.' ? '' : '.');
55+
56+
$this->dataRecord['aux'] = $this->dataRecord['order'];
57+
58+
parent::onSubmit();
59+
}
60+
61+
62+
function onShowEnd() {
63+
global $app, $conf;
64+
65+
// Split the parts of NAPTR record, unescape (backslashes), and unquote to edit.
66+
//
67+
// Examples:
68+
// ;; order pref flags service regexp replacement
69+
// IN NAPTR 100 10 "" "" "!^cid:.+@([^\.]+\.)(.*)$!\2!i" .
70+
//
71+
// ;; order pref flags service regexp replacement
72+
// IN NAPTR 100 100 "s" "thttp+L2R" "" thttp.example.com.
73+
// IN NAPTR 100 100 "s" "ftp+L2R" "" ftp.example.com.
74+
//
75+
// 'order' in stored in 'aux' column,
76+
// all of 'pref "flags" "service" "regexp" replacement.' is here in 'data'
77+
//
78+
$matched = preg_match('/^\s*(\d+)\s+"([a-zA-Z0-9]*)"\s+"([^"]*)"\s+"(.*)"\s+([^\s]*\.)\s*$/', $this->dataRecord['data'], $matches);
79+
80+
if ($matched === FALSE || is_array($matches) && count($matches) == 0) {
81+
if ( isset($app->tform->errorMessage) ) {
82+
$app->tform->errorMessage .= '<br/>' . $app->tform->wordbook["record_parse_error"];
83+
}
84+
} else {
85+
$app->tpl->setVar('pref', $matches[1], true);
86+
$app->tpl->setVar('flags', $this->zoneFileUnescape($matches[2]), true);
87+
$app->tpl->setVar('service', $this->zoneFileUnescape($matches[3]), true);
88+
$app->tpl->setVar('regexp', $this->zoneFileUnescape($matches[4]), true);
89+
$app->tpl->setVar('replacement', $matches[5], true);
90+
}
91+
92+
parent::onShowEnd();
93+
}
94+
95+
}
96+
97+
$page = new page_action;
98+
$page->onLoad();
99+
100+
?>
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
3+
/*
4+
Form Definition
5+
6+
Tabledefinition
7+
8+
Datatypes:
9+
- INTEGER (Forces the input to Int)
10+
- DOUBLE
11+
- CURRENCY (Formats the values to currency notation)
12+
- VARCHAR (no format check, maxlength: 255)
13+
- TEXT (no format check)
14+
- DATE (Dateformat, automatic conversion to timestamps)
15+
16+
Formtype:
17+
- TEXT (Textfield)
18+
- TEXTAREA (Textarea)
19+
- PASSWORD (Password textfield, input is not shown when edited)
20+
- SELECT (Select option field)
21+
- RADIO
22+
- CHECKBOX
23+
- CHECKBOXARRAY
24+
- FILE
25+
26+
VALUE:
27+
- Wert oder Array
28+
29+
Hint:
30+
The ID field of the database table is not part of the datafield definition.
31+
The ID field must be always auto incement (int or bigint).
32+
33+
34+
*/
35+
global $app;
36+
37+
$form["title"] = "DNS NAPTR";
38+
$form["description"] = "";
39+
$form["name"] = "dns_naptr";
40+
$form["action"] = "dns_naptr_edit.php";
41+
$form["db_table"] = "dns_rr";
42+
$form["db_table_idx"] = "id";
43+
$form["db_history"] = "yes";
44+
$form["tab_default"] = "dns";
45+
$form["list_default"] = "dns_a_list.php";
46+
$form["auth"] = 'yes'; // yes / no
47+
48+
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
49+
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
50+
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
51+
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
52+
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
53+
54+
$form["tabs"]['dns'] = array (
55+
'title' => "DNS NAPTR",
56+
'width' => 100,
57+
'template' => "templates/dns_naptr_edit.htm",
58+
'fields' => array (
59+
//#################################
60+
// Begin Datatable fields
61+
//#################################
62+
'server_id' => array (
63+
'datatype' => 'INTEGER',
64+
'formtype' => 'SELECT',
65+
'default' => '',
66+
'value' => '',
67+
'width' => '30',
68+
'maxlength' => '255'
69+
),
70+
'zone' => array (
71+
'datatype' => 'INTEGER',
72+
'formtype' => 'TEXT',
73+
'default' => @$app->functions->intval($_REQUEST["zone"]),
74+
'value' => '',
75+
'width' => '30',
76+
'maxlength' => '255'
77+
),
78+
'name' => array (
79+
'datatype' => 'VARCHAR',
80+
'formtype' => 'TEXT',
81+
'filters' => array(
82+
0 => array( 'event' => 'SAVE',
83+
'type' => 'IDNTOASCII'),
84+
1 => array( 'event' => 'SHOW',
85+
'type' => 'IDNTOUTF8'),
86+
2 => array( 'event' => 'SAVE',
87+
'type' => 'TOLOWER')
88+
),
89+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
90+
'regex' => '/^((\*|[a-zA-Z0-9\-_]{1,255})(\.[a-zA-Z0-9\-_]{1,255})*\.?)?$/',
91+
'errmsg'=> 'name_error_regex'),
92+
),
93+
'default' => '',
94+
'value' => '',
95+
'width' => '30',
96+
'maxlength' => '1024'
97+
),
98+
'type' => array (
99+
'datatype' => 'VARCHAR',
100+
'formtype' => 'TEXT',
101+
'default' => 'NAPTR',
102+
'value' => '',
103+
'width' => '5',
104+
'maxlength' => '5'
105+
),
106+
'data' => array (
107+
'datatype' => 'VARCHAR',
108+
'formtype' => 'TEXT',
109+
'validators' => array (
110+
0 => array (
111+
'type' => 'NOTEMPTY',
112+
'errmsg'=> 'data_error_empty'),
113+
1 => array (
114+
'type' => 'REGEX',
115+
// matching: 'pref "flags" "service" "regexp" replacement.'
116+
'regex' => '/^\s*(\d+)\s+"([a-zA-Z0-9]*)"\s+"([^"]*)"\s+"(.*)"\s+([^\s]*\.)\s*$/',
117+
'errmsg'=> 'naptr_error_regex'),
118+
),
119+
'default' => '100 "" "" "" .',
120+
'value' => '',
121+
'width' => '30',
122+
'maxlength' => '1024'
123+
),
124+
'aux' => array (
125+
'datatype' => 'INTEGER',
126+
'formtype' => 'TEXT',
127+
'default' => '100',
128+
'value' => '',
129+
'width' => '10',
130+
'maxlength' => '10'
131+
),
132+
'ttl' => array (
133+
'datatype' => 'INTEGER',
134+
'formtype' => 'TEXT',
135+
'validators' => array ( 0 => array ( 'type' => 'RANGE',
136+
'range' => '60:',
137+
'errmsg'=> 'ttl_range_error'),
138+
),
139+
'default' => '3600',
140+
'value' => '',
141+
'width' => '10',
142+
'maxlength' => '10'
143+
),
144+
'active' => array (
145+
'datatype' => 'VARCHAR',
146+
'formtype' => 'CHECKBOX',
147+
'default' => 'Y',
148+
'value' => array(0 => 'N', 1 => 'Y')
149+
),
150+
'stamp' => array (
151+
'datatype' => 'VARCHAR',
152+
'formtype' => 'TEXT',
153+
'default' => '',
154+
'value' => '',
155+
'width' => '30',
156+
'maxlength' => '255'
157+
),
158+
'serial' => array (
159+
'datatype' => 'INTEGER',
160+
'formtype' => 'TEXT',
161+
'default' => '',
162+
'value' => '',
163+
'width' => '10',
164+
'maxlength' => '10'
165+
),
166+
//#################################
167+
// END Datatable fields
168+
//#################################
169+
)
170+
);
171+
172+
173+
174+
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$wb["server_id_txt"] = 'Server';
3+
$wb["zone_txt"] = 'Zone';
4+
$wb["name_txt"] = 'Hostname';
5+
$wb["order_txt"] = 'Order';
6+
$wb["pref_txt"] = 'Pref';
7+
$wb["flags_txt"] = 'Flags';
8+
$wb["service_txt"] = 'Service';
9+
$wb["regexp_txt"] = 'RegExp';
10+
$wb["replacement_txt"] = 'Replacement';
11+
$wb["ttl_txt"] = 'TTL';
12+
$wb["active_txt"] = 'Active';
13+
$wb["limit_dns_record_txt"] = 'The max. number of DNS records for your account is reached.';
14+
$wb["no_zone_perm"] = 'You do not have the permission to add a record to this DNS zone.';
15+
$wb["name_error_empty"] = 'The hostname is empty.';
16+
$wb["name_error_regex"] = 'The hostname has the wrong format.';
17+
$wb["data_error_empty"] = 'NAPTR record is empty.';
18+
$wb["naptr_error_regex"] = 'Invalid NAPTR record. The NAPTR record must include Order, Pref and either Regex or Replacement.';
19+
$wb['ttl_range_error'] = 'Min. TTL time is 60 seconds.';
20+
$wb['record_parse_error'] = 'Could not parse the record found in database.';
21+
?>

interface/web/dns/list/dns_a.list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
'prefix' => "",
133133
'suffix' => "",
134134
'width' => "",
135-
'value' => array('A'=>'A', 'AAAA' => 'AAAA', 'ALIAS'=>'ALIAS', 'CAA'=>'CAA', 'CNAME'=>'CNAME', 'DS'=>'DS', 'HINFO'=>'HINFO', 'LOC'=>'LOC', 'MX'=>'MX', 'NS'=>'NS', 'PTR'=>'PTR', 'RP'=>'RP', 'SRV'=>'SRV', 'TLSA'=>'TLSA', 'TXT'=>'TXT'));
135+
'value' => array('A'=>'A', 'AAAA' => 'AAAA', 'ALIAS'=>'ALIAS', 'CAA'=>'CAA', 'CNAME'=>'CNAME', 'DS'=>'DS', 'HINFO'=>'HINFO', 'LOC'=>'LOC', 'MX'=>'MX', 'NAPTR'=>'NAPTR', 'NS'=>'NS', 'PTR'=>'PTR', 'RP'=>'RP', 'SRV'=>'SRV', 'TLSA'=>'TLSA', 'TXT'=>'TXT'));
136136

137137

138138
?>

interface/web/dns/templates/dns_a_list.htm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_hinfo_edit.php?zone={tmpl_var name='parent_id'}">HINFO</button>
2929
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_loc_edit.php?zone={tmpl_var name='parent_id'}">LOC</button>
3030
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_mx_edit.php?zone={tmpl_var name='parent_id'}">MX</button>
31+
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_naptr_edit.php?zone={tmpl_var name='parent_id'}">NAPTR</button>
3132
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_ns_edit.php?zone={tmpl_var name='parent_id'}">NS</button>
3233
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_ptr_edit.php?zone={tmpl_var name='parent_id'}">PTR</button>
3334
<button class="btn btn-default formbutton-success" type="button" data-load-content="dns/dns_rp_edit.php?zone={tmpl_var name='parent_id'}">RP</button>

0 commit comments

Comments
 (0)