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, 10 de enero de 2026

Dialing and getting DIALSTATUS

#!/usr/bin/env php

<?php


echo "EXEC Dial \"PJSIP/6002,7\"\n";


echo "GET VARIABLE DIALSTATUS\n";


$dstatus=null;

while($line= fgets(STDIN)){


if (strpos($line, "result=1") !== false) {


echo "EXEC Verbose \"$line \"\n";


$dstatus=explode(')',$line);


$dstatus=explode('(',$dstatus[0])[1];


echo "EXEC Verbose \"$dstatus\"\n";


break;

}

}

if($dstatus!='ANSWER'){


echo "EXEC Playback im-sorry\n";


}


?>


;;;;;;;;;;;;;;;;;;;


[dial_AGI]

exten=>2001,1,AGi(/root/agi.php)

same=>n,hangup()


viernes, 9 de enero de 2026

Custom Ringroup

[internal]

exten=>2000,1,Answer()
same=>n,Agi(/var/www/html/mysql_class/extensions_list.php)
same=>n(restart),Set(i=0)
same=>n,NoOp(Ext=${HASH(extension,${i})})
same=>n,NoOp(Timeout=${HASH(timeout,${i})})
same=>n,NoOp(-------------- Total number of extensions to call $[${lastExten}+1] -------)
same=>n,While($["${DIALSTATUS}" != "ANSWER"])
same=>n,NoOp(Calling extension ${HASH(extension,${i})} / Last status ${DIALSTATUS})
same=>n,Dial(PJSIP/${HASH(extension,${i})},${HASH(timeout,${i})})
same=>n,ExecIf($["${DIALSTATUS}"="ANSWER"]?Hangup())
same=>n,GotoIf($[${i}>=${lastExten}]?restart)
same=>n,Set(i=$[${i}+1])
same=>n,NoOp(Next extension ${HASH(extension,${i})} | Total $[${lastExten}+1])
same=>n,EndWhile()
same=>n,Hangup()




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#!/usr/bin/env php
<?php

require_once(__DIR__."/dbManager.php");

$db=new dbManager(
    host:'127.0.0.1',
    user:'root',
    password:'7136',
    db:'test_db'
);

$extensions=$db->select("SELECT * FROM extensions ORDER BY position ASC");

echo "Answer\n";

$i=0;

foreach($extensions as $ext){
    echo "{$ext['number']} {$ext['position']}\n";
    echo "SET VARIABLE HASH(extension,{$i}) \"{$ext['number']}\"\n";
    echo "SET VARIABLE HASH(timeout,{$i}) \"{$ext['timeout']}\"\n";
    $i++;
}

$lastExten=count($extensions)-1;

echo "SET VARIABLE lastExten \"{$lastExten}\"\n";
echo "EXEC Verbose \"Total of extensions to call: from 0 to {$lastExten}\" 1\n";

?>

;;;;;;;;;;;;;;;;;;;;;;;;;;;CLASS


<?php

declare(strict_types=1);

class dbManager
{
    private string $host;
    private string $user;
    private string $password;
    private string $db;

    private ?PDO $pdo = null;

    /**
     * Internal documentation array for methods
     */
    private static array $docs = [
        '__construct' => [
            'description' => 'Create a database connection.',
            'example' => "new dbManager(host: '127.0.0.1', user: 'root', password: 'pass', db: 'test')"
        ],
        'updateConnection' => [
            'description' => 'Update the connection configuration; only provided parameters are updated.',
            'example' => "\$db->updateConnection(user: 'newuser')"
        ],
        'insert' => [
            'description' => 'Insert a row and return last insert ID.',
            'example' => "\$db->insert(\"INSERT INTO users (name,status) VALUES (:name,:status)\", ['name'=>'John','status'=>'active'])"
        ],
        'select' => [
            'description' => 'Select multiple rows.',
            'example' => "\$db->select(\"SELECT * FROM users WHERE status = :status\", ['status'=>'active'])"
        ],
        'selectOne' => [
            'description' => 'Select single row or null.',
            'example' => "\$db->selectOne(\"SELECT * FROM users WHERE id = :id\", ['id'=>1])"
        ],
        'update' => [
            'description' => 'Update rows and return affected count.',
            'example' => "\$db->update(\"UPDATE users SET status=:status WHERE id=:id\", ['status'=>'inactive','id'=>1])"
        ],
        'delete' => [
            'description' => 'Delete rows and return affected count.',
            'example' => "\$db->delete(\"DELETE FROM users WHERE id=:id\", ['id'=>1])"
        ],
        'getConInfo' => [
            'description' => 'Return current connection information.',
            'example' => "\$db->getConInfo()"
        ],
        'printMethods' => [
            'description' => 'Print all documented public methods with description and usage.',
            'example' => "dbManager::printMethods()"
        ]
    ];

    /**
     * Constructor
     */
    public function __construct(string $host, string $user, string $password, string $db)
    {
        $this->validateHost($host);

        if (trim($user) === '' || strlen($user) < 3) {
            throw new InvalidArgumentException('Username must be at least 3 characters long');
        }

        $this->host = $host;
        $this->user = $user;
        $this->password = $password;
        $this->db = $db;

        $this->connect();
    }

    /**
     * Connect to the database
     */
    private function connect(): void
    {
        $dsn = "mysql:host={$this->host};dbname={$this->db};charset=utf8mb4";
        try {
            $this->pdo = new PDO($dsn, $this->user, $this->password, [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
            ]);
        } catch (PDOException $e) {
            echo $e->getMessage();
            exit;
        }
    }

    /**
     * Update connection configuration
     */
    public function updateConnection(?string $host = null, ?string $user = null, ?string $password = null, ?string $db = null): void
    {
        if ($host !== null) {
            $this->validateHost($host);
            $this->host = $host;
        }

        if ($user !== null) {
            if (trim($user) === '' || strlen($user) < 3) {
                throw new InvalidArgumentException('Username must be at least 3 characters long');
            }
            $this->user = $user;
        }

        if ($password !== null) {
            $this->password = $password;
        }

        if ($db !== null) {
            $this->db = $db;
        }

        $this->connect();
    }

    /**
     * CRUD Methods
     */
    public function insert(string $sql, array $params = []): int
    {
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        return (int)$this->pdo->lastInsertId();
    }

    public function select(string $sql, array $params = []): array
    {
       
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        return $stmt->fetchAll();
    }

    public function selectOne(string $sql, array $params = []): ?array
    {
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        $result = $stmt->fetch();
        return $result === false ? null : $result;
    }

    public function update(string $sql, array $params = []): int
    {    
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        return $stmt->rowCount();
    

     }

    public function delete(string $sql, array $params = []): int
    {
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        return $stmt->rowCount();
    }

    /**
     * Get connection info
     */
    public function getConInfo(): array
    {
        return [
            'host' => $this->host,
            'user' => $this->user,
            'database' => $this->db
        ];
    }

    /**
     * Print all documented public methods with description and usage
     */
    public static function printMethods(): void
    {
        foreach (self::$docs as $method => $info) {
            echo $method . "()\n";
            echo "  Description: " . $info['description'] . "\n";
            echo "  Example: " . $info['example'] . "\n\n";
        }
    }

    /**
     * Validate host/IP
     */
    private function validateHost(string $host): void
    {
        if (!filter_var($host, FILTER_VALIDATE_IP) &&
            !filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
        ) {
            throw new InvalidArgumentException('Invalid host or IP address');
        }
    }
}
?>