Soporte & Consultoria

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

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()

pjsip template

res_pjsip Configuration Examples

 

 ;===============TRANSPORT


[simpletrans]

type=transport

protocol=udp

bind=0.0.0.0


;===============ENDPOINT TEMPLATES


[endpoint-basic](!)

type=endpoint

context=internal

disallow=all

allow=ulaw


[auth-userpass](!)

type=auth

auth_type=userpass


[aor-single-reg](!)

type=aor

max_contacts=1


;===============EXTENSION 6001


[6001](endpoint-basic)

auth=auth6001

aors=6001


[auth6001](auth-userpass)

password=6001

username=6001


[6001](aor-single-reg)


;===============EXTENSION 6002


[6002](endpoint-basic)

auth=auth6002

aors=6002


[auth6002](auth-userpass)

password=6002

username=6002


[6002](aor-single-reg)


;===============EXTENSION 6003


[6003](endpoint-basic)

auth=auth6003

aors=6003


[auth6003](auth-userpass)

password=6003

username=6003


[6003](aor-single-reg)


https://docs.asterisk.org/Configuration/Channel-Drivers/SIP/Configuring-res_pjsip/res_pjsip-Configuration-Examples/

domingo, 1 de diciembre de 2024

Ajax call file

<title>AJAX Timer Example</title>


<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>


<script>


function callAgentConf() {

    // Fetch the session variable via PHP and inject it into the URL

    $.ajax({

        type: "GET",  // Use GET method

        url: "call_file.php",  // Path to the PHP script

        data: { wpExten: "<?= $_SESSION['wpExten']; ?>" },  // Pass the session variable using GET

        success: function(data) {

            console.log(data); // Log the response from the server

            if (data == 'ok') {

                txtCallStatus.innerHTML = "<i><?=$TEXT_Entrato_in_conferenza?></i>"; // Success message

                gotConf = false; // Set a variable (you can modify or use it as needed)

            } else {

                txtCallStatus.innerHTML = "<i><?=$TEXT_Errore_Non_entrato_in_conferenza?></i>"; // Error message

            }

        }

    });

}


// Call the function after 1 second

setTimeout('callAgentConf()', 1000);

</script> </head> <body>

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

 <?php

session_start();  // Make sure session is started if you are using session variables


// Retrieve the 'wpExten' GET parameter from the URL (passed via AJAX)

if (isset($_GET['wpExten'])) {

    // Use the GET parameter to set $myPaddedUserId

    $myPaddedUserId = "989898" . str_pad($_GET['wpExten'], 6, '0', STR_PAD_LEFT);


    // Debugging: Output the $myPaddedUserId to make sure it was set correctly

    // echo "Using wpExten: " . $myPaddedUserId;


    // Running the system command to kick the user from the conference bridge

    $sysCmd = "/usr/bin/sudo /usr/sbin/asterisk -rx 'confbridge kick ".$myPaddedUserId." all'";

    $foo = `$sysCmd`;  // Execute the system command


    // Prepare the .call file contents

    $callFilePath = "/tmp/" . rand(1000000, 9999999) . ".call";

    $dialString = "Channel: SIP/" . $myPaddedUserId;

    $callFileContents = $dialString . "\n" .

                        "MaxRetries: 0\n" .

                        "Context: sidialConfBridges\n" .

                        "Extension: " . $myPaddedUserId . "\n" .

                        "Set: myExten=" . $myPaddedUserId . "\n" .

                        "CallerID: conf <conf>\n" .

                        "WaitTime: 10";


    // Write the .call file

    $fh = fopen($callFilePath, "w");

    fwrite($fh, $callFileContents);

    fclose($fh);


    // Move the .call file to the outgoing directory

    $sysCmd = "/usr/bin/sudo /bin/mv " . $callFilePath . " /var/spool/asterisk/outgoing/" . rand(1000000, 9999999) . ".call";

    $foo = `$sysCmd`;  // Execute the system command


    // Output 'ok' to indicate success

    echo "ok";

} else {

    // If the 'wpExten' parameter is not provided, return an error

    echo "error: wpExten parameter missing";

}

?>