fixed some bugs on prod server regarding paths; config and sqlite files now reside one directory above webroot

This commit is contained in:
eclipse 2025-03-19 13:41:11 +01:00
parent a22afad927
commit 900f1f0a63
5 changed files with 33 additions and 27 deletions

View File

@ -1,7 +1,8 @@
<?php <?php
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/ // inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
require(dirname(__FILE__) . '/../functions.php'); $webroot = $_SERVER['DOCUMENT_ROOT'];
require($webroot . '/functions.php');
$successURL = '/newsletter/danke.html'; $successURL = '/newsletter/danke.html';
$errorURL = '/error.html'; $errorURL = '/error.html';

View File

@ -7,7 +7,8 @@ if ( $_POST['address'] != '' ) {
exit; exit;
} }
require(dirname(__FILE__) . '/../functions.php'); $webroot = $_SERVER['DOCUMENT_ROOT'];
require($webroot . '/functions.php');
$successURL = '/success.html'; $successURL = '/success.html';
$errorURL = '/error.html'; $errorURL = '/error.html';
@ -23,12 +24,12 @@ $body = [
$mailContents = [ $mailContents = [
'subject' => 'Diese Nachricht kam ueber das Kontaktformular von t-r.de', 'subject' => 'Diese Nachricht kam ueber das Kontaktformular von t-r.de',
'bodyText' => implode("\n\n", $body), 'bodyText' => implode("\n\n", $body),
'fromAddress' => '***REMOVED***', //'kontakt@tobias-radloff.de', 'fromAddress' => $general['notificationAddress'],
'fromName' => 'Tobias Radloffs Kontaktformular' 'fromName' => 'Tobias Radloffs Kontaktformular'
]; ];
try { try {
SendEmail($_POST['email'], $mailContents); SendEmail($general['notificationAddress'], $mailContents);
} catch (Exception $e) { } catch (Exception $e) {
GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
} }

View File

@ -9,30 +9,21 @@ require $dname . '/Exception.php';
require $dname . '/PHPMailer.php'; require $dname . '/PHPMailer.php';
require $dname . '/SMTP.php'; require $dname . '/SMTP.php';
$webroot = $_SERVER['DOCUMENT_ROOT'];
// read ini file // read ini file
$ini_file = '../../config.ini'; $ini_file = $webroot . '/../config.ini';
$ini = parse_ini_file($ini_file, TRUE); $ini = parse_ini_file($ini_file, TRUE);
// general constants // general constants
$general = [ $general = $ini['general'];
// string concatenated with email address to create a non-recreatable md5 hash $general['sql'] = [
'uniqueKey' => $ini['hash']['uniqueKey'], // works like password salt 'create_table' => 'CREATE TABLE IF NOT EXISTS subscribers (id INTEGER PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT);',
// file name of confirm script 'create_record' => 'INSERT INTO subscribers(email, name) VALUES(:e, :n);',
'confirmScript' => '/newsletter/confirm.php', 'read_record' => 'SELECT 1 FROM subscribers WHERE email = :e;',
// status code to be used when redirection to success or error page 'update_record' => '',
'statusCode' => 'HTTP/1.1 303 See Other', 'delete_record' => 'DELETE FROM subscribers WHERE email = :e;'
// array of SQL statements used
'sql' => [
'create_table' => 'CREATE TABLE IF NOT EXISTS subscribers (id INTEGER PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT);',
'create_record' => 'INSERT INTO subscribers(email, name) VALUES(:e, :n);',
'read_record' => 'SELECT 1 FROM subscribers WHERE email = :e;',
'update_record' => '',
'delete_record' => 'DELETE FROM subscribers WHERE email = :e;'
],
'notificationAddress' => 'webseite@tobias-radloff.de'
]; ];
// complete site URL
$general['siteURL'] = $ini['general']['protocol'] . '://' . $ini['general']['domain'];
$smtp = $ini['smtp']; $smtp = $ini['smtp'];
$db = $ini['db']; $db = $ini['db'];
@ -45,7 +36,14 @@ function GetConfirmationHash($confEmail) {
// connects to database and returns PDO object // connects to database and returns PDO object
function getPDO($dbType = 'sqlite') { function getPDO($dbType = 'sqlite') {
global $db; global $db;
return new \PDO($db[$dbType]['dsn']); if ( $dbType == 'sqlite' ) {
global $webroot;
error_log('my dsn is ' . 'sqlite:' . $webroot . '/../' . $db['sqlite_file']);
return new \PDO('sqlite:' . $webroot . '/../' . $db['sqlite_file']);
}
// error
return NULL;
} }
// Sends an email to single recipient with subject, body and sender info specified in an array // Sends an email to single recipient with subject, body and sender info specified in an array

View File

@ -1,12 +1,17 @@
<?php <?php
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/ // inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
require(dirname(__FILE__) . '/../functions.php'); $webroot = $_SERVER['DOCUMENT_ROOT'];
require($webroot . '/functions.php');
$successURL = '/success.html'; $successURL = '/success.html';
$errorURL = '/error.html'; $errorURL = '/error.html';
$err = 'Anmeldung fehlgeschlagen'; $err = 'Anmeldung fehlgeschlagen';
// file name of confirm script
$confirmScript = '/newsletter/confirm.php';
// body template for confirmation email // body template for confirmation email
$body = [ $body = [
'Hallo!', 'Hallo!',
@ -47,7 +52,7 @@ try {
// build and add link to // build and add link to
$confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]); $confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]);
$confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery; $confirmLink = $general['site_url'] . $confirmScript . "?" . $confirmQuery;
$mailContents['bodyHTML'] = str_replace('%Placeholder%', "<a href=\"{$confirmLink}\">Anmeldung bestätigen</a>", $mailContents['bodyHTML']); $mailContents['bodyHTML'] = str_replace('%Placeholder%', "<a href=\"{$confirmLink}\">Anmeldung bestätigen</a>", $mailContents['bodyHTML']);
$mailContents['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyText']); $mailContents['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyText']);

View File

@ -1,6 +1,7 @@
<?php <?php
require(dirname(__FILE__) . '/../functions.php'); $webroot = $_SERVER['DOCUMENT_ROOT'];
require($webroot . '/functions.php');
$successURL = '/success.html'; $successURL = '/success.html';
$errorURL = '/error.html'; $errorURL = '/error.html';