Esempio n. 1
0
        bool UpdateSession(byte[] image)
        {
            // update the session duration
            using (var command = new OleDbCommand(Program.Settings.CommandUpdateDuration, connection))
            {
                command.Parameters.AddWithValue("@Duration", (int)((DateTime.Now - sessionStart).TotalMinutes));
                command.Parameters.AddWithValue("@Session", session);
                if (command.ExecuteNonQuery() != 1)
                {
                    return(false);
                }
            }

            // update the screenshot
            using (var command = new OleDbCommand(Program.Settings.CommandUpdateScreenshot, connection))
            {
                command.Parameters.AddWithValue("@Screenshot", (object)image ?? DBNull.Value);
                command.Parameters.AddWithValue("@Session", session);
                try { command.ExecuteNonQuery(); }
                catch (OleDbException e) { ServiceApplication.LogEvent(EventLogEntryType.Warning, e.Message); }
            }

            // return success
            return(true);
        }
Esempio n. 2
0
        void HandleRequest(object state)
        {
            // try to logon the user and create the response
            var request = (Request)state;
            int timeout;

            try { timeout = LogonAndCreateSession(request.UserName, request.Password, request.Address); }
            catch (OleDbException e)
            {
                ServiceApplication.LogEvent(EventLogEntryType.Error, e.Message);
                return;
            }
            var response = new RadiusPacket(timeout < 0 ? PacketCode.AccessReject : PacketCode.AccessAccept);

            response.Identifier = request.Identifier;
            if (timeout > 0)
            {
                response.Attribute(RadiusAttribute.SessionTimeout).Add(timeout);
            }
            response.Attribute(RadiusAttribute.ProxyState).AddRange(request.ProxyStates);
            response.SignResponse(request.Authenticator, sharedSecred);
            try { socket.SendTo(response.GetBuffer(), 0, response.Length, SocketFlags.None, request.Client); }
            catch (ObjectDisposedException) { }
            catch (SocketException e) { ServiceApplication.LogEvent(EventLogEntryType.Error, e.Message); }
        }
Esempio n. 3
0
 bool System.ServiceModel.Dispatcher.IErrorHandler.HandleError(Exception error)
 {
     // ignore expected fault exceptions and log all other types
     if (!(error is FaultException))
     {
         ServiceApplication.LogEvent(EventLogEntryType.Error, error.Message);
     }
     return(false);
 }
Esempio n. 4
0
        public bool Continue(Stream image)
        {
            // check the input argument and the state of the session
            if (image == null)
            {
                throw new ArgumentNullException("image").AsFault();
            }
            if (disposed)
            {
                throw new ObjectDisposedException(ToString()).AsFault();
            }
            if (!ready)
            {
                new InvalidOperationException().AsFault();
            }

            try
            {
                // ensure that the user is still allowed to logon
                using (var command = new OleDbCommand(Program.Settings.CommandVerifyLogin, connection))
                {
                    command.Parameters.AddWithValue("@ID", id);
                    command.Parameters.AddWithValue("@State", state);
                    if (!Convert.ToBoolean(command.ExecuteScalar()))
                    {
                        return(false);
                    }
                }

                // load, adjust and store the screenshot and update the duration
                using (var screenshot = LoadImageFromStream(image))
                    using (var zoomed = screenshot.Zoom(Program.Settings.ScreenshotSize.Width, Program.Settings.ScreenshotSize.Height, Program.Settings.ScreenshotFormat))
                        return(UpdateSession(zoomed.ToOleObject(progId: "Screenshot", dde: "Screenshot", modifiable: false)));
            }
            catch (OleDbException e)
            {
                // keep the session going as long as allowed
                if (databaseErrors++ < Program.Settings.DatabaseIgnoreUpdateErrors)
                {
                    ServiceApplication.LogEvent(EventLogEntryType.Error, e.Message);
                    return(true);
                }

                // otherwise rethrow the error
                throw;
            }
        }
Esempio n. 5
0
 static void CleanupScreenshots(object state)
 {
     // clean up all out-of-date screenshots
     try
     {
         using (var connection = new OleDbConnection(Program.Settings.Database))
         {
             connection.Open();
             using (var command = new OleDbCommand(Program.Settings.CommandCleanupScreenshots, connection))
             {
                 command.Parameters.AddWithValue("@Interval", Program.Settings.ScreenshotCleanupInterval.TotalSeconds);
                 command.ExecuteNonQuery();
             }
         }
     }
     catch (OleDbException e) { ServiceApplication.LogEvent(EventLogEntryType.Warning, e.Message); }
 }
Esempio n. 6
0
        void Listener()
        {
            // create the buffer and start listening
            var buffer = new byte[0x10000];

            while (true)
            {
                // receive the next message
                var endpoint = (EndPoint) new IPEndPoint(IPAddress.Any, 0);
                var length   = socket.ReceiveFrom(buffer, ref endpoint);

                // if nothing is received, continue listening
                if (length == 0)
                {
                    continue;
                }

                // parse the packet and retrieve all necessary attributes
                var request = new Request();
                request.Client = (IPEndPoint)endpoint;
                try
                {
                    var packet = new RadiusPacket(buffer, length);
                    if (packet.Code != PacketCode.AccessRequest)
                    {
                        continue;
                    }
                    request.Identifier    = packet.Identifier;
                    request.Authenticator = packet.Authenticator;
                    if (packet.Attribute(RadiusAttribute.CHAPPassword).Count > 0)
                    {
                        throw new FormatException("CHAP-Password is not supported");
                    }
                    var userNames = packet.Attribute(RadiusAttribute.UserName);
                    if (userNames.Count != 1)
                    {
                        throw new FormatException("User-Name is not present");
                    }
                    request.UserName = userNames[0];
                    if (packet.Attribute(RadiusAttribute.UserPassword).Count != 1)
                    {
                        throw new FormatException("User-Password is not present");
                    }
                    request.Password = packet.GetUserPassword(sharedSecred);
                    var callerIds = packet.Attribute(RadiusAttribute.CallingStationId);
                    request.Address     = callerIds.Count > 0 ? callerIds[0] : null;
                    request.ProxyStates = packet.Attribute(RadiusAttribute.ProxyState).ToArray();
                }
#if DEBUG
                catch (FormatException e)
                {
                    ServiceApplication.LogEvent(EventLogEntryType.Information, e.Message);
                    continue;
                }
#else
                catch (FormatException) { continue; }
#endif

                // enqueue the request
                ThreadPool.QueueUserWorkItem(HandleRequest, request);
            }
        }