@@ -83,8 +83,10 @@ function soa_insert($event_name,$data) {
8383 function soa_update ($ event_name ,$ data ) {
8484 global $ app , $ conf ;
8585
86+ //* Load libraries
87+ $ app ->uses ("getconf,tpl " );
88+
8689 //* load the server configuration options
87- $ app ->uses ("getconf " );
8890 $ dns_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'dns ' );
8991
9092 //* Write the domain file
@@ -94,24 +96,25 @@ function soa_update($event_name,$data) {
9496 $ zone = $ data ['new ' ];
9597 $ tpl ->setVar ($ zone );
9698
97- $ records = $ app ->db ->queryAllRecords ("SELECT * FROM dns_rr WHERE zone = " .$ zone ['id ' ]);
98- $ tpl ->setLoop ('records ' ,$ records );
99+ $ records = $ app ->db ->queryAllRecords ("SELECT * FROM dns_rr WHERE zone = " .$ zone ['id ' ]. " AND active = 'Y' " );
100+ $ tpl ->setLoop ('zones ' ,$ records );
99101
100- $ filename = escapeshellcmd ($ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .$ zone ['origin ' ]);
102+ $ filename = escapeshellcmd ($ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .substr ($ zone ['origin ' ],0 ,-1 ));
103+ $ app ->log ("Writing BIND domain file: " .$ filename ,LOGLEVEL_DEBUG );
101104 file_put_contents ($ filename ,$ tpl ->grab ());
102105 exec ('chown ' .escapeshellcmd ($ dns_config ['bind_user ' ]).': ' .escapeshellcmd ($ dns_config ['bind_group ' ]).' ' .$ filename );
103106 unset($ tpl );
104107 unset($ records );
105108 unset($ zone );
106109
107110 //* rebuild the named.conf file if the origin has changed or when the origin is inserted.
108- if ($ this ->action == 'insert ' || $ data ['old ' ]['origin ' ] != $ data ['new ' ]['origin ' ]) {
111+ // if($this->action == 'insert' || $data['old']['origin'] != $data['new']['origin']) {
109112 $ this ->write_named_conf ($ data ,$ dns_config );
110- }
113+ // }
111114
112115 //* Delete old domain file, if domain name has been changed
113116 if ($ data ['old ' ]['origin ' ] != $ data ['new ' ]['origin ' ]) {
114- $ filename = $ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .$ data ['old ' ]['origin ' ];
117+ $ filename = $ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .substr ( $ data ['old ' ]['origin ' ], 0 ,- 1 ) ;
115118 if (is_file ($ filename )) unset($ filename );
116119 }
117120
@@ -133,6 +136,7 @@ function soa_delete($event_name,$data) {
133136 //* Delete the domain file
134137 $ filename = $ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .$ data ['old ' ]['origin ' ];
135138 if (is_file ($ filename )) unset($ filename );
139+ $ app ->log ("Deleting BIND domain file: " .$ filename ,LOGLEVEL_DEBUG );
136140
137141 //* Reload bind nameserver
138142 $ app ->services ->restartServiceDelayed ('bind ' ,'reload ' );
@@ -180,14 +184,24 @@ function rr_delete($event_name,$data) {
180184 function write_named_conf ($ data , $ dns_config ) {
181185 global $ app , $ conf ;
182186
183- $ zones = $ app ->db ->queryAllRecords ("SELECT origin FROM dns_soa WHERE active = 'Y' " );
187+ $ tmps = $ app ->db ->queryAllRecords ("SELECT origin FROM dns_soa WHERE active = 'Y' " );
188+ $ zones = array ();
189+ foreach ($ tmps as $ tmp ) {
190+ $ zones [] = array ( 'zone ' => substr ($ tmp ['origin ' ],0 ,-1 ),
191+ 'zonefile_path ' => $ dns_config ['bind_zonefiles_dir ' ].'/pri. ' .substr ($ tmp ['origin ' ],0 ,-1 )
192+ );
193+ }
184194
185195 $ tpl = new tpl ();
186196 $ tpl ->newTemplate ("bind_named.conf.local.master " );
187197 $ tpl ->setLoop ('zones ' ,$ zones );
188198
189199 file_put_contents ($ dns_config ['named_conf_local_path ' ],$ tpl ->grab ());
200+ $ app ->log ("Writing BIND named.conf.local file: " .$ dns_config ['named_conf_local_path ' ],LOGLEVEL_DEBUG );
201+
190202 unset($ tpl );
203+ unset($ zones );
204+ unset($ tmps );
191205
192206 }
193207
0 commit comments