Example #1
0
        public static string[] TestConnection(string username, string password, bool tryLoopback)
        {
            var r = new string[] {};

            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            try
            {
                _websitelive = true;
                r            = Wsa.TestConnection(username, password, port, MainForm.Identifier, tryLoopback, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddressExternal);
            }
            catch (Exception ex)
            {
                _websitelive = false;
                Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
            }
            if (_websitelive)
            {
                if (r.Length == 1 && r[0] != "OK") //login failed
                {
                    r[0] = LocRm.GetString(r[0]);
                }
                if (r.Length > 3 && r[3] != "")
                {
                    r[3] = LocRm.GetString(r[3]);
                }
                return(r);
            }
            return(new[] { LocRm.GetString("iSpyDown") });
        }
Example #2
0
        public static string Disconnect()
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }
                try
                {
                    r = Wsa.Disconnect(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port);
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #3
0
 private static void ReconnectElapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         string s = Wsa.Ping();
         if (s == "OK")
         {
             ReconnectTimer.Stop();
             Log.Info("Reconnecting...");
             if (MainForm.Conf.ServicesEnabled)
             {
                 try
                 {
                     s = Connect(MainForm.Conf.Loopback);
                     if (s == "OK")
                     {
                         MainForm.StopAndStartServer();
                         ForceSync(MainForm.IPAddress, MainForm.Conf.LANPort, MainForm.MWS.GetObjectList());
                     }
                     WebsiteLive = true;
                     Log.Info("Connected");
                 }
                 catch (Exception ex)
                 {
                     Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                     ReconnectTimer.Start();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
     }
 }
Example #4
0
        public static void DoPingRequest()
        {
            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            LastLiveCheck = Helper.Now;
            string[] r = null;
            try
            {
                //using IPAddress in both as the website determines remoteip for ipv4 or uses ipv6 for both internal and external

                r = Wsa.PingAlive(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddress, MainForm.IPAddress);
                if (r[0] != lastResponse)
                {
                    Logger.LogMessage("Ping: " + r[0]);
                }
                lastResponse = r[0];
                WebsiteLive  = true;
                _pingIndex   = 0;
            }
            catch (Exception ex)
            {
                WebsiteLive = false;
                Logger.LogException(ex, "Ping");
                _pingIndex = Math.Min(_pingIndex + 1, PingDelays.Length - 1);
            }
            _pingRequestThread = null;
        }
Example #5
0
        public static string SendSms(string smsNumber, string message)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r = Wsa.SendSMS(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, smsNumber,
                                    message);
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #6
0
        public static string SendContent(string emailAddress, string subject, string message)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r = Wsa.SendContent(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword,
                                        emailAddress, subject, message);
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #7
0
        public static string ExternalIPv4(bool refresh)
        {
            if (_externalIP != "" && !refresh)
            {
                return(_externalIP);
            }
            if (WebsiteLive)
            {
                try
                {
                    Debug.WriteLine("WEBSERVICE CALL: RemoteAddress");
                    _externalIP = Wsa.RemoteAddress();
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(_externalIP);
                }
            }
            if (_externalIP != "")
            {
                return(_externalIP);
            }

            return(LocRm.GetString("Unavailable"));
        }
Example #8
0
        public static string ExternalIPv4(bool refresh)
        {
            if (_externalIP != "" && !refresh)
            {
                return(_externalIP);
            }
            if (WebsiteLive)
            {
                try
                {
                    _externalIP = Wsa.RemoteAddress();
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(_externalIP);
                }
            }
            if (_externalIP != "")
            {
                return(_externalIP);
            }

            return(LocRm.GetString("Unavailable"));
        }
Example #9
0
        public static void DoPingRequest()
        {
            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            LastLiveCheck = Helper.Now;

            try
            {
                //using IPAddress in both as the website determines remoteip for ipv4 or uses ipv6 for both internal and external

                Wsa.PingAlive(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port,
                              MainForm.Conf.IPMode == "IPv4", MainForm.IPAddress, MainForm.IPAddress);

                WebsiteLive = true;
                _pingIndex  = 0;
            }
            catch
            {
                WebsiteLive = false;
                _pingIndex  = Math.Min(_pingIndex + 1, PingDelays.Length - 1);
            }
        }
Example #10
0
        public static string SendAlertWithImage(string emailAddress, string subject, string message, byte[] imageData)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r = Wsa.SendAlertWithImage(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword,
                                               emailAddress, subject, message, imageData);
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #11
0
        public static string SendTweet(string message)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r = Wsa.SendTweet(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, message);
                    if (r != "OK")
                    {
                        Log.Info(r);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #12
0
        public static void PingServer()
        {
            if (!MainForm.Conf.ServicesEnabled || LoginFailed || MainForm.ShuttingDown)
            {
                return;
            }

            try
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }

                LastLiveCheck = Helper.Now;
                Debug.WriteLine("WEBSERVICE CALL: PingServer");
                Wsa.PingAliveAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddressExternal, MainForm.IPAddress, Guid.NewGuid());
            }
            catch (Exception ex)
            {
                WebsiteLive = false;
                MainForm.LogExceptionToFile(ex);
            }
        }
