PHP Classes

Find Needle: Locate and display file lists with given content

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 160 This week: 1All time: 8,960 This week: 571Up
Version License PHP version Categories
find-needle 1GNU General Publi...5HTML, PHP 5, Files and Folders, Searc...
Description 

Author

This package can Locate and display file lists with given content.

It can traverse given directories and locate files that have a given content string.

The class can also display the list of files found.

Picture of Soltermann Paul
  Performance   Level  
Name: Soltermann Paul <contact>
Classes: 2 packages by
Country: Switzerland Switzerland
Age: ???
All time rank: 298827 in Switzerland Switzerland
Week rank: 420 Up6 in Switzerland Switzerland Up

Example

<?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>";
?>


Details

 ###################### chk4needle #######################
 ####                                                 ####
 ####    Author : Paul Soltermann,                    ####
 ####    eMail  : ps@g2p.ch   web: www.g2p.ch/myRGi/  ####
 ####    Date   : 2017-05-12                          ####
 ####    Updated:                                     ####
 ####                                                 ####
 #########################################################
 readme for chk4needle

Preamble

The first time I was shocked when a php file was moved to quarantaene by my AV software shortly after downloading from ISP server to my local Windows system. I have found the cause and corrected immediately ... Later I received a strange error message about an e-mail that could not be delivered to the destination. A email and a destination I had never heard of. I have react sensitive now and have checked the logfile on my ISP server. The result was shocking: Someone with an IP address that is pointing to an ISP in St. Petersburg accessed to a program in my library which has been inactive for a long time ... accessed not just once but many times in one day. We have to be careful with emails unintentional sent by the own server, we can be held responsible, even when we didn't knew anything.

The legend that there is no virus danger on Linux system was brocken compleatly and i need finde a solution for: 1. Change PW on mysql-server and for ftp-access 2. Determine the size of damage (affected programs) 3. Remove unused and outdated programs. 4. Overwork active programs. 5. Keep a clean local and online library

In order to cover point 2 to 5 i have created a little utility that can run on the web server, local or online and hope it will also be useful for others: chk4needle.php as an example for use of findneedle.php

Installation on Linux webserver

create directory somwhere in your directory tree which is accessable for the webserver you may start with check on your local webserver /var/www/html/tools/check/ or similar download needle.zip extract the downloaded file in this new directory

following files should be present: x chk4needle.php (example) x findneedle.php (class file) x heaps.jpg x favicon.jpg x needle_(01,02,03,04).jpg

make sure directory is readable for webuser open chk4needle.php in FF webbrowser.

Operating

open ../tools/check/chk4needle.php edit the entries for: x needle (see most dangerious needle in needle_01.jpg) x base directory , for me it is: /var/www/ /var/www/html/programme/ etc as example for local server or /home/httpd/vhosts/g2p.ch/httpdocs/myRGi/ as example for ISP server x text-filetyp: chose php or txt or enter an other textfile type in program code.

hit "go" then "show sresults" (see needle_02.jpg) and watch "show scanned directories" (see needle_03.jpg)

a hint for remove unused and outdated programs; (see needle_04.jpg)

Other uses

Search and check for outdated php functions such as "split" in your program library Enter 'split' in the needle field in this case.

future steps

x run utility as cronjob with email anoncement in case of existing events. x exclude list for frindly needles x write results to a logfile


Screenshots  
  • needle_02.jpg
  • needle_03.jpg
  • needle_04
  • needle_01.jpg
  Files folder image Files  
File Role Description
Accessible without login Plain text file readme Doc. how to use
Accessible without login Plain text file chk4needle.php Example example
Accessible without login Image file flavicon Icon icon
Plain text file findneedle.php Class class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:160
This week:1
All time:8,960
This week:571Up