Skip to content

Commit e65960b

Browse files
author
A. Täffner
committed
did accidentally overwrite previous implmeentation of SPF
This one also sets type SPF as well as two records within DNS as of RFC4408 Hop that's okay?
1 parent 13b62b9 commit e65960b

File tree

5 files changed

+313
-46
lines changed

5 files changed

+313
-46
lines changed

interface/web/dns/dns_spf_edit.php

Lines changed: 219 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2014, Florian Schaal, info@schaal-24.de
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without modification,
@@ -40,10 +40,226 @@
4040

4141
require_once '../../lib/config.inc.php';
4242
require_once '../../lib/app.inc.php';
43-
require_once './dns_edit_base.php';
43+
44+
//* Check permissions for module
45+
$app->auth->check_module_permissions('dns');
4446

4547
// Loading classes
46-
class page_action extends dns_page_action {
48+
$app->uses('tpl,tform,tform_actions,validate_dns');
49+
$app->load('tform_actions');
50+
51+
class page_action extends tform_actions {
52+
53+
function onShowNew() {
54+
global $app, $conf;
55+
// we will check only users, not admins
56+
if($_SESSION["s"]["user"]["typ"] == 'user') {
57+
58+
// Get the limits of the client
59+
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
60+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
61+
62+
// Check if the user may add another mailbox.
63+
if($client["limit_dns_record"] >= 0) {
64+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id);
65+
if($tmp["number"] >= $client["limit_dns_record"]) {
66+
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
67+
}
68+
}
69+
}
70+
71+
parent::onShowNew();
72+
}
73+
74+
function onShowEnd() {
75+
global $app, $conf;
76+
77+
$zone = $app->functions->intval($_GET['zone']);
78+
79+
//* check for an existing spf-record
80+
$sql = "SELECT data, active FROM dns_rr WHERE data LIKE 'v=spf1%' AND zone = ? AND " . $app->tform->getAuthSQL('r');
81+
$rec = $app->db->queryOneRecord($sql, $zone);
82+
if ( isset($rec) && !empty($rec) ) {
83+
$this->id = 1;
84+
$old_data = strtolower($rec['data']);
85+
86+
$app->tpl->setVar("data", $old_data);
87+
if ($rec['active'] == 'Y') $app->tpl->setVar("active", "CHECKED"); else $app->tpl->setVar("active", "UNCHECKED");
88+
89+
$spf_hostname = '';
90+
$spf_ip = '';
91+
$spf_domain = '';
92+
$spf_mechanism = '';
93+
94+
// browse through data
95+
$temp = explode(' ', $old_data);
96+
foreach ($temp as $part) {
97+
if ($part == 'a') $app->tpl->setVar("spf_a_active", "CHECKED");
98+
if ($part == 'mx') $app->tpl->setVar("spf_mx_active", "CHECKED");
99+
if (preg_match("/^ip(4|6):/", $part)) $spf_ip .= str_replace(array('ip4:','ip6:'), '', $part) . ' ';
100+
if (preg_match("/^a:/", $part)) $spf_hostname .= str_replace('a:', '', $part) . ' ';
101+
if (preg_match("/^\\??include/", $part)) $spf_domain .= str_replace(array('include:', '?'), '', $part) . ' ';
102+
}
103+
unset($temp);
104+
$spf_ip = rtrim($spf_ip);
105+
$spf_hostname = rtrim($spf_hostname);
106+
$spf_domain = rtrim($spf_domain);
107+
$spf_mechanism = substr($rec['data'], -4, 1);
108+
}
109+
110+
//set html-values
111+
$app->tpl->setVar("spf_ip", $spf_ip);
112+
$app->tpl->setVar("spf_hostname", $spf_hostname);
113+
$app->tpl->setVar("spf_domain", $spf_domain);
114+
//create spf-mechanism-list
115+
$spf_mechanism_value = array(
116+
'+' => 'spf_mechanism_pass_txt',
117+
'-' => 'spf_mechanism_fail_txt',
118+
'~' => 'spf_mechanism_softfail_txt',
119+
'?' => 'spf_mechanism_neutral_txt'
120+
);
121+
$spf_mechanism_list='';
122+
foreach($spf_mechanism_value as $value => $txt) {
123+
$selected = @($spf_mechanism == $value)?' selected':'';
124+
$spf_mechanism_list .= "<option value='$value'$selected>".$app->tform->wordbook[$txt]."</option>\r\n";
125+
}
126+
$app->tpl->setVar('spf_mechanism', $spf_mechanism_list);
127+
128+
parent::onShowEnd();
129+
130+
}
131+
132+
function onSubmit() {
133+
global $app, $conf;
134+
135+
136+
// Get the parent soa record of the domain
137+
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $app->functions->intval($_POST["zone"]));
138+
139+
// Check if Domain belongs to user
140+
if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"];
141+
142+
// Check the client limits, if user is not the admin
143+
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
144+
// Get the limits of the client
145+
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
146+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
147+
148+
// Check if the user may add another mailbox.
149+
if($this->id == 0 && $client["limit_dns_record"] >= 0) {
150+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id);
151+
if($tmp["number"] >= $client["limit_dns_record"]) {
152+
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
153+
}
154+
}
155+
} // end if user is not admin
156+
157+
//create spf-record
158+
if (!empty($this->dataRecord['spf_mx'])) {
159+
$spf_record[] = 'mx';
160+
}
161+
if (!empty($this->dataRecord['spf_a'])) {
162+
$spf_record[] = 'a';
163+
}
164+
$spf_ip = trim($this->dataRecord['spf_ip']);
165+
if (!empty($spf_ip)) {
166+
$rec = split(' ', $spf_ip);
167+
foreach ($rec as $ip) {
168+
$temp_ip = explode('/', $ip);
169+
if (filter_var($temp_ip[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
170+
$temp = 'ip4:' . $temp_ip[0];
171+
if (isset($temp_ip[1])) $temp .= '/' . $temp_ip[1];
172+
$spf_record[] = $temp;
173+
unset($temp);
174+
}
175+
elseif (filter_var($temp_ip[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
176+
$temp = 'ip6:' . $temp_ip[0];
177+
if (isset($temp_ip[1])) $temp .= '/' . $temp_ip[1];
178+
$spf_record[] = $temp;
179+
unset($temp);
180+
}
181+
else {
182+
if (isset($app->tform->errorMessage )) $app->tform->errorMessage = '<br/>' . $app->tform->errorMessage;
183+
$app->tform->errorMessage .= $app->tform->wordbook["spf_invalid_ip_txt"]. $temp_ip[0];
184+
if (isset( $temp_ip[1])) $app->tform->errorMessage .= "/".$temp_ip[1];
185+
}
186+
}
187+
}
188+
$spf_hostname = trim($this->dataRecord['spf_hostname']);
189+
if (!empty($spf_hostname)) {
190+
$rec = split(' ', $spf_hostname);
191+
foreach ($rec as $hostname) {
192+
if (preg_match('/^[a-zA-Z0-9\\.\\-\\*]{0,64}$/', $hostname))
193+
$spf_record[] = 'a:' . $hostname;
194+
else {
195+
if (isset($app->tform->errorMessage )) $app->tform->errorMessage .= '<br/>' . $app->tform->wordbook["spf_invalid_hostname_txt"]. $hostname;
196+
$app->tform->errorMessage .= $app->tform->wordbook["spf_invalid_hostname_txt"]. $hostname;
197+
}
198+
}
199+
unset($rec);
200+
}
201+
$spf_domain = trim($this->dataRecord['spf_domain']);
202+
if (!empty($spf_domain)) {
203+
$rec = split(' ', $spf_domain);
204+
foreach ($rec as $domain) {
205+
if (preg_match('/^[_a-zA-Z0-9\\.\\-\\*]{0,64}$/', $domain))
206+
$spf_record[] = 'include:' . $domain;
207+
else {
208+
if (isset($app->tform->errorMessage )) $app->tform->errorMessage .= '<br/>' . $app->tform->wordbook["spf_invalid_domain_txt"]. $domain;
209+
$app->tform->errorMessage .= $app->tform->wordbook["spf_invalid_domain_txt"]. $domain;
210+
}
211+
}
212+
}
213+
214+
$temp = implode(' ', $spf_record);unset($spf_record);
215+
if (!empty($temp))
216+
$this->dataRecord['data'] = 'v=spf1 ' . $temp . ' ' . $this->dataRecord['spf_mechanism'] . 'all';
217+
else $this->dataRecord['data'] = 'v=spf1 ' . $this->dataRecord['spf_mechanism'] . 'all';
218+
unset($temp);
219+
220+
$this->dataRecord['name'] = $soa['origin'];
221+
if (isset($this->dataRecord['active'])) $this->dataRecord['active'] = 'Y';
222+
223+
// Set the server ID of the rr record to the same server ID as the parent record.
224+
$this->dataRecord["server_id"] = $soa["server_id"];
225+
226+
// Update the serial number and timestamp of the RR record
227+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ?", $this->id);
228+
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
229+
$this->dataRecord["stamp"] = date('Y-m-d H:i:s');
230+
231+
// always update an existing entry
232+
$check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ? AND type = ? AND data LIKE 'v=spf1%' AND name = ?", $this->dataRecord["zone"], $this->dataRecord["type"], $this->dataRecord['name']);
233+
$this->id = $check['id'];
234+
235+
if (!isset($this->dataRecord['active'])) $this->dataRecord['active'] = 'N';
236+
237+
parent::onSubmit();
238+
}
239+
240+
function onAfterInsert() {
241+
global $app, $conf;
242+
243+
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
244+
$soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $app->functions->intval($this->dataRecord["zone"]));
245+
$app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
246+
247+
//* Update the serial number of the SOA record
248+
$soa_id = $app->functions->intval($_POST["zone"]);
249+
$serial = $app->validate_dns->increase_serial($soa["serial"]);
250+
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
251+
252+
}
253+
254+
function onAfterUpdate() {
255+
global $app, $conf;
256+
257+
//* Update the serial number of the SOA record
258+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $app->functions->intval($this->dataRecord["zone"]));
259+
$soa_id = $app->functions->intval($_POST["zone"]);
260+
$serial = $app->validate_dns->increase_serial($soa["serial"]);
261+
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
262+
}
47263

48264
}
49265

