ONO::Scripts::Trigger

package ONO::Scripts::Trigger;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# 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.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################


use strict;

use ONO::Lib::DateTime::ToolBox;
use ONO::Lib::Web::Cookie;

###############################################################################
# RUN
###############################################################################

sub run {

#: This module catches HTML triggers, it is currently used to check if users
#: consent using /displaying external, third party content on a website.
#: Allowing / disallowing external content will store a cookie in order to
#: remember a user's choice. This is required for GDPR compliance.

my $REQ = $ENV{'REQUEST_URI'};
$REQ =~ s~^(.*)/cgi-bin/~/cgi-bin/~;

my (
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp
) = ONO::Lib::DateTime::ToolBox->get;

my $STATUS = 0;

my (%vars,$COOKIE);

if ($REQ =~ s~/cgi-bin/ono/ajax/trigger.pl\?~~) {

if ($REQ =~ s~setcookie=$year$mon$mday-~~) {

if ($REQ =~ m~^(allow|disallow)-external-content-(.*?)$~) {

my $MODE = $1;
$REQ = lc $2;

if ($REQ =~ /[a-z]/ && $REQ =~ /\./ && length $REQ > 3 && length $REQ < 128) {

$STATUS = 1;

if ($MODE eq "allow") {
$COOKIE = ONO::Lib::Web::Cookie->make("ono_always_allow_external_content_$REQ","true","30d",\%vars);
}

if ($MODE eq "disallow") {
$COOKIE = ONO::Lib::Web::Cookie->make("ono_always_allow_external_content_$REQ","true","expire",\%vars);
}

}

}

}

}

print "Content-Type: text/plain\n$COOKIE\n";

print "ONO TriggerGateway: nothing_to_say for '$REQ' on '$year$mon$mday' [$STATUS]";

return "";

}

###############################################################################
# end of script
###############################################################################

1;

__END__