示例#1
0
# Test User Agent
Aastra_test_phone_versions(array('1' => '1.4.2.', '2' => '1.4.2.', '3' => '2.5.3.', '4' => '2.5.3.', '5' => '3.0.1.'), '0');
# Retrieve phone information
$header = Aastra_decode_HTTP_header();
# Get phone language
$language = Aastra_get_language();
# Global compatibility
$nb_softkeys = Aastra_number_softkeys_supported();
# Keep URL
$XML_SERVER .= '?user='******'park':
        # Retrieve parking lot
        $parking = Aastra_get_park_config_Asterisk();
        # Parking lot configured
        if ($parking['parkext'] != '') {
            # Decompose the string
            $chars = preg_split('//', $parking['parkext'], -1, PREG_SPLIT_NO_EMPTY);
            # Send key sequence
            require_once 'AastraIPPhoneExecute.class.php';
            $object = new AastraIPPhoneExecute();
            $object->addEntry('Key:Xfer');
            foreach ($chars as $value) {
                switch ($value) {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
示例#2
0
function create_mac($mac, $extension, $username, $secret, $callerid, $model, $profile, $tz_name, $tz_code, $lang_code, $lang)
{
    global $AA_XML_SERVER;
    global $AA_PROXY_SERVER;
    global $AA_REGISTRAR_SERVER;
    global $AA_XMLDIRECTORY;
    global $AA_PRESENCE_STATE;
    global $AA_SPEEDDIAL_STATE;
    global $AA_ASK_TZ;
    global $AA_FREEPBX_MODE;
    global $language;
    # So far so good
    $return = True;
    # Read profile file
    if ($AA_FREEPBX_MODE == '1') {
        $array_profile = Aastra_readCFGfile($profile . '-user.prf', '#', ':');
    } else {
        $array_profile = Aastra_readCFGfile($profile . '-device-nouser.prf', '#', ':');
    }
    if (count($array_profile) == 0) {
        Aastra_debug('Profile file ' . $profile . ' not available');
        return False;
    }
    # Check if model is available
    if (count($array_profile[$model]) == 0) {
        Aastra_debug('Phone model ' . $model . ' not configured in the Profile file (' . $profile . ')');
        return False;
    }
    # Get park configuration
    $park = Aastra_get_park_config_Asterisk();
    # Get polling value
    $polling = Aastra_get_polling_interval_Asterisk();
    # Prepare replace strings
    $search = array('/\\$\\$AA_SIPAUTHNAME_AA\\$\\$/', '/\\$\\$AA_SIPSECRET_AA\\$\\$/', '/\\$\\$AA_SIPUSERNAME_AA\\$\\$/', '/\\$\\$AA_SIPCALLERID_AA\\$\\$/', '/\\$\\$AA_TZ_NAME_AA\\$\\$/', '/\\$\\$AA_TZ_CODE_AA\\$\\$/', '/\\$\\$AA_XML_SERVER_AA\\$\\$/', '/\\$\\$AA_PROXY_SERVER_AA\\$\\$/', '/\\$\\$AA_REGISTRAR_SERVER_AA\\$\\$/', '/\\$\\$AA_PARKINGLOT_AA\\$\\$/', '/\\$\\$AA_XMLDIRECTORY_AA\\$\\$/', '/\\$\\$AA_INTERCOM_CODE_AA\\$\\$/', '/\\$\\$AA_POLLING_INT_AA\\$\\$/');
    $replace = array(quotemeta($username), $secret, quotemeta($extension), quotemeta($callerid), $tz_name, $tz_code, $AA_XML_SERVER, $AA_PROXY_SERVER, $AA_REGISTRAR_SERVER, $park['parkext'], $AA_XMLDIRECTORY, Aastra_get_intercom_config_Asterisk(), $polling);
    # Also use the core piece for device and user
    if ($AA_FREEPBX_MODE == '2') {
        foreach ($array_profile['Core'] as $key => $value) {
            $line = preg_replace($search, $replace, $value);
            if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                $pieces = explode(' ', $key);
                $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
            }
            $array_config[$key] = $line;
        }
    }
    # Use the common piece
    foreach ($array_profile['Common'] as $key => $value) {
        $line = preg_replace($search, $replace, $value);
        if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
            $pieces = explode(' ', $key);
            $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
        }
        $array_config[$key] = $line;
    }
    # Model exists
    if ($array_profile[$model] != NULL) {
        # Check if full template
        if (key_exists('template', $array_profile[$model])) {
            $template = $array_profile[$model]['template'];
        } else {
            $template = $model;
        }
        # Use the template
        foreach ($array_profile[$template] as $key => $value) {
            if ($key != 'template') {
                $line = preg_replace($search, $replace, $value);
                if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                    $pieces = explode(' ', $key);
                    $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
                }
                $array_config[$key] = $line;
            }
        }
        # Use the add-ons
        if ($template != $model) {
            foreach ($array_profile[$model] as $key => $value) {
                if ($key != 'template') {
                    $line = preg_replace($search, $replace, $value);
                    $array_config[$key] = $line;
                }
            }
        }
    }
    # Read user custom configuration
    $array_user = Aastra_readCFGfile('user-custom.prf', '#', ':');
    # User/Device exists
    if ($array_user[$extension] != NULL) {
        # Use the user configuration additions
        foreach ($array_user[$extension] as $key => $value) {
            $line = preg_replace($search, $replace, $value);
            if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                $pieces = explode(' ', $key);
                $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
            }
            $array_config[$key] = $line;
        }
    }
    # Remove TZ if not needed
    if (!$AA_ASK_TZ) {
        unset($array_config['time zone name']);
        unset($array_config['time zone code']);
    }
    # Process language
    if ($lang_code != '') {
        $array_config['language'] = $lang_code;
        if (Aastra_test_phone_version('2.0.1.', '1') == 0) {
            $array_config['web language'] = $lang_code;
            $array_wl = array('fr' => 'French', 'it' => 'Italian', 'es' => 'Spanish', 'en' => 'English', 'de' => 'German', 'pt' => 'Portuguese');
            if ($array_wl[substr($lang, 0, 2)] != '') {
                $array_config['input language'] = $array_wl[substr($lang, 0, 2)];
            }
        }
    }
    # User mode
    if ($AA_FREEPBX_MODE == '1') {
        # Retrieve user keys
        $keys = Aastra_get_user_context($username, 'keys');
        # User has existing keys
        if (count($keys[$model]) != 0) {
            # Remove all profile keys
            foreach ($array_config as $key => $value) {
                if (stristr($key, 'key')) {
                    unset($array_config[$key]);
                }
            }
            # Add user keys
            foreach ($keys[$model] as $key => $value) {
                $array_config[$key] = $value;
            }
        }
        # Process day/night keys
        foreach ($array_config as $key => $value) {
            if (strstr($value, 'daynight.php')) {
                $pieces = explode(' ', $key);
                if (stristr($pieces[0], 'expmod')) {
                    $appli = $pieces[0] . ' ' . $pieces[1];
                } else {
                    $appli = $pieces[0];
                }
                $url = parse_url($value);
                parse_str($url['query'], $parse);
                if ($parse['index'] != '') {
                    $index = $parse['index'];
                } else {
                    $index = '';
                }
                if (!Aastra_is_daynight_appli_allowed_Asterisk($username, $index)) {
                    unset($array_config[$appli . ' type']);
                    unset($array_config[$appli . ' label']);
                    unset($array_config[$appli . ' value']);
                    unset($array_config[$appli . ' states']);
                }
            }
        }
        # Process presence
        if (!$AA_PRESENCE_STATE) {
            foreach ($array_config as $key => $value) {
                if (strstr($value, 'away.php')) {
                    $pieces = explode(' ', $key);
                    if (stristr($pieces[0], 'expmod')) {
                        $appli = $pieces[0] . ' ' . $pieces[1];
                    } else {
                        $appli = $pieces[0];
                    }
                    break;
                }
            }
            if ($appli != '') {
                unset($array_config[$appli . ' type']);
                unset($array_config[$appli . ' label']);
                unset($array_config[$appli . ' value']);
                unset($array_config[$appli . ' states']);
            }
        }
        # Process speed dial
        if (!$AA_SPEEDDIAL_STATE) {
            foreach ($array_config as $key => $value) {
                if (strstr($value, 'speed.php')) {
                    $pieces = explode(' ', $key);
                    if (stristr($pieces[0], 'expmod')) {
                        $appli = $pieces[0] . ' ' . $pieces[1];
                    } else {
                        $appli = $pieces[0];
                    }
                    break;
                }
            }
            if ($appli != '') {
                unset($array_config[$appli . ' type']);
                unset($array_config[$appli . ' label']);
                unset($array_config[$appli . ' value']);
                unset($array_config[$appli . ' states']);
            }
        }
    }
    # Translate the needed parameters
    foreach ($array_config as $key => $value) {
        $test = False;
        if (stristr($key, 'key') and stristr($key, 'label')) {
            $test = True;
        }
        if (stristr($key, 'xml application title')) {
            $test = True;
        }
        if ($test) {
            $array_config[$key] = Aastra_get_label($value, $language);
        }
    }
    # Config file
    $write = @fopen(AASTRA_TFTP_DIRECTORY . '/' . $mac . '.cfg', 'w');
    # No problem with the file
    if ($write) {
        # Dump the config file
        foreach ($array_config as $key => $value) {
            fputs($write, $key . ': ' . $value . "\n");
        }
        # Close the MAC.cfg file
        fclose($write);
    } else {
        # Trace
        Aastra_debug('Cannot write MAC.cfg (' . AASTRA_TFTP_DIRECTORY . '/' . $mac . '.cfg )');
        $return = False;
    }
    # Return result
    return $return;
}
function Aastra_check_park_Asterisk($user, $number)
{
    # No return
    $return = '';
    # Connect to AGI
    $as = new AGI_AsteriskManager();
    $res = $as->connect();
    # Prepare command
    if (Aastra_compare_version_Asterisk('1.6')) {
        $command1 = 'parkedcalls show';
        $command2 = 'core show channel';
        $param_channel = 1;
        $param_timeout = 6;
    } else {
        $command1 = 'show parkedcalls';
        $command2 = 'show channel';
        $param_channel = 1;
        $param_timeout = 6;
    }
    # Check current list
    $res = $as->Command($command1);
    $line = split("\n", $res['data']);
    $count = 0;
    $found = False;
    foreach ($line as $myline) {
        if (Aastra_compare_version_Asterisk('1.6') and !$found) {
            if (strstr($myline, 'Extension') and strstr($myline, 'Channel')) {
                $found = True;
                $linevalue = preg_split('/ /', $myline, -1, PREG_SPLIT_NO_EMPTY);
                $param_channel = array_search('Channel', $linevalue);
                $param_timeout = array_search('Timeout', $linevalue);
            }
        }
        if (!strstr($myline, 'Privilege') && !strstr($myline, 'Extension') && !strstr($myline, 'parked') && !strstr($myline, 'Parking') && $myline != '') {
            $linevalue = preg_split("/ /", $myline, -1, PREG_SPLIT_NO_EMPTY);
            if ($linevalue[0] != '' and is_numeric($linevalue[0])) {
                $park[$count]['orbit'] = $linevalue[0];
                $park[$count]['timeout'] = substr($linevalue[$param_timeout], 0, -1);
                $res_i = $as->Command($command2 . ' ' . $linevalue[$param_channel]);
                $line_i = @split("\n", $res_i['data']);
                foreach ($line_i as $myline_i) {
                    if (strstr($myline_i, 'Caller ID:')) {
                        $park[$count]['number'] = substr(substr(strrchr($myline_i, ":"), 1), 1);
                    }
                    if (substr($myline_i, 0, 10) == 'EXTTOCALL=') {
                        $temp[0] = substr(strrchr($myline_i, '='), 1);
                    }
                    if (substr($myline_i, 0, 17) == 'DIALEDPEERNUMBER=') {
                        $temp[1] = substr(strrchr($myline_i, '='), 1);
                    }
                    if (substr($myline_i, 0, 14) == 'FILTERED_DIAL=') {
                        $temp[2] = substr(strrchr($myline_i, '='), 1);
                    }
                    if (substr($myline_i, 0, 6) == 'FMGRP=') {
                        $temp[3] = substr(strrchr($myline_i, '='), 1);
                    }
                }
                for ($i = 0; $i < 4; $i++) {
                    if ($temp[$i] != '') {
                        $park[$count]['user'] = $temp[$i];
                        break;
                    }
                }
                unset($temp);
                $count++;
            }
        }
    }
    # Disconnect properly
    $as->disconnect();
    # Get Park config
    $conf_park = Aastra_get_park_config_Asterisk();
    # Find the right call
    $timeout = 0;
    $repark = 0;
    if ($number >= $conf_park['parkposmin'] and $number <= $conf_park['parkposmax']) {
        $repark = 1;
        $timeout = $conf_park['parkingtime'] - 20;
    }
    if (count($park) > 0) {
        foreach ($park as $key => $value) {
            if ($repark == 0) {
                if ($value['number'] == $number and $value['user'] == $user and $value['timeout'] > $timeout) {
                    $timeout = $value['timeout'];
                    $return = $value['orbit'];
                }
            } else {
                if ($value['user'] == $user and $value['timeout'] > $timeout) {
                    $timeout = $value['timeout'];
                    $return = $value['orbit'];
                }
            }
        }
    }
    # Return answer
    return $return;
}
示例#4
0
function generate_user_config($device, $user, $last_user)
{
    global $AA_XML_SERVER;
    global $AA_XMLDIRECTORY;
    global $AA_PRESENCE_STATE;
    global $AA_SPEEDDIAL_STATE;
    global $language;
    # Get type of phone
    $header = Aastra_decode_HTTP_header();
    $model = $header['model'];
    # Read profile file
    if ($user != '') {
        $profile = Aastra_get_startup_profile_Asterisk($user);
    } else {
        $profile = Aastra_get_startup_profile_Asterisk($device);
    }
    $array_user = Aastra_readCFGfile($profile . '-device-user.prf', '#', ':');
    $array_nouser = Aastra_readCFGfile($profile . '-device-nouser.prf', '#', ':');
    $array_custom = Aastra_readCFGfile('user-custom.prf', '#', ':');
    # Language
    $code = Aastra_ask_language_Asterisk();
    $ask_language = $code[0];
    # Retrieve user information
    $device_info = Aastra_get_device_info_Asterisk($device);
    # There is a user
    if ($user != '') {
        # Retrieve user information
        $user_info = Aastra_get_user_info_Asterisk($user);
        # Get park configuration
        $park = Aastra_get_park_config_Asterisk();
        # Get polling value
        $polling = Aastra_get_polling_interval_Asterisk();
        # Prepare replace strings
        $search = array('/\\$\\$AA_SIPUSERNAME_AA\\$\\$/', '/\\$\\$AA_SIPCALLERID_AA\\$\\$/', '/\\$\\$AA_XML_SERVER_AA\\$\\$/', '/\\$\\$AA_PARKINGLOT_AA\\$\\$/', '/\\$\\$AA_XMLDIRECTORY_AA\\$\\$/', '/\\$\\$AA_INTERCOM_CODE_AA\\$\\$/', '/\\$\\$AA_POLLING_INT_AA\\$\\$/');
        $replace = array($user_info['cidnum'], $user_info['cidname'], $AA_XML_SERVER, $park['parkext'], $AA_XMLDIRECTORY, Aastra_get_intercom_config_Asterisk(), $polling);
        # Use the common piece
        foreach ($array_user['Common'] as $key => $value) {
            if (!array_key_exists($key, $array_nouser['Core'])) {
                $line = preg_replace($search, $replace, $value);
                if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                    $pieces = explode(' ', $key);
                    $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
                }
                $array_out[$key] = $line;
            }
        }
        # Model exists
        if ($array_user[$model] != NULL) {
            # Check if full template
            if (key_exists('template', $array_user[$model])) {
                $template = $array_user[$model]['template'];
            } else {
                $template = $model;
            }
            # Use the template
            foreach ($array_user[$template] as $key => $value) {
                if ($key != 'template' and !array_key_exists($key, $array_nouser['Core'])) {
                    $line = preg_replace($search, $replace, $value);
                    if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                        $pieces = explode(' ', $key);
                        $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
                    }
                    $array_out[$key] = $line;
                }
            }
            # Use the add-ons
            if ($template != $model) {
                foreach ($array_user[$model] as $key => $value) {
                    if ($key != 'template') {
                        $line = preg_replace($search, $replace, $value);
                        $array_out[$key] = $line;
                    }
                }
            }
        }
        # User customization exists
        if ($array_custom[$user] != NULL) {
            # Use the user configuration additions
            foreach ($array_custom[$user] as $key => $value) {
                $line = preg_replace($search, $replace, $value);
                if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                    $pieces = explode(' ', $key);
                    $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
                }
                $array_out[$key] = $line;
            }
        }
        # Language
        if ($ask_language) {
            $array_language = Aastra_get_user_context($device, 'language');
            $array_out['language'] = $array_language['code'];
            $array_out['web language'] = $array_language['code'];
            $array_out['input language'] = $array_language['clear'];
            $language = $array_language['language'];
        }
    } else {
        # Use the common piece
        foreach ($array_user['Common'] as $key => $value) {
            if (!array_key_exists($key, $array_nouser['Core'])) {
                $array_out[$key] = '';
            }
        }
        # Model exists for the user
        if ($array_user[$model] != NULL) {
            # Check if full template
            if (key_exists('template', $array_user[$model])) {
                $template = $array_user[$model]['template'];
            } else {
                $template = $model;
            }
            # Use the template
            foreach ($array_user[$template] as $key => $value) {
                if ($key != 'template' and !array_key_exists($key, $array_nouser['Core'])) {
                    $array_out[$key] = '';
                }
            }
            # Use the add-ons
            if ($template != $model) {
                foreach ($array_user[$model] as $key => $value) {
                    if ($key != 'template') {
                        $array_out[$key] = '';
                    }
                }
            }
        }
        # Device customization exists
        if ($array_custom[$last_user] != NULL) {
            foreach ($array_custom[$last_user] as $key => $value) {
                if (!array_key_exists($key, $array_nouser['Core'])) {
                    $array_out[$key] = '';
                }
            }
        }
        # Prepare replace strings
        $search = array('/\\$\\$AA_SIPUSERNAME_AA\\$\\$/', '/\\$\\$AA_SIPCALLERID_AA\\$\\$/', '/\\$\\$AA_XML_SERVER_AA\\$\\$/', '/\\$\\$AA_PARKINGLOT_AA\\$\\$/', '/\\$\\$AA_XMLDIRECTORY_AA\\$\\$/');
        $replace = array($device, Aastra_get_callerid_Asterisk($device), $AA_XML_SERVER, $park['parkext'], $AA_XMLDIRECTORY);
        # Use the common piece
        foreach ($array_nouser['Common'] as $key => $value) {
            $line = preg_replace($search, $replace, $value);
            if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                $pieces = explode(' ', $key);
                $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
            }
            $array_out[$key] = $line;
        }
        # Model exists for the device
        if ($array_nouser[$model] != NULL) {
            # Check if full template
            if (key_exists('template', $array_nouser[$model])) {
                $template = $array_nouser[$model]['template'];
            } else {
                $template = $model;
            }
            # Use the template
            foreach ($array_nouser[$template] as $key => $value) {
                if ($key != 'template') {
                    $line = preg_replace($search, $replace, $value);
                    if (stristr($line, '$$AA_KEYPRESS_AA$$')) {
                        $pieces = explode(' ', $key);
                        $line = preg_replace('/\\$\\$AA_KEYPRESS_AA\\$\\$/', $pieces[0], $line);
                    }
                    $array_out[$key] = $line;
                }
            }
            # Use the add-ons
            if ($template != $model) {
                foreach ($array_nouser[$model] as $key => $value) {
                    if ($key != 'template') {
                        $line = preg_replace($search, $replace, $value);
                        $array_out[$key] = $line;
                    }
                }
            }
        }
        # Language
        if ($ask_language) {
            $array_out['language'] = '';
            $array_out['web language'] = '';
            $array_out['input language'] = '';
            $language = $code[1][$code[2]];
        }
    }
    # Process day/night keys
    foreach ($array_out as $key => $value) {
        if (strstr($value, 'daynight.php')) {
            $pieces = explode(' ', $key);
            if (stristr($pieces[0], 'expmod')) {
                $appli = $pieces[0] . ' ' . $pieces[1];
            } else {
                $appli = $pieces[0];
            }
            $url = parse_url($value);
            parse_str($url['query'], $parse);
            if ($parse['index'] != '') {
                $index = $parse['index'];
            } else {
                $index = 'ALL';
            }
            if (!Aastra_is_daynight_appli_allowed_Asterisk($username, $index)) {
                unset($array_out[$appli . ' type']);
                unset($array_out[$appli . ' label']);
                unset($array_out[$appli . ' value']);
                unset($array_out[$appli . ' states']);
            }
        }
    }
    # Process presence
    if (!$AA_PRESENCE_STATE) {
        foreach ($array_out as $key => $value) {
            if (strstr($value, 'away.php')) {
                $pieces = explode(' ', $key);
                if (stristr($pieces[0], 'expmod')) {
                    $appli = $pieces[0] . ' ' . $pieces[1];
                } else {
                    $appli = $pieces[0];
                }
                break;
            }
        }
        if ($appli != '') {
            unset($array_out[$appli . ' type']);
            unset($array_out[$appli . ' label']);
            unset($array_out[$appli . ' value']);
            unset($array_out[$appli . ' states']);
        }
    }
    # Process speed dial
    if (!$AA_SPEEDDIAL_STATE) {
        foreach ($array_out as $key => $value) {
            if (strstr($value, 'speed.php')) {
                $pieces = explode(' ', $key);
                if (stristr($pieces[0], 'expmod')) {
                    $appli = $pieces[0] . ' ' . $pieces[1];
                } else {
                    $appli = $pieces[0];
                }
                break;
            }
        }
        if ($appli != '') {
            unset($array_out[$appli . ' type']);
            unset($array_out[$appli . ' label']);
            unset($array_out[$appli . ' value']);
            unset($array_out[$appli . ' states']);
        }
    }
    # Remove 'logout' if device is fixed
    if ($user != '' and $device_info['type'] == 'fixed') {
        foreach ($array_out as $key => $value) {
            if (strstr($value, 'logout.php')) {
                $pieces = explode(' ', $key);
                if (stristr($pieces[0], 'expmod')) {
                    $appli = $pieces[0] . ' ' . $pieces[1];
                } else {
                    $appli = $pieces[0];
                }
                break;
            }
        }
        if ($appli != '') {
            unset($array_out[$pieces[0] . ' type']);
            unset($array_out[$pieces[0] . ' label']);
            unset($array_out[$pieces[0] . ' value']);
            unset($array_out[$pieces[0] . ' states']);
        }
    }
    # Find the special keys
    if ($user != '') {
        init_special_keys($device, $array_out);
    }
    # Translate labels
    foreach ($array_out as $key => $value) {
        $test = False;
        if (stristr($key, 'key') and stristr($key, 'label')) {
            $test = True;
        }
        if (stristr($key, 'xml application title')) {
            $test = True;
        }
        if ($test) {
            $array_out[$key] = Aastra_get_label($value, $language);
        }
    }
    # Return result
    return $array_out;
}