Пример #1
0
func main() {
	logger := log.New(os.Stdout, "[HashDBServer] ", log.LstdFlags)

	logger.Println("[*] Initializing Hash-Database")
	hashMix, err := hashdb.OpenMix("db", 10)
	if err != nil {
		logger.Println("Error initializing HashMix:", err)
		return
	}
	ghh, err := NewGetHashHandler(hashMix, logger)
	if err != nil {
		logger.Println("Error initializing GetHashHandler:", err)
		return
	}
	phh, err := NewPutHashHandler(hashMix, logger)
	if err != nil {
		logger.Println("Error initializing PutHashHandler:", err)
		return
	}

	logger.Println("[*] Waiting for clients...")
	http.Handle("/md5", ghh)
	http.Handle("/sha1", ghh)
	http.Handle("/new", phh)
	// Redirect all other requests to...
	http.Handle("/", http.RedirectHandler("https://github.com/marpie/hashdb", 301))

	http.ListenAndServe(":8080", nil)
}
Пример #2
0
func main() {
	if len(os.Args) < 3 {
		Usage()
		return
	}

	outputDirectory := os.Args[1]
	inputFilename := os.Args[2]

	if !DirectoryExists(outputDirectory) || !FileExists(inputFilename) {
		Usage()
		return
	}

	println("[*] Initializing Import...")
	mix, err := hashdb.OpenMix("db", 1)
	if err != nil {
		println("Error initializing database:", err)
		syscall.Exit(1)
	}

	resultChan := make(chan bool, 1)
	passes := make(chan string, 1)

	go DatabaseImport(mix, passes, resultChan)

	println("[*] Import started...")
	if err := ReadFileByLine(inputFilename, passes); err != nil {
		println("Error while importing:", err)
		syscall.Exit(1)
		return
	}

	go StatusUpdate(mix)

	if err := <-resultChan; !err {
		println("Error while importing to database:", err)
		syscall.Exit(1)
		return
	}

	println("[X] Done.")
}