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;
|
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;
|
2016-09-06 13:26:02 +01:00
|
|
|
use App\Mail\TestMailConfig;
|
2016-09-05 16:46:11 +01:00
|
|
|
use App\Photo;
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-03-21 21:48:55 +00:00
|
|
|
$albumCount = DbHelper::getAlbumsForCurrentUser()->count();
|
2016-09-05 16:46:11 +01:00
|
|
|
$photoCount = Photo::all()->count();
|
2017-02-15 09:14:52 +00:00
|
|
|
$groupCount = Group::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
|
|
|
|
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,
|
2016-09-09 15:06:34 +01:00
|
|
|
'memory_limit' => ini_get('memory_limit'),
|
|
|
|
'photo_count' => $photoCount,
|
|
|
|
'php_version' => phpversion(),
|
|
|
|
'os_version' => exec('lsb_release -ds 2>/dev/null || cat /etc/*release 2>/dev/null | head -n1 || uname -om'),
|
|
|
|
'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
|
|
|
|
|
|
|
public function saveSettings(SaveSettingsRequest $request)
|
|
|
|
{
|
2016-09-06 13:26:02 +01:00
|
|
|
$passwordKeys = [
|
|
|
|
'smtp_password'
|
|
|
|
];
|
2016-09-05 21:43:58 +01:00
|
|
|
$checkboxKeys = [
|
|
|
|
'allow_self_registration',
|
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 = [
|
|
|
|
'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)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|