Skip to content

Commit 9342934

Browse files
author
Marius Cramer
committed
- added dns edit base class and moved common methods into it to avoid duplicate code
1 parent 3a11d23 commit 9342934

File tree

12 files changed

+159
-971
lines changed

12 files changed

+159
-971
lines changed

interface/web/dns/dns_a_edit.php

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -40,102 +40,17 @@
4040

4141
require_once '../../lib/config.inc.php';
4242
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';
4644

4745
// 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 {
9847

48+
protected function checkDuplicate() {
9949
//* Check for duplicates where IP and hostname are the same
10050
$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;
13753
}
138-
13954
}
14055

14156
$page = new page_action;

interface/web/dns/dns_aaaa_edit.php

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -40,96 +40,10 @@
4040

4141
require_once '../../lib/config.inc.php';
4242
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';
4644

4745
// 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 = $_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
98-
99-
100-
// Set the server ID of the rr record to the same server ID as the parent record.
101-
$this->dataRecord["server_id"] = $soa["server_id"];
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-
parent::onSubmit();
109-
}
110-
111-
function onAfterInsert() {
112-
global $app, $conf;
113-
114-
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
115-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]);
116-
$app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
117-
118-
//* Update the serial number of the SOA record
119-
$soa_id = $app->functions->intval($_POST["zone"]);
120-
$serial = $app->validate_dns->increase_serial($soa["serial"]);
121-
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
122-
}
123-
124-
function onAfterUpdate() {
125-
global $app, $conf;
126-
127-
//* Update the serial number of the SOA record
128-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]);
129-
$soa_id = $app->functions->intval($_POST["zone"]);
130-
$serial = $app->validate_dns->increase_serial($soa["serial"]);
131-
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
132-
}
46+
class page_action extends dns_page_action {
13347

13448
}
13549

interface/web/dns/dns_alias_edit.php

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -40,96 +40,10 @@
4040

4141
require_once '../../lib/config.inc.php';
4242
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';
4644

4745
// 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($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
98-
99-
100-
// Set the server ID of the rr record to the same server ID as the parent record.
101-
$this->dataRecord["server_id"] = $soa["server_id"];
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-
parent::onSubmit();
109-
}
110-
111-
function onAfterInsert() {
112-
global $app, $conf;
113-
114-
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
115-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]);
116-
$app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
117-
118-
//* Update the serial number of the SOA record
119-
$soa_id = $app->functions->intval($_POST["zone"]);
120-
$serial = $app->validate_dns->increase_serial($soa["serial"]);
121-
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
122-
}
123-
124-
function onAfterUpdate() {
125-
global $app, $conf;
126-
127-
//* Update the serial number of the SOA record
128-
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $this->dataRecord["zone"]);
129-
$soa_id = $app->functions->intval($_POST["zone"]);
130-
$serial = $app->validate_dns->increase_serial($soa["serial"]);
131-
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);
132-
}
46+
class page_action extends dns_page_action {
13347

13448
}
13549

0 commit comments

Comments
 (0)