$bind_listenonv6 $bind_listenon"; if (key_exists("ipv6allow",$config['system'])){ $bind_conf .="\t\tlisten-on-v6 { $bind_listenonv6 };\n"; } $bind_conf .="\t\tlisten-on { $bind_listenon };\n"; #forwarder config if ($bind_forwarder == on) $bind_conf .="\t\tforwarders { $forwader_ips };\n"; if ($bind_notify == on) $bind_conf .="\t\tnotify yes;\n"; if ($hide_version == on) $bind_conf .="\t\tversion \"N/A\";\n"; $bind_conf .="\t\t$custom_options\n"; $bind_conf .= "\t};\n\n"; if ($bind_logging == on){ $bind_conf .= << on_type_zone_changed()\n"); } # Carregar o campo com os dados da views # ----------------------------------------------------------------------------- function get_bind_conf_items_list($data_group, $fieldname) { global $config; $res = ''; if (is_array($config["installedpackages"][$data_group])){ $conf = $config["installedpackages"][$data_group]["config"]; if (is_array($conf)) foreach($conf as $cf) $res[] = $cf[$fieldname]; } return $res; } # Carregar o campo com os dados da views # ----------------------------------------------------------------------------- function bind_views_before_form_dest($pkg,$data_group,$fieldname,$dest) { $destination_items = get_bind_conf_items_list($data_group,$fieldname); $i=0; if (is_array($pkg['fields']['field'])) foreach($pkg['fields']['field'] as $field) { # if ($field['fieldname'] == $dest) { $fld = &$pkg['fields']['field'][$i]; if (is_array($destination_items)) foreach($destination_items as $nmkey => $nm) $fld['options']['option'][] = array('name'=>ucfirst(strtolower($nm)), 'value'=>strtolower($nm)); } $i++; } } # Analizador do serial da zona de dns # ----------------------------------------------------------------------------- function get_bind_conf_serial($data_group, $fieldname) { global $config; $res = ''; if (is_array($config["installedpackages"][$data_group])){ $conf = $config["installedpackages"][$data_group]["config"]; if (is_array($conf)) foreach($conf as $cf) $res[] = $cf[$fieldname]; } return $res; } # Carregar o campo com os dados da views # ----------------------------------------------------------------------------- function bind_zona_before_form_dest($pkg,$data_group,$fieldname,$dest) { $destination_items = get_bind_conf_serial($data_group,$fieldname); $i=0; if (is_array($pkg['fields']['field'])) foreach($pkg['fields']['field'] as $field) { # if ($field['fieldname'] == $dest) { $fld = &$pkg['fields']['field'][$i]; $fld['default_value'] = date("Y")."000000"; #$fld['value'] = date("Ymdhms")."boa"; } $i++; } } function bind_write_rcfile() { $rc = array(); $BIND_LOCALBASE = "/usr/local"; $rc['file'] = 'named.sh'; $rc['start'] = <</dev/null sleep 2 EOD; $rc['restart'] = <</dev/null sleep 3 $BIND_LOCALBASE}/sbin/named -c /etc/namedb/named.conf -u bind fi EOD; conf_mount_rw(); write_rcfile($rc); conf_mount_ro(); } function create_log_file(){ mwexec("touch /var/log/named.log"); mwexec("chown bind:bind /var/log/named.log"); mwexec("chmod 755 /var/log/named.log"); } function delete_log_file(){ mwexec("rm /var/log/named.log"); } /* Uses XMLRPC to synchronize the changes to a remote node */ function bind_sync_on_changes() { global $config, $g; if (is_array($config['installedpackages']['bind']['config'])){ $bind_sync=$config['installedpackages']['bind']['config'][0]; $synconchanges = $bind_sync['synconchanges']; $synctimeout = $bind_sync['synctimeout']; switch ($synconchanges){ case "manual": if (is_array($bind_sync[row])){ $rs=$bind_sync[row]; } else{ log_error("[bind] xmlrpc sync is enabled but there is no hosts to push on bind config."); return; } break; case "auto": if (is_array($config['installedpackages']['carpsettings']) && is_array($config['installedpackages']['carpsettings']['config'])){ $system_carp=$config['installedpackages']['carpsettings']['config'][0]; $rs[0]['ipaddress']=$system_carp['synchronizetoip']; $rs[0]['username']=$system_carp['username']; $rs[0]['password']=$system_carp['password']; } else{ log_error("[bind] xmlrpc sync is enabled but there is no system backup hosts to push bind config."); return; } break; default: return; break; } if (is_array($rs)){ log_error("[bind] xmlrpc sync is starting."); foreach($rs as $sh){ $sync_to_ip = $sh['ipaddress']; $password = $sh['password']; if($sh['username']) $username = $sh['username']; else $username = 'admin'; if($password && $sync_to_ip) bind_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout); } log_error("[bind] xmlrpc sync is ending."); } } } /* Do the actual XMLRPC sync */ function bind_do_xmlrpc_sync($sync_to_ip, $username, $password, $synctimeout) { global $config, $g; if(!$username) return; if(!$password) return; if(!$sync_to_ip) return; if(!$synctimeout) $synctimeout=25; $xmlrpc_sync_neighbor = $sync_to_ip; if($config['system']['webgui']['protocol'] != "") { $synchronizetoip = $config['system']['webgui']['protocol']; $synchronizetoip .= "://"; } $port = $config['system']['webgui']['port']; /* if port is empty lets rely on the protocol selection */ if($port == "") { if($config['system']['webgui']['protocol'] == "http") $port = "80"; else $port = "443"; } $synchronizetoip .= $sync_to_ip; /* xml will hold the sections to sync */ $xml = array(); $xml['bind'] = $config['installedpackages']['bind']; $xml['bindacls'] = $config['installedpackages']['bindacls']; $xml['bindviews'] = $config['installedpackages']['bindviews']; $xml['bindzone'] = $config['installedpackages']['bindzone']; /* assemble xmlrpc payload */ $params = array( XML_RPC_encode($password), XML_RPC_encode($xml) ); /* set a few variables needed for sync code borrowed from filter.inc */ $url = $synchronizetoip; log_error("[bind] Beginning bind XMLRPC sync to {$url}:{$port}."); $method = 'pfsense.merge_installedpackages_section_xmlrpc'; $msg = new XML_RPC_Message($method, $params); $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port); $cli->setCredentials($username, $password); if($g['debug']) $cli->setDebug(1); /* send our XMLRPC message and timeout after defined sync timeout value*/ $resp = $cli->send($msg, $synctimeout); if(!$resp) { $error = "A communications error occurred while attempting bind XMLRPC sync with {$url}:{$port}."; log_error($error); file_notice("sync_settings", $error, "bind Settings Sync", ""); } elseif($resp->faultCode()) { $cli->setDebug(1); $resp = $cli->send($msg, $synctimeout); $error = "An error code was received while attempting bind XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); log_error($error); file_notice("sync_settings", $error, "bind Settings Sync", ""); } else { log_error("[bind] XMLRPC sync successfully completed with {$url}:{$port}."); } /* tell bind to reload our settings on the destination sync host. */ $method = 'pfsense.exec_php'; $execcmd = "require_once('/usr/local/pkg/bind.inc');\n"; $execcmd .= "bind_sync('yes');"; /* assemble xmlrpc payload */ $params = array( XML_RPC_encode($password), XML_RPC_encode($execcmd) ); log_error("[bind] XMLRPC reload data {$url}:{$port}."); $msg = new XML_RPC_Message($method, $params); $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port); $cli->setCredentials($username, $password); $resp = $cli->send($msg, $synctimeout); if(!$resp) { $error = "A communications error occurred while attempting bind XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; log_error($error); file_notice("sync_settings", $error, "Bind Settings Sync", ""); } elseif($resp->faultCode()) { $cli->setDebug(1); $resp = $cli->send($msg, $synctimeout); $error = "[Bind] An error code was received while attempting bind XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); log_error($error); file_notice("sync_settings", $error, "bind Settings Sync", ""); } else { log_error("Bind XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php)."); } } ?>