Пример #1
0
// generate default srnd.ini
func GenSRNdConfig() error {
	conf := configparser.NewConfiguration()

	// nntp related section
	sect := conf.NewSection("nntp")
	sect.Add("instance_name", "test.srndv2.tld")
	sect.Add("bind", "127.0.0.1:1199")
	sect.Add("sync_on_start", "1")
	sect.Add("allow_anon", "0")
	sect.Add("allow_anon_attachments", "0")

	// article store section
	sect = conf.NewSection("articles")

	sect.Add("store_dir", "articles")
	sect.Add("incoming_dir", "/tmp/articles")
	sect.Add("attachments_dir", "webroot/img")
	sect.Add("thumbs_dir", "webroot/thm")
	sect.Add("convert_bin", "/usr/bin/convert")
	sect.Add("ffmpegthumbnailer_bin", "/usr/bin/ffmpegthumbnailer")
	sect.Add("sox_bin", "/usr/bin/sox")

	// database backend config
	sect = conf.NewSection("database")

	// change this to mysql to use with mariadb or mysql
	sect.Add("type", "postgres")
	// change this to infinity to use with infinity-next
	sect.Add("schema", "srnd")
	sect.Add("host", "127.0.0.1")
	sect.Add("port", "5432")
	sect.Add("user", "root")
	sect.Add("password", "root")

	// baked in static html frontend
	sect = conf.NewSection("frontend")
	sect.Add("enable", "1")
	sect.Add("allow_files", "1")
	sect.Add("regen_on_start", "0")
	sect.Add("regen_threads", "1")
	sect.Add("nntp", "[::]:1119")
	sect.Add("bind", "[::]:18000")
	sect.Add("name", "web.srndv2.test")
	sect.Add("webroot", "webroot")
	sect.Add("prefix", "/")
	sect.Add("static_files", "contrib")
	sect.Add("templates", "contrib/templates/default")
	sect.Add("domain", "localhost")
	secret_bytes := nacl.RandBytes(8)
	secret := base32.StdEncoding.EncodeToString(secret_bytes)
	sect.Add("api-secret", secret)

	return configparser.Save(conf, "srnd.ini")
}
Пример #2
0
// given an address
// generate a new encryption key for it
// return the encryption key and the encrypted address
func newAddrEnc(addr string) (string, string) {
	key_bytes := nacl.RandBytes(encAddrBytes())
	key := base64.StdEncoding.EncodeToString(key_bytes)
	return key, encAddr(addr, key)
}
Пример #3
0
// make a random string
func randStr(length int) string {
	return hex.EncodeToString(nacl.RandBytes(length))[length:]
}