Ejemplo n.º 1
0
 private static void SharedPrinterListenerWorker()
 {
     while (listeningForRemotePrinting)
     {
         SeapClient.ListenRemotePrintBlocking(OnRemotePrintingRequest);
     }
 }
Ejemplo n.º 2
0
        private static void OnCreate(object source, FileSystemEventArgs e)
        {
            Logger.GetInstance().Debug("Local Printing: " + e.FullPath);
            String printerDir;
            String docName;

            metaPath         = e.FullPath;
            localJobId       = Path.GetFileNameWithoutExtension(metaPath);
            printerDir       = Path.GetDirectoryName(metaPath);
            docName          = "";
            localPrinterName = printerDir.Substring(
                printerDir.LastIndexOf(Path.DirectorySeparatorChar) + 1,
                printerDir.Length - (printerDir.LastIndexOf(Path.DirectorySeparatorChar) + 1));
            localXpsPath = metaPath.Replace(".meta", ".xps");
            try
            {
                if (WaitForFile(metaPath))
                {
                    string[] metaText = System.IO.File.ReadAllLines(metaPath, System.Text.Encoding.Unicode);
                    if (metaText.Length > 0)
                    {
                        docName = metaText[0].Replace("docname:", "").Trim();
                    }
                }
                else
                {
                    Logger.GetInstance().Error("OnCreate: WaitForFile failed for meta file");
                }
            }
            catch (Exception ex)
            {
                Logger.GetInstance().Error("OnCreate:" + ex);
            }

            if (SeapClient.NotitfyPrintOperation(docName, localPrinterName, localXpsPath) == FileOperation.Action.ALLOW)
            {
                try
                {
                    var thread = new Thread(WorkerMethodLocal);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                }
                catch (Exception ex)
                {
                    Logger.GetInstance().Error(ex);
                    if (ex.InnerException != null)
                    {
                        Logger.GetInstance().Error(ex.InnerException.Message + ex.InnerException.StackTrace);
                    }
                }
            }
            else
            {
                Logger.GetInstance().Debug("blocked print:" + docName + " " + localXpsPath);
                //Do nothing block item
            }
        }
