static void PushThreadActionRunner(object o) { if (!(o is PushDataForThreadRunner)) { return; } PushDataForThreadRunner t = (PushDataForThreadRunner)o; try { switch (t.p.Action) { case "ping": t.net.ResponsePushData10("ok", t.p.Action, 10, t.p.ReplyID); break; case "chatmessage": try { PushChatMessage m = JsonConvert.DeserializeObject <PushChatMessage>(t.p.AdditionalData1); PushMessage(m); } catch { } t.net.ResponsePushData10(new NetBool() { Data = true }, t.p.Action, 10, t.p.ReplyID); break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push10: PushThreadActionRunner thread crashed", System.Diagnostics.EventLogEntryType.Information); } }
static bool CheckConnection() { if (LastCalled != null) { if ((DateTime.Now - LastCalled.Value).TotalMinutes > 9) //timeout { LastCalled = null; } } if (LastCalled == null) { LastCalled = DateTime.Now; CurrentConsoleSessionID = -1; CurrentConnectionGUID = ""; } else { LastCalled = DateTime.Now; } lock (CheckConnectionLocker) { FullReset: Int64 Con = ProgramAgent.CPP.GetConsoleSessionID(); if (CurrentConsoleSessionID != Con) { if (CurrentConnectionGUID != "") { FoxEventLog.VerboseWriteEventLog("Console Session ID changed from " + CurrentConsoleSessionID.ToString() + " to " + Con.ToString() + " - Closing Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); try { if (Pipe != null) { Pipe.Pipe1.CloseSession(); } Pipe = null; } catch { } CurrentConnectionGUID = ""; } } CurrentConsoleSessionID = Con; if (CurrentConnectionGUID == "") { CurrentConnectionGUID = Guid.NewGuid().ToString(); FoxEventLog.VerboseWriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); if (StartApp(CurrentConnectionGUID, out PipeProcessID) == false) { return(false); } Pipe = new MainScreenRedir(CurrentConnectionGUID); Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } int Counter = 0; bool Connected = false; do { if (ProcessExists(PipeProcessID) == false) { FoxEventLog.VerboseWriteEventLog("Screen Capture Process ID " + PipeProcessID.ToString() + " for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID + " gone", EventLogEntryType.Warning); Connected = false; if (ProgramAgent.CPP.GetConsoleSessionID() != CurrentConsoleSessionID) { goto FullReset; } break; } try { if (Pipe.Pipe1.Ping() == true) { Connected = true; break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } Thread.Sleep(100); Counter++; if (Counter > 10 * 30) { break; } Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } while (true); if (Connected == false) { //Restart the app CurrentConnectionGUID = Guid.NewGuid().ToString(); FoxEventLog.VerboseWriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " (2nd try!) Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); if (StartApp(CurrentConnectionGUID, out PipeProcessID) == false) { return(false); } Pipe = new MainScreenRedir(CurrentConnectionGUID); Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); Connected = false; do { if (ProcessExists(PipeProcessID) == false) { FoxEventLog.VerboseWriteEventLog("Screen Capture Process ID " + PipeProcessID.ToString() + " for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID + " gone", EventLogEntryType.Warning); Connected = false; if (ProgramAgent.CPP.GetConsoleSessionID() != CurrentConsoleSessionID) { goto FullReset; } break; } try { if (Pipe.Pipe1.Ping() == true) { Connected = true; break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } Thread.Sleep(100); Counter++; if (Counter > 10 * 30) { break; } Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } while (true); if (Connected == false) { FoxEventLog.WriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " failed!", EventLogEntryType.Error); CurrentConnectionGUID = ""; return(false); } } return(true); } }
static void PushThreadActionRunner(object o) { if (!(o is PushDataForThreadRunner)) { return; } PushDataForThreadRunner t = (PushDataForThreadRunner)o; try { switch (t.p.Action) { case "clock": t.net.ResponsePushData0(DateTime.UtcNow, t.p.Action, 0, t.p.ReplyID); break; case "ping": t.net.ResponsePushData0("ok", t.p.Action, 0, t.p.ReplyID); break; case "tasks": t.net.ResponsePushData0(TaskManager.GetTasks(), t.p.Action, 0, t.p.ReplyID); break; case "killtask": t.net.ResponsePushData0(TaskManager.KillTask(t.p.AdditionalData1), t.p.Action, 0, t.p.ReplyID); break; case "listfiles": t.net.ResponsePushData0(Filesystem.ListFiles(t.p.AdditionalData1), t.p.Action, 0, t.p.ReplyID); break; case "checkfile": t.net.ResponsePushData0(Filesystem.CheckFile(t.p.AdditionalData1), t.p.Action, 0, t.p.ReplyID); break; case "getsessions": t.net.ResponsePushData0(TaskManager.GetTSRunningSessions(), t.p.Action, 0, t.p.ReplyID); break; case "runtask": t.net.ResponsePushData0(TaskManager.RunTask(t.p.AdditionalData1, t.net), t.p.Action, 0, t.p.ReplyID); break; case "wugetlist": t.net.ResponsePushData0(WindowsUpdateClient.GetUpdateList(), t.p.Action, 0, t.p.ReplyID); break; case "wucheck": t.net.ResponsePushData0(WindowsUpdateClient.CheckForUpdates(), t.p.Action, 0, t.p.ReplyID); break; case "wustatus": t.net.ResponsePushData0(WindowsUpdateClient.GetStatus(), t.p.Action, 0, t.p.ReplyID); break; case "wuinstall": t.net.ResponsePushData0(WindowsUpdateClient.InstallUpdates(), t.p.Action, 0, t.p.ReplyID); break; case "wustatusrestart": t.net.ResponsePushData0(WindowsUpdateClient.QueryRestartPending(), t.p.Action, 0, t.p.ReplyID); break; case "restartsystem": ProgramAgent.CPP.RestartSystem(); t.net.ResponsePushData0(new NetInt32() { Data = 0 }, t.p.Action, 0, t.p.ReplyID); break; case "restartsystemforced": ProgramAgent.CPP.RestartSystemForced(); t.net.ResponsePushData0(new NetInt32() { Data = 0 }, t.p.Action, 0, t.p.ReplyID); break; case "services": t.net.ResponsePushData0(Services.GetServices(), t.p.Action, 0, t.p.ReplyID); break; case "servicecontrol": t.net.ResponsePushData0(Services.ServiceControl(t.p.AdditionalData1), t.p.Action, 0, t.p.ReplyID); break; case "efigetdevices": t.net.ResponsePushData0(EFIBios.GetEFIBootDevices(), t.p.Action, 0, t.p.ReplyID); break; case "efisetnextdevice": t.net.ResponsePushData0(EFIBios.SetNextEFIBootDevice(t.p.AdditionalData1), t.p.Action, 0, t.p.ReplyID); break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push0: PushThreadActionRunner thread crashed", System.Diagnostics.EventLogEntryType.Information); } }
static public void StartPushThread() { FoxEventLog.VerboseWriteEventLog("Push0: Starting Push Thread", System.Diagnostics.EventLogEntryType.Information); pm = new Thread(new ThreadStart(PushThread)); pm.Start(); }
static void PushThread() { Network net = null; PushDataRoot pd; int Crashes = 0; do { try { if (net == null) { net = Utilities.ConnectNetwork(-1); } if (net == null) { FoxEventLog.VerboseWriteEventLog("Push0: no connection", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitNoConnection; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } pd = net.GetPushData0(); if (pd == null) { FoxEventLog.VerboseWriteEventLog("Push0: pd==null", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitPDisNULL; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } pd = net.GetPushData0(); if (pd == null) { net = null; FoxEventLog.VerboseWriteEventLog("Push0: pd==null - 2nd time - resetting connection", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitPDisNULL2; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } } if (ApplicationCertificate.Verify(pd) == false) { FoxEventLog.WriteEventLog("Push0: One or more PushData were tampered - no PushData will be processed.", System.Diagnostics.EventLogEntryType.Error); for (int i = 0; i < WaitTamperIssue; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } Crashes = 0; if (pd.Data.Action == "repeat") { if (StopThread == true) { return; } FoxEventLog.VerboseWriteEventLog("Push0: repeat", System.Diagnostics.EventLogEntryType.Information); continue; } if (pd.Data.Action == "quit") { FoxEventLog.VerboseWriteEventLog("Push0: quit", System.Diagnostics.EventLogEntryType.Information); net = null; for (int i = 0; i < WaitQuit; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } if (pd.Data.Action == "stdin") { Redirs.MainSTDIORedir.ProcessStdInAgent(pd.Data.AdditionalData1); continue; } Thread a = new Thread(new ParameterizedThreadStart(PushThreadActionRunner)); PushDataForThreadRunner t = new PushDataForThreadRunner(); t.net = net.CloneElement(); t.p = pd.Data; a.Start(t); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push0: SEH internally", System.Diagnostics.EventLogEntryType.Information); Crashes++; if (Crashes > 3) { FoxEventLog.VerboseWriteEventLog("Push0: Resetting connection due too many crashes", System.Diagnostics.EventLogEntryType.Information); net = null; Crashes = 0; } for (int i = 0; i < WaitCrash; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } } } while (StopThread == false); }
public RESTStatus SendMessage(SQLLib sql, WriteMessage message, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } if (message == null) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Name) == true) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Subject) == true) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Text) == true) { return(RESTStatus.Fail); } ComputerData pc; lock (ni.sqllock) { pc = Computers.GetComputerDetail(sql, ni.Username); } string ErrorMessage; string Message; string Subject; Subject = "Support Request: " + message.Subject + " (" + pc.Computername + ")"; Message = "Support Request\n"; Message += "Computer: " + pc.Computername + " (" + pc.GroupingPath + ")\n"; Message += "Computer ID: " + pc.MachineID + "\n"; Message += "Date: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n"; Message += "Name: " + message.Name + "\n"; Message += "Subject: " + message.Subject + "\n"; Message += "IP Address: " + pc.IPAddress + "\n"; Message += "Version: " + pc.AgentVersion + " / " + pc.AgentVersionID.ToString() + "\n"; if (Settings.Default.UseContract == true) { Message += "Contract ID: " + pc.ContractID + "\n"; } Message += "\n"; Message += message.Text; System.Net.Mail.MailPriority prio = System.Net.Mail.MailPriority.Normal; switch (message.Priority) { case 0: prio = System.Net.Mail.MailPriority.Low; break; case 2: prio = System.Net.Mail.MailPriority.High; break; } if (MailSender.SendEMailAdmin(Subject, Message, prio, out ErrorMessage) == false) { FoxEventLog.WriteEventLog("Cannot send Support Request E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); return(RESTStatus.Fail); } return(RESTStatus.NoContent); }
void ApplyUserPolicy(InternationalPolicy p) { try { using (RegistryKey intluser = Registry.CurrentUser.OpenSubKey("Control Panel\\International", true)) { if (intluser == null) { FoxEventLog.WriteEventLog("Cannot open HKCU\\Control Panel\\International - Registry broken?", System.Diagnostics.EventLogEntryType.Error); return; } if (p.EnableMainLocation == true) { using (RegistryKey k = intluser.CreateSubKey("Geo")) { k.SetValue("Nation", p.MainLocation, RegistryValueKind.String); } } if (p.EnableDate2DigitYear == true) { using (RegistryKey k = intluser.CreateSubKey("Calendars\\TwoDigitYearMax")) { k.SetValue("1", p.Date2DigitYear, RegistryValueKind.String); k.SetValue("10", p.Date2DigitYear, RegistryValueKind.String); k.SetValue("11", p.Date2DigitYear, RegistryValueKind.String); k.SetValue("12", p.Date2DigitYear, RegistryValueKind.String); k.SetValue("2", p.Date2DigitYear, RegistryValueKind.String); k.SetValue("9", p.Date2DigitYear, RegistryValueKind.String); } } if (p.EnableMainFormat == true) { try { CultureInfo c = new CultureInfo(p.MainFormat); RegionInfo regi = new RegionInfo(p.MainFormat); intluser.SetValue("sLanguage", c.ThreeLetterWindowsLanguageName, RegistryValueKind.String); intluser.SetValue("sCountry", regi.NativeName, RegistryValueKind.String); intluser.SetValue("LocaleName", c.IetfLanguageTag, RegistryValueKind.String); intluser.SetValue("Locale", p.MainFormat.ToString("X8")); Console.WriteLine(c.ThreeLetterWindowsLanguageName); //ENG Console.WriteLine(c.IetfLanguageTag); //en-GB Console.WriteLine(regi.NativeName); //United Kingdom } catch { FoxEventLog.WriteEventLog("Cannot apply main region settings for ID " + p.MainFormat, System.Diagnostics.EventLogEntryType.Warning); } } if (p.EnableCurrCurrencySymbol == true) { intluser.SetValue("sCurrency", p.CurrCurrencySymbol, RegistryValueKind.String); } if (p.EnableCurrDecimalSymbol == true) { intluser.SetValue("sMonDecimalSep", p.CurrDecimalSymbol, RegistryValueKind.String); } if (p.EnableCurrDigitGrouping == true) { switch (p.CurrDigitGrouping) { case 0: intluser.SetValue("sMonGrouping", "0", RegistryValueKind.String); break; case 1: intluser.SetValue("sMonGrouping", "3;0", RegistryValueKind.String); break; case 2: intluser.SetValue("sMonGrouping", "3;0;0", RegistryValueKind.String); break; case 3: intluser.SetValue("sMonGrouping", "3;2;0", RegistryValueKind.String); break; default: FoxEventLog.WriteEventLog("Invalid policy value in Intl Policy \"CurrDigitGrouping\"", System.Diagnostics.EventLogEntryType.Warning); break; } } if (p.EnableCurrDigitGroupingSymbol == true) { intluser.SetValue("sMonThousandSep", p.CurrDigitGroupingSymbol, RegistryValueKind.String); } if (p.EnableCurrNegativeFormat == true) { intluser.SetValue("iNegCurr", p.CurrNegativeFormat, RegistryValueKind.String); } if (p.EnableCurrNumDigitsAfterDec == true) { intluser.SetValue("iCurrDigits", p.CurrNumDigitsAfterDec, RegistryValueKind.String); } if (p.EnableCurrPositiveFormat == true) { intluser.SetValue("iCurrency", p.CurrPositiveFormat, RegistryValueKind.String); } if (p.EnableDate1stDayOfWeek == true) { intluser.SetValue("iFirstDayOfWeek", p.Date1stDayOfWeek, RegistryValueKind.String); } if (p.EnableDateFirstWeekOfYear == true) { intluser.SetValue("iFirstWeekOfYear", p.DateFirstWeekOfYear, RegistryValueKind.String); } if (p.EnableDateFormat == true) { intluser.SetValue("iDate", p.DateFormat, RegistryValueKind.String); } if (p.EnableDateLongDate == true) { intluser.SetValue("sLongDate", p.DateLongDate, RegistryValueKind.String); } if (p.EnableDateSeparator == true) { intluser.SetValue("sDate", p.DateSeparator, RegistryValueKind.String); } if (p.EnableDateShortDate == true) { intluser.SetValue("sShortDate", p.DateShortDate, RegistryValueKind.String); } if (p.EnableNumDecimalSymbol == true) { intluser.SetValue("sDecimal", p.NumDecimalSymbol, RegistryValueKind.String); } if (p.EnableNumDigitGrouping == true) { switch (p.NumDigitGrouping) { case 0: intluser.SetValue("sGrouping", "0", RegistryValueKind.String); break; case 1: intluser.SetValue("sGrouping", "3;0", RegistryValueKind.String); break; case 2: intluser.SetValue("sGrouping", "3;0;0", RegistryValueKind.String); break; case 3: intluser.SetValue("sGrouping", "3;2;0", RegistryValueKind.String); break; default: FoxEventLog.WriteEventLog("Invalid policy value in Intl Policy \"NumDigitGrouping\"", System.Diagnostics.EventLogEntryType.Warning); break; } } if (p.EnableNumDigitGroupingSymbol == true) { intluser.SetValue("sThousand", p.NumDigitGroupingSymbol, RegistryValueKind.String); } if (p.EnableNumDisplayLeading0 == true) { intluser.SetValue("iLZero", p.NumDisplayLeading0, RegistryValueKind.String); } if (p.EnableNumListSeparator == true) { intluser.SetValue("sList", p.NumListSeparator, RegistryValueKind.String); } if (p.EnableNumMeasurement == true) { intluser.SetValue("iMeasure", p.NumMeasurement, RegistryValueKind.String); } if (p.EnableNumNegativeNumberFormat == true) { intluser.SetValue("iNegNumber", p.NumNegativeNumberFormat, RegistryValueKind.String); } if (p.EnableNumNegativeSignSymbol == true) { intluser.SetValue("sNegativeSign", p.NumNegativeSignSymbol, RegistryValueKind.String); } if (p.EnableNumNumOfDigitsAfterDec == true) { intluser.SetValue("iDigits", p.NumNumOfDigitsAfterDec, RegistryValueKind.String); } if (p.EnableNumPositiveSignSymbol == true) { intluser.SetValue("sPositiveSign", p.NumPositiveSignSymbol, RegistryValueKind.String); } if (p.EnableNumStdDigits == true) { switch (p.NumStdDigits) { case 0: intluser.SetValue("sNativeDigits", "0123456789", RegistryValueKind.String); break; default: FoxEventLog.WriteEventLog("Invalid policy value in Intl Policy \"NumStdDigits\"", System.Diagnostics.EventLogEntryType.Warning); break; } } if (p.EnableNumUseNativeDigits == true) { intluser.SetValue("NumShape", p.NumUseNativeDigits, RegistryValueKind.String); } if (p.EnablePaperSize == true) { intluser.SetValue("iPaperSize", p.PaperSize, RegistryValueKind.String); } if (p.EnableTelephoneIDN == true) { intluser.SetValue("iCountry", p.TelephoneIDN, RegistryValueKind.String); } if (p.EnableTime24Hour == true) { intluser.SetValue("iTime", p.Time24Hour, RegistryValueKind.String); } if (p.EnableTimeAM == true) { intluser.SetValue("s1159", p.TimeAM, RegistryValueKind.String); } if (p.EnableTimePM == true) { intluser.SetValue("s2359", p.TimePM, RegistryValueKind.String); } if (p.EnableTimeLongTime == true) { intluser.SetValue("sTimeFormat", p.TimeLongTime, RegistryValueKind.String); } if (p.EnableTimeShortPrefix0Hour == true) { intluser.SetValue("iTLZero", p.TimeShortTimePrefix0Hour, RegistryValueKind.String); } if (p.EnableTimeShortTime == true) { intluser.SetValue("sShortTime", p.TimeShortTime, RegistryValueKind.String); } if (p.EnableTimeSeparator == true) { intluser.SetValue("sTime", p.TimeSeparator, RegistryValueKind.String); } } } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot apply User Intl Settings for ID " + p.ID + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
public bool FinaliseApplyPolicy() { foreach (PolicyPackageCertificates ap in ToRemove) { lock (ActivePackageCertsLock) { byte[] d = Convert.FromBase64String(ap.UUCerFile); for (int i = 0; i < ActivePackageCerts.Count; i++) { byte[] b = ActivePackageCerts[i]; if (b.SequenceEqual(d) == true) { ActivePackageCerts.RemoveAt(i); break; } } } } foreach (PolicyPackageCertificates ap in ToAdd) { lock (ActivePackageCertsLock) { byte[] d = Convert.FromBase64String(ap.UUCerFile); bool HasData = false; for (int i = 0; i < ActivePackageCerts.Count; i++) { byte[] b = ActivePackageCerts[i]; if (b.SequenceEqual(d) == true) { HasData = true; break; } } if (HasData == false) { ActivePackageCerts.Add(d); } } } ToAdd = null; ToRemove = null; if (RegistryData.Verbose == 1) { string blahblah = "ActivePackageCerts:\n\n"; lock (ActivePackageCertsLock) { foreach (byte[] data in ActivePackageCerts) { blahblah += "0x"; foreach (byte b in data) { blahblah += b.ToString("X2"); } blahblah += "\n"; } } FoxEventLog.VerboseWriteEventLog(blahblah, System.Diagnostics.EventLogEntryType.Information); } return(true); }
static int Main() { List <int> UIRunningInSession = new List <int>(); const string PackageID = "Vulpes-SDCA1-Update"; string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (dir.EndsWith("\\") == false) { dir += "\\"; } string pkgfile = dir + "agentupdate.foxpkg"; if (File.Exists(pkgfile) == false) { return(1); } PackageInstaller pkgi = new PackageInstaller(); string Error; if (pkgi.PackageInfo(pkgfile, null, out Error) == false) { FoxEventLog.WriteEventLog("Self-Update: Error reading package file " + pkgfile + ": " + Error, EventLogEntryType.Error); return(2); } if (pkgi.PackageInfoData.PackageID != PackageID) { FoxEventLog.WriteEventLog("Self-Update: PackageID mismatch on file " + pkgfile, EventLogEntryType.Error); return(3); } FileVersionInfo fv = FileVersionInfo.GetVersionInfo(dir + "FoxSDC_Agent.exe"); Int64 sdcversion = Convert.ToInt64(fv.FileBuildPart.ToString("0000") + fv.FilePrivatePart.ToString("0000")); if (pkgi.PackageInfoData.VersionID <= sdcversion) { FoxEventLog.WriteEventLog("Self-Update: Version on package is same or older than installed for file " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + fv.ToString(), EventLogEntryType.Error); return(4); } ServiceController svc = new ServiceController("FoxSDCA"); try { svc.Stop(); } catch { } int i = 0; do { i++; if (i > 120 * 4) { break; } svc.Refresh(); Thread.Sleep(1000); } while (svc.Status != ServiceControllerStatus.Stopped); #region Kill Processes foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe") { if (UIRunningInSession.Contains(proc.SessionId) == false) { UIRunningInSession.Add(proc.SessionId); } proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe") { proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe") { proc.Kill(); } } catch { } } #endregion FoxEventLog.WriteEventLog("Self-Update: Updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information); PKGStatus status; PKGRecieptData reciept; if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Test, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false) { FoxEventLog.WriteEventLog("Self-Update: Error testing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error); svc = new ServiceController("FoxSDCA"); svc.Start(); return(5); } if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Install, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false) { FoxEventLog.WriteEventLog("Self-Update: Error installing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error); svc = new ServiceController("FoxSDCA"); svc.Start(); return(6); } FoxEventLog.WriteEventLog("Self-Update: Completed updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information); svc = new ServiceController("FoxSDCA"); svc.Start(); try { File.Delete(pkgfile); } catch { CommonUtilities.PendingMove(pkgfile, null); } SessionStarter.StartProgramInSessions(dir.ToLower() + "foxsdc_agent_ui.exe", UIRunningInSession); return(0); }
void ApplyPolicy(WSUSPolicy p) { if (p.ConfigureWSUS == null) { return; } if (p.StatusServer == null) { p.SpecifyStatusServer = null; } if (p.WUServer == null) { p.SpecifyWUServer = null; } if (string.IsNullOrWhiteSpace(p.Target) == true) { p.SpecifyClientSideTargeting = false; } if (p.ConfigureWSUS == true) { using (RegistryKey regDOD = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Policies\\Microsoft\\Windows\\DeliveryOptimization")) { if (regDOD == null || regDOD == null) { FoxEventLog.WriteEventLog("Cannot write Delivery Optimization Registry Settings", System.Diagnostics.EventLogEntryType.Error); return; } if (p.EnableDownloadMode == true) { regDOD.SetValue("DODownloadMode", p.DownloadMode, RegistryValueKind.DWord); } else { regDOD.DeleteValue("DODownloadMode", false); } } using (RegistryKey regWU = Registry.LocalMachine.CreateSubKey("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate")) { using (RegistryKey regAU = Registry.LocalMachine.CreateSubKey("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU")) { if (regWU == null || regAU == null) { FoxEventLog.WriteEventLog("Cannot write Windows Update Registry Settings", System.Diagnostics.EventLogEntryType.Error); return; } if (p.SpecifyWUOptions == true) { regAU.SetValue("AUOptions", p.WUOptions, RegistryValueKind.DWord); } else { regAU.DeleteValue("AUOptions", false); } if (p.InstallDuringMaintenance != null) { regAU.SetValue("AutomaticMaintenanceEnabled", p.InstallDuringMaintenance == true ? 1 : 0, RegistryValueKind.DWord); } if (p.SpecifyScheduleInstall == true) { regAU.SetValue("ScheduledInstallDay", p.ScheduleInstallDay, RegistryValueKind.DWord); regAU.SetValue("ScheduledInstallTime", p.ScheduleInstallHour, RegistryValueKind.DWord); } if (p.SpecifyScheduleInstall == false) { regAU.DeleteValue("ScheduledInstallDay", false); regAU.DeleteValue("ScheduledInstallTime", false); } if (p.InstallMicrosoftUpdates != null) { regAU.SetValue("AllowMUUpdateService", p.InstallMicrosoftUpdates == true ? 1 : 0, RegistryValueKind.DWord); } if (p.SpecifyWUServer != null) { regAU.SetValue("UseWUServer", p.SpecifyWUServer == true ? 1 : 0, RegistryValueKind.DWord); if (p.SpecifyWUServer == true) { regWU.SetValue("WUServer", p.WUServer.Trim(), RegistryValueKind.String); if (p.SpecifyStatusServer == true) { regWU.SetValue("WUStatusServer", p.StatusServer.Trim(), RegistryValueKind.String); } } else { regWU.DeleteValue("WUServer", false); regWU.DeleteValue("WUStatusServer", false); } } if (p.SpecifyClientSideTargeting != null) { regWU.SetValue("TargetGroupEnabled", p.SpecifyClientSideTargeting == true ? 1 : 0, RegistryValueKind.DWord); } if (p.SpecifyClientSideTargeting == true) { regWU.SetValue("TargetGroup", p.Target.Trim(), RegistryValueKind.String); } if (p.SpecifyClientSideTargeting == false) { regWU.DeleteValue("TargetGroup", false); } if (p.NoMSServer != null) { regWU.SetValue("DoNotConnectToWindowsUpdateInternetLocations", p.NoMSServer == true ? 1 : 0, RegistryValueKind.DWord); } if (p.SpecifyDetectionFreq != null) { regAU.SetValue("DetectionFrequencyEnabled", p.SpecifyDetectionFreq == true ? 1 : 0, RegistryValueKind.DWord); if (p.SpecifyDetectionFreq == true) { regAU.SetValue("DetectionFrequency", p.DetectionFreq, RegistryValueKind.DWord); } if (p.SpecifyDetectionFreq == false) { regAU.DeleteValue("DetectionFrequency", false); } } if (p.DontAutoRestart != null) { regAU.SetValue("NoAutoRebootWithLoggedOnUsers", p.DontAutoRestart == true ? 1 : 0, RegistryValueKind.DWord); } if (p.SpecifyAlwaysAutoRestart != null) { regAU.SetValue("AlwaysAutoRebootAtScheduledTime", p.SpecifyAlwaysAutoRestart == true ? 1 : 0, RegistryValueKind.DWord); if (p.SpecifyAlwaysAutoRestart == true) { regAU.SetValue("AlwaysAutoRebootAtScheduledTime_Minutes", p.AlwaysAutoRestartDelay, RegistryValueKind.DWord); } else { regAU.DeleteValue("AlwaysAutoRebootAtScheduledTime_Minutes", false); } } if (p.SpecifyDeadline != null) { regWU.SetValue("SetAutoRestartDeadline", p.SpecifyDeadline == true ? 1 : 0, RegistryValueKind.DWord); if (p.SpecifyDeadline == true) { regWU.SetValue("AutoRestartDeadlinePeriodInDays", p.DeadLine, RegistryValueKind.DWord); } else { regWU.DeleteValue("AutoRestartDeadlinePeriodInDays", false); } } if (p.DontAutoRestartDuringActiveHours != null) { regWU.SetValue("SetActiveHours", p.DontAutoRestartDuringActiveHours == true ? 1 : 0, RegistryValueKind.DWord); if (p.DontAutoRestartDuringActiveHours == true) { regWU.SetValue("ActiveHoursStart", p.ActiveHoursFrom, RegistryValueKind.DWord); regWU.SetValue("ActiveHoursEnd", p.ActiveHoursTo, RegistryValueKind.DWord); } else { regWU.DeleteValue("ActiveHoursStart", false); regWU.DeleteValue("ActiveHoursEnd", false); } } if (p.DisableDualScan != null) { regWU.SetValue("DisableDualScan", p.DisableDualScan == true ? 1 : 0, RegistryValueKind.DWord); } else { regWU.DeleteValue("DisableDualScan", false); } } } } if (p.ConfigureWSUS == false) { Registry.LocalMachine.DeleteSubKeyTree("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate", false); Registry.LocalMachine.DeleteSubKeyTree("Software\\Policies\\Microsoft\\Windows\\DeliveryOptimization", false); } }
static void PushThread() { Network net = null; PushDataRoot pd; int Crashes = 0; DateTime? ChatPickup = null; do { try { if (net == null) { net = Utilities.ConnectNetwork(-1); } if (net == null) { FoxEventLog.VerboseWriteEventLog("Push10: no connection", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitNoConnection; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } ConfirmPopMessage(net); if (ChatPickup == null) { ChatPickup = DateTime.UtcNow.AddDays(-1); } if ((DateTime.UtcNow - ChatPickup.Value).TotalMinutes > ChatPickupPeriodMin) { PickupMessages(net); ChatPickup = DateTime.UtcNow; } pd = net.GetPushData10(); if (pd == null) { FoxEventLog.VerboseWriteEventLog("Push10: pd==null", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitPDisNULL; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } pd = net.GetPushData10(); if (pd == null) { net = null; FoxEventLog.VerboseWriteEventLog("Push10: pd==null - 2nd time - resetting connection", System.Diagnostics.EventLogEntryType.Information); for (int i = 0; i < WaitPDisNULL2; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } } if (ApplicationCertificate.Verify(pd) == false) { FoxEventLog.WriteEventLog("Push10: One or more PushData were tampered - no PushData will be processed.", System.Diagnostics.EventLogEntryType.Error); for (int i = 0; i < WaitTamperIssue; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } Crashes = 0; if (pd.Data.Action == "repeat") { if (StopThread == true) { return; } FoxEventLog.VerboseWriteEventLog("Push10: repeat", System.Diagnostics.EventLogEntryType.Information); continue; } if (pd.Data.Action == "quit") { FoxEventLog.VerboseWriteEventLog("Push10: quit", System.Diagnostics.EventLogEntryType.Information); net = null; for (int i = 0; i < WaitQuit; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } continue; } Thread a = new Thread(new ParameterizedThreadStart(PushThreadActionRunner)); PushDataForThreadRunner t = new PushDataForThreadRunner(); t.net = net.CloneElement2(); t.p = pd.Data; a.Start(t); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push10: SEH internally", System.Diagnostics.EventLogEntryType.Information); Crashes++; if (Crashes > 3) { FoxEventLog.VerboseWriteEventLog("Push10: Resetting connection due too many crashes", System.Diagnostics.EventLogEntryType.Information); net = null; Crashes = 0; } for (int i = 0; i < WaitCrash; i++) { Thread.Sleep(1000); if (StopThread == true) { return; } } } } while (StopThread == false); }
static int Main() { FoxEventLog.Shutup = true; string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (dir.EndsWith("\\") == false) { dir += "\\"; } ProgramAgent.Init(); if (ProgramAgent.LoadDLL() == false) { return(1); } if (SystemInfos.CollectSystemInfo() != 0) { return(1); } if (ApplicationCertificate.LoadCertificate() == false) { FoxEventLog.WriteEventLog("Cannot load certificate", System.Diagnostics.EventLogEntryType.Error); return(1); } if (FilesystemData.LoadCertificates() == false) { return(1); } if (FilesystemData.LoadPolicies() == false) { return(1); } FilesystemData.LoadLocalPackageData(); FilesystemData.LoadLocalPackages(); FilesystemData.LoadUserPackageData(); FilesystemData.LoadEventLogList(); FoxEventLog.Shutup = false; if (SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.Uninstall) == false) { return(5); } ServiceController svc = new ServiceController("FoxSDCA"); try { svc.Stop(); } catch { } int i = 0; do { i++; if (i > 120 * 4) { break; } svc.Refresh(); Thread.Sleep(1000); } while (svc.Status != ServiceControllerStatus.Stopped); #region Kill Processes foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe") { proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe") { proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe") { proc.Kill(); } } catch { } } #endregion try { RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); reg.DeleteValue("FoxSDCAgent", false); reg.DeleteValue("FoxSDCAgentApply", false); reg.Close(); } catch { } try { Process.Start(Environment.ExpandEnvironmentVariables("%systemroot%\\system32\\msiexec.exe"), "/x {A6F066EE-E795-4C65-8FE4-2D93AB52BC36} /passive"); } catch { } return(0); }
void ListenerThreadFn() { Sock.Listen((int)SocketOptionName.MaxConnections); int Counter; Thread ct = new Thread(new ThreadStart(ServerConnectThread)); ct.Start(); try { do { bool ConnectedRes = false; if (NewBeginAccept == true) { connectedevent.Reset(); Sock.BeginAccept(new AsyncCallback(AcceptAsync), Sock); NewBeginAccept = false; } Counter = 0; #if DEBUG while (Counter < 30) #else while (Counter < 60) #endif { ConnectedRes = connectedevent.WaitOne(1000); if (ConnectedRes == false) { Counter++; } else { break; } if (StopThread == true) { break; } } if (StopThread == true) { break; } if (ConnectedRes == true) { if (net == null) { //reject connection NextConnected.Close(); continue; } else { Thread t = new Thread(new ParameterizedThreadStart(RunningConnectionAccepterAndGetter)); NetworkConnectionThreadPasser p = new NetworkConnectionThreadPasser(); p.RunningConnectionAccepterAndGetterThread = t; p.GUID = ""; p.net = net.CloneElement(); p.sock = NextConnected; t.Start(p); } } } while (StopThread == false); } catch (Exception ee) { FoxEventLog.VerboseWriteEventLog("SEH in PortMappings_ConnectionNode::ListenerThreadFn() " + ee.ToString(), EventLogEntryType.Error); } try { Sock.Close(); } catch { } StopThread = true; }
public static void FinaliseApplyPolicy(List <PortMappingPolicy> Add, List <PortMappingPolicy> Remove) { Add = DeDup(Add); Remove = DeDup(Remove); foreach (PortMappingPolicy rm in Remove) { bool DontRemove = false; //check if this policy is in "add" (to prevent connection breaking) foreach (PortMappingPolicy ad in Add) { if (rm.BindTo0000 == ad.BindTo0000 && rm.ClientPort == ad.ClientPort && rm.EditHOSTS == ad.EditHOSTS && rm.HOSTSEntry == ad.HOSTSEntry && rm.ID == ad.ID && rm.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected) { DontRemove = true; break; } } if (DontRemove == true) { continue; } PortMappings_ConnectionNode RMC = null; foreach (PortMappings_ConnectionNode C in Connections) { if (C.RunningPort == rm.ClientPort && C.PolicyID == rm.ID) { RMC = C; break; } } if (RMC != null) { Connections.Remove(RMC); RMC.StopConnection(); } } for (int i = 0; i < Add.Count; i++) { bool BadPort = false; PortMappingPolicy ad = Add[i]; for (int j = 0; j < Add.Count; j++) { if (i == j) { continue; } if (ad.ClientPort == Add[j].ClientPort) { FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " conflicts with Policy ID " + ad.ID + " and " + Add[j].ID, EventLogEntryType.Error); BadPort = true; break; } } if (BadPort == true) { continue; } foreach (PortMappings_ConnectionNode cc in Connections) { if (ad.ID == cc.PolicyID) { if (cc.PolicyData.BindTo0000 == ad.BindTo0000 && cc.PolicyData.ClientPort == ad.ClientPort && cc.PolicyData.EditHOSTS == ad.EditHOSTS && cc.PolicyData.HOSTSEntry == ad.HOSTSEntry && cc.PolicyData.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected) { //no changes - continue BadPort = true; break; } else { //remove connection Connections.Remove(cc); cc.StopConnection(); break; } } } if (BadPort == true) { continue; } if (NetworkUtilities.PortAvailable(ad.ClientPort) == false) { FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " from Policy ID " + ad.ID + " is unavailable.", EventLogEntryType.Error); continue; } if (ad.NoBindIfSDCServerIsDetected == true) { bool FoundSDCS = false; using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\FoxSDCS")) { if (reg != null) { FoundSDCS = true; } } if (FoundSDCS == true) { continue; } } if (ad.EditHOSTS == true) { if (string.IsNullOrWhiteSpace(ad.HOSTSEntry) == false) { foreach (string HOSTS in ad.HOSTSEntry.Split('|')) { if (string.IsNullOrWhiteSpace(HOSTS) == true) { continue; } HostsEdit.AppendIntoHOSTSFile(HOSTS.Trim(), "127.0.0.1"); } } } PortMappings_ConnectionNode C = new PortMappings_ConnectionNode(ad); C.StartConnection(); Connections.Add(C); } }
static int Main(string[] args) { foreach (string arg in args) { if (arg.ToLower() == "-nopackages") { NoPackages = true; } } FoxEventLog.Shutup = true; ProgramAgent.Init(); if (ProgramAgent.LoadDLL() == false) { return(1); } FoxEventLog.Shutup = false; #if !DEBUG List <string> Additionals = new List <string>(); Additionals.Add(Assembly.GetExecutingAssembly().Location); if (ProgramAgent.TestIntegrity(Additionals) == false) { FoxEventLog.WriteEventLog("Apply User settings: Integrity failed!", EventLogEntryType.Error, true); return(1); } #endif FoxEventLog.Shutup = true; if (SystemInfos.CollectSystemInfo() != 0) { return(1); } if (ApplicationCertificate.LoadCertificate() == false) { FoxEventLog.Shutup = false; FoxEventLog.WriteEventLog("Apply User settings: Cannot load certificate", System.Diagnostics.EventLogEntryType.Error); return(1); } FoxEventLog.Shutup = false; if (FilesystemData.LoadCertificates(true) == false) { return(1); } if (FilesystemData.LoadPolicies() == false) { return(1); } FilesystemData.LoadLocalPackageData(); FilesystemData.LoadLocalPackages(); FilesystemData.LoadUserPackageData(); FilesystemData.LoadEventLogList(); SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplyUser); if (NoPackages == true) { return(0); } string PackagesFolder = SystemInfos.ProgramData + "Packages\\"; if (Directory.Exists(PackagesFolder) == false) { return(2); } foreach (PackagesToInstall pkg in FilesystemData.LocalPackages) { LocalPackageData lpkg = FilesystemData.FindLocalPackageFromListLatest(pkg.PackageID); if (lpkg == null) { continue; } if (pkg.Version != lpkg.Version) { continue; } PackageInstaller inst = new PackageInstaller(); string metafile = PackagesFolder + pkg.MetaFilename; if (File.Exists(metafile) == false) { continue; } string Error; PKGRecieptData Reciept; PKGStatus res; if (inst.InstallPackage(metafile, PackageCertificate.ActivePackageCerts, PackageInstaller.InstallMode.ApplyUserSettingsTest, true, out Error, out res, out Reciept) == false) { FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be tested: " + Error, System.Diagnostics.EventLogEntryType.Error); continue; } FoxEventLog.VerboseWriteEventLog("Apply User settings: Applying user settings for " + pkg.MetaFilename, EventLogEntryType.Information); if (inst.ApplyUserSettings(metafile, PackageCertificate.ActivePackageCerts, out Error, out res) == false) { FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be used to apply user settings: " + Error, System.Diagnostics.EventLogEntryType.Error); continue; } } if (RegistryData.Verbose == 1) { FoxEventLog.VerboseWriteEventLog("Apply User settings: ApplyUserSettings success for " + Environment.UserDomainName + "\\" + Environment.UserName, EventLogEntryType.Information); } return(0); }