Exemple #1
0
        public void Start(string use_backend = "sqlite")
        {
            tmpPath = "/tmp/rainy-test-data/";
            Directory.CreateDirectory(tmpPath);
            DbConfig.SetSqliteFile(Path.Combine(tmpPath, "rainy-test.db"));
            // tmpPath = Path.GetTempPath () + Path.GetRandomFileName ();

            IDataBackend backend;

            if (use_backend == "sqlite")
            {
                backend = new DatabaseBackend(tmpPath, credentialsVerifier);
                DbConfig.CreateSchema(reset: true);
                using (var c = DbConfig.GetConnection()) {
                    c.Insert <DBUser>(new DBUser()
                    {
                        Username = TEST_USER
                    });
                }
            }
            else
            {
                backend = new RainyFileSystemBackend(tmpPath, credentialsVerifier);
            }

            rainyServer = new RainyStandaloneServer(backend, RainyListenUrl);

            rainyServer.Start();
        }
Exemple #2
0
        public RainyTestServer(ComposeObjectGraphDelegate composer = null)
        {
            if (composer == null)
            {
                // specifies which default scenario to use
                this.ScenarioSqlite();
            }

            rainyServer = new RainyStandaloneServer(ListenUrl, (c) => {
                if (this.ObjectGraphComposer == null)
                {
                    throw new Exception("need to setup a composer/scenario for RainyTestServer!");
                }
                this.ObjectGraphComposer(c);
            });
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            // parse command line arguments
            string config_file = "settings.conf";
            string cert_file = null, pvk_file = null;

            int  loglevel     = 0;
            bool show_help    = false;
            bool open_browser = true;

            var p = new OptionSet()
            {
                { "c|config=", "use config file",
                  (string file) => config_file = file },
                { "v", "increase log level, where -vvvv is highest",
                  v => { if (v != null)
                         {
                             ++loglevel;
                         }
                  } },
                { "h|help", "show this message and exit",
                  v => show_help = v != null },
                { "cert=", "use this certificate for SSL",
                  (string file) => cert_file = file },
                { "pvk=", "use private key for certSSL",
                  (string file2) => pvk_file = file2 },

                { "b|nobrowser", "do not open browser window upon start",
                  v => { if (v != null)
                         {
                             open_browser = false;
                         }
                  } },
            };

            p.Parse(args);

            if (show_help)
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            if (!File.Exists(config_file))
            {
                Console.WriteLine("Could not find a configuration file (try the -c flag)!");
                return;
            }

            // set the configuration from the specified file
            Config.Global = Config.ApplyJsonFromPath(config_file);

            DataPath = Config.Global.DataPath;
            if (string.IsNullOrEmpty(DataPath))
            {
                DataPath = Directory.GetCurrentDirectory();
            }
            else
            {
                if (!Directory.Exists(DataPath))
                {
                    Directory.CreateDirectory(DataPath);
                }
            }
            SetupLogging(loglevel);
            logger = LogManager.GetLogger("Main");

            string listen_url = Config.Global.ListenUrl;

            if (string.IsNullOrEmpty(listen_url))
            {
                listen_url = "https://localhost:443/";
                logger.InfoFormat("no ListenUrl set in the settings.conf, using the default: {0}",
                                  listen_url);
            }
            // servicestack expects trailing slash, else error is thrown
            if (!listen_url.EndsWith("/"))
            {
                listen_url += "/";
            }

            ConfigureSslCerts(listen_url, cert_file, pvk_file);

            // by default we use the filesystem backend
            if (string.IsNullOrEmpty(Config.Global.Backend))
            {
                Config.Global.Backend = "filesystem";
            }

            if (Config.Global.Backend != "filesystem" && string.IsNullOrEmpty(Config.Global.AdminPassword))
            {
                logger.Fatal("An administrator password must be set");
                Environment.Exit(-1);
            }

            open_browser = open_browser && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DISPLAY"));
            open_browser = open_browser && !string.IsNullOrEmpty(Config.Global.AdminPassword);
            open_browser = open_browser && Config.Global.Backend != "filesystem";
            string admin_ui_url = listen_url.Replace("*", "localhost");

            admin_ui_url += "admin/";

            ComposeObjectGraphDelegate object_graph_composer = ComposeObjectGraph;

            using (var listener = new RainyStandaloneServer(Config.Global.ListenUrl, object_graph_composer)) {
                listener.Start();
                Uptime = DateTime.UtcNow;

                if (open_browser)
                {
                    Process.Start(admin_ui_url);
                }

                if (Environment.OSVersion.Platform != PlatformID.Unix &&
                    Environment.OSVersion.Platform != PlatformID.MacOSX)
                {
                    // we run on windows, can't wait for unix signals
                    Console.WriteLine("Press return to stop Rainy");
                    Console.ReadLine();
                    Environment.Exit(0);
                }
                else
                {
                    // we run UNIX
                    UnixSignal [] signals = new UnixSignal[] {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGTERM),
                    };

                    // Wait for a unix signal
                    for (bool exit = false; !exit;)
                    {
                        int id = UnixSignal.WaitAny(signals);

                        if (id >= 0 && id < signals.Length)
                        {
                            if (signals[id].IsSet)
                            {
                                exit = true;
                            }
                            logger.Debug("received signal, exiting");
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void Start(string use_backend = "sqlite")
        {
            tmpPath = "/tmp/rainy-test-data/";
            Directory.CreateDirectory (tmpPath);
            DbConfig.SetSqliteFile (Path.Combine (tmpPath, "rainy-test.db"));
            // tmpPath = Path.GetTempPath () + Path.GetRandomFileName ();

            IDataBackend backend;
            if (use_backend == "sqlite") {
                backend = new DatabaseBackend (tmpPath, credentialsVerifier);
                DbConfig.CreateSchema(reset: true);
                using (var c = DbConfig.GetConnection ()) {
                    c.Insert<DBUser>(new DBUser() { Username = TEST_USER });
                }
            }
            else
                backend = new RainyFileSystemBackend (tmpPath, credentialsVerifier);

            rainyServer = new RainyStandaloneServer (backend, RainyListenUrl);

            rainyServer.Start ();
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            // parse command line arguments
            string config_file = "settings.conf";
            string cert_file = null, pvk_file = null;

            int loglevel = 0;
            bool show_help = false;
            bool open_browser = true;

            var p = new OptionSet () {
                { "c|config=", "use config file",
                    (string file) => config_file = file },
                { "v", "increase log level, where -vvvv is highest",
                    v => { if (v != null) ++loglevel; } },
                { "h|help",  "show this message and exit",
                    v => show_help = v != null },
                { "cert=",  "use this certificate for SSL",
                    (string file) => cert_file = file },
                { "pvk=",  "use private key for certSSL",
                    (string file2) => pvk_file = file2 },

                { "b|nobrowser",  "do not open browser window upon start",
                    v => { if (v != null) open_browser = false; } },
            };
            p.Parse (args);

            if (show_help) {
                p.WriteOptionDescriptions (Console.Out);
                return;
            }

            if (!File.Exists (config_file)) {
                Console.WriteLine ("Could not find a configuration file (try the -c flag)!");
                return;
            }

            // set the configuration from the specified file
            Config.Global = Config.ApplyJsonFromPath (config_file);

            DataPath = Config.Global.DataPath;
            if (string.IsNullOrEmpty (DataPath)) {
                DataPath = Directory.GetCurrentDirectory ();
            } else {
                if (!Directory.Exists (DataPath))
                    Directory.CreateDirectory (DataPath);
            }
            SetupLogging (loglevel);
            logger = LogManager.GetLogger ("Main");

            string listen_url = Config.Global.ListenUrl;
            if (string.IsNullOrEmpty (listen_url)) {
                listen_url = "https://localhost:443/";
                logger.InfoFormat ("no ListenUrl set in the settings.conf, using the default: {0}",
                                   listen_url);
            }
            // servicestack expects trailing slash, else error is thrown
            if (!listen_url.EndsWith ("/")) listen_url += "/";

            ConfigureSslCerts (listen_url, cert_file, pvk_file);

            // by default we use the filesystem backend
            if (string.IsNullOrEmpty (Config.Global.Backend)) {
                Config.Global.Backend = "filesystem";
            }

            if (Config.Global.Backend != "filesystem" && string.IsNullOrEmpty (Config.Global.AdminPassword)) {
                logger.Fatal ("An administrator password must be set");
                Environment.Exit (-1);
            }

            open_browser = open_browser && !string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("DISPLAY"));
            open_browser = open_browser && !string.IsNullOrEmpty (Config.Global.AdminPassword);
            open_browser = open_browser && Config.Global.Backend != "filesystem";
            string admin_ui_url = listen_url.Replace ("*", "localhost");
            admin_ui_url += "admin/";

            ComposeObjectGraphDelegate object_graph_composer = ComposeObjectGraph;

            using (var listener = new RainyStandaloneServer (Config.Global.ListenUrl, object_graph_composer)) {

                listener.Start ();
                Uptime = DateTime.UtcNow;

                if (open_browser) {
                    Process.Start (admin_ui_url);
                }

                if (Environment.OSVersion.Platform != PlatformID.Unix &&
                    Environment.OSVersion.Platform != PlatformID.MacOSX) {
                    // we run on windows, can't wait for unix signals
                    Console.WriteLine ("Press return to stop Rainy");
                    Console.ReadLine ();
                    Environment.Exit(0);
                } else {
                    // we run UNIX
                    UnixSignal [] signals = new UnixSignal[] {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGTERM),
                    };

                    // Wait for a unix signal
                    for (bool exit = false; !exit; )
                    {
                        int id = UnixSignal.WaitAny(signals);

                        if (id >= 0 && id < signals.Length)
                        {
                            if (signals[id].IsSet) exit = true;
                            logger.Debug ("received signal, exiting");
                        }
                    }
                }
            }
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            // parse command line arguments
            string config_file = "settings.conf";
            string cert_file = null, pvk_file = null;

            int  loglevel     = 0;
            bool show_help    = false;
            bool open_browser = false;

            var p = new OptionSet()
            {
                { "c|config=", "use config file",
                  (string file) => config_file = file },
                { "v", "increase log level, where -vvvv is highest",
                  v => { if (v != null)
                         {
                             ++loglevel;
                         }
                  } },
                { "h|help", "show this message and exit",
                  v => show_help = v != null },
                { "cert=", "use this certificate for SSL",
                  (string file) => cert_file = file },
                { "pvk=", "use private key for certSSL",
                  (string file2) => pvk_file = file2 },

                //{ "b|nobrowser",  "do not open browser window upon start",
                //	v => { if (v != null) open_browser = false; } },
            };

            p.Parse(args);

            if (show_help)
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            if (!File.Exists(config_file))
            {
                Console.WriteLine("Could not find a configuration file (try the -c flag)!");
                return;
            }

            // set the configuration from the specified file
            Config.Global = Config.ApplyJsonFromPath(config_file);

            DataPath = Config.Global.DataPath;
            if (string.IsNullOrEmpty(DataPath))
            {
                DataPath = Directory.GetCurrentDirectory();
            }
            else
            {
                if (!Directory.Exists(DataPath))
                {
                    Directory.CreateDirectory(DataPath);
                }
            }

            var sqlite_file = Path.Combine(DataPath, "rainy.db");

            DbConfig.SetSqliteFile(sqlite_file);

            SetupLogging(loglevel);
            logger = LogManager.GetLogger("Main");

            string listen_url = Config.Global.ListenUrl;

            if (string.IsNullOrEmpty(listen_url))
            {
                listen_url = "https://localhost:443/";
                logger.InfoFormat("no ListenUrl set in the settings.conf, using the default: {0}",
                                  listen_url);
            }
            // servicestack expects trailing slash, else error is thrown
            if (!listen_url.EndsWith("/"))
            {
                listen_url += "/";
            }

            ConfigureSslCerts(listen_url, cert_file, pvk_file);

            // determine and setup data backend
            string backend = Config.Global.Backend;

            IDataBackend data_backend;
            // simply use user/password list from config for authentication
            CredentialsVerifier config_authenticator = (username, password) => {
                // call the authenticater callback
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    return(false);
                }

                foreach (dynamic credentials in Config.Global.Users)
                {
                    if (credentials.Username == username && credentials.Password == password)
                    {
                        return(true);
                    }
                }
                return(false);
            };

            // by default we use the filesystem backend
            if (string.IsNullOrEmpty(backend))
            {
                backend = "filesystem";
            }

            if (backend == "sqlite")
            {
                /* if (string.IsNullOrEmpty (Config.Global.AdminPassword)) {
                 *      Console.WriteLine ("FATAL: Field 'AdminPassword' in the settings config may not " +
                 *                         "be empty when using the sqlite backend");
                 *      return;
                 * } */
                data_backend = new DatabaseBackend(DataPath, config_authenticator);
            }
            else
            {
                data_backend = new RainyFileSystemBackend(DataPath, config_authenticator);
            }

            string admin_ui_url = listen_url.Replace("*", "localhost");

            if (open_browser)
            {
                admin_ui_url += "admin/#?admin_pw=" + Config.Global.AdminPassword;
            }

            using (var listener = new RainyStandaloneServer(data_backend, listen_url)) {
                listener.Start();
                Uptime = DateTime.UtcNow;

                if (open_browser)
                {
                    Process.Start(admin_ui_url);
                }

                if (Environment.OSVersion.Platform != PlatformID.Unix &&
                    Environment.OSVersion.Platform != PlatformID.MacOSX)
                {
                    // we run on windows, can't wait for unix signals
                    Console.WriteLine("Press return to stop Rainy");
                    Console.ReadLine();
                    Environment.Exit(0);
                }
                else
                {
                    // we run UNIX
                    UnixSignal [] signals = new UnixSignal[] {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGTERM),
                    };

                    // Wait for a unix signal
                    for (bool exit = false; !exit;)
                    {
                        int id = UnixSignal.WaitAny(signals);

                        if (id >= 0 && id < signals.Length)
                        {
                            if (signals[id].IsSet)
                            {
                                exit = true;
                            }
                            logger.Debug("received signal, exiting");
                        }
                    }
                }
            }
        }
Exemple #7
0
        public RainyTestServer(ComposeObjectGraphDelegate composer = null)
        {
            if (composer == null) {
                // specifies which default scenario to use
                this.ScenarioSqlite ();
            }

            rainyServer = new RainyStandaloneServer (ListenUrl, (c) => {
                if (this.ObjectGraphComposer == null)
                    throw new Exception ("need to setup a composer/scenario for RainyTestServer!");
                this.ObjectGraphComposer(c);
            });
        }
Exemple #8
0
        public static void StartNewServer(string use_backend = "sqlite")
        {
            tmpPath = "/tmp/rainy-test-data/";
            if (Directory.Exists (tmpPath)) {
                Directory.Delete (tmpPath, true);
            }
            Directory.CreateDirectory (tmpPath);
            DbConfig.SetSqliteFile (Path.Combine (tmpPath, "rainy-test.db"));
            // tmpPath = Path.GetTempPath () + Path.GetRandomFileName ();

            // for debugging, we only use a simple single user authentication
            CredentialsVerifier debug_authenticator = (user,pass) => {
                if (user == TEST_USER  && pass == TEST_PASS) return true;
                else return false;
            };

            IDataBackend backend;
            if (use_backend == "sqlite")
                backend = new DatabaseBackend (tmpPath, auth: debug_authenticator, reset: true);
            else
                backend = new RainyFileSystemBackend (tmpPath, debug_authenticator);

            rainyServer = new RainyStandaloneServer (backend, RainyListenUrl, test_server: true);

            rainyServer.Start ();
        }
Exemple #9
0
        public static void Main(string[] args)
        {
            // parse command line arguments
            string config_file = "settings.conf";
            string cert_file = null, pvk_file = null;

            int loglevel = 0;
            bool show_help = false;
            bool open_browser = false;

            var p = new OptionSet () {
                { "c|config=", "use config file",
                    (string file) => config_file = file },
                { "v", "increase log level, where -vvvv is highest",
                    v => { if (v != null) ++loglevel; } },
                { "h|help",  "show this message and exit",
                    v => show_help = v != null },
                { "cert=",  "use this certificate for SSL",
                    (string file) => cert_file = file },
                { "pvk=",  "use private key for certSSL",
                    (string file2) => pvk_file = file2 },

                //{ "b|nobrowser",  "do not open browser window upon start",
                //	v => { if (v != null) open_browser = false; } },
            };
            p.Parse (args);

            if (show_help) {
                p.WriteOptionDescriptions (Console.Out);
                return;
            }

            if (!File.Exists (config_file)) {
                Console.WriteLine ("Could not find a configuration file (try the -c flag)!");
                return;
            }

            // set the configuration from the specified file
            Config.Global = Config.ApplyJsonFromPath (config_file);

            DataPath = Config.Global.DataPath;
            if (string.IsNullOrEmpty (DataPath)) {
                DataPath = Directory.GetCurrentDirectory ();
            } else {
                if (!Directory.Exists (DataPath))
                    Directory.CreateDirectory (DataPath);
            }

            var sqlite_file = Path.Combine (DataPath, "rainy.db");
            DbConfig.SetSqliteFile (sqlite_file);

            SetupLogging (loglevel);
            logger = LogManager.GetLogger ("Main");

            string listen_url = Config.Global.ListenUrl;
            if (string.IsNullOrEmpty (listen_url)) {
                listen_url = "https://localhost:443/";
                logger.InfoFormat ("no ListenUrl set in the settings.conf, using the default: {0}",
                                   listen_url);
            }
            // servicestack expects trailing slash, else error is thrown
            if (!listen_url.EndsWith ("/")) listen_url += "/";

            ConfigureSslCerts (listen_url, cert_file, pvk_file);

            // determine and setup data backend
            string backend = Config.Global.Backend;

            IDataBackend data_backend;
            // simply use user/password list from config for authentication
            CredentialsVerifier config_authenticator = (username, password) => {
                // call the authenticater callback
                if (string.IsNullOrEmpty (username) || string.IsNullOrEmpty (password))
                return false;

                foreach (dynamic credentials in Config.Global.Users) {
                    if (credentials.Username == username && credentials.Password == password)
                        return true;
                }
                return false;
            };
            // by default we use the filesystem backend
            if (string.IsNullOrEmpty (backend)) {
                backend = "filesystem";
            }

            if (backend == "sqlite") {

                /* if (string.IsNullOrEmpty (Config.Global.AdminPassword)) {
                    Console.WriteLine ("FATAL: Field 'AdminPassword' in the settings config may not " +
                                       "be empty when using the sqlite backend");
                    return;
                } */
                data_backend = new DatabaseBackend (DataPath, config_authenticator);
            } else {

                data_backend = new RainyFileSystemBackend (DataPath, config_authenticator);
            }

            string admin_ui_url = listen_url.Replace ("*", "localhost");

            if (open_browser) {
                admin_ui_url += "admin/#?admin_pw=" + Config.Global.AdminPassword;
            }

            using (var listener = new RainyStandaloneServer (data_backend, listen_url)) {

                listener.Start ();
                Uptime = DateTime.UtcNow;

                if (open_browser) {
                    Process.Start (admin_ui_url);
                }

                if (Environment.OSVersion.Platform != PlatformID.Unix &&
                    Environment.OSVersion.Platform != PlatformID.MacOSX) {
                    // we run on windows, can't wait for unix signals
                    Console.WriteLine ("Press return to stop Rainy");
                    Console.ReadLine ();
                    Environment.Exit(0);

                } else {
                    // we run UNIX
                    UnixSignal [] signals = new UnixSignal[] {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGTERM),
                    };

                    // Wait for a unix signal
                    for (bool exit = false; !exit; )
                    {
                        int id = UnixSignal.WaitAny(signals);

                        if (id >= 0 && id < signals.Length)
                        {
                            if (signals[id].IsSet) exit = true;
                            logger.Debug ("received signal, exiting");
                        }
                    }
                }
            }
        }