示例#1
0
文件: util.go 项目: ZiRo-/srndv2
// make a random string
func randStr(length int) string {
	return hex.EncodeToString(nacl.RandBytes(length))[length:]
}
示例#2
0
文件: util.go 项目: ZiRo-/srndv2
// 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
文件: config.go 项目: ZiRo-/srndv2
// generate default srnd.ini
func GenSRNdConfig() *configparser.Configuration {
	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")
	sect.Add("allow_attachments", "1")
	sect.Add("require_tls", "1")
	sect.Add("anon_nntp", "0")

	// profiling settings
	sect = conf.NewSection("pprof")
	sect.Add("enable", "0")
	sect.Add("bind", "127.0.0.1:17000")

	// crypto related section
	sect = conf.NewSection("crypto")
	sect.Add("tls-keyname", "overchan")
	sect.Add("tls-hostname", "!!put-hostname-or-ip-of-server-here")
	sect.Add("tls-trust-dir", "certs")

	// 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/ffmpeg")
	sect.Add("sox_bin", "/usr/bin/sox")
	sect.Add("compression", "0")

	// database backend config
	sect = conf.NewSection("database")
	// defaults to redis if enabled
	if RedisEnabled() {
		sect.Add("type", "redis")
		sect.Add("schema", "single")
		sect.Add("host", "localhost")
		sect.Add("port", "6379")
		sect.Add("user", "")
		sect.Add("password", "")
	} else {
		// otherwise defaults to postgres
		sect.Add("type", "postgres")
		sect.Add("schema", "srnd")
		sect.Add("host", "/var/run/postgresql")
		sect.Add("port", "")
		sect.Add("user", "")
		sect.Add("password", "")
	}

	// cache backend config
	sect = conf.NewSection("cache")
	// defaults to file
	sect.Add("type", "file")

	// 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("translations", "contrib/translations")
	sect.Add("locale", "en")
	sect.Add("domain", "localhost")
	sect.Add("json-api", "0")
	sect.Add("json-api-username", "f*****g-change-this-value")
	sect.Add("json-api-password", "seriously-f*****g-change-this-value")
	secret_bytes := nacl.RandBytes(8)
	secret := base32.StdEncoding.EncodeToString(secret_bytes)
	sect.Add("api-secret", secret)

	return conf
}