add feed policy for inbound feeds in default section of feeds.ini
This commit is contained in:
parent
cc467ac312
commit
cfaa96b82c
@ -69,6 +69,7 @@ type SRNdConfig struct {
|
||||
worker map[string]string
|
||||
pprof *ProfilingConfig
|
||||
hooks []*HookConfig
|
||||
inboundPolicy *FeedPolicy
|
||||
}
|
||||
|
||||
// check for config files
|
||||
@ -219,8 +220,16 @@ func GenSRNdConfig() *configparser.Configuration {
|
||||
}
|
||||
|
||||
// save a list of feeds to overwrite feeds.ini
|
||||
func SaveFeeds(feeds []FeedConfig) (err error) {
|
||||
func SaveFeeds(feeds []FeedConfig, inboundPolicy *FeedPolicy) (err error) {
|
||||
conf := configparser.NewConfiguration()
|
||||
|
||||
if inboundPolicy != nil {
|
||||
s := conf.NewSection("")
|
||||
for k, v := range inboundPolicy.rules {
|
||||
s.Add(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
for _, feed := range feeds {
|
||||
if len(feed.Name) == 0 {
|
||||
// don't do feed with no name
|
||||
@ -381,8 +390,8 @@ func ReadConfig() *SRNdConfig {
|
||||
fname = os.Getenv("SRND_FEEDS_INI_PATH")
|
||||
}
|
||||
}
|
||||
|
||||
confs, err := feedParse(fname)
|
||||
var confs []FeedConfig
|
||||
confs, sconf.inboundPolicy, err = feedParse(fname)
|
||||
if err != nil {
|
||||
log.Fatal("failed to parse", fname, err)
|
||||
}
|
||||
@ -399,7 +408,7 @@ func ReadConfig() *SRNdConfig {
|
||||
if err == nil {
|
||||
for _, f := range feeds {
|
||||
log.Println("load feed", f)
|
||||
confs, err := feedParse(f)
|
||||
confs, _, err := feedParse(f)
|
||||
if err != nil {
|
||||
log.Fatal("failed to parse feed", f, err)
|
||||
}
|
||||
@ -411,12 +420,20 @@ func ReadConfig() *SRNdConfig {
|
||||
return &sconf
|
||||
}
|
||||
|
||||
func feedParse(fname string) (confs []FeedConfig, err error) {
|
||||
func feedParse(fname string) (confs []FeedConfig, inboundPolicy *FeedPolicy, err error) {
|
||||
|
||||
conf, err := configparser.Read(fname)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
default_sect, err := conf.Section("")
|
||||
if err == nil {
|
||||
opts := default_sect.Options()
|
||||
inboundPolicy = &FeedPolicy{
|
||||
rules: opts,
|
||||
}
|
||||
}
|
||||
|
||||
sections, err := conf.Find("feed-*")
|
||||
|
@ -295,7 +295,7 @@ func (self *NNTPDaemon) storeFeedsConfig() (err error) {
|
||||
for _, status := range feeds {
|
||||
feedconfigs = append(feedconfigs, *status.State.Config)
|
||||
}
|
||||
err = SaveFeeds(feedconfigs)
|
||||
err = SaveFeeds(feedconfigs, self.conf.inboundPolicy)
|
||||
return
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ func (self *NNTPDaemon) persistFeed(conf *FeedConfig, mode string, n int) {
|
||||
continue
|
||||
}
|
||||
nntp := createNNTPConnection(conf.Addr)
|
||||
nntp.policy = conf.policy
|
||||
nntp.policy = &conf.policy
|
||||
nntp.feedname = conf.Name
|
||||
nntp.name = fmt.Sprintf("%s-%d-%s", conf.Name, n, mode)
|
||||
stream, reader, use_tls, err := nntp.outboundHandshake(textproto.NewConn(conn), conf)
|
||||
@ -948,6 +948,7 @@ func (self *NNTPDaemon) acceptloop() {
|
||||
}
|
||||
addr := conn.RemoteAddr()
|
||||
nntp.name = fmt.Sprintf("%s-inbound-feed", addr.String())
|
||||
nntp.policy = self.conf.inboundPolicy
|
||||
c := textproto.NewConn(conn)
|
||||
// send banners and shit
|
||||
err = nntp.inboundHandshake(c)
|
||||
|
@ -61,7 +61,7 @@ type nntpConnection struct {
|
||||
// what article is currently selected
|
||||
selected_article string
|
||||
// the policy for federation
|
||||
policy FeedPolicy
|
||||
policy *FeedPolicy
|
||||
// lock help when expecting non pipelined activity
|
||||
access sync.Mutex
|
||||
|
||||
@ -439,7 +439,7 @@ func (self *nntpConnection) checkMIMEHeaderNoAuth(daemon *NNTPDaemon, hdr textpr
|
||||
reason = "poster's pubkey is banned"
|
||||
ban = true
|
||||
return
|
||||
} else if !self.policy.AllowsNewsgroup(newsgroup) {
|
||||
} else if self.policy != nil && !self.policy.AllowsNewsgroup(newsgroup) {
|
||||
reason = "newsgroup not allowed by feed policy"
|
||||
ban = true
|
||||
return
|
||||
|
Reference in New Issue
Block a user