Tag Archives: php

Finding files on my fileserver

I use several tools to find files on my server.

Loads of stuff on my main fileserver.
(Graph is a great tool called DUC) https://duc.zevv.nl/

Besides a search engine, i have a file finder.
Due to the massive amount of data, i like to find things by other means than knowing the directory structure.

I can find files by filename, but also by contents.

I’ll talk about find by contents first.

I’ve got loads of documents in Pdf, HTML, txt, doc, sheets , wordperfect etcetera.
Those documents i can find using a tool named Namazu.
This is quite a old tool, but i’m using it for a long time and it still works great.
I didn’t find a better replacement yet.
(But i’ve been looking into : elasticsearch, Solr, Lucene)

http://www.namazu.org/ is easy to install, but if you want the tool to scrape different kinds of documents you have to add some additional software.

My multipurpose printer can scan pages in pdf.
Those are only embedded jpg’s in a pdf container.
I will talk about how i handle these later.

My current start page :
This index contains 267,763 documents and 14,036,762 keywords.
Search example of namazu

Some things to consider when implementing namazu:

  • tweak the file types to scrape, it makes no sense to scrape binaries
  • tweak the directories to scrape (example below)
    • 0 1 * * 1 fash /usr/bin/mknmz -f /etc/namazu/mknmzrc –output-dir=/namazu/ /mnt/private/paperwork/ /mnt/private/information/ /mnt/private/Art\ en\ hobby\ Projects/ /mnt/private/Music\ Projects/ /mnt/private/bagpipe-music-writer/ –exclude=XXX –exclude=/mnt/binaries > /tmp/namazu.log 2>&1
  • you can set a parameter in the config for search only, this disables downloading the found link in the results!

Before Namazu i used HtDig.

Screenshot htdig

HtDIg also can scrape remote websites, Namazu can’t.

Preparing PDF for indexing:

