commit | author | age
|
b9ea02
|
1 |
<?php |
F |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
Copyright (c) 2013, Florian Schaal, info@schaal-24.de |
|
6 |
All rights reserved. |
|
7 |
|
|
8 |
Redistribution and use in source and binary forms, with or without modification, |
|
9 |
are permitted provided that the following conditions are met: |
|
10 |
|
|
11 |
* Redistributions of source code must retain the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer. |
|
13 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
this list of conditions and the following disclaimer in the documentation |
|
15 |
and/or other materials provided with the distribution. |
|
16 |
* Neither the name of ISPConfig nor the names of its contributors |
|
17 |
may be used to endorse or promote products derived from this software without |
|
18 |
specific prior written permission. |
|
19 |
|
|
20 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
21 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
22 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
23 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
24 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
25 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
26 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
27 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
29 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
*/ |
|
31 |
|
|
32 |
/****************************************** |
|
33 |
* Begin Form configuration |
|
34 |
******************************************/ |
|
35 |
|
|
36 |
$tform_def_file = "form/dns_dkim.tform.php"; |
|
37 |
|
|
38 |
/****************************************** |
|
39 |
* End Form configuration |
|
40 |
******************************************/ |
|
41 |
|
b1a6a5
|
42 |
require_once '../../lib/config.inc.php'; |
MC |
43 |
require_once '../../lib/app.inc.php'; |
b9ea02
|
44 |
|
F |
45 |
//* Check permissions for module |
|
46 |
$app->auth->check_module_permissions('dns'); |
|
47 |
|
|
48 |
// Loading classes |
|
49 |
$app->uses('tpl,tform,tform_actions,validate_dns'); |
|
50 |
$app->load('tform_actions'); |
|
51 |
|
|
52 |
class page_action extends tform_actions { |
b1a6a5
|
53 |
|
b9ea02
|
54 |
function onShowNew() { |
F |
55 |
global $app, $conf; |
|
56 |
// we will check only users, not admins |
|
57 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
b1a6a5
|
58 |
|
b9ea02
|
59 |
// Get the limits of the client |
c6d29c
|
60 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
6c57e7
|
61 |
$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); |
b1a6a5
|
62 |
|
b9ea02
|
63 |
// Check if the user may add another record. |
F |
64 |
if($client["limit_dns_record"] >= 0) { |
6c57e7
|
65 |
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id); |
b9ea02
|
66 |
if($tmp["number"] >= $client["limit_dns_record"]) { |
F |
67 |
$app->error($app->tform->wordbook["limit_dns_record_txt"]); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
parent::onShowNew(); |
5f82ee
|
73 |
|
cc7a82
|
74 |
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_GET['zone']); |
MC |
75 |
$sql=$app->db->queryOneRecord("SELECT dkim_public, dkim_selector FROM mail_domain WHERE domain = ? AND dkim = 'y' AND " . $app->tform->getAuthSQL('r'), substr_replace($soa['origin'],'',-1)); |
5f82ee
|
76 |
$public_key=str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$sql['dkim_public']); |
FS |
77 |
$app->tpl->setVar('public_key', $public_key); |
|
78 |
$app->tpl->setVar('selector', $sql['dkim_selector']); |
|
79 |
$app->tpl->setVar('name', $soa['origin']); |
|
80 |
|
b9ea02
|
81 |
} |
F |
82 |
|
|
83 |
function onSubmit() { |
|
84 |
global $app, $conf; |
|
85 |
// Get the parent soa record of the domain |
cc7a82
|
86 |
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_POST["zone"]); |
b9ea02
|
87 |
// Check if Domain belongs to user |
F |
88 |
if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"]; |
b1a6a5
|
89 |
|
b9ea02
|
90 |
// Check the client limits, if user is not the admin |
F |
91 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin |
|
92 |
// Get the limits of the client |
c6d29c
|
93 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
6c57e7
|
94 |
$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); |
b9ea02
|
95 |
// Check if the user may add another record. |
F |
96 |
if($this->id == 0 && $client["limit_dns_record"] >= 0) { |
6c57e7
|
97 |
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id); |
b9ea02
|
98 |
if($tmp["number"] >= $client["limit_dns_record"]) { |
F |
99 |
$app->error($app->tform->wordbook["limit_dns_record_txt"]); |
|
100 |
} |
|
101 |
} |
|
102 |
} // end if user is not admin |
b1a6a5
|
103 |
|
b9ea02
|
104 |
// Set the server ID of the rr record to the same server ID as the parent record. |
F |
105 |
$this->dataRecord["server_id"] = $soa["server_id"]; |
b1a6a5
|
106 |
|
b9ea02
|
107 |
// add dkim-settings to the public-key in the txt-record |
76be2b
|
108 |
if (!empty($this->dataRecord['data'])) { |
FS |
109 |
$this->dataRecord['data']='v=DKIM1; t=s; p='.$this->dataRecord['data']; |
|
110 |
$this->dataRecord['name']=$this->dataRecord['selector'].'._domainkey.'.$this->dataRecord['name']; |
74df31
|
111 |
$this->dataRecord['ttl']=60; |
76be2b
|
112 |
} |
5f82ee
|
113 |
// Update the serial number and timestamp of the RR record |
FS |
114 |
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ?", $this->id); |
|
115 |
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]); |
|
116 |
$this->dataRecord["stamp"] = date('Y-m-d H:i:s'); |
b1a6a5
|
117 |
|
5f82ee
|
118 |
// check for duplicate entry |
FS |
119 |
$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']); |
|
120 |
if ($check!='') $app->tform->errorMessage .= $app->tform->wordbook["record_exists_txt"]; |
|
121 |
if (empty($this->dataRecord['data'])) $app->tform->errorMessage .= $app->tform->wordbook["dkim_disabled_txt"]; |
b9ea02
|
122 |
parent::onSubmit(); |
F |
123 |
} |
b1a6a5
|
124 |
|
b9ea02
|
125 |
function onAfterInsert() { |
F |
126 |
global $app, $conf; |
b1a6a5
|
127 |
|
b9ea02
|
128 |
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record |
cc7a82
|
129 |
$soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]); |
3a11d2
|
130 |
$app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id); |
b9ea02
|
131 |
|
F |
132 |
//* Update the serial number of the SOA record |
|
133 |
$soa_id = $app->functions->intval($_POST["zone"]); |
|
134 |
$serial = $app->validate_dns->increase_serial($soa["serial"]); |
3a11d2
|
135 |
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id); |
b9ea02
|
136 |
} |
b1a6a5
|
137 |
|
b9ea02
|
138 |
function onAfterUpdate() { |
F |
139 |
global $app, $conf; |
b1a6a5
|
140 |
|
b9ea02
|
141 |
//* Update the serial number of the SOA record |
cc7a82
|
142 |
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]); |
b9ea02
|
143 |
$soa_id = $app->functions->intval($_POST["zone"]); |
F |
144 |
$serial = $app->validate_dns->increase_serial($soa["serial"]); |
3a11d2
|
145 |
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id); |
b9ea02
|
146 |
} |
b1a6a5
|
147 |
|
b9ea02
|
148 |
} |
F |
149 |
|
|
150 |
$page = new page_action; |
|
151 |
$page->onLoad(); |
|
152 |
|
|
153 |
?> |