info('User visits notifications index.'); $title = (string) trans('firefly.system_settings'); $mainTitleIcon = 'fa-hand-spock-o'; $subTitle = (string) trans('firefly.title_owner_notifications'); $subTitleIcon = 'envelope-o'; // notification settings: $slackUrl = FireflyConfig::getEncrypted('slack_webhook_url', '')->data; $pushoverAppToken = FireflyConfig::getEncrypted('pushover_app_token', '')->data; $pushoverUserToken = FireflyConfig::getEncrypted('pushover_user_token', '')->data; $ntfyServer = FireflyConfig::getEncrypted('ntfy_server', 'https://ntfy.sh')->data; $ntfyTopic = FireflyConfig::getEncrypted('ntfy_topic', '')->data; $ntfyAuth = FireflyConfig::get('ntfy_auth', false)->data; $ntfyUser = FireflyConfig::getEncrypted('ntfy_user', '')->data; $ntfyPass = FireflyConfig::getEncrypted('ntfy_pass', '')->data; $channels = config('notifications.channels'); $forcedAvailability = []; // admin notification settings: $notifications = []; foreach (config('notifications.notifications.owner') as $key => $info) { if (true === $info['enabled']) { $notifications[$key] = FireflyConfig::get(sprintf('notification_%s', $key), true)->data; } } // loop all channels to see if they are available. foreach ($channels as $channel => $info) { $forcedAvailability[$channel] = true; } $forcedAvailability['ntfy'] = '' !== $ntfyTopic; $forcedAvailability['pushover'] = '' !== $pushoverAppToken && '' !== $pushoverUserToken; $forcedAvailability['slack'] = '' !== $slackUrl; return view( 'settings.notifications.index', compact( 'title', 'subTitle', 'forcedAvailability', 'mainTitleIcon', 'subTitleIcon', 'channels', 'slackUrl', 'notifications', 'pushoverAppToken', 'pushoverUserToken', 'ntfyServer', 'ntfyTopic', 'ntfyAuth', 'ntfyUser', 'ntfyPass' ) ); } public function postIndex(NotificationRequest $request): RedirectResponse { $all = $request->getAll(); foreach (config('notifications.notifications.owner') as $key => $info) { if (array_key_exists($key, $all)) { FireflyConfig::set(sprintf('notification_%s', $key), $all[$key]); } } $variables = ['slack_webhook_url', 'pushover_app_token', 'pushover_user_token', 'ntfy_server', 'ntfy_topic', 'ntfy_user', 'ntfy_pass']; foreach ($variables as $variable) { if ('' === $all[$variable]) { FireflyConfig::delete($variable); } if ('' !== $all[$variable]) { FireflyConfig::setEncrypted($variable, $all[$variable]); } } FireflyConfig::set('ntfy_auth', $all['ntfy_auth'] ?? false); session()->flash('success', (string) trans('firefly.notification_settings_saved')); return redirect(route('settings.notification.index')); } public function testNotification(Request $request): RedirectResponse { $all = $request->all(); $channel = $all['test_submit'] ?? ''; switch ($channel) { default: session()->flash('error', (string) trans('firefly.notification_test_failed', ['channel' => $channel])); break; case 'email': case 'slack': case 'pushover': case 'ntfy': $owner = new OwnerNotifiable(); app('log')->debug(sprintf('Now in testNotification("%s") controller.', $channel)); event(new OwnerTestNotificationChannel($channel, $owner)); session()->flash('success', (string) trans('firefly.notification_test_executed', ['channel' => $channel])); } return redirect(route('settings.notification.index')); } }