aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Lionel <lionel@les-miquelots.net>2021-07-14 23:09:21 +0100
committerMiquel Lionel <lionelmiquel@sfr.fr>2021-07-14 23:20:32 +0100
commit6a318b7833adf2777c7041017c37e6e480b3619e (patch)
treee20f565385cd2a9f2546dcdac6f9300481c4725f
parentd49a7581500af58f929d808d3e052aa1cd526d21 (diff)
downloadgpigeon-6a318b7833adf2777c7041017c37e6e480b3619e.tar.gz
gpigeon-6a318b7833adf2777c7041017c37e6e480b3619e.zip
added crude file upload possibilities
-rw-r--r--Makefile9
-rw-r--r--README.md5
-rw-r--r--link-tmpl-template.cgi110
-rw-r--r--nginx-example.conf2
-rw-r--r--styles.css1
5 files changed, 81 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 000e898..4900467 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ gpigeon: gpigeon-template.cgi link-tmpl-template.cgi
exit 1; \
fi
@if test -n '$(_GPGID)'; then \
- printf "Your GPG 0xlong id is ${BOLD}$(_GPGID)${STOP}\n";\
+ printf "Your GPG 0xlong id is ${BOLD}0x$(_GPGID)${STOP}\n";\
sed -e 's|gpgid_goes_here|0x$(_GPGID)|g' -i link-tmpl.cgi;\
else \
printf "${RED}It seems that no public GPG key is tied to ${BOLD}$(MYMAIL_ADDR)${STOP}\n";\
@@ -71,6 +71,13 @@ gpigeon: gpigeon-template.cgi link-tmpl-template.cgi
printf "\n${RED}The path for the link template wasn't set in your config.mk. Fix that.${STOP}" ;\
exit 1;\
fi
+ @if test -n '$(UPLOAD_TMPDIR)'; then \
+ printf "\nUploaded files will be temporary stored at ${BOLD}$(UPLOAD_TMPDIR)${STOP}"; \
+ sed -e 's|tmp_dir_goes_here|$(UPLOAD_TMPDIR)|g' -i gpigeon.cgi; \
+ else \
+ printf "\n${RED}The temporary directory for uploaded files wasn't set in your config.mk. Fix that.${STOP}" ;\
+ exit 1;\
+ fi
@if test -n '$(ARGON2ID_HASH)'; then\
printf "\nThe argon2id hash is ${BOLD}${ARGON2ID_HASH}${STOP}\n"; \
diff --git a/README.md b/README.md
index 8be7b9a..1109df8 100644
--- a/README.md
+++ b/README.md
@@ -37,10 +37,7 @@ You will need perl and the following modules and my perl version is **v5.34.0**,
- Email::Valid
- String::Random
-Having a webserver with CGI support or a separate CGI engine is needed. I'm using
-nginx and fcgiwrap.
-A note on **Net::SMTP** and **Net:SMTPS** dependencies: if you have a well configured mailserver on the same server you plan to install gpigeon on, you should set the `HAS_MAILSERVER`
-variable in `config.mk` to 1.
+Having a webserver with CGI support or a separate CGI engine is needed. I'm using nginx and fcgiwrap.
Installation
diff --git a/link-tmpl-template.cgi b/link-tmpl-template.cgi
index 87b4b1a..49e5b47 100644
--- a/link-tmpl-template.cgi
+++ b/link-tmpl-template.cgi
@@ -1,6 +1,5 @@
#! /usr/bin/perl -wT
my $linkuser = q{link_user};
-my $linkfilename = q{link_filename};
# link-tmpl.cgi : self-destructing message form to send yourself GPG
# encrypted messages. Part of gpigeon.
@@ -21,17 +20,11 @@ my $linkfilename = q{link_filename};
use warnings;
use strict;
-use GPG;
use CGI qw(param);
-$ENV{'PATH'}="/usr/bin";
delete @ENV{qw(IFS PATH CDPATH BASH_ENV)};
-
-sub EscapeArobase {
- my $escapedmailaddress = shift;
- $escapedmailaddress =~ s/@/\\@/;
- return $escapedmailaddress;
-}
+$ENV{'PATH'}="/usr/bin";
+$ENV{TMPDIR} = q{tmp_dir_goes_here};
my $HAS_MAILSERVER = q{has_mailserver_goes_here};
my $msg_form_char_limit = q{msg_char_limit_goes_here};
@@ -45,50 +38,82 @@ my $GPG_HOMEDIR = q{gpg_homedir_goes_here};
my $cgi_query_get = CGI->new;
my $msg_form = $cgi_query_get->param('msg');
my $length_msg_form = length $msg_form;
-my ($enc_msg, $error_processing_msg) = undef;
+my ($smtp, $enc_msg, $error_processing_msg) = undef;
if (defined $length_msg_form and $length_msg_form > $msg_form_char_limit){
- $error_processing_msg = qq{<span style="color:red"><b>Cannot send message : message length must be under $msg_form_char_limit characters.</b></span>};
+ $error_processing_msg = qq{<span id="failure"><b>Cannot send message : message length must be under $msg_form_char_limit characters.</b></span>};
}
elsif (defined $length_msg_form and $length_msg_form eq 0 ){
- $error_processing_msg = qq{<span style="color:red"><b>Cannot send message : message is empty. You can type up to $msg_form_char_limit characters.</b></span>};
+ $error_processing_msg = qq{<span id="failure"><b>Cannot send message : message is empty. You can type up to $msg_form_char_limit characters.</b></span>};
}
else {
if (defined $length_msg_form and $ENV{REQUEST_METHOD} eq 'POST'){
+ use MIME::Entity;
+ use Mail::GPG;
$msg_form =~ tr/\r//d;
- my $gpg = new GPG(gnupg_path => "/usr/bin", homedir => $GPG_HOMEDIR);
+ my $gpgmail = Mail::GPG->new(
+ default_key_id => $mymailaddr,
+ gnupg_hash_init => {homedir => $GPG_HOMEDIR},
+ debug => 0,
+ no_strict_7bit_encoding => 1,
+ );
+ my $mimentity = MIME::Entity->build(
+ From => $mailsender,
+ To => $mailaddr,
+ Subject => '.',
+ Data => ["This is a message from $linkuser:\n\n$msg_form"],
+ Charset => 'utf-8',
+ );
+
$enc_msg = $gpg->encrypt("$linkuser:\n\n$msg_form", $mymail_gpgid) or die $gpg->error();
- if ($HAS_MAILSERVER){
- use Mail::Sendmail;
- my %mail = ( To => "$mymailaddr",
- From => "$mailsender",
- Subject => '.',
- Message => "$enc_msg\n"
+ if (my $fh = $cgi_query_get->upload('file')){
+ my $fullfn = $cgi_query_get->param('file');
+ $fullfn =~ s/^[a-zA-Z_0-9\-\.]/_/g;
+ $fullfn =~ s/__+/_/g;
+ my $fpath = $cgi_query_get->tmpFileName( $fh );
+ my $fsize = -s $fpath;
+ $CGI::POST_MAX = 1024*1024*100; # 100Mo limit
+ if ($fsize > $CGI::POST_MAX){
+ die 'ERROR: File is too big (>100MB).';
+ }
+# my $mimetype = $cgi_query_get->uploadInfo( $fh )->{'Content-Type'};
+# my $lengthf = $cgi_query_get->uploadInfo( $fh )->{'Content-Length'};
+ if (not $mimetype =~ /^([\w]+)\/([\w]+)$/){
+ die 'Unrecognized MIME type of uploaded file.';
+ }
+ $mimentity->attach(
+ Type => $mimetype,
+ Description => 'OpenPGP encrypted attachment',
+ Encoding => 'base64',
+ Path => $fpath,
);
- 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);
+ my $mimentity_encrypted = $gpgmail->mime_encrypt(
+ entity => $mimentity,
+ );
+
+ my $puremime = $mimentity_encrypted->as_string;
+
+ use Net::SMTP;
+ use Net::SMTPS;
+ if ($HAS_MAILSERVER){
+ $smtp = Net::SMTP->new( Host => 'localhost', Debug => 0);
+ }
+ else {
+ $smtp = Net::SMTPS->new($mailsender_smtp, Port => $mailsender_port, doSSL => 'ssl', Debug_SSL => 0);
$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();
- }
+ }
+ $smtp->mail($mailsender) or die "Net::SMTP module has broke: $!.";
+ if ($smtp->to($mymailaddr)){
+ $smtp->data($puremime);
+ $smtp->dataend();
+ $smtp->quit();
+ }
+ else {
+ die $smtp->message();
}
unlink $linkfilename;
@@ -114,8 +139,11 @@ if (defined $error_processing_msg){
printf $error_processing_msg;
}
printf q{
- <br>
- <input type="submit" value="{link_send_btn}">
+ <label for="filechoice" id="msgbelow">
+ (Optional) file upload:
+ <input id="filechoice" type="file" name="file">
+ </label>
+ <input id="sendbtn" type="submit" value="{link_send_btn}">
</form>
</body>
</html> };
diff --git a/nginx-example.conf b/nginx-example.conf
index f3d9252..9f7d355 100644
--- a/nginx-example.conf
+++ b/nginx-example.conf
@@ -36,5 +36,7 @@ server {
add_header X-Frame-Options DENY;
add_header Access-Control-Allow-Origin https://$server_name;
add_header Vary Origin; # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin#cors_and_caching
+
+ client_max_body_size 100m;
}
diff --git a/styles.css b/styles.css
index 7f8770d..ff3687e 100644
--- a/styles.css
+++ b/styles.css
@@ -10,6 +10,7 @@ body{
}
h1, #msgbelow{
+ display:block;
text-align:center;
}