WIP
parent
0141fb51b9
commit
ce680a9546
|
@ -23,6 +23,11 @@ namespace ln.radius
|
|||
public string Name => AttributeName(Type);
|
||||
|
||||
public virtual byte[] Bytes { get; set; }
|
||||
public String AsText
|
||||
{
|
||||
get => Encoding.UTF8.GetString(Bytes);
|
||||
set => Bytes = Encoding.UTF8.GetBytes(value);
|
||||
}
|
||||
|
||||
public RadiusAttribute(byte type)
|
||||
{
|
||||
|
@ -87,74 +92,66 @@ namespace ln.radius
|
|||
|
||||
static RadiusAttribute()
|
||||
{
|
||||
RegisterAttributeFactory(0x01, "User-Name", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x02, "User-Password", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x03, "CHAP-Password", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x04, "NAS-IP-Address", (type) => new IPv4Attribute(type));
|
||||
RegisterAttributeFactory(0x05, "NAS-Port", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x06, "Service-Type", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x07, "Framed-Protocol", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x08, "Framed-IP-Address", (type) => new IPv4Attribute(type));
|
||||
RegisterAttributeFactory(0x09, "Framed-IP-Netmask", (type) => new IPv4Attribute(type));
|
||||
RegisterAttributeFactory(0x0A, "Framed-Routing", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x0B, "Filter-Id", (type) => new TextAttribute(type));
|
||||
RegisterAttributeFactory(0x0C, "Framed-MTU", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x0D, "Framed-Compression", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x0E, "Login-IP-Host", (type) => new IPv4Attribute(type));
|
||||
RegisterAttributeFactory(0x0F, "Login-Service", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x01, "User-Name", (type) => new UserName());
|
||||
RegisterAttributeFactory(0x02, "User-Password", (type) => new UserPassword());
|
||||
RegisterAttributeFactory(0x03, "CHAP-Password", (type) => new ChapPassword());
|
||||
RegisterAttributeFactory(0x04, "NAS-IP-Address", (type) => new NASIPAddress());
|
||||
RegisterAttributeFactory(0x05, "NAS-Port", (type) => new NASPort());
|
||||
RegisterAttributeFactory(0x06, "Service-Type", (type) => new ServiceType());
|
||||
RegisterAttributeFactory(0x07, "Framed-Protocol", (type) => new FramedProtocol());
|
||||
RegisterAttributeFactory(0x08, "Framed-IP-Address", (type) => new FramedIPAddress());
|
||||
RegisterAttributeFactory(0x09, "Framed-IP-Netmask", (type) => new FramedIPNetmask());
|
||||
RegisterAttributeFactory(0x0A, "Framed-Routing", (type) => new FramedRouting());
|
||||
RegisterAttributeFactory(0x0B, "Filter-Id", (type) => new FilterID());
|
||||
RegisterAttributeFactory(0x0C, "Framed-MTU", (type) => new FramedMTU());
|
||||
RegisterAttributeFactory(0x0D, "Framed-Compression", (type) => new FramedCompression());
|
||||
RegisterAttributeFactory(0x0E, "Login-IP-Host", (type) => new LoginIPHost());
|
||||
RegisterAttributeFactory(0x0F, "Login-Service", (type) => new LoginService());
|
||||
|
||||
RegisterAttributeFactory(0x10, "Login-TCP-Port", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x10, "Login-TCP-Port", (type) => new LoginTCPPort());
|
||||
//RegisterAttributeFactory(0x11, "", (type) => new RadiusAttribute(type)); // Reserved
|
||||
RegisterAttributeFactory(0x12, "Reply-Message", (type) => new TextAttribute(type));
|
||||
RegisterAttributeFactory(0x13, "Callback-Number", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x14, "Callback-Id", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x12, "Reply-Message", (type) => new ReplyMessage());
|
||||
RegisterAttributeFactory(0x13, "Callback-Number", (type) => new CallbackNumber());
|
||||
RegisterAttributeFactory(0x14, "Callback-Id", (type) => new CallbackID());
|
||||
//RegisterAttributeFactory(0x15, "", (type) => new RadiusAttribute(type)); // Reserved
|
||||
RegisterAttributeFactory(0x16, "Framed-Route", (type) => new TextAttribute(type));
|
||||
RegisterAttributeFactory(0x17, "Framed-IPX-Network", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x18, "State", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x19, "Class", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x1A, "Vendor-Specific", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x1B, "Session-Timeout", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x1C, "Idle-Timeout", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x1D, "Termination-Action", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x1E, "Called-Station-Id", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x1F, "Calling-Station-Id", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x16, "Framed-Route", (type) => new FramedRoute());
|
||||
RegisterAttributeFactory(0x17, "Framed-IPX-Network", (type) => new FramedIPXNetwork());
|
||||
RegisterAttributeFactory(0x18, "State", (type) => new State());
|
||||
RegisterAttributeFactory(0x19, "Class", (type) => new Class());
|
||||
RegisterAttributeFactory(0x1A, "Vendor-Specific", (type) => new VendorSpecific());
|
||||
RegisterAttributeFactory(0x1B, "Session-Timeout", (type) => new SessionTimeout());
|
||||
RegisterAttributeFactory(0x1C, "Idle-Timeout", (type) => new IdleTimeout());
|
||||
RegisterAttributeFactory(0x1D, "Termination-Action", (type) => new TerminationAction());
|
||||
RegisterAttributeFactory(0x1E, "Called-Station-Id", (type) => new CalledStationID());
|
||||
RegisterAttributeFactory(0x1F, "Calling-Station-Id", (type) => new CallingStationID());
|
||||
|
||||
RegisterAttributeFactory(0x20, "NAS-Identifier", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x21, "Proxy-State", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x22, "Login-LAT-Service", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x23, "Login-LAT-Node", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x24, "Login-LAT-Group", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x25, "Framed-AppleTalk-Link", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x26, "Framed-AppleTalk-Network", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x27, "Framed-AppleTalk-Zone", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x20, "NAS-Identifier", (type) => new NASIdentifier());
|
||||
RegisterAttributeFactory(0x21, "Proxy-State", (type) => new ProxyState());
|
||||
RegisterAttributeFactory(0x22, "Login-LAT-Service", (type) => new LoginLATService());
|
||||
RegisterAttributeFactory(0x23, "Login-LAT-Node", (type) => new LoginLATNode());
|
||||
RegisterAttributeFactory(0x24, "Login-LAT-Group", (type) => new LoginLATGroup());
|
||||
RegisterAttributeFactory(0x25, "Framed-AppleTalk-Link", (type) => new FramedAppleTalkLink());
|
||||
RegisterAttributeFactory(0x26, "Framed-AppleTalk-Network", (type) => new FramedAppleTalkNetwork());
|
||||
RegisterAttributeFactory(0x27, "Framed-AppleTalk-Zone", (type) => new FramedAppleTalkZone());
|
||||
|
||||
RegisterAttributeFactory(0x3C, "CHAP-Challenge", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x3D, "NAS-Port-Type", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x3E, "Port-Limit", (type) => new IntAttribute(type));
|
||||
RegisterAttributeFactory(0x3F, "Login-LAT-Port", (type) => new RadiusAttribute(type));
|
||||
RegisterAttributeFactory(0x3C, "CHAP-Challenge", (type) => new ChapChallenge());
|
||||
RegisterAttributeFactory(0x3D, "NAS-Port-Type", (type) => new NASPortType());
|
||||
RegisterAttributeFactory(0x3E, "Port-Limit", (type) => new PortLimit());
|
||||
RegisterAttributeFactory(0x3F, "Login-LAT-Port", (type) => new LoginLATPort());
|
||||
}
|
||||
|
||||
class TextAttribute : RadiusAttribute
|
||||
public class TextAttribute : RadiusAttribute
|
||||
{
|
||||
public String Text { get; set; }
|
||||
|
||||
public override byte[] Bytes
|
||||
{
|
||||
get => Encoding.UTF8.GetBytes(Text);
|
||||
set => Text = Encoding.UTF8.GetString(value);
|
||||
}
|
||||
|
||||
public TextAttribute(byte type)
|
||||
: base(type)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("[RadiusAttribute Type={0} {1}]", Name, Text);
|
||||
return string.Format("[RadiusAttribute Type={0} {1}]", Name, AsText);
|
||||
}
|
||||
}
|
||||
class IPv4Attribute : RadiusAttribute
|
||||
public class IPv4Attribute : RadiusAttribute
|
||||
{
|
||||
public IPv4 IP { get; set; }
|
||||
public override byte[] Bytes
|
||||
|
@ -174,7 +171,7 @@ namespace ln.radius
|
|||
|
||||
}
|
||||
|
||||
class IntAttribute : RadiusAttribute
|
||||
public class IntAttribute : RadiusAttribute
|
||||
{
|
||||
public UInt32 UInt32 { get; set; }
|
||||
public override byte[] Bytes
|
||||
|
@ -193,13 +190,13 @@ namespace ln.radius
|
|||
}
|
||||
}
|
||||
|
||||
class TimeAttribute : RadiusAttribute
|
||||
public class TimeAttribute : RadiusAttribute
|
||||
{
|
||||
DateTimeOffset DateTimeOffset { get; set; }
|
||||
public override byte[] Bytes
|
||||
{
|
||||
get => ((uint)DateTimeOffset.ToUnixTimeSeconds()).GetBytes(true);
|
||||
set => DateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(BitConverter.ToUInt32(value.BigEndian(),0));
|
||||
set => DateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(BitConverter.ToUInt32(value.BigEndian(), 0));
|
||||
}
|
||||
|
||||
public TimeAttribute(byte type)
|
||||
|
@ -212,5 +209,50 @@ namespace ln.radius
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* */
|
||||
public class UserName : RadiusAttribute { public UserName() : base(0x01) { } }
|
||||
public class UserPassword : RadiusAttribute { public UserPassword() : base(0x02) { } }
|
||||
public class ChapPassword : RadiusAttribute { public ChapPassword() : base(0x03) { } }
|
||||
public class NASIPAddress : IPv4Attribute { public NASIPAddress() : base(0x04) { } }
|
||||
public class NASPort : IntAttribute { public NASPort() : base(0x05) { } }
|
||||
public class ServiceType : IntAttribute { public ServiceType() : base(0x06) { } }
|
||||
public class FramedProtocol : IntAttribute { public FramedProtocol() : base(0x07) { } }
|
||||
public class FramedIPAddress : IPv4Attribute { public FramedIPAddress() : base(0x08) { } }
|
||||
public class FramedIPNetmask : IPv4Attribute { public FramedIPNetmask() : base(0x09) { } }
|
||||
public class FramedRouting : IntAttribute { public FramedRouting() : base(0x0a) { } }
|
||||
public class FilterID : TextAttribute { public FilterID() : base(0x0b) { } }
|
||||
public class FramedMTU : IntAttribute { public FramedMTU() : base(0x0c) { } }
|
||||
public class FramedCompression : IntAttribute { public FramedCompression() : base(0x0d) { } }
|
||||
public class LoginIPHost : IPv4Attribute { public LoginIPHost() : base(0x0e) { } }
|
||||
public class LoginService : IntAttribute { public LoginService() : base(0x0f) { } }
|
||||
|
||||
public class LoginTCPPort : IntAttribute { public LoginTCPPort() : base(0x10) { } }
|
||||
public class ReplyMessage : TextAttribute { public ReplyMessage() : base(0x12) { } }
|
||||
public class CallbackNumber : RadiusAttribute { public CallbackNumber() : base(0x13) { } }
|
||||
public class CallbackID : RadiusAttribute { public CallbackID() : base(0x14) { } }
|
||||
public class FramedRoute : TextAttribute { public FramedRoute() : base(0x16) { } }
|
||||
public class FramedIPXNetwork : IntAttribute { public FramedIPXNetwork() : base(0x17) { } }
|
||||
public class State : RadiusAttribute { public State() : base(0x18) { } }
|
||||
public class Class : RadiusAttribute { public Class() : base(0x19) { } }
|
||||
public class VendorSpecific : RadiusAttribute { public VendorSpecific() : base(0x1A) { } }
|
||||
public class SessionTimeout : IntAttribute { public SessionTimeout() : base(0x1B) { } }
|
||||
public class IdleTimeout : IntAttribute { public IdleTimeout() : base(0x1C) { } }
|
||||
public class TerminationAction : IntAttribute { public TerminationAction() : base(0x1D) { } }
|
||||
public class CalledStationID : RadiusAttribute { public CalledStationID() : base(0x1E) { } }
|
||||
public class CallingStationID : RadiusAttribute { public CallingStationID() : base(0x1F) { } }
|
||||
public class NASIdentifier : RadiusAttribute { public NASIdentifier() : base(0x20) { } }
|
||||
public class ProxyState : RadiusAttribute { public ProxyState() : base(0x21) { } }
|
||||
public class LoginLATService : RadiusAttribute { public LoginLATService() : base(0x22) { } }
|
||||
public class LoginLATNode : RadiusAttribute { public LoginLATNode() : base(0x23) { } }
|
||||
public class LoginLATGroup : RadiusAttribute { public LoginLATGroup() : base(0x24) { } }
|
||||
public class FramedAppleTalkLink : IntAttribute { public FramedAppleTalkLink() : base(0x25) { } }
|
||||
public class FramedAppleTalkNetwork : IntAttribute { public FramedAppleTalkNetwork() : base(0x26) { } }
|
||||
public class FramedAppleTalkZone : RadiusAttribute { public FramedAppleTalkZone() : base(0x27) { } }
|
||||
public class ChapChallenge : RadiusAttribute { public ChapChallenge() : base(0x3c) { } }
|
||||
public class NASPortType : RadiusAttribute { public NASPortType() : base(0x3d) { } }
|
||||
public class PortLimit : RadiusAttribute { public PortLimit() : base(0x3e) { } }
|
||||
public class LoginLATPort : RadiusAttribute { public LoginLATPort() : base(0x3f) { } }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,14 @@ namespace ln.radius
|
|||
Code = radiusCode;
|
||||
}
|
||||
|
||||
public RAT GetAttribute<RAT>(string attrName) where RAT : RadiusAttribute => (RAT)GetAttribute(attrName);
|
||||
public RAT GetAttribute<RAT>() where RAT : RadiusAttribute
|
||||
{
|
||||
foreach (RadiusAttribute radiusAttribute in radiusAttributes)
|
||||
if (radiusAttribute is RAT)
|
||||
return (RAT)radiusAttribute;
|
||||
return null;
|
||||
|
||||
}
|
||||
public RadiusAttribute GetAttribute(string attrName)
|
||||
{
|
||||
foreach (RadiusAttribute radiusAttribute in radiusAttributes)
|
||||
|
|
Loading…
Reference in New Issue