~fkooman/vpn-user-portal

7f0af2c6acc18041f33dfc10c2eedd52e17ddb79 — François Kooman 3 months ago 63ded89
remove protocol negotiation from API
1 files changed, 0 insertions(+), 30 deletions(-)

M src/VpnApiModule.php
M src/VpnApiModule.php => src/VpnApiModule.php +0 -30
@@ 64,7 64,6 @@ class VpnApiModule implements ServiceModuleInterface
                    /** @var \LC\Portal\OAuth\VpnAccessTokenInfo */
                    $accessTokenInfo = $hookData['auth'];

                    $protoSupport = self::determineProtoSupport($request);
                    $profileList = $this->serverClient->getRequireArray('profile_list');
                    $userPermissions = $this->getPermissionList($accessTokenInfo);



@@ 76,9 75,6 @@ class VpnApiModule implements ServiceModuleInterface

                    $userProfileList = [];
                    foreach ($profileList as $profileId => $profileData) {
                        if (!\in_array('openvpn', $protoSupport, true)) {
                            continue;
                        }
                        $profileConfig = new ProfileConfig(new Config($profileData));
                        if ($profileConfig->hideProfile()) {
                            continue;


@@ 464,30 460,4 @@ class VpnApiModule implements ServiceModuleInterface

        return new DateTime($this->serverClient->getRequireString('user_session_expires_at', ['user_id' => $accessTokenInfo->getUserId()]));
    }

    /**
     * Return the list of protocols the client claims to support. Client is
     * assumed to support all protocols if the X-Proto-Support header is not
     * set.
     *
     * @return array<string>
     */
    private static function determineProtoSupport(Request $request)
    {
        $supportedProtoList = ['openvpn', 'wireguard'];
        if (null === $protoSupportHeader = $request->optionalHeader('HTTP_X_PROTO_SUPPORT')) {
            // client claims to support everything
            return $supportedProtoList;
        }

        $availableProtoList = [];
        $requestProtoList = explode(',', $protoSupportHeader);
        foreach ($requestProtoList as $requestProto) {
            if (\in_array($requestProto, $supportedProtoList, true)) {
                $availableProtoList[] = $requestProto;
            }
        }

        return $availableProtoList;
    }
}