Dies ist ein leichtgewichtiges Proof-of-Concept-Kontaktformular für selbst gehostete statische Websites.
Die kanonische Quelle des Knowbl-Clusters wird auf https://git.knowbl.co/dev/log-based-contact-form/ gehostet.
mail
für Debian/Ubuntu. /submit/
) muss ein leerer Ordner sein, sonst werden alle legitimen Abfragen an /submit/ umgeleitet.Fügen Sie im http-Block Ihres Nginx-Servers das Protokollformat für Ihre spezifische Konfiguration unten im Block ein, aber vor den ersten Serverblöcken. Weniger wird empfohlen.
log_format contactstatic ' $time_local | $request ' ;
Siehe Platzierungsort nginx-exmaple.conf
.
Fügen Sie im Serverblock Ihres Nginx-Servers den Speicherort Ihrer Aktion (in diesem Fall /submit/
) innerhalb des Formulars ein.
location ~* /submit/(.*)$ {
access_log /home/example/logs/static-contact-access.log contactstatic;
error_log /home/example/logs/static-contact-error.log;
return https://example.com/;
}
Dadurch wird der Besucher zum Stammverzeichnis zurückgeführt. Passen Sie es an Ihre spezifischen Bedürfnisse an.
Siehe Platzierungsort nginx-exmaple.conf
.
Fügen Sie das Formular auf Ihrer Website hinzu. Stylen Sie es nach Bedarf.
< form action =" /submit/ " method =" GET " >
< label for =" name " > Name: </ label >
< input type =" text " name =" name " required =" yes " placeholder =" What can I call you? " >
< label for =" email " > Email: </ label >
< input type =" email " name =" email " required =" yes " placeholder =" [email protected] " >
< label for =" message " > Short message: </ label >
< textarea type =" message " name =" message " required =" yes " placeholder =" What do you want to say (in 140 characters)? " maxlength =" 140 " > </ textarea >
< input type =" submit " value =" Send a message " >
</ form >
Fügen Sie so viele <input>
wie nötig hinzu.
GET ist als Methode erforderlich, da sie zum Parsen innerhalb der Protokolle benötigt wird.
Es gibt verschiedene Möglichkeiten, Ihre eingehenden Formularbeiträge zu überwachen.
Direkter Blick auf die Live-Log-Datei.
tail -f /home/example/logs/access.log
Senden Sie Anfragen an eine E-Mail-Adresse.
cd /home/example/
nano log-based-static-contact-form-emailer.sh
#! /bin/bash
EMAIL= " [email protected] "
EMAILSUBJECT= " Contact form "
LOG= " /home/example/logs/static-contact-access.log "
CRON= " /home/example/logs/example-cron.log "
# ## DO NOT EDIT BELOW ###
NOW= $( date + " Form sent to $EMAIL -- %Y-%m-%d %H:%M:%S -- " ) ;
if [ ! -f $LOG ] ;
then
printf " . " >> $CRON
else
mail -s " $EMAILSUBJECT " $EMAIL < $LOG ;
printf " n n $NOW n n " >> $CRON
fi
Hinweis: Je nachdem, wer Ihr Formular ausfüllt (Bösewichte?), möchten Sie möglicherweise eine Benachrichtigung senden, dass neue Kontaktformularinformationen vorliegen, anstatt das gesamte Protokoll im Text einer E-Mail zu senden.
chmod +x log-based-static-contact-form-emailer.sh
crontab -e
Fügen Sie es am Ende der Crontab hinzu
0 9-17 * * 1-5 /var/log/log-based-form.sh
Dieser Cron ist für jede volle Stunde von 9:00 bis 17:00 Uhr, Montag bis Freitag, eingestellt. Fühlen Sie sich frei, etwas einzustellen, das besser zu Ihrem eigenen Setup passt.
Direktes Feedback zum HackerNews-Beitrag kann hier gegeben werden
https://news.ycombinator.com/item?id=13358753
Oder bringen Sie ein Problem zur Sprache
https://github.com/knowbl/log-based-static-contact-form/issues
Wenn dies für Sie von Nutzen ist, spenden Sie bitte an die EFF. Ich arbeite dort nicht, aber sie leisten fantastische Arbeit in der Branche
https://eff.org/donate/