Skip to content

Commit c6d29c1

Browse files
author
Florian Schaal
committed
add dkim-keys to the resync-tool
display dns-record for dkim in the mail-domain rewrite function domain_dkim_update in server/plugins-available/mail_plugin_dkim.inc.php change dns*.php according to commit 604c0c2
1 parent 015dffd commit c6d29c1

File tree

10 files changed

+109
-75
lines changed

10 files changed

+109
-75
lines changed

interface/web/dns/dns_dkim_edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function onShowNew() {
5757
if($_SESSION["s"]["user"]["typ"] == 'user') {
5858

5959
// Get the limits of the client
60-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
60+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
6161
$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");
6262

6363
// Check if the user may add another record.
@@ -82,7 +82,7 @@ function onSubmit() {
8282
// Check the client limits, if user is not the admin
8383
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
8484
// Get the limits of the client
85-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
85+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
8686
$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");
8787
// Check if the user may add another record.
8888
if($this->id == 0 && $client["limit_dns_record"] >= 0) {

interface/web/dns/dns_wizard.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@
102102
if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
103103

104104
// Get the limits of the client
105-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
105+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
106106
$client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
107107

108108

109109
// load the list of clients
110-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id'];
110+
sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$app->functions->intval($client['client_id']);
111111
$clients = $app->db->queryAllRecords($sql);
112-
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client['client_id']);
112+
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client['client_id']));
113113
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
114114
if(is_array($clients)) {
115115
foreach( $clients as $client) {
@@ -122,8 +122,8 @@
122122
}
123123

124124
if($_SESSION["s"]["user"]["typ"] != 'admin')
125-
{
126-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
125+
126+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);{
127127
$client_dns = $app->db->queryOneRecord("SELECT dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
128128

129129
$client_dns['dns_servers_ids'] = explode(',', $client_dns['dns_servers']);
@@ -149,7 +149,7 @@
149149

150150
}
151151

152-
$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '$template_id'");
152+
$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '".$app->functions->intval($template_id)."'");
153153
$fields = explode(',', $template_record['fields']);
154154
if(is_array($fields)) {
155155
foreach($fields as $field) {
@@ -165,7 +165,7 @@
165165

166166
if ($post_server_id)
167167
{
168-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
168+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
169169
$client = $app->db->queryOneRecord("SELECT dns_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
170170

171171
$client['dns_servers_ids'] = explode(',', $client['dns_servers']);

interface/web/js/mail_domain_dkim.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ This Javascript is invoked by
6060
else {
6161
document.getElementsByName('dkim_private')[0].value = request.responseXML.getElementsByTagName('privatekey')[0].firstChild.nodeValue;
6262
document.getElementsByName('dkim_public')[0].value = request.responseXML.getElementsByTagName('publickey')[0].firstChild.nodeValue;
63+
document.getElementsByName('dns_record')[0].value = request.responseXML.getElementsByTagName('dns_record')[0].firstChild.nodeValue;
6364
}
6465
break;
6566
default:

interface/web/mail/mail_domain_dkim_create.php

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2828
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2929
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
3031

31-
This script is invoked by interface/js/mail_domain_dkim.js
32-
to generate or show the DKIM Private-key and to show the Private-key.
33-
returns DKIM Private-Key and DKIM Public-Key
34-
*/
32+
/**
33+
* This script is invoked by interface/js/mail_domain_dkim.js
34+
* to generate or show the DKIM Private-key and to show the Private-key.
35+
* returns DKIM Private-Key and DKIM Public-Key
36+
*/
3537

3638

3739
require_once '../../lib/config.inc.php';
@@ -46,7 +48,6 @@
4648
header('Content-Type: text/xml; charset=utf-8');
4749
header('Cache-Control: must-revalidate, pre-check=0, no-store, no-cache, max-age=0, post-check=0');
4850

49-
5051
/**
5152
* This function fix PHP's messing up POST input containing characters space, dot,
5253
* open square bracket and others to be compatible with with the deprecated register_globals
@@ -64,7 +65,6 @@ function getRealPOST() {
6465
return $vars;
6566
}
6667

67-
6868
/**
6969
* This function formats the public-key
7070
* @param array $pubkey
@@ -76,32 +76,39 @@ function pub_key($pubkey) {
7676
return $public_key;
7777
}
7878

79+
function get_public_key($private_key) {
80+
require_once('../../lib/classes/validate_dkim.inc.php');
81+
$validate_dkim=new validate_dkim ();
82+
if($validate_dkim->validate_post('private',$private_key)) { /* validate the $_POST-value */
83+
exec('echo '.escapeshellarg($private_key).'|openssl rsa -pubout -outform PEM',$pubkey,$result);
84+
$public_key=pub_key($pubkey);
85+
} else {
86+
$public_key='invalid key';
87+
}
88+
return $public_key;
89+
}
90+
7991
$_POST=getRealPOST();
8092

8193
switch ($_POST['action']) {
82-
case 'create': /* create DKIM Private-key */
83-
exec('openssl rand -out /usr/local/ispconfig/server/temp/random-data.bin 4096', $output, $result);
84-
exec('openssl genrsa -rand /usr/local/ispconfig/server/temp/random-data.bin 1024', $privkey, $result);
85-
unlink("/usr/local/ispconfig/server/temp/random-data.bin");
86-
$private_key='';
87-
foreach($privkey as $values) $private_key=$private_key.$values."\n";
88-
if($validate_dkim->validate_post('private', $private_key)) { /* validate the $_POST-value */
89-
exec('echo '.escapeshellarg($private_key).'|openssl rsa -pubout -outform PEM', $pubkey, $result);
90-
$public_key=pub_key($pubkey);
91-
} else { $public_key='invalid key'; }
94+
case 'create': /* create DKIM Private-key */
95+
exec('openssl rand -out /usr/local/ispconfig/server/temp/random-data.bin 4096', $output, $result);
96+
exec('openssl genrsa -rand /usr/local/ispconfig/server/temp/random-data.bin 1024', $privkey, $result);
97+
unlink("/usr/local/ispconfig/server/temp/random-data.bin");
98+
$private_key='';
9299
break;
93-
case 'show': /* show the DNS-Record onLoad */
94-
$private_key=$_POST['pkey'];
95-
if($validate_dkim->validate_post('private', $private_key)) { /* validate the $_POST-value */
96-
/* get the public-key */
97-
exec('echo '.escapeshellarg($private_key).'|openssl rsa -pubout -outform PEM', $pubkey, $result);
98-
$public_key=pub_key($pubkey);
99-
} else { $public_key='invalid key'; }
100+
101+
case 'show': /* show the DNS-Record onLoad */
102+
$private_key=$_POST['pkey'];
100103
break;
101104
}
105+
106+
$public_key=get_public_key($private_key);
107+
$dns_record=str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$public_key);
102108
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
103109
echo "<formatname>\n";
104110
echo "<privatekey>".$private_key."</privatekey>\n";
105111
echo "<publickey>".$public_key."</publickey>\n";
112+
echo "<dns_record>v=DKIM1; t=s; p=".$dns_record."</dns_record>\n";
106113
echo "</formatname>\n";
107114
?>

interface/web/mail/templates/mail_domain_edit.htm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
9393
</div>
9494
<div class="ctrlHolder">
9595
<textarea name="dkim_public" style="display:none;" id="dkim_public" rows='5' cols='30' readonly>{tmpl_var name='dkim_public'}</textarea>
96-
<!--
97-
<label for="dkim_public">{tmpl_var name='dkim_dns_txt'}</label>
98-
<textarea name="dkim_public" id="dkim_public" rows='5' cols='30' readonly>{tmpl_var name='dkim_public'}</textarea>
99-
-->
96+
</div>
97+
<div class="ctrlHolder">
98+
<label for="dns_record">{tmpl_var name='dkim_dns_txt'}</label>
99+
<textarea name="dns_record" id="dns_record" rows='10' cols='30' readonly>{tmpl_var name='dns_record'}</textarea>
100100
</div>
101101

102102
</div>

interface/web/tools/lib/lang/de_resync.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $wb['resync_shell_txt'] = 'Shell Benutzer';
77
$wb['resync_cron_txt'] = 'Cronjobs';
88
$wb['resync_db_txt'] = 'Datenbanken';
99
$wb['resync_mailbox_txt'] = 'E-Mail Konten';
10+
$wb['resync_dkim_txt'] = 'DKIM-Keys';
1011
$wb['resync_dns_txt'] = 'DNS Einträge';
1112
$wb['btn_start_txt'] = 'Start';
1213
$wb['btn_cancel_txt'] = 'Zurück';

interface/web/tools/lib/lang/en_resync.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ $wb['resync_shell_txt'] = 'Resync shell users';
77
$wb['resync_cron_txt'] = 'Resync cronjobs';
88
$wb['resync_db_txt'] = 'Resync clientdb config';
99
$wb['resync_mailbox_txt'] = 'Resync Mailboxes';
10+
$wb['resync_dkim_txt'] = 'Resync DKIM-Keys';
1011
$wb['resync_dns_txt'] = 'Resync DNS records';
1112
$wb['btn_start_txt'] = 'Start';
1213
$wb['btn_cancel_txt'] = 'Cancel';
13-
?>
14+
?>

interface/web/tools/resync.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@
146146
}
147147
}
148148

149+
//* Resyncing DKIM-Keys
150+
if(isset($_POST['resync_dkim']) && $_POST['resync_dkim'] == 1) {
151+
$db_table = 'mail_domain';
152+
$index_field = 'domain_id';
153+
$sql = "SELECT * FROM ".$db_table." WHERE active = 'y' AND dkim = 'y'";
154+
$records = $app->db->queryAllRecords($sql);
155+
if(is_array($records)) {
156+
foreach($records as $rec) {
157+
$app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
158+
$msg .= "Resynced DKIM-Key: ".$rec['domain'].'<br />';
159+
}
160+
}
161+
}
162+
149163
//* Resyncing dns zones
150164
if(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) {
151165
$zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'");

interface/web/tools/templates/resync.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ <h2><tmpl_var name="head_txt"></h2>
4141
<input id="resync_mailbox" type="checkbox" value="1" name="resync_mailbox" />
4242
</div>
4343
</div>
44+
<div class="ctrlHolder">
45+
<p class="label">{tmpl_var name="resync_dkim_txt"}</p>
46+
<div class="multiField">
47+
<input id="resync_dkim" type="checkbox" value="1" name="resync_dkim" />
48+
</div>
49+
</div>
4450
<div class="ctrlHolder">
4551
<p class="label">{tmpl_var name="resync_dns_txt"}</p>
4652
<div class="multiField">

0 commit comments

Comments
 (0)