static void PushThreadActionRunner(object o) { if (!(o is PushDataForThreadRunner)) { return; } PushDataForThreadRunner t = (PushDataForThreadRunner)o; try { switch (t.p.Action) { case "ping": t.net.ResponsePushData2("ok", t.p.Action, 2, t.p.ReplyID); break; //case "getfullscreen": // t.net.ResponsePushData2(Redirs.MainScreenSystem.GetFullscreen(), t.p.Action, 2, t.p.ReplyID); // break; //case "getdeltascreen": // t.net.ResponsePushData2(Redirs.MainScreenSystem.GetDeltaScreen(), t.p.Action, 2, t.p.ReplyID); // break; case "startwsscreen": t.net.ResponsePushData2(Redirs.MainScreenDataWS.StartRemoteScreen(t.net, t.p.AdditionalData1), t.p.Action, 1, t.p.ReplyID); break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push2: PushThreadActionRunner thread crashed", System.Diagnostics.EventLogEntryType.Information); } }
public bool FinaliseUninstallProgramm() { #if DEBUG FoxEventLog.VerboseWriteEventLog("TestPolicy.FinaliseApplyPolicyUserPart() called", System.Diagnostics.EventLogEntryType.Information); #endif return(true); }
public bool PreApplyPolicy() { #if DEBUG FoxEventLog.VerboseWriteEventLog("TestPolicy.PreApplyPolicy() called", System.Diagnostics.EventLogEntryType.Information); #endif return(true); }
static void PushThreadActionRunner(object o) { if (!(o is PushDataForThreadRunner)) { return; } PushDataForThreadRunner t = (PushDataForThreadRunner)o; try { switch (t.p.Action) { case "ping": t.net.ResponsePushData1("ok", t.p.Action, 1, t.p.ReplyID); break; case "netcreatedata2": t.net.ResponsePushData1(NetRedirPWS.StartNet(t.p.AdditionalData1, t.net), t.p.Action, 1, t.p.ReplyID); break; case "netclosedata2": t.net.ResponsePushData1(NetRedirPWS.CloseConnection(t.p.AdditionalData1, t.net), t.p.Action, 1, t.p.ReplyID); break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); FoxEventLog.VerboseWriteEventLog("Push1: PushThreadActionRunner thread crashed", System.Diagnostics.EventLogEntryType.Information); } }
public bool RemovePolicy(LoadedPolicyObject policy) { #if DEBUG PolicyTesting t = JsonConvert.DeserializeObject <PolicyTesting>(policy.PolicyObject.Data); FoxEventLog.VerboseWriteEventLog("REMOVEAL Testing: " + t.CheckBox1.ToString() + " " + t.CheckBox2.ToString() + " " + t.CheckBox3.ToString() + " " + t.Text, System.Diagnostics.EventLogEntryType.Information); #endif return(true); }
static public void StopPushThread() { FoxEventLog.VerboseWriteEventLog("Push0: Stopping Push Thread", System.Diagnostics.EventLogEntryType.Information); StopThread = true; if (pm != null) { pm.Join(); } }
public bool UpdatePolicy(LoadedPolicyObject oldpolicy, LoadedPolicyObject newpolicy) { #if DEBUG PolicyTesting t = JsonConvert.DeserializeObject <PolicyTesting>(oldpolicy.PolicyObject.Data); FoxEventLog.VerboseWriteEventLog("[OLD] Testing: " + t.CheckBox1.ToString() + " " + t.CheckBox2.ToString() + " " + t.CheckBox3.ToString() + " " + t.Text, System.Diagnostics.EventLogEntryType.Information); t = JsonConvert.DeserializeObject <PolicyTesting>(newpolicy.PolicyObject.Data); FoxEventLog.VerboseWriteEventLog("[NEW] Testing: " + t.CheckBox1.ToString() + " " + t.CheckBox2.ToString() + " " + t.CheckBox3.ToString() + " " + t.Text, System.Diagnostics.EventLogEntryType.Information); #endif return(true); }
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 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 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); }
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; }
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); }