aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Lionel <lionel@les-miquelots.net>2021-06-23 14:28:20 +0100
committerMiquel Lionel <lionelmiquel@sfr.fr>2021-06-23 14:32:18 +0100
commit3da6985b6b9598e8fb4b5f71e09c4460c23d4255 (patch)
tree0843525115c4b58ab9149ed512546ff7cc4293ef
parent3ba254bbaf0be04c237c5aae5dfcb43538202dc2 (diff)
downloadgpigeon-3da6985b6b9598e8fb4b5f71e09c4460c23d4255.tar.gz
gpigeon-3da6985b6b9598e8fb4b5f71e09c4460c23d4255.zip
Fix auto deletion flow in link-tmpl-template.cgi
- The file auto-deletion flow was *inside* the HAS_MAILSERVER check... oops, fixing that - fixing the indenting in the same file, it was a clusterfuck (still is but way less). - removed an useless for(1) in ValidCookie function in gpigeon-template.cgi. - Makefile change: I trust more the GNUPGHOME variable than the --homedir options of gpg for importing a key and creating a GPG directory at the same time.
-rw-r--r--Makefile6
-rwxr-xr-xgpigeon-template.cgi6
-rw-r--r--link-tmpl-template.cgi80
3 files changed, 45 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index 98a8a8e..a31c7df 100644
--- a/Makefile
+++ b/Makefile
@@ -136,9 +136,9 @@ gpigeon: gpigeon-template.cgi link-tmpl-template.cgi
@printf "\nDone preparing files. You can now type\nsudo make install\nin your terminal.\n"
install:
- mkdir -p $(DESTDIR)$(COOKIES_DIR)
- mkdir -m700 -p $(DESTDIR)$(_GPG_HOMEDIR)
- gpg --homedir "$(DESTDIR)$(_GPG_HOMEDIR)" --import gpg.txt; \
+ mkdir -p $(DESTDIR)$(COOKIES_DIR);
+ mkdir -m700 -p $(DESTDIR)$(_GPG_HOMEDIR);
+ GNUPGHOME="$(DESTDIR)$(_GPG_HOMEDIR)" gpg --import gpg.txt; \
mkdir -p $(DESTDIR)$(WWWPREFIX)/cgi-bin/l
install -Dm700 gpigeon.cgi $(DESTDIR)$(GPIGEON_PATH)
install -Dm600 link-tmpl.cgi $(DESTDIR)$(LINK_TEMPLATE_PATH)
diff --git a/gpigeon-template.cgi b/gpigeon-template.cgi
index 9f9dc4c..529c589 100755
--- a/gpigeon-template.cgi
+++ b/gpigeon-template.cgi
@@ -1,4 +1,4 @@
-#! /usr/bin/perl -wT
+#! /usr/bin/perl -T
use warnings;
use strict;
@@ -26,9 +26,7 @@ sub ValidCookie {
my $login_cookiefile = "$dir/$filename.txt";
if (-e $login_cookiefile){
open my $in, '<', $login_cookiefile or die "can't read file: $!";
- for(1){
- my $cookie_line = readline $in;
- }
+ my $cookie_line = readline $in;
close $in;
if (not defined $cookie_line){
return;
diff --git a/link-tmpl-template.cgi b/link-tmpl-template.cgi
index b2fe3b3..2984e9f 100644
--- a/link-tmpl-template.cgi
+++ b/link-tmpl-template.cgi
@@ -36,48 +36,48 @@ elsif (defined $length_msg_form and $length_msg_form eq 0 ){
}
else {
if (defined $length_msg_form and $ENV{REQUEST_METHOD} eq 'POST'){
- $msg_form =~ tr/\r//d;
- my $gpg = new GPG(gnupg_path => "/usr/bin", homedir => $GPG_HOMEDIR);
- $enc_msg = $gpg->encrypt("$linkuser:\n\n$msg_form", $mymail_gpgid) or die $gpg->error();
+ $msg_form =~ tr/\r//d;
+ my $gpg = new GPG(gnupg_path => "/usr/bin", homedir => $GPG_HOMEDIR);
+ $enc_msg = $gpg->encrypt("$linkuser:\n\n$msg_form", $mymail_gpgid) or die $gpg->error();
- if ($HAS_MAILSERVER){
- undef $mymailaddr_escaped;
- use Mail::Sendmail;
- my %mail = ( To => "$mymailaddr"
- From => "$mailsender"
- Subject => '.'
- Message => "$enc_msg\n"
- );
- sendmail(%mail) or die $Mail::Sendmail::error;
- }
- else {
- use Net::SMTP;
- use Net::SMTPS;
- my $smtp = Net::SMTPS->new($mailsender_smtp, Port => $mailsender_port, doSSL => 'ssl', Debug_SSL => 0);
- my $mymailaddr_escaped = EscapeArobase{$mymailaddr};
- my $mailsender_escaped = EscapeArobase($mailsender);
+ if ($HAS_MAILSERVER){
+ undef $mymailaddr_escaped;
+ use Mail::Sendmail;
+ my %mail = ( To => "$mymailaddr"
+ From => "$mailsender"
+ Subject => '.'
+ Message => "$enc_msg\n"
+ );
+ sendmail(%mail) or die $Mail::Sendmail::error;
+ }
+ else {
+ use Net::SMTP;
+ use Net::SMTPS;
+ my $smtp = Net::SMTPS->new($mailsender_smtp, Port => $mailsender_port, doSSL => 'ssl', Debug_SSL => 0);
+ my $mymailaddr_escaped = EscapeArobase{$mymailaddr};
+ my $mailsender_escaped = EscapeArobase($mailsender);
- $smtp->auth($mailsender, $mailsender_pw) or die;
- $smtp->mail($mailsender) or die "Net::SMTP module has broke: $!.";
- if ($smtp->to($mymailaddr)){
- $smtp->data();
- $smtp->datasend("From: $mailsender_escaped\n");
- $smtp->datasend("To: $mymailaddr_escaped\n");
- $smtp->datasend("Subject: .\n");
- $smtp->datasend("\n");
- $smtp->datasend("$enc_msg\n");
- $smtp->dataend();
- }
- else {
- die $smtp->message();
- }
- my $f = $0;
- if ($f =~ /^([\w]+)$/){
- unlink "$1";
- }
- print "Location: /merci/index.html\n\n";
- }
- }
+ $smtp->auth($mailsender, $mailsender_pw) or die;
+ $smtp->mail($mailsender) or die "Net::SMTP module has broke: $!.";
+ if ($smtp->to($mymailaddr)){
+ $smtp->data();
+ $smtp->datasend("From: $mailsender_escaped\n");
+ $smtp->datasend("To: $mymailaddr_escaped\n");
+ $smtp->datasend("Subject: .\n");
+ $smtp->datasend("\n");
+ $smtp->datasend("$enc_msg\n");
+ $smtp->dataend();
+ }
+ else {
+ die $smtp->message();
+ }
+ }
+
+ if ($0 =~ /([\w]+)\.cgi$/){
+ unlink "$1.cgi";
+ }
+ print "Location: /merci/index.html\n\n";
+ }
}
print "Content-type: text/html", "\n\n";
print qq{<!DOCTYPE html>