Esempio n. 1
0
        private void WindowMonitoring_Load(object sender, EventArgs e)
        {
            lblVersionID.Text = System.Reflection.Assembly.GetExecutingAssembly()
                                .GetName()
                                .Version
                                .ToString();

            Log.DebugFormat("[WindowMonitoring] Version: {0}", lblVersionID.Text);

            lblAuthorizationInfo.Text = TextAuthorizationInfo;

            OpenAuthorizationPanel();

            Size = _sizeOpen;
            Resize();
            CreateTooltipsForStatics();

            System.Security.Principal.WindowsIdentity  identity  = System.Security.Principal.WindowsIdentity.GetCurrent();
            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);

            if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
            {
                MessageBox.Show("For use return tokens from EVE CREST we need run WHL as administrator");
            }

            frmMain.DelegateStartProcess startProcessFunction = StartPilotAuthorizeFlow;

            new Thread(() => new CrestApiListener().ListenLocalhost(startProcessFunction))
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 2
0
        public void ListenLocalhost(frmMain.DelegateStartProcess StartPilotAuthorizeFlow)
        {
            var web = new HttpListener();

            const string url    = "http://localhost";
            const string port   = "8080";
            var          prefix = string.Format("{0}:{1}/", url, port);

            //NetAclChecker.AddAddress(prefix);

            web.Prefixes.Add(prefix);

            Log.DebugFormat("Listening new ..");

            web.Start();

            while (true)
            {
                var context = web.GetContext();

                Task.Run(() =>
                {
                    var code = "";

                    Log.DebugFormat("Get new request.");

                    foreach (var key in context.Request.QueryString.Keys.Cast <object>().Where(key => key.ToString() == "code"))
                    {
                        code = context.Request.QueryString[key.ToString()];
                    }

                    using (var writer = new StreamWriter(context.Response.OutputStream))
                    {
                        writer.WriteLine("Wormhole Locator authorize complete. Close this tab and return to application.");
                    }
                    context.Response.OutputStream.Close();

                    if (string.IsNullOrEmpty(code) == false)
                    {
                        StartPilotAuthorizeFlow(code);
                    }
                });
            }
        }