func (c *Config) validate() error { if c.Server { if c.Net.AgentMgntPort == 0 { return errors.New("Not set Net.AgentMgntPort in server config file") } if c.Net.AgentDataPort == 0 { return errors.New("Not set Net.AgentDataPort in server config file") } } if !c.Server { if c.DownDir == "" { return errors.New("Not set DownDir in client config file") } } if c.Auth.Username == "" || c.Auth.Password == "" || c.Auth.Factor == "" || c.Auth.Crc == "" { return errors.New("Not set auth in config file") } var err error c.Crypto, err = gokits.NewCrypto(c.Auth.Factor, c.Auth.Crc) if err != nil { return err } c.Auth.Password, err = c.Crypto.DecryptStr(c.Auth.Password) if err != nil { return err } return nil }
func main() { flag.Parse() if !*a && !*s && *p == "" { fmt.Println("miss option") usage() } if *p != "" { factor := gokits.NewRand(8) crc := gokits.KermitStr(factor) crypto, _ := gokits.NewCrypto(factor, crc) stxt, _ := crypto.EncryptStr(*p) fmt.Println("factor =", factor) fmt.Println("crc =", crc) fmt.Println("stxt =", stxt) return } if flag.NArg() < 1 { fmt.Println("miss config file") usage() } cfgfile := flag.Args()[0] var cfg *common.Config var err error if cfg, err = common.ParserConfig(cfgfile, *s); err != nil { fmt.Printf("parser config file %s error, %s.\n", cfgfile, err.Error()) os.Exit(3) } var svc common.Service if *s { if svc, err = server.NewServer(cfg); err != nil { fmt.Printf("start server error, %s.\n", err.Error()) os.Exit(4) } } if *a { if svc, err = agent.NewAgent(cfg); err != nil { fmt.Printf("start agent error, %s.\n", err.Error()) os.Exit(4) } } if err = svc.Start(); err != nil { fmt.Printf("Start service failed, %s.\n", err.Error()) os.Exit(4) } quitChan := listenSigInt() select { case <-quitChan: fmt.Printf("got control-C") svc.Stop() } }
func readSecureCfg() { secure, err := cfg.GetSection("secure") if err != nil { panic(err) } factor := secure.Key("factor").String() crc := secure.Key("crc").String() crypto, err = gokits.NewCrypto(factor, crc) if err != nil { panic(err) } }