Beispiel #1
0
func showUserInfo(uid string) {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	user := md.AdminGetUserInfoByID(uid)
	if user == nil {
		fmt.Println("User Not Found")
		return
	}

	fmt.Println("User info:")
	fmt.Println("ID:", uid)
	fmt.Println("Enabled:", user.Enabled)
	fmt.Println("Registered TS:", user.RegTs)
	fmt.Println("Registered IP:", user.RegIP)
	fmt.Println("Activity Logs:")

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, '\t', 0)
	fmt.Fprintln(w, "Timestamp\tType\tDescripton")
	fmt.Fprintln(w, "---------\t----\t----------")

	for _, lines := range user.GetAllActivity() {
		for _, line := range lines {
			fmt.Fprintf(
				w,
				"%d\t%s\t%s\n",
				line.Ts,
				line.LogType,
				line.Desc)
		}
	}
	w.Flush()
}
Beispiel #2
0
func listUsers() {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, '\t', 0)
	fmt.Fprintln(w, "Uid\tEnabled\tRegTs\tRegIP\tLogLines")
	fmt.Fprintln(w, "---\t-------\t-----\t-----\t--------")

	for uid, user := range md.GetRegisteredUsers() {
		lines := 0
		for _, v := range user.GetAllActivity() {
			lines += len(v)
		}
		fmt.Fprintf(
			w,
			"%s\t%s\t%d\t%s\t%d\n",
			uid,
			user.Enabled,
			user.RegTs,
			user.RegIP,
			lines)
	}
	w.Flush()
}
Beispiel #3
0
func addUser(cmdUsersAddUID string, cmdUsersAddKey string) {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	if _, err := md.RegisterUser(cmdUsersAddUID, cmdUsersAddKey, "127.0.0.1"); err != nil {
		fmt.Println("Problem trying to register the user:"******"User registered")
	}
}
Beispiel #4
0
func main() {
	if len(os.Args) > 1 {
		cfg.Init("pit", os.Args[1])

		log.SetLogger(
			log.Levels[cfg.GetStr("logger", "level")],
			cfg.GetStr("logger", "log_file"),
			cfg.GetInt("logger", "max_log_size_mb"),
		)
	} else {
		cfg.Init("pit", "dev")
	}
	runtime.GOMAXPROCS(runtime.NumCPU())

	usersModel := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	accountsManager := accountsmanager.Init(
		cfg.GetStr("rec-api", "base-url"),
		cfg.GetStr("mail", "addr"),
		cfg.GetStr("mail", "server"),
		cfg.GetInt("mail", "port"),
		usersModel)

	shardsManager := shardsmanager.Init(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		cfg.GetStr("aws", "s3-backups-path"),
		int(cfg.GetInt("rec-api", "port")),
		usersModel,
		cfg.GetStr("mail", "addr"))

	api.Init(
		shardsManager,
		accountsManager,
		cfg.GetStr("rec-api", "static"),
		int(cfg.GetInt("rec-api", "port")),
		int(cfg.GetInt("rec-api", "ssl-port")),
		cfg.GetStr("rec-api", "ssl-cert"),
		cfg.GetStr("rec-api", "ssl-key"))

	log.Info("System started...")
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
	// Block until a signal is received.
	<-c

	log.Info("Stopping all the services")
	shardsManager.Stop()
}
Beispiel #5
0
func enableUser(uid string) {
	fmt.Println("The user with user ID:", uid, "will be enabled")
	if askForConfirmation() {
		md := users.GetModel(
			cfg.GetStr("aws", "prefix"),
			cfg.GetStr("aws", "region"))

		user := md.AdminGetUserInfoByID(uid)
		if user != nil {
			user.EnableUser()
			fmt.Println("User Enabled")
		} else {
			fmt.Println("User not found")
		}
	}
}