Example #1
0
        private void ExtCheckBoxWebServerEnable_CheckedChanged(object sender, EventArgs e)
        {
            bool runit = extCheckBoxWebServerEnable.Checked;

            if (runit)
            {
                var res = ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "You need to configure Windows to allow EDD to webserve" + Environment.NewLine +
                                                                "Click Yes to do this. If you are not the adminstrator, a dialog will appear to ask you" + Environment.NewLine +
                                                                "to sign in as an admin to allow this to happen" + Environment.NewLine +
                                                                "If you have previously done this on this same port number you can click No and the enable will work".T(EDTx.UserControlSettings_WSQ),
                                                                "Web Server",
                                                                MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (res == DialogResult.Yes)
                {
                    BaseUtils.Processes process = new BaseUtils.Processes();

                    // exe method to set it to the eddiscovery ext does not seem to work during debugging.. not sure, can't find out.. abandon for now.
                    //string exe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                    //string cmd = "-Command new-netfirewallrule -Name EDDiscovery -DisplayName EDDiscovery -Description Webserver -Program \"" + exe + "\" -Direction Inbound -Action Allow -LocalPort " + EDDConfig.Instance.WebServerPort.ToStringInvariant() + " -Protocol TCP" +

                    string cmd = "-Command " +
                                 "new-netfirewallrule " +
                                 "-Name EDDiscovery " +
                                 "-DisplayName EDDiscovery " +
                                 "-Description Webserver " +
                                 "-Direction Inbound " +
                                 "-Action Allow " +
                                 $"-LocalPort {EDDConfig.Instance.WebServerPort.ToStringInvariant()} " +
                                 "-Protocol TCP;" +
                                 "netsh http add urlacl " +
                                 $"url = http://*:{EDDConfig.Instance.WebServerPort.ToStringInvariant()}/ " +
                                 $"user=\"{Environment.GetEnvironmentVariable("USERNAME")}\"";

                    int pid = process.StartProcess("Powershell.exe", cmd, "runas");

                    if (pid == 0)
                    {
                        ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Configuration did not run", "Web Server");
                    }
                    else
                    {
                        process.WaitForProcess(pid, 25000);
                    }
                }
            }

            if (!discoveryform.WebServerControl(runit))
            {
                ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Did not start - click OK to configure windows".T(EDTx.UserControlSettings_WSF), "Web Server");
            }
            else
            {
                EDDConfig.Instance.WebServerEnable = runit;     // this is for next time at startup
            }
        }
Example #2
0
 public FunctionPersistentData()
 {
     fh    = new BaseUtils.FileHandles();
     procs = new BaseUtils.Processes();
 }