interface/web/dns/form/dns_spf.tform.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@
105105
'data' => array (
106106
'datatype' => 'VARCHAR',
107107
'formtype' => 'TEXT',
108-
'validators' => array (
109-
0 => array (
110-
'type' => 'NOTEMPTY',
111-
'errmsg'=> 'data_error_empty'
112-
),
113-
),
114108
'default' => '',
115109
'value' => '',
116110
'width' => '30',
117111
'maxlength' => '255'
118112
),
113+
/*
114+
'aux' => array (
115+
'datatype' => 'INTEGER',
116+
'formtype' => 'TEXT',
117+
'default' => '0',
118+
'value' => '',
119+
'width' => '10',
120+
'maxlength' => '10'
121+
),
122+
*/
119123
'ttl' => array (
120124
'datatype' => 'INTEGER',
121125
'formtype' => 'TEXT',
@@ -132,7 +136,6 @@
132136
'datatype' => 'VARCHAR',
133137
'formtype' => 'CHECKBOX',
134138
'default' => 'Y',
135-
'value' => array(0 => 'N', 1 => 'Y')
136139
),
137140
'stamp' => array (
138141
'datatype' => 'VARCHAR',
@@ -151,15 +154,11 @@
151154
'maxlength' => '10'
152155
),
153156
//#################################
154-
// ENDE Datatable fields
157+
// End Datatable fields
155158
//#################################
156159
)
157160
);
158161

