Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/debug/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
echo getNavItemDebug('myconfig');
echo getNavItemDebug('remotebuzzerlog');
echo getNavItemDebug('synctodrivelog');
echo getNavItemDebug('remotestoragelog');
echo getNavItemDebug('devlog');
if (Environment::isLinux()) {
echo getNavItemDebug('serverprocesses');
Expand Down
106 changes: 7 additions & 99 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
require_once '../lib/boot.php';

use Photobooth\Image;
use Photobooth\Helper;
use Photobooth\Collage;
use Photobooth\Enum\FolderEnum;
use Photobooth\Enum\ImageFilterEnum;
use Photobooth\Processor\ImageProcessor;
use Photobooth\Service\DatabaseManagerService;
use Photobooth\Service\LoggerService;
use Photobooth\Service\RemoteStorageService;
use Photobooth\Utility\ImageUtility;
use Photobooth\Utility\PathUtility;

Expand All @@ -21,6 +21,7 @@
$logger->debug(basename($_SERVER['PHP_SELF']));

$database = DatabaseManagerService::getInstance();
$remoteStorage = RemoteStorageService::getInstance();

$processor = null;

Expand Down Expand Up @@ -279,106 +280,13 @@
}
}

// send to ftp server
// Store images on remote storage
if ($config['ftp']['enabled']) {
// init connection to ftp server
$ftp = ftp_ssl_connect($config['ftp']['baseURL'], $config['ftp']['port']);

if ($ftp === false) {
$message = 'Failed to connect to FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
$remoteStorage->write($remoteStorage->getStorageFolder() . '/images/' . $vars['singleImageFile'], (string) file_get_contents($vars['resultFile']));
$remoteStorage->write($remoteStorage->getStorageFolder() . '/thumbs/' . $vars['singleImageFile'], (string) file_get_contents($vars['thumbFile']));
if ($config['ftp']['create_webpage']) {
$remoteStorage->createWebpage();
}
ftp_set_option($ftp, FTP_TIMEOUT_SEC, 10);

// login to ftp server
$login_result = ftp_login($ftp, $config['ftp']['username'], $config['ftp']['password']);

if (!$login_result) {
$message = 'Can\'t connect to FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

// turn passive mode on to enable creation of folder and upload of files
ftp_pasv($ftp, true);

$destination = empty($config['ftp']['baseFolder']) ? '' : DIRECTORY_SEPARATOR . $config['ftp']['baseFolder'] . DIRECTORY_SEPARATOR;

$destination .= $config['ftp']['folder'] . DIRECTORY_SEPARATOR . Helper::slugify($config['ftp']['title']);
if ($config['ftp']['appendDate']) {
$destination .= DIRECTORY_SEPARATOR . date('Y/m/d');
}

// navigate trough folder on the server to the destination
@Helper::cdFTPTree($ftp, $destination);

// upload processed picture into destination folder
$put_result = @ftp_put($ftp, $vars['singleImageFile'], $vars['resultFile'], FTP_BINARY);

if (!$put_result) {
$message = 'Unable to save file on FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

// upload the thumbnail if enabled
if ($config['ftp']['upload_thumb']) {
$thumb_result = ftp_put($ftp, 'tmb_' . $vars['singleImageFile'], $vars['thumbFile'], FTP_BINARY);
if (!$thumb_result) {
$logger->error('Unable to load the thumbnail', $config['ftp']);
}
}

// check if the webpage is enabled and is not already loaded on the ftp server
if ($config['ftp']['create_webpage'] && (!isset($_SESSION['ftpWebpageLoaded']) || $_SESSION['ftpWebpageLoaded'] != $config['ftp']['title'])) {
// if the date folder structure is appended, return to the main folder
if ($config['ftp']['appendDate']) {
@Helper::cdFTPTree($ftp, '../../../');
}

// another security check on the file in the server (e.g. 2-day event with the same ftp folder location)
$webpage_exist = ftp_size($ftp, 'index.php');
if ($webpage_exist == -1) {
// get the index.php template file from the configured location
$webpage_template = file_get_contents($config['ftp']['template_location']);

if ($webpage_template === false) {
throw new \Exception('File could not be read: ' . $config['ftp']['template_location']);
}
// set the {title} variable
$final_webpage = str_replace('{title}', $config['ftp']['title'], $webpage_template);

// put the file into a stream
$stream = fopen('php://memory', 'r+');
if ($stream === false) {
throw new \Exception('Could not put the file into a stream!');
}
fwrite($stream, $final_webpage);
rewind($stream);

// load the index.php result file in the ftp server
$upload_webpage = ftp_fput($ftp, 'index.php', $stream, FTP_BINARY);

fclose($stream);

if (!$upload_webpage) {
$message = 'Unable to save file on FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

// update the session variable to avoid unnecessary checks
$_SESSION['ftpWebpageLoaded'] = $config['ftp']['title'];
}
}

// close the connection
@ftp_close($ftp);
}

// Change permissions
Expand Down
56 changes: 5 additions & 51 deletions api/deletePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

use Photobooth\Enum\FolderEnum;
use Photobooth\FileDelete;
use Photobooth\Helper;
use Photobooth\Service\DatabaseManagerService;
use Photobooth\Service\LoggerService;
use Photobooth\Service\RemoteStorageService;

header('Content-Type: application/json');

$logger = LoggerService::getInstance()->getLogger('main');
$logger->debug(basename($_SERVER['PHP_SELF']));

$remoteStorage = RemoteStorageService::getInstance();

try {
if (empty($_POST['file'])) {
throw new \Exception('No file provided');
Expand Down Expand Up @@ -47,56 +49,8 @@
}

if ($config['ftp']['enabled'] && $config['ftp']['delete']) {
$ftp = ftp_ssl_connect($config['ftp']['baseURL'], $config['ftp']['port']);

if ($ftp === false) {
$message = 'Failed to connect to FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

// login to ftp server
$login_result = ftp_login($ftp, $config['ftp']['username'], $config['ftp']['password']);

if (!$login_result) {
$message = 'Can\'t connect to FTP Server!';
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

$remote_dest = empty($config['ftp']['baseFolder']) ? '' : DIRECTORY_SEPARATOR . $config['ftp']['baseFolder'] . DIRECTORY_SEPARATOR;

$remote_dest .= $config['ftp']['folder'] . DIRECTORY_SEPARATOR . Helper::slugify($config['ftp']['title']);
if ($config['ftp']['appendDate']) {
$remote_dest .= DIRECTORY_SEPARATOR . date('Y/m/d');
}

@Helper::cdFTPTree($ftp, $remote_dest);

$delete_result = ftp_delete($ftp, $file);

if (!$delete_result) {
$message = 'Unable to delete file on ftp server ' . $file;
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}

if ($config['ftp']['upload_thumb']) {
$delete_result = ftp_delete($ftp, 'tmb_' . $file);

if (!$delete_result) {
$message = 'Unable to delete thumb on ftp server ' . $file;
$logger->error($message, $config['ftp']);
echo json_encode(['error' => $message]);
die();
}
}

// close the connection
@ftp_close($ftp);
$remoteStorage->delete($remoteStorage->getStorageFolder() . '/images/' . $file);
$remoteStorage->delete($remoteStorage->getStorageFolder() . '/thumbs/' . $file);
}

if (!$logData['success'] || $config['dev']['loglevel'] > 1) {
Expand Down
19 changes: 12 additions & 7 deletions api/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Photobooth\Processor\PrintProcessor;
use Photobooth\Service\LoggerService;
use Photobooth\Service\PrintManagerService;
use Photobooth\Service\RemoteStorageService;
use Photobooth\Utility\PathUtility;

header('Content-Type: application/json');
Expand Down Expand Up @@ -96,14 +97,18 @@
}

if ($config['print']['qrcode']) {
// create qr code
if ($config['ftp']['enabled'] && $config['ftp']['useForQr'] && isset($config['ftp']['processedTemplate'])) {
$imageHandler->qrUrl = $config['ftp']['processedTemplate'] . DIRECTORY_SEPARATOR . $vars['fileName'];
} elseif ($config['qr']['append_filename']) {
$imageHandler->qrUrl = PathUtility::getPublicPath($config['qr']['url'] . $vars['fileName'], true);
} else {
$imageHandler->qrUrl = PathUtility::getPublicPath($config['qr']['url'], true);
$url = $config['qr']['url'];
if ($config['ftp']['enabled'] && $config['ftp']['useForQr']) {
$remoteStorageService = RemoteStorageService::getInstance();
$url = $remoteStorageService->getWebpageUri();
if ($config['qr']['append_filename']) {
$url .= '/images/';
}
}
if ($config['qr']['append_filename']) {
$url .= $vars['fileName'];
}
$imageHandler->qrUrl = PathUtility::getPublicPath($url, true);
$imageHandler->qrSize = $config['print']['qrSize'];
$imageHandler->qrMargin = $config['print']['qrMargin'];
$imageHandler->qrColor = $config['print']['qrBgColor'];
Expand Down
22 changes: 14 additions & 8 deletions api/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

/** @var array $config */

use Photobooth\Service\RemoteStorageService;
use Photobooth\Utility\PathUtility;
use Photobooth\Utility\QrCodeUtility;

require_once '../lib/boot.php';

$filename = (isset($_GET['filename']) && $_GET['filename']) != '' ? $_GET['filename'] : false;

if ($filename || !$config['qr']['append_filename']) {
if ($config['ftp']['enabled'] && $config['ftp']['useForQr'] && isset($config['ftp']['processedTemplate'])) {
$url = $config['ftp']['processedTemplate'] . DIRECTORY_SEPARATOR . $filename;
} elseif ($config['qr']['append_filename']) {
$url = PathUtility::getPublicPath($config['qr']['url'] . $filename, true);
} else {
$url = PathUtility::getPublicPath($config['qr']['url'], true);
if ($filename) {
$url = $config['qr']['url'];
if ($config['ftp']['enabled'] && $config['ftp']['useForQr']) {
$remoteStorageService = RemoteStorageService::getInstance();
$url = $remoteStorageService->getWebpageUri();
if ($config['qr']['append_filename']) {
$url .= '/images/';
}
}
if ($config['qr']['append_filename']) {
$url .= $filename;
}
$url = PathUtility::getPublicPath($url, true);
try {
$result = QrCodeUtility::create($url);
header('Content-Type: ' . $result->getMimeType());
Expand All @@ -28,6 +33,7 @@
echo $e->getMessage();
}
}

} else {
http_response_code(400);
echo 'No filename defined.';
Expand Down
2 changes: 2 additions & 0 deletions api/serverInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function handleDebugPanel(string $content, array $config): string|false
return readFileContents(PathUtility::getAbsolutePath('var/log/remotebuzzer.log'));
case 'nav-synctodrivelog':
return readFileContents(PathUtility::getAbsolutePath('var/log/synctodrive.log'));
case 'nav-remotestoragelog':
return readFileContents(PathUtility::getAbsolutePath('var/log/remotestorage.log'));
case 'nav-myconfig':
echo implode("\n", showConfig($config));
return json_encode('');
Expand Down
64 changes: 15 additions & 49 deletions api/testFtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,23 @@

require_once '../lib/boot.php';

use Photobooth\Service\LoggerService;
use Photobooth\Service\RemoteStorageService;

header('Content-Type: application/json');

$logger = LoggerService::getInstance()->getLogger('main');
$logger->debug(basename($_SERVER['PHP_SELF']));

$data = $_POST;

$params = ['baseURL', 'port', 'username', 'password'];

$result = [
'response' => 'error',
'message' => 'ftp:missing_parameters',
'missing' => [],
];

foreach ($params as $param) {
if ($data['ftp'][$param] == '') {
$result['missing'][] = $param;
}
}

if (!empty($result['missing'])) {
die(json_encode($result));
$remoteStorage = RemoteStorageService::getInstance();
if (!$remoteStorage->testConnection()) {
echo json_encode([
'response' => 'error',
'message' => 'ftp:no_connection',
'missing' => [],
]);
exit();
}

$baseUrl = $data['ftp']['baseURL'];
$port = $data['ftp']['port'];
$username = $data['ftp']['username'];
$password = $data['ftp']['password'];

// init connection to ftp server
$ftp = ftp_ssl_connect($baseUrl, $port, 10);

if ($ftp === false) {
$logger->error('Can\'t connect to FTP Server!');
$result['response'] = 'error';
$result['message'] = 'ftp:no_connection';
die(json_encode($result));
}

// login to ftp server
$login_result = @ftp_login($ftp, $username, $password);
$result['response'] = 'success';
$result['message'] = 'ftp:connected';

if (!$login_result) {
$logger->error('Can\'t connect to FTP Server!');
$result['response'] = 'error';
$result['message'] = 'ftp:no_connection';
}
@ftp_close($ftp);
die(json_encode($result));
echo json_encode([
'response' => 'success',
'message' => 'ftp:connected',
'missing' => [],
]);
exit();
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"ext-zip": "*",
"endroid/qr-code": "^6.0",
"league/commonmark": "^2.4",
"league/flysystem": "^3.29",
"league/flysystem-ftp": "^3.29",
"league/flysystem-sftp-v3": "^3.29",
"monolog/monolog": "^3.5",
"phpmailer/phpmailer": "^6.8",
"symfony/asset": "^7.0",
Expand Down
Loading
Loading