From 1ad482978dd421c5b763a5330f1ded275099e09c Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Thu, 18 Jan 2018 02:26:14 -0500 Subject: [PATCH] Use __DIR__ magic constant instead of environment variable --- .env.example | 2 -- getmappings.php | 4 ++-- redirect.php | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 1811723..6551a8d 100644 --- a/.env.example +++ b/.env.example @@ -6,8 +6,6 @@ KEY='' # Delivery address is the original email before the "@". e.g. if delivering to "support_mt@mayfirst.org", set this to "support_mt" DELIVERY_ADDRESS='support_mt' CATCHALL_PROJECT_NAME='catch' -# The path to the root directory containing this file. -FILEPATH='/usr/local/bin/redirect_test' # Leave these three blank for false. DEBUG_MODE= DRY_RUN= diff --git a/getmappings.php b/getmappings.php index 7524221..7360505 100755 --- a/getmappings.php +++ b/getmappings.php @@ -20,7 +20,7 @@ $membershipMapping = getUserMemberships($userList, $client); writeUsers($projectsById, $membershipMapping); function writeDomains($projectsByDomain) { - $domainHandle = fopen('./data/domainmap.csv', 'w'); + $domainHandle = fopen(__DIR__ . '/data/domainmap.csv', 'w'); foreach ($projectsByDomain as $domain => $identifier) { fwrite ($domainHandle, "$domain,$identifier\n"); } @@ -28,7 +28,7 @@ function writeDomains($projectsByDomain) { } function writeUsers($projectsById, $membershipMapping) { - $userHandle = fopen('./data/usermap.csv', 'w'); + $userHandle = fopen(__DIR__ . '/data/usermap.csv', 'w'); foreach ($membershipMapping as $email => $projectId) { fwrite ($userHandle, "$email,{$projectsById[$projectId]}\n"); } diff --git a/redirect.php b/redirect.php index 53769aa..5206679 100755 --- a/redirect.php +++ b/redirect.php @@ -155,12 +155,11 @@ function SendToMailHandler($input, $params) { //See if this email address is associated with a particular project function ParseSenderEmail($from) { - $filePath = getenv('FILEPATH'); $project = $email = NULL; if(preg_match("/\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b/i", $from, $matches)) { $email = $matches[1]; } - if (($handle = fopen($filePath . "/" . "data/usermap.csv", 'r')) !== FALSE) { + if (($handle = fopen(__DIR__ . "/" . "data/usermap.csv", 'r')) !== FALSE) { while (($data = fgetcsv($handle, 1000)) !== FALSE) { $users[$data[0]] = $data[1]; } @@ -172,12 +171,11 @@ function ParseSenderEmail($from) { } function ParseSenderDomain($email) { - $filePath = getenv('FILEPATH'); $domain = $project = NULL; if(preg_match("/@(.*)\b/", $email, $matches)) { $domain = $matches[1]; } - if (($handle = fopen($filePath . "/" . "data/domainmap.csv", 'r')) !== FALSE) { + if (($handle = fopen(__DIR__ . "/" . "data/domainmap.csv", 'r')) !== FALSE) { while (($data = fgetcsv($handle, 1000)) !== FALSE) { $domains[$data[0]] = $data[1]; }