示例#1
0
文件: config.go 项目: ZiRo-/srndv2
// save a list of feeds to overwrite feeds.ini
func SaveFeeds(feeds []FeedConfig) (err error) {
	conf := configparser.NewConfiguration()
	for _, feed := range feeds {
		if len(feed.Name) == 0 {
			// don't do feed with no name
			continue
		}
		sect := conf.NewSection("feed-" + feed.Name)
		if len(feed.proxy_type) > 0 {
			sect.Add("proxy-type", feed.proxy_type)
		}
		phost, pport, _ := net.SplitHostPort(feed.proxy_addr)
		sect.Add("proxy-host", phost)
		sect.Add("proxy-port", pport)
		host, port, _ := net.SplitHostPort(feed.Addr)
		sect.Add("host", host)
		sect.Add("port", port)
		sync := "0"
		if feed.sync {
			sync = "1"
		}
		sect.Add("sync", sync)
		interval := feed.sync_interval / time.Second
		sect.Add("sync-interval", fmt.Sprintf("%d", int(interval)))
		sect.Add("username", feed.username)
		sect.Add("password", feed.passwd)
		sect = conf.NewSection(feed.Name)
		for k, v := range feed.policy.rules {
			sect.Add(k, v)
		}
	}
	return configparser.Save(conf, "feeds.ini")
}
示例#2
0
文件: config.go 项目: kurtcoke/srndv2
// 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")
}
示例#3
0
文件: config.go 项目: kurtcoke/srndv2
// generate default feeds.ini
func GenFeedsConfig() error {
	conf := configparser.NewConfiguration()
	sect := conf.NewSection("feed-10.0.0.1:119")
	sect.Add("proxy-type", "socks4a")
	sect.Add("proxy-host", "127.0.0.1")
	sect.Add("proxy-port", "9050")

	sect = conf.NewSection("10.0.0.1:119")
	sect.Add("overchan.*", "1")
	sect.Add("ano.paste", "0")
	sect.Add("ctl", "1")

	return configparser.Save(conf, "feeds.ini")
}
示例#4
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
}