Пример #1
0
func main() {
	confpath := flag.String("config", "", "readeef config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*confpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *confpath, err))
	}

	if cfg.SearchIndex.BlevePath == "" {
		exitWithError("No bleve-path in search-index section of the config")
	}

	logger := readeef.NewLogger(cfg)
	repo, err := repo.New(cfg.DB.Driver, cfg.DB.Connect, logger)
	if err != nil {
		exitWithError(fmt.Sprintf("Error connecting to database: %v", err))
	}

	si, err := readeef.NewSearchIndex(repo, cfg, logger)

	if err != nil {
		exitWithError(fmt.Sprintf("Error creating search index: %v", err))
	}

	logger.Infoln("Getting all articles")

	if err := si.IndexAllArticles(); err != nil {
		exitWithError(fmt.Sprintf("Error indexing all articles: %v", err))
	}
}
Пример #2
0
func main() {
	serverconfpath := flag.String("server-config", "", "server config path")
	readeefconfpath := flag.String("readeef-config", "", "readeef config path")
	host := flag.String("host", "", "server host")
	port := flag.Int("port", 0, "server port")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*readeefconfpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *readeefconfpath, err))
	}

	server := webfw.NewServer(*serverconfpath)
	if *host != "" {
		server.SetHost(*host)
	}

	if *port > 0 {
		server.SetPort(*port)
	}

	dispatcher := server.Dispatcher("/api/")

	logger := log.New(os.Stderr, "", 0)
	readeef.InitDebug(logger, cfg)

	if err := api.RegisterControllers(cfg, dispatcher, logger); err != nil {
		exitWithError(err.Error())
	}

	dispatcher = server.Dispatcher("/")
	web.RegisterControllers(dispatcher, "/api/")

	if err := server.ListenAndServe(); err != nil {
		exitWithError(fmt.Sprintf("Error starting server: %s\n", err.Error()))
	}
}
Пример #3
0
func main() {
	confpath := flag.String("config", "", "readeef config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*confpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *confpath, err))
	}

	logger := readeef.NewLogger(cfg)
	repo, err := repo.New(cfg.DB.Driver, cfg.DB.Connect, logger)
	if err != nil {
		exitWithError(fmt.Sprintf("Error connecting to database: %v", err))
	}

	var sp content.SearchProvider

	switch cfg.Content.SearchProvider {
	case "elastic":
		if sp, err = search.NewElastic(cfg.Content.ElasticURL, cfg.Content.SearchBatchSize, logger); err != nil {
			exitWithError(fmt.Sprintf("Error initializing Elastic search: %v\n", err))
		}
	case "bleve":
		fallthrough
	default:
		if sp, err = search.NewBleve(cfg.Content.BlevePath, cfg.Content.SearchBatchSize, logger); err != nil {
			exitWithError(fmt.Sprintf("Error initializing Bleve search: %v\n", err))
		}
	}

	logger.Infoln("Getting all articles")

	if err := sp.IndexAllFeeds(repo); err != nil {
		exitWithError(fmt.Sprintf("Error indexing all articles: %v", err))
	}
}
Пример #4
0
func main() {
	confpath := flag.String("config", "", "config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*confpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *confpath, err))
	}

	logger := readeef.NewLogger(cfg)
	repo, err := repo.New(cfg.DB.Driver, cfg.DB.Connect, logger)
	if err != nil {
		exitWithError(fmt.Sprintf("Error connecting to database: %v", err))
	}

	switch flag.Arg(0) {
	case "add":
		if flag.NArg() != 3 {
			exitWithError("Not enough arguments for 'add' command. Login and password must be specified")
		}
		login := flag.Arg(1)
		pass := flag.Arg(2)

		u := repo.User()
		i := u.Data()

		i.Login = data.Login(login)
		i.Active = true

		u.Data(i)

		u.Password(pass, []byte(cfg.Auth.Secret))
		u.Update()

		if u.HasErr() {
			exitWithError(fmt.Sprintf("Error setting password for user '%s': %v", login, u.Err()))
		}
	case "remove":
		if flag.NArg() != 2 {
			exitWithError("Not enough arguments for 'remove' command. Login must be specified")
		}
		login := flag.Arg(1)

		u := repo.UserByLogin(data.Login(login))
		u.Delete()

		if u.HasErr() {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, u.Err()))
		}
	case "get":
		if flag.NArg() != 3 {
			exitWithError("Not enough arguments for 'get' command. Login and user property must be specified")
		}
		login := flag.Arg(1)
		prop := flag.Arg(2)

		u := repo.UserByLogin(data.Login(login))
		if repo.HasErr() {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, repo.Err()))
		}

		lowerProp := strings.ToLower(prop)
		switch lowerProp {
		case "firstname", "first_name":
			fmt.Printf("%s\n", u.Data().FirstName)
		case "lastname", "last_name":
			fmt.Printf("%s\n", u.Data().LastName)
		case "email":
			fmt.Printf("%s\n", u.Data().Email)
		case "hashtype", "hash_type":
			fmt.Printf("%s\n", u.Data().HashType)
		case "salt":
			fmt.Printf("%v\n", u.Data().Salt)
		case "hash":
			fmt.Printf("%v\n", u.Data().Hash)
		case "md5api", "md5_api":
			fmt.Printf("%v\n", u.Data().MD5API)
		case "admin":
			fmt.Printf("%v\n", u.Data().Admin)
		case "active":
			fmt.Printf("%v\n", u.Data().Active)
		default:
			exitWithError(fmt.Sprintf("Unknown user property '%s'", prop))
		}
	case "set":
		if flag.NArg() != 4 {
			exitWithError("Not enough arguments for 'set' command. Login, user property, and value must be specified")
		}
		login := flag.Arg(1)
		prop := flag.Arg(2)
		val := flag.Arg(3)

		u := repo.UserByLogin(data.Login(login))
		if repo.HasErr() {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, repo.Err()))
		}

		in := u.Data()

		lowerProp := strings.ToLower(prop)
		switch lowerProp {
		case "firstname", "first_name":
			in.FirstName = val
		case "lastname", "last_name":
			in.LastName = val
		case "email":
			in.Email = val
		case "password":
			u.Password(val, []byte(cfg.Auth.Secret))
		case "admin", "active":
			enabled := false
			if val == "1" || val == "true" || val == "on" {
				enabled = true
			}
			if lowerProp == "admin" {
				in.Admin = enabled
			} else {
				in.Active = enabled
			}
		default:
			exitWithError(fmt.Sprintf("Unknown user property '%s'", prop))
		}

		u.Update()
		if u.HasErr() {
			exitWithError(fmt.Sprintf("Error updating the user database record for '%s': %v", login, u.Err()))
		}
	case "list":
		users := repo.AllUsers()
		if repo.HasErr() {
			exitWithError(fmt.Sprintf("Error getting users from the database: %v", repo.Err()))
		}

		for _, u := range users {
			fmt.Printf("%s\n", u.Data().Login)
		}
	case "list-detailed":
		users := repo.AllUsers()
		if repo.HasErr() {
			exitWithError(fmt.Sprintf("Error getting users from the database: %v", repo.Err()))
		}

		for _, u := range users {
			in := u.Data()
			fmt.Printf("Login: %s", in.Login)
			if in.FirstName != "" {
				fmt.Printf(", first name: %s", in.FirstName)
			}
			if in.LastName != "" {
				fmt.Printf(", last name: %s", in.LastName)
			}
			if in.Email != "" {
				fmt.Printf(", email: %s", in.Email)
			}
			if in.HashType != "" {
				fmt.Printf(", has type: %s", in.HashType)
			}
			fmt.Printf("\n")
		}
	default:
		exitWithError(fmt.Sprintf("Unknown command '%s'", flag.Arg(0)))
	}
}
Пример #5
0
func main() {
	serverconfpath := flag.String("server-config", "", "server config path")
	readeefconfpath := flag.String("readeef-config", "", "readeef config path")
	address := flag.String("address", "", "local server network address")
	port := flag.Int("port", 0, "server port")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*readeefconfpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *readeefconfpath, err))
	}

	logger := readeef.NewLogger(cfg)
	defer func() {
		if rec := recover(); rec != nil {
			stack := debug.Stack()
			logger.Fatalf("Fatal error: %v\n%s\n", rec, stack)
		}
	}()

	server := webfw.NewServer(*serverconfpath)
	if *address != "" {
		server.Address = *address
	}

	if *port > 0 {
		server.Port = *port
	}

	var accessWriter io.Writer
	if cfg.Logger.AccessFile == "-" {
		accessWriter = os.Stdout
	} else {
		accessWriter = &lumberjack.Logger{
			Filename:   cfg.Logger.AccessFile,
			MaxSize:    20,
			MaxBackups: 5,
			MaxAge:     28,
		}
	}

	accessLogger := webfw.NewStandardLogger(accessWriter, "", 0)

	dispatcher := server.Dispatcher("/api/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	if err := api.RegisterControllers(cfg, dispatcher, logger); err != nil {
		exitWithError(err.Error())
	}

	dispatcher = server.Dispatcher("/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	web.RegisterControllers(cfg, dispatcher, "/api/")

	if err := server.ListenAndServe(); err != nil {
		exitWithError(fmt.Sprintf("Error starting server: %s\n", err.Error()))
	}
}
Пример #6
0
func main() {
	confpath := flag.String("config", "", "config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*confpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *confpath, err))
	}

	db := readeef.NewDB(cfg.DB.Driver, cfg.DB.Connect)
	if err := db.Connect(); err != nil {
		exitWithError(fmt.Sprintf("Error connecting to database: %v", err))
	}

	switch flag.Arg(0) {
	case "add":
		if flag.NArg() != 3 {
			exitWithError("Not enough arguments for 'add' command. Login and password must be specified")
		}
		login := flag.Arg(1)
		pass := flag.Arg(2)

		u := readeef.User{Login: login, Active: true}
		if err := u.SetPassword(pass); err != nil {
			exitWithError(fmt.Sprintf("Error setting password for user '%s': %v", login, err))
		}

		if err := db.UpdateUser(u); err != nil {
			exitWithError(fmt.Sprintf("Error updating the user database record for '%s': %v", login, err))
		}
	case "remove":
		if flag.NArg() != 2 {
			exitWithError("Not enough arguments for 'remove' command. Login must be specified")
		}
		login := flag.Arg(1)

		u, err := db.GetUser(login)
		if err != nil {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, err))
		}

		if err := db.DeleteUser(u); err != nil {
			exitWithError(fmt.Sprintf("Error removing user '%s' from the database: %v", login, err))
		}
	case "get":
		if flag.NArg() != 3 {
			exitWithError("Not enough arguments for 'get' command. Login and user property must be specified")
		}
		login := flag.Arg(1)
		prop := flag.Arg(2)

		u, err := db.GetUser(login)
		if err != nil {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, err))
		}

		lowerProp := strings.ToLower(prop)
		switch lowerProp {
		case "firstname", "first_name":
			fmt.Printf("%s\n", u.FirstName)
		case "lastname", "last_name":
			fmt.Printf("%s\n", u.LastName)
		case "email":
			fmt.Printf("%s\n", u.Email)
		case "hashtype", "hash_type":
			fmt.Printf("%s\n", u.HashType)
		case "salt":
			fmt.Printf("%v\n", u.Salt)
		case "hash":
			fmt.Printf("%v\n", u.Hash)
		case "md5api", "md5_api":
			fmt.Printf("%v\n", u.MD5API)
		case "admin":
			fmt.Printf("%v\n", u.Admin)
		case "active":
			fmt.Printf("%v\n", u.Active)
		default:
			exitWithError(fmt.Sprintf("Unknown user property '%s'", prop))
		}
	case "set":
		if flag.NArg() != 4 {
			exitWithError("Not enough arguments for 'update' command. Login, user property, and value must be specified")
		}
		login := flag.Arg(1)
		prop := flag.Arg(2)
		val := flag.Arg(3)

		u, err := db.GetUser(login)
		if err != nil {
			exitWithError(fmt.Sprintf("Error getting user '%s' from the database: %v", login, err))
		}

		lowerProp := strings.ToLower(prop)
		switch lowerProp {
		case "firstname", "first_name":
			u.FirstName = val
		case "lastname", "last_name":
			u.LastName = val
		case "email":
			u.Email = val
		case "password":
			if err := u.SetPassword(val); err != nil {
				exitWithError(fmt.Sprintf("Error setting password for user '%s': %v", u.Login, err))
			}
		case "admin", "active":
			enabled := false
			if val == "1" || val == "true" || val == "on" {
				enabled = true
			}
			if lowerProp == "admin" {
				u.Admin = enabled
			} else {
				u.Active = enabled
			}
		default:
			exitWithError(fmt.Sprintf("Unknown user property '%s'", prop))
		}

		if err := db.UpdateUser(u); err != nil {
			exitWithError(fmt.Sprintf("Error updating the user database record for '%s': %v", login, err))
		}
	case "list":
		users, err := db.GetUsers()
		if err != nil {
			exitWithError(fmt.Sprintf("Error getting users from the database: %v", err))
		}

		for _, u := range users {
			fmt.Printf("%s\n", u.Login)
		}
	case "list-detailed":
		users, err := db.GetUsers()
		if err != nil {
			exitWithError(fmt.Sprintf("Error getting users from the database: %v", err))
		}

		for _, u := range users {
			fmt.Printf("Login: %s", u.Login)
			if u.FirstName != "" {
				fmt.Printf(", first name: %s", u.FirstName)
			}
			if u.LastName != "" {
				fmt.Printf(", last name: %s", u.LastName)
			}
			if u.Email != "" {
				fmt.Printf(", email: %s", u.Email)
			}
			if u.HashType != "" {
				fmt.Printf(", has type: %s", u.HashType)
			}
			fmt.Printf("\n")
		}
	default:
		exitWithError(fmt.Sprintf("Unknown command '%s'", flag.Arg(0)))
	}
}
Пример #7
0
func main() {
	configpath := flag.String("config", "", "readeef config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*configpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *configpath, err))
	}

	if len(cfg.Config.Session.IgnoreURLPrefix) == 0 {
		cfg.Config.Session.IgnoreURLPrefix = []string{"/v2/fever", "/v12/tt-rss"}
	}
	if len(cfg.Config.I18n.Languages) == 0 {
		cfg.Config.I18n.Languages = []string{"en", "bg"}
	}
	if len(cfg.Config.I18n.IgnoreURLPrefix) == 0 {
		cfg.Config.I18n.IgnoreURLPrefix = []string{"/dist", "/js", "/css", "/images", "/proxy"}
	}

	logger := readeef.NewLogger(cfg)
	defer func() {
		if rec := recover(); rec != nil {
			stack := debug.Stack()
			logger.Fatalf("Fatal error: %v\n%s\n", rec, stack)
		}
	}()

	server := webfw.NewServerWithConfig(cfg.Config)

	var accessWriter io.Writer
	if cfg.Logger.AccessFile == "-" {
		accessWriter = os.Stdout
	} else {
		accessWriter = &lumberjack.Logger{
			Filename:   cfg.Logger.AccessFile,
			MaxSize:    20,
			MaxBackups: 5,
			MaxAge:     28,
		}
	}

	accessLogger := webfw.NewStandardLogger(accessWriter, "", 0)

	dispatcher := server.Dispatcher("/api/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	if err := api.RegisterControllers(cfg, dispatcher, logger); err != nil {
		exitWithError(err.Error())
	}

	dispatcher = server.Dispatcher("/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	web.RegisterControllers(cfg, dispatcher, "/api/")

	if err := server.ListenAndServe(); err != nil {
		exitWithError(fmt.Sprintf("Error starting server: %s\n", err.Error()))
	}
}