|
40 | 40 |
|
41 | 41 | require_once '../../lib/config.inc.php'; |
42 | 42 | require_once '../../lib/app.inc.php'; |
43 | | - |
44 | | -//* Check permissions for module |
45 | | -$app->auth->check_module_permissions('dns'); |
| 43 | +require_once './dns_edit_base.php'; |
46 | 44 |
|
47 | 45 | // Loading classes |
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 | | - |
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 = intval($_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 mailbox. |
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 | | - |
78 | | - // Get the parent soa record of the domain |
79 | | - $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_POST["zone"]); |
80 | | - |
81 | | - // Check if Domain belongs to user |
82 | | - if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"]; |
83 | | - |
84 | | - // Check the client limits, if user is not the admin |
85 | | - if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin |
86 | | - // Get the limits of the client |
87 | | - $client_group_id = intval($_SESSION["s"]["user"]["default_group"]); |
88 | | - $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); |
89 | | - |
90 | | - // Check if the user may add another mailbox. |
91 | | - if($this->id == 0 && $client["limit_dns_record"] >= 0) { |
92 | | - $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id); |
93 | | - if($tmp["number"] >= $client["limit_dns_record"]) { |
94 | | - $app->error($app->tform->wordbook["limit_dns_record_txt"]); |
95 | | - } |
96 | | - } |
97 | | - } // end if user is not admin |
| 46 | +class page_action extends dns_page_action { |
98 | 47 |
|
| 48 | + protected function checkDuplicate() { |
99 | 49 | //* Check for duplicates where IP and hostname are the same |
100 | 50 | $tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE (type = 'A' AND name = ? AND zone = ? and data = ? and id != ?) OR (type = 'CNAME' AND name = ? AND zone = ? and id != ?)", $this->dataRecord["name"], $this->dataRecord["zone"], $this->dataRecord["data"], $this->id, $this->dataRecord["name"], $this->dataRecord["zone"], $this->id); |
101 | | - if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("data_error_duplicate")."<br>"; |
102 | | - unset($tmp); |
103 | | - |
104 | | - |
105 | | - // Set the server ID of the rr record to the same server ID as the parent record. |
106 | | - $this->dataRecord["server_id"] = $soa["server_id"]; |
107 | | - |
108 | | - // Update the serial number and timestamp of the RR record |
109 | | - $soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ?", $this->id); |
110 | | - $this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]); |
111 | | - $this->dataRecord["stamp"] = date('Y-m-d H:i:s'); |
112 | | - |
113 | | - parent::onSubmit(); |
114 | | - } |
115 | | - |
116 | | - function onAfterInsert() { |
117 | | - global $app, $conf; |
118 | | - |
119 | | - //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record |
120 | | - $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]); |
121 | | - $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id); |
122 | | - |
123 | | - //* Update the serial number of the SOA record |
124 | | - $soa_id = $app->functions->intval($_POST["zone"]); |
125 | | - $serial = $app->validate_dns->increase_serial($soa["serial"]); |
126 | | - $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id); |
127 | | - } |
128 | | - |
129 | | - function onAfterUpdate() { |
130 | | - global $app, $conf; |
131 | | - |
132 | | - //* Update the serial number of the SOA record |
133 | | - $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]); |
134 | | - $soa_id = $app->functions->intval($_POST["zone"]); |
135 | | - $serial = $app->validate_dns->increase_serial($soa["serial"]); |
136 | | - $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id); |
| 51 | + if($tmp['number'] > 0) return true; |
| 52 | + return false; |
137 | 53 | } |
138 | | - |
139 | 54 | } |
140 | 55 |
|
141 | 56 | $page = new page_action; |
|
0 commit comments