function nvweb_templates_find_closing_list_tag($html, $offset)
{
    $found = false;
    $level = 0;
    $closing_tag_position = 0;
    $loops = 0;
    // find next nv object="" tag (opening or closing)
    // if it is an opening tag --> level + 1
    // if it is a closing tag --> level - 1
    //      if level = 0, that's the closing tag we were looking for
    //      else repeat from current offset
    while (!$found && $loops < 2000) {
        // check if there is a special '<nv>' opening tag (list, search, conditional) before the next closing found tag
        $next_opening = stripos_array($html, array('<nv object="list" ', '<nv object="search" ', '<nv object="conditional" '), $offset);
        // find next '</nv>' occurrence from offset
        $next_closing = stripos($html, '</nv>', $offset);
        if ($next_opening !== false && $next_opening < $next_closing) {
            // there is an opening tag before a closing tag, so there is an inner nvlist_conditional
            // move the offset to the opening tag found
            $offset = $next_opening + strlen('<nv object="');
            $level++;
        } else {
            // found a closing tag without an inner nvlist_conditional opening tag
            $level--;
            if ($level > 0) {
                $offset = $next_closing + strlen('</nv>');
            } else {
                $closing_tag_position = $next_closing;
                $found = true;
            }
        }
        $loops++;
    }
    if (!$found) {
        $closing_tag_position = false;
    }
    return $closing_tag_position;
    /*
    
    
    // no support for nested lists
    // $template_end = strpos($html, '</nv>', $tag['offset']);
    // return $template_end;
    
    // supporting nested lists
    $loops = 0;
    $found = false;
    
    while(!$found)
    {
        // find next '</nv>' occurrence from offset
        $next_closing = stripos($html, '</nv>', $offset);
    
        // check if there is a special '<nv>' opening tag (list, search, conditional) before the next closing found tag
        $next_opening = stripos_array(
            $html,
            array(
                '<nv object="list" ',
                '<nv object="search" ',
                '<nv object="conditional" '
            ),
            $offset
        );
    
        if(!$next_opening)
        {
            $found = true;
        }
        else
        {
            $found = $next_opening > $next_closing;
    
            if(!$found)
            {
                $offset = $next_closing + strlen('</nv>');
                $loops++;
            }
        }
    
        if(!$found && ($offset > strlen($html) || $loops > 1000))
            break;
    }
    
    if(!$found)
        $next_closing = false;
    
    return $next_closing;
    */
}
Beispiel #2
0
        // warn regex
    } else {
        if (preg_match($warn_regex, $dwd_output, $matches)) {
            $out_state = 1;
            // ok string check stristr should be more performant
        } else {
            if (stristr($dwd_output, $ok_string)) {
                $out_state = 0;
                // this should not never happen
            } else {
                $out_state = 3;
            }
        }
    }
    // ignore return
    $out_state = array_key_exists('warnung_count', $matches) && $matches['warnung_count'] !== '' && !stripos_array($matches['warnung'], $ignore_warnung) ? $out_state : 0;
    if ($out_state > 2) {
        $output = "Kein gültiges Ergebnis gefunden. Bitte überprüfen Sie die URL " . $url . " und melden sich beim Autor des Plugins";
    } else {
        if ($out_state > 0) {
            $output = $matches['warnung_count'] . " Warnung(en) für " . $region_name . " gefunden, " . $matches['warnung'] . " von: " . $matches['von_datum'] . " bis: " . $matches['bis_datum'];
        } else {
            $output = "keine Warnungen für " . $region_name . " auf " . $url . " gefunden";
        }
    }
    $perf = sprintf("'aktive_warnungen'=%s", array_key_exists('warnung_count', $matches) && $matches['warnung_count'] !== '' ? $matches['warnung_count'] : 0);
}
// close curl resource to free up system resources
curl_close($ch);
echo $nagios_return[$out_state] . ": " . $output . PHP_EOL . "URL: " . $url . "|" . $perf;
exit($out_state);
            // warn regex
        } else {
            if (preg_match($warn_regex, $region['output'], $matches)) {
                $out_state = 1;
                // ok string check stristr should be more performant
            } else {
                if (stristr($region['output'], $ok_string)) {
                    $out_state = 0;
                    // this should not never happen
                } else {
                    $out_state = 3;
                }
            }
        }
        // ignore return
        $out_state = !stripos_array($matches['warnung'], $ignore_warnung) ? $out_state : 0;
        if ($out_state > 2) {
            $output = "Kein gültiges Ergebnis gefunden. Bitte überprüfen Sie die URL " . $url . " und melden sich beim Autor des Plugins";
        } else {
            if ($out_state > 0) {
                // XXX currently no real check for count of warnings
                $matches['warnung_count'] = 1;
                $output = "1 Warnung(en) für " . $region_name . " gefunden, " . $matches['warnung'] . " von: " . $matches['von_datum'] . " bis: " . $matches['bis_datum'];
            }
        }
    } else {
        $out_state = 0;
        $output = "keine Warnungen für " . $region_name . " auf " . $url . " gefunden";
    }
    $perf = sprintf("'aktive_warnungen'=%s", array_key_exists('warnung_count', $matches) && $matches['warnung_count'] !== '' ? $matches['warnung_count'] : 0);
}