Esempio n. 1
0
// check for config files
// generate defaults on demand
func CheckConfig() {
	if !CheckFile("srnd.ini") {
		var conf *configparser.Configuration
		if !InstallerEnabled() {
			log.Println("no srnd.ini, creating...")
			conf = GenSRNdConfig()
		} else {
			res := make(chan *configparser.Configuration)
			installer := NewInstaller(res)
			go installer.Start()
			conf = <-res
			installer.Stop()
			close(res)
		}
		err := configparser.Save(conf, "srnd.ini")
		if err != nil {
			log.Fatal("cannot generate srnd.ini", err)
		}
	}
	if !CheckFile("feeds.ini") {
		log.Println("no feeds.ini, creating...")
		err := GenFeedsConfig()
		if err != nil {
			log.Fatal("cannot generate feeds.ini", err)
		}
	}
}
Esempio n. 2
0
// 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")
}
Esempio n. 3
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")
}
Esempio n. 4
0
// 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")
}