Example #13
0
        public static string ExternalIPv4(bool refresh, out bool success)
        {
            if (_externalIP != "" && !refresh)
            {
                success = true;
                return(_externalIP);
            }
            if (WebsiteLive || refresh)
            {
                try
                {
                    Debug.WriteLine("WEBSERVICE CALL: RemoteAddress");
                    _externalIP = Wsa.RemoteAddress();
                    WebsiteLive = true;
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex, "Webservices");
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    success = true;
                    return(_externalIP);
                }
            }
            if (_externalIP != "")
            {
                success = true;
                return(_externalIP);
            }

            success = false;
            return(LocRm.GetString("Unavailable"));
        }
Example #14
0
 public static void SendTweet(string message)
 {
     if (!Enabled)
         return;
     Debug.WriteLine("WEBSERVICE CALL: Tweet");
     Wsa.SendTweetAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, message, Guid.NewGuid());
 }
Example #15
0
 public static void SendSms(string smsNumber, string message)
 {
     if (!Enabled)
         return;
     Debug.WriteLine("WEBSERVICE CALL: SendSMS");
     Wsa.SendSMSAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, smsNumber, message, Guid.NewGuid());
 }
Example #16
0
        public static string SendMms(string mobileNumber, string message, byte[] imageData)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r = Wsa.SendMMS(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword,
                                    mobileNumber, message, imageData);
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #17
0
        public static string Connect(bool tryLoopback)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }

                try
                {
                    bool   success;
                    string ip = MainForm.IPAddressExternal(false, out success);
                    if (success)
                    {
                        r = Wsa.Connect2(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port,
                                         MainForm.Identifier, tryLoopback, Application.ProductVersion,
                                         MainForm.Conf.ServerName, MainForm.Conf.IPMode == "IPv4", ip, MainForm.Affiliateid,
                                         X509.SslEnabled);
                        if (r == "OK" && tryLoopback)
                        {
                            MainForm.LoopBack = true;
                        }
                    }
                    //Logger.LogMessageToFile("Webservices: " + r);
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }

                if (WebsiteLive)
                {
                    LoginFailed = (r == "Webservices_LoginFailed");
                    if (r != "OK")
                    {
                        Logger.LogErrorToFile("Webservices: " + r);
                        return(LocRm.GetString(r));
                    }
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #18
0
        public static void SendContent(string emailAddress, string subject, string message)
        {
            if (MainForm.Conf.UseSMTP)
            {
                Mailer.Send(emailAddress, subject, message);
                return;
            }

            if (!Enabled)
                return;
            Debug.WriteLine("WEBSERVICE CALL: SendContentAsync");
            Wsa.SendContentAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, emailAddress, subject, message,Guid.NewGuid());
        }
