From 4e5f4398d932289721a588901e1bb9533166de4c Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 3 Aug 2015 21:56:47 +0200 Subject: checkmk- code style fixes, fix URL again to use last working stable release --- config/checkmk-agent/checkmk.inc | 378 ++++++++++++++++++++------------------- 1 file changed, 195 insertions(+), 183 deletions(-) (limited to 'config') diff --git a/config/checkmk-agent/checkmk.inc b/config/checkmk-agent/checkmk.inc index def0ae2d..67d82e6b 100644 --- a/config/checkmk-agent/checkmk.inc +++ b/config/checkmk-agent/checkmk.inc @@ -1,302 +1,314 @@ 0) + } + if ($mk_config['checkmkenable']=="on") { + $mk_rc_conf_file .= 'inetd_enable="YES"' . "\n"; + $mk_rc_conf_file .= 'inetd_flags="-wW"' . "\n"; + } + + file_put_contents(ETC_RC_CONF, $mk_rc_conf_file, LOCK_EX); + if ($inet_daemons_count > 0) { mwexec("/etc/rc.d/inetd restart"); - else + } else { mwexec("/etc/rc.d/inetd stop"); + } - //Write config if any file from filesystem was loaded - if ($update_conf > 0) + /* Write config if any file from filesystem was loaded. */ + if ($update_conf > 0) { write_config(); - - // mount filesystem readonly + } + conf_mount_ro(); - + checkmk_sync_on_changes(); } function checkmk_validate_input($post, &$input_errors) { foreach ($post as $key => $value) { - if (empty($value)) + if (empty($value)) { continue; - if (substr($key, 0, 3) == "port" && !preg_match("/^\d+$/", $value)) + } + 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)) + } + 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)) + } + 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 */ + +/* 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]; + if (is_array($config['installedpackages']['checkmksync']['config'])) { + $checkmk_sync = $config['installedpackages']['checkmksync']['config'][0]; $synconchanges = $checkmk_sync['synconchanges']; $synctimeout = $checkmk_sync['synctimeout']; - switch ($synconchanges){ + 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."); + 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; + 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){ + 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']) + if ($sh['username']) { $username = $sh['username']; - else + } else { $username = 'admin'; - if($password && $sync_to_ip) + } + if ($password && $sync_to_ip) { checkmk_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout); } - log_error("[Check_mk-agent] xmlrpc sync is ending."); + log_error("[check_mk-agent] XMLRPC sync is ending."); } - } + } + } } -############################################## -/* Do the actual XMLRPC sync */ + +/* Do the actual XMLRPC sync. */ function checkmk_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout) { global $config, $g; - if(!$username) + if (!$username) { return; - - if(!$password) + } + + if (!$password) { return; + } - if(!$sync_to_ip) + if (!$sync_to_ip) { return; + } $xmlrpc_sync_neighbor = $sync_to_ip; - if($config['system']['webgui']['protocol'] != "") { + 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 = $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 + } else { $port = "443"; - } + } + } $synchronizetoip .= $sync_to_ip; - /* xml will hold the sections to sync */ + /* xml will hold the sections to sync. */ $xml = array(); $xml['checkmk'] = $config['installedpackages']['checkmk']; - - /* assemble xmlrpc payload */ + + /* 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 */ + /* 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}."); + 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']) + if ($g['debug']) { $cli->setDebug(1); - /* send our XMLRPC message and timeout after 250 seconds */ + } + /* 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}."; + 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()) { + } 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(); + $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}."); + log_error("[check_mk-agent] XMLRPC sync successfully completed with {$url}:{$port}."); } - - /* tell checkmk to reload our settings on the destionation sync host. */ + + /* 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 = "require_once('/usr/local/pkg/checkmk.inc');\n"; $execcmd .= "sync_package_checkmk();"; - /* assemble xmlrpc payload */ + /* Assemble XMLRPC payload. */ $params = array( XML_RPC_encode($password), XML_RPC_encode($execcmd) ); - - log_error("[Check_mk-agent] XMLRPC reload data {$url}:{$port}."); + + 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)."; + 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()) { + } 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(); + $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)."); + log_error("[check_mk-agent] XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php)."); } - } ?> -- cgit v1.2.3