#! /usr/bin/perl -T
# gpigeon.cgi: generate links for someone to send you GPG encrypted messages via a one time form.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Copyright (c) 2020-2021, Miquel Lionel
use warnings;
use strict;
use DBI;
use Email::Valid;
use CGI qw(param);
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use Crypt::Argon2 qw(argon2id_verify);
use File::Path qw(mkpath rmtree);
use File::stat;
use String::Random;
delete @ENV{qw(IFS PATH CDPATH BASH_ENV)};
$ENV{'PATH'} = q{bin_path_goes_here};
my $rIP = $ENV{REMOTE_ADDR};
my $uagent = $ENV{HTTP_USER_AGENT};
my %text_strings = (
addr => 'Address',
addr_ok => 'is valid!',
addr_nok => 'is not valid !',
addr_unknown => 'Unknown',
create_link_btn => 'Create link',
create_invite_btn => 'Create invite',
cookie_problems =>'You got a cookie problem. Clean them and log in again',
delete_link_btn_text => 'Delete',
delete_links_btn_text => 'Delete all links',
disconnect_btn_text => 'Disconnect',
here => 'here',
landingpage_title => 'GPIGEON - Log in',
logout_btn_text => 'Logout',
loginbtn => 'Log in',
link_asker_field_label => "Asker's mail :",
link_del_ok => 'Successful removal !',
link_legend_textarea =>'Type your message below :',
link_ok_for => 'Generated a link for',
link_del_failed => 'Deletion failed and here is why : ',
link_generated_ok => "Here's the link",
mailto_body => 'Your link is ',
mailto_subject => 'Link to your one time GPG messaging form',
incorrect_ids => 'Username/password combination is incorrect. Try again.',
password_label => 'Password',
refresh_btn => 'Refresh',
theader_link => 'Link',
theader_for => 'For',
theader_deletion => 'Deletion',
theader_cdate => 'Created on',
username_label => 'Username',
web_title => 'GPIGEON.CGI - Main',
web_greet_msg => 'Hi and welcome. What will you do today ?',
);
sub DbGetLine {
my ($dbh, $query) = @_;
my $prep = $dbh->prepare( $query );
my $exec = $prep->execute() or die $DBI::errstr;
if ($exec < 0){
print $DBI::errstr;
}
while (my @rows = $prep->fetchrow_array()) {
my $row = $rows[0];
return $row;
}
}
sub GetFileTable {
my ($dir ,$hidden_loginfield) = @_;
my @table = ();
opendir my $dir_hnd, "$dir" or die "[GetFileTable function] Can't open $dir: $!";
while (readdir $dir_hnd) {
if ($_ ne '.' and $_ ne '..'){
my $linkfile_fn = $_;
my $linkstats = stat("$dir/$linkfile_fn");
my $mtime = scalar localtime $linkstats->mtime;
my $link_asker = undef;
if (open my $f_hnd , '<', "$dir/$linkfile_fn"){
for (1..2){
$link_asker = readline $f_hnd;
$link_asker =~ s/q\{(.*?)\}//i;
$link_asker = $1;
}
close $linkfile_handle;
my $for_field_body = qq{$link_asker};
if (not defined $link_asker){
$for_field_body = $text_strings{addr_unknown};
}
#create links table html
push @table,
qq{