Archived
1
0

more recent changes

This commit is contained in:
Jeff Becker 2016-10-18 07:03:51 -04:00
parent 378a257377
commit 4f3bc5cf6e
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
9 changed files with 133 additions and 7 deletions

View File

@ -22,7 +22,7 @@ CXXFLAGS := -std=c++14 -Wall -Wextra $(INC_FLAGS) -g
all: $(EXE) $(TOOL) all: $(EXE) $(TOOL)
$(EXE): $(OBJECTS) $(EXE): $(OBJECTS)
$(CXX) -o $(EXE) $(LD_FLAGS) $(OBJECTS) $(CXXFLAGS) nntpchan.cpp $(CXX) -o $(EXE) $(LD_FLAGS) $(OBJECTS) $(CXXFLAGS) nntpd.cpp
$(TOOL): $(OBJECTS) $(TOOL): $(OBJECTS)
$(CXX) -o $(TOOL) $(LD_FLAGS) $(OBJECTS) $(CXXFLAGS) tool.cpp $(CXX) -o $(TOOL) $(LD_FLAGS) $(OBJECTS) $(CXXFLAGS) tool.cpp

View File

@ -3,6 +3,7 @@
#include "storage.hpp" #include "storage.hpp"
#include "nntp_server.hpp" #include "nntp_server.hpp"
#include "event.hpp" #include "event.hpp"
#include "exec_frontend.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
@ -57,6 +58,26 @@ int main(int argc, char * argv[]) {
nntp.SetLoginDB(nntpconf["authdb"]); nntp.SetLoginDB(nntpconf["authdb"]);
} }
if ( level.sections.find("frontend") != level.sections.end()) {
// frontend enabled
auto & frontconf = level.sections["frontend"];
if (frontconf.find("type") == frontconf.end()) {
std::cerr << "frontend section provided but 'type' value not provided" << std::endl;
return 1;
}
auto & ftype = frontconf.find("type");
if (ftype == "exec") {
if (frontconf.find("exec") == frontconf.end()) {
std::cerr << "exec frontend specified but no 'exec' value provided" << std::endl;
return 1;
}
nntp.SetFrontend(new nntpchan::ExecFrontend(loop, frontconf["exec"]));
} else {
std::cerr << "unknown frontend type '" << ftype << "'" << std::endl;
}
}
auto & a = nntpconf["bind"]; auto & a = nntpconf["bind"];
try { try {

View File

@ -0,0 +1,9 @@
#ifndef NNTPCHAN_EXEC_FRONTEND_HPP
#define NNTPCHAN_EXEC_FRONTEND_HPP
namespace nntpchan
{
}
#endif

View File

@ -0,0 +1,25 @@
#ifndef NNTPCHAN_FRONTEND_HPP
#define NNTPCHAN_FRONTEND_HPP
namespace nntpchan
{
/** @brief nntpchan frontend ui interface */
class Frontend
{
public:
virtual ~Frontend() {}
/** @brief process an inbound message stored at fpath that we have accepted. */
void ProcessNewMessage(const std::string & fpath) = 0;
/** @brief return true if we take posts in a newsgroup */
bool AcceptsNewsgroup(const std::string & newsgroup) = 0;
/** @brief return true if we will accept a message given its message-id */
bool AcceptsMessage(const std::string & msgid) = 0;
};
}
#endif

View File

@ -2,6 +2,8 @@
## usage ## ## usage ##
### srndv2 unstable ###
add to nntpchan.json hooks section: add to nntpchan.json hooks section:
{ {
@ -9,3 +11,12 @@ add to nntpchan.json hooks section:
"exec": "/path/to/frontend.py" "exec": "/path/to/frontend.py"
} }
### nntpd ###
add this to nntpchan.ini
...
[frontend]
type=exec
exec=/path/to/frontend.py

View File

@ -1,9 +1,37 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import nntpchan from nntpchan import message
from nntpchan import db
import logging
import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
msgid = sys.argv[1] lvl = logging.INFO
group = sys.argv[2] if 'NNTPCHAN_DEBUG' in os.environ:
if nntpchan.addArticle(msgid, group): lvl = logging.DEBUG
nntpchan.regenerate(msgid, group) logging.basicConfig(level=lvl)
l = logging.getLogger(__name__)
cmd = sys.argv[1]
if cmd == 'post':
fpath = sys.argv[2]
msg = None
if not os.path.exists(fpath):
print("{} does not exist".format(fpath))
exit(1)
with open(fpath) as f:
msg = message.parse(f)
if msg:
l.debug("loaded {}".format(fpath))
elif cmd == 'newsgroup':
if db.allowsNewsgroup(sys.argv[2]):
exit(0)
else:
exit(1)
elif cmd == 'msgid':
if db.allowsMessage(sys.argv[2]):
exit(0)
else:
exit(1)
elif cmd == 'init':
db.init()

View File

@ -0,0 +1,11 @@
#
# please edit this file to contain the required information
#
""" path to article storage directory """
storage = '/path/to/storage/'
""" database connector url """
dburl = 'postgresql://user:password@localhost/database'
#dburl = 'sqlite:///path/to/nntpchan.sqlite3'

View File

@ -0,0 +1,16 @@
from nntpchan import config
import sqlalchemy
def allowsMessage(msgid):
return True
def allowsNewsgroup(group):
return True
def init():
"""
initialize db backend
"""

View File

@ -0,0 +1,5 @@
// Generated by CoffeeScript 1.11.1
(function() {
}).call(this);