2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Album;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Configuration;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Facade\UserConfig;
|
2017-02-15 09:14:52 +00:00
|
|
|
use App\Group;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Helpers\ConfigHelper;
|
2017-03-21 21:48:55 +00:00
|
|
|
use App\Helpers\DbHelper;
|
2017-09-10 15:25:59 +01:00
|
|
|
use App\Helpers\MiscHelper;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Http\Requests\SaveSettingsRequest;
|
2017-09-10 09:07:56 +01:00
|
|
|
use App\Label;
|
2016-09-06 13:26:02 +01:00
|
|
|
use App\Mail\TestMailConfig;
|
2016-09-05 16:46:11 +01:00
|
|
|
use App\Photo;
|
2018-07-29 21:58:28 +01:00
|
|
|
use App\Services\GiteaService;
|
2017-10-01 16:48:50 +01:00
|
|
|
use App\Services\GithubService;
|
2017-09-16 08:26:05 +01:00
|
|
|
use App\Services\PhotoService;
|
2017-09-10 15:46:16 +01:00
|
|
|
use App\Storage;
|
2016-09-09 15:06:34 +01:00
|
|
|
use App\User;
|
2016-09-05 15:28:56 +01:00
|
|
|
use Illuminate\Http\Request;
|
2016-09-06 13:26:02 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-09-06 13:26:02 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2016-10-05 16:31:37 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2016-09-22 07:34:18 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
2016-10-05 16:31:37 +01:00
|
|
|
View::share('is_admin', true);
|
2016-09-22 07:34:18 +01:00
|
|
|
}
|
|
|
|
|
2017-10-01 16:48:50 +01:00
|
|
|
public function about()
|
|
|
|
{
|
|
|
|
return Theme::render('admin.about', [
|
|
|
|
'current_version' => config('app.version'),
|
|
|
|
'licence_text' => file_get_contents(sprintf('%s/LICENSE', dirname(dirname(dirname(dirname(__DIR__))))))
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function aboutLatestRelease()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-07-29 21:58:28 +01:00
|
|
|
$giteaService = new GiteaService();
|
|
|
|
$releaseInfo = $giteaService->checkForLatestRelease();
|
2017-10-01 16:48:50 +01:00
|
|
|
|
|
|
|
// Convert the publish date so we can re-format it with the user's settings
|
2018-07-29 21:58:28 +01:00
|
|
|
$publishDate = \DateTime::createFromFormat('Y-m-d\TH:i:sP', $releaseInfo->published_at);
|
2017-10-01 16:48:50 +01:00
|
|
|
|
|
|
|
// HTML-ify the body text
|
|
|
|
$body = nl2br($releaseInfo->body);
|
|
|
|
$body = preg_replace('/\*\*(.+)\*\*/', '<b>$1</b>', $body);
|
|
|
|
|
|
|
|
// Remove the "v" from the release name
|
2018-07-29 21:58:28 +01:00
|
|
|
$version = substr($releaseInfo->tag_name, 1);
|
2017-10-01 16:48:50 +01:00
|
|
|
|
|
|
|
// Determine if we can upgrade
|
|
|
|
$canUpgrade = version_compare($version, config('app.version')) > 0;
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'can_upgrade' => $canUpgrade,
|
|
|
|
'body' => $body,
|
|
|
|
'name' => $version,
|
|
|
|
'publish_date' => $publishDate->format(UserConfig::get('date_format')),
|
|
|
|
'url' => $releaseInfo->html_url
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return response()->json(['error' => $ex->getMessage()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-16 08:26:05 +01:00
|
|
|
public function metadataUpgrade()
|
|
|
|
{
|
|
|
|
$albumIDs = DbHelper::getAlbumIDsForCurrentUser();
|
|
|
|
|
|
|
|
$photoMetadata = DB::table('photos')
|
|
|
|
->whereIn('album_id', $albumIDs)
|
|
|
|
->select([
|
|
|
|
'album_id',
|
|
|
|
DB::raw('MIN(metadata_version) AS min_metadata_version')
|
|
|
|
])
|
|
|
|
->groupBy('album_id')
|
|
|
|
->get();
|
|
|
|
|
2018-07-12 06:35:08 +01:00
|
|
|
$resultingAlbumIDs = [];
|
2017-09-16 08:26:05 +01:00
|
|
|
foreach ($photoMetadata as $metadata)
|
|
|
|
{
|
2018-07-12 06:35:08 +01:00
|
|
|
if (isset($metadata->min_metadata_version) && $metadata->min_metadata_version > 0)
|
|
|
|
{
|
|
|
|
$resultingAlbumIDs[$metadata->album_id] = $metadata->min_metadata_version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now load the full album definitions
|
|
|
|
$albumsQuery = DbHelper::getAlbumsForCurrentUser_NonPaged();
|
|
|
|
$albumsQuery->whereIn('id', array_keys($resultingAlbumIDs));
|
|
|
|
$albums = $albumsQuery->paginate(UserConfig::get('items_per_page'));
|
|
|
|
|
|
|
|
/** @var Album $album */
|
|
|
|
foreach ($resultingAlbumIDs as $albumID => $metadataMinVersion)
|
|
|
|
{
|
2017-09-16 08:26:05 +01:00
|
|
|
foreach ($albums as $album)
|
|
|
|
{
|
2018-07-12 06:35:08 +01:00
|
|
|
if ($album->id == $albumID)
|
2017-09-16 08:26:05 +01:00
|
|
|
{
|
2018-07-12 06:35:08 +01:00
|
|
|
$album->min_metadata_version = $metadataMinVersion;
|
2017-09-16 08:26:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Theme::render('admin.metadata_upgrade', [
|
|
|
|
'albums' => $albums,
|
|
|
|
'current_metadata_version' => PhotoService::METADATA_VERSION
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-09-01 16:23:39 +01:00
|
|
|
public function index()
|
|
|
|
{
|
2017-03-21 21:48:55 +00:00
|
|
|
$this->authorizeAccessToAdminPanel();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2018-07-12 06:42:57 +01:00
|
|
|
$albumCount = count(DbHelper::getAlbumIDsForCurrentUser());
|
2016-09-05 16:46:11 +01:00
|
|
|
$photoCount = Photo::all()->count();
|
2017-02-15 09:14:52 +00:00
|
|
|
$groupCount = Group::all()->count();
|
2017-09-10 09:07:56 +01:00
|
|
|
$labelCount = Label::all()->count();
|
2016-09-09 15:06:34 +01:00
|
|
|
$userCount = User::where('is_activated', true)->count();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2018-07-12 06:09:28 +01:00
|
|
|
$minMetadataVersion = Photo::min('metadata_version');
|
|
|
|
$metadataUpgradeNeeded = $minMetadataVersion > 0 && $minMetadataVersion < PhotoService::METADATA_VERSION;
|
2017-09-16 08:26:05 +01:00
|
|
|
|
2017-09-29 20:15:24 +01:00
|
|
|
// Default to a supported function call to get the OS version
|
|
|
|
$osVersion = sprintf('%s %s', php_uname('s'), php_uname('r'));
|
|
|
|
|
|
|
|
// If the exec() function is enabled, we can do a bit better
|
|
|
|
if (MiscHelper::isExecEnabled())
|
|
|
|
{
|
|
|
|
$osVersion = exec('lsb_release -ds 2>/dev/null || cat /etc/*release 2>/dev/null | head -n1 || uname -om');
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.index', [
|
2016-09-05 16:46:11 +01:00
|
|
|
'album_count' => $albumCount,
|
2016-09-09 15:06:34 +01:00
|
|
|
'app_version' => config('app.version'),
|
2017-02-15 09:14:52 +00:00
|
|
|
'group_count' => $groupCount,
|
2017-09-10 09:07:56 +01:00
|
|
|
'label_count' => $labelCount,
|
2016-09-09 15:06:34 +01:00
|
|
|
'memory_limit' => ini_get('memory_limit'),
|
2017-09-16 08:26:05 +01:00
|
|
|
'metadata_upgrade_needed' => $metadataUpgradeNeeded,
|
2016-09-09 15:06:34 +01:00
|
|
|
'photo_count' => $photoCount,
|
|
|
|
'php_version' => phpversion(),
|
2017-09-29 20:15:24 +01:00
|
|
|
'os_version' => $osVersion,
|
2016-09-09 15:06:34 +01:00
|
|
|
'server_name' => gethostname(),
|
|
|
|
'upload_file_size' => ini_get('upload_max_filesize'),
|
|
|
|
'upload_max_limit' => ini_get('post_max_size'),
|
|
|
|
'user_count' => $userCount
|
2016-09-01 16:23:39 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-05 15:28:56 +01:00
|
|
|
|
2017-09-10 15:25:59 +01:00
|
|
|
public function quickUpload(Request $request)
|
|
|
|
{
|
|
|
|
$this->authorizeAccessToAdminPanel('admin:manage-albums');
|
|
|
|
|
|
|
|
$returnUrl = $request->headers->get('referer');
|
|
|
|
if (!MiscHelper::isSafeUrl($returnUrl))
|
|
|
|
{
|
|
|
|
$returnUrl = route('home');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pre-validate the upload before passing to the Photos controller
|
|
|
|
$files = $request->files->get('photo');
|
|
|
|
if (!is_array($files) || count($files) == 0)
|
|
|
|
{
|
|
|
|
$request->session()->flash('error', trans('admin.quick_upload.no_image_provided'));
|
|
|
|
return redirect($returnUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
$albumID = $request->get('album_id');
|
|
|
|
if (intval($albumID) == 0)
|
|
|
|
{
|
2017-09-10 15:46:16 +01:00
|
|
|
$albumName = trim($request->get('album_name'));
|
|
|
|
if (strlen($albumName) == 0)
|
|
|
|
{
|
|
|
|
$request->session()->flash('error', trans('admin.quick_upload.no_album_selected'));
|
|
|
|
return redirect($returnUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
$albumViews = UserConfig::allowedAlbumViews();
|
|
|
|
|
|
|
|
$album = new Album();
|
|
|
|
$album->storage_id = Storage::where('is_default', true)->first()->id;
|
|
|
|
$album->user_id = Auth::user()->id;
|
|
|
|
$album->default_view = UserConfig::get('default_album_view');
|
|
|
|
$album->name = $albumName;
|
|
|
|
$album->description = '';
|
|
|
|
$album->save();
|
|
|
|
|
|
|
|
$request->request->set('album_id', $album->id);
|
2017-09-10 15:25:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @var PhotoController $photoController */
|
|
|
|
$photoController = app(PhotoController::class);
|
|
|
|
return $photoController->store($request);
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
public function saveSettings(SaveSettingsRequest $request)
|
|
|
|
{
|
2017-04-15 09:41:15 +01:00
|
|
|
$this->authorizeAccessToAdminPanel('admin:configure');
|
|
|
|
|
2016-09-06 13:26:02 +01:00
|
|
|
$passwordKeys = [
|
|
|
|
'smtp_password'
|
|
|
|
];
|
2016-09-05 21:43:58 +01:00
|
|
|
$checkboxKeys = [
|
2018-07-12 22:52:50 +01:00
|
|
|
'albums_menu_parents_only',
|
2016-09-05 21:43:58 +01:00
|
|
|
'allow_self_registration',
|
2017-04-17 15:45:25 +01:00
|
|
|
'enable_visitor_hits',
|
2016-09-11 07:19:11 +01:00
|
|
|
'hotlink_protection',
|
|
|
|
'recaptcha_enabled_registration',
|
2016-10-05 16:31:37 +01:00
|
|
|
'remove_copyright',
|
2016-09-06 12:23:14 +01:00
|
|
|
'require_email_verification',
|
2016-09-11 07:19:11 +01:00
|
|
|
'restrict_original_download',
|
2016-09-08 11:02:49 +01:00
|
|
|
'smtp_encryption',
|
2016-09-05 21:43:58 +01:00
|
|
|
];
|
2016-09-05 15:28:56 +01:00
|
|
|
$updateKeys = [
|
2018-07-12 22:52:50 +01:00
|
|
|
'albums_menu_number_items',
|
2016-09-05 15:28:56 +01:00
|
|
|
'app_name',
|
2016-09-05 15:36:46 +01:00
|
|
|
'date_format',
|
2016-09-06 12:23:14 +01:00
|
|
|
'sender_address',
|
|
|
|
'sender_name',
|
2016-09-06 13:26:02 +01:00
|
|
|
'smtp_server',
|
|
|
|
'smtp_port',
|
|
|
|
'smtp_username',
|
|
|
|
'smtp_password',
|
2016-09-08 11:02:49 +01:00
|
|
|
'theme',
|
|
|
|
'recaptcha_site_key',
|
2016-10-28 16:07:24 +01:00
|
|
|
'recaptcha_secret_key',
|
|
|
|
'analytics_code'
|
2016-09-05 15:28:56 +01:00
|
|
|
];
|
|
|
|
|
2016-09-06 12:23:14 +01:00
|
|
|
$defaults = UserConfig::defaults();
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
foreach ($updateKeys as $key)
|
|
|
|
{
|
|
|
|
$config = UserConfig::getOrCreateModel($key);
|
2016-09-06 13:26:02 +01:00
|
|
|
|
|
|
|
// Bit of a hack when the browser returns an empty password field - meaning the user didn't change it
|
|
|
|
// - don't touch it!
|
|
|
|
if (
|
|
|
|
$key == 'smtp_password' &&
|
|
|
|
strlen($config->value) > 0 &&
|
|
|
|
strlen($request->request->get($key)) == 0 &&
|
|
|
|
strlen($request->request->get('smtp_username')) > 0
|
|
|
|
)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
$config->value = $request->request->get($key);
|
2016-10-28 14:05:53 +01:00
|
|
|
if (in_array($key, $passwordKeys) && strlen($config->value) > 0)
|
2016-09-06 13:26:02 +01:00
|
|
|
{
|
|
|
|
$config->value = encrypt($config->value);
|
|
|
|
}
|
2016-09-06 12:23:14 +01:00
|
|
|
|
|
|
|
if (isset($defaults[$key]) && $defaults[$key] == $config->value)
|
|
|
|
{
|
|
|
|
$config->delete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$config->save();
|
|
|
|
}
|
2016-09-05 15:28:56 +01:00
|
|
|
}
|
|
|
|
|
2016-09-05 21:43:58 +01:00
|
|
|
foreach ($checkboxKeys as $key)
|
|
|
|
{
|
|
|
|
$config = UserConfig::getOrCreateModel($key);
|
|
|
|
$config->value = ($request->request->get($key) == 'on' ? 1 : 0);
|
2016-09-06 12:23:14 +01:00
|
|
|
|
|
|
|
if (isset($defaults[$key]) && $defaults[$key] == $config->value)
|
|
|
|
{
|
|
|
|
$config->delete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$config->save();
|
|
|
|
}
|
2016-09-05 21:43:58 +01:00
|
|
|
}
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
$request->session()->flash('success', trans('admin.settings_saved_message'));
|
|
|
|
return redirect(route('admin.settings'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function settings(Request $request)
|
|
|
|
{
|
2017-04-15 09:41:15 +01:00
|
|
|
$this->authorizeAccessToAdminPanel('admin:configure');
|
2016-09-05 15:28:56 +01:00
|
|
|
|
|
|
|
// Load the current configuration
|
|
|
|
$config = array_merge(UserConfig::defaults(), UserConfig::getAll());
|
|
|
|
|
|
|
|
$dateFormats = UserConfig::allowedDateFormats();
|
|
|
|
$dateFormatsLookup = [];
|
|
|
|
|
|
|
|
foreach ($dateFormats as $dateFormat)
|
|
|
|
{
|
|
|
|
$dateFormatsLookup[$dateFormat] = date($dateFormat);
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:36:46 +01:00
|
|
|
$themeNamesLookup = UserConfig::allowedThemeNames();
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
return Theme::render('admin.settings', [
|
|
|
|
'config' => $config,
|
|
|
|
'date_formats' => $dateFormatsLookup,
|
2016-09-05 15:36:46 +01:00
|
|
|
'success' => $request->session()->get('success'),
|
|
|
|
'theme_names' => $themeNamesLookup
|
2016-09-05 15:28:56 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-06 13:26:02 +01:00
|
|
|
|
|
|
|
public function testMailSettings(SaveSettingsRequest $request)
|
|
|
|
{
|
2017-04-15 09:41:15 +01:00
|
|
|
$this->authorizeAccessToAdminPanel('admin:configure');
|
|
|
|
|
2016-09-06 13:26:02 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$validKeys = [
|
|
|
|
'sender_address',
|
|
|
|
'sender_name',
|
|
|
|
'smtp_server',
|
|
|
|
'smtp_port',
|
|
|
|
'smtp_username',
|
|
|
|
'smtp_password',
|
|
|
|
'smtp_encryption'
|
|
|
|
];
|
|
|
|
$config = $request->only($validKeys);
|
|
|
|
|
|
|
|
/** @var \Swift_Mailer $swiftMailer */
|
|
|
|
$swiftMailer = resolve('mailer')->getSwiftMailer();
|
|
|
|
|
|
|
|
/** @var \Swift_SmtpTransport $transport */
|
|
|
|
$transport = $swiftMailer->getTransport();
|
|
|
|
$transport->setHost($config['smtp_server']);
|
|
|
|
$transport->setPort(intval($config['smtp_port']));
|
|
|
|
$transport->setUsername($config['smtp_username']);
|
|
|
|
$transport->setPassword($config['smtp_password']);
|
|
|
|
|
|
|
|
if (isset($config['smtp_encryption']) && strtolower($config['smtp_encryption']) == 'on')
|
|
|
|
{
|
|
|
|
$transport->setEncryption('tls');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$transport->setEncryption('');
|
|
|
|
}
|
|
|
|
|
|
|
|
Mail::to(Auth::user())->send(new TestMailConfig($config['sender_name'], $config['sender_address']));
|
|
|
|
|
2017-04-10 20:48:47 +01:00
|
|
|
return response()->json(array('is_successful' => true, 'message' => trans('admin.settings_test_email_successful')));
|
2016-09-06 13:26:02 +01:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return response()->json(array('is_successful' => false, 'message' => $ex->getMessage()));
|
|
|
|
}
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|