Exemplo n.º 1
0
        /// <summary>
        /// constructor, which is called for each http request
        /// </summary>
        public TOpenPetraOrgSessionManager() : base()
        {
            try
            {
                Init();
            }
            catch (Exception e)
            {
                if (TLogWriter.GetLogFileName() == String.Empty)
                {
                    throw new Exception("Exception in TOpenPetraOrgSessionManager.Init(): " + e.ToString());
                }

                TLogging.Log("Exception in TOpenPetraOrgSessionManager.Init()");
                TLogging.Log(e.ToString());
                throw new Exception("Exception in TOpenPetraOrgSessionManager.Init()");
            }
        }
Exemplo n.º 2
0
        private Boolean ApplyPetraPatch(String APatchFile)
        {
            Boolean ReturnValue;
            String  TempPath;

            string[] directories;
            String[] files;
            ReturnValue = false;
            TLogging.Log("installing patch " + APatchFile);

            // create temp directory
            TempPath = Path.GetFullPath(Path.GetTempPath() + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(APatchFile));

            if (Directory.Exists(TempPath))
            {
                //  remove old temp directory: for testing patches, otherwise we are using the old version
                Directory.Delete(TempPath, true);
            }

            Directory.CreateDirectory(TempPath);

            // extract the tar patch file into the temp directory
            PackTools.Unzip(TempPath, APatchFile);

            // make sure that PetraClient has been stopped
            if (PatchApplication.ProcessStillRunning(FBinPath + Path.DirectorySeparatorChar + "PetraClient.exe"))
            {
                TLogging.Log("Wait for PetraClient to stop...");

                while (PatchApplication.ProcessStillRunning(FBinPath + Path.DirectorySeparatorChar + "PetraClient.exe"))
                {
                    TLogging.Log("Wait for PetraClient to stop...");
                }
            }

            try
            {
                // apply the patch
                TLogging.Log("applying patch, please wait");

                // go through all directories in patch, all files
                directories = System.IO.Directory.GetDirectories(TempPath);

                foreach (string dir in directories)
                {
                    ApplyPatchRecursively(TempPath, dir);
                }

                // rename the manually patched .dll and .exe files in net-patches directory,
                // since they should be part of the official patch in bin directory

                // go through bin/netpatches (or sapatches or remotepatches)
                directories = System.IO.Directory.GetDirectories(FBinPath, "*patches");

                foreach (string dir in directories)
                {
                    // delete the file.old if it already exists, if there is a file without .old
                    // that way we prevent the deletion of nrr (non routine request) files that have gone to the wrong directory
                    files = System.IO.Directory.GetFiles(dir, "*.old");

                    foreach (string filename in files)
                    {
                        if (System.IO.File.Exists(filename.Substring(0, filename.Length - 4)))
                        {
                            System.IO.File.Delete(filename);
                        }
                        else
                        {
                            // restore the .dll file (nrr)
                            System.IO.File.Move(filename, filename.Substring(0, filename.Length - 4));
                        }
                    }

                    // rename .dll file to file.dll.old
                    files = System.IO.Directory.GetFiles(directories[0], "*.dll");

                    foreach (string filename in files)
                    {
                        System.IO.File.Move(filename, filename + ".old");
                    }

                    // rename .exe file to file.exe.old
                    files = System.IO.Directory.GetFiles(directories[0], "*.exe");

                    foreach (string filename in files)
                    {
                        System.IO.File.Move(filename, filename + ".old");
                    }
                }

                // delete the .dll.orig files, because we have applied the new version for all files
                // those files have been created manually when we give out special dll files (not recommended)
                files = System.IO.Directory.GetFiles(FBinPath, "*.orig");

                foreach (string filename in files)
                {
                    if (System.IO.File.Exists(filename.Substring(0, filename.Length - 5)))
                    {
                        System.IO.File.Delete(filename);
                    }
                }

                TLogging.Log("Patch " + APatchFile + " has been applied successfully!");
                ReturnValue = true;
            }
            catch (Exception e)
            {
                TLogging.Log("Patch could not be installed: " + e.Message);
                TLogging.Log(e.ToString());
                TLogging.Log(e.StackTrace);
                TLogging.Log("Restoring the situation before the patch...");

                // if unsuccessful, restore the previous situation;
                // go through all directories in patch, all files
                directories = System.IO.Directory.GetDirectories(TempPath);

                foreach (string dir in directories)
                {
                    UndoPatchRecursively(TempPath, dir);
                }

                TLogging.Log("Please contact your IT support and send the file " + TLogWriter.GetLogFileName());
            }

            // clean up the safety backup files of the patch
            directories = System.IO.Directory.GetDirectories(TempPath);

            foreach (string dir in directories)
            {
                CleanupPatchRecursively(TempPath, dir);
            }

            // delete temp directory recursively (and the backup zip files)
            Directory.Delete(TempPath, true);
            return(ReturnValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the session id for this current thread.
        /// Each request has its own thread.
        /// Threads can be reused for different users.
        /// </summary>
        public static void InitThread(string AThreadDescription, string AConfigFileName, string ASessionID = null)
        {
            TLogWriter.ResetStaticVariables();
            TLogging.ResetStaticVariables();

            new TAppSettingsManager(AConfigFileName);
            new TLogging(TSrvSetting.ServerLogFile);
            TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0);

            string httprequest = "";

            if ((HttpContext.Current != null) && (HttpContext.Current.Request != null))
            {
                httprequest = " for path " + HttpContext.Current.Request.PathInfo;
            }

            TLogging.LogAtLevel(4, AThreadDescription + ": Running InitThread for thread id " + Thread.CurrentThread.ManagedThreadId.ToString() + httprequest);

            FSessionID     = ASessionID;
            FSessionValues = null;

            string sessionID;

            if (ASessionID == null)
            {
                sessionID = FindSessionID();
            }
            else
            {
                sessionID = ASessionID;
            }

            TDataBase db = null;

            // avoid dead lock on parallel logins
            FDeleteSessionMutex.WaitOne();

            try
            {
                db = ConnectDB("SessionInitThread");

                TDBTransaction t            = new TDBTransaction();
                bool           SubmissionOK = false;
                bool           newSession   = false;

                db.WriteTransaction(ref t,
                                    ref SubmissionOK,
                                    delegate
                {
                    // get the session ID, or start a new session
                    // load the session values from the database
                    // update the session last access in the database
                    // clean old sessions
                    newSession = InitSession(sessionID, t);

                    SubmissionOK = true;
                });

                if (newSession)
                {
                    // use a separate transaction to clean old sessions
                    db.WriteTransaction(ref t,
                                        ref SubmissionOK,
                                        delegate
                    {
                        CleanOldSessions(t);
                        SubmissionOK = true;
                    });
                }
            }
            finally
            {
                db.CloseDBConnection();

                FDeleteSessionMutex.ReleaseMutex();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// initialise the server for each Web Request
        /// </summary>
        private static bool Init()
        {
            string ConfigFileName = string.Empty;

            // make sure the correct config file is used
            string Instance = HttpContext.Current.Request.Url.ToString().Replace("http://", "").Replace("https://", "");

            Instance = Instance.Substring(0, Instance.IndexOf(".")).Replace("op_", "op").Replace("op", "op_");

            // for demo etc
            if (!Instance.StartsWith("op_"))
            {
                Instance = "op_" + Instance;
            }

            ConfigFileName = "/home/" + Instance + "/etc/PetraServerConsole.config";

            if (File.Exists(ConfigFileName))
            {
                // we are in a multi tenant hosting scenario
            }
            else if (Environment.CommandLine.Contains("/appconfigfile="))
            {
                // this happens when we use fastcgi-mono-server4
                ConfigFileName = Environment.CommandLine.Substring(
                    Environment.CommandLine.IndexOf("/appconfigfile=") + "/appconfigfile=".Length);

                if (ConfigFileName.IndexOf(" ") != -1)
                {
                    ConfigFileName = ConfigFileName.Substring(0, ConfigFileName.IndexOf(" "));
                }
            }
            else
            {
                // this is the normal behaviour when running with local http server
                ConfigFileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "web.config";
            }

            TLogWriter.ResetStaticVariables();
            TLogging.ResetStaticVariables();
            TTypedDataTable.ResetStaticVariables();
            TPdfPrinter.ResetStaticVariables();
            THTTPUtils.ResetStaticVariables();
            TSharedDataCache.TMPartner.ResetStaticVariables();
            TServerManagerBase.ResetStaticVariables();
            TClientManager.ResetStaticVariables();

            new TAppSettingsManager(ConfigFileName);
            new TLogging(TSrvSetting.ServerLogFile);
            TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0);
            TSession.InitThread();

            if (TLogging.DebugLevel >= 4)
            {
                TLogging.Log("TOpenPetraOrgSessionManager.Init");
                TLogging.Log(HttpContext.Current.Request.PathInfo);
            }

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Server.ScriptTimeout = Convert.ToInt32(
                    TimeSpan.FromMinutes(TAppSettingsManager.GetInt32("WebRequestTimeOutInMinutes", 15)).
                    TotalSeconds);
            }

            // if the Login Method is called: reset cookie, ignore any old session
            if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login"))
            {
                TSession.CloseSession();
                TSession.InitThread();
            }

            Catalog.Init();

            ErrorCodeInventory.Init();
            ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Petra.Shared.PetraErrorCodes));
            ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Common.Verification.TStringChecks));

            TServerManager.TheServerManager = new TServerManager();

            // initialise the cached tables and the delegates
            TSetupDelegates.Init();

            TLogging.LogAtLevel(4, "Server has been initialised");

            return(true);
        }