<commit_before><?php
/*
 * Centreon is developped with GPL Licence 2.0 :
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * Developped by : <NAME> - <NAME> 
 * 
 * The Software is provided to you AS IS and WITH ALL FAULTS.
 * Centreon makes no representation and gives no warranty whatsoever,
 * whether express or implied, and without limitation, with regard to the quality,
 * any particular or intended purpose of the Software found on the Centreon web site.
 * In no event will Centreon be liable for any direct, indirect, punitive, special,
 * incidental or consequential damages however they may arise and even if Centreon has
 * been previously advised of the possibility of such damages.
 * 
 * For information : <EMAIL>
 */
  	
 	$error_flag = 0;
	$command = $_GET["command_line"];
	$example = $_GET["command_example"];		
	$args = split("!", $example);

	$resource_def = str_replace('$', '@DOLLAR@', $command);
	while (preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches))	{
			$DBRESULT =& $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");
			if (PEAR::isError($DBRESULT))
				print "DB Error : ".$DBRESULT->getDebugInfo()."<br />";
			$resource = $DBRESULT->fetchRow();
			$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
	}		
	while (preg_match("/@DOLLAR@HOSTADDRESS@DOLLAR@/", $resource_def, $matches))	{			
			if (isset($_GET["command_hostaddress"]))
				$resource_def = str_replace("@DOLLAR@HOSTADDRESS@DOLLAR@", $_GET["command_hostaddress"], $resource_def);
			else
				$error_flag = 1;
	}
	while (preg_match("/@DOLLAR@ARG([0-9]+)@DOLLAR@/", $resource_def, $matches))	{
			$match_id = $matches[1];
			if (isset($args[$match_id])){
				$resource_def = str_replace("@DOLLAR@ARG". $match_id ."@DOLLAR@", $args[$match_id], $resource_def);
				$resource_def = str_replace('$', '@DOLLAR@', $resource_def);
				if(preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches)) {
					$DBRESULT =& $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");
					if (PEAR::isError($DBRESULT))
						print "DB Error : ".$DBRESULT->getDebugInfo()."<br />";
					$resource = $DBRESULT->fetchRow();
				$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
				}
				if (preg_match("/@DOLLAR@HOSTADDRESS@DOLLAR@/", $resource_def, $matches)) {
					if (isset($_GET["command_hostaddress"]))
						$resource_def = str_replace("@DOLLAR@HOSTADDRESS@DOLLAR@", $_GET["command_hostaddress"], $resource_def);
					else
						$error_flag = 1;
				}	
			}
			else
				$error_flag = 1;
	}
	
	$command = $resource_def;
	$stdout = array();
	unset($stdout);
	
	//$command = "/usr/local/nagios/libexec/check_centreon_dummy -s 1 -o \"OK my ass\"";	
	exec($command, $stdout, $status);	
	$msg = join(" ",$stdout);
	$msg = str_replace("\n", "<br />", $msg);
	
	if ($status == 1)
		$status = "WARNING";
	else if ($status == 2)
		$status = "CRITICAL";
	else if ($status == 0)
		$status = "OK";	
	else
		$status = "UN" .
				"KNOWN";
	$attrsText 	= array("size"=>"25");
	$form = new HTML_QuickForm('Form', 'post', "?p=".$p);
	$form->addElement('header', 'title',_("Plugin Test"));<commit_msg>checks if specified macros exist<commit_after><?php
/*
 * Centreon is developped with GPL Licence 2.0 :
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * Developped by : <NAME> - <NAME> 
 * 
 * The Software is provided to you AS IS and WITH ALL FAULTS.
 * Centreon makes no representation and gives no warranty whatsoever,
 * whether express or implied, and without limitation, with regard to the quality,
 * any particular or intended purpose of the Software found on the Centreon web site.
 * In no event will Centreon be liable for any direct, indirect, punitive, special,
 * incidental or consequential damages however they may arise and even if Centreon has
 * been previously advised of the possibility of such damages.
 * 
 * For information : <EMAIL>
 */
  	
 	$error_msg = "";
	$command = $_GET["command_line"];
	$example = $_GET["command_example"];		
	$args = split("!", $example);

	$resource_def = str_replace('$', '@DOLLAR@', $command);
	while (preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches) and $error_msg == "")	{
			$DBRESULT =& $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");			
			if (PEAR::isError($DBRESULT))
				print "DB Error : ".$DBRESULT->getDebugInfo()."<br />";
			$resource = $DBRESULT->fetchRow();
			if (!isset($resource["resource_line"])){
				$error_msg .= "\$USER".$matches[1]."\$";				
			}
			else {
				$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
			}
	}		
	while (preg_match("/@DOLLAR@HOSTADDRESS@DOLLAR@/", $resource_def, $matches) and $error_msg == "")	{			
			if (isset($_GET["command_hostaddress"]) && $_GET["command_hostaddress"] != "")
				$resource_def = str_replace("@DOLLAR@HOSTADDRESS@DOLLAR@", $_GET["command_hostaddress"], $resource_def);
			else
				$error_msg .= "\$HOSTADDRESS\$";
	}
	while (preg_match("/@DOLLAR@ARG([0-9]+)@DOLLAR@/", $resource_def, $matches) and $error_msg == "")	{
			$match_id = $matches[1];
			if (isset($args[$match_id])){
				$resource_def = str_replace("@DOLLAR@ARG". $match_id ."@DOLLAR@", $args[$match_id], $resource_def);
				$resource_def = str_replace('$', '@DOLLAR@', $resource_def);
				if(preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches)) {
					$DBRESULT =& $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");
					if (PEAR::isError($DBRESULT))
						print "DB Error : ".$DBRESULT->getDebugInfo()."<br />";
					$resource = $DBRESULT->fetchRow();
					if (!isset($resource["resource_line"])){
						$error_msg .= "\$USER".$match_id."\$";
					}
					else {
						$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
					}
				}
				if (preg_match("/@DOLLAR@HOSTADDRESS@DOLLAR@/", $resource_def, $matches)) {
					if (isset($_GET["command_hostaddress"]))
						$resource_def = str_replace("@DOLLAR@HOSTADDRESS@DOLLAR@", $_GET["command_hostaddress"], $resource_def);
					else
						$error_msg .= "\$HOSTADDRESS\$";
				}	
			}
			else
				$error_msg = "\$USER" . $match_id . "\$";
	}	
	if ($error_msg != "") {
		$command = $resource_def;
		$command = str_replace('@DOLLAR@', '$', $command);	
		$msg = _("Could not find macro ") . $error_msg;
		$status = _("ERROR");
	}
	else {
		$command = $resource_def;
		$stdout = array();
		unset($stdout);	
		exec($command, $stdout, $status);	
		$msg = join(" ",$stdout);
		$msg = str_replace("\n", "<br />", $msg);
	
		if ($status == 1)
			$status = _("WARNING");
		else if ($status == 2)
			$status = _("CRITICAL");
		else if ($status == 0)
			$status = _("OK");	
		else
			$status = _("UNKNOWN");
	}
	
	$attrsText 	= array("size"=>"25");
	$form = new HTML_QuickForm('Form', 'post', "?p=".$p);
	$form->addElement('header', 'title',_("Plugin Test"));
{'fraction_non_alphanumeric': 0.1963495575221239, 'fraction_numerical': 0.006913716814159292, 'mean_word_length': 4.34589800443459, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438511', 'n_tokens_mistral': 2900, 'n_tokens_neox': 2559, 'n_words': 561}