Ejemplo n.º 3
0
        public void StartBackground()
        {
            lock (MainController.GetInstance())
            {
                //notify logger that we are in main service
                Logger.GetInstance().InitializeMainLogger(serviceLogger);
                SvcController.StopMyDLP = new SvcController.StopMyDLPDelegate(Stop);

                //Keep watchdog tied up during debugging
                if (System.Environment.UserInteractive == false)
                {
                    ServiceController service = new ServiceController("mydlpepwatchdog");
                    try
                    {
                        if (!service.Status.Equals(ServiceControllerStatus.Running) && !service.Status.Equals(ServiceControllerStatus.StartPending))
                        {
                            Logger.GetInstance().Info("Starting mydlpepwatchdog at start up");
                            SvcController.StartServiceNonBlocking("mydlpepwatchdog", 10000);
                            Logger.GetInstance().Info("Starting mydlpepwatchdog at start up finished");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.GetInstance().Error("Unable to start watchdog" + e);
                    }
                    //enable watchdog check

                    Logger.GetInstance().Info("Watchdog check enabled");
                    watchdogTimer          = new System.Timers.Timer(watchdogTimerPeriod);
                    watchdogTimer.Elapsed += new ElapsedEventHandler(OnTimedWatchdogEvent);
                    watchdogTimer.Enabled  = true;
                }



                if (Configuration.GetAppConf() == false)
                {
                    Logger.GetInstance().Error("Unable to get configuration exiting!");
                    //Environment.Exit(1);
                }
                else
                {
                    //start backend engine

                    Configuration.GetUserConf();
                    Configuration.StartTime = DateTime.Now;

                    SessionManager.Start();

                    Engine.GetPhysicalMemory = new Engine.GetPhysicalMemoryDelegate(GetPhysicalMemory);
                    Engine.Start();
                    Configuration.SetPids();

                    Logger.GetInstance().Debug("mydlpepwin tries to install mydlpmf");
                    MyDLPEP.MiniFilterController.GetInstance().Start();

                    MyDLPEP.FilterListener.getInstance().StartListener();
                    Logger.GetInstance().Info("mydlpepwin service started");

                    bool testSuccess = false;
                    for (int i = 0; i < 10; i++)
                    {
                        testSuccess = SeapClient.SeapConnectionTest();
                        if (testSuccess)
                        {
                            break;
                        }
                        Logger.GetInstance().Debug("Seap connection test attempt:" + i);
                        System.Threading.Thread.Sleep(3000);
                    }

                    if (!testSuccess)
                    {
                        Logger.GetInstance().Error("Seap connection test failed");
                        Stop();
                    }

                    if (Configuration.BlockScreenShot)
                    {
                        ScreenShotContoller.Start();
                    }

                    SessionServer.Start();

                    if (Configuration.PrinterMonitor)
                    {
                        Service.PrinterController.getInstance().Start();
                    }

                    if (Configuration.RemovableStorageEncryption)
                    {
                        DiskCryptor.StartDcrypt();
                    }

                    if (Configuration.UsbSerialAccessControl)
                    {
                        Core.USBController.Activate();
                        Core.USBController.GetUSBStorages();
                    }
                }

                //initialize configuration timer
                Logger.GetInstance().Info("Configuration check enabled");
                confTimer          = new System.Timers.Timer(confCheckTimerPeriod);
                confTimer.Elapsed += new ElapsedEventHandler(OnTimedConfCheckEvent);
                confTimer.Enabled  = true;

                Logger.GetInstance().Info("mydlpepwin service started");
            }
        }
Ejemplo n.º 4
0
        private void OnTimedConfCheckEvent(object source, ElapsedEventArgs e)
        {
            bool   oldUSBSerialAC       = Configuration.UsbSerialAccessControl;
            bool   oldPrinterMonitor    = Configuration.PrinterMonitor;
            bool   oldArchiveInbound    = Configuration.ArchiveInbound;
            bool   oldBlockScreenShot   = Configuration.BlockScreenShot;
            bool   oldRemStorEncryption = Configuration.RemovableStorageEncryption;
            bool   oldHasEncryptionKey  = Configuration.HasEncryptionKey;
            String oldPrinterPrefix     = Configuration.PrinterPrefix;

            if (SeapClient.HasNewConfiguration())
            {
                Logger.GetInstance().Info("New configuration notified.");

                Configuration.GetUserConf();

                if (Configuration.UsbSerialAccessControl && !oldUSBSerialAC)
                {
                    Core.USBController.Activate();
                }
                else if (!Configuration.UsbSerialAccessControl && oldUSBSerialAC)
                {
                    Core.USBController.Deactive();
                }

                if (Configuration.UsbSerialAccessControl)
                {
                    USBController.InvalidateCache();
                    Core.USBController.GetUSBStorages();
                }

                if (Configuration.PrinterMonitor && !oldPrinterMonitor)
                {
                    Service.PrinterController.getInstance().Start();
                }
                else if (!Configuration.PrinterMonitor && oldPrinterMonitor)
                {
                    Service.PrinterController.getInstance().Stop();
                }
                else if (Configuration.PrinterMonitor && (Configuration.PrinterPrefix != oldPrinterPrefix))
                {
                    Service.PrinterController.getInstance().Stop();
                    Service.PrinterController.getInstance().Start();
                }

                if (Configuration.RemovableStorageEncryption && !oldRemStorEncryption)
                {
                    DiskCryptor.StartDcrypt();
                }
                else if (!Configuration.RemovableStorageEncryption && oldRemStorEncryption)
                {
                    DiskCryptor.StopDcrypt();
                }

                if (oldArchiveInbound != Configuration.ArchiveInbound ||
                    oldUSBSerialAC != Configuration.UsbSerialAccessControl)
                {
                    Logger.GetInstance().Debug("New mydlpmf configuration");
                    MyDLPEP.MiniFilterController.GetInstance().Stop();
                    MyDLPEP.MiniFilterController.GetInstance().Start();
                    MyDLPEP.FilterListener.getInstance().StartListener();
                }

                if (oldBlockScreenShot)
                {
                    ScreenShotContoller.Stop();
                }

                if (Configuration.BlockScreenShot)
                {
                    ScreenShotContoller.Start();
                }
            }

            if (Configuration.RemovableStorageEncryption)
            {
                if (oldHasEncryptionKey)
                {
                    if (!SeapClient.HasKeyfile())
                    {
                        Configuration.HasEncryptionKey = false;
                        DiskCryptor.AfterKeyLose();
                    }
                }
                else
                {
                    if (SeapClient.HasKeyfile())
                    {
                        Configuration.HasEncryptionKey = true;
                        DiskCryptor.AfterKeyReceive();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void WorkerMethodLocal(object state)
        {
            Logger.GetInstance().Debug("Started Printing for MyDLP printer: " + localPrinterName);
            PrintQueue pQueue = null;

            try
            {
                PrinterController controller = PrinterController.getInstance();
                if (controller.IsPrinterConnection(localPrinterName))
                {
                    //It will be printerd remotely
                    //It is a network printer connection on local computer
                    PrinterController.PrinterConnection connection = controller.GetPrinterConnection(localPrinterName);
                    IPAddress[] addresslist = Dns.GetHostAddresses(connection.server);
                    Logger.GetInstance().Debug("Initiating remote print remoteprinter: " +
                                               connection.name + " on server:" + connection.server + "of File:" + localXpsPath);
                    SeapClient.InitiateRemotePrint(localJobId, connection.name, addresslist[0].ToString(), localXpsPath);
                }
                else
                {
                    //It is a local printer
                    LocalPrintServer     pServer     = new LocalPrintServer();
                    PrintQueueCollection qCollection = pServer.GetPrintQueues();
                    foreach (PrintQueue q in qCollection)
                    {
                        //Find mathing non secure printer
                        if (PrinterController.GetSecurePrinterName(q.Name) == localPrinterName)
                        {
                            pQueue = q;
                        }
                    }
                    if (pQueue == null)
                    {
                        throw new Exception("Unable to find a matching non secure printer for mydlp printer: " + localPrinterName);
                    }
                    Logger.GetInstance().Debug("Adding print job on real printer: " + pQueue.Name +
                                               ", path:" + localXpsPath + ", jobID:" + localJobId);
                    if (WaitForFile(localXpsPath))
                    {
                        pQueue.AddJob(localJobId, localXpsPath, false);
                        Thread.Sleep(1000);
                        Logger.GetInstance().Debug("Removing:" + localXpsPath);
                        File.Delete(localXpsPath);
                        File.Delete(metaPath);
                        Logger.GetInstance().Debug("Finished Printing");
                    }
                    else
                    {
                        Logger.GetInstance().Debug("WorkerMethodLocal WaitForFile failed for xps file");
                    }
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error("WorkerMethod Exception" + e);
                if (e.InnerException != null)
                {
                    Logger.GetInstance().Error(e.InnerException.Message + e.InnerException.StackTrace);
                }
            }
        }