void UploaderThread() { while (file.Position < filesz) { Int64 blksz; Int64 nchunk = 512 * 1024; if (nchunk > filesz - file.Position) nchunk = filesz - file.Position; byte[] data = new byte[nchunk]; blksz = file.Read(data, 0, data.Length); currentsz += blksz; counter++; UploadData ud = new UploadData(); ud.Counter = counter; ud.data = data; ud.Size = blksz; ud.MD5 = MD5Utilities.CalcMD5(data); if (this.net.UploadData(ud) == false) { lasterror = this.net.GetLastError(); this.net.CloseConnection(); file.Close(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnError)); return; } if (CancelThread == true) { lasterror = "Canceled"; this.net.UploadCancel(); this.net.CloseConnection(); file.Close(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnCancel)); return; } this.BeginInvoke(new voidy(UpdatePromille)); } file.Close(); NewUploadDataID nid = this.net.UploadFinalise(); if (nid == null) { lasterror = this.net.GetLastError(); this.net.CloseConnection(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnError)); return; } this.net.CloseConnection(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new newd(OnSuccess), nid); }
private void CompareFiles() { ListView.SelectedListViewItemCollection files = listViewMain.SelectedItems; string sourceDir = $"{comboBoxFolder.Text}\\{treeViewMain.SelectedNode.FullPath}"; string sourceFile = $"{sourceDir}\\{files[0].Text}"; string vvDir = $"{(string)vvConfig.GetValue("VVPath")}\\{treeViewMain.SelectedNode.FullPath}\\{files[0].Text}"; string vvFile = $"{vvDir}\\{((VVItem)listBoxVV.SelectedItem).ItemName}"; if (File.Exists(sourceFile)) { // check if files are exactly the same FileInfo sourceInfo = new FileInfo(sourceFile); FileInfo vvInfo = new FileInfo(vvFile); if (sourceInfo.Length == vvInfo.Length && MD5Utilities.CalcMD5(sourceFile) == MD5Utilities.CalcMD5(vvFile)) { MessageBox.Show("Files are identical", _appName, MessageBoxButtons.OK); } else { // launch ExternalCompareApp process with the two files string compareApp = Properties.Settings.Default.ExternalCompareApp; string compareOptions = Properties.Settings.Default.ExternalCompareAppOptions; Process p = Process.Start(compareApp, $"{compareOptions} \"{sourceFile}\" \"{vvFile}\""); p.WaitForExit(); int result = p.ExitCode; } } else { // launch file viewer (default = notepad) to show the deleted file string compareApp = Properties.Settings.Default.ExternalFileViewer; Process p = Process.Start(compareApp, $"\"{vvFile}\""); p.WaitForExit(); int result = p.ExitCode; } }
public RESTStatus UploadData(SQLLib sql, UploadData data, NetworkConnectionInfo ni) { if (ni.Upload == null) { ni.Error = "Upload is not running"; ni.ErrorID = ErrorFlags.UploadNotRunning; return(RESTStatus.Fail); } if (data.Size < 0) { ni.Error = "Negative SZ"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } if (data.Size > Consts.MaxFileChunk) { ni.Error = "Chunk too large"; ni.ErrorID = ErrorFlags.ChunkTooLarge; return(RESTStatus.Fail); } if (data == null) { ni.Error = "No data"; ni.ErrorID = ErrorFlags.NoData; return(RESTStatus.Fail); } if (data.data.Length != data.Size) { ni.Error = "Faulty sizes"; ni.ErrorID = ErrorFlags.FaultySizes; return(RESTStatus.Fail); } if (ni.Upload.CurrentPosition + data.Size > ni.Upload.Size) { ni.Error = "Too many data"; ni.ErrorID = ErrorFlags.TooManyData; return(RESTStatus.Fail); } if (ni.Upload.Counter + 1 != data.Counter) { ni.Error = "Invalid count"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } if (MD5Utilities.CalcMD5(data.data).ToLower() != data.MD5.ToLower()) { ni.Error = "MD5 error"; ni.ErrorID = ErrorFlags.CheckSumError; return(RESTStatus.Fail); } ni.Upload.Data.Write(data.data, 0, data.data.Length); ni.Upload.Counter++; ni.Upload.CurrentPosition += data.Size; return(RESTStatus.Success); }
public RESTStatus ComputerLogin(SQLLib sql, RecoveryLogon logon, NetworkConnectionInfo ni, string IPAddress) { RD = new RecoveryData(); if (Fox_LicenseGenerator.SDCLicensing.ValidLicense == false) { RD.Worked = false; return(RESTStatus.Fail); } if (Fox_LicenseGenerator.SDCLicensing.TestExpiry() == false) { RD.Worked = false; return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(logon.UCID) == true) { RD.Worked = false; return(RESTStatus.Fail); } if (Settings.Default.UseContract == true) { if (string.IsNullOrWhiteSpace(logon.ContractID) == true || string.IsNullOrWhiteSpace(logon.ContractPassword) == true) { RD.Worked = false; return(RESTStatus.Fail); } } string newID = NetworkConnection.NewSession(); ni = NetworkConnection.GetSession(newID); if (NetworkConnectionProcessor.InitNi(ni) == false) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.ServerError); } sql = ni.sql; if (Settings.Default.UseContract == true) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT Count(*) FROM Contracts WHERE ContractID=@id AND ContractPassword=@pw AND Disabled=0", new SQLParam("@id", logon.ContractID), new SQLParam("@pw", logon.ContractPassword))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE ContractID=@id AND UCID=@u", new SQLParam("@id", logon.ContractID), new SQLParam("@u", logon.UCID))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } } if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE UCID=@u", new SQLParam("@u", logon.UCID))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM ComputerAccounts WHERE UCID=@u", new SQLParam("@u", logon.UCID)); dr.Read(); string Check = Convert.ToString(dr["CPUName"]).Trim(); Check += Convert.ToString(dr["ComputerModel"]).Trim(); Check += Convert.ToString(dr["BIOS"]).Trim(); string MD5 = MD5Utilities.CalcMD5(Check); if (MD5.ToLower() != logon.MoreMachineHash.ToLower()) { dr.Close(); NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } RD.MachineID = Convert.ToString(dr["MachineID"]); RD.MachinePassword = Convert.ToString(dr["Password"]); RD.Worked = true; dr.Close(); NetworkConnection.DeleteSession(newID); return(RESTStatus.Success); }
public static void SMain() { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; #endif FoxEventLog.RegisterEventLog(); if (UsePipeAction == false && UseScreenAction == false && UseDNSAutoConfig == false && UseLoginRecovery == false) //Pipe Actions can also be run in user-space ... { if (IsSystemUser() != true) { #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } } if (LoadDLL() == false) { #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } #if !DEBUG if (TestIntegrity(null) == false) { FoxEventLog.WriteEventLog("Integrity check failed!", EventLogEntryType.Error); service.Stop(); return; } #endif if (UseDNSAutoConfig == true) { try { List <List <string> > Query = CPP.DNSQueryTXT("sdc-contract.my-vulpes-config.lu"); if (Query == null) { return; } string ContractID = null; string ContractPassword = null; string UseOnPrem = null; string OnPremURL = null; foreach (List <string> Q in Query) { if (Q == null) { continue; } foreach (string QR in Q) { if (string.IsNullOrWhiteSpace(QR) == true) { continue; } if (QR.ToLower().StartsWith("contractid=") == true) { ContractID = QR.Substring(11).Trim(); } if (QR.ToLower().StartsWith("contractpassword="******"useonprem=") == true) { UseOnPrem = QR.Substring(10).Trim(); } if (QR.ToLower().StartsWith("onpremurl=") == true) { OnPremURL = QR.Substring(10).Trim(); } } } using (RegistryKey k = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Fox\\SDC")) { if (string.IsNullOrWhiteSpace(ContractID) == false && string.IsNullOrWhiteSpace(ContractPassword) == false) { k.SetValue("ContractID", ContractID, RegistryValueKind.String); k.SetValue("ContractPassword", ContractPassword, RegistryValueKind.String); } int UseOnPremInt; if (int.TryParse(UseOnPrem, out UseOnPremInt) == true) { if (UseOnPremInt == 1 && string.IsNullOrWhiteSpace(OnPremURL) == false) { k.SetValue("UseOnPremServer", 1, RegistryValueKind.DWord); k.SetValue("Server", OnPremURL, RegistryValueKind.String); } else { k.SetValue("UseOnPremServer", 0, RegistryValueKind.DWord); } } else { k.SetValue("UseOnPremServer", 0, RegistryValueKind.DWord); } } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } return; } if (UseLoginRecovery == true) { if (SystemInfos.CollectSystemInfo() != 0) { return; } #if !DEBUG if (SystemInfos.SysInfo.RunningInWindowsPE == false || SystemInfos.SysInfo.RunningInWindowsPE == null) { return; } #endif RecoveryLogon reclogon = new RecoveryLogon(); reclogon.UCID = SystemInfos.SysInfo.UCID; reclogon.ContractID = SystemInfos.ContractID; reclogon.ContractPassword = SystemInfos.ContractPassword; string Check = SystemInfos.SysInfo.CPUName.Trim(); Check += SystemInfos.SysInfo.ComputerModel == "" ? "N/A" : SystemInfos.SysInfo.ComputerModel.Trim(); Check += SystemInfos.SysInfo.BIOS == "" ? "N/A" : SystemInfos.SysInfo.BIOS.Trim(); reclogon.MoreMachineHash = MD5Utilities.CalcMD5(Check); Network net = Utilities.NoConnectNetwork(); RecoveryData rd = net.GetRecoveryLogon(reclogon); if (rd == null) { return; } if (rd.Worked == false) { return; } string Registry = "Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Fox\\SDC]\r\n\"ID\"=\"" + rd.MachineID + "\"\r\n\"PassID\"=\"" + rd.MachinePassword + "\""; try { File.WriteAllText(Environment.ExpandEnvironmentVariables("%SYSTEMROOT%\\Fox SDC MachinePW.reg"), Registry, Encoding.Unicode); } catch { } return; } if (UsePipeAction == false && UseScreenAction == false) { using (RegistryKey installer = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + VulpesBranding.MSIGUID, false)) { if (installer == null) { FoxEventLog.WriteEventLog("Missing installer key in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + VulpesBranding.MSIGUID + ". This can lead to erratic behavoir of the program!", EventLogEntryType.Warning); } } if (CPP.SetToken() == false) { FoxEventLog.WriteEventLog("Cannot setup token - 0x" + Marshal.GetLastWin32Error().ToString("X") + " - " + new Win32Exception(Marshal.GetLastWin32Error()).Message, System.Diagnostics.EventLogEntryType.Error); return; } } if (UsePipeAction == true) { try { Process2ProcessCommClient.RunPipeClient(); } catch (Exception ee) { FoxEventLog.WriteEventLog("Pipe SEH " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } return; } if (UseScreenAction == true) { try { if (SystemInfos.CollectSystemInfo() != 0) { return; } MainScreenSystemClient.RunPipeClient(); } catch (Exception ee) { FoxEventLog.WriteEventLog("Screen Pipe SEH " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } return; } if (SystemInfos.CollectSystemInfo() != 0) { #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } RegistryData.InstallPath = AppPath; if (ApplicationCertificate.LoadCertificate() == false) { FoxEventLog.WriteEventLog("Cannot load certificate", System.Diagnostics.EventLogEntryType.Error); #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } if (FilesystemData.LoadCertificates() == false) { #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } if (FilesystemData.LoadPolicies() == false) { #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return; } FilesystemData.LoadLocalPackageData(); FilesystemData.LoadLocalPackages(); FilesystemData.LoadUserPackageData(); FilesystemData.LoadEventLogList(); SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplySystem); PipeCommunicationSRV.StartPipeSrv(); try { string p = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (p.EndsWith("\\") == false) { p += "\\"; } using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { reg.SetValue("FoxSDCAgent", p + "FoxSDC_Agent_UI.exe", RegistryValueKind.String); reg.SetValue("FoxSDCAgentApply", p + "FoxSDC_ApplyUserSettings.exe", RegistryValueKind.String); reg.Close(); } } catch { } try { using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true)) { object o = reg.GetValue("SoftwareSASGeneration", null); int rvalue = 0; if (o != null) { rvalue = Convert.ToInt32(o); } if (rvalue != 1 && rvalue != 3) { reg.SetValue("SoftwareSASGeneration", 1); } reg.Close(); } } catch { } Threads.StartAllThreads(); }
public RESTStatus AppendUpload(SQLLib sql, FileUploadAppendData upload, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } if (upload == null) { ni.Error = "Invalid data"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } lock (ni.sqllock) { if (Computers.MachineExists(sql, upload.MachineID) == false) { ni.Error = "Invalid data"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } } if (upload.Data.Length != upload.Size) { ni.Error = "Invalid SZ"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(upload.MD5) == true) { ni.Error = "No MD5"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } if (upload.MD5.ToLower() != MD5Utilities.CalcMD5(upload.Data).ToLower()) { ni.Error = "MD5 Error"; ni.ErrorID = ErrorFlags.CheckSumError; return(RESTStatus.Fail); } lock (ni.sqllock) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM FileTransfers WHERE ID=@id AND MachineID=@mid AND [Size]!=[ProgressSize] AND Direction=3", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID))) == 0) { ni.Error = "Invalid ID"; ni.ErrorID = ErrorFlags.InvalidData; return(RESTStatus.Fail); } } Int64 TotalSZ; Int64 ProgressSize; lock (ni.sqllock) { TotalSZ = Convert.ToInt64(sql.ExecSQLScalar("SELECT [Size] FROM FileTransfers WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID))); } lock (ni.sqllock) { ProgressSize = Convert.ToInt64(sql.ExecSQLScalar("SELECT ProgressSize FROM FileTransfers WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID))); } if (ProgressSize + upload.Size > TotalSZ) { ni.Error = "Too many data"; ni.ErrorID = ErrorFlags.ChunkTooLarge; return(RESTStatus.Fail); } string Filename = null; lock (ni.sqllock) { Filename = Settings.Default.DataPath + Convert.ToString(sql.ExecSQLScalar("SELECT ServerFile FROM FileTransfers WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID))); } if (File.Exists(Filename) == false) { if (ProgressSize > 0) { ni.Error = "FS Error - Missing"; ni.ErrorID = ErrorFlags.FileSystemError; return(RESTStatus.Fail); } } using (FileStream str = File.Open(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { str.Seek(0, SeekOrigin.End); str.Write(upload.Data, 0, upload.Size); } FileInfo fi = new FileInfo(Filename); if (ProgressSize + upload.Size != fi.Length) { ni.Error = "FS Error - Final SZ Error"; ni.ErrorID = ErrorFlags.FileSystemError; return(RESTStatus.Fail); } lock (ni.sqllock) { sql.ExecSQL("UPDATE FileTransfers SET ProgressSize=@psz, DTUpdated=getutcdate() WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@psz", fi.Length), new SQLParam("@id", upload.ID)); } if (fi.Length == TotalSZ) { string MD5 = MD5Utilities.CalcMD5File(Filename); string MD5DB = ""; lock (ni.sqllock) { MD5DB = Convert.ToString(sql.ExecSQLScalar("SELECT MD5Sum FROM FileTransfers WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID))); } if (MD5.ToLower() != MD5DB.ToLower()) { ni.Error = "Final MD5 error"; ni.ErrorID = ErrorFlags.InvalidData; return(RESTStatus.Fail); } lock (ni.sqllock) { sql.ExecSQL("UPDATE FileTransfers SET Direction=0 WHERE ID=@id AND MachineID=@mid", new SQLParam("@mid", upload.MachineID), new SQLParam("@id", upload.ID)); } } return(RESTStatus.Success); }