Skip to content

Commit

Permalink
Add log search
Browse files Browse the repository at this point in the history
  • Loading branch information
zuno committed Apr 25, 2012
1 parent 299c5a2 commit d46b289
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions htdocs/config.inc.php-sample
Expand Up @@ -11,6 +11,7 @@ $repodir="/var/www/data";

$access_log_file="/var/log/httpd/access_log";

$enablefilelist=true;


?>
12 changes: 9 additions & 3 deletions htdocs/index.php
Expand Up @@ -36,12 +36,13 @@
$_SESSION['searcher_visitor']=$db->counter_get('visits');
}
#echo "You are the ".$_SESSION['searcher_visitor']."st visitor<br />";
$name=$desc=$file=$repo=$order=null;
$newsearch=$name=$desc=$file=$repo=$order=null;
foreach($_GET as $key => $value)$$key=$value;
if ($name or $desc or $file) {
if(($start==0)and($_SESSION['last_search']!="name=$name&desc=$desc&file=$file")){
$_SESSION['last_search']="name=$name&desc=$desc&file=$file";
$db->counter_inc('searches');
$newsearch=true;
}
}
#echo "Searched ".$db->counter_get('searches')." packages from 6 March 2010<br /><br />";
Expand Down Expand Up @@ -115,7 +116,8 @@

if(isset($_GET['debug']))var_dump($pkg,$nres);
$to=$start+$maxresult; if($to > $nres)$to=$nres;
echo "Time: ".(round($pkg->db->msec/1000,3))." msec<br />";
$duration=round($pkg->db->msec/1000,3);
echo "Time: $duration msec<br />";
echo "Results ".($start+1)."-$to of $nres: ";
if($start > 0){
echo "<a href='index.php?start=0&maxresult=$maxresult&repo=$repo&name=$name&desc=$desc&file=$file&order=$order#results'>&lt;&lt;</a> ";
Expand Down Expand Up @@ -194,7 +196,8 @@
$nres=$fl->find($sfile,$sname,$sdesc,$repo,$ord);
if(isset($_GET['debug']))var_dump($fl,$nres);
$to=$start+$maxresult; if($to > $nres)$to=$nres;
echo "Time: ".(round($fl->db->msec/1000,3))." msec<br />";
$duration=round($pkg->db->msec/1000,3);
echo "Time: $duration msec<br />";

echo "Results ".($start+1)."-$to of $nres: ";

Expand Down Expand Up @@ -277,6 +280,9 @@
</script>
<?php
}
if ($newsearch){
$db->addsearch($_SERVER["REMOTE_ADDR"],$name,$desc,$file,$repo,time(),$nres,$duration);
}
if (!($name or $desc or $file)){
echo "<br><table width=100% style='border-top:1px dotted #000000;border-bottom:1px dotted #000000;'>";
echo "<tr>";
Expand Down
16 changes: 16 additions & 0 deletions htdocs/libs/database.inc.php
Expand Up @@ -34,6 +34,18 @@ public function createdb(){
PRIMARY KEY ( field )
) ENGINE = InnoDB;
"))return false;
if(!$thie->db->query("
CREATE TABLE IF NOT EXISTS #__searches (
dt DATETIME,
sname VARCHAR(50),
sdesc VARCHAR(50),
sfile VARCHAR(50),
ip VARCHAR(15),
srepo INT,
results INT,
duration INT
) ENGINE = InnoDB;
"))return false;
$this->db->query("INSERT INTO #__mixed (field,value) value ('count_visits','1');");
$this->db->query("INSERT INTO #__mixed (field,value) value ('count_searches','1');");
$this->db->query("INSERT INTO #__mixed (field,value) value ('count_srctxt','1');");
Expand All @@ -49,6 +61,10 @@ public function counter_get($counter){
public function counter_inc($counter){
$this->db->query("update #__mixed set value = (value +1) where field='count_$counter';");
}
public function addsearch($ip,$name,$desc,$file,$repo,$date,$results,$duration){
$this->db->insert("searches",array("ip" => $ip, "sname" => $name, "sdesc" => $desc, "sfile" => $file, "srepo" => $repo,
"dt" => date("Y-m-d H:i:s",$date), "results" => $results, "duration" => $duration*1000));
}
}


Expand Down

0 comments on commit d46b289

Please sign in to comment.