|
| 1 | +<?php |
| 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 | + |
| 42 | +require_once('../../lib/config.inc.php'); |
| 43 | +require_once('../../lib/app.inc.php'); |
| 44 | + |
| 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 { |
| 53 | + |
| 54 | + function onShowNew() { |
| 55 | + global $app, $conf; |
| 56 | + // we will check only users, not admins |
| 57 | + if($_SESSION["s"]["user"]["typ"] == 'user') { |
| 58 | + |
| 59 | + // Get the limits of the client |
| 60 | + $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| 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"); |
| 62 | + |
| 63 | + // Check if the user may add another record. |
| 64 | + if($client["limit_dns_record"] >= 0) { |
| 65 | + $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id"); |
| 66 | + if($tmp["number"] >= $client["limit_dns_record"]) { |
| 67 | + $app->error($app->tform->wordbook["limit_dns_record_txt"]); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + parent::onShowNew(); |
| 73 | + } |
| 74 | + |
| 75 | + function onSubmit() { |
| 76 | + global $app, $conf; |
| 77 | + // Get the parent soa record of the domain |
| 78 | + $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".$app->functions->intval($_POST["zone"])."' AND ".$app->tform->getAuthSQL('r')); |
| 79 | + // Check if Domain belongs to user |
| 80 | + if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"]; |
| 81 | + |
| 82 | + // Check the client limits, if user is not the admin |
| 83 | + if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin |
| 84 | + // Get the limits of the client |
| 85 | + $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| 86 | + $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"); |
| 87 | + // Check if the user may add another record. |
| 88 | + if($this->id == 0 && $client["limit_dns_record"] >= 0) { |
| 89 | + $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id"); |
| 90 | + if($tmp["number"] >= $client["limit_dns_record"]) { |
| 91 | + $app->error($app->tform->wordbook["limit_dns_record_txt"]); |
| 92 | + } |
| 93 | + } |
| 94 | + } // end if user is not admin |
| 95 | + |
| 96 | + // Set the server ID of the rr record to the same server ID as the parent record. |
| 97 | + $this->dataRecord["server_id"] = $soa["server_id"]; |
| 98 | + |
| 99 | + // add dkim-settings to the public-key in the txt-record |
| 100 | + $this->dataRecord['data']='v=DKIM1; t=s; p='.$this->dataRecord['data']; |
| 101 | + $this->dataRecord['name']='default._domainkey.'.$this->dataRecord['name']; |
| 102 | + |
| 103 | + // Update the serial number and timestamp of the RR record |
| 104 | + $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id); |
| 105 | + $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]); |
| 106 | + $this->dataRecord["stamp"] = date('Y-m-d H:i:s'); |
| 107 | + |
| 108 | + // check for duplicate entry |
| 109 | + $check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ".$this->dataRecord["zone"]." AND type = '".$this->dataRecord["type"]."' AND data ='".$this->dataRecord["data"]."' AND name = '".$this->dataRecord['name']."'"); |
| 110 | + if ($check!='') $app->tform->errorMessage .= $app->tform->wordbook["record_exists_txt"]; |
| 111 | + |
| 112 | + parent::onSubmit(); |
| 113 | + } |
| 114 | + |
| 115 | + function onAfterInsert() { |
| 116 | + global $app, $conf; |
| 117 | + |
| 118 | + //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record |
| 119 | + $soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r')); |
| 120 | + $app->db->datalogUpdate('dns_rr', "sys_groupid = ".$soa['sys_groupid'], 'id', $this->id); |
| 121 | + |
| 122 | + //* Update the serial number of the SOA record |
| 123 | + $soa_id = $app->functions->intval($_POST["zone"]); |
| 124 | + $serial = $app->validate_dns->increase_serial($soa["serial"]); |
| 125 | + $app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id); |
| 126 | + } |
| 127 | + |
| 128 | + function onAfterUpdate() { |
| 129 | + global $app, $conf; |
| 130 | + |
| 131 | + //* Update the serial number of the SOA record |
| 132 | + $soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r')); |
| 133 | + $soa_id = $app->functions->intval($_POST["zone"]); |
| 134 | + $serial = $app->validate_dns->increase_serial($soa["serial"]); |
| 135 | + $app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id); |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +$page = new page_action; |
| 140 | +$page->onLoad(); |
| 141 | + |
| 142 | +?> |
0 commit comments