mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-02-11 00:00:08 +08:00
Wrap eval config
This commit is contained in:
19
OpenVPN Adapter/OpenVPNProperties+Internal.h
Normal file
19
OpenVPN Adapter/OpenVPNProperties+Internal.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// OpenVPNProperties+Internal.h
|
||||
// OpenVPN Adapter
|
||||
//
|
||||
// Created by Sergey Abramchuk on 26.04.17.
|
||||
//
|
||||
//
|
||||
|
||||
#import <client/ovpncli.hpp>
|
||||
|
||||
#import "OpenVPNProperties.h"
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
@interface OpenVPNProperties (Internal)
|
||||
|
||||
- (instancetype)initWithEvalConfig:(ClientAPI::EvalConfig)eval;
|
||||
|
||||
@end
|
||||
79
OpenVPN Adapter/OpenVPNProperties.h
Normal file
79
OpenVPN Adapter/OpenVPNProperties.h
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// OpenVPNProperties.h
|
||||
// OpenVPN Adapter
|
||||
//
|
||||
// Created by Sergey Abramchuk on 26.04.17.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "OpenVPNTransportProtocol.h"
|
||||
|
||||
@class OpenVPNServerEntry;
|
||||
|
||||
@interface OpenVPNProperties : NSObject
|
||||
|
||||
/**
|
||||
This username must be used with profile
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSString *username;
|
||||
|
||||
/**
|
||||
Profile name of config
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSString *profileName;
|
||||
|
||||
/**
|
||||
"Friendly" name of config
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSString *friendlyName;
|
||||
|
||||
/**
|
||||
If YES no creds required, otherwise username/password required
|
||||
*/
|
||||
@property (readonly, nonatomic) BOOL autologin;
|
||||
|
||||
/**
|
||||
Static challenge, may be empty, ignored if autologin
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSString *staticChallenge;
|
||||
|
||||
/**
|
||||
YES if static challenge response should be echoed to UI, ignored if autologin
|
||||
*/
|
||||
@property (readonly, nonatomic) BOOL staticChallengeEcho;
|
||||
|
||||
/**
|
||||
YES if this profile requires a private key password
|
||||
*/
|
||||
@property (readonly, nonatomic) BOOL privateKeyPasswordRequired;
|
||||
|
||||
/**
|
||||
YES if user is allowed to save authentication password in UI
|
||||
*/
|
||||
@property (readonly, nonatomic) BOOL allowPasswordSave;
|
||||
|
||||
/**
|
||||
Address of the first remote item in config
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSString *remoteHost;
|
||||
|
||||
/**
|
||||
Port of the first remote item in config
|
||||
*/
|
||||
@property (readonly, nonatomic) NSUInteger remotePort;
|
||||
|
||||
/**
|
||||
Transport protocol of the first remote item in config
|
||||
*/
|
||||
@property (readonly, nonatomic) OpenVPNTransportProtocol remoteProto;
|
||||
|
||||
/**
|
||||
Optional list of user-selectable VPN servers
|
||||
*/
|
||||
@property (nullable, readonly, nonatomic) NSArray<OpenVPNServerEntry *> *servers;
|
||||
|
||||
- (nonnull instancetype) __unavailable init;
|
||||
|
||||
@end
|
||||
61
OpenVPN Adapter/OpenVPNProperties.mm
Normal file
61
OpenVPN Adapter/OpenVPNProperties.mm
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// OpenVPNProperties.m
|
||||
// OpenVPN Adapter
|
||||
//
|
||||
// Created by Sergey Abramchuk on 26.04.17.
|
||||
//
|
||||
//
|
||||
|
||||
#import <openvpn/common/number.hpp>
|
||||
|
||||
#import "OpenVPNValuesConverter.h"
|
||||
#import "OpenVPNServerEntry+Internal.h"
|
||||
#import "OpenVPNProperties.h"
|
||||
#import "OpenVPNProperties+Internal.h"
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
@implementation OpenVPNProperties
|
||||
|
||||
- (instancetype)initWithEvalConfig:(ClientAPI::EvalConfig)eval {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_username = !eval.userlockedUsername.empty() ? [NSString stringWithUTF8String:eval.userlockedUsername.c_str()] : nil;
|
||||
|
||||
_profileName = !eval.profileName.empty() ? [NSString stringWithUTF8String:eval.profileName.c_str()] : nil;
|
||||
_friendlyName = !eval.friendlyName.empty() ? [NSString stringWithUTF8String:eval.friendlyName.c_str()] : nil;
|
||||
|
||||
_autologin = eval.autologin;
|
||||
|
||||
_staticChallenge = !eval.staticChallenge.empty() ? [NSString stringWithUTF8String:eval.staticChallenge.c_str()] : nil;
|
||||
_staticChallengeEcho = eval.staticChallengeEcho;
|
||||
|
||||
_privateKeyPasswordRequired = eval.privateKeyPasswordRequired;
|
||||
_allowPasswordSave = eval.allowPasswordSave;
|
||||
|
||||
_remoteHost = !eval.remoteHost.empty() ? [NSString stringWithUTF8String:eval.remoteHost.c_str()] : nil;
|
||||
|
||||
uint16_t port = 0;
|
||||
parse_number(eval.remotePort, port);
|
||||
|
||||
_remotePort = port;
|
||||
|
||||
NSString *currentProto = [NSString stringWithUTF8String:eval.remoteProto.c_str()];
|
||||
_remoteProto = [OpenVPNPropertyConverter getTransportProtocolFromString:currentProto];
|
||||
|
||||
_servers = nil;
|
||||
if (!eval.serverList.empty()) {
|
||||
NSMutableArray *servers = [NSMutableArray new];
|
||||
|
||||
for (ClientAPI::ServerEntry entry : eval.serverList) {
|
||||
OpenVPNServerEntry *serverEntry = [[OpenVPNServerEntry alloc] initWithServerEntry:entry];
|
||||
[servers addObject:serverEntry];
|
||||
}
|
||||
|
||||
_servers = servers;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user