159-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
160-
unset($form["tabs"]['dns']['fields']['data']['validators']);
161-
$form["tabs"]['dns']['fields']['data']['validators'][0]['type'] = 'NOTEMPTY';
162-
$form["tabs"]['dns']['fields']['data']['validators'][0]['errmsg'] = 'data_error_empty';
163-
$form["tabs"]['dns']['fields']['data']['maxlength'] = 512;
164-
}
162+
163+
165164
?>
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1+
2+
13
<?php
2-
$wb['server_id_txt'] = 'Server';
3-
$wb['zone_txt'] = 'Zone';
4-
$wb['name_txt'] = 'Hostname';
5-
$wb['type_txt'] = 'Typ';
6-
$wb['data_txt'] = 'Daten';
4+
$wb['data_txt'] = 'SPF Record';
5+
$wb['spf_mechanism_txt'] = 'SPF Mechanismus';
6+
$wb['spf_mechanism_pass_txt'] = 'Pass - Mails von anderen Sendern zulassen';
7+
$wb['spf_mechanism_fail_txt'] = 'Fail - Mails von anderen Sendern abweisen';
8+
$wb['spf_mechanism_softfail_txt'] = 'SoftFail - Mails von anderen Sendern zulassen aber markieren';
9+
$wb['spf_mechanism_neutral_txt'] = 'Neutral - nichts unternehmen';
10+
$wb['spf_mx_txt'] = 'Von allen MX-Servern dürfen Mails für diese Domain verschicken';
11+
$wb['spf_a_txt'] = 'Von allen eingetragenen IP-Adressen dürfen Mails für diese Domain verschickt werden';
12+
$wb['spf_ip_txt'] = '(Zusätzliche) IP-Adressen im CIDR Format, die Mails für diese Domain verschicken dürfen';
13+
$wb['spf_ip_note_txt'] = '(mehrere IPs mit Leerzeichen trennen)';
14+
$wb['spf_invalid_ip_txt'] = 'Ungültige IP-Adresse';
15+
$wb['spf_hostname_txt'] = '(Zusätzliche) Hostnamen, die für diese Domain Mails verschicken dürfen oder als Relay arbeiten.';
16+
$wb['spf_hostname_note_txt'] = '(mehrere Hostnamen mit Leerzeichen trennen)';
17+
$wb['spf_invalid_hostname_txt'] = 'Ungültiger Hostname';
18+
$wb['spf_domain_txt'] = 'Zusätzliche Domains, die Mails verschicken dürfen oder als Relay arbeiten';
19+
$wb['spf_domain_note_txt'] = '(mehrerer Domains mit Leerzeichen trennen)';
20+
$wb['spf_invalid_domain_txt'] = 'Ungültiger Domainname';
721
$wb['ttl_txt'] = 'TTL';
822
$wb['active_txt'] = 'Aktiv';
23+
$wb["record_exists_txt"] = 'DNS-Eintrag existiert bereits';
24+
$wb['ttl_range_error'] = 'Min. TTL time ist 60 Sekunden.';
925
$wb['limit_dns_record_txt'] = 'Die maximale Anzahl an DNS Einträgen für Ihr Konto wurde erreicht.';
1026
$wb['no_zone_perm'] = 'Sie haben nicht die Berechtigung, einen Eintrag zu dieser DNS Zone hinzuzufügen.';
11-
$wb['name_error_empty'] = 'Der Hostname ist leer.';
12-
$wb['name_error_regex'] = 'Der Hostname hat das falsche Format.';
13-
$wb['data_error_empty'] = 'Text ist leer';
14-
$wb['data_error_regex'] = 'Textformat ungültig';
15-
$wb['ttl_range_error'] = 'Min. TTL time is 60 seconds.';
16-
$wb['info_txt'] = 'Im Nameserver wird zusätzlich ein identischer TXT-Record angelegt. Ihnen wird jedoch nur der SPF-Record angezeigt und auch nur ein Record berechnet.';
1727
?>
28+
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1+
2+
13
<?php
2-
$wb["server_id_txt"] = 'Server';
3-
$wb["zone_txt"] = 'Zone';
4-
$wb["name_txt"] = 'Hostname';
5-
$wb["type_txt"] = 'type';
6-
$wb["data_txt"] = 'Daten';
4+
$wb['data_txt'] = 'SPF-Record';
5+
$wb['spf_mechanism_txt'] = 'SPF Mechanism';
6+
$wb['spf_mechanism_pass_txt'] = 'Pass - allow mail from other senders';
7+
$wb['spf_mechanism_fail_txt'] = 'Fail - reject mail from other senders';
8+
$wb['spf_mechanism_softfail_txt'] = 'SoftFail - allow mail from other senders but mark the email';
9+
$wb['spf_mechanism_neutral_txt'] = 'Neutral - do nothing';
10+
$wb['spf_mx_txt'] = 'Allow servers listed as MX to send email for this domain';
11+
$wb['spf_a_txt'] = 'Allow current IP address of the domain to send email for this domain';
12+
$wb['spf_ip_txt'] = 'Additional IP addresses in CIDR format that deliver or relay mail for this domain';
13+
$wb['spf_ip_note_txt'] = '(Sepearate IPs with whitespaces)';
14+
$wb['spf_invalid_ip_txt'] = 'Invalid IP-address';
15+
$wb['spf_hostname_txt'] = 'Any other server hostname that may deliver or relay mail for this domain';
16+
$wb['spf_hostname_note_txt'] = '(Sepearate hostnames with whitespaces)';
17+
$wb['spf_invalid_hostname_txt'] = 'Invalid hostname';
18+
$wb['spf_domain_txt'] = 'Any domains that may deliver or relay mail for this domain';
19+
$wb['spf_domain_note_txt'] = '(Sepearate domains with whitespaces)';
20+
$wb['spf_invalid_domain_txt'] = 'Invalid domainname';
721
$wb["ttl_txt"] = 'TTL';
822
$wb["active_txt"] = 'Active';
23+
$wb["record_exists_txt"] = 'DNS-Record already exists';
924
$wb["limit_dns_record_txt"] = 'The max. number of DNS records for your account is reached.';
1025
$wb["no_zone_perm"] = 'You do not have the permission to add a record to this DNS zone.';
11-
$wb["name_error_empty"] = 'The hostname is empty.';
12-
$wb["name_error_regex"] = 'The hostname has the wrong format.';
13-
$wb["data_error_empty"] = 'Text empty';
14-
$wb["data_error_regex"] = 'Text format invalid';
1526
$wb['ttl_range_error'] = 'Min. TTL time is 60 seconds.';
16-
$wb['info_txt'] = 'This will also create an identic TXT record within the nameserver. You will only see the SPF record and you will also only be charged for one record.';
1727
?>
28+

0 commit comments

Comments
 (0)