public static bool HasKeyfile()
        {
            try
            {
                Logger.GetInstance().Debug("HasKeyfile");
                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;

                response  = sClient.sendMessage("HASKEY");
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(false);
                }

                if (splitResp[1].Equals("yes"))
                {
                    return(true);
                }
                else if (splitResp[1].Equals("no"))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                //todo: Default Acion
                return(false);
            }
            //todo: Default Acion
            return(false);
        }
        public static void ListenRemotePrintBlocking(RemotePrinterHandlerDelegate processPrinting)
        {
            String user        = "";
            String printerName = "";
            String jobId       = "";
            String path        = "";

            try
            {
                SeapClient sClient = SeapClient.GetTrapInstance();
                Logger.GetInstance().Debug("TRAP");
                String   response;
                String[] splitResp;

                response  = sClient.sendMessage("TRAP");
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return;
                }
                if (splitResp[1].StartsWith("retrap"))
                {
                    return;
                }
                else if (splitResp[1].StartsWith("print"))
                {
                    path = splitResp[2];
                    for (int i = 3; i < splitResp.Length; i++)
                    {
                        int    idx = splitResp[i].IndexOf('=');
                        String key = splitResp[i].Substring(0, idx);
                        String val = splitResp[i].Substring(idx + 1);
                        val = qpDecode(val);
                        if (key == "user")
                        {
                            user = val;
                        }
                        else if (key == "user")
                        {
                            user = val;
                        }
                        else if (key == "printerName")
                        {
                            printerName = val;
                        }
                        else if (key == "jobId")
                        {
                            jobId = val;
                        }
                    }
                    Logger.GetInstance().Info("Handling remte print on server for remote user:"******" printerName: " + printerName + " jobId: " + jobId + " path: " + path);
                    processPrinting(jobId, path, printerName);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
            }
        }
        public static string GetKeyfile()
        {
            try
            {
                Logger.GetInstance().Debug("GetKeyfile");
                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;

                response  = sClient.sendMessage("GETKEY");
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(null);
                }

                return(splitResp[1]);
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                return(null);
            }
            //todo: Default Acion
            return(null);
        }
        public static bool HasNewConfiguration()
        {
            try
            {
                Logger.GetInstance().Debug("GetConfUpdateNotification");
                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;

                String loggedOnUser = Configuration.GetLoggedOnUser();
                String version      = Configuration.GetMyDLPVersion();
                if (version == null || version.Length == 0)
                {
                    version = "No version";
                }

                response = sClient.sendMessage("CONFUPDATE "
                                               + "version=" + qpEncode(version) + " "
                                               + "user="******" "
                                               + "hostname=" + qpEncode(System.Environment.MachineName));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(false);
                }

                if (splitResp[1].Equals("yes"))
                {
                    return(true);
                }
                else if (splitResp[1].Equals("no"))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                //todo: Default Acion
                return(false);
            }
            //todo: Default Acion
            return(false);
        }
        public static bool SeapConnectionTest()
        {
            try
            {
                SeapClient sClient = SeapClient.GetInstance();
                Logger.GetInstance().Debug("Connection test");

                String   response;
                String[] splitResp;

                response = sClient.sendMessage("BEGIN");
            }
            catch (Exception e)
            {
                Logger.GetInstance().Debug(e);
                return(false);
            }
            return(true);
        }
        public static void InitiateRemotePrint(String jobId, String printerName, String server, String path)
        {
            try
            {
                SeapClient sClient = SeapClient.GetInstance();
                Logger.GetInstance().Debug("InitiatedRemotePrint " + " printerName: " + printerName + " server:" + server +
                                           " path: " + path);
                String shortFilePath = Engine.GetShortPath(path);
                String response;
                String request = "IECP " + server + " " + qpEncode(shortFilePath)
                                 + " command=print"
                                 + " user="******" printerName=" + qpEncode(printerName)
                                 + " jobId=" + qpEncode(jobId);
                Logger.GetInstance().Debug("request:<" + request + ">");

                response = sClient.sendMessage(request);
                Logger.GetInstance().Debug("response:<" + response + ">");
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e.ToString());
            }
        }
        public static FileOperation.Action NotitfyPrintOperation(String documentName, String printerName, String path)
        {
            try
            {
                SeapClient sClient = SeapClient.GetInstance();
                Logger.GetInstance().Debug("NotitfyPrintOperation " +
                                           " documentName: " + documentName + " printerName : " + printerName +
                                           " path: " + path);

                String shortFilePath = Engine.GetShortPath(path);

                String   response;
                String[] splitResp;
                long     id;

                response = sClient.sendMessage("BEGIN");

                if (response.Equals("ERR"))
                {
                    return(FileOperation.Action.ALLOW);
                }
                else
                {
                    splitResp = response.Split(' ');
                    if (splitResp[0].Equals("OK"))
                    {
                        id = Int64.Parse(splitResp[1]);
                    }
                    else
                    {
                        return(FileOperation.Action.ALLOW);
                    }
                }

                /*response = sClient.sendMessage("SETPROP " + id + " burn_after_reading=true");
                 * splitResp = response.Split(' ');
                 * if (!splitResp[0].Equals("OK"))
                 * {
                 *  return FileOperation.Action.ALLOW;
                 * }*/

                /*response = sClient.sendMessage("SETPROP " + id + " pageCount=" + pageCount);
                 * splitResp = response.Split(' ');
                 * if (!splitResp[0].Equals("OK"))
                 * {
                 *  return;
                 * }*/

                response  = sClient.sendMessage("SETPROP " + id + " filename=" + qpEncode(documentName) + ".xps");
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("SETPROP " + id + " printerName=" + qpEncode(printerName));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " user="******"OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                /*response = sClient.sendMessage("SETPROP " + id + " user="******"OK"))
                 * {
                 *  return;
                 * }*/

                response = sClient.sendMessage("PUSHFILE " + id + " " +
                                               qpEncode(shortFilePath));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("END " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("ACLQ " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                sClient.sendMessage("DESTROY " + id);

                if (splitResp[1].Equals("block"))
                {
                    return(FileOperation.Action.BLOCK);
                }
                else if (splitResp[1].Equals("pass"))
                {
                    return(FileOperation.Action.ALLOW);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                return(FileOperation.Action.ALLOW);
            }
            return(FileOperation.Action.ALLOW);
        }
        public static FileOperation.Action GetWriteDecisionByPath(String filePath, String tempFilePath)
        {
            try
            {
                Logger.GetInstance().Debug("GetWriteDecisionByPath filePath:" + filePath + " tempFilePath:" + tempFilePath);

                if (tempFilePath.Equals("") || Engine.GetShortPath(tempFilePath).Equals(""))
                {
                    return(FileOperation.Action.ALLOW);
                }

                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;
                long       id;

                response = sClient.sendMessage("BEGIN");

                if (response.Equals("ERR"))
                {
                    return(FileOperation.Action.ALLOW);
                }
                else
                {
                    splitResp = response.Split(' ');
                    if (splitResp[0].Equals("OK"))
                    {
                        id = Int64.Parse(splitResp[1]);
                    }
                    else
                    {
                        return(FileOperation.Action.ALLOW);
                    }
                }

                //response = sClient.sendMessage("SETPROP " + id + " filename=" + Engine.GetShortPath(filePath));
                response = sClient.sendMessage("SETPROP " + id +
                                               " filename=" + qpEncode(Path.GetFileName(filePath)));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " fullpath=" + qpEncode(filePath));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("SETPROP " + id + " burn_after_reading=true");
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " user="******"OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("PUSHFILE " + id + " " + qpEncode(tempFilePath));

                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("END " + id);

                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("ACLQ " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                sClient.sendMessage("DESTROY " + id);

                if (splitResp[1].Equals("block"))
                {
                    return(FileOperation.Action.BLOCK);
                }
                else if (splitResp[1].Equals("pass"))
                {
                    return(FileOperation.Action.ALLOW);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                //todo: Default Acion
                return(FileOperation.Action.ALLOW);
            }
            //todo: Default Acion
            return(FileOperation.Action.ALLOW);
        }
        public static FileOperation.Action GetUSBSerialDecision(String serial)
        {
            try
            {
                Logger.GetInstance().Debug("GetUSBSerialDecision serial: " + serial);

                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;
                long       id;

                response = sClient.sendMessage("BEGIN");

                if (response.Equals("ERR"))
                {
                    return(FileOperation.Action.ALLOW);
                }
                else
                {
                    splitResp = response.Split(' ');
                    if (splitResp[0].Equals("OK"))
                    {
                        id = Int64.Parse(splitResp[1]);
                    }
                    else
                    {
                        return(FileOperation.Action.ALLOW);
                    }
                }

                response = sClient.sendMessage("SETPROP " + id + " type=usb_device");

                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " user="******"OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                //response = sClient.sendMessage("SETPROP " + id + " filename=" + shortFilePath);
                response = sClient.sendMessage("SETPROP " + id + " device_id=" + serial);

                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("END " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("ACLQ " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                sClient.sendMessage("DESTROY " + id);

                if (splitResp[1].Equals("block"))
                {
                    return(FileOperation.Action.BLOCK);
                }
                else if (splitResp[1].Equals("pass"))
                {
                    return(FileOperation.Action.ALLOW);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                //todo: Default Acion
                return(FileOperation.Action.ALLOW);
            }
            //todo: Default Acion
            return(FileOperation.Action.ALLOW);
        }
Esempio n. 10
0
        public static FileOperation.Action GetWriteDecisionByCache(String filePath, MemoryStream cache)
        {
            try
            {
                Logger.GetInstance().Debug("GetWriteDecisionByCache path: " + filePath + " length:" + cache.Length);

                if (cache.Length == 0)
                {
                    return(FileOperation.Action.ALLOW);
                }

                SeapClient sClient = SeapClient.GetInstance();
                String     response;
                String[]   splitResp;
                long       id;

                response = sClient.sendMessage("BEGIN");

                if (response.Equals("ERR"))
                {
                    return(FileOperation.Action.ALLOW);
                }
                else
                {
                    splitResp = response.Split(' ');
                    if (splitResp[0].Equals("OK"))
                    {
                        id = Int64.Parse(splitResp[1]);
                    }
                    else
                    {
                        return(FileOperation.Action.ALLOW);
                    }
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " filename=" + qpEncode(Path.GetFileName(filePath)));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " fullpath=" + qpEncode(filePath));
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("SETPROP " + id +
                                               " user="******"OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }


                String cmd = "PUSH " + id + " " + cache.Length;

                response  = sClient.sendMessage(cmd, cache);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response = sClient.sendMessage("END " + id);

                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                response  = sClient.sendMessage("ACLQ " + id);
                splitResp = response.Split(' ');
                if (!splitResp[0].Equals("OK"))
                {
                    return(FileOperation.Action.ALLOW);
                }

                sClient.sendMessage("DESTROY " + id);

                if (splitResp[1].Equals("block"))
                {
                    return(FileOperation.Action.BLOCK);
                }
                else if (splitResp[1].Equals("pass"))
                {
                    return(FileOperation.Action.ALLOW);
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error(e);
                //todo: Default Acion
                return(FileOperation.Action.ALLOW);
            }
            //todo: Default Acion
            return(FileOperation.Action.ALLOW);
        }