Example #19
0
        private static void ForceSync(string internalIPAddress, int internalPort, string settings)
        {
            if (LoginFailed || !WebsiteLive || !MainForm.Conf.ServicesEnabled || MainForm.ShuttingDown)
                return;

            MainForm.NeedsSync = false;
            int port = MainForm.Conf.ServerPort;
            if (MainForm.Conf.IPMode == "IPv6")
                port = MainForm.Conf.LANPort;

            bool success;
            string ip = MainForm.IPAddressExternal(out success);
            Debug.WriteLine("WEBSERVICE CALL: ForceSync");
            if (success)
                Wsa.SyncAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, internalIPAddress, internalPort, settings, MainForm.Conf.IPMode == "IPv4", ip, Guid.NewGuid());
        }
Example #20
0
        public static string[] TestConnection(string username, string password, bool tryLoopback)
        {
            var r = new string[] {};

            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            try
            {
                if (MainForm.CustomWebserver)
                {
                    r = Wsa.TestConnection2(username, password, port, MainForm.Identifier, tryLoopback, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddress, X509.SslEnabled);
                }
                else
                {
                    r = Wsa.TestConnection3(username, password, port, MainForm.Identifier, tryLoopback, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddress, X509.SslEnabled);
                }
                WebsiteLive = true;
            }
            catch (Exception ex)
            {
                WebsiteLive = false;
                Logger.LogException(ex);
            }
            if (WebsiteLive)
            {
                LoginFailed = (r[0] == "Webservices_LoginFailed" || r[0] == "Expired");
                if (r.Length == 1 && r[0] != "OK")
                {
                    r[0] = LocRm.GetString(r[0]);
                    Logger.LogError("Webservices: " + r[0]);
                }
                if (r.Length > 3 && r[3] != "")
                {
                    r[3] = LocRm.GetString(r[3]);
                    Logger.LogError("Webservices: " + r[3]);
                }
                return(r);
            }

            return(new[] { LocRm.GetString("iSpyDown") });
        }
Example #21
0
 public static void Disconnect()
 {
     if (MainForm.Conf.ServicesEnabled && WebsiteLive && !LoginFailed)
     {
         int port = MainForm.Conf.ServerPort;
         if (MainForm.Conf.IPMode == "IPv6")
             port = MainForm.Conf.LANPort;
         try
         {
             Wsa.DisconnectAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, Guid.NewGuid());                       
         }
         catch (Exception ex)
         {
             Logger.LogExceptionToFile(ex);
             WebsiteLive = false;
         }
     }
 }
Example #22
0
        public static void SendAlertWithImage(string emailAddress, string subject, string message, byte[] imageData)
        {
            if (MainForm.Conf.UseSMTP)
            {
                Mailer.Send(emailAddress, subject, message, imageData);
                return;
            }

            if (!Enabled)
                return;
            if (imageData.Length == 0)
            {
                SendAlert(emailAddress, subject, message);
                return;
            }
            Debug.WriteLine("WEBSERVICE CALL: SendAlertWithImageAsync");
            Wsa.SendAlertWithImageAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, emailAddress, subject, message, imageData,Guid.NewGuid());
        }
Example #23
0
        public static string[] TestConnection(string username, string password, bool tryLoopback)
        {
            var r = new string[] {};

            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            try
            {
                bool   success;
                string ip = MainForm.IPAddressExternal(out success);
                if (success)
                {
                    r           = Wsa.TestConnection2(username, password, port, MainForm.Identifier, tryLoopback, MainForm.Conf.IPMode == "IPv4", ip, X509.SslEnabled);
                    WebsiteLive = true;
                }
            }
            catch (Exception ex)
            {
                WebsiteLive = false;
                MainForm.LogExceptionToFile(ex);
            }
            if (WebsiteLive)
            {
                LoginFailed = (r[0] == "Webservices_LoginFailed");
                if (r.Length == 1 && r[0] != "OK")
                {
                    r[0] = LocRm.GetString(r[0]);
                    MainForm.LogErrorToFile("Webservices: " + r[0]);
                }
                if (r.Length > 3 && r[3] != "")
                {
                    r[3] = LocRm.GetString(r[3]);
                    MainForm.LogErrorToFile("Webservices: " + r[3]);
                }
                return(r);
            }

            return(new[] { LocRm.GetString("iSpyDown") });
        }
