PHP Classes

File: chk4needle.php

Recommend this page to a friend!
  Classes of Soltermann Paul   Find Needle   chk4needle.php   Download  
File: chk4needle.php
Role: Example script
Content type: text/plain
Description: example
Class: Find Needle
Locate and display file lists with given content
Author: By
Last change: changed Description and Listing priority
Date: 6 years ago
Size: 5,460 bytes
 

Contents

Class file image Download
<?php
   
    
/*
     ###################### chk4needle ######################
     #### ####
     #### Author : Paul Soltermann, ####
     #### eMail : ps@g2p.ch web: www.g2p.ch/myRGi/ ####
     #### Date : 2017-05-12 ####
     #### Updated: ####
     #### ####
     #########################################################
     * example for use of class findneedle
     */
?>
    <!DOCTYPE html >
    <html>
    <head>
    <title>check4needle</title>
    <META HTTP-EQUIV="Content-Type" CONTENT="text-html: charset=UTF-8">
   
    <style type="text/css">
    tr
    {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        background-color: transparent;
    }
    tr#i
    {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        font-weight: bold;
        background-color: transparent;
        color: white;
    }
    input
    {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 12px;
        background-color: #D2CACA;
        color: #4A4A4A;
    }
    select
    {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 12px;

        color: #7F7F7F;
    }
    </style>
    </head>
    <body>
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="GET">
    <?php
   
// Formulardaten anzeigen
    // foreach ($_GET as $k => $v) echo "Get: $k $v <br>";
   
$status ="please select options and press go";
   
   
$needle = isset($_GET['needle'])? $_GET['needle'] :"eval";
   
$spath = isset($_GET['spath'])? $_GET['spath'] :"/var/www/html/";
   
$mesh = isset($_GET['mesh'])? $_GET['mesh'] :"php";
   
$opt = isset($_GET['opt'])? $_GET['opt'] :"screen_only";
   
$directories = isset($_GET['directories'])? TRUE:FALSE;
   
$show = isset($_GET['show'])? TRUE:FALSE;
   
$go = isset($_GET['go'])? TRUE:FALSE;
 

   
    echo
"<table style = \"background-color:#FFAAAA;\" border=0 width=400 >";
    echo
"<tr style=\"color:#715307; font-weight: bolder;\"><td colspan=2>Easy locate <b>dangerous</b> foreign code (e)val<br>
    and<br>
    obsolete expressions (split) in your program library.</td></tr>"
;
    echo
"<tr><td>";
    echo
"<table style = \"background-color:#A49E9E;padding:10px;\" width=100% >
    <tr id=i>
        <td width=130 >needle:</td>
        <td width=200 ><input name=needle type=text value=
$needle ></td></tr>
    <tr id=i><td >base directory:</td>
        <td><input name=spath type=text value=
$spath ></td></tr>
    <tr id=i><td >text-filetyp in which to search:</td>
        <td>"
;
    echo
"<select name=\"mesh\">";
   
$mesh_arr = array(0 => 'choose a filetyp',1 => 'php',2 => 'txt');
    foreach (
$mesh_arr as $key => $val )
    {
       
$sel = ($val == $mesh) ? "selected" : "" ;
        echo
"<option value=$val $sel >$val</option>";
    }
    echo
"</select>";
               
    echo
"</td></tr>";
    echo
"<tr id=i><td colspan=2 >output to:";
   
       
$out_opt = array("screen_only","csv","txt");
        foreach (
$out_opt as $k => $v)
        {
           
$sel = ($v == $opt) ? "checked" : "" ;
            echo
"<input type='radio' $sel name='opt' value=$v>$v";
        }
    echo
"</td></tr>";
    if(
$go)
    {
        echo
"<tr id=i><td><INPUT name=show type=submit value=\"show results\"></td>
            <td><INPUT name=directories type=submit value=\"show scanned directories\"></td></tr>"
;
           
$status = "edit options or hit result or directory button";
    }
   
    echo
"<tr id=i ><td><INPUT name=go type=submit value=go></td><td >it works fine on my web <a href=\"http://www.g2p.ch/myRGi/\" title=\"go to www.g2p.ch/myRGi/\"><img src=\"./favicon.jpg\" height=16 ></a></td></tr>";
    echo
"</td></tr>";
    echo
"</table>";
   
$link =FALSE;
    if(
$go or $show or $directories )
     {
         if(
$show or $directories)
         {
           
$ts = date("Ymd-His");
           
$log = "./scores/needle_txt"."_$ts";
            if (
$opt == 'csv') $log = $log.".csv";
            if (
$opt == 'txt') $log = $log.".txt";
           
            require_once(
'./findneedle.php');
           
$heugabel = new findneedle($log);
           
$stat = $heugabel->open($log);
            if(
$heugabel==false)
            {
                echo
$heugabel->error;
                die;
            }
               
$wagen = $heugabel->getHaystack($spath);
                if(
$directories)
                {
                   
$needle_box = $heugabel->getEvents($wagen,$needle,$mesh);
                    if(
count($wagen) > 0 ) $heugabel->boost($wagen); else $status = "press \"no directory found\"";
                }
                elseif(
$show)
                {
                   
$needle_box = $heugabel->getEvents($wagen,$needle,$mesh);
                    if(
count($needle_box) > 0 )
                    {
                            if(
$heugabel->needle_box($needle_box, $needle))
                           
$status ="please ckeck result table!";
                        if(
$opt == 'txt' or $opt == 'csv' )
                        {

                            if(
$heugabel->needle_box_to_file($needle_box, $needle))
                            if (
$heugabel->close())
                        {
                           
$link = TRUE;
                        }
                        else
                        {
                           
$status = "fehler";
                        }
                        echo
"<table style = \"background-color:#FFAAAA;\" border=0 width=100% ><tr><td>output written to $log.</td></tr></table>";
                        }
                    }
                    elseif(
count($needle_box) == 0)
                    {
                       
$status = "\"$needle\""." not found in directory tree.";
                    }
                }

        }
        else {
$status = "press for results or scanned directories";}
    }else {
$status = "please select options and press go";}
    echo
"<table style = \"background-color:#FFAAAA;\" border=0 width=100% ><tr><td colspan=2>$status";
    if(
$link) echo"<a href=\"$log\" type=\"application/text\"><img alt=\"$log\"</a></td>
    </tr></table>"
;
    echo
"</table></form>";
?>