* change feed defaults to be sane
* update docs * add git revision to version * bump to 2.5.1
This commit is contained in:
@@ -57,6 +57,7 @@ type FeedConfig struct {
|
||||
Name string
|
||||
sync_interval time.Duration
|
||||
connections int
|
||||
disable bool
|
||||
}
|
||||
|
||||
type APIConfig struct {
|
||||
@@ -107,16 +108,16 @@ func CheckConfig() {
|
||||
if !CheckFile(os.Getenv("SRND_INI_PATH")) {
|
||||
log.Printf("No config file found at %s...", os.Getenv("SRND_INI_PATH"))
|
||||
var conf *configparser.Configuration
|
||||
if !InstallerEnabled() {
|
||||
log.Println("Creating srnd.ini in working directory...")
|
||||
conf = GenSRNdConfig()
|
||||
} else {
|
||||
if InstallerEnabled() {
|
||||
res := make(chan *configparser.Configuration)
|
||||
installer := NewInstaller(res)
|
||||
go installer.Start()
|
||||
conf = <-res
|
||||
installer.Stop()
|
||||
close(res)
|
||||
} else {
|
||||
log.Println("Creating srnd.ini in working directory...")
|
||||
conf = GenSRNdConfig()
|
||||
}
|
||||
err := configparser.Save(conf, "srnd.ini")
|
||||
if err != nil {
|
||||
@@ -138,18 +139,26 @@ func CheckConfig() {
|
||||
// generate default feeds.ini
|
||||
func GenFeedsConfig() error {
|
||||
conf := configparser.NewConfiguration()
|
||||
sect := conf.NewSection("feed-dummy")
|
||||
sect.Add("proxy-type", "socks4a")
|
||||
|
||||
sect := conf.NewSection("global")
|
||||
sect.Add("overchan.overchan", "1")
|
||||
sect.Add("ctl", "1")
|
||||
sect.Add("*", "0")
|
||||
|
||||
sect = conf.NewSection("feed-2hu")
|
||||
sect.Add("proxy-type", "None")
|
||||
sect.Add("proxy-host", "127.0.0.1")
|
||||
sect.Add("proxy-port", "9050")
|
||||
sect.Add("host", "dummy")
|
||||
sect.Add("host", "2hu-ch.org")
|
||||
sect.Add("port", "119")
|
||||
sect.Add("connections", "1")
|
||||
sect.Add("connections", "0")
|
||||
sect.Add("sync", "1")
|
||||
sect.Add("disable", "1")
|
||||
|
||||
sect = conf.NewSection("dummy")
|
||||
sect.Add("overchan.*", "1")
|
||||
sect.Add("ano.paste", "0")
|
||||
sect = conf.NewSection("2hu")
|
||||
sect.Add("overchan.overchan", "1")
|
||||
sect.Add("ctl", "1")
|
||||
sect.Add("*", "0")
|
||||
|
||||
return configparser.Save(conf, "feeds.ini")
|
||||
}
|
||||
@@ -171,6 +180,7 @@ func GenSRNdConfig() *configparser.Configuration {
|
||||
sect.Add("feeds", filepath.Join(".", "feeds.d"))
|
||||
sect.Add("archive", "0")
|
||||
sect.Add("article_lifetime", "0")
|
||||
sect.Add("filters_file", "filters.txt")
|
||||
|
||||
// profiling settings
|
||||
sect = conf.NewSection("pprof")
|
||||
@@ -182,10 +192,15 @@ func GenSRNdConfig() *configparser.Configuration {
|
||||
sect.Add("enable", "0")
|
||||
sect.Add("exec", "/bin/true")
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
if hostname == "" {
|
||||
hostname = "!!please-manually-set-this"
|
||||
}
|
||||
|
||||
// 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-hostname", hostname)
|
||||
sect.Add("tls-trust-dir", "certs")
|
||||
|
||||
// article store section
|
||||
@@ -242,7 +257,7 @@ func GenSRNdConfig() *configparser.Configuration {
|
||||
secret_bytes := randbytes(8)
|
||||
secret := base32.StdEncoding.EncodeToString(secret_bytes)
|
||||
sect.Add("api-secret", secret)
|
||||
|
||||
sect.Add("rapeme", "no")
|
||||
return conf
|
||||
}
|
||||
|
||||
@@ -309,7 +324,7 @@ func ReadConfig() *SRNdConfig {
|
||||
log.Fatal("cannot read config file ", fname)
|
||||
return nil
|
||||
}
|
||||
var sconf SRNdConfig
|
||||
sconf := new(SRNdConfig)
|
||||
|
||||
s, err = conf.Section("pprof")
|
||||
if err == nil {
|
||||
@@ -357,6 +372,12 @@ func ReadConfig() *SRNdConfig {
|
||||
|
||||
sconf.daemon = s.Options()
|
||||
|
||||
filtersFile := s.ValueOf("filters_file")
|
||||
|
||||
if filtersFile == "" {
|
||||
filtersFile = "filters.txt"
|
||||
}
|
||||
|
||||
s, err = conf.Section("database")
|
||||
if err != nil {
|
||||
log.Println("no section 'database' in srnd.ini")
|
||||
@@ -420,7 +441,7 @@ func ReadConfig() *SRNdConfig {
|
||||
var confs []FeedConfig
|
||||
confs, sconf.inboundPolicy, err = feedParse(fname)
|
||||
if err != nil {
|
||||
log.Fatal("failed to parse", fname, err)
|
||||
log.Fatal("failed to load feeds: ", err)
|
||||
}
|
||||
|
||||
sconf.feeds = append(sconf.feeds, confs...)
|
||||
@@ -437,23 +458,22 @@ func ReadConfig() *SRNdConfig {
|
||||
log.Println("load feed", f)
|
||||
confs, _, err := feedParse(f)
|
||||
if err != nil {
|
||||
log.Fatal("failed to parse feed", f, err)
|
||||
log.Fatal("failed to parse feed ", f, ": ", err)
|
||||
}
|
||||
sconf.feeds = append(sconf.feeds, confs...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filterFile := "filters.txt"
|
||||
|
||||
if CheckFile(filterFile) {
|
||||
err = sconf.filter.LoadFile(filterFile)
|
||||
if CheckFile(filtersFile) {
|
||||
log.Println("loading content filter file", filtersFile)
|
||||
err = sconf.filter.LoadFile(filtersFile)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to load %s: %s", filterFile, err)
|
||||
log.Fatalf("failed to load %s: %s", filtersFile, err)
|
||||
}
|
||||
log.Printf("loaded %d filters", len(sconf.filter.globalFilters))
|
||||
}
|
||||
return &sconf
|
||||
return sconf
|
||||
}
|
||||
|
||||
func feedParse(fname string) (confs []FeedConfig, inboundPolicy *FeedPolicy, err error) {
|
||||
@@ -464,7 +484,7 @@ func feedParse(fname string) (confs []FeedConfig, inboundPolicy *FeedPolicy, err
|
||||
return
|
||||
}
|
||||
|
||||
default_sect, err := conf.Section("")
|
||||
default_sect, err := conf.Section("global")
|
||||
if err == nil {
|
||||
opts := default_sect.Options()
|
||||
inboundPolicy = &FeedPolicy{
|
||||
@@ -505,6 +525,9 @@ func feedParse(fname string) (confs []FeedConfig, inboundPolicy *FeedPolicy, err
|
||||
fconf.sync_interval = time.Second * time.Duration(i)
|
||||
}
|
||||
|
||||
// check for feed disabled
|
||||
fconf.disable = sect.ValueOf("disable") == "1"
|
||||
|
||||
// concurrent connection count
|
||||
fconf.connections = mapGetInt(sect.Options(), "connections", 1)
|
||||
|
||||
|
@@ -304,6 +304,10 @@ func (self *NNTPDaemon) storeFeedsConfig() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *NNTPDaemon) AllowsNewsgroup(group string) bool {
|
||||
return self.conf.inboundPolicy == nil || self.conf.inboundPolicy.AllowsNewsgroup(group)
|
||||
}
|
||||
|
||||
// change a feed's policy given the feed's name
|
||||
// return error if one occurs while modifying feed's policy
|
||||
func (self *NNTPDaemon) modifyFeedPolicy(feedname string, policy FeedPolicy) (err error) {
|
||||
@@ -373,6 +377,10 @@ func (self *NNTPDaemon) messageSizeLimitFor(newsgroup string) int64 {
|
||||
}
|
||||
|
||||
func (self *NNTPDaemon) persistFeed(conf *FeedConfig, mode string, n int) {
|
||||
if conf.disable {
|
||||
log.Println(conf.Name, "is disabled not persisting")
|
||||
return
|
||||
}
|
||||
log.Println(conf.Name, "persisting in", mode, "mode")
|
||||
backoff := time.Second
|
||||
for {
|
||||
|
@@ -326,7 +326,7 @@ func (self *Installer) HandleInstallerPost(wr http.ResponseWriter, r *http.Reque
|
||||
next, newErr := self.currentNode.post(self.currentNode, r.PostForm, self.config)
|
||||
if next == nil {
|
||||
self.result <- self.config
|
||||
//defer self.srv.Stop(10 * time.Second)
|
||||
go self.srv.Stop(5 * time.Second)
|
||||
}
|
||||
self.currentNode = next
|
||||
self.currentErr = newErr
|
||||
@@ -490,7 +490,7 @@ func checkHost(host string) error {
|
||||
|
||||
func (self *Installer) Start() {
|
||||
log.Println("starting installer on", self.srv.Server.Addr)
|
||||
log.Println("open up http://127.0.0.1:18000 to do initial configuration")
|
||||
log.Println(fmt.Sprintf("open up http://youserver%s/ to do initial configuration", self.srv.Server.Addr))
|
||||
self.srv.ListenAndServe()
|
||||
}
|
||||
|
||||
@@ -499,5 +499,5 @@ func (self *Installer) Stop() {
|
||||
}
|
||||
|
||||
func InstallerEnabled() bool {
|
||||
return os.Getenv("SRND_NO_INSTALLER") != "1"
|
||||
return os.Getenv("SRND_INSTALLER") != "0"
|
||||
}
|
||||
|
@@ -1393,11 +1393,13 @@ func (self *nntpConnection) scrapeServer(daemon *NNTPDaemon, conn *textproto.Con
|
||||
if banned {
|
||||
// we don't want it
|
||||
} else if err == nil {
|
||||
// scrape the group
|
||||
err = self.scrapeGroup(daemon, conn, group)
|
||||
if err != nil {
|
||||
log.Println(self.name, "did not scrape", group, err)
|
||||
break
|
||||
if daemon.AllowsNewsgroup(group) {
|
||||
// scrape the group
|
||||
err = self.scrapeGroup(daemon, conn, group)
|
||||
if err != nil {
|
||||
log.Println(self.name, "did not scrape", group, err)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// error while checking for ban
|
||||
|
@@ -808,6 +808,9 @@ func (self *PostgresDatabase) AddModPubkey(pubkey string) error {
|
||||
|
||||
func (self *PostgresDatabase) GetGroupForMessage(message_id string) (group string, err error) {
|
||||
err = self.conn.QueryRow("SELECT newsgroup FROM ArticlePosts WHERE message_id = $1", message_id).Scan(&group)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -830,6 +833,8 @@ func (self *PostgresDatabase) GetInfoForMessage(msgid string) (root string, news
|
||||
perpage, _ := self.GetPagesPerBoard(newsgroup)
|
||||
err = self.conn.QueryRow("WITH thread(bump) AS (SELECT last_bump FROM ArticleThreads WHERE root_message_id = $1 ) SELECT COUNT(*) FROM ( SELECT last_bump FROM ArticleThreads INNER JOIN thread ON (thread.bump <= ArticleThreads.last_bump AND newsgroup = $2 ) ) AS amount", root, newsgroup).Scan(&page)
|
||||
page = page / int64(perpage)
|
||||
} else if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -956,6 +961,9 @@ func (self *PostgresDatabase) UnmarkPubkeyAdmin(pubkey string) (err error) {
|
||||
func (self *PostgresDatabase) CheckAdminPubkey(pubkey string) (admin bool, err error) {
|
||||
var count int64
|
||||
err = self.conn.QueryRow("SELECT COUNT(pubkey) FROM ModPrivs WHERE pubkey = $1 AND permission = $2", pubkey, "admin").Scan(&count)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
if err == nil {
|
||||
admin = count > 0
|
||||
}
|
||||
@@ -1106,10 +1114,11 @@ func (self *PostgresDatabase) GetPostModel(prefix, messageID string) PostModel {
|
||||
// quiet fail
|
||||
self.conn.QueryRow(self.stmt[GetArticlePubkey], messageID).Scan(&model.Key)
|
||||
return model
|
||||
} else {
|
||||
} else if err != sql.ErrNoRows {
|
||||
log.Println("failed to prepare query for geting post model for", messageID, err)
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *PostgresDatabase) GetCitesByPostHashLike(like string) (cites []MessageIDTuple, err error) {
|
||||
|
@@ -7,7 +7,7 @@ package srnd
|
||||
import "fmt"
|
||||
|
||||
const major_version = 5
|
||||
const minor_version = 0
|
||||
const minor_version = 1
|
||||
const program_name = "srnd"
|
||||
|
||||
var GitVersion string
|
||||
|
Reference in New Issue
Block a user