function Aastra_ask_language_Asterisk()
{
    $return[0] = False;
    $array = Aastra_readCFGfile(AASTRA_TFTP_DIRECTORY . '/aastra.cfg', '#', ':');
    if ($array['']['ask_language'] == '1') {
        $return[0] = True;
        $return[1][0] = 'en';
        for ($i = 1; $i < 5; $i++) {
            if ($array['']['language ' . $i] != '') {
                sscanf($array['']['language ' . $i], 'lang_%[^.].txt', $code);
                $return[1][$i] = $code;
            }
        }
    }
    $return[2] = $array['']['language'];
    return $return;
}
function Aastra_get_key_function($search, $mac)
{
    # Not found yet
    $return = '';
    # Read profile file
    $array = Aastra_readCFGfile(AASTRA_TFTP_DIRECTORY . '/' . $mac . '.cfg', '#', ':');
    # Look into each parameter
    foreach ($array[''] as $key => $value) {
        if (stristr($key, 'key')) {
            if (stristr($value, $search)) {
                $pieces = explode(' ', $key);
                $return = $pieces[0];
            }
        }
    }
    # Return result
    return $return;
}
Beispiel #3
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;
}
Beispiel #4
0
 # Compute what to do
 $test = False;
 if ($header['model'] == 'Aastra6739i') {
     if (Aastra_test_phone_version('3.2.0.', 1, $header) == 0) {
         $test = True;
     }
 } else {
     if (Aastra_is_dynamic_sip_supported()) {
         $test = True;
     }
 }
 # Depending on Dynamic SIP support
 if ($test) {
     # Get new configuration
     $array_mac = Aastra_readCFGfile(AASTRA_TFTP_DIRECTORY . '/' . $header['mac'] . '.cfg', '#', ':');
     $array_aastra = Aastra_readCFGfile(AASTRA_TFTP_DIRECTORY . '/aastra.cfg', '#', ':');
     $array_intersect = array_intersect_key($array_aastra[''], $array_mac['']);
     foreach ($array_mac[''] as $key => $value) {
         $array_config[$key] = '';
     }
     foreach ($array_intersect as $key => $value) {
         $array_config[$key] = $value;
     }
     # Save config
     Aastra_save_user_context($user, 'logout', $array_config);
     # Erase mac.cfg
     Aastra_delete_mac($header['mac']);
     # How many pages?
     $last = intval(count($array_config) / AASTRA_MAXCONFIGURATIONS);
     if (count($array_config) - $last * AASTRA_MAXCONFIGURATIONS != 0) {
         $last++;
Beispiel #5
0
function extra_keys($user, $header, $array_saved, $array_user)
{
    global $AA_XML_SERVER, $AA_PROXY_SERVER, $AA_REGISTRAR_SERVER, $AA_XMLDIRECTORY;
    # Retrieve user profile
    $profile = Aastra_get_startup_profile_Asterisk($user);
    $array_profile = Aastra_readCFGfile($profile . '-user.prf', '#', ':');
    # Retrieve extra keys
    $array_extra = array();
    foreach ($array_profile['Extra'] as $key => $value) {
        if (strstr($key, 'extrakey')) {
            $explode = explode(' ', $key);
            switch ($explode[1]) {
                case 'type':
                case 'label':
                case 'value':
                case 'states':
                case 'exclude':
                    $array_extra[$explode[0]][$explode[1]] = $value;
                    break;
            }
        }
    }
    # Prepare replace strings
    $search = array('/\\$\\$AA_XML_SERVER_AA\\$\\$/', '/\\$\\$AA_PROXY_SERVER_AA\\$\\$/', '/\\$\\$AA_REGISTRAR_SERVER_AA\\$\\$/', '/\\$\\$AA_XMLDIRECTORY_AA\\$\\$/');
    $replace = array($AA_XML_SERVER, $AA_PROXY_SERVER, $AA_REGISTRAR_SERVER, $AA_XMLDIRECTORY);
    # Filter extra keys
    foreach ($array_extra as $key => $value) {
        if (!isset($value['type']) or !isset($value['label']) or !isset($value['value'])) {
            unset($array_extra[$key]);
        } else {
            if ($array_extra[$key]['type'] == 'xml') {
                $array_extra[$key]['value'] = preg_replace($search, $replace, $array_extra[$key]['value']);
            }
            if (isset($value['exclude'])) {
                $explode = explode(',', $value['exclude']);
                if (in_array($header['model'], $explode)) {
                    unset($array_extra[$key]);
                }
            }
        }
    }
    # Filter compare to deleted keys
    if (isset($array_saved[$header['model']])) {
        foreach ($array_saved[$header['model']] as $key => $value) {
            foreach ($array_extra as $key2 => $value2) {
                if ($value['type'] == $value2['type'] and $value['value'] == $value2['value']) {
                    unset($array_extra[$key2]);
                    break;
                }
            }
        }
    }
    # Filter compare to current keys
    if (isset($array_user)) {
        foreach ($array_user as $key => $value) {
            foreach ($array_extra as $key2 => $value2) {
                if ($value['type'] == $value2['type'] and $value['value'] == $value2['value']) {
                    unset($array_extra[$key2]);
                    break;
                }
            }
        }
    }
    # Return extra keys
    return $array_extra;
}
Beispiel #6
0
function update_user_keys($user)
{
    # Get MAC address and type of phone
    $header = Aastra_decode_HTTP_header();
    # Read config file
    $array_temp = Aastra_readCFGfile(AASTRA_TFTP_DIRECTORY . '/' . $header['mac'] . '.cfg', '#', ':');
    $array_config = $array_temp[''];
    # Update user keys
    $keys = Aastra_get_user_context($user, 'keys');
    foreach ($array_config as $key => $value) {
        if (stristr($key, 'key')) {
            $array_key[$key] = $value;
        }
    }
    $keys[$header['model']] = $array_key;
    Aastra_save_user_context($user, 'keys', $keys);
}