public static void DeleteAllContent(int objectTypeId, int objectid) { var dir = GetMediaDirectory(objectTypeId, objectid); var dirName = GetDirectory(objectTypeId, objectid); if (objectTypeId == 1) { var lFi = new List <FileInfo>(); var dirinfo = new DirectoryInfo(dir + "audio\\" + dirName + "\\"); lFi.AddRange(dirinfo.GetFiles()); lFi = lFi.FindAll(f => f.Extension.ToLower() == ".mp3"); foreach (FileInfo fi in lFi) { try { FileOperations.Delete(fi.FullName); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } } } if (objectTypeId == 2) { var lFi = new List <FileInfo>(); var dirinfo = new DirectoryInfo(dir + "video\\" + dirName + "\\"); lFi.AddRange(dirinfo.GetFiles()); lFi = lFi.FindAll(f => f.Extension.ToLower() == ".mp4" || f.Extension.ToLower() == ".avi"); foreach (FileInfo fi in lFi) { try { FileOperations.Delete(fi.FullName); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } } System.Array.ForEach(Directory.GetFiles(dir + "video\\" + dirName + "\\thumbs\\"), delegate(string path) { try { FileOperations.Delete(path); } catch { // ignored } }); } }
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; 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") }); }
private static void ReconnectElapsed(object sender, ElapsedEventArgs e) { try { string s = Wsa.Ping(); if (s == "OK") { ReconnectTimer.Stop(); MainForm.LogMessageToFile("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; MainForm.LogMessageToFile("Connected"); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); ReconnectTimer.Start(); } } } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } }
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) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
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")); }
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) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
public static string ProductLatestVersion(int productId) { string r = ""; if (WebsiteLive) { try { //call the real website... using (var ws = new iSpyAPI()) { Debug.WriteLine("WEBSERVICE CALL: ProductLatestVersionGet"); r = ws.ProductLatestVersionGet(productId); } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
public static string SendFrameGrab(string emailAddress, string subject, string message, byte[] imageData) { if (!MainForm.Conf.ServicesEnabled) { return(WebservicesDisabledMessage); } string r = ""; if (WebsiteLive) { try { r = Wsa.SendFrameGrab(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, emailAddress, subject, message, imageData); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
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") { MainForm.LogMessageToFile(r); } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
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); } }
private void FinishPTZRequest(IAsyncResult result) { var myRequestState = (RequestState)result.AsyncState; WebRequest myWebRequest = myRequestState.Request; // End the Asynchronous request. try { myRequestState.Response = myWebRequest.EndGetResponse(result); myRequestState.Response.Close(); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } myRequestState.Response = null; myRequestState.Request = null; _request = null; if (_nextcommand != "") { string nc = _nextcommand; _nextcommand = ""; SendPTZCommand(nc); } }
public static bool SetPorts(int wanPort, int lanPort) { bool b = false; int i = 3; while (Mappings == null && i > 0) { Thread.Sleep(2000); i--; } if (Mappings != null) { try { Mappings.Remove(wanPort, "TCP"); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } try { Mappings.Add(wanPort, "TCP", lanPort, MainForm.AddressIPv4, true, "iSpy"); b = true; } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } } return(b); }
public static bool Send(string to, string subject, string body, byte[] attach) { bool success = true; try { to = to.Replace(",", ";"); string[] addrs = to.Split(';'); var sendFrom = new MailAddress(MainForm.Conf.SMTPFromAddress.Trim()); var sendTo = new MailAddress(addrs[0].Trim()); var myMessage = new MailMessage(sendFrom, sendTo) { Subject = subject.Replace(Environment.NewLine, " ").Trim(), Body = body, IsBodyHtml = true }; if (addrs.Length > 1) { for (int i = 1; i < addrs.Length && i < 5; i++) { if (IsValidEmail(addrs[i].Trim())) { myMessage.Bcc.Add(new MailAddress(addrs[i].Trim())); } } } if (attach != null && attach.Length > 0) { var attachFile = new Attachment(new MemoryStream(attach), "Screenshot.jpg"); myMessage.Attachments.Add(attachFile); } var emailClient = new SmtpClient(MainForm.Conf.SMTPServer, MainForm.Conf.SMTPPort) { UseDefaultCredentials = false, Credentials = new NetworkCredential(MainForm.Conf.SMTPUsername, MainForm.Conf.SMTPPassword), EnableSsl = MainForm.Conf.SMTPSSL }; emailClient.Send(myMessage); myMessage.Dispose(); myMessage = null; emailClient.Dispose(); emailClient = null; } catch (Exception ex) { success = false; MainForm.LogExceptionToFile(ex); } return(success); }
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(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; } } //MainForm.LogMessageToFile("Webservices: " + r); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive) { LoginFailed = (r == "Webservices_LoginFailed"); if (r != "OK") { MainForm.LogErrorToFile("Webservices: " + r); return(LocRm.GetString(r)); } return(r); } } return(LocRm.GetString("iSpyDown")); }
public static string LoadCertificate(string fileName) { try { _sslCertificate = X509Certificate.CreateFromCertFile(fileName); MainForm.LogMessageToFile("Loaded SSL Certificate: " + _sslCertificate.ToString(false)); return("OK"); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); return(ex.Message); } }
private static bool SendRTSPReq(string addr, string login, string password) { bool b = false; try { var uri = new Uri(addr); var request = "OPTIONS " + addr + " RTSP/1.0\r\n" + "CSeq: 1\r\n" + "User-Agent: iSpy\r\n" + "Accept: */*\r\n"; if (!String.IsNullOrEmpty(login)) { var authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(login + ":" + password)); request += "Authorization: Basic " + authInfo + "\r\n"; } request += "\r\n"; IPAddress host = IPAddress.Parse(uri.DnsSafeHost); var hostep = new IPEndPoint(host, uri.Port); var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { ReceiveTimeout = 2000 }; sock.Connect(hostep); var response = sock.Send(Encoding.UTF8.GetBytes(request)); if (response > 0) { var bytesReceived = new byte[200]; var bytes = sock.Receive(bytesReceived, bytesReceived.Length, 0); string resp = Encoding.ASCII.GetString(bytesReceived, 0, bytes); if (resp.IndexOf("200 OK", StringComparison.Ordinal) != -1) { b = true; } MainForm.LogMessageToFile("RTSP attempt: " + resp + " at " + addr); } sock.Close(); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } return(b); }
static void WsaSendTweetCompleted(object sender, SendTweetCompletedEventArgs e) { if (e.Error != null) { MainForm.LogExceptionToFile(e.Error); } else { if (e.Result != "OK") { MainForm.LogErrorToFile("Send Tweet: " + e.Result); } } }
private static void AddCameraToDatabase(string type, string model, string prefix, string source, string url, string cookies, string flags, int port) { try { var r = new Reporting.Reporting { Timeout = 8000 }; r.AddCamera2(type, model, prefix, source, url, cookies, flags, port); r.Dispose(); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } }
private void AddFloorPlanLoad(object sender, EventArgs e) { txtName.Text = Fpc.Fpobject.name; if (Fpc.Fpobject.image != "") { try { _floorPlanImage = (Bitmap)Image.FromFile(Fpc.Fpobject.image); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } } lbObjects.AllowDrop = true; _pnlPlan = new PictureBox { Location = new Point(64, 0), Size = new Size(533, 400), AllowDrop = true }; pnlFloorPlan.Controls.Add(_pnlPlan); _floorPlanEntries = new List <objectsFloorplanObjectsEntry>(); foreach (objectsFloorplanObjectsEntry fpobj in Fpc.Fpobject.objects.@object) { _floorPlanEntries.Add(fpobj); } ShowObjects(); _pnlPlan.DragDrop += PnlPlanDragDrop; _pnlPlan.DragEnter += PnlPlanDragEnter; _pnlPlan.DragOver += PnlPlanDragOver; _pnlPlan.MouseDown += PMouseDown; _pnlPlan.MouseUp += PMouseUp; _pnlPlan.MouseMove += PMouseMove; _pnlPlan.Paint += PnlPlanPaint; chkOriginalSize.Checked = Fpc.Fpobject.originalsize; txtAccessGroups.Text = Fpc.Fpobject.accessgroups; _pnlPlan.Invalidate(); if (Fpc.Fpobject.id > -1) { Text = LocRm.GetString("EditFloorPlan"); } }
static void WsaSyncCompleted(object sender, SyncCompletedEventArgs e) { if (e.Error != null) { WebsiteLive = false; MainForm.NeedsSync = true; MainForm.LogExceptionToFile(e.Error); } else { if (e.Result != "OK") { MainForm.LogErrorToFile("Sync: " + e.Result); } } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { try { var fi = new FileInfo(_filename); if (_fbdSaveTo.ShowDialog(Handle)) { File.Copy(_filename, _fbdSaveTo.FileName + @"\" + fi.Name); } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } }
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") }); }
private void SendPtzCommand(string cmd, bool wait) { if (cmd == "") { MessageBox.Show(LocRm.GetString("CommandNotSupported")); return; } try { CameraControl.Calibrating = true; CameraControl.PTZ.SendPTZCommand(cmd, wait); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); MessageBox.Show( LocRm.GetString("Validate_Camera_PTZIPOnly"), LocRm.GetString("Error")); } }
private void BtnFeedbackClick(object sender, EventArgs e) { bool success = false; string feedback = txtFeedback.Text.Trim(); if (feedback == "") { MessageBox.Show(LocRm.GetString("Feedback_PleaseEnter"), LocRm.GetString("Error")); return; } string fromEmail = txtEmail.Text.Trim(); if (!IsValidEmail(fromEmail)) { if ( MessageBox.Show(LocRm.GetString("Feedback_ValidateEmail"), LocRm.GetString("AreYouSure"), MessageBoxButtons.YesNo) == DialogResult.No) { return; } } var rep = new Reporting.Reporting(); try { rep.SendFeedback("iSpy Feedback: " + feedback + "<br/><br/>Version: " + Application.ProductVersion, fromEmail); success = true; rep.Dispose(); } catch (Exception ex) { rep.Dispose(); MainForm.LogExceptionToFile(ex); MessageBox.Show(LocRm.GetString("Feedback_NotSent"), LocRm.GetString("Error")); } if (success) { MessageBox.Show(LocRm.GetString("Feedback_Sent"), LocRm.GetString("Note")); Close(); } }
private void ScanNetwork() { _exiting = false; _dt = new DataTable("Network"); _dt.Columns.Add(new DataColumn("IP Address")); _dt.Columns.Add(new DataColumn("Port")); _dt.Columns.Add(new DataColumn("Device Name")); _dt.Columns.Add(new DataColumn("WebServer")); _dt.Columns.Add(new DataColumn("MAC Address")); _dt.AcceptChanges(); dataGridView1.DataSource = _dt; string host = ddlHost.SelectedItem.ToString(); var nb = new NetworkBrowser(); DnsEntries.Clear(); try { foreach (string s1 in nb.GetNetworkComputers()) { var ipEntry = Dns.GetHostEntry(s1.Trim('\\')); var addr = ipEntry.AddressList.Where(p => p.AddressFamily == AddressFamily.InterNetwork); foreach (var t in addr) { DnsEntries.Add(t.ToString().Trim()); } } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } var manager = new Thread(p => PortScannerManager(host)) { Name = "Port Scanner", IsBackground = false, Priority = ThreadPriority.Normal }; manager.Start(); }
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.Connect(MainForm.Conf.WSUsername, MainForm.Conf.WSPassword, port, MainForm.Identifier, tryLoopback, Application.ProductVersion, MainForm.Conf.ServerName, MainForm.Conf.IPMode == "IPv4", MainForm.IPAddressExternal); if (r == "OK" && tryLoopback) { MainForm.LoopBack = true; } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } if (WebsiteLive && r != "OK") { return(LocRm.GetString(r)); } if (WebsiteLive) { return(r); } } return(LocRm.GetString("iSpyDown")); }
public static bool Delete(string filePath) { try { if (MainForm.Conf.DeleteToRecycleBin) { MoveToRecycleBin(filePath); } else { DeleteCompletelySilent(filePath); } } catch (Exception ex) { MainForm.LogExceptionToFile(ex); return(false); } return(true); }
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) { MainForm.LogExceptionToFile(ex); WebsiteLive = false; } } }
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); } }
internal static bool ArchiveFile(string filename) { if (!string.IsNullOrEmpty(MainForm.Conf.Archive) && Directory.Exists(MainForm.Conf.Archive)) { string fn = filename.Substring(filename.LastIndexOf("\\", StringComparison.Ordinal) + 1); if (File.Exists(filename)) { try { if (!File.Exists(MainForm.Conf.Archive + fn)) { File.Copy(filename, MainForm.Conf.Archive + fn); } return(true); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); } } } return(false); }