Beispiel #1
0
func NewTestNode(name string, port uint16) *DataMgr {
	base := base.NewBase(name, port)
	link := link.NewLinkMgr(base)
	sync := sync.NewSyncMgr(link)
	meta := meta.NewMetaMgr(sync)
	data := NewDataMgr("/tmp/wtf/"+name, meta)
	data.Run()
	return data
}
Beispiel #2
0
func NewTestNode(name string, linkPort uint16, apiPort uint16) *ApiMgr {
	base := base.NewBase(name, linkPort)
	link := link.NewLinkMgr(base)
	sync := sync.NewSyncMgr(link)
	meta := meta.NewMetaMgr(sync)
	data := data.NewDataMgr("/tmp/data/"+name, meta)
	api := NewApiMgr("localhost", linkPort, apiPort, data)
	api.Run()
	return api
}
Beispiel #3
0
func NewTestNode(name string, port uint16) *TestNode {
	base := base.NewBase(name, port)
	link := link.NewLinkMgr(base)
	sync := sync.NewSyncMgr(link)
	meta := NewMetaMgr(sync)

	tn := &TestNode{
		id:   base.Ident,
		port: base.Port,
		log:  base.Log,
		link: link,
		sync: sync,
		meta: meta,
	}
	tn.meta.Run()
	return tn
}
Beispiel #4
0
func main() {
	user, err := user.Current()
	if err != nil {
		fatal("Current user is invalid", err)
	}

	defaultDir := path.Join(user.HomeDir, DefaultDir)

	dir := flag.String("d", defaultDir, "The directory your h0tb0x stuff lives in")
	flag.Parse()
	if *dir == "" {
		fatal("Directory option is required", nil)
	}

	cfgFilename := path.Join(*dir, ConfigFilename)
	dbFilename := path.Join(*dir, DbFilename)
	idFilename := path.Join(*dir, IdFilename)
	dataDir := path.Join(*dir, "data")

	var config *Config
	var thedb *db.Database
	var ident *crypto.SecretIdentity
	if fi, err := os.Stat(*dir); err == nil && fi.IsDir() {
		pass1, err := gopass.GetPass("Please enter your h0tb0x password: "******"", err)
		}
		configFile, err := os.Open(cfgFilename)
		if err != nil {
			fatal("", err)
		}
		dec := json.NewDecoder(configFile)
		err = dec.Decode(&config)
		if err != nil {
			fatal("", err)
		}
		configFile.Close()
		identFile, err := os.Open(idFilename)
		if err != nil {
			fatal("", err)
		}
		var lockedId *crypto.LockedIdentity
		err = transfer.Decode(identFile, &lockedId)
		if err != nil {
			fatal("", err)
		}
		ident, err = crypto.UnlockSecretIdentity(lockedId, pass1)
		if err != nil {
			fatal("", err)
		}
		thedb = db.NewDatabase(dbFilename)
	} else {
		fmt.Println("Making a *NEW* h0tb0x config")
		err = os.MkdirAll(*dir, 0700)
		if err != nil {
			fatal("", err)
		}
		pass1, err := gopass.GetPass("Please enter the new password for your h0tb0x: ")
		if err != nil {
			fatal("", err)
		}
		pass2, err := gopass.GetPass("Re-enter your password: "******"", err)
		}
		if pass1 != pass2 {
			fmt.Println("Passwords don't match, go away")
			return
		}
		config = &Config{
			ApiPort:  DefaultApiPort,
			LinkPort: DefaultLinkPort,
		}
		configFile, err := os.Create(cfgFilename)
		if err != nil {
			fatal("", err)
		}
		enc := json.NewEncoder(configFile)
		err = enc.Encode(&config)
		if err != nil {
			fatal("", err)
		}
		configFile.Close()
		thedb = db.NewDatabase(dbFilename)
		thedb.Install()
		ident = crypto.NewSecretIdentity(pass1)
		identFile, err := os.Create(idFilename)
		if err != nil {
			fatal("", err)
		}
		_, err = identFile.Write(transfer.AsBytes(ident.Lock()))
		if err != nil {
			fatal("", err)
		}
	}

	extHost, extPort := GetExternalAddr(config.LinkPort)

	base := &base.Base{
		Log:   log.New(os.Stderr, "h0tb0x", log.LstdFlags),
		Db:    thedb,
		Ident: ident,
		Port:  config.LinkPort,
	}

	link := link.NewLinkMgr(base)
	sync := sync.NewSyncMgr(link)
	meta := meta.NewMetaMgr(sync)
	data := data.NewDataMgr(dataDir, meta)
	api := api.NewApiMgr(extHost.String(), extPort, config.ApiPort, data)
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, os.Interrupt, os.Kill)
	api.Run()
	<-ch
	fmt.Fprintf(os.Stderr, "\n")
	api.Stop()
}