Exemplo n.º 1
0
/**
 * support function for disp_vpn_login()
 * it groups the list of enabled VPN providers by the "auth-user-pass" setting
 * @return array multidimensional array, first key defines group, second key is for group members
 */
function group_enabled_providers()
{
    global $_settings;
    $providers = array();
    //this is returned
    $enabled = $_settings->get_settings_array('VPN_PROVIDERS');
    foreach ($enabled as $ep) {
        $cmdret = array();
        $ovpns = get_ovpn_list($ep[1]);
        if (!array_key_exists(0, $ovpns)) {
            return FALSE;
        }
        //pick first one of the ovpn files to get "auth-user-pass" setting
        $inj = escapeshellarg('/pia/ovpn/' . $ovpns[0] . '.ovpn');
        exec('grep "auth-user-pass" ' . $inj . ' | gawk -F" " \'{print $2}\' ', $cmdret);
        $providers[$cmdret[0]][] = $ep[1];
    }
    //var_dump($providers);die('end');
    return $providers;
}
Exemplo n.º 2
0
/**
 * retrieves the name of the login file from one of the providers .ovpn files
 * @param type $VPN_provider
 * @return boolean|array
 * @throws Exception
 */
function VPN_get_loginfile($VPN_provider)
{
    if (!preg_match("/^[a-zA-Z]{3,10}+\\z/", $VPN_provider)) {
        throw new Exception('FATAL ERROR: invalid vpn_provider by user.');
    }
    $ovpns = get_ovpn_list($VPN_provider);
    if (!array_key_exists(0, $ovpns)) {
        return FALSE;
    }
    //pick first one of the ovpn files to get "auth-user-pass" setting
    $inj = escapeshellarg('/pia/ovpn/' . $ovpns[0] . '.ovpn');
    $cmdret = array();
    exec('grep "auth-user-pass" ' . $inj . ' | gawk -F" " \'{print $2}\' ', $cmdret);
    $login_file = $cmdret[0];
    if (!preg_match("/^\\/pia\\/login-[a-zA-Z]{3,10}\\.conf+\\z/", $login_file)) {
        throw new Exception('FATAL ERROR: invalid login file name retrieved');
    }
    return $login_file;
}