Skip to content

Commit 596f0b8

Browse files
committed
move code for dns' owner change to plugin
1 parent 6f4f7db commit 596f0b8

File tree

4 files changed

+114
-96
lines changed

4 files changed

+114
-96
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* dns_dns_slave_plugin plugin
4+
*
5+
* @author Sergio Cambra <sergio@programatica.es> 2014
6+
*/
7+
8+
9+
class dns_dns_slave_plugin {
10+
11+
var $plugin_name = 'dns_dns_slave_plugin';
12+
var $class_name = 'dns_dns_slave_plugin';
13+
14+
/*
15+
This function is called when the plugin is loaded
16+
*/
17+
function onLoad() {
18+
global $app;
19+
//Register for the events
20+
$app->plugin->registerEvent('dns:dns_slave:on_after_insert', 'dns_dns_slave_plugin', 'dns_dns_slave_edit');
21+
$app->plugin->registerEvent('dns:dns_slave:on_after_update', 'dns_dns_slave_plugin', 'dns_dns_slave_edit');
22+
}
23+
24+
/*
25+
Function to change dns slave owner
26+
*/
27+
function dns_dns_slave_edit($event_name, $page_form) {
28+
global $app, $conf;
29+
30+
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
31+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
32+
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
33+
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$page_form->id);
34+
}
35+
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
36+
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
37+
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$page_form->id);
38+
}
39+
40+
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
41+
if($page_form->oldDataRecord && $page_form->oldDataRecord["client_group_id"] != $page_form->dataRecord["client_group_id"] && $page_form->dataRecord["sys_userid"] != 1) {
42+
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
43+
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
44+
if($tmp["userid"] > 0) {
45+
$app->db->query("UPDATE dns_slave SET sys_userid = ".$tmp["userid"]." WHERE id = ".$page_form->id);
46+
}
47+
}
48+
}
49+
50+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* dns_dns_soa_plugin plugin
4+
*
5+
* @author Sergio Cambra <sergio@programatica.es> 2014
6+
*/
7+
8+
9+
class dns_dns_soa_plugin {
10+
11+
var $plugin_name = 'dns_dns_soa_plugin';
12+
var $class_name = 'dns_dns_soa_plugin';
13+
14+
/*
15+
This function is called when the plugin is loaded
16+
*/
17+
function onLoad() {
18+
global $app;
19+
//Register for the events
20+
$app->plugin->registerEvent('dns:dns_soa:on_after_insert', 'dns_dns_soa_plugin', 'dns_dns_soa_edit');
21+
$app->plugin->registerEvent('dns:dns_soa:on_after_update', 'dns_dns_soa_plugin', 'dns_dns_soa_edit');
22+
}
23+
24+
/*
25+
Function to change dns soa owner
26+
*/
27+
function dns_dns_soa_edit($event_name, $page_form) {
28+
global $app, $conf;
29+
30+
if ($event_name == 'dns:dns_soa:on_after_update') {
31+
$tmp = $app->db->diffrec($page_form->oldDataRecord, $app->tform->getDataRecord($page_form->id));
32+
if($tmp['diff_num'] > 0) {
33+
// Update the serial number of the SOA record
34+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$page_form->id);
35+
$app->db->query("UPDATE dns_soa SET serial = '".$app->validate_dns->increase_serial($soa["serial"])."' WHERE id = ".$page_form->id);
36+
}
37+
38+
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
39+
if($page_form->oldDataRecord["client_group_id"] != $page_form->dataRecord["client_group_id"] && $page_form->dataRecord["sys_userid"] != 1) {
40+
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
41+
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
42+
if($tmp["userid"] > 0) {
43+
$app->db->query("UPDATE dns_soa SET sys_userid = ".$tmp["userid"]." WHERE id = ".$page_form->id);
44+
$app->db->query("UPDATE dns_rr SET sys_userid = ".$tmp["userid"]." WHERE zone = ".$page_form->id);
45+
}
46+
}
47+
}
48+
49+
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
50+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
51+
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
52+
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$page_form->id);
53+
// And we want to update all rr records too, that belong to this record
54+
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$page_form->id);
55+
}
56+
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
57+
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
58+
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$page_form->id);
59+
// And we want to update all rr records too, that belong to this record
60+
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$page_form->id);
61+
}
62+
}
63+
64+
}

interface/web/dns/dns_slave_edit.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -169,47 +169,6 @@ function onInsert() {
169169
parent::onInsert();
170170
}
171171

172-
function onAfterInsert() {
173-
global $app, $conf;
174-
175-
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
176-
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
177-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
178-
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
179-
}
180-
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
181-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
182-
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
183-
}
184-
185-
}
186-
187-
function onAfterUpdate() {
188-
global $app, $conf;
189-
190-
$tmp = $app->db->diffrec($this->oldDataRecord, $app->tform->getDataRecord($this->id));
191-
192-
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
193-
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
194-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
195-
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
196-
}
197-
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
198-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
199-
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
200-
}
201-
202-
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
203-
if($this->oldDataRecord["client_group_id"] != $this->dataRecord["client_group_id"] && $this->dataRecord["sys_userid"] != 1) {
204-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
205-
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
206-
if($tmp["userid"] > 0) {
207-
$app->db->query("UPDATE dns_slave SET sys_userid = ".$tmp["userid"]." WHERE id = ".$this->id);
208-
}
209-
}
210-
211-
}
212-
213172
}
214173

215174
$page = new page_action;

interface/web/dns/dns_soa_edit.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,6 @@ function onSubmit() {
220220
parent::onSubmit();
221221
}
222222

223-
function onAfterInsert() {
224-
global $app, $conf;
225-
226-
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
227-
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
228-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
229-
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$this->id);
230-
// And we want to update all rr records too, that belong to this record
231-
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
232-
}
233-
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
234-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
235-
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$this->id);
236-
// And we want to update all rr records too, that belong to this record
237-
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
238-
}
239-
240-
}
241-
242223
function onBeforeUpdate () {
243224
global $app, $conf;
244225

@@ -256,42 +237,6 @@ function onBeforeUpdate () {
256237
}
257238
}
258239

259-
function onAfterUpdate() {
260-
global $app, $conf;
261-
262-
$tmp = $app->db->diffrec($this->oldDataRecord, $app->tform->getDataRecord($this->id));
263-
if($tmp['diff_num'] > 0) {
264-
// Update the serial number of the SOA record
265-
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
266-
$app->db->query("UPDATE dns_soa SET serial = '".$app->validate_dns->increase_serial($soa["serial"])."' WHERE id = ".$this->id);
267-
}
268-
269-
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
270-
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
271-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
272-
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$this->id);
273-
// And we want to update all rr records too, that belong to this record
274-
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
275-
}
276-
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
277-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
278-
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$this->id);
279-
// And we want to update all rr records too, that belong to this record
280-
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
281-
}
282-
283-
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
284-
if($this->oldDataRecord["client_group_id"] != $this->dataRecord["client_group_id"] && $this->dataRecord["sys_userid"] != 1) {
285-
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
286-
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
287-
if($tmp["userid"] > 0) {
288-
$app->db->query("UPDATE dns_soa SET sys_userid = ".$tmp["userid"]." WHERE id = ".$this->id);
289-
$app->db->query("UPDATE dns_rr SET sys_userid = ".$tmp["userid"]." WHERE zone = ".$this->id);
290-
}
291-
}
292-
293-
}
294-
295240
}
296241

297242
$page = new page_action;

0 commit comments

Comments
 (0)