<?php
//////////PARAMETROS/////
$pbx_admin="jcadmin";
$pbx_passw="Sapoop2382";
$pbx_ip="192.168.22.2";


function tokenize($sext)
	{
	$hash=md5($sext."-JDA_MITRU:PBX");
	$hash=md5(substr($hash, 16, 10)."JHSDUY83JSDF873QDKMG83".substr($hash, 0, 10));
	$hash=md5("JDA".$hash);
	return $hash;
	}

$token1=$_GET["token"];
$ext=$_GET["ext"];
$token2=tokenize($ext);
if($token1!=$token2)
	{
	echo("Error de TOKEN.");
	exit;
	}

$uid=uniqid();
$ckfile="cookie.txt";
//$cookiefile = fopen($ckfile, "w") or die("Unable to open file!");
//fclose($cookiefile);
//$ckfile="COOKIE_$uid.txt";
$url = "http://$pbx_ip/admin/config.php";
$fields = array(
					'username' => "$pbx_admin",
					'password' => "$pbx_passw"
					);
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
$result = curl_exec($ch);
echo($result);
//LOGIN TERMINADO

$url = "http://$pbx_ip/admin/config.php?display=extensions&extdisplay=".$ext."&action=del";
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
$result = curl_exec($ch);
echo($result);

exec("fwconsole reload", $output);
print_r($output);
//unlink("$uid.".csv"");
?>