@@ -113,7 +113,7 @@ public function get_ispconfig_url() {
113113 return $ url ;
114114 }
115115
116- function json_encode ($ data ) {
116+ public function json_encode ($ data ) {
117117 if (!function_exists ('json_encode ' )){
118118 if (is_array ($ data ) || is_object ($ data )){
119119 $ islist = is_array ($ data ) && (empty ($ data ) || array_keys ($ data ) === range (0 ,count ($ data )-1 ));
@@ -177,6 +177,105 @@ function json_encode($data) {
177177 return json_encode ($ data );
178178 }
179179 }
180+
181+ public function suggest_ips ($ type = 'IPv4 ' ){
182+ global $ app ;
183+
184+ if ($ type == 'IPv4 ' ){
185+ $ regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/ " ;
186+ } else {
187+ // IPv6
188+ $ regex = "/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i " ;
189+ }
190+
191+ $ ips = array ();
192+ $ results = $ app ->db ->queryAllRecords ("SELECT ip_address AS ip FROM server_ip WHERE ip_type = ' " .$ type ."' " );
193+ if (!empty ($ results ) && is_array ($ results )){
194+ foreach ($ results as $ result ){
195+ if (preg_match ($ regex , $ result ['ip ' ])) $ ips [] = $ result ['ip ' ];
196+ }
197+ }
198+ $ results = $ app ->db ->queryAllRecords ("SELECT ip_address AS ip FROM openvz_ip " );
199+ if (!empty ($ results ) && is_array ($ results )){
200+ foreach ($ results as $ result ){
201+ if (preg_match ($ regex , $ result ['ip ' ])) $ ips [] = $ result ['ip ' ];
202+ }
203+ }
204+ $ results = $ app ->db ->queryAllRecords ("SELECT data AS ip FROM dns_rr WHERE type = 'A' OR type = 'AAAA' " );
205+ if (!empty ($ results ) && is_array ($ results )){
206+ foreach ($ results as $ result ){
207+ if (preg_match ($ regex , $ result ['ip ' ])) $ ips [] = $ result ['ip ' ];
208+ }
209+ }
210+ $ results = $ app ->db ->queryAllRecords ("SELECT ns AS ip FROM dns_slave " );
211+ if (!empty ($ results ) && is_array ($ results )){
212+ foreach ($ results as $ result ){
213+ if (preg_match ($ regex , $ result ['ip ' ])) $ ips [] = $ result ['ip ' ];
214+ }
215+ }
216+
217+ $ results = $ app ->db ->queryAllRecords ("SELECT xfer FROM dns_slave WHERE xfer != '' " );
218+ if (!empty ($ results ) && is_array ($ results )){
219+ foreach ($ results as $ result ){
220+ $ tmp_ips = explode (', ' , $ result ['xfer ' ]);
221+ foreach ($ tmp_ips as $ tmp_ip ){
222+ $ tmp_ip = trim ($ tmp_ip );
223+ if (preg_match ($ regex , $ tmp_ip )) $ ips [] = $ tmp_ip ;
224+ }
225+ }
226+ }
227+ $ results = $ app ->db ->queryAllRecords ("SELECT xfer FROM dns_soa WHERE xfer != '' " );
228+ if (!empty ($ results ) && is_array ($ results )){
229+ foreach ($ results as $ result ){
230+ $ tmp_ips = explode (', ' , $ result ['xfer ' ]);
231+ foreach ($ tmp_ips as $ tmp_ip ){
232+ $ tmp_ip = trim ($ tmp_ip );
233+ if (preg_match ($ regex , $ tmp_ip )) $ ips [] = $ tmp_ip ;
234+ }
235+ }
236+ }
237+ $ results = $ app ->db ->queryAllRecords ("SELECT also_notify FROM dns_soa WHERE also_notify != '' " );
238+ if (!empty ($ results ) && is_array ($ results )){
239+ foreach ($ results as $ result ){
240+ $ tmp_ips = explode (', ' , $ result ['also_notify ' ]);
241+ foreach ($ tmp_ips as $ tmp_ip ){
242+ $ tmp_ip = trim ($ tmp_ip );
243+ if (preg_match ($ regex , $ tmp_ip )) $ ips [] = $ tmp_ip ;
244+ }
245+ }
246+ }
247+ $ results = $ app ->db ->queryAllRecords ("SELECT remote_ips FROM web_database WHERE remote_ips != '' " );
248+ if (!empty ($ results ) && is_array ($ results )){
249+ foreach ($ results as $ result ){
250+ $ tmp_ips = explode (', ' , $ result ['remote_ips ' ]);
251+ foreach ($ tmp_ips as $ tmp_ip ){
252+ $ tmp_ip = trim ($ tmp_ip );
253+ if (preg_match ($ regex , $ tmp_ip )) $ ips [] = $ tmp_ip ;
254+ }
255+ }
256+ }
257+ $ ips = array_unique ($ ips );
258+ sort ($ ips , SORT_NUMERIC );
259+
260+ $ result_array = array ('cheader ' => array (), 'cdata ' => array ());
261+
262+ if (!empty ($ ips )){
263+ $ result_array ['cheader ' ] = array ('title ' => 'IPs ' ,
264+ 'total ' => count ($ ips ),
265+ 'limit ' => count ($ ips )
266+ );
267+
268+ foreach ($ ips as $ ip ){
269+ $ result_array ['cdata ' ][] = array ( 'title ' => $ ip ,
270+ 'description ' => $ type ,
271+ 'onclick ' => '' ,
272+ 'fill_text ' => $ ip
273+ );
274+ }
275+ }
276+
277+ return $ result_array ;
278+ }
180279
181280
182281
0 commit comments