private static void ConfigureServices(IServiceCollection services)
        {
            var path = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + Path.DirectorySeparatorChar;

            //create logging
            var levelSwitch         = new LoggingLevelSwitch(LogEventLevel.Information);
            var loggerConfiguration = new LoggerConfiguration()
                                      .MinimumLevel.ControlledBy(levelSwitch)
                                      .WriteTo.Console(LogEventLevel.Debug)
                                      .WriteTo.File($"{path}logs{Path.DirectorySeparatorChar}log-.txt", rollingInterval: RollingInterval.Day);

            Log.Logger = loggerConfiguration.CreateLogger();


            //load radius attributes dictionary
            var dictionaryPath = path + "content" + Path.DirectorySeparatorChar + "radius.dictionary";
            var dictionary     = new RadiusDictionary(dictionaryPath, Log.Logger);

            //init configuration
            var configuration = Configuration.Load(dictionary);

            SetLogLevel(configuration.LogLevel, levelSwitch);

            services.AddSingleton(Log.Logger);
            services.AddSingleton(configuration);

            services.AddMemoryCache();

            services.AddSingleton <IRadiusDictionary>(dictionary);
            services.AddSingleton <IRadiusPacketParser, RadiusPacketParser>();
            services.AddSingleton <CacheService>();
            services.AddSingleton <RadiusServer>();

            services.AddHostedService <ServerHost>();
        }
        private RadiusDictionary GetDictionary()
        {
            var path       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\content\\radius.dictionary";
            var dictionary = new RadiusDictionary(path);

            return(dictionary);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a radius client which sends and receives responses on localEndpoint
 /// </summary>
 /// <param name="localEndpoint"></param>
 /// <param name="clientCertificate"></param>
 /// <param name="trustServerCertificate">If set to true, server certificate will not be validated. This can be useful for testing with self signed certificates</param>
 public RadSecClient(RadiusDictionary dictionary, X509Certificate clientCertificate, Boolean trustServerCertificate = false)
 {
     _dictionary = dictionary;
     _client     = new TcpClient();
     _certs.Add(clientCertificate);
     _trustServerCertificate = trustServerCertificate;
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var path               = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "/Content/radius.dictionary";
            var dictionary         = new RadiusDictionary(path, NullLogger <RadiusDictionary> .Instance);
            var radiusPacketParser = new RadiusPacketParser(NullLogger <RadiusPacketParser> .Instance, dictionary);

            var packetHandler = new TestPacketHandler();
            var repository    = new PacketHandlerRepository();

            repository.AddPacketHandler(IPAddress.Any, packetHandler, "secret");

            var authenticationServer = new RadiusServer(
                new UdpClientFactory(),
                new IPEndPoint(IPAddress.Any, 1812),
                radiusPacketParser,
                RadiusServerType.Authentication, repository, NullLogger <RadiusServer> .Instance);

            authenticationServer.Start();

            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        private void StartServer()
        {
            var port = 1645;
            Int32.TryParse(textBox_Port.Text, out port);

            //var clients = JsonConvert.DeserializeObject<RadiusServersModel>(File.ReadAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\clients.json"));

            _log.Info("Reading configuration");
            _contextFactory = new FlexinetsEntitiesFactory(CloudConfigurationManager.GetSetting("SQLConnectionString"));
            var path = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\dictionary";
            var dictionary = new RadiusDictionary(path);
            var ipassSecret = CloudConfigurationManager.GetSetting("ipasssecret");
            var mbbSecret = CloudConfigurationManager.GetSetting("mbbsecret");
            var disconnectSecret = CloudConfigurationManager.GetSetting("disconnectSecret");
            var apiUrl = CloudConfigurationManager.GetSetting("ApiUrl");
            _log.Info("Configuration read");

            _rsIpass = new RadiusServer(new IPEndPoint(IPAddress.Any, port), dictionary);
            _rsIpass.AddPacketHandler(IPAddress.Parse("127.0.0.1"), ipassSecret, new iPassPacketHandler(_contextFactory));
            _rsIpass.Start();


            var networkIdProvider = new NetworkIdProvider(_contextFactory, apiUrl);
            var smsgateway = new SMSGatewayTwilio(
                   CloudConfigurationManager.GetSetting("twilio.deliveryreporturl"),
                   CloudConfigurationManager.GetSetting("twilio.accountsid"),
                   CloudConfigurationManager.GetSetting("twilio.authtoken"));

            var welcomeSender = new WelcomeSender(_contextFactory, smsgateway);
            var disconnector = new RadiusDisconnector(_contextFactory, disconnectSecret);
            var mdPacketHandler = new MobileDataPacketHandler(_contextFactory, networkIdProvider, welcomeSender, disconnector);

            _rsMbb = new RadiusServer(new IPEndPoint(IPAddress.Any, port + 1), dictionary);   // daah...
            _rsMbb.AddPacketHandler(IPAddress.Parse("127.0.0.1"), mbbSecret, mdPacketHandler);
            _rsMbb.Start();

            button1.Content = "Stop";
        }
Ejemplo n.º 6
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _log.Info($"Starting RadiusServerService build version {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion}");
                _log.Info("Reading configuration");

                var loggerFactory = new LoggerFactory();
                loggerFactory.AddNLog();
                var dictionary = new RadiusDictionary(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\content\\radius.dictionary", loggerFactory.CreateLogger <RadiusDictionary>());


                var radiusPacketParser = new RadiusPacketParser(loggerFactory.CreateLogger <RadiusPacketParser>(), dictionary);
                var packetHandler      = new TestPacketHandler();
                var repository         = new PacketHandlerRepository();

                repository.AddPacketHandler(IPAddress.Parse("127.0.0.1"), packetHandler, "secret");

                _authenticationServer = new RadiusServer(
                    new Net.UdpClientFactory(),
                    new IPEndPoint(IPAddress.Any, 1812),
                    radiusPacketParser,
                    RadiusServerType.Authentication,
                    repository,
                    loggerFactory.CreateLogger <RadiusServer>());


                _log.Info("Configuration read");

                _authenticationServer.Start();
            }
            catch (Exception ex)
            {
                _log.Fatal(ex, "Failed to start service");
                throw;
            }
        }
        protected override void OnStart(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            try
            {
                _log.Info($"Starting RadiusServerService build version {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion}");
                _log.Info("Reading configuration");

                _contextFactory = new FlexinetsEntitiesFactory(CloudConfigurationManager.GetSetting("SQLConnectionString"));

                var dictionary = new RadiusDictionary(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\content\\radius.dictionary");
                var port       = Convert.ToInt32(CloudConfigurationManager.GetSetting("Port"));
                _authenticationServer = new RadiusServer(new IPEndPoint(IPAddress.Any, port), dictionary, RadiusServerType.Authentication);
                _accountingServer     = new RadiusServer(new IPEndPoint(IPAddress.Any, port + 1), dictionary, RadiusServerType.Accounting); // todo, good grief...

                var authProxy = new iPassAuthenticationProxy(
                    _contextFactory,
                    CloudConfigurationManager.GetSetting("ipass.checkpathold"),
                    CloudConfigurationManager.GetSetting("ipass.checkpathnew"));

                var ipassPacketHandler = new iPassPacketHandler(_contextFactory, authProxy, new UserAuthenticationProvider(null, _contextFactory, null));
                var ipassSecret        = CloudConfigurationManager.GetSetting("ipasssecret");
                _authenticationServer.AddPacketHandler(IPAddress.Parse("127.0.0.1"), ipassSecret, ipassPacketHandler);
                _accountingServer.AddPacketHandler(IPAddress.Parse("127.0.0.1"), ipassSecret, ipassPacketHandler);

                var smsgateway = new SMSGatewayTwilio(
                    CloudConfigurationManager.GetSetting("twilio.deliveryreporturl"),
                    CloudConfigurationManager.GetSetting("twilio.accountsid"),
                    CloudConfigurationManager.GetSetting("twilio.authtoken"));

                var welcomeSender  = new WelcomeSender(_contextFactory, smsgateway);
                var disconnectorV2 = new RadiusDisconnectorV2(
                    CloudConfigurationManager.GetSetting("disconnector.username"),
                    CloudConfigurationManager.GetSetting("disconnector.password"),
                    CloudConfigurationManager.GetSetting("disconnector.apiurl"));
                var mbbPacketHandlerV2 = new MobileDataPacketHandlerV2(_contextFactory, welcomeSender, disconnectorV2);

                // todo refactor this
                var remoteAddresses = new List <IPAddress> {
                    IPAddress.Parse("10.239.24.6"),
                    IPAddress.Parse("10.239.24.7"),
                    IPAddress.Parse("10.239.24.8"),
                    IPAddress.Parse("10.239.24.15"),
                    IPAddress.Parse("10.239.24.16"),
                    IPAddress.Parse("10.239.24.17")
                };


                var mbbNewSecret = CloudConfigurationManager.GetSetting("mbbnewsecret");
                _authenticationServer.AddPacketHandler(remoteAddresses, mbbNewSecret, mbbPacketHandlerV2);
                _accountingServer.AddPacketHandler(remoteAddresses, mbbNewSecret, mbbPacketHandlerV2);

                _log.Info("Configuration read");

                _authenticationServer.Start();
                _accountingServer.Start();
            }
            catch (Exception ex)
            {
                _log.Fatal("Failed to start service", ex);
                throw;
            }
        }