Browse Source

controlpanel: URL handling & debugging

Improved group handling in init.d script too.
master
Jon Foster 11 months ago
parent
commit
ffab54d30d
6 changed files with 77 additions and 10 deletions
  1. +2
    -0
      controlpanel/default
  2. +5
    -3
      controlpanel/init
  3. +28
    -0
      controlpanel/lighttpd.conf
  4. +3
    -3
      controlpanel/mainskin.tmpl
  5. +5
    -2
      controlpanel/sample.js
  6. +34
    -2
      controlpanel/trafficctrl.cpp

+ 2
- 0
controlpanel/default View File

@@ -7,3 +7,5 @@
#RUN=/run
# This needs to match the "daemon.lock" entry in the $CONF file.
#PID=$RUN/poorman-ids/trafficctrl.pid
# The group to run as. This is the Debian default for web servers.
GROUP=www-data

+ 5
- 3
controlpanel/init View File

@@ -1,8 +1,8 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: trafficctrl
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Control categories of network traffic
@@ -18,6 +18,7 @@ DAEMON="/usr/sbin/$NAME"
RUN=/run
CONF=/etc/poorman-ids/sample.js
PID=""
GROUP=""

# Pull in config
if [ -r "/etc/default/$NAME" ]; then
@@ -33,6 +34,7 @@ RUN="$RUN/poorman-ids"
# NOTE: this needs to match what $CONF says
[ -n "$PID" ] || PID="$RUN/$NAME.pid"
mkdir -p "$RUN"
[ -z "$GROUP" ] || GROUP="-g $GROUP"



@@ -47,7 +49,7 @@ CTRL() {

do_start() {
echo -n "Starting Traffic Control: "
if CTRL --start --oknodo -- -c "$CONF"; then
if CTRL --start --oknodo --umask 007 $GROUP -- -c "$CONF"; then
echo "OK"
else
echo "FAIL"


+ 28
- 0
controlpanel/lighttpd.conf View File

@@ -0,0 +1,28 @@
# This is based on a Debian 10 install of LigHTTPd install.
# Include the 10-fastcgi.conf or:
# server.modules += ( "mod_fastcgi" )

#fastcgi.debug = 1
fastcgi.server = (
"/webmonitor" =>
( "trafficctrl" =>
( "socket" => "/run/poorman-ids/trafficctrl.fcgi",
"check-local" => "disable",
# "fix-root-scriptname" => "enable",
#"docroot" => "/" # remote server may use
# its own docroot

)
)
)

# Password restriction could be done something like this:

auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/etc/lighttpd/lighttpd.users"
auth.require += ( "/webmonitor" => (
"method" => "basic",
"realm" => "Web Monitor",
#"require" => "user=root"
), )
# Check LigHTTPd docs for your version.

+ 3
- 3
controlpanel/mainskin.tmpl View File

@@ -12,9 +12,9 @@

<% template menu() %>
<b>Filters: </b>
<a href="/">To Be Decided</a> |
<a href="/accepted">Accepted</a> |
<a href="/blocked">Blocks</a>
<a href="<% url "" %>">To Be Decided</a> |
<a href="<% url "accepted" %>">Accepted</a> |
<a href="<% url "blocked" %>">Blocks</a>
<% end template %>




+ 5
- 2
controlpanel/sample.js View File

@@ -16,6 +16,9 @@
// This is a MySQL example replace the {...} parts with your site's settings.
"trafficctrl": {
"db": "mysql:user={username};password={password};database={db_name};@pool_size=10;@opt_reconnect=1"
// Root URI (path) within a site. If using the stand alone HTTP server this
// needs to match "http.script". But in that case leave both "".
"root_uri": "", // root path on the hosting site. "" = "/"
},


@@ -32,7 +35,8 @@
// },
// "http" : { "script": "" },
// This is a FastCGI example, which could be used to provide HTTPS & passwords:
// This is a FastCGI example, which could be used to provide HTTPS & passwords
// via the host service:
"service": {
"api" : "fastcgi",
// To serve on a TCP socket: "ip": "0.0.0.0", "port": 8080
@@ -54,7 +58,6 @@
"daemon": {
"enable": true,
"lock": "/run/poorman-ids/trafficctrl.pid",
"user": "www-data"
},
"logging": {
"syslog": {


+ 34
- 2
controlpanel/trafficctrl.cpp View File

@@ -28,6 +28,11 @@
#include "../strutil.h"
#include "data.h"

/// Build flags ///

// TODO: better application of C++CMS booster logging
//#define DEBUGGIN



//////////////////////////////////////////////////////////////////////
@@ -36,6 +41,7 @@

const std::string filter_titles[] = { "Undecided", "Accepted", "Blocked" };
const std::string actions[] = { "Reset", "Accept", "Block" };
std::string root_uri = "";

struct app: public cppcms::application {
std::auto_ptr<cppdb::session> sql;
@@ -140,15 +146,32 @@ struct app: public cppcms::application {
app(cppcms::service &s): cppcms::application(s), items_per_page(50) {
#ifdef DEBUGGIN
std::cerr << "spawning app object" << std::endl;
#endif
sql.reset(new cppdb::session());
sql->open(settings().get<std::string>("trafficctrl.db"));
mapper().root(root_uri);
mapper().assign("blocked", "/blocked");
dispatcher().assign("/blocked/?", &app::blocked, this);
mapper().assign("accepted", "/accepted");
dispatcher().assign("/accepted/?", &app::accepted, this);
mapper().assign("");
dispatcher().assign("/?", &app::undecided, this);

}
// logging
void main(const std::string url) {
#ifdef DEBUGGIN
std::cerr << "request: " << url << '\n'
<< " INFO: " << request().path_info() << '\n'
<< " SCRIPT: " << request().script_name() << '\n'
<< std::endl;
#endif
cppcms::application::main(url);
}
};

@@ -159,11 +182,20 @@ struct app: public cppcms::application {
//////////////////////////////////////////////////////////////////////

int main(int argc, char **args) {
// create server object
cppcms::service srv(argc, args);
// Get root URI from configuration file.
root_uri = srv.settings().get("trafficctrl.root_uri", "");
// Mount our app in the server
srv.applications_pool().mount(
cppcms::create_pool<app>(),
cppcms::mount_point("")
cppcms::mount_point(root_uri)
);
// Serve it!
// TODO: log crashes.
#ifdef DEBUGGIN
std::cerr << "Launching" << std::endl;
#endif
srv.run();

return 0;


Loading…
Cancel
Save