From 900f1f0a63f05d54e475fb410dde4d7bb4dc45fc Mon Sep 17 00:00:00 2001 From: eclipse Date: Wed, 19 Mar 2025 13:41:11 +0100 Subject: [PATCH] fixed some bugs on prod server regarding paths; config and sqlite files now reside one directory above webroot --- content/php/confirm.php | 3 ++- content/php/contact.php | 7 ++++--- content/php/functions.php | 38 ++++++++++++++++++------------------- content/php/subscribe.php | 9 +++++++-- content/php/unsubscribe.php | 3 ++- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/content/php/confirm.php b/content/php/confirm.php index 77dcaef..d87a476 100644 --- a/content/php/confirm.php +++ b/content/php/confirm.php @@ -1,7 +1,8 @@ 'Diese Nachricht kam ueber das Kontaktformular von t-r.de', 'bodyText' => implode("\n\n", $body), - 'fromAddress' => '***REMOVED***', //'kontakt@tobias-radloff.de', + 'fromAddress' => $general['notificationAddress'], 'fromName' => 'Tobias Radloffs Kontaktformular' ]; try { - SendEmail($_POST['email'], $mailContents); + SendEmail($general['notificationAddress'], $mailContents); } catch (Exception $e) { GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); } diff --git a/content/php/functions.php b/content/php/functions.php index ca70061..39e9d54 100644 --- a/content/php/functions.php +++ b/content/php/functions.php @@ -9,30 +9,21 @@ require $dname . '/Exception.php'; require $dname . '/PHPMailer.php'; require $dname . '/SMTP.php'; +$webroot = $_SERVER['DOCUMENT_ROOT']; + // read ini file -$ini_file = '../../config.ini'; +$ini_file = $webroot . '/../config.ini'; $ini = parse_ini_file($ini_file, TRUE); // general constants -$general = [ - // string concatenated with email address to create a non-recreatable md5 hash - 'uniqueKey' => $ini['hash']['uniqueKey'], // works like password salt - // file name of confirm script - 'confirmScript' => '/newsletter/confirm.php', - // status code to be used when redirection to success or error page - 'statusCode' => 'HTTP/1.1 303 See Other', - // 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' +$general = $ini['general']; +$general['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;' ]; -// complete site URL -$general['siteURL'] = $ini['general']['protocol'] . '://' . $ini['general']['domain']; $smtp = $ini['smtp']; $db = $ini['db']; @@ -45,7 +36,14 @@ function GetConfirmationHash($confEmail) { // connects to database and returns PDO object function getPDO($dbType = 'sqlite') { 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 diff --git a/content/php/subscribe.php b/content/php/subscribe.php index a30ea58..1c3015f 100644 --- a/content/php/subscribe.php +++ b/content/php/subscribe.php @@ -1,12 +1,17 @@ GetConfirmationHash($email), 'e' => $email]); -$confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery; +$confirmLink = $general['site_url'] . $confirmScript . "?" . $confirmQuery; $mailContents['bodyHTML'] = str_replace('%Placeholder%', "Anmeldung bestätigen", $mailContents['bodyHTML']); $mailContents['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyText']); diff --git a/content/php/unsubscribe.php b/content/php/unsubscribe.php index c308d41..3d7946f 100644 --- a/content/php/unsubscribe.php +++ b/content/php/unsubscribe.php @@ -1,6 +1,7 @@