I’ve written some scripts to make PDFs containing scanned text scrape-able.
( https://gitlab.com/fash/inotify-scanner-parser )
What it does:

  • My scanner puts a scanned pdf on my fileserver in a certain directory
  • Inotify detects a written file
  • it will copy the file, run OCR on it (tesseract) and writes a txt file (scapeable)
  • After that the text will be embedded (overlay) on the PDF, so now it becomes searchable/scrapeable
  • When certain keywords are found, it will sort documents in subdirs
Example from a scanned jpg, i can find OCR words!
(note .. the overlay is exact on the found words)

Finding files by name:

For finding files a made a little webpage like this:

It is a simple webpage grabbing through a list of files.
It takes the first keyword and does a grep, it takes a second keyword to match also.
I can select different file databases to search. (This case is private)
Between search and private i can give the number of entries to print.
So i can do
Search “ansible” NOT “tower” 50 entries from the public fileset


20 5 * * * /usr/bin/find /mnt/shark*  > /var/www/html/findfiles/sharkoon
10 4 * * * /usr/bin/find /tank/populair > /var/www/html/findfiles/populair
20 4 * * * /usr/bin/find /tank/celtic > /var/www/html/findfiles/celtic

And a php script (dirty fast hack, never came around it to make it a final version)

<font face="Tahoma"><small>|keyword|(keyword)|search|(nr results)|NOT SECOND KEYWORD|share|</small><BR>
Search: <form method="post" action="/findfiles/?"><input type="Text" name="words" size=10 value=""><input type="Text" name="words2" size=10 value=""><input type="Submit" name="submit" value="search"><input type="Text" name="nrlines" size=3 value=""><input type="checkbox" name="not" unchecked>
<SELECT NAME=findfile>
<OPTION VALUE=private>private
<OPTION VALUE=celtic>celtic
<OPTION VALUE=populair>populair
<OPTION VALUE=dump>public
<OPTION VALUE=sharkoon>sharkoon

if ($words2=="xsearch") { $findfile="other"; $words2=""; }
if ($nrlines) {  } else { $nrlines=100; }
if ($words && $words2=="") {
$words = preg_replace("(\r\n|\n|\r)", "", $words);
$words = preg_replace("/[^0-9a-z]/i",'', $words);
$command = "/bin/cat $findfile |/bin/grep -i $words |head -$nrlines";
$blah=str_replace($words, "<b><font color=red>$words</font></b>",$blah);
print $blah;
if (($words) and ($words2)) {
$words = preg_replace("(\r\n|\n|\r)", "", $words);
$words = preg_replace("/[^0-9a-z.]/i",'', $words);
$words2 = preg_replace("(\r\n|\n|\r)", "", $words2);
$words2 = preg_replace("/[^0-9a-z.]/i",'', $words2);
if ($not=="on") {
$command = "/bin/cat $findfile |/bin/grep -i $words | /bin/grep -iv $words2 |head -$nrlines";
} else {
$command = "/bin/cat $findfile |/bin/grep -i $words | /bin/grep -i $words2 |head -$nrlines";
$blah=str_replace($words, "<b><font color=red>$words</font></b>",$blah);
$blah=str_replace($words2, "<b><font color=red>$words2</font></b>",$blah);
print $blah;

Nikon Lenses

Created a graph for my Nikon lenses. It shows me what lens i can use at what Aperture / Range.

( https://media.henriaanstoot.nl/websites/lenses/ )

It uses canvas to draw lines and text, but thats only interesting for static stuff. ( https://www.w3schools.com/graphics/canvas_drawing.asp )
My example uses a php script to load information from a csv file. And loops though those entries and draw lens info.

Piece of canvas script to draw 17-70mm lens info.

ctx.fillStyle = 'rgba(0, 200, 100, 0.9)';
ctx.fillStyle = 'rgba(0,0,0,0.9';
ctx.translate( 189.98560128675,153.25813588993);
ctx.rotate(-Math.PI / 4);
ctx.fillText("17-70mm", 0,0);

CSV lenses info

80;200;2.8;2.8;FX;80-200mm f/2.8
10;24;3.5;4.5;DX;10-24mm wide
28;100;3.5;5.6;;28-100mm leen
35;35;1.8;1.8;DX;35mm f/1.8
60;60;2.8;2.8;FX;60mm f/2.8

PHP Code to generate

<!DOCTYPE html>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <style type='text/css'>
    body{ background-color: ivory; }
#canvas{border:1px solid white;}

<script type='text/javascript'>//<![CDATA[
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");

print "ctx.strokeStyle = 'rgba(200, 0, 0, 0.1)';";
print "ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';";
foreach ($apes as &$value) {
print "ctx.font = '20px Arial';";
print "ctx.fillText(\"$value\", 20, $height);";
print "ctx.lineWidth=2;";
print "ctx.moveTo(50, $height);";
print "ctx.lineTo(900, $height);";
print "ctx.stroke();";
foreach ($apes as &$value) {
print "ctx.fillText(\"$value\", $width, 270);";
print "ctx.font = '15px Arial';";
ctx.strokeStyle="rgba(0, 0, 0, 0.9)";



        foreach ($config as $value) {
if ( $x1 == $x2 ) { $color="200,0,0"; } else { $color="0,0,0"; }
if ( $x1 == $x2 ) { $x2 = $x2 + 6; }

if ( $xx1 == $xx2 ) { $xx2 = $xx2 + 6; }
if ( $value[4] == "FX" ) { $col="200"; $trans=0.2; } else { $col="0";$trans=0.9;  }

ctx.fillStyle = 'rgba(<?PHP print $col; ?>, <?PHP print $green; ?>, 100, <?PHP print $trans; ?>)';
ctx.moveTo(<?PHP print "$x1"; ?>,<?PHP print "$y1"; ?>);
ctx.lineTo(<?PHP print "$x2"; ?>,<?PHP print "$y2"; ?>);
ctx.lineTo(<?PHP print "$x2"; ?>,<?PHP print "250"; ?>);
ctx.lineTo(<?PHP print "$x1"; ?>,<?PHP print "250"; ?>);
ctx.strokeStyle="rgba(<?PHP print "$color"; ?>,<?PHP print $trans;  ?>)";
ctx.fillStyle = 'rgba(<?PHP print "$color"; ?>,<?PHP print $trans;  ?>';
ctx.translate( <?PHP print "$x1"; ?>,<?PHP print "$yy1"; ?>);
ctx.rotate(-Math.PI / 4);
ctx.fillText("<?PHP print "$value[5]"; ?>", 0,0);

if ( $value[4] == "FX" ) {
ctx.fillStyle = 'rgba(0, <?PHP print "200"; ?>, 0, 0.9)';
ctx.moveTo(<?PHP print "$xx1"; ?>,<?PHP print "$y1"; ?>);
ctx.lineTo(<?PHP print "$xx2"; ?>,<?PHP print "$y2"; ?>);
ctx.lineTo(<?PHP print "$xx2"; ?>,<?PHP print "250"; ?>);
ctx.lineTo(<?PHP print "$xx1"; ?>,<?PHP print "250"; ?>);
ctx.strokeStyle="rgba(<?PHP print "$color"; ?>,0.9";
ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';
ctx.translate( <?PHP print "$xx1"; ?>,<?PHP print "$yy1"; ?>);
ctx.rotate(-Math.PI / 4);
ctx.fillText("<?PHP print "$value[5]"; ?> crop", <?PHP print "0"; ?>, <?PHP print "0"; ?>);

ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
ctx.font = 'bold 10pt Calibri';



  <canvas id="canvas" width=700 height=300></canvas>

   function get2DArrayFromCsv($file,$delimiter) {
       if (($handle = fopen($file, "r")) !== FALSE) {
           $i = 0;
           while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
               for ($j=0; $j<count($lineArray); $j++) {
                   $data2DArray[$i][$j] = $lineArray[$j];
       return $data2DArray;


        foreach ($config as $value) {
            print "<B>Lens = $value[5] </B><BR>";
            print "Focal min = $value[0] <BR>";
            print "Focal max = $value[1] <BR>";
            print "Arp min = $value[2] <BR>";
            print "Arp max = $value[3] <BR>";
            print "Crop (FX/DX) = $value[4] <P>";




Kanban effectiveness graph generator

While attending a Kanban workshop, i needed to keep myself awake.
I’d hardly slept that night.

So i wrote something useful using PHP JPgraph and Sqlite, while attending the workshop.
It shows the effectiveness of the team using kanban.


include ("insert.php");
include ("getlast.php");
<img src="graph.php"><P>
<form action="" method="POST">
Tickets from board: <input size="4" name="klaar" value="<?PHP print $klaar; ?>"/> <input type="checkbox" name="useklaar" value="useklaar" checked> Use fromboard <P>
            <td>inlane:</td><td><input size="4" name="inlane" value="<?PHP print $inlanelast; ?>"/></td>
            <td>analyse:</td><td><input size="4" name="analyze" value="<?PHP print $analyzelast; ?>" /></td>
            <td>implement:</td><td><input size="4" name="implement" value="<?PHP print $implementlast; ?>" /></td>
            <td>documentation:</td><td><input size="4" name="documentation" value="<?PHP print $documentationlast; ?>"/></td>
            <td>peer:</td><td><input size="4" name="peer" value="<?PHP print $peerlast; ?>"/></td>
            <td>test:</td><td><input size="4" name="test" value="<?PHP print $testlast; ?>"/></td>
            <td>done:</td><td><input size="4"  name="done" value="<?PHP print $donelast; ?>"/></td>
            <input type="submit" value="Submit"/>



include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_line.php");
$db = new SQLite3('mysqlitedb.db');
$results = $db->query('SELECT inlane FROM ENTRIES');
while ($row = $results->fetchArray()) {
$inlane[$index] = $row[0];
$results = $db->query('SELECT analyze FROM ENTRIES');
while ($row = $results->fetchArray()) {
$analyze[$index] = $row[0];
$results = $db->query('SELECT implement FROM ENTRIES');
while ($row = $results->fetchArray()) {
$implement[$index] = $row[0];
$results = $db->query('SELECT documentation FROM ENTRIES');
while ($row = $results->fetchArray()) {
$documentation[$index] = $row[0];
$results = $db->query('SELECT peer FROM ENTRIES');
while ($row = $results->fetchArray()) {
$peer[$index] = $row[0];
$results = $db->query('SELECT test FROM ENTRIES');
while ($row = $results->fetchArray()) {
$test[$index] = $row[0];
$results = $db->query('SELECT done FROM ENTRIES');
while ($row = $results->fetchArray()) {
$done[$index] = $row[0];
//$datay = array(1,2,4);
$datay1 = array(2,4,4,6,7,4);
$datay2 = array(2,3,4);
$graph = new Graph(600,600,"auto");
$graph->title->Set("Kanban grapher - A pruts by FASH");

// Add 10% grace to top and bottom of plot


$p1 = new LinePlot($inlane);

$p2 = new LinePlot($analyze);

$p3 = new LinePlot($implement);

$p4 = new LinePlot($documentation);

$p5 = new LinePlot($peer);

$p6 = new LinePlot($test);

$p7 = new LinePlot($done);


$p1->SetLegend ("inlane"); 
$p2->SetLegend ("analyse"); 
$p3->SetLegend ("implementation"); 
$p4->SetLegend ("documentation"); 
$p5->SetLegend ("peer"); 
$p6->SetLegend ("test"); 
$p7->SetLegend ("done"); 
$graph ->legend->Pos( 0.09,0.09,"left" ,"top");



$db = new SQLite3('mysqlitedb.db');

$db->exec("DELETE FROM BOARD");
$db->exec("INSERT INTO BOARD  VALUES ($klaar,$inlane,$analyze,$implement,$documentation,$peer,$test,$done)");


$db->exec("INSERT INTO ENTRIES  VALUES (NULL,$inlane,$analyze,$implement,$documentation,$peer,$test,$done)");
$db = new SQLite3('mysqlitedb.db');

$results = $db->query('SELECT inlane FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$inlanelast = $row[0];

$results = $db->query('SELECT implement FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$implementlast = $row[0];

$results = $db->query('SELECT documentation FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$documentationlast = $row[0];

$results = $db->query('SELECT peer FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$peerlast = $row[0];

$results = $db->query('SELECT test FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$testlast = $row[0];

$results = $db->query('SELECT done FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$donelast = $row[0];

$results = $db->query('SELECT vanbord FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$klaar = $row[0];

$results = $db->query('SELECT analyze FROM BOARD LIMIT 1;');
$row = $results->fetchArray();
$analyzelast = $row[0];

Onkyo web control hack

Back in 2009 i’ve posted my web controller for Onkyo in a forum.

Several people build on that source and made android/iphones app using this as example.

It uses pfsockopen with raw packets in php.
Spend a lot of work reverse engineering the tcp headers to be send.
Another fun trick was re-using a trick i’ve used for my ipcam controller and dartabase. (Dart game application)

Below a PDF with first page of forum

I’ve made a alteration in my logitechmediaserver (squeezebox server) which embedded a onkyo volume control part in the gui.

Volume Onkyo in LMS

Part of code

// :colorscheme elflord
// Henri Aanstoot
// Onkyo Reciever Web Interface 2009
// Version 0.6b - 23 Oct 2009
// maximum to set volume (0-100) 
// !! some have 64 max????
// (i had to enable this port by going onto the menu's on my Onkyo

// trick browser into staying on same page
$ibrowser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($ibrowser == false) {
header("HTTP/1.0 204 No Response");
// test write to file
//$fp=fopen("test.txt", "wb");
// write to Receiver 
$fp = pfsockopen($receiveripnumber, $receiverlistenport, $errno, $errstr, 30);
//get command from post form
//get volume if cmd is numeric
if ($command > $volumemax) { $command=$volumemax; }
echo $command;
  $vol=str_pad(dechex($command), 2, '0', STR_PAD_LEFT);
// Calculate header and datapacket lengths
// total eiscp packet to send 
// write
fwrite($fp, $line);
// rest status part
//    while (!feof($fp)) {
//        echo fgets($fp, 128);
//    } 


if ($ibrowser == true) {
print "<html>
<title>Sending Command...</title>`
<meta http-equiv=\"refresh\" content=\"0;url=index.php\">


List of command’s

!1AMT00,Audio muting off
!1AMT01,Audio muting on
!1AMTQSTN,Audio muting stat
header, Speaker A/B (Main/Front?)
!1SPA00,Speaker A Off
!1SPA01,Speaker A On
!1SPB00,Speaker B Off
!1SPB01,Speaker B On
header,Sound modus
!1LMD40,5.1ch Surround
!1LMD40,Straight Decode*1
!1LMD41,Dolby EX/DTS ES
!1LMD41,Dolby EX*2
!1LMD42,THX Cinema
!1LMD43,THX Surround EX
!1LMD50,U2/S2 Cinema/Cinema2
!1LMD52,Games Mode
!1LMD80,PLII/PLIIx Movie
!1LMD81,PLII/PLIIx Music
!1LMD82,Neo:6 Cinema
!1LMD83,Neo:6 Music
!1LMD85,Neo:6 THX Cinema
!1LMD87,Neural Surr*3
!1LMD88,Neural THX
!1LMD89,PLII THX Games
!1LMD8A,Neo:6 THX Games
!1LMDUP,Listening Mode Wrap-Around Up
!1LMDDOWN,Listening Mode Wrap-Around Down
header,Input Selector
!1SLI04,VIDEO5    AUX2
!1SLIUP,Selector Position Wrap-Around Up
!1SLIDOWN,Selector Position Wrap-Around Down

Beer crate bottle counter

Post in 2002 due to screenshot .. dont know when i build it, some years before.

Using 24 pushbuttons and a IO expander, i could count the bottles in a crate. Probably used something like a hef4067 ??

Now i probably use a weight sensor or a beer cap counter using a webcam image.

Notification to email and shopping list printer.

Web Interface

Every bottle had to be placed back upside down so the opening of the bottle would not press down on the button. Later i used springs which could hold a empty bottle elevated above the button. The weight of a full bottle would press on the button.

Web part Dopcounter (screenshot at top of page)

<HTML><HEAD><TITLE>dopDB.counter running @ fash's place</TITLE></HEAD><BODY bgcolor=white text=black>
if ($show){
print "<a href='index.php'>Show Last</a>";
else {
print "<a href='?show=1'>Show All</a>";
$db = mysql_connect("localhost", "user", "pass");
// store voor bargraph
$result2 = mysql_query("SELECT max(timestamp) FROM counter",$db);
$maxtimestamp = mysql_fetch_array($result2);
$result = mysql_query("SELECT * FROM counter",$db);
while ($myrow = mysql_fetch_array($result)) {
if ( $lenght = 24)
if ($maxtimestamp[0] == $myrow[0] || $show)
 $row1= substr("$myrow[1]", 0, 6);
 $row2= substr("$myrow[1]", 6, 6);
 $row3= substr("$myrow[1]", 12, 6);
 $row4= substr("$myrow[1]", 18, 6);
 $row1 = str_replace("1","<td><img src='dop.jpg'></td>",$row1);
 $row1 = str_replace("0","<td><img src='dopl.jpg'></td>",$row1);
 $row2 = str_replace("1","<td><img src='dop.jpg'></td>",$row2);
 $row2 = str_replace("0","<td><img src='dopl.jpg'></td>",$row2);
 $row3 = str_replace("1","<td><img src='dop.jpg'></td>",$row3);
 $row3 = str_replace("0","<td><img src='dopl.jpg'></td>",$row3);
 $row4 = str_replace("1","<td><img src='dop.jpg'></td>",$row4);
 $row4 = str_replace("0","<td><img src='dopl.jpg'></td>",$row4);
 print "<TABLE border=15 bgcolor='#aaaaaa'><TR>";
 print $row1;
 print "</tr><tr>";
 print $row2;
 print "</tr><tr>";
 print $row3;
 print "</tr><tr>";
 print $row4;
 print "</tr><table>";
if ($maxtimestamp[0] == $myrow[0] || $show)
print "<P>";
print date('l dS of F Y H:i:s',$myrow[0]); 
print "<BR><H1>$totaldop bottles left</H1>";
$store = $store + 1;
if ($totaldop < 6 && $maxtimestamp[0] == $myrow[0])
 print "<BR>Time to buy some beer again!<BR>";
print "numba bottles error! check code!";

<table border=0>
if ($storebck > 50){ $store=$storebck-50; } else { $store=0; }
while ($store <= $storebck){
print "<td bgcolor=#efefff width=10 valign='bottom'>";
print "<img src='bar1.gif' width=15 height=$double></td>";
$store = $store +1;
if ($storebck > 50){ $store=$storebck-50; } else { $store=0; }
while ($store <= $storebck){
print "<td bgcolor=#efefff width=10 valign='bottom'>";
print "$storetotals[$store]</td>";
$store = $store +1;


Somewhere start 2002, i made a tool for playing darts.
Well … keeping score and history

I was multiuser, multigame with statistics and undo.
You could click on the little dartboard what your have thrown on a real board. It just kept score and told you best finish options.

Screenshot below was a digitized picture, no way accurate. Versions later the board was realtime drawn with GDlib and pixelperfect.
It even showed you previous throws.

Later version