MLMMJ Webview

MLMMJ Webview
Login

MLMMJ Webview

It is a index page for mlmmj, it aims at provide informations about the existing mailing lists, and provide a helper to allow subscribing/unsubscribing via a webpage.

Configuration

with nginx

Here is an example of using mlmmj-webview with nginx and fastcgi

location / {
	try_files $uri @mlmmj-webview;
}
location /assets {
	root /usr/local/mlmmj/www/;
}
location @mlmmj-webview {
	gzip off;
	include fastcgi_params;
	fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
	fastcgi_param MLMMJ_WEBVIEW_MAILING_LISTS /usr/local/mlmmj/lists;
	fastcgi_param MLMMJ_WEBVIEW_TEMPLATES /usr/local/mlmmj/www/templates;
	fastcgi_param SCRIPT_FILENAME /usr/local/bin/mlmmj-webview;
	fastcgi_param PATH_INFO $uri;
	fastcgi_param QUERY_STRING $args;

	fastcgi_pass  unix:/var/run/fcgiwrap/fcgiwrap.sock;
}

Templates

2 templates are supported:

index

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/><link rel="stylesheet" type="text/css" href="/assets/mlmmj-webview.css"/>
    <title>Mailing lists</title>
  </head>
  <body>
    <header>
      <img src="/assets/logo.png"/><h1>mailing lists</h1>
    </header>
    <table class="table">
      <tbody>
      @@mw_mailinglists@@
      </tbody>
    </table>
    <footer>
      generated by<a href="@@mw_url@@">@@mw_name@@</a>
    </footer>
  </body>
</html>

subscription

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" type="text/css" href="/assets/mlmmj-webview.css"/>
    <title>Mailing lists: subscription for @@ml_name@@</title>
  </head>
  <body>
    <header>
      <img src="/assets/logo.png"/><h1>Subscription for @@ml_name@@</h1>
    </header>
    <main>
      <center>
        <table>
          <tr>
            <td>Browse the archives: </td>
            <td><a href="https://lists.domain.org/archives/@@ml_name@@/">here</a></td>
          </tr>
          <tr>
            <td>Subscribe to the digest: </td>
            <td><a href="mailto:@@ml_name@@+subscribe-digest@domain.org" title="Subscribe to the digest of this list">@@ml_name@@+subscribe-digest@domain.org</a></td>
          </tr>
          <tr>
            <td>Unsubscribe to the digest: </td>
            <td><a href="mailto:@@ml_name@@+unsubscribe-digest@domain.org" title="Unsubscribe to this list">@@ml_name@@+unsubscribe-digest@domain.org</a></td>
          </tr>
          <tr>
            <td>Subscribe: </td>
            <td><a href="mailto:@@ml_name@@+subscribe@domain.org" title="Subscribe to this list">@@ml_name@@+subscribe@domain.org</a></td>
          </tr>
          <tr>
            <td>Unsubscribe: </td>
            <td><a href="mailto:@@ml_name@@+unsubscribe@domain.org" title="Unsubscribe to this list">@@ml_name@@+unsubscribe@domain.org</a></td>
          </tr>
          <tr>
            <td>Subscribe without receiving mails: </td>
            <td><a href="mailto:@@ml_name@@+subscribe-nomail@domain.org" title="Subscribe to this list">@@ml_name@@+subscribe-nomail@domain.org</a></td>
          </tr>
          <tr>
            <td>Unsubscribe without receiving mails: </td>
            <td><a href="mailto:@@ml_name@@+unsubscribe-nomail@domain.org" title="Subscribe to this list">@@ml_name@@+unsubscribe-nomail@domain.org</a></td>
          </tr>
        </table>
      </center>
      <hr/>
      <form action="/action" method="post">
        <p>Subscribe or unsubscribe online directly:</p>
        <label for="email">Your email address: </label>
        <input type="text" name="email" id="email" placeholder="foo@bar.net"/><br/>
        <input type="hidden" name="ml" value="@@ml_name@@"/>
        <input type="Submit" name="Subscribe" value="Subscribe"/><input type="Submit" name="Unsubscribe" value="Unsubscribe"/>
      </form>
    </main>
    <footer>
generated by <a href="@@mw_url@@">@@mw_name@@</a>
    </footer>
  </body>
</html>

How subscription works

The (un)subscription will write to a temporary file in /var/spool/mlmmj-webview/{subscribe,unsubscribe}

It expects a script to on regular basis have a look at this location on regular basis (for example via crontab.

here is an example of this script:

#!/bin/sh
set -eu

tmpdir=/usr/local/mlmmj/tmp/
mls=/usr/local/mlmmj/lists
tml=$(mktemp -d ${tmpdir}/subscribe.XXXXX)

for f in $(find /var/spool/mlmmj-webview/subscribe -type f); do
        ml=$(head -1 $f)
        email=$(tail -1 $f | tr -d '[:space:]')
        testemail=$(tail -1 $f | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
        rm -f $f
        case $testemail in
        *@domain.org)
                awk -v mail="${testemail%@domain.org}" 'BEGIN { found=1 } $1 == mail { found=0; exit } END { exit found }' /usr/local/mlmmj/virtual && continue
                ;;
        esac
        if [ -d ${mls}/${ml} ]; then
                echo $email >> ${tml}/${ml}
        fi
done
for f in $(find ${tml} -type f); do
        for m in $(sort -u ${f}); do
                /usr/local/bin/mlmmj-sub -L ${mls}/${f##*/} -a $m -C
        done
done
rm -rf "${tml}"

tml=$(mktemp -d ${tmpdir}/unsubscribe.XXXXX)

for f in $(find /var/spool/mlmmj-webview/unsubscribe -type f); do
        ml=$(head -1 $f)
        email=$(tail -1 $f | tr -d '[:space:]')
        testemail=$(tail -1 $f | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
        rm -f $f
        case $testemail in
        *@domain.org)
                awk -v mail="${testemail%@domain.org}" 'BEGIN { found=1 } $1 == mail { found=0; exit } END { exit found }' /usr/local/mlmmj/virtual && continue
                ;;
        esac
        if [ -d ${mls}/${ml} ]; then
                echo $email >> ${tml}/${ml}
        fi
done
for f in $(find ${tml} -type f); do
        for m in $(sort -u ${f}); do
                /usr/local/bin/mlmmj-unsub -L ${mls}/${f##*/} -a $m -C
        done
done
rm -rf "${tml}"

a crontab configuration could be for example added in /usr/local/etc/cron.d/mlmmj-webview

@120 mlmmj /usr/local/mlmmj/bin/mlsubscriptions.sh