Ejemplo n.º 1
0
 private static void SendYouTubeMails(string addresses, string message, string videoid)
 {
     string[] emails = addresses.Split('|');
     foreach (string email in emails)
     {
         string em = email.Trim();
         if (em.IsValidEmail())
         {
             string body;
             if (em != MainForm.EmailAddress)
             {
                 body = LocRm.GetString("YouTubeShareMailBody").Replace("[USERNAME]",
                                                                         MainForm.Conf.WSUsername);
                 body = body.Replace("[EMAIL]", MainForm.EmailAddress);
                 body = body.Replace("[MESSAGE]", message);
                 body = body.Replace("[INFO]", videoid);
                 WsWrapper.SendContent(em,
                                          LocRm.GetString("YouTubeShareMailSubject").Replace("[EMAIL]",
                                                                                             MainForm.
                                                                                                 EmailAddress),
                                          body);
             }
             else
             {
                 body = LocRm.GetString("YouTubeUploadMailBody").Replace("[USERNAME]",
                                                                          MainForm.Conf.WSUsername);
                 body = body.Replace("[INFO]", videoid);
                 WsWrapper.SendContent(em, LocRm.GetString("YouTubeUploadMailSubject"), body);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void Troubleshooter()
        {
            //causes a reset of detected ip addresses
            MainForm.AddressIPv4 = MainForm.Conf.IPv4Address;
            MainForm.AddressIPv6 = MainForm.Conf.IPv6Address;

            UISync.Execute(() => rtbOutput.Clear());

            try
            {
                MainForm.StopAndStartServer();
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex);
            }

            bool portMapOk = false;
            bool bIPv6     = MainForm.Conf.IPMode == "IPv6";

            UISync.Execute(() => button2.Enabled = false);



            string localserver = (MainForm.Conf.SSLEnabled?"https":"http") + "://" + MainForm.IPAddress + ":" + MainForm.Conf.LANPort;

            UISync.Execute(() => rtbOutput.Text = $"Local iSpy Server: {localserver}{NL}");
            if (webports.IndexOf("," + MainForm.Conf.LANPort + ",", StringComparison.Ordinal) == -1)
            {
                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}");
            }
            if (MainForm.IPAddress.StartsWith("169.254"))
            {
                UISync.Execute(() => rtbOutput.Text += NL + "Warning: Your network adaptor has assigned itself a link-local address (169.254.x.x). This means your PC is setup for DHCP but can't find a DHCP server and iSpy will be unavailable over your LAN. Try resetting your router." + NL);
            }
            if (MainForm.Conf.SSLEnabled)
            {
                UISync.Execute(() => rtbOutput.Text += "Warning: Using SSL - disable SSL in settings if you are having problems with connecting." + NL);
            }
            if (MainForm.Conf.SpecificIP)
            {
                UISync.Execute(
                    () =>
                    rtbOutput.Text +=
                        "Warning: You are binding to a specific IP address. This can cause issues on systems with multiple NICs. Try unchecking the Bind To IP Address option in settings/ web server if you have problems." +
                        NL);
            }

            UISync.Execute(() => rtbOutput.Text += "Checking local server... ");
            Application.DoEvents();
            string res = "";

            if (!loadurl(localserver + "/ping", out res))
            {
                string res1 = res;
                UISync.Execute(() => rtbOutput.Text += $"Failed: {res1}{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("ispy", StringComparison.Ordinal) != -1)
                {
                    UISync.Execute(() => rtbOutput.Text += "OK");
                }
                else
                {
                    string res1 = res;
                    UISync.Execute(() => rtbOutput.Text += $"Unexpected output: {res1}");
                }
            }
            UISync.Execute(() => rtbOutput.Text += NL);
            UISync.Execute(() => rtbOutput.Text += "Checking WebServer... ");
            Application.DoEvents();
            if (!loadurl(MainForm.Webserver + "/webservices/ispyapi.asmx", out res))
            {
                UISync.Execute(() => rtbOutput.Text += "Webservices not responding.");
            }
            else
            {
                if (res.IndexOf("error occurred while", StringComparison.Ordinal) != -1)
                {
                    UISync.Execute(() => rtbOutput.Text += "Error with webservices. Please try again later (check your internet connection).");
                }
                else
                {
                    UISync.Execute(() => rtbOutput.Text += "OK");
                }
            }
            UISync.Execute(() => rtbOutput.Text += NL);
            UISync.Execute(() => rtbOutput.Text += "Checking your firewall... ");
            Application.DoEvents();
            var fw = new FireWall();

            fw.Initialize();

            bool bOn;
            var  r = fw.IsWindowsFirewallOn(out bOn);

            if (r == FireWall.FwErrorCode.FwNoerror)
            {
                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* - add ispy.exe to the windows firewall allowed list");
                    }
                    else
                    {
                        UISync.Execute(() => rtbOutput.Text += "iSpy is enabled");
                    }
                }
                else
                {
                    UISync.Execute(() => rtbOutput.Text += "Firewall is off");
                }
            }
            else
            {
                UISync.Execute(() => rtbOutput.Text += "Firewall error: " + r);
            }
            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
            {
                string[] result1 = result;
                UISync.Execute(() => rtbOutput.Text += "Found: " + result1[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)
                                {
                                    int maps = 0;
                                    try
                                    {
                                        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;
                                                    }
                                                }
                                            }
                                            maps++;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        UISync.Execute(
                                            () => rtbOutput.Text += "Port mapping lookup failed (" + ex.Message.Trim() + "). If the connection fails try resetting your router or manually configure port forwarding. " + NL);
                                        if (maps == 0)
                                        {
                                            throw;
                                        }
                                    }
                                    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)
                        {
                            Logger.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] != "")
                    {
                        MainForm.Conf.Loopback = MainForm.LoopBack = false;
                        UISync.Execute(() => rtbOutput.Text += "iSpyConnect is trying to contact your server at: " + result[6] + NL);
                        UISync.Execute(() => rtbOutput.Text += "Failed: " + result[3] + NL);
                        if (!bIPv6)
                        {
                            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. ");
                            }
                        }

                        if (MainForm.AddressListIPv4.Length > 1)
                        {
                            UISync.Execute(() => rtbOutput.Text += NL + "Warning: There are multiple network adaptors in your PC. Try selecting a different IP address to listen on in iSpy web settings or disable unused network adaptors and restart iSpy: " + NL);
                            foreach (var ip in MainForm.AddressListIPv4)
                            {
                                string ip1 = ip.ToString();
                                if (ip1 != MainForm.IPAddress)
                                {
                                    UISync.Execute(() => rtbOutput.Text += "\t" + ip1 + NL);
                                }
                            }
                        }
                        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)");

                            MainForm.Conf.Loopback = MainForm.LoopBack = true;
                        }
                    }
                }
                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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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 + Environment.NewLine + LocRm.GetString("TryDifferentPort"));
                return;
            }

            if (!String.IsNullOrWhiteSpace(txtUsername.Text.Trim()))
            {
                try
                {
                    var fw = new FireWall();
                    var r  = fw.Initialize();
                    if (r == FireWall.FwErrorCode.FwNoerror)
                    {
                        bool bOn;
                        r = fw.IsWindowsFirewallOn(out bOn);
                        if (r == FireWall.FwErrorCode.FwNoerror)
                        {
                            if (bOn)
                            {
                                string strApplication = Application.StartupPath + "\\iSpy.exe";
                                bool   bEnabled       = false;
                                r = fw.IsAppEnabled(strApplication, ref bEnabled);
                                if (r == FireWall.FwErrorCode.FwNoerror)
                                {
                                    if (!bEnabled)
                                    {
                                        fw.AddApplication(strApplication, "iSpy");
                                    }
                                }
                            }
                        }
                    }
                    if (r != FireWall.FwErrorCode.FwNoerror)
                    {
                        throw new Exception(r.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex);
                    MessageBox.Show(this,
                                    LocRm.GetString("ErrorFromFirewall") + Environment.NewLine + ex.Message + Environment.NewLine +
                                    LocRm.GetString("AddFirewallExceptionManually"));
                }

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

                MainForm.Conf.DHCPReroute = chkReroute.Checked;
                MainForm.Conf.SpecificIP  = chkBindSpecific.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(LocRm.GetString("NoResponse"), 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");
        }
Ejemplo n.º 5
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)
                {
                    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[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()),
                                            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()),
                                            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[0].ToLower().IndexOf("login") == -1)
                        {
                            MessageBox.Show(result[0], LocRm.GetString("Error"));
                        }
                        else
                        {
                            MessageBox.Show(result[0], 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");
        }