<?php
#################################################################################
#                                                                            
    #
# Mosucker 3.0 PHP Notification Script. Copyright by Geeto (Geeto@flamenap.net) #
#            Translated to PHP from Zeloran's CGI Notfication Script         
    #
#                                                                            
    #
#################################################################################

$time = explode(":", date("h:i"));

$filename = getenv("DOCUMENT_ROOT")."/mophp/online.txt";
$ip = getenv("REMOTE_ADDR");

if (!file_exists($filename))
{
   $handle = fopen ($filename, "w");
   fclose($handle);
}

$in = fopen ($filename, "r");
$lines = explode("\n",fread($in, filesize ($filename)));
fclose($in);

$counter = 0;

if (count($lines) > 0){
foreach ($lines as $element) {
  $parameter1 = explode("#", $element);
  $parameter2 = $time;

  if($parameter1[0] <= $parameter2[0]) {
    $buffer1 = $parameter2[0] - $parameter1[0];
    $buffer2 = $parameter2[1] - $parameter1[1];
    $buffer3 = ($buffer1 * 60) + $buffer2;
  } else {
    $buffer1 = $parameter2[0] - $parameter1[0] + 24;
    $buffer2 = $parameter2[1] - $parameter1[1];
    $buffer3 = ($buffer1 * 60) + $buffer2;
  }
  if($buffer3 <= 10) {
    $new[$counter] = "$element";
    ++$counter;
  }
}
}

$out = fopen ($filename, "w");
if (count($new) > 0){
foreach ($new as $element) {
  fwrite($out,$element."\n");
}
}
fclose($out);

echo "START\n";
if (count($new) > 0){
foreach ($new as $element) {
  $output = true;
  $parameters = explode("#", $element);

  if($parameter[ip] != "" && $parameters[2] != $parameter[ip]) {
    $output = false;
  }
  if($parameter[port] != "" && $parameters[3] != $parameter[port]) {
    $output = false;
  }
  if($parameter[nick] != "" && $parameters[4] != $parameter[nick]) {
    $output = false;
  }
  if($parameter[country] != "" && $parameters[5] != $parameter[country]) {
    $output = false;
  }
  if($parameter[visible] != "" && $parameters[6] != $parameter[visible]) {
    $output = false;
  }
  if($parameter[protected] != "" && $parameters[7] != $parameter[protected]) 
{
    $output = false;
  }
  if($parameter[about] != "" && $parameters[8] != $parameter[about]) {
    $output = false;
  }

  if($output == "true") {
    echo "$element";
  }

}
}
echo "STOP";
?>
