0) { mwexec("/etc/rc.d/inetd restart"); } else { mwexec("/etc/rc.d/inetd stop"); } /* Write config if any file from filesystem was loaded. */ if ($update_conf > 0) { write_config(); } conf_mount_ro(); checkmk_sync_on_changes(); } function checkmk_validate_input($post, &$input_errors) { foreach ($post as $key => $value) { if (empty($value)) { continue; } if (substr($key, 0, 3) == "port" && !preg_match("/^\d+$/", $value)) { $input_errors[] = "{$value} is no a valid port number"; } if (substr($key, 0, 11) == "description" && !preg_match("@^[a-zA-Z0-9 _/.-]+$@", $value)) { $input_errors[] = "Do not use special characters on description"; } if (substr($key, 0, 8) == "fullfile" && !preg_match("@^[a-zA-Z0-9_/.-]+$@", $value)) { $input_errors[] = "Do not use special characters on filename"; } } } /* Uses XMLRPC to synchronize the changes to a remote node. */ function checkmk_sync_on_changes() { global $config, $g; if (is_array($config['installedpackages']['checkmksync']['config'])) { $checkmk_sync = $config['installedpackages']['checkmksync']['config'][0]; $synconchanges = $checkmk_sync['synconchanges']; $synctimeout = $checkmk_sync['synctimeout']; switch ($synconchanges) { case "manual": if (is_array($checkmk_sync[row])) { $rs = $checkmksync[row]; } else { log_error("[check_mk-agent] XMLRPC sync is enabled but there is no hosts to push on squid 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("[check_mk-agent] XMLRPC sync is enabled but there is no system backup hosts to push squid config."); return; } break; default: return; break; } if (is_array($rs)) { log_error("[check_mk-agent] 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) { checkmk_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout); } log_error("[check_mk-agent] XMLRPC sync is ending."); } } } } /* Do the actual XMLRPC sync. */ function checkmk_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout) { global $config, $g; if (!$username) { return; } if (!$password) { return; } if (!$sync_to_ip) { return; } $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, let's 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['checkmk'] = $config['installedpackages']['checkmk']; /* 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("[check_mk-agent] Beginning checkmk 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 250 seconds. */ $resp = $cli->send($msg, $synctimeout); if (!$resp) { $error = "[check_mk-agent] A communications error occurred while attempting checkmk XMLRPC sync with {$url}:{$port}."; log_error($error); file_notice("sync_settings", $error, "checkmk Settings Sync", ""); } elseif ($resp->faultCode()) { $cli->setDebug(1); $resp = $cli->send($msg, $synctimeout); $error = "[check_mk-agent] An error code was received while attempting checkmk XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); log_error($error); file_notice("sync_settings", $error, "checkmk Settings Sync", ""); } else { log_error("[check_mk-agent] XMLRPC sync successfully completed with {$url}:{$port}."); } /* Tell check_mk to reload our settings on the destination sync host. */ $method = 'pfsense.exec_php'; $execcmd = "require_once('/usr/local/pkg/checkmk.inc');\n"; $execcmd .= "sync_package_checkmk();"; /* Assemble XMLRPC payload. */ $params = array( XML_RPC_encode($password), XML_RPC_encode($execcmd) ); log_error("[check_mk-agent] 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 = "[check_mk-agent] A communications error occurred while attempting checkmk XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; log_error($error); file_notice("sync_settings", $error, "checkmk Settings Sync", ""); } elseif ($resp->faultCode()) { $cli->setDebug(1); $resp = $cli->send($msg, $synctimeout); $error = "[check_mk-agent] An error code was received while attempting checkmk XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); log_error($error); file_notice("sync_settings", $error, "checkmk Settings Sync", ""); } else { log_error("[check_mk-agent] XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php)."); } } ?>