Soporte & Consultoria

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

domingo, 2 de junio de 2024

Ami event filter

 #!/usr/bin/php

<?php

require("setting.php");


// Establish connection to Asterisk Manager Interface

$socket = fsockopen($host, "5038", $errno, $errstr, 10);

if (!$socket) {

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

} else {

    // Send login action to AMI

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

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

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


    // Send WaitEvent action to AMI

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


    // Send Logoff action to AMI (to close the connection after receiving events)

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


    // Read AMI events

    while (!feof($socket)) {

        $result = fread($socket, 5000);

        $result .= date("Y-m-d H:i:s");

        $events = ["SoftHangupRequest", "Newchannel", "ChallengeResponseFailed", "InvalidPassword", "InvalidAccountID", "Hold", "Unhold"];


        // Check for specific events and take appropriate actions

        foreach ($events as $value) {

            if (preg_match("/\b$value\b/i", $result, $match)) {

                echo "$result\n";


                if ($value === "SoftHangupRequest") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Soft Hangup Request Event", $result);

                }


                if ($value === "Newchannel") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "New Channel Event", $result);

                }


                if ($value === "ChallengeResponseFailed") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Challenge Response Failed Event", $result);

                }


                if ($value === "InvalidPassword") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Invalid Password Event", $result);

                }


                if ($value === "InvalidAccountID") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Invalid Account ID Event", $result);

                }


                if ($value === "Hold") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Call is On Hold", $result);

                }


                if ($value === "Unhold") {

                    echo "$result\n";

                    mail("ambiorixg12@gmail.com", "Call has been Unheld", $result);

                }

            }

        }

    }

}


fclose($socket);

?>


No hay comentarios:

Publicar un comentario