Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

sábado, 11 de enero de 2025

getting read variable value from agi GET VAARIABLE

 #!/usr/bin/php

<?php


// Send the Read command to capture user input

echo "EXEC Read opt,demo-thanks,1\n";

flush(); // Ensure the command is sent to Asterisk


// Capture the response for EXEC Read

while (!feof(STDIN)) {

    $line = trim(fgets(STDIN));

    if (strpos($line, '200 result=') === 0) {

        break; // Stop reading after receiving the result

    }

}


// Send the GET VARIABLE command to retrieve the value of 'opt'

echo "GET VARIABLE opt\n";

flush(); // Ensure the command is sent to Asterisk


// Initialize a variable to store the result

$userInput = null;


// Capture the response for GET VARIABLE

while (!feof(STDIN)) {

    $line = trim(fgets(STDIN));

    if (preg_match('/^200 result=1 \((.*)\)$/', $line, $matches)) {

        $userInput = $matches[1]; // Store the captured value

        break;

    }

}


// Use the captured value

if ($userInput !== null) {

    echo "VERBOSE \"Captured user input: $userInput\"\n"; // Debug output to Asterisk CLI

    flush();

}


?>


domingo, 22 de diciembre de 2024

while endwhile

 exten=>330,1,answer()

same=>n,Set(i=1)

same=>n,While($[${i} < 5])

;same=>n,Agi(/var/www/html/dial_agi.php,${i})

same=>n,Saydigits(${i})

same=>n,Set(i=$[${i} + 1])

same=>n,EndWhile()


;; code after  while end

same=>n,playback(demo-thanks)

same=>n,hangup()


jueves, 12 de diciembre de 2024

confbridge

cmd.php?coference=989898000036&action=resume



<?php
require_once("./confbridgeinfo.php");  // get conf channel info

//Function to run the  commands
function runcmd($command){

$socket = fsockopen("127.0.0.1","7831", $errno, $errstr,60);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: 193\r\n\r\n");

            fputs($socket, "Action: Command\r\n");
            fputs($socket, "Command: $command\r\n\r\n");

            fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){
          echo fgets($socket).'<br>';

 
           }
            fclose($socket);
            }


}       


// end  of the function section //

$coference=$_GET['coference'];

$action=$_GET['action'];

if($action=="hold"){
 $hold="channel originate Local/600@hold-context extension $coference@sidialConfBridges";


$agent_chan=get_conf_info($coference)[1];
 
$mute="confbridge mute $coference $agent_chan";
runcmd($hold);
runcmd($mute);

}

elseif($action=="resume"){

echo $hold_channel=get_conf_info($coference)[0];

 $unhold="channel request hangup $hold_channel";
 $unmute="confbridge unmute $coference all";

runcmd($unhold);
runcmd($unmute);
}
else {

///Nothing for now
}


?>

----------------------------


confbridgeinfo.php

<?php

$arr=array();


function  get_conf_info($agent){
$socket = fsockopen("127.0.0.1","7831", $errno, $errstr,60);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: 1333\r\n\r\n");

            fputs($socket, "Action: ConfbridgeList\r\n");
            fputs($socket, "Conference: $agent\r\n\r\n");

            fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){
         // echo fgets($socket).'<br>';
          $arr[]=fgets($socket);
 
           }
            fclose($socket);
            }


foreach($arr as $key=>$value){
//echo "$key - $value<br>";


if(substr_count($value,"hold")){
  
 
 $arr['channel']=  explode(" ",$value)[1];
  
}



elseif(substr_count($value,"SIP")){
  
 
 $arr['agent']=  explode(" ",$value)[1];
  
}


} 

if (isset($arr['agent'])) {
      
return   $channels=explode(" ","$arr[channel] $arr[agent]");



} else {
    // If the channel does not exist, create an error message and encode $arr
    $arr['e'] = "No conference channel found";

}

}


//print_r(get_conf_info($argv[1]));
?>

channel originate from AMI

 <?php



$conferece=$_GET['conference'];


$action=$_GET['action'];


if($action=="hold"){

 $command="channel originate Local/600@hold-context extension $conferece@contextConfBridges";


}


elseif($action=="resume"){




}

$socket = fsockopen("127.0.0.1","7831", $errno, $errstr,60);

      if (!$socket){

        echo "$errstr ($errno)\n";

        }else{

            fputs($socket, "Action: Login\r\n");

            fputs($socket, "UserName: admin\r\n");

            fputs($socket, "Secret: 113333\r\n\r\n");


            fputs($socket, "Action: Command\r\n");

            fputs($socket, "Command: $command\r\n\r\n");


            fputs($socket, "Action: Logoff\r\n\r\n");

           while (!feof($socket)){

          echo fgets($socket).'<br>';


 

           }

            fclose($socket);

            }

 
?>


get confbridge channel info

 <?php

header('Content-Type: application/json');

$arr=array();

$agent=$_GET['agent'];


$socket = fsockopen("127.0.0.1","7831", $errno, $errstr,60);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: 113333333\r\n\r\n");

            fputs($socket, "Action: ConfbridgeList\r\n");
            fputs($socket, "Conference: $agent\r\n\r\n");

            fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){
         // echo fgets($socket).'<br>';
          $arr[]=fgets($socket);
 
           }
            fclose($socket);
            }


foreach($arr as $key=>$value){
//echo "$key - $value<br>";  // to show  all values


if(substr_count($value,"hold")){   ///search value 
  
 
 $arr['channel']=  explode(" ",$value)[1];  //grab the exact info
  
}

} 

if (isset($arr['channel'])) {
      
    echo json_encode(array('channel' => trim($arr['channel'])));
//foreach($arr as  $k=>$v){
//echo  "$k:$v";

//}

} else {
    // If the channel does not exist, create an error message and encode $arr
    $arr['e'] = "No conference channel found";
    echo json_encode(array('e' => $arr['e']));

}


?>

domingo, 8 de diciembre de 2024

get channel name function

$channel = "SIP/8001-3455ac;";


function get_channel($channel, $device) {

    // Ensure $device is treated as a string for consistency in comparison

    if (strpos($channel, (string)$device) !== false) {

        // Use a more robust way to extract the channel before the dash

        return explode("-", $channel)[0];

    }

    return null;  // Return null if the device is not found

}



$device = 8001;

$channelResult = get_channel($channel, $device);


if ($channelResult) {

    echo "Channel: " . $channelResult;

} else {

    echo "Device not found in the channel.";

}


jueves, 5 de diciembre de 2024

channel redirect , channel originate, channel request hanguip

CLI> channel redirect SIP/989898000036-00000007 hold-context,600,1


989898000036@sidialConfBridges



channel redirect SIP/989898000036-00000007 sidialConfBridge,989898000036,1



 channel redirect SIP/989898000036-00000008 sidialConfBridges,989898000036,1


atest*CLI> channel originate Local/600@hold-context extension 989898000036@sidialConfBridges



atest*CLI> channel request hangup Local/600@hold-context-00000016;1

[hold-context]
exten => 600,1,Answer()
exten => 600,n,MusicOnHold(default)
exten => 600,n,Hangup()