Exemplo n.º 1
0
        /// <summary>
        /// Initialises the internal variables that hold the Server Settings, using the current config file.
        ///
        /// </summary>
        /// <returns>void</returns>
        public TSrvSetting()
        {
            FConfigurationFile = TAppSettingsManager.ConfigFileName;
            FExecutingOS       = Utilities.DetermineExecutingOS();

            // Server.RDBMSType
            FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql"));

            FApplicationBinFolder = TAppSettingsManager.GetValue("Server.ApplicationBinDirectory", string.Empty, false);

            if (TAppSettingsManager.HasValue("Server.LogFile"))
            {
                FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false);
            }
            else
            {
                // maybe the log file has already been set, eg. by the NUnit Server Test
                FServerLogFile = TLogging.GetLogFileName();

                if (FServerLogFile.Length == 0)
                {
                    // this is effectively the bin directory (current directory)
                    FServerLogFile = "Server.log";
                }
            }

            // Server.Port
            FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 80);

            // Determine network configuration of the Server
            Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses);

            FApplicationVersion = TFileVersionInfo.GetApplicationVersion();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Examines the network configuration of the computer where this procedure is
        /// executed.
        ///
        /// </summary>
        /// <param name="ComputerName">Network name of the computer</param>
        /// <param name="IPAddresses">IP Address(es) of the computer (separated by semicolons if
        /// there is more than one IP Address for this computer)
        /// </param>
        /// <returns>void</returns>
        public static void DetermineNetworkConfig(out String ComputerName, out String IPAddresses)
        {
            IPHostEntry HostInfo;

            // Get ComputerName and IPAddress(es) of the local computer
            ComputerName = Dns.GetHostName();
            HostInfo     = Dns.GetHostEntry(ComputerName);

            // Loop through all IPAddressses of the local computer
            IPAddresses = "";

            foreach (IPAddress ip in HostInfo.AddressList)
            {
                IPAddresses = IPAddresses + ip.ToString() + "; ";
            }

            IPAddresses = IPAddresses.Substring(0, IPAddresses.Length - 2); // remove last '; '

            // on virtual servers, we have to tell the IP address manually, iptables forwarding hides the IP address
            IPAddresses = TAppSettingsManager.GetValue("ListenOnIPAddress", IPAddresses, false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Rotates the logfiles names in the following way.
        /// Example: the current log file for today is PetraClient.log,
        /// the logfile from yesterday PetraClient-01.log,
        /// the day before yesterday PetraClient-02.log, and files older than 6 days are deleted.
        ///
        /// When it comes to rotate the logfiles, the number of each logfile is increased
        /// </summary>
        /// <param name="LogFileName">Full Path including filename</param>
        private static void RotateFiles(string LogFileName)
        {
            string LogfilePath = Path.GetDirectoryName(LogFileName);
            string Extension   = Path.GetExtension(LogFileName);
            string LogFileNameWithoutExtension = Path.GetFileNameWithoutExtension(LogFileName);

            int NumberOfLogFilesToKeep = TAppSettingsManager.GetInt16("NumberOfLogFilesToKeep", -2);

            if ((NumberOfLogFilesToKeep == -2) ||   // -2: log rotation config file setting doesn't exist
                (NumberOfLogFilesToKeep == -1))     // -1: log rotation config file setting -1 means: do not rotate log.
            {
                // rotation is disabled
                return;
            }

            for (int i = NumberOfLogFilesToKeep; i > 0; i--)
            {
                string NameToRotate = LogFileNameWithoutExtension + "-" + i.ToString("00") + Extension;
                string OldFile      = Path.Combine(LogfilePath, NameToRotate);

                if (File.Exists(OldFile))
                {
                    if (NumberOfLogFilesToKeep == i)
                    {
                        File.Delete(OldFile);
                    }
                    else
                    {
                        string NewName = LogFileNameWithoutExtension + "-" + (i + 1).ToString("00") + Extension;

                        File.Move(OldFile, Path.Combine(LogfilePath, NewName));
                    }
                }
            }

            // change the newest logfile to -01.log
            string Name = LogFileNameWithoutExtension + "-01" + Extension;

            File.Move(LogFileName, Path.Combine(LogfilePath, Name));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialises the font settings by using values from the config file,
        /// but also checking the Windows environment to find out whether this is a western or asian system
        /// </summary>
        /// <returns>the default font to be used</returns>
        public static Font InitFontI18N()
        {
            TextBox txt         = new TextBox();
            Font    WindowsFont = txt.Font;

            Font ReturnValue;

            // set the font in the config file; or try to figure it out from the Windows XP system font (WindowsFont)

            if (TAppSettingsManager.HasValue("FontName") && TAppSettingsManager.HasValue("FontSize"))
            {
                changeFonts = true;
                ReturnValue = new System.Drawing.Font(
                    TAppSettingsManager.GetValue("FontName"),
                    TAppSettingsManager.GetFloat("FontSize"));
                SetDefaultUIFont(ReturnValue);

                if (TAppSettingsManager.HasValue("FontAllowBold") && (TAppSettingsManager.GetBoolean("FontAllowBold", false) == true))
                {
                    SetDefaultBoldFont(new System.Drawing.Font(
                                           TAppSettingsManager.GetValue("FontName"),
                                           TAppSettingsManager.GetFloat("FontSize"),
                                           System.Drawing.FontStyle.Bold));
                }
                else
                {
                    SetDefaultBoldFont(ReturnValue);
                }
            }
            // just set the font size in the config file, without specifying the font; will use the default Windows font
            else if ((!TAppSettingsManager.HasValue("FontName") && TAppSettingsManager.HasValue("FontSize")))
            {
                changeFonts = true;
                ReturnValue = new System.Drawing.Font(WindowsFont.Name, TAppSettingsManager.GetFloat("FontSize"));
                SetDefaultUIFont(ReturnValue);

                if (TAppSettingsManager.HasValue("FontAllowBold") && (TAppSettingsManager.GetBoolean("FontAllowBold", false) == true))
                {
                    SetDefaultBoldFont(new System.Drawing.Font(
                                           TAppSettingsManager.GetValue("FontName"),
                                           TAppSettingsManager.GetFloat("FontSize"),
                                           System.Drawing.FontStyle.Bold));
                }
                else
                {
                    SetDefaultBoldFont(ReturnValue);
                }
            }
            else if (WindowsFont.Name == "Microsoft Sans Serif")
            {
                // japanese winxp: MS UI Gothic
                // english winxp: Microsoft Sans Serif

                // this is a western / english Windows XP
                changeFonts = false;
                ReturnValue = new System.Drawing.Font("Verdana", 8.25f);
                SetDefaultUIFont(ReturnValue);
                SetDefaultBoldFont(
                    new System.Drawing.Font("Verdana",
                                            8.25f,
                                            System.Drawing.FontStyle.Bold,
                                            System.Drawing.GraphicsUnit.Point,
                                            0));
            }
            else
            {
                // this might be an asian windows; no special font for bold because that makes it unreadable, e.g. chinese or japanese
                ReturnValue = new System.Drawing.Font(WindowsFont.Name, 12.0f);
                changeFonts = true;
                SetDefaultBoldFont(ReturnValue);
                SetDefaultUIFont(ReturnValue);
            }

            return(ReturnValue);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialises the internal variables that hold the Server Settings, using the current config file.
        ///
        /// </summary>
        /// <returns>void</returns>
        public TSrvSetting()
        {
            if (USingletonSrvSetting == null)
            {
                USingletonSrvSetting = this;
            }

            FConfigurationFile = TAppSettingsManager.ConfigFileName;
            FExecutingOS       = Utilities.DetermineExecutingOS();

            // Server.RDBMSType
            FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql"));

            FDatabaseHostOrFile = TAppSettingsManager.GetValue("Server.DBHostOrFile", "localhost");
            FDatabasePort       = TAppSettingsManager.GetValue("Server.DBPort", "5432");
            FDatabaseName       = TAppSettingsManager.GetValue("Server.DBName", "openpetra");
            FDBUsername         = TAppSettingsManager.GetValue("Server.DBUserName", "petraserver");
            FDBPassword         = TAppSettingsManager.GetValue("Server.DBPassword", string.Empty, false);

            FApplicationBinFolder = TAppSettingsManager.GetValue("Server.ApplicationBinDirectory", string.Empty, false);

            if (FDBPassword == "PG_OPENPETRA_DBPWD")
            {
                // get the password from the file ~/.pgpass. This currently only works for PostgreSQL on Linux
                using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                                                          Path.DirectorySeparatorChar + ".pgpass"))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith(FDatabaseHostOrFile + ":" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":") ||
                            line.StartsWith("*:" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":"))
                        {
                            FDBPassword = line.Substring(line.LastIndexOf(':') + 1);
                            break;
                        }
                    }
                }
            }

            if (TAppSettingsManager.HasValue("Server.LogFile"))
            {
                FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false);
            }
            else
            {
                // maybe the log file has already been set, eg. by the NUnit Server Test
                FServerLogFile = TLogging.GetLogFileName();

                if (FServerLogFile.Length == 0)
                {
                    // this is effectively the bin directory (current directory)
                    FServerLogFile = "Server.log";
                }
            }

            // Server.Port
            FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 9000);

            FRunAsStandalone = TAppSettingsManager.GetBoolean("Server.RunAsStandalone", false);

            // Server.ClientIdleStatusAfterXMinutes
            FClientIdleStatusAfterXMinutes = TAppSettingsManager.GetInt32("Server.ClientIdleStatusAfterXMinutes", 5);

            // Server.ClientKeepAliveCheckIntervalInSeconds
            FClientKeepAliveCheckIntervalInSeconds = TAppSettingsManager.GetInt32("Server.ClientKeepAliveCheckIntervalInSeconds", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_LAN
            FClientKeepAliveTimeoutAfterXSecondsLAN = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_LAN", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_Remote
            FClientKeepAliveTimeoutAfterXSecondsRemote =
                TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_Remote", (ClientKeepAliveTimeoutAfterXSecondsLAN * 2));

            // Server.ClientConnectionTimeoutAfterXSeconds
            FClientConnectionTimeoutAfterXSeconds = TAppSettingsManager.GetInt32("Server.ClientConnectionTimeoutAfterXSeconds", 20);

            // Server.ClientAppDomainShutdownAfterKeepAliveTimeout
            FClientAppDomainShutdownAfterKeepAliveTimeout = TAppSettingsManager.GetBoolean("Server.ClientAppDomainShutdownAfterKeepAliveTimeout",
                                                                                           true);

            FSMTPServer = TAppSettingsManager.GetValue("Server.SMTPServer", "localhost");

            // This is disabled in processing at the moment, so we reflect that here. When it works change to true
            FAutomaticIntranetExportEnabled = TAppSettingsManager.GetBoolean("Server.AutomaticIntranetExportEnabled", false);

            // The following setting specifies the email address where the Intranet Data emails are sent to when "Server.AutomaticIntranetExportEnabled" is true.
            FIntranetDataDestinationEmail = TAppSettingsManager.GetValue("Server.IntranetDataDestinationEmail", "???@???.org");

            // The following setting is temporary - until we have created a GUI where users can specify the email address for the
            // responsible Personnel and Finance persons themselves. Those will be stored in SystemDefaults then.
            FIntranetDataSenderEmail = TAppSettingsManager.GetValue("Server.IntranetDataSenderEmail", "???@???.org");

            // Determine network configuration of the Server
            Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses);

            FApplicationVersion = TFileVersionInfo.GetApplicationVersion();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialises the internal variables that hold the Server Settings, using the current config file.
        ///
        /// </summary>
        /// <returns>void</returns>
        public TSrvSetting()
        {
            if (USingletonSrvSetting == null)
            {
                USingletonSrvSetting = this;
            }

            FConfigurationFile = TAppSettingsManager.ConfigFileName;
            FExecutingOS       = Utilities.DetermineExecutingOS();

            // Server.RDBMSType
            FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql"));

            FDatabaseHostOrFile        = TAppSettingsManager.GetValue("Server.DBHostOrFile", "localhost");
            FDatabasePort              = TAppSettingsManager.GetValue("Server.DBPort", "5432");
            FDatabaseName              = TAppSettingsManager.GetValue("Server.DBName", "openpetra");
            FDBUsername                = TAppSettingsManager.GetValue("Server.DBUserName", "petraserver");
            FDBPassword                = TAppSettingsManager.GetValue("Server.DBPassword", string.Empty, false);
            FDBConnectionCheckInterval = TAppSettingsManager.GetInt32("Server.DBConnectionCheckInterval", 0);

            FApplicationBinFolder = TAppSettingsManager.GetValue("Server.ApplicationBinDirectory", string.Empty, false);

            if (FDBPassword == "PG_OPENPETRA_DBPWD")
            {
                // get the password from the file ~/.pgpass. This currently only works for PostgreSQL on Linux
                using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                                                          Path.DirectorySeparatorChar + ".pgpass"))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith(FDatabaseHostOrFile + ":" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":") ||
                            line.StartsWith("*:" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":"))
                        {
                            FDBPassword = line.Substring(line.LastIndexOf(':') + 1);
                            break;
                        }
                    }
                }
            }

            if (TAppSettingsManager.HasValue("Server.LogFile"))
            {
                FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false);
            }
            else
            {
                // maybe the log file has already been set, eg. by the NUnit Server Test
                FServerLogFile = TLogging.GetLogFileName();

                if (FServerLogFile.Length == 0)
                {
                    // this is effectively the bin directory (current directory)
                    FServerLogFile = "Server.log";
                }
            }

            // Server.Port
            FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 9000);

            FRunAsStandalone = TAppSettingsManager.GetBoolean("Server.RunAsStandalone", false);

            // Server.ClientIdleStatusAfterXMinutes
            FClientIdleStatusAfterXMinutes = TAppSettingsManager.GetInt32("Server.ClientIdleStatusAfterXMinutes", 5);

            // Server.ClientKeepAliveCheckIntervalInSeconds
            FClientKeepAliveCheckIntervalInSeconds = TAppSettingsManager.GetInt32("Server.ClientKeepAliveCheckIntervalInSeconds", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_LAN
            FClientKeepAliveTimeoutAfterXSecondsLAN = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_LAN", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_Remote
            FClientKeepAliveTimeoutAfterXSecondsRemote =
                TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_Remote", (ClientKeepAliveTimeoutAfterXSecondsLAN * 2));

            // Server.ClientConnectionTimeoutAfterXSeconds
            FClientConnectionTimeoutAfterXSeconds = TAppSettingsManager.GetInt32("Server.ClientConnectionTimeoutAfterXSeconds", 20);

            // Server.ClientAppDomainShutdownAfterKeepAliveTimeout
            FClientAppDomainShutdownAfterKeepAliveTimeout = TAppSettingsManager.GetBoolean("Server.ClientAppDomainShutdownAfterKeepAliveTimeout",
                                                                                           true);

            FSmtpHost               = TAppSettingsManager.GetValue("SmtpHost", "");
            FSmtpPort               = TAppSettingsManager.GetInt32("SmtpPort", 25);
            FSmtpUser               = TAppSettingsManager.GetValue("SmtpUser", "YourSmtpUser");
            FSmtpPassword           = TAppSettingsManager.GetValue("SmtpPassword", "YourSmtpPassword");
            FSmtpEnableSsl          = TAppSettingsManager.GetBoolean("SmtpEnableSsl", true);
            FSmtpAuthenticationType = TAppSettingsManager.GetValue("SmtpAuthenticationType", "config").ToLower();
            FSmtpIgnoreServerCertificateValidation = TAppSettingsManager.GetBoolean("IgnoreServerCertificateValidation", false);

            // Determine network configuration of the Server
            Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses);

            FApplicationVersion = TFileVersionInfo.GetApplicationVersion();
        }