<?php
include '../config.php';
$service=getService($_GET['service']);
$machine=getMachine($service->machine_id);
$host=$machine->host;
$proto=$service->protocol;
$port=$service->port;
$sleep=$service->interval;
$count=$service->count;
$extra=isset($_GET['manuall']);
$html_file = dirname(__FILE__)."/../txt/html.txt";
$sip_file = dirname(__FILE__)."/../txt/opt.txt";
if($extra){
sleep(30);
}
$chk_return=false;
if($proto=="http") {
$cmd = "cat $html_file | nc $host $port 2>/dev/null";
$chk_return=true;
}
else {
if ($proto=="sip") {
$cmd = "cat $sip_file | nc -u $host $port -w2 2>/dev/null";
}
else {
die("unknown protocol $proto<br/>");
}
}
for($i=0; $i<$count; $i++){
exec ($cmd,$out,$return);
if(count($out)>0 || ($return==0 && $chk_return)){
echo "started ".$_GET['service'];
die();
}
sleep($sleep);
if($extra){
sleep(5);
}
}
echo "failed ".$_GET['service'];
die();
?>