Ejemplo n.º 1
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (!AdminPrivilege.isElevated())
            {
                groupBox1.Enabled = false;
                MessageBox.Show("This application needs admin previlege to modify hosts.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (Preferences.isExist())
            {
                textBox1.Text = Preferences.Get_StorageSize();
            }
            else
            {
                groupBox2.Enabled = false;
            }

            try
            {
                using (var client = new WebClient())
                {
                    client.DownloadFile(GITHUB_ADSLIST, FILE_ADSLIST);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Something went wrong...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Starts the session.
        /// </summary>
        /// <param name="clientId"> The client id. </param>
        /// <param name="sessionId"> The session id. </param>
        /// <param name="serverPipe"> The server pipe. </param>
        /// <param name="responsePipe"> The response pipe. </param>
        /// <remarks>
        /// </remarks>
        public static void Start(string clientId, string sessionId, NamedPipeServerStream serverPipe, NamedPipeServerStream responsePipe)
        {
            var isElevated = false;
            var userId     = string.Empty;

            serverPipe.RunAsClient(() => {
                var identity = WindowsIdentity.GetCurrent();
                if (identity != null)
                {
                    userId     = identity.Name;
                    isElevated = AdminPrivilege.IsProcessElevated();
                }
            });

            var existingSessions = (from session in ActiveSessions
                                    where session._clientId == clientId && session._sessionId == sessionId && isElevated == session._isElevated && session._userId == userId
                                    select session).ToList();

            if (existingSessions.Any())
            {
                if (existingSessions.Count() > 1)
                {
                    // multiple matching sessions? This isn't good. Shut em all down to be safe
                    foreach (var each in existingSessions)
                    {
                        each.End();
                    }
                }
                else
                {
                    var session = existingSessions.FirstOrDefault();
                    if (session != null)
                    {
                        // found just one session.
                        session._serverPipe   = serverPipe;
                        session._responsePipe = responsePipe;
                        Logger.Message("Rejoining existing session...");
                        // session.SendSessionStarted(sessionId);
                        session.Connected = true;
                        session.SendQueuedMessages();
                    }
                    return;
                }
            }
            else
            {
                // if the exact session isn't there, find any that are partial matches, and shut em down.
                foreach (
                    var each in (from session in ActiveSessions where session._clientId == clientId && session._sessionId == sessionId select session).ToList()
                    )
                {
                    each.End();
                }
            }
            // no viable matching session.
            // Let's start a new one.
            Add(new Session(clientId, sessionId, serverPipe, responsePipe, userId, isElevated));
            Logger.Message("Starting new session...");
        }