Update API endpoints, add wash certificate handling
Replaced legacy 'nnks.truckwash.dk' endpoint with 'api.truckwash.dk' across the codebase for consistency. Implemented a feature to handle certificate downloads, including file serving and validation. Updated PHP configuration to support additional dependencies like PHPMailer, and introduced necessary route and configuration changes for wash certificate processing.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#echo "Backup script started at $(date)"
|
||||
#echo "Auth key: $auth_key"
|
||||
# Curl the backup script
|
||||
curl -s "https://nnks.truckwash.dk/?internalCronCall=true&script=run&action=cron&auth_key=$auth_key"
|
||||
# shellcheck disable=SC2154
|
||||
curl -s "https://api.truckwash.dk/?internalCronCall=true&script=run&action=cron&auth_key=$auth_key"
|
||||
# Show the script has finished
|
||||
#echo "Backup script finished at $(date)"
|
||||
@@ -105,12 +105,13 @@ class redis implements redis_i
|
||||
public function get_department_name(int $department_id): string|null
|
||||
{
|
||||
// Get the department name
|
||||
$tmp_department = (object)$this->get('department_' . $department_id) ?? null;
|
||||
$tmp_department = $this->get('department_' . $department_id) ?? null;
|
||||
if ($tmp_department === 'IS_EMPTY_OR_NULL' || $tmp_department === null) {
|
||||
return null;
|
||||
}
|
||||
$tmp_department = json_decode($tmp_department);
|
||||
// Return the department name
|
||||
return $tmp_department->name;
|
||||
return $tmp_department->name ?: $tmp_department['name'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,4 +31,19 @@ class wash_certificate_store implements minio_wash_certificates_i
|
||||
{
|
||||
return self::getPresignedUrl('wash_certificate_' . $id . '.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @return string The path to the downloaded file
|
||||
*/
|
||||
public function download(string $file): string
|
||||
{
|
||||
$path = '/tmp/' . $file;
|
||||
$result = self::getS3Client()->getObject([
|
||||
'Bucket' => self::getBucket(),
|
||||
'Key' => $file,
|
||||
'SaveAs' => $path
|
||||
]);
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// Get the file name from the URL
|
||||
$file = $_SERVER['REQUEST_URI'];
|
||||
$file = str_replace('/modules/washcertificates/output/certificates/', '', $file);
|
||||
|
||||
// Download the file from minio, and send it to the client
|
||||
$wash_certificate_store = new \classes\wash_certificate_store();
|
||||
|
||||
// Check if the certificate exists
|
||||
if (!$wash_certificate_store->washCertificateExists($file)) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Download the certificate from the store to /tmp
|
||||
$certificate_path = $wash_certificate_store->download($file);
|
||||
|
||||
// Send the certificate to the client
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: inline; filename="' . $file . '"');
|
||||
header('Content-Length: ' . filesize($certificate_path));
|
||||
readfile($certificate_path);
|
||||
exit;
|
||||
@@ -102,6 +102,12 @@ if (php_sapi_name() === 'cli' || isset($_GET['internalCronCall'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// If the route ends with .php, then require the file_server.php
|
||||
if (str_contains($_SERVER['REQUEST_URI'], '.pdf')) {
|
||||
require_once 'file_server.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Autoload all the routes
|
||||
$router->auto_load_routes(WD . '/routes');
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace routes;
|
||||
|
||||
use traits\route_t;
|
||||
|
||||
class washCertificateRoute
|
||||
{
|
||||
use route_t;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
/** All bookings */
|
||||
$this->get('/modules/washcertificates', function () {
|
||||
// Set the working directory to /modules/washcertificates,
|
||||
// so the output directory is created in the correct location
|
||||
chdir(WD . '/modules/washcertificates');
|
||||
// Run the index.php file
|
||||
require_once 'index.php';
|
||||
exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -22,22 +22,24 @@ http {
|
||||
# Include server block configurations
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
|
||||
|
||||
# Redirect HTTP to HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
server_name nnks.truckwash.dk;
|
||||
server_name api.truckwash.dk;
|
||||
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name nnks.truckwash.dk;
|
||||
server_name api.truckwash.dk;
|
||||
|
||||
|
||||
|
||||
# SSL certificates
|
||||
ssl_certificate /etc/letsencrypt/live/nnks.truckwash.dk/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/nnks.truckwash.dk/privkey.pem;
|
||||
ssl_certificate /etc/letsencrypt/live/api.truckwash.dk/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/api.truckwash.dk/privkey.pem;
|
||||
|
||||
# Enable SSL options
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
@@ -55,8 +57,18 @@ http {
|
||||
|
||||
# Location block for PHP files
|
||||
|
||||
|
||||
location ^~ / {
|
||||
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";
|
||||
add_header Access-Control-Allow-Credentials true;
|
||||
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";
|
||||
return 204;
|
||||
}
|
||||
|
||||
include fastcgi_params;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_index index.php;
|
||||
|
||||
+11
-2
@@ -14,10 +14,10 @@ RUN apt-get update && apt-get install -y \
|
||||
libonig-dev \
|
||||
libxml2-dev \
|
||||
zip \
|
||||
unzip \
|
||||
git \
|
||||
curl \
|
||||
&& docker-php-ext-install mbstring exif pcntl bcmath gd pdo_mysql mysqli
|
||||
libzip-dev \
|
||||
&& docker-php-ext-install mbstring exif pcntl bcmath gd pdo_mysql mysqli zip
|
||||
|
||||
# Copy application files into the container
|
||||
COPY /nginx/app /var/www/html
|
||||
@@ -26,9 +26,18 @@ COPY /nginx/app /var/www/html
|
||||
RUN chown -R www-data:www-data /var/www/html \
|
||||
&& chmod -R 755 /var/www/html
|
||||
|
||||
# Require the phpmailer/phpmailer package
|
||||
RUN composer require phpmailer/phpmailer
|
||||
|
||||
# Install using Composer
|
||||
RUN composer install --no-dev
|
||||
|
||||
# Install the /var/www/html/modules/washcertificates directory
|
||||
WORKDIR /var/www/html/modules/washcertificates
|
||||
RUN composer install --no-dev
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Expose port 9000
|
||||
EXPOSE 9000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user