Page Multiple Tenants at Once
If you would require to page to all or to a certain number of tenants at once, you can create a very simple custom script. See our Custom Scripts page on Developer Resource Center.

2007-10-13

ScopServ Telephony 1.4.5, Asterisk 1.4.13 and Wanpipe 3.2.0
more...



Opération de Masse (Base de données)

Vous pouvez construire des scripts personnalisés pour lister/éditer/effacer les informations de la base de données de ScopServ.  Sur cette page, vous trouverez la bibliothèque de base et des échantillons multiples de code qui démontrent comment changer les informations sur la base de données de ScopServ.

Veuillez noter que des connaissances en programmation PHP sont requises.

Veuillez se référer à ScopServ API pour plus de détails sur les fonctions disponibles.

  • Désactiver l'enveloppe de la messagerie vocale et changer le mot de passe de 1234 en aléatoire. (Exemple #1)
  • Lister toutes les informations des Codecs pour chaque extensions. (Exemple #2)
  • Mettre les codecs 'ulaw', 'g729' and 'gsm' pour toutes les extensions. (Exemple #3)
  • Désactiver la limite d'appel pour toutes les extensions. (Exemple #4)
  • Activer le transfert d'appel sur toutes les lignes entrantes. (Exemple #5)
  • Script en ligne de commande pour ajouter des compositions abrégées. (Exemple #6)
  • Activer 'Use User-Local CallForward' pour toutes les lignes entrantes. (Exemple #7)
  • Activer 'DUNDi' pour toutes les extensions (Exemple #8)
  • Mettre le temps de sonnerie maximum sur 15 secondes pour les extensions 1000 à 5000. (Exemple #9)
  • Modifie le mot de passe dans la messagerie vocale et l'interface Web pour faire coïncider le numéro d'extension. (Exemple #10)
  • Comment importer des données en liste blanche de SQL pour des restrictions d'appel sortant. (Exemple #11)
  • Microbrowser support is awesome! Now I have thousands of phones to enable microbrowser. (Example #12)
  • Enable Voicemail and MWI for all extensions. Use extension as password. (Example #13)
  • External (SQL) CallerID Lookup on Outgoing Lines. (Example #14)
  • Set 'Call Forward on Busy' to Voicemail for all Extensions. (Example #15)

    Bbliothèque de base des applications ScopServ.

    Afin de créer des scripts d'opérations de masse, vous devez définir quelques variables et charger la bibliothèque de base. Pour vous aider dans cette tache, nous avons créé un script très simple. Sauvegarder le fichier comme/var/www/scopserv/telephony/contrib/base.php et incluez le dans vos scripts.

    <?php
    // No auth.
    @define('AUTH_HANDLER'true);
    @
    define('TELEPHONY_COMMIT'true);
    ini_set('include_path''/var/www/scopserv/framework');

    @
    define('TELEPHONY_BASE''/var/www/scopserv/telephony');
    require_once 
    TELEPHONY_BASE '/lib/base.php';

    require_once 
    'Console/Getopt.php';
    require_once 
    'Horde/CLI.php';
    require_once 
    'Horde/Array.php';

    // Load the CLI environment - make sure there's no time limit, init
    // some variables, etc.
    $c = &new Horde_CLI();

    // Make sure no one runs this from the web.
    if (!$c->runningFromCLI()) {
        
    $c->fatal(_("This script must be run from the command line."));
    }
    $c->init();

    /* Make sure there's no compression. */
    @ob_end_clean();


    Désactiver l'enveloppe de la messagerie vocale et changer le mot de passe de 1234 en aléatoire.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all users from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        
    /* Set default value to false */
        
    $changed false;
        
        
    /* Get info Extension number */
        
    $ext $info['phone_extension'];
        
        print 
    "Extension $ext ...\n";
        
    /* Check if Voicemail Envelope is defined and set it to false */
        
    if (isset($info['phone_vm_envelope'])) {
        
    $info['phone_vm_envelope'] = false;
        
    $changed true;
        print 
    " - VM Envelope disabled.\n";
        }
        
        
    /* If the Password (SIP) is set to 1234, changed it to random password */
        
    if (isset($info['phone_password']) && $info['phone_password'] == '1234') {
        
    $newpass generatePassword();
        
    $info['phone_password'] = $newpass;
        print 
    " - Password changed to $newpass\n";
        
    $changed true;
        }

        
    /* If infos have changed, save it */
        
    if ($changed) {
        
    $ext_id $telephony->saveExtension($info);
        }
        
        print 
    "Done.\n\n";
    }

    /* Generate a random password with alphanumeric */
    function generatePassword() {
        
        
    /* Password length (default: 6) */
        
    $length 6;
        
        
    /* Prefix */
        
    $pass   '';

        
    /* Characters set */
        
    $chars  "abcdefghijkmnopqrstuvwxyz023456789";
        
        
    $i      strlen($pass);
        
    srand((double)microtime()*1000000);
        
        while (
    $i <= $length) {
        
    $num rand() % 33;
        
    $tmp substr($chars$num1);
        
    $pass $pass $tmp;
        
    $i++;
        }

        
    /* Return generated password */
        
    return $pass;
    }


    Lister toutes les informations des Codecs pour chaque extensions.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all Phones from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        if (!isset(
    $info['phone_codec'])) {
        continue;
        }
        
        print 
    "Extension: " $info['phone_extension'] . "\n";
        print 
    "Codec : " implode(', '$info['phone_codec']) . "\n";
        print 
    "\n";
    }


    Mettre les codecs 'ulaw', 'g729' and 'gsm' pour toutes les extensions.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all Phones from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        if (!isset(
    $info['phone_codec'])) {
        continue;
        }
        
        
    $info['phone_codec'] = array('ulaw''g729''gsm');
        
    $telephony->saveExtension($info);
    }


    Désactiver la limite d'appel pour toutes les extensions.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all Phones from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        if (!isset(
    $info['phone_limit_in'])) {
        continue;
        }
        
        
    $info['phone_limit_in'] = '';
        
    $info['phone_limit_out'] = '';
        
    $info['phone_limit_sip_call'] = '';
        
        
    $telephony->saveExtension($info);
    }


    Activer le transfert d'appel sur toutes les lignes entrantes.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all Incoming Lines from backend. */
    $infos $telephony->getExtensions('line_in'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        
    /* Get the destination */
        
    $dest $info['line_in_destination'];
        
        
    /* Check if 'Use User-CallForward' is enabled */
        
    $uselocal = @$info['line_in_destination_ext_uselocal'];
        
        
    /* If Destination is 'Extension' and 'UseLocal' is not enabled */
        
    if ($dest == 'ext' && !$uselocal) {
        
        
    /* Enable 'Call Transfer' to 'Callee' */
        
    $info['line_in_destination_ext_transfer'] = 'callee';
        
        
    /* Save Informations */
        
    $telephony->saveExtension($info);
        }
    }


    Script en ligne de commande pour ajouter des compositions abrégées.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Add Speeddial Information */
    $args    Console_Getopt::readPHPArgv();
    $info = array();
    $info['type'] = 'speeddial';
    $info['speeddial_ext']    = $args[1];
    $info['speeddial_name']   = $args[2];
    $info['speeddial_number'] = $args[3];      
    $ext_id $telephony->saveExtension($info);
          


    Activer 'Use User-Local CallForward' pour toutes les lignes entrantes.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Add Speeddial Information */
    foreach($telephony->getExtensions('line_in'false) as $id => $info) {
        
    $dest $info['line_in_destination'];
        
        if (
    $dest == 'ext') {
        
    // print "$dest\n";
        
    $fb = isset($info['line_in_fallback']) ? $info['line_in_fallback'] : 'none';
        if (
    $fb == 'none') {
            
    $info['line_in_destination_ext_uselocal'] = true;
            
    $ext_id $telephony->saveExtension($info);
        }
        }
    }


    Activer 'DUNDi' pour toutes les extensions

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    // Loop through each phone extensions
    foreach($telephony->getExtensions('phone'false) as $id => $info) {

        if (
    in_array($info['phone_type'], array('vm''fax''agent'))) {
        continue;
        }
        
        
    $info['phone_dundi'] = true;
        
    $info['phone_dundi_number'] = $info['phone_extension'];
        
    $info['phone_dundi_context'] = '_default_';
        
        
    $telephony->saveExtension($info);
    }


    Mettre le temps de sonnerie maximum sur 15 secondes pour les extensions 1000 à 5000.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    // Loop through all phone extensions
    foreach($telephony->getExtensions('phone'false) as $id => $info) {

        
    $ext $info['phone_extension'];
        
        if (
    $ext >= 1000 && $ext <= 5000) {
        
        echo 
    sprintf("Ext %s: Ringtime %d -> %d\n"$ext$info['phone_maxtime'], 15);
        
    $info['phone_maxtime'] = 15;
        
    $telephony->saveExtension($info);
        }
    }


    Modifie le mot de passe dans la messagerie vocale et l'interface Web pour faire coïncider le numéro d'extension.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all users from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        
    /* Set default value to false */
        
    $changed false;
        
        
    /* Get info Extension number */
        
    $ext $info['phone_extension'];
        
        print 
    "Extension $ext ...\n";
        
    /* If the Voicemail is enable, change password to match the extension */
        
    if (isset($info['phone_vm']) && $info['phone_vm']) {
        
    $info['phone_vm_password'] = $ext;
        print 
    " - Password changed to $ext\n";
        
    $changed true;
        }

        
    /* If Web GUI is enable, change the username to match the extension number */
        
    if (isset($info['phone_user_gui']) && $info['phone_user_gui']) {
        
    $info['phone_web_username'] = $ext;
        print 
    " - Web GUI username changed to $ext\n";
        
    $changed true;
        }
        
        
    /* If infos have changed, save it */
        
    if ($changed) {
        
    $ext_id $telephony->saveExtension($info);
        }
        
        print 
    "Done.\n\n";
    }


    Comment importer des données en liste blanche de SQL pour des restrictions d'appel sortant.

    #!/usr/bin/php -q
    <?php

    /*
     
    Table structure for table 'whitelist'
    -------------------------------------------
      
    CREATE TABLE whitelist (
      phone_number varchar(32) NOT NULL,
      phone_name varchar(64) NOT NULL,
      phone_type varchar(32) NOT NULL,
      PRIMARY KEY  (phone_number)
    ) TYPE=MyISAM;

    CREATE INDEX phone_number ON whitelist (phone_number);

    Record structure for file 'whitelist.txt'
    -------------------------------------------

    NUMBER;NAME;TYPE
    8195551212;John Doe;PRIVATE
    5145551234;Mary Jane;PRIVATE
    5145550000;ACME Inc.;COMPANY

    */

    require_once '/var/www/scopdev/telephony/contrib/base.php';

    /* Record separator (; or ,) */
    $sep   ';';
    $table 'whitelist';
    $file  'whitelist.txt';

    if (!@
    file_exists($file)) {
        print 
    "Missing file: $file\n";
        exit;
    }

    $handle fopen($file"r");
    while ((
    $data fgetcsv($handle1000$sep)) !== FALSE) {
        
        
    $num  = (string)$data[0];
        
    $name $data[1];
        
    $type $data[2];
        
        
    $sql_sprintf 'INSERT INTO %s SET phone_number = %s, phone_name = %s, phone_type = %s';
        
        
    $sql sprintf($sql_sprintf,
               
    $table,
               
    $telephony->_db->quote($num),
               
    $telephony->_db->quote($name),
               
    $telephony->_db->quote($type));
        
        print 
    "Added $num to $table ... ";
        
    $telephony->_db->query($sql);
        print 
    "done\n";
        
    }


    Microbrowser support is awesome! Now I have thousands of phones to enable microbrowser.

    #!/usr/bin/php -q
    <?php

    /* Microbrowser support is awesome!
     * 
     * Now I have thousands of phones to enable microbrowser.
     * 
     * Please post script for phone APS and usage docs for the following:
     * 
     * - Use server LAN IP to configure internal microbrowser services.
     * - Use extension assigned to line 1 as extension to monitor
     * - Enable phone status and ACD status options for microbrowser
    **/
      
    // Ok, for this script, I have add both method to load the base
    // library config. If the base.php file exist on the contrib directory
    // it will load base config, else it use one defined on this script.
    // Not really useful but showed as example.
    if (file_exists('/var/www/scopserv/telephony/contrib/base.php')) {
        require_once 
    '/var/www/scopserv/telephony/contrib/base.php';
    } else {
        
    // No auth.
        
    @define('AUTH_HANDLER'true);
        @
    define('ASTERISK_COMMIT'true);
        
    ini_set('include_path''/var/www/scopserv/framework');
        
        @
    define('ASTERISK_BASE''/var/www/scopserv/telephony');
        require_once 
    ASTERISK_BASE '/lib/base.php';
        
        require_once 
    'Console/Getopt.php';
        require_once 
    'Horde/CLI.php';
        require_once 
    'Horde/Array.php';
        
        
    // Load the CLI environment - make sure there's no time limit, init
        // some variables, etc.
        
    $c = &new Horde_CLI();
        
        
    // Make sure no one runs this from the web.
        
    if (!$c->runningFromCLI()) {
        
    $c->fatal(_("This script must be run from the command line."));
        }
        
    $c->init();
        
        
    /* Make sure there's no compression. */
        
    @ob_end_clean();
    }

    /* Get Network Configurations */
    $server_configs $scopserv->getConfig('config');

    /* Get Network Configurations */
    $network_configs $scopserv->getConfig('network');

    /* Set informations for Server URL */
    // Check if we use HTTP or HTTPS (SSL) and use HTTP as default
    $proto  = @$server_configs['config_ssl'] ? 'https' 'http';
        
    // Get IP Address for LAN (use config_wan_ipaddr for WAN)
    $server implode('.'$network_configs['config_lan_ipaddr']);

    // Get Server Port from config and if use 5555 as default
    $port   = @$server_configs['config_port'] ? $server_configs['config_port'] : 5555;


    /* Get all Auto Provisioning System (APS) informations from backend. */
    $infos $telephony->getExtensions('aps'nulltruefalse);
    foreach(
    $infos as $id => $info) {

        
    // Status if informations have changed. Set default value to false.
        
    $changed false;
        
        
    // Get Phone Type
        
    $type $info['aps_aps_type'];
        
        
    // Check if Internal MicroBrowser variable is available
        
    if (isset($info['aps_mb_internal'])) {
        
        
    // Enable Internal MicroBrowser
        
    $info['aps_mb_internal'] = true;
        
        
    /* Set informations for Server URL */
        // Check if we use HTTP or HTTPS (SSL) and use HTTP as default
        
    $info['aps_mb_internal_proto'] = @$server_configs['config_ssl'] ? 'https' 'http';
        
        
    // Get IP Address for LAN (use config_wan_ipaddr for WAN)
        
    $info['aps_mb_internal_srv']   = implode('.'$network_configs['config_lan_ipaddr']);
        
        
    // Get Server Port from config and if use 5555 as default
        
    $info['aps_mb_internal_port']  = @$server_configs['config_port'] ? $server_configs['config_port'] : 5555;

        
    // Enable Phone and ACD status permissions for MicroBrowser
        
    $info['aps_mb_internal_show_acd']     = true;
        
    $info['aps_mb_internal_show_hotdesk'] = true;
        
    $info['aps_mb_internal_show_spy']     = false;

        
    // Use extension assigned to line 1 as extension to monitor
        // Special case for polycom phone that doesn't use same variable
        
    if (isset($info['aps_polycom_button_1'])) {
            
    $ext $info['aps_polycom_button_1'];
        } elseif (isset(
    $info['aps_button_1'])) {
            
    $ext $info['aps_button_1'];
        } else {
            
    $ext false;
        }
        
        
    // Set Extension to Monitor
        
    $info['aps_mb_internal_ext']   = $ext;
        
        
    // Set the status to Changed if an extension is defined
        
    if ($ext) {
            
            
    // Change status set to true
            
    $changed true;
            
            
    // Print information about Extension
            
    print "Enable Internal Microbrowser on Extension $ext ($type) ...\n";
        }
        }
        
        
    /* If infos have changed, save it */
        
    if ($changed) {
        
    $ext_id $telephony->saveExtension($info);
        }
        
    }

        


    Enable Voicemail and MWI for all extensions. Use extension as password.

    #!/usr/bin/php -q
    <?php

    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all users from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        
    /* Set default value to false */
        
    $changed false;
        
        
    /* Get info Extension number */
        
    $ext $info['phone_extension'];
        
        print 
    "Extension $ext ...\n";
        
        
    /* Enable Voicemail if it disabled */
        
    if (isset($info['phone_vm']) && !$info['phone_vm']) {
            
    $info['phone_vm']          = true// Enable Voicemail
            
    $info['phone_usemwi']      = true// Enable MWI
            
    $info['phone_vm_password'] = $ext// Set Password as Extension
            
    $changed true;
            print 
    " - Voicemail Enabled.\n";
        }
        
        
    /* If infos have changed, save it */
        
    if ($changed) {
            
    $ext_id $telephony->saveExtension($info);
        }
        
        print 
    "Done.\n\n";
    }


    External (SQL) CallerID Lookup on Outgoing Lines.

    #!/usr/bin/php -q
    <?php

    /*
    Table structure for table 'cidlookup'
    -------------------------------------------
      
    CREATE TABLE cidlookup (
      phone_number varchar(32) NOT NULL,
      calleridnum varchar(32) NOT NULL,
      calleridname varchar(64) NOT NULL,
      calleridpres varchar(32) NOT NULL,
      PRIMARY KEY  (phone_number)
    ) TYPE=MyISAM;

    CREATE INDEX phone_number ON cidlookup (phone_number);

    Record structure for file 'cidlookup.txt'
    -------------------------------------------

    NUMBER;CIDNUM;CIDNAME;CIDPRES
    1234;8195551212;John Doe;allowed_not_screened
    1000;5145551234;Mary Jane;allowed
    5555;5145550000;ACME Inc.;

    */

    require_once '/var/www/scopdev/telephony/contrib/base.php';

    /* Record separator (; or ,) */
    $sep   ';';
    $table 'cidlookup';
    $file  'cidlookup.txt';

    if (!@
    file_exists($file)) {
        print 
    "Missing file: $file\n";
        exit;
    }

    $handle fopen($file"r");
    while ((
    $data fgetcsv($handle1000$sep)) !== FALSE) {
        
        
    $num   = (string)$data[0];
        
    $cnum  $data[1];
        
    $cname $data[2];
        
    $cpres $data[3];
        
        
    $sql_sprintf 'INSERT INTO %s SET phone_number = %s, calleridnum = %s, calleridname = %s, calleridpres = %s';
        
        
    $sql sprintf($sql_sprintf,
               
    $table,
               
    $telephony->_db->quote($num),
               
    $telephony->_db->quote($cnum),
               
    $telephony->_db->quote($cname),
               
    $telephony->_db->quote($cpres));
        
        print 
    "Added $num to $table ... ";
        
    $telephony->_db->query($sql);
        print 
    "done\n";
        
    }


    Set 'Call Forward on Busy' to Voicemail for all Extensions.

    <?php

    // Load default libraries
    require_once '/var/www/scopserv/telephony/contrib/base.php';

    /* Get all users from backend. */
    $infos $telephony->getExtensions('phone'nulltruefalse);
    foreach(
    $infos as $id => $info) {
        
        
    // Set default value to false 
        
    $changed false;
        
        
    // Get info Extension number
        
    $ext $info['phone_extension'];

        
    // Check if Voicemail is enabled on the extension
        
    if (isset($info['phone_vm']) && $info['phone_vm']) {
        
        
    // Display the current extension
        
    print "Extension $ext ...\n";
        
        
    // Check if CF on Busy is defined and not set to 'none'
        
    if (isset($info['phone_user_cfob']) && $info['phone_user_cfob'] == 'none') {
            
            print 
    " - CallForward on Busy set to Voicemail ($ext)\n";
            
            
    // Set new information for CFOB
            
    $info['phone_user_cfob']           = 'vmail';
            
    $info['phone_user_cfob_vmail']     = $ext '/';
            
    $info['phone_user_cfob_vmail_msg'] = 'busy';
            
            
    // Set change flag to true
            
    $changed true;
        }
        
        }
        
        
    /* If infos have changed, save it */
        
    if ($changed) {
        
    // Save information on database
        
    $ext_id $telephony->saveExtension($info);
        }
        
    }