<?php
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;
	}
//$sec=$_GET["sec"];
$sec="!mitruHotel_06072018!";
//$nom=$_GET["nom"];
//$ape=$_GET["ape"];
$email="";
$lang="es";
$context="from-internal";
if ($ext=="" || !isset($_GET["ext"]))
	{
	echo("Faltan Parámetros");
	exit;
	}
$nomcompleto=$ext." VACIA";
$context="CheckOut";
$action="add";
$csv="action,extension,password,name,voicemail,ringtimer,noanswer,recording,outboundcid,sipname,noanswer_cid,busy_cid,chanunavail_cid,noanswer_dest,busy_dest,chanunavail_dest,mohclass,id,tech,dial,devicetype,user,description,emergency_cid,recording_in_external,recording_out_external,recording_in_internal,recording_out_internal,recording_ondemand,recording_priority,answermode,intercom,cid_masquerade,concurrency_limit,accountcode,allow,avpf,callerid,canreinvite,context,defaultuser,deny,disallow,dtmfmode,encryption,force_avp,host,icesupport,mailbox,namedcallgroup,namedpickupgroup,nat,permit,port,qualify,qualifyfreq,rtcp_mux,secret,sendrpid,sessiontimers,sipdriver,transport,trustrpid,type,videosupport,vmexten,callwaiting_enable,findmefollow_strategy,findmefollow_grptime,findmefollow_grppre,findmefollow_grplist,findmefollow_annmsg_id,findmefollow_postdest,findmefollow_dring,findmefollow_needsconf,findmefollow_remotealert_id,findmefollow_toolate_id,findmefollow_ringing,findmefollow_pre_ring,findmefollow_voicemail,findmefollow_changecid,findmefollow_fixedcid,findmefollow_enabled,languages_language,voicemail_enable,voicemail_vmpwd,voicemail_email,voicemail_pager,voicemail_options
".$action.",".$ext.",,\"".$nomcompleto."\",default,60,,,,,,,,,,,default,".$ext.",sip,SIP/".$ext.",fixed,".$ext.",\"".$nomcompleto."\",,dontcare,dontcare,dontcare,dontcare,disabled,10,disabled,enabled,".$ext.",3,,,no,\"device <".$ext.">\",no,".$context.",,0.0.0.0/0.0.0.0,,rfc2833,no,no,dynamic,no,".$ext."@device,,,no,0.0.0.0/0.0.0.0,5060,yes,60,no,".$sec.",pai,accept,chan_sip,\"udp,tcp,tls\",yes,friend,inherit,,ENABLED,ringallv2-prim,20,,".$ext.",,ext-local".$ext."dest,,,0,0,Ring,7,default,default,,,".$lang.",yes,".$ext.",".$email.",,attach=yes|saycid=yes|envelope=yes|delete=no";

$uid=uniqid("ADD_");
$csvFile = fopen($uid.".csv", "w") or die("No se puede crear el archivo.");
fwrite($csvFile, $csv);
fclose($csvFile);
$rutafile=realpath($uid.".csv");
exec("fwconsole bi --type='extensions' $rutafile", $output);
print_r($output);
echo("<br>_________________________________________<br><br>");
exec("fwconsole reload", $output);
print_r($output);
unlink($uid.".csv");
?>