public HubUser SetUser(string hubName, string name, string groupName, string realName, string note, DateTime createTime, DateTime updatedTime, DateTime expireTime, uint numLogin, AuthType authType, byte[] hashedPw, byte[] securePw) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", name }, { "GroupName", groupName }, { "Realname", SoftEtherValueType.UnicodeString, realName }, { "Note", SoftEtherValueType.UnicodeString, note }, { "CreatedTime", createTime }, { "UpdatedTime", updatedTime }, { "ExpireTime", expireTime }, { "NumLogin", numLogin }, { "AuthType", (int)authType }, { "HashedKey", hashedPw }, { "NtLmSecureHash", securePw } }; var rawData = _softEther.CallMethod("SetUser", requestData); return(HubUser.Deserialize(rawData)); }
public VirtualHostOptions SetSecureNatOptions(string hubName, VirtualHostOptions options) { var requestData = new SoftEtherParameterCollection { { "RpcHubName", options.RpcHubName }, { "MacAddress", options.MacAddress }, { "Ip", options.Ip }, { "Mask", options.Mask }, { "UseNat", options.UseNat }, { "Mtu", options.Mtu }, { "NatTcpTimeout", options.NatTcpTimeout }, { "NatUdpTimeout", options.NatUdpTimeout }, { "UseDhcp", options.UseDhcp }, { "DhcpLeaseIPStart", options.DhcpLeaseIPStart }, { "DhcpLeaseIPEnd", options.DhcpLeaseIPEnd }, { "DhcpSubnetMask", options.DhcpSubnetMask }, { "DhcpExpireTimeSpan", options.DhcpExpireTimeSpan }, { "DhcpGatewayAddress", options.DhcpGatewayAddress }, { "DhcpDnsServerAddress", options.DhcpDnsServerAddress }, { "DhcpDnsServerAddress2", options.DhcpDnsServerAddress2 }, { "DhcpDomainName", options.DhcpDomainName }, { "SaveLog", options.SaveLog }, { "ApplyDhcpPushRoutes", options.ApplyDhcpPushRoutes }, { "DhcpPushRoutes", options.DhcpPushRoutes.ToString() } }; var rawData = _softEther.CallMethod("SetSecureNATOption", requestData); return(VirtualHostOptions.Deserialize(rawData)); }
public HubLog GetLog(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("GetHubLog", requestData); return(HubLog.Deserialize(rawData)); }
public ConnectionInfo GetConnectionInfo(string name) { var requestData = new SoftEtherParameterCollection { { "Name", name } }; var rawData = _softEther.CallMethod("GetConnectionInfo", requestData); return(ConnectionInfo.Deserialize(rawData)); }
public SoftEtherList <HubIpAddress> GetIpAddressList(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("EnumIpTable", requestData); return(HubIpAddress.DeserializeMany(rawData)); }
public SoftEtherList <HubUserList> GetUserList(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("EnumUser", requestData); return(HubUserList.DeserializeMany(rawData)); }
public Hub Delete(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("DeleteHub", requestData); return(Hub.Deserialize(rawData)); }
public SoftEtherResult DisableSecureNat(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("DisableSecureNAT", requestData); return(SoftEtherResult.Deserialize(rawData)); }
public SoftEtherResult DeleteIpAddress(string hubName, uint ipAddressKey) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Key", ipAddressKey } }; var rawData = _softEther.CallMethod("DeleteIpTable", requestData); return(SoftEtherResult.Deserialize(rawData)); }
public SoftEtherResult DisconnectSession(string hubName, string sessionName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", sessionName } }; var rawData = _softEther.CallMethod("DeleteSession", requestData); return(SoftEtherResult.Deserialize(rawData)); }
public HubUser DeleteUser(string hubName, string name) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", name } }; var rawData = _softEther.CallMethod("DeleteUser", requestData); return(HubUser.Deserialize(rawData)); }
public HubSessionStatus GetSessionStatus(string hubName, string sessionName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", sessionName } }; var rawData = _softEther.CallMethod("GetSessionStatus", requestData); return(HubSessionStatus.Deserialize(rawData)); }
public Hub SetOnline(string hubName, bool online) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Online", online } }; var rawData = _softEther.CallMethod("SetHubOnline", requestData); return(Hub.Deserialize(rawData)); }
public VirtualHostOptions GetSecureNatOptions(string hubName) { var requestData = new SoftEtherParameterCollection { { "RpcHubName", hubName } }; var rawData = _softEther.CallMethod("GetSecureNATOption", requestData); var model = VirtualHostOptions.Deserialize(rawData); model.RpcHubName = hubName; //Fix, as softEther clears the hubname return(model); }
public HubGroup SetGroup(string hubName, string name, string realName, string note) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", name }, { "Realname", SoftEtherValueType.UnicodeString, realName }, { "Note", SoftEtherValueType.UnicodeString, note } }; var rawData = _softEther.CallMethod("SetGroup", requestData); return(HubGroup.Deserialize(rawData)); }
public SoftEtherParameterCollection CallMethod(string functionName, SoftEtherParameterCollection payload = null) { if (payload == null) { payload = new SoftEtherParameterCollection(); } payload.RemoveNullParameters(); payload.Add("function_name", functionName); var serializedPayload = SoftEtherProtocol.Serialize(payload); var serializedLength = SoftEtherProtocol.SerializeInt(serializedPayload.Length); _socket.Write(serializedLength); _socket.Write(serializedPayload); _socket.Flush(); var dataLength = new byte[4]; var bytesRead = _socket.Read(dataLength, 0, 4); if (bytesRead != 4) { throw new Exception("Failed to read dataLength"); } var dataLengthAsInt = SoftEtherProtocol.DeserializeInt(dataLength); var responseBuffer = new byte[dataLengthAsInt]; bytesRead = 0; for (var i = 0; i < 10; i++) //retrie 10 times to read all data { bytesRead += _socket.Read(responseBuffer, bytesRead, dataLengthAsInt - bytesRead); if (bytesRead == dataLengthAsInt) { break; } Thread.Sleep(50); } if (bytesRead != dataLengthAsInt) { throw new Exception("read less than dataLength"); } var response = SoftEtherProtocol.Deserialize(responseBuffer); return(response); }
public static void GenerateSourceFile(string className, SoftEtherParameterCollection list, bool containsMany = false) { var fileBuffer = new StringBuilder(); fileBuffer.AppendLine(@"using System;"); fileBuffer.AppendLine(); fileBuffer.AppendLine(@"namespace SoftEtherApi.SoftEtherModel"); fileBuffer.AppendLine(@"{"); fileBuffer.AppendLine($@" public class {className} : BaseSoftEtherModel<{className}>"); fileBuffer.AppendLine(@" {"); var usingLists = false; var compiler = new CSharpCodeProvider(); foreach (var el in list) { var fieldName = ModelDeserializer.FilterKeyName(el.Key); var fieldType = el.Value[0].GetType(); var fieldTypeName = compiler.GetTypeOutput(new CodeTypeReference(fieldType)); if (fieldName.Contains("Time") || fieldName.Contains("Date")) { fieldTypeName = "DateTime"; } if (el.Value.Count > 1 && !containsMany) { usingLists = true; fieldTypeName = $"List<{fieldTypeName}>"; } fileBuffer.AppendLine($@" public {fieldTypeName} {fieldName};"); } if (usingLists) { fileBuffer.Insert(0, $"using System.Collections.Generic;{Environment.NewLine}"); } fileBuffer.AppendLine(@" }"); fileBuffer.AppendLine(@"}"); fileBuffer.AppendLine(); using (var file = new StreamWriter($"{className}.cs", false)) { file.Write(fileBuffer.ToString()); } }
public L2tpSettings SetL2tpSettings(L2tpSettings settings) { var requestData = new SoftEtherParameterCollection { { "L2TP_Raw", settings.L2TP_Raw }, { "L2TP_IPsec", settings.L2TP_IPsec }, { "EtherIP_IPsec", settings.EtherIP_IPsec }, { "L2TP_DefaultHub", settings.L2TP_DefaultHub }, { "IPsec_Secret", settings.IPsec_Secret } }; var rawData = _softEther.CallMethod("SetIPsecServices", requestData); return(L2tpSettings.Deserialize(rawData)); }
public SecureNatStatus GetSecureNatStatus(string hubName) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName } }; var rawData = _softEther.CallMethod("GetSecureNATStatus", requestData); var result = SecureNatStatus.Deserialize(rawData); if (string.IsNullOrEmpty(result.HubName)) { result.HubName = hubName; //field is not set by softEther, its a bug } return(result); }
public AuthResult Authenticate(byte[] passwordHash, string hubName = null) { if (RandomFromServer == null) { return new AuthResult { Error = SoftEtherError.ConnectFailed } } ; var authPayload = new SoftEtherParameterCollection { { "method", "admin" }, { "client_str", "SoftEtherNet" }, { "client_ver", 1 }, { "client_build", 0 } }; if (!string.IsNullOrWhiteSpace(hubName)) { authPayload.Add("hubname", hubName); } var securePassword = CreateSaltedHash(passwordHash, RandomFromServer); authPayload.Add("secure_password", securePassword); var serializedAuthPayload = SoftEtherProtocol.Serialize(authPayload); _socket.SendHttpRequest("POST", "/vpnsvc/vpn.cgi", serializedAuthPayload, SoftEtherNetwork.GetDefaultHeaders()); var authResponse = _socket.GetHttpResponse(); if (authResponse.code != 200) { return new AuthResult { Error = SoftEtherError.AuthFailed } } ; var authDict = SoftEtherProtocol.Deserialize(authResponse.body); return(AuthResult.Deserialize(authDict)); }
public static SoftEtherList <T> DeserializeMany <T>(SoftEtherParameterCollection collection, bool moreThanOne) where T : BaseSoftEtherModel <T>, new() { var keyMapping = CreateKeyMapping(collection); if (keyMapping.ContainsKey("error") && keyMapping["error"].Value.Count <= 1) { return(new SoftEtherList <T> { Error = (SoftEtherError)Enum.ToObject(typeof(SoftEtherError), keyMapping["error"].Value[0]) }); } var elementCount = collection.Max(m => m.Value.Count); var returnVal = new SoftEtherList <T>(); //if we expect more than one property to be filled but only get one if (!moreThanOne || collection.Count <= 1) { return(returnVal); } var valFields = typeof(T).GetFields(); for (var i = 0; i < elementCount; i++) { var elementVal = new T(); foreach (var field in valFields) { var keyName = field.Name.ToLower(); if (!keyMapping.ContainsKey(keyName)) { continue; } var val = keyMapping[keyName].Value; SetValueForField(field, val, elementVal, i); } returnVal.Elements.Add(elementVal); } return(returnVal); }
public Hub Create(string name, string password, bool online, bool noAnonymousEnumUser = true, HubType hubType = HubType.Standalone, int maxSession = 0) { var hashPair = _softEther.CreateHashAnSecure(password); var requestData = new SoftEtherParameterCollection { { "HubName", name }, { "HashedPassword", hashPair.Hash }, { "SecurePassword", hashPair.SaltedHash }, { "Online", online }, { "MaxSession", maxSession }, { "NoEnum", noAnonymousEnumUser }, { "HubType", (int)hubType } }; var rawData = _softEther.CallMethod("CreateHub", requestData); return(Hub.Deserialize(rawData)); }
public SoftEtherList <HubAccessList> SetAccessList(string hubName, params HubAccessList[] accessList) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Id", accessList.Select(m => m.Id) }, { "Note", SoftEtherValueType.UnicodeString, accessList.Select(m => m.Note) }, { "Active", accessList.Select(m => m.Active) }, { "Priority", accessList.Select(m => m.Priority) }, { "Discard", accessList.Select(m => m.Discard) }, { "SrcIpAddress", accessList.Select(m => m.SrcIpAddress) }, { "SrcSubnetMask", accessList.Select(m => m.SrcSubnetMask) }, { "DestIpAddress", accessList.Select(m => m.DestIpAddress) }, { "DestSubnetMask", accessList.Select(m => m.DestSubnetMask) }, { "Protocol", accessList.Select(m => m.Protocol) }, { "SrcPortStart", accessList.Select(m => m.SrcPortStart) }, { "SrcPortEnd", accessList.Select(m => m.SrcPortEnd) }, { "DestPortStart", accessList.Select(m => m.DestPortStart) }, { "DestPortEnd", accessList.Select(m => m.DestPortEnd) }, { "SrcUsername", accessList.Select(m => m.SrcUsername) }, { "DestUsername", accessList.Select(m => m.DestUsername) }, { "CheckSrcMac", accessList.Select(m => m.CheckSrcMac) }, { "SrcMacAddress", accessList.Select(m => m.SrcMacAddress) }, { "SrcMacMask", accessList.Select(m => m.SrcMacMask) }, { "CheckDstMac", accessList.Select(m => m.CheckDstMac) }, { "DstMacAddress", accessList.Select(m => m.DstMacAddress) }, { "DstMacMask", accessList.Select(m => m.DstMacMask) }, { "CheckTcpState", accessList.Select(m => m.CheckTcpState) }, { "Established", accessList.Select(m => m.Established) }, { "Delay", accessList.Select(m => m.Delay) }, { "Jitter", accessList.Select(m => m.Jitter) }, { "Loss", accessList.Select(m => m.Loss) }, { "IsIPv6", accessList.Select(m => m.IsIPv6) }, { "UniqueId", accessList.Select(m => m.UniqueId) }, { "RedirectUrl", accessList.Select(m => m.RedirectUrl) } }; var rawData = _softEther.CallMethod("SetAccessList", requestData); return(HubAccessList.DeserializeMany(rawData)); }
public HubAccessList AddAccessList(string hubName, HubAccessList accessList) { var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Id", accessList.Id }, { "Note", SoftEtherValueType.UnicodeString, accessList.Note }, { "Active", accessList.Active }, { "Priority", accessList.Priority }, { "Discard", accessList.Discard }, { "SrcIpAddress", accessList.SrcIpAddress }, { "SrcSubnetMask", accessList.SrcSubnetMask }, { "DestIpAddress", accessList.DestIpAddress }, { "DestSubnetMask", accessList.DestSubnetMask }, { "Protocol", accessList.Protocol }, { "SrcPortStart", accessList.SrcPortStart }, { "SrcPortEnd", accessList.SrcPortEnd }, { "DestPortStart", accessList.DestPortStart }, { "DestPortEnd", accessList.DestPortEnd }, { "SrcUsername", accessList.SrcUsername }, { "DestUsername", accessList.DestUsername }, { "CheckSrcMac", accessList.CheckSrcMac }, { "SrcMacAddress", accessList.SrcMacAddress }, { "SrcMacMask", accessList.SrcMacMask }, { "CheckDstMac", accessList.CheckDstMac }, { "DstMacAddress", accessList.DstMacAddress }, { "DstMacMask", accessList.DstMacMask }, { "CheckTcpState", accessList.CheckTcpState }, { "Established", accessList.Established }, { "Delay", accessList.Delay }, { "Jitter", accessList.Jitter }, { "Loss", accessList.Loss }, { "IsIPv6", accessList.IsIPv6 }, { "UniqueId", accessList.UniqueId }, { "RedirectUrl", accessList.RedirectUrl } }; var rawData = _softEther.CallMethod("AddAccess", requestData); return(HubAccessList.Deserialize(rawData)); }
public static T Deserialize <T>(SoftEtherParameterCollection collection) where T : new() { var keyMapping = CreateKeyMapping(collection); var returnVal = new T(); var valFields = typeof(T).GetFields(); foreach (var field in valFields) { var keyName = field.Name.ToLower(); if (!keyMapping.ContainsKey(keyName)) { continue; } var val = keyMapping[keyName].Value; SetValueForField(field, val, returnVal); } return(returnVal); }
public HubUser CreateUser(string hubName, string name, string password, string groupName = null, string realName = null, string note = null, DateTime?expireTime = null) { var hashPair = _softEther.CreateUserHashAndNtLm(name, password); var requestData = new SoftEtherParameterCollection { { "HubName", hubName }, { "Name", name }, { "GroupName", groupName }, { "Realname", SoftEtherValueType.UnicodeString, realName }, { "Note", SoftEtherValueType.UnicodeString, note }, { "ExpireTime", expireTime }, { "AuthType", (int)AuthType.Password }, { "HashedKey", hashPair.Hash }, { "NtLmSecureHash", hashPair.SaltedHash } }; var rawData = _softEther.CallMethod("CreateUser", requestData); return(HubUser.Deserialize(rawData)); }
public static Dictionary <string, SoftEtherParameter> CreateKeyMapping(SoftEtherParameterCollection collection) { return(collection.Select(m => new Tuple <string, SoftEtherParameter>(FilterKeyName(m.Key), m)) .ToDictionary(m => m.Item1.ToLower(), m => m.Item2)); }
public static T Deserialize(SoftEtherParameterCollection collection) { return(ModelDeserializer.Deserialize <T>(collection)); }
public static SoftEtherList <T> DeserializeMany(SoftEtherParameterCollection collection, bool moreThanOne = true) { return(ModelDeserializer.DeserializeMany <T>(collection, moreThanOne)); }