Example #24
0
        public static void Disconnect()
        {
            if (MainForm.Conf.ServicesEnabled && WebsiteLive && !LoginFailed)
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }

                try
                {
                    Wsa.Disconnect(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port);
                }
                catch
                {
                }
            }
        }
Example #25
0
        public static string Connect(bool tryLoopback)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return(WebservicesDisabledMessage);
            }
            string r = "";

            if (WebsiteLive)
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }

                try
                {
                    r = Wsa.Connect2(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port,
                                     MainForm.Identifier, tryLoopback, Application.ProductVersion,
                                     MainForm.Conf.ServerName, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddressExternal, MainForm.AFFILIATEID);
                    if (r == "OK" && tryLoopback)
                    {
                        MainForm.LoopBack = true;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive && r != "OK")
                {
                    return(LocRm.GetString(r));
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #26
0
        private static void ForceSync(string internalIPAddress, int internalPort)
        {
            if (LoginFailed || !WebsiteLive || !MainForm.Conf.ServicesEnabled || MainForm.ShuttingDown)
            {
                return;
            }

            string settings = MainForm.MWS.GetObjectList();

            MainForm.NeedsSync = false;
            int port = MainForm.Conf.ServerPort;

            if (MainForm.Conf.IPMode == "IPv6")
            {
                port = MainForm.Conf.LANPort;
            }

            Debug.WriteLine("WEBSERVICE CALL: ForceSync");
            Wsa.SyncAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, internalIPAddress, internalPort, settings, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddress, Guid.NewGuid());
        }
Example #27
0
        public static void PingServer()
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return;
            }

            try
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }
                Wsa.PingAlive3Completed += WsaPingAlive3Completed;
                Wsa.PingAlive3Async(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddressExternal);
            }
            catch (Exception ex)
            {
                _websitelive = false;
                MainForm.LogExceptionToFile(ex);
            }
        }
Example #28
0
        private static void ForceSync(string internalIPAddress, int internalPort, string settings)
        {
            if (!MainForm.Conf.ServicesEnabled)
            {
                return;
            }
            if (WebsiteLive)
            {
                int port = MainForm.Conf.ServerPort;
                if (MainForm.Conf.IPMode == "IPv6")
                {
                    port = MainForm.Conf.LANPort;
                }

                string ip = MainForm.IPAddressExternal;
                if (WebsiteLive)
                {
                    Wsa.SyncCompleted += WsaSyncCompleted;
                    Wsa.SyncAsync(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port,
                                  internalIPAddress, internalPort, settings, MainForm.Conf.IPMode == "IPv4", ip);
                }
            }
        }
Example #29
0
        public static string ProductLatestVersion(int productId)
        {
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    r           = Wsa.ProductLatestVersionGet(productId);
                    WebsiteLive = true;
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);//MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }
Example #30
0
        public static string ProductLatestVersion(int productId)
        {
            string r = "";

            if (WebsiteLive)
            {
                try
                {
                    Debug.WriteLine("WEBSERVICE CALL: ProductLatestVersionGet");
                    r           = Wsa.ProductLatestVersionGet(productId);
                    WebsiteLive = true;
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex);
                    WebsiteLive = false;
                }
                if (WebsiteLive)
                {
                    return(r);
                }
            }
            return(LocRm.GetString("iSpyDown"));
        }