/// <summary>
        /// Refreshes the flags from the shared configuration.
        /// </summary>
        private void RefreshConfigurationSettings()
        {
            var config = _SharedConfiguration.Get();

            _DefaultAircraftListFeedId     = config.GoogleMapSettings.WebSiteReceiverId;
            _ShowPicturesToInternetClients = config.InternetClientSettings.CanShowPictures;
            _ShowFlags        = _ConfiguredFlagsFolder.CheckConfiguration(config.BaseStationSettings.OperatorFlagsFolder, Provider);
            _ShowPictures     = _ConfiguredPicturesFolder.CheckConfiguration(config.BaseStationSettings.PicturesFolder, Provider);
            _ShowSilhouettes  = _ConfiguredSilhouettesFolder.CheckConfiguration(config.BaseStationSettings.SilhouettesFolder, Provider);
            _ShortTrailLength = config.GoogleMapSettings.ShortTrailLengthSeconds;
        }
Beispiel #2
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        public void Refresh()
        {
            var users  = new Dictionary <string, CachedUser>();
            var config = _SharedConfiguration.Get();

            foreach (var user in _UserManager.GetUsers().Where(r => r.Enabled))
            {
                var isAdministrator  = config.WebServerSettings.AdministratorUserIds.Contains(user.UniqueId);
                var isWebContentUser = isAdministrator || config.WebServerSettings.BasicAuthenticationUserIds.Contains(user.UniqueId);

                if (LoadAllUsers || isWebContentUser)
                {
                    var key = NormaliseLoginName(user.LoginName);
                    if (!users.ContainsKey(key))
                    {
                        var cachedUser = new CachedUser(user, isWebContentUser, isAdministrator);
                        if (TagAction != null)
                        {
                            TagAction(cachedUser);
                        }

                        users.Add(key, cachedUser);
                    }
                }
            }

            lock (_SyncLock) {
                _Cache = users;
            }
        }
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="textContent"></param>
        public void ManipulateTextResponse(IDictionary <string, object> environment, TextContent textContent)
        {
            string mapStylesheet = null;
            string mapJavascript = null;

            switch (_SharedConfiguration.Get().GoogleMapSettings.MapProvider)
            {
            case MapProvider.GoogleMaps:
                mapJavascript = @"<script src=""script/jquiplugin/jquery.vrs.map-google.js"" type=""text/javascript""></script>";
                break;

            case MapProvider.Leaflet:
                mapStylesheet = @"<link rel=""stylesheet"" href=""css/leaflet/leaflet.css"" type=""text/css"" media=""screen"" />
                                      <link rel=""stylesheet"" href=""css/leaflet.markercluster/MarkerCluster.css"" type=""text/css"" media=""screen"" />
                                      <link rel=""stylesheet"" href=""css/leaflet.markercluster/MarkerCluster.Default.css"" type=""text/css"" media=""screen"" />";
                mapJavascript = @"<script src=""script/leaflet-src.js"" type=""text/javascript""></script>
                                      <script src=""script/leaflet.markercluster-src.js"" type=""text/javascript""></script>
                                      <script src=""script/jquiplugin/jquery.vrs.map-leaflet.js"" type=""text/javascript""></script>";
                break;

            default:
                throw new NotImplementedException();
            }

            if (!String.IsNullOrEmpty(mapStylesheet))
            {
                textContent.Content = textContent.Content.Replace("<!-- [[ MAP STYLESHEET ]] -->", mapStylesheet);
            }
            if (!String.IsNullOrEmpty(mapJavascript))
            {
                textContent.Content = textContent.Content.Replace("<!-- [[ MAP PLUGIN ]] -->", mapJavascript);
            }
        }
 /// <summary>
 /// See interface docs.
 /// </summary>
 /// <param name="sharedConfiguration"></param>
 public void SharedConfigurationChanged(ISharedConfiguration sharedConfiguration)
 {
     _Wrapped.Enabled = sharedConfiguration
                        .Get()
                        .GoogleMapSettings
                        .EnableCompression;
 }
Beispiel #5
0
        /// <summary>
        /// Reloads the configuration if it has changed since the last time we fetched it.
        /// </summary>
        private void RefreshConfiguration()
        {
            if (_SharedConfiguration == null)
            {
                _SharedConfiguration = Factory.ResolveSingleton <ISharedConfiguration>();
            }

            var configurationChangedUtc = _SharedConfiguration.GetConfigurationChangedUtc();

            if (_ConfigurationLastParsed < configurationChangedUtc)
            {
                _ConfigurationLastParsed = configurationChangedUtc;

                var configuration = _SharedConfiguration.Get();
                var allowDomains  = (configuration.GoogleMapSettings.AllowCorsDomains ?? "").Trim();

                _CorsEnabled     = configuration.GoogleMapSettings.EnableCorsSupport;
                _AllowAllDomains = allowDomains == "*";
                _AllowedDomains  = _AllowAllDomains ? new string[0] :
                                   allowDomains
                                   .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                                   .Select(r => r.Trim().ToLowerInvariant())
                                   .Distinct()
                                   .ToArray();
            }
        }
Beispiel #6
0
 /// <summary>
 /// Returns true if minification is enabled.
 /// </summary>
 private bool IsEnabled()
 {
     if (_SharedConfiguration == null)
     {
         _SharedConfiguration = Factory.Singleton.ResolveSingleton <ISharedConfiguration>();
     }
     return(_SharedConfiguration.Get().GoogleMapSettings.EnableMinifying);
 }
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="icao"></param>
        public void Lookup(string icao)
        {
            Initialise();

            if (_SharedConfiguration.Get().BaseStationSettings.LookupAircraftDetailsOnline)
            {
                var normalisedIcao = NormaliseIcao(icao);
                if (ValidateIcao(icao))
                {
                    var queueEntry = new QueueEntry(normalisedIcao, _Clock.UtcNow);
                    lock (_Queue) {
                        if (!_Queue.ContainsKey(normalisedIcao))
                        {
                            _Queue.Add(normalisedIcao, queueEntry);
                            UpdateQueueStatistics();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="icao"></param>
        /// <returns></returns>
        public bool IsGoodAircraftIcao(string icao)
        {
            var result = !String.IsNullOrEmpty(icao) && icao.Length == 6;

            if (result)
            {
                if (icao == "000000" && _SharedConfiguration.Get().RawDecodingSettings.SuppressIcao0)
                {
                    result = false;
                }
            }

            return(result);
        }
Beispiel #9
0
        private bool ServeAudio(OwinContext context)
        {
            var result = String.Equals(context.RequestPathNormalised, "/Audio", StringComparison.OrdinalIgnoreCase);

            if (result)
            {
                result = context.IsLocalOrLan || _SharedConfiguration.Get().InternetClientSettings.CanPlayAudio;
            }

            if (result)
            {
                var queryString = context.RequestQueryStringDictionary(caseSensitiveKeys: false);
                switch (queryString["cmd"]?.ToLower())
                {
                case "say":
                    var text = queryString["line"];
                    if (text == null)
                    {
                        result = false;
                    }
                    else
                    {
                        var audio      = Factory.Resolve <IAudio>();
                        var audioBytes = audio.SpeechToWavBytes(text);

                        context.ResponseHttpStatusCode = HttpStatusCode.OK;
                        context.ReturnBytes(
                            MimeType.WaveAudio,
                            audioBytes
                            );
                    }
                    break;

                default:
                    result = false;
                    break;
                }
            }

            return(result);
        }
Beispiel #10
0
        private bool ServeAudio(PipelineContext context)
        {
            var result = String.Equals(context.Request.PathNormalised.Value, "/Audio", StringComparison.OrdinalIgnoreCase);

            if (result)
            {
                result = context.Request.IsLocalOrLan || _SharedConfiguration.Get().InternetClientSettings.CanPlayAudio;
            }

            if (result)
            {
                switch (context.Request.Query["cmd"]?.ToLower())
                {
                case "say":
                    var text = context.Request.Query["line"];
                    if (text == null)
                    {
                        result = false;
                    }
                    else
                    {
                        var audio      = Factory.Singleton.Resolve <IAudio>();
                        var audioBytes = audio.SpeechToWavBytes(text);

                        var response = context.Response;
                        response.ContentType   = MimeType.WaveAudio;
                        response.ContentLength = audioBytes.Length;
                        response.StatusCode    = (int)HttpStatusCode.OK;
                        response.Body.Write(audioBytes, 0, audioBytes.Length);
                    }
                    break;

                default:
                    result = false;
                    break;
                }
            }

            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// Returns true if the request is authenticated, false otherwise. If the request has not been
        /// authenticated then pipeline processing should be stopped.
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        private bool Authenticated(IDictionary <string, object> environment)
        {
            var result = true;

            var sharedConfig = _SharedConfiguration.Get();
            var context      = PipelineContext.GetOrCreate(environment);
            var request      = context.Request;

            var isAdminOnlyPath = _AuthenticationConfiguration.IsAdministratorPath(request.PathNormalised.Value);
            var isGlobalAuthenticationEnabled = sharedConfig.WebServerSettings.AuthenticationScheme == AuthenticationSchemes.Basic;

            if (isAdminOnlyPath || isGlobalAuthenticationEnabled)
            {
                result = false;

                string userName = null;
                string password = null;
                if (ExtractCredentials(request, ref userName, ref password))
                {
                    var cachedUser      = _BasicAuthentication.GetCachedUser(userName);
                    var cachedUserTag   = _BasicAuthentication.GetCachedUserTag(cachedUser);
                    var isPasswordValid = _BasicAuthentication.IsPasswordValid(cachedUser, cachedUserTag, password);

                    result = isPasswordValid && (!isAdminOnlyPath || cachedUser.IsAdministrator);
                    if (result)
                    {
                        request.User = _BasicAuthentication.CreatePrincipal(cachedUser, cachedUserTag);
                    }
                }

                if (!result)
                {
                    SendNeedsAuthenticationResponse(environment);
                }
            }

            return(result);
        }
Beispiel #12
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        public void Start()
        {
            if (!_Started)
            {
                _Started   = true;
                _Clock     = Factory.Singleton.Resolve <IClock>();
                Downloader = Factory.Singleton.Resolve <IAirPressureDownloader>();
                Lookup     = Factory.Singleton.Resolve <IAirPressureLookup>();

                _SharedConfiguration = Factory.Singleton.ResolveSingleton <ISharedConfiguration>();
                Enabled = _SharedConfiguration.Get().BaseStationSettings.DownloadGlobalAirPressureReadings;
                _SharedConfiguration.ConfigurationChanged += SharedConfiguration_ConfigurationChanged;

                if (_BackgroundWorker == null)
                {
                    _BackgroundWorker         = Factory.Singleton.Resolve <IBackgroundWorker>();
                    _BackgroundWorker.DoWork += BackgroundWorker_DoWork;
                }

                _HeartbeatService           = Factory.Singleton.ResolveSingleton <IHeartbeatService>();
                _HeartbeatService.SlowTick += HeartbeatService_SlowTick;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Called when XPlane sends aircraft details.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void XPlaneUdp_RposReplyReceived(object sender, EventArgs <XPlaneRposReply> e)
        {
            var xplane = e.Value;
            var config = _SharedConfig.Get();

            var aircraftList = FlightSimulatorAircraftList;

            if (aircraftList != null)
            {
                lock (aircraftList.ListSyncLock) {
                    var aircraft = aircraftList.Aircraft.FirstOrDefault(r => r.Callsign == XPlaneCallsign);
                    if (aircraft == null)
                    {
                        aircraft              = Factory.Resolve <IAircraft>();
                        aircraft.Icao24       = "000002";
                        aircraft.UniqueId     = 2;
                        aircraft.Callsign     = XPlaneCallsign;
                        aircraft.AltitudeType = AltitudeType.Barometric;
                        aircraftList.Aircraft.Add(aircraft);
                    }

                    lock (aircraft) {
                        var now = DateTime.UtcNow;
                        aircraft.DataVersion  = Math.Max(now.Ticks, aircraft.DataVersion + 1);
                        aircraft.Latitude     = xplane.Latitude;
                        aircraft.Longitude    = xplane.Longitude;
                        aircraft.GroundSpeed  = xplane.GroundSpeedKnots;
                        aircraft.Track        = xplane.Heading;
                        aircraft.Altitude     = xplane.AltitudeFeet;
                        aircraft.VerticalRate = xplane.VerticalRateFeetPerSecond;

                        aircraft.UpdateCoordinates(now, config.GoogleMapSettings.ShortTrailLengthSeconds);
                    }
                }
            }
        }
Beispiel #14
0
 /// <summary>
 /// See interface docs.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void SharedConfiguration_ConfigurationChanged(object sender, EventArgs args)
 {
     Enabled = _SharedConfiguration.Get().BaseStationSettings.DownloadGlobalAirPressureReadings;
 }
Beispiel #15
0
        /// <summary>
        /// Updates the display of any configuration settings we're showing on the view.
        /// </summary>
        private void DisplayConfigurationSettings()
        {
            var configuration = _SharedConfiguration.Get();

            View.RebroadcastServersConfiguration = Describe.RebroadcastSettingsCollection(configuration.RebroadcastSettings);
        }
Beispiel #16
0
        /// <summary>
        /// Handles the request for an image.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private bool ServeImage(OwinContext context)
        {
            var handled      = false;
            var imageRequest = ExtractImageRequest(context);
            var result       = imageRequest != null;

            if (result)
            {
                Image stockImage = null;
                Image tempImage  = null;

                try {
                    result = BuildInitialImage(context, imageRequest, ref stockImage, ref tempImage);

                    if (result)
                    {
                        var configuration = _SharedConfiguration.Get();

                        if (imageRequest.IsHighDpi)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.ResizeForHiDpi(tempImage ?? stockImage));
                        }
                        if (imageRequest.RotateDegrees > 0.0)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.RotateImage(tempImage ?? stockImage, imageRequest.RotateDegrees.Value));
                        }
                        if (imageRequest.Width != null)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.WidenImage(tempImage ?? stockImage, imageRequest.Width.Value, imageRequest.CentreImageHorizontally));
                        }
                        if (imageRequest.ShowAltitudeStalk)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.AddAltitudeStalk(tempImage ?? stockImage, imageRequest.Height.GetValueOrDefault(), imageRequest.CentreX.GetValueOrDefault()));
                        }
                        else if (imageRequest.Height != null)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.HeightenImage(tempImage ?? stockImage, imageRequest.Height.Value, imageRequest.CentreImageVertically));
                        }

                        var addTextLines = imageRequest.HasTextLines && (!context.IsInternet || configuration.InternetClientSettings.CanShowPinText);
                        if (addTextLines)
                        {
                            tempImage = _Graphics.UseImage(tempImage, _Graphics.AddTextLines(tempImage ?? stockImage, imageRequest.TextLines, centreText: true, isHighDpi: imageRequest.IsHighDpi));
                        }
                    }

                    if (result)
                    {
                        var image = tempImage ?? stockImage;

                        if (image != null)
                        {
                            using (var stream = new MemoryStream()) {
                                using (var copy = (Image)image.Clone()) {
                                    copy.Save(stream, imageRequest.ImageFormat);
                                    var bytes = stream.ToArray();

                                    context.ResponseHttpStatusCode = HttpStatusCode.OK;
                                    context.ReturnBytes(
                                        ImageMimeType(imageRequest.ImageFormat),
                                        bytes
                                        );

                                    handled = true;
                                }
                            }
                        }
                    }
                } finally {
                    if (stockImage != null)
                    {
                        stockImage.Dispose();                            // clones are now made of all stock images
                    }
                    if (tempImage != null)
                    {
                        tempImage.Dispose();
                    }
                }
            }

            return(handled);
        }