示例#1
0
        private void Troubleshooter()
        {
            UISync.Execute(() => rtbOutput.Clear());

            try
            {
                MainForm.StopAndStartServer();
            }
            catch (Exception ex)
            {
                Log.Error("",ex);//MainForm.LogExceptionToFile(ex);
            }

            bool portMapOk = false;
            bool IPv6 = MainForm.Conf.IPMode == "IPv6";
            UISync.Execute(() => button2.Enabled = false);

            string localserver = "http://" + MainForm.IPAddress + ":" + MainForm.Conf.LANPort;

            UISync.Execute(() => rtbOutput.Text = "Local iSpy Server: "+localserver+NL);
            if (MainForm.Conf.LANPort!=8080)
            {
                UISync.Execute(() => rtbOutput.Text +=
                    "--Warning, running a local server on a non-standard port ("+MainForm.Conf.LANPort+") may cause web-browser security errors. Click the link above to test in your web browser." +
                    NL);
            }
            UISync.Execute(() => rtbOutput.Text += "Checking local server... ");
            Application.DoEvents();
            string res = "";
            if (!loadurl(localserver+"/ping", out res))
            {
                UISync.Execute(() => rtbOutput.Text += "Failed: " + res + NL);
                if (MainForm.MWS.Running)
                {
                    UISync.Execute(() => rtbOutput.Text += "Server reports it IS running" + NL);
                }
                else
                    UISync.Execute(() => rtbOutput.Text += "Server reports it IS NOT running - check the log file for errors (View-> Log File)" + NL);

                UISync.Execute(() => rtbOutput.Text += "Do you have a third party firewall or antivirus running (AVG/ zonealarm etc)?" + NL);
            }
            else
            {
                res = res.ToLower();
                if (res.IndexOf("access")!=-1 || res.IndexOf("ok")!=-1)
                {
                    UISync.Execute(() => rtbOutput.Text += "OK");
                }
                else
                {
                    UISync.Execute(() => rtbOutput.Text += "Unexpected output: " + res);
                }
            }
            UISync.Execute(() => rtbOutput.Text += NL);
            UISync.Execute(() => rtbOutput.Text += "Checking WebServer... ");
            Application.DoEvents();
            if (!loadurl(MainForm.Webserver + "/webservices/ispy.asmx", out res))
            {
                UISync.Execute(() => rtbOutput.Text += "Webservices not responding.");
            }
            else
            {
                if (res.IndexOf("error occurred while")!=-1)
                    UISync.Execute(() => rtbOutput.Text += "Error with webservices. Please try again later.");
                else
                    UISync.Execute(() => rtbOutput.Text += "OK");
            }
            UISync.Execute(() => rtbOutput.Text += NL);
            UISync.Execute(() => rtbOutput.Text += "Checking your firewall... ");
            Application.DoEvents();
            var fw = new WinXPSP2FireWall();
            fw.Initialize();

            bool bOn = false;
            fw.IsWindowsFirewallOn(ref bOn);
            if (bOn)
            {
                string strApplication = Application.StartupPath + "\\iSpy.exe";
                bool bEnabled = false;
                fw.IsAppEnabled(strApplication, ref bEnabled);
                if (!bEnabled)
                {
                    UISync.Execute(() => rtbOutput.Text += "iSpy is *not* enabled");
                }
                else
                {
                    UISync.Execute(() => rtbOutput.Text += "iSpy is enabled");
                }
            }
            else
            {
                UISync.Execute(() => rtbOutput.Text += "Firewall is off");
            }
            UISync.Execute(() => rtbOutput.Text += NL);

            UISync.Execute(() => rtbOutput.Text += "Checking your account... ");

            var result = WsWrapper.TestConnection(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, false);
            if (result[0] != "OK")
            {
                UISync.Execute(() => rtbOutput.Text += result[0]);
            }
            else
            {

                UISync.Execute(() => rtbOutput.Text += "Found: " + result[2]);
                if (Convert.ToBoolean(result[1]))
                {
                    UISync.Execute(() => rtbOutput.Text += NL + "Your subscription is valid." + NL);
                    if (MainForm.Conf.IPMode == "IPv4")
                    {

                        UISync.Execute(() => rtbOutput.Text += "IPv4: Checking port mappings... " + NL);
                        try
                        {
                            if (NATControl.Mappings == null)
                            {
                                UISync.Execute(
                                    () =>
                                    rtbOutput.Text +=
                                    "IPv4 Port mappings are unavailable - set up port mapping manually, instructions here: http://portforward.com/english/routers/port_forwarding/routerindex.htm" +
                                    NL);
                            }
                            else
                            {
                                int j = 2;
                                while (!portMapOk && j > 0)
                                {
                                    var enumerator = NATControl.Mappings.GetEnumerator();

                                    while (enumerator.MoveNext())
                                    {
                                        var map = (NATUPNPLib.IStaticPortMapping) enumerator.Current;
                                        UISync.Execute(
                                            () =>
                                            rtbOutput.Text +=
                                            map.ExternalPort + " -> " + map.InternalPort + " on " + map.InternalClient +
                                            " (" +
                                            map.Protocol + ")" + NL);
                                        if (map.ExternalPort == MainForm.Conf.ServerPort)
                                        {
                                            if (map.InternalPort != MainForm.Conf.LANPort)
                                            {
                                                UISync.Execute(
                                                    () =>
                                                    rtbOutput.Text +=
                                                    "*** External port is routing to " + map.InternalPort +
                                                    " instead of " +
                                                    MainForm.Conf.LANPort + NL);
                                            }
                                            else
                                            {
                                                if (map.InternalClient != MainForm.AddressIPv4)
                                                {
                                                    UISync.Execute(
                                                        () =>
                                                        rtbOutput.Text +=
                                                        "*** Port is mapping to IP Address " + map.InternalClient +
                                                        " - should be " +
                                                        MainForm.AddressIPv4 +
                                                        ". Set a static IP address for your computer and then update the port mapping." +
                                                        NL);
                                                }
                                                else
                                                {
                                                    portMapOk = true;
                                                }
                                            }
                                        }
                                    }
                                    if (!portMapOk)
                                    {
                                        //add port mapping
                                        UISync.Execute(() => rtbOutput.Text += "IPv4: Fixing port mapping... " + NL);
                                        if (!NATControl.SetPorts(MainForm.Conf.ServerPort, MainForm.Conf.LANPort))
                                        {
                                            UISync.Execute(
                                                () => rtbOutput.Text += LocRm.GetString("ErrorPortMapping") + NL);
                                        }

                                        j--;
                                        if (j > 0)
                                            UISync.Execute(
                                                () => rtbOutput.Text += "IPv4: Checking port mappings... " + NL);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("",ex);//MainForm.LogExceptionToFile(ex);
                        }
                    }

                    UISync.Execute(() => rtbOutput.Text += "Checking external access... "+NL);

                    result = WsWrapper.TestConnection(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, true);

                    if (result.Length>3 && result[3] != "")
                    {
                        UISync.Execute(() => rtbOutput.Text += "iSpyConnect is trying to contact your server at: "+result[6] + NL);
                        UISync.Execute(() => rtbOutput.Text += "Failed: " + result[3] + NL);
                        if (!IPv6)
                        {
                            UISync.Execute(
                                () =>
                                rtbOutput.Text +=
                                "Your router should be configured to forward TCP traffic from WAN (external) port " +
                                MainForm.Conf.ServerPort + " to internal (LAN) port " +
                                MainForm.Conf.LANPort + " on IP address " + MainForm.AddressIPv4 +
                                NL);
                            if (portMapOk)
                            {
                                UISync.Execute(
                                    () =>
                                    rtbOutput.Text +=
                                    NL +
                                    "Your port mapping seems to be OK - try turning your router off and on again. Failing that we recommend checking with your ISP to see if they are blocking port " +
                                    MainForm.Conf.ServerPort +
                                    " or check if your antivirus protection (eset, zonealarm etc) is blocking iSpy. ");
                            }
                        }

                        UISync.Execute(() => rtbOutput.Text += NL + NL + "Please see the troubleshooting section here: http://www.ispyconnect.com/userguide-remote-access-troubleshooting.aspx");
                    }
                    else
                    {
                        if (result.Length==1)
                            UISync.Execute(() => rtbOutput.Text +=
                                "Failed: Communication with webserver failed." + NL + NL);
                        else
                            UISync.Execute(() => rtbOutput.Text +=
                                "Success!"+NL+NL+"If you cannot access content locally please ensure 'Use LAN IP when available' is checked on "+MainForm.Webserver+"/account.aspx and also ensure you're using an up to date web browser (we recommend google Chrome. Opera is incompatible)");
                    }
                }
                else
                {
                    UISync.Execute(() => rtbOutput.Text += NL +
                                      "Not subscribed - local access only. http://www.ispyconnect.com/subscribe.aspx");

                }
            }
            UISync.Execute(() => rtbOutput.Text+=NL);
            Application.DoEvents();
            UISync.Execute(() => button2.Enabled = true);
        }
示例#2
0
        private void Button1Click(object sender, EventArgs e)
        {
            bool bIPv6 = tcIPMode.SelectedIndex == 1;
            int port, localPort;
            string error;

            if (!SetupNetwork(out port, out localPort, out error))
            {
                MessageBox.Show(error+" - Try a different port.");
                return;
            }

            if (txtUsername.Text.Trim() != "")
            {
                try
                {
                    var fw = new WinXPSP2FireWall();
                    fw.Initialize();

                    bool bOn = false;
                    fw.IsWindowsFirewallOn(ref bOn);
                    if (bOn)
                    {
                        string strApplication = Application.StartupPath + "\\iSpy.exe";
                        bool bEnabled = false;
                        fw.IsAppEnabled(strApplication, ref bEnabled);
                        if (!bEnabled)
                        {
                            fw.AddApplication(strApplication, "iSpy");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("",ex);//MainForm.LogExceptionToFile(ex);
                }

                Next.Enabled = false;
                Next.Text = "...";
                Application.DoEvents();

                MainForm.Conf.DHCPReroute = chkReroute.Checked;
                bool failed = false;

                var result = WsWrapper.TestConnection(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, true);
                if (result[0] != "OK")
                {
                    MessageBox.Show(result[0], LocRm.GetString("Error"));
                    failed = true;
                }

                if (!failed)
                {
                    if (result.Length>0 && result[0] == "OK")
                    {
                        EmailAddress = result[2];
                        MobileNumber = result[4];
                        MainForm.Conf.Reseller = result[5];
                        MainForm.Conf.ServicesEnabled = true;
                        MainForm.Conf.Subscribed = Convert.ToBoolean(result[1]);
                        if (result[3] != "")
                        {
                            if (!bIPv6)
                            {
                                //try setting port automatically
                                if (chkuPNP.Checked)
                                {
                                    if (!NATControl.SetPorts(port, localPort))
                                    {
                                        MessageBox.Show(LocRm.GetString("ErrorPortMapping"), LocRm.GetString("Error"));
                                        chkuPNP.Checked = false;
                                    }
                                    else
                                    {
                                        result = WsWrapper.TestConnection(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, true);
                                    }
                                }

                            }

                            if (result[3] != "")
                            {
                                MainForm.Conf.Loopback = false;
                                Next.Enabled = true;
                                Next.Text = LocRm.GetString("Finish");
                                MainForm.LoopBack = false;
                                if (!bIPv6)
                                {
                                    switch (
                                        MessageBox.Show(
                                            LocRm.GetString("ErrorLoopback").Replace("[PORT]", port.ToString(CultureInfo.InvariantCulture)),
                                            LocRm.GetString("Error"), MessageBoxButtons.YesNoCancel))
                                    {
                                        case DialogResult.Yes:
                                            ShowTroubleShooter();
                                            return;
                                        case DialogResult.No:
                                            MainForm.Conf.Loopback = false;
                                            MainForm.LoopBack = false;
                                            DialogResult = DialogResult.Yes;
                                            Close();
                                            return;
                                        case DialogResult.Cancel:
                                            return;
                                    }
                                }
                                else
                                {
                                    switch (
                                        MessageBox.Show(
                                            LocRm.GetString("ErrorLoopbackIPv6").Replace("[PORT]", localPort.ToString(CultureInfo.InvariantCulture)),
                                            LocRm.GetString("Error"), MessageBoxButtons.YesNoCancel))
                                    {
                                        case DialogResult.Yes:
                                            ShowTroubleShooter();
                                            return;
                                        case DialogResult.No:
                                            MainForm.Conf.Loopback = false;
                                            MainForm.LoopBack = false;
                                            DialogResult = DialogResult.Yes;
                                            Close();
                                            return;
                                        case DialogResult.Cancel:
                                            return;
                                    }
                                }
                            }
                        }
                        if (result[3] == "")
                        {
                            MainForm.Conf.Loopback = true;
                            MainForm.LoopBack = true;

                            DialogResult = DialogResult.Yes;
                            Close();
                            return;
                        }
                        Next.Enabled = true;
                        Next.Text = LocRm.GetString("Finish");
                    }
                    else
                    {
                        if (result.Length>0 && result[0].ToLower().IndexOf("login", StringComparison.Ordinal) == -1)
                        {
                            MessageBox.Show(result[0], LocRm.GetString("Error"));
                        }
                        else
                        {
                            MessageBox.Show("No response", LocRm.GetString("ConnectFailed"));
                        }
                    }
                }
            }
            else
            {
                Next.Enabled = true;
                Next.Text = LocRm.GetString("Finish");
                if (
                    MessageBox.Show(LocRm.GetString("WarningLogin"), LocRm.GetString("Note"), MessageBoxButtons.OKCancel) ==
                    DialogResult.Cancel)
                {
                    return;
                }
                MainForm.Conf.ServicesEnabled = false;
                MainForm.Conf.Subscribed = false;
                MainForm.Conf.WSUsername = "";
                MainForm.Conf.WSPassword = "";
                DialogResult = DialogResult.OK;
                Close();
            }
            Next.Enabled = true;
            Next.Text = LocRm.GetString("Finish");
        }