Exemple #1
0
        public OAuthDatabaseHandler(CredentialsVerifier auth) : base(auth)
        {
            AccessTokens = new DbAccessTokenRepository <AccessToken> ();
            TokenStore   = new Rainy.OAuth.SimpleStore.SimpleTokenStore(AccessTokens, RequestTokens);

            SetupInspectors();
        }
Exemple #2
0
        public OAuthDatabaseHandler(CredentialsVerifier auth)
            : base(auth)
        {
            AccessTokens = new DbAccessTokenRepository<AccessToken> ();
            TokenStore = new Rainy.OAuth.SimpleStore.SimpleTokenStore (AccessTokens, RequestTokens);

            SetupInspectors ();
        }
Exemple #3
0
        public DatabaseBackend(string database_path, CredentialsVerifier auth = null)
        {
            if (auth == null)
                oauthHandler = new OAuthDatabaseHandler (DbAuthenticator);
            else
                oauthHandler = new OAuthDatabaseHandler (auth);

            DbConfig.CreateSchema ();
        }
Exemple #4
0
        public OAuthHandlerBase(CredentialsVerifier auth)
        {
            Authenticator = auth;

            ConsumerStore = new RainyConsumerStore ();
            NonceStore = new TestNonceStore ();
            // initialize those classes that are not persisted
            // TODO request tokens should be persisted in the future
            RequestTokens = new SimpleTokenRepository<RequestToken> ();
        }
Exemple #5
0
        public OAuthHandlerBase(CredentialsVerifier auth)
        {
            Authenticator = auth;

            ConsumerStore = new RainyConsumerStore();
            NonceStore    = new TestNonceStore();
            // initialize those classes that are not persisted
            // TODO request tokens should be persisted in the future
            RequestTokens = new SimpleTokenRepository <RequestToken> ();
        }
Exemple #6
0
        public RainyFileSystemBackend(string data_path, CredentialsVerifier auth, bool reset = false)
        {
            oauthHandler = new OAuthDatabaseHandler (auth);

            // TODO move this into the oauth stuff
            DbConfig.CreateSchema ();

            this.notesBasePath = Path.Combine (data_path, "notes");
            if (!Directory.Exists (notesBasePath)) {
                Directory.CreateDirectory (notesBasePath);
            }
        }
Exemple #7
0
 public RainyTestServer(CredentialsVerifier verifier = null)
 {
     // for debugging, we only use a simple single user authentication
     if (verifier == null) {
         credentialsVerifier = (user,pass) => {
             if (user == TEST_USER  && pass == TEST_PASS) return true;
             else return false;
         };
     }
     else {
         credentialsVerifier = verifier;
     }
 }
Exemple #8
0
        public DatabaseBackend(string database_path, CredentialsVerifier auth = null)
        {
            if (auth == null)
            {
                oauthHandler = new OAuthDatabaseHandler(DbAuthenticator);
            }
            else
            {
                oauthHandler = new OAuthDatabaseHandler(auth);
            }

            DbConfig.CreateSchema();
        }
Exemple #9
0
        public RainyFileSystemBackend(string data_path, CredentialsVerifier auth, bool reset = false)
        {
            oauthHandler = new OAuthDatabaseHandler(auth);

            // TODO move this into the oauth stuff
            DbConfig.CreateSchema();

            this.notesBasePath = Path.Combine(data_path, "notes");
            if (!Directory.Exists(notesBasePath))
            {
                Directory.CreateDirectory(notesBasePath);
            }
        }
Exemple #10
0
 public RainyTestServer(CredentialsVerifier verifier = null)
 {
     // for debugging, we only use a simple single user authentication
     if (verifier == null)
     {
         credentialsVerifier = (user, pass) => {
             if (user == TEST_USER && pass == TEST_PASS)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         };
     }
     else
     {
         credentialsVerifier = verifier;
     }
 }
Exemple #11
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");
                        }
                    }
                }
            }
        }