commit | author | age
|
596f0b
|
1 |
<?php |
SC |
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 |
cc7a82
|
34 |
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ?", $page_form->id); |
MC |
35 |
$app->db->query("UPDATE dns_soa SET serial = ? WHERE id = ?", $app->validate_dns->increase_serial($soa["serial"]), $page_form->id); |
596f0b
|
36 |
} |
SC |
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"]); |
cc7a82
|
41 |
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id); |
596f0b
|
42 |
if($tmp["userid"] > 0) { |
cc7a82
|
43 |
$app->db->query("UPDATE dns_soa SET sys_userid = ? WHERE id = ?", $tmp["userid"], $page_form->id); |
MC |
44 |
$app->db->query("UPDATE dns_rr SET sys_userid = ? WHERE zone = ?", $tmp["userid"], $page_form->id); |
596f0b
|
45 |
} |
SC |
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"]); |
cc7a82
|
52 |
$app->db->query("UPDATE dns_soa SET sys_groupid = ?, sys_perm_group = 'ru' WHERE id = ?", $client_group_id, $page_form->id); |
596f0b
|
53 |
// And we want to update all rr records too, that belong to this record |
cc7a82
|
54 |
$app->db->query("UPDATE dns_rr SET sys_groupid = ? WHERE zone = ?", $client_group_id, $page_form->id); |
596f0b
|
55 |
} |
SC |
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"]); |
cc7a82
|
58 |
$app->db->query("UPDATE dns_soa SET sys_groupid = ?, sys_perm_group = 'riud' WHERE id = ?", $client_group_id, $page_form->id); |
596f0b
|
59 |
// And we want to update all rr records too, that belong to this record |
cc7a82
|
60 |
$app->db->query("UPDATE dns_rr SET sys_groupid = ? WHERE zone = ?", $client_group_id, $page_form->id); |
596f0b
|
61 |
} |
SC |
62 |
} |
|
63 |
|
|
64 |
} |