commit | author | age
|
c13535
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2009, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class dns_module { |
b1a6a5
|
32 |
|
c13535
|
33 |
var $module_name = 'dns_module'; |
T |
34 |
var $class_name = 'dns_module'; |
b1a6a5
|
35 |
var $actions_available = array( 'dns_soa_insert', |
MC |
36 |
'dns_soa_update', |
|
37 |
'dns_soa_delete', |
|
38 |
'dns_slave_insert', |
|
39 |
'dns_slave_update', |
|
40 |
'dns_slave_delete', |
|
41 |
'dns_rr_insert', |
|
42 |
'dns_rr_update', |
|
43 |
'dns_rr_delete'); |
|
44 |
|
c13535
|
45 |
//* This function is called during ispconfig installation to determine |
T |
46 |
// if a symlink shall be created for this plugin. |
|
47 |
function onInstall() { |
|
48 |
global $conf; |
b1a6a5
|
49 |
|
80e3c9
|
50 |
if($conf['services']['dns'] == true) { |
T |
51 |
return true; |
|
52 |
} else { |
|
53 |
return false; |
|
54 |
} |
b1a6a5
|
55 |
|
c13535
|
56 |
} |
b1a6a5
|
57 |
|
c13535
|
58 |
/* |
T |
59 |
This function is called when the module is loaded |
|
60 |
*/ |
b1a6a5
|
61 |
|
c13535
|
62 |
function onLoad() { |
T |
63 |
global $app; |
b1a6a5
|
64 |
|
c13535
|
65 |
/* |
b1a6a5
|
66 |
Annonce the actions that where provided by this module, so plugins |
c13535
|
67 |
can register on them. |
T |
68 |
*/ |
b1a6a5
|
69 |
|
MC |
70 |
$app->plugins->announceEvents($this->module_name, $this->actions_available); |
|
71 |
|
c13535
|
72 |
/* |
T |
73 |
As we want to get notified of any changes on several database tables, |
|
74 |
we register for them. |
b1a6a5
|
75 |
|
c13535
|
76 |
The following function registers the function "functionname" |
b1a6a5
|
77 |
to be executed when a record for the table "dbtable" is |
c13535
|
78 |
processed in the sys_datalog. "classname" is the name of the |
T |
79 |
class that contains the function functionname. |
|
80 |
*/ |
b1a6a5
|
81 |
|
MC |
82 |
$app->modules->registerTableHook('dns_soa', $this->module_name, 'process'); |
|
83 |
$app->modules->registerTableHook('dns_slave', $this->module_name, 'process'); |
|
84 |
$app->modules->registerTableHook('dns_rr', $this->module_name, 'process'); |
|
85 |
|
|
86 |
|
7dbea0
|
87 |
// Register service |
b1a6a5
|
88 |
$app->services->registerService('bind', 'dns_module', 'restartBind'); |
MC |
89 |
$app->services->registerService('powerdns', 'dns_module', 'restartPowerDNS'); |
|
90 |
|
c13535
|
91 |
} |
b1a6a5
|
92 |
|
c13535
|
93 |
/* |
T |
94 |
This function is called when a change in one of the registered tables is detected. |
|
95 |
The function then raises the events for the plugins. |
|
96 |
*/ |
|
97 |
|
b1a6a5
|
98 |
function process($tablename, $action, $data) { |
c13535
|
99 |
global $app; |
b1a6a5
|
100 |
|
c13535
|
101 |
switch ($tablename) { |
b1a6a5
|
102 |
case 'dns_soa': |
MC |
103 |
if($action == 'i') $app->plugins->raiseEvent('dns_soa_insert', $data); |
|
104 |
if($action == 'u') $app->plugins->raiseEvent('dns_soa_update', $data); |
|
105 |
if($action == 'd') $app->plugins->raiseEvent('dns_soa_delete', $data); |
a59731
|
106 |
break; |
b1a6a5
|
107 |
case 'dns_slave': |
MC |
108 |
if($action == 'i') $app->plugins->raiseEvent('dns_slave_insert', $data); |
|
109 |
if($action == 'u') $app->plugins->raiseEvent('dns_slave_update', $data); |
|
110 |
if($action == 'd') $app->plugins->raiseEvent('dns_slave_delete', $data); |
c13535
|
111 |
break; |
b1a6a5
|
112 |
case 'dns_rr': |
MC |
113 |
if($action == 'i') $app->plugins->raiseEvent('dns_rr_insert', $data); |
|
114 |
if($action == 'u') $app->plugins->raiseEvent('dns_rr_update', $data); |
|
115 |
if($action == 'd') $app->plugins->raiseEvent('dns_rr_delete', $data); |
c13535
|
116 |
break; |
T |
117 |
} // end switch |
|
118 |
} // end function |
b1a6a5
|
119 |
|
MC |
120 |
|
7dbea0
|
121 |
function restartBind($action = 'restart') { |
b1a6a5
|
122 |
global $app, $conf; |
MC |
123 |
|
33bcd0
|
124 |
$app->uses('system'); |
b1a6a5
|
125 |
|
47f5e0
|
126 |
$daemon = ''; |
J |
127 |
if(is_file($conf['init_scripts'] . '/' . 'bind9')) { |
|
128 |
$daemon = 'bind9'; |
7dbea0
|
129 |
} else { |
47f5e0
|
130 |
$daemon = 'named'; |
7dbea0
|
131 |
} |
b1a6a5
|
132 |
|
615a0a
|
133 |
$retval = array('output' => '', 'retval' => 0); |
7dbea0
|
134 |
if($action == 'restart') { |
33bcd0
|
135 |
exec($app->system->getinitcommand($daemon, 'restart').' 2>&1', $retval['output'], $retval['retval']); |
7dbea0
|
136 |
} else { |
33bcd0
|
137 |
exec($app->system->getinitcommand($daemon, 'reload').' 2>&1', $retval['output'], $retval['retval']); |
7dbea0
|
138 |
} |
615a0a
|
139 |
return $retval; |
7dbea0
|
140 |
} |
a59731
|
141 |
|
D |
142 |
function restartPowerDNS($action = 'restart') { |
b1a6a5
|
143 |
global $app, $conf; |
a59731
|
144 |
|
b1a6a5
|
145 |
$app->uses('system'); |
MC |
146 |
$app->log("restartPDNS called.", LOGLEVEL_DEBUG); |
|
147 |
|
|
148 |
/** Since PowerDNS does not currently allow to limit AXFR for specific zones to specific |
|
149 |
* IP addresses, we create a list of IPs allowed of AXFR transfers from our PowerDNS, |
|
150 |
* however any of these IPs is allowed to AXFR transfer any of the zones we are masters |
|
151 |
* for. |
|
152 |
*/ |
|
153 |
|
|
154 |
|
|
155 |
$tmps = $app->db->queryAllRecords("SELECT DISTINCT xfer FROM dns_soa WHERE active = 'Y' UNION SELECT DISTINCT xfer FROM dns_slave WHERE active = 'Y' "); |
a59731
|
156 |
|
D |
157 |
//* Make sure the list is never empty |
b1a6a5
|
158 |
$options='127.0.0.1'; |
MC |
159 |
foreach($tmps as $tmp) { |
|
160 |
if (trim($tmp['xfer'])!='') { |
|
161 |
if ($options=='') { |
a59731
|
162 |
$options.=$tmp['xfer']; |
b1a6a5
|
163 |
} else { |
MC |
164 |
$options=$options.",".$tmp['xfer']; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
a59731
|
168 |
|
D |
169 |
//* Remove duplicate IPs from the array |
b1a6a5
|
170 |
$options = "allow-axfr-ips=".implode(",", array_unique(explode(",", $options))); |
MC |
171 |
$app->log("".$options, LOGLEVEL_DEBUG); |
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
/** Not an ideal way to use a hardcoded path like that, but currently |
|
176 |
* we have no way to find out where powerdns' configuration files are |
|
177 |
* located, so we have to work on assumption. |
|
178 |
*/ |
|
179 |
file_put_contents('/etc/powerdns/pdns.d/pdns.ispconfig-axfr', $options."\n"); |
a59731
|
180 |
|
efb7dc
|
181 |
$daemon= ''; |
47f5e0
|
182 |
if (is_file($conf['init_scripts'] . '/' . 'powerdns')) { |
J |
183 |
$daemon = 'powerdns'; |
a59731
|
184 |
} else { |
47f5e0
|
185 |
$daemon = 'pdns'; |
a59731
|
186 |
} |
D |
187 |
|
615a0a
|
188 |
$retval = array('output' => '', 'retval' => 0); |
33bcd0
|
189 |
exec($app->system->getinitcommand($daemon, 'restart').' 2>&1', $retval['output'], $retval['retval']); |
a59731
|
190 |
|
b1a6a5
|
191 |
// unset $tmps; |
615a0a
|
192 |
return $retval; |
a59731
|
193 |
|
D |
194 |
} |
b1a6a5
|
195 |
|
c13535
|
196 |
|
T |
197 |
} // end class |
|
198 |
|
a59731
|
199 |
?> |