diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php
index 2530c3e254..ceb7f47d58 100644
--- a/phpBB/includes/acp/acp_board.php
+++ b/phpBB/includes/acp/acp_board.php
@@ -19,6 +19,7 @@
* @ignore
*/
+use Minishlink\WebPush\VAPID;
use phpbb\config\config;
use phpbb\language\language;
use phpbb\user;
@@ -490,6 +491,7 @@ class acp_board
'title' => 'ACP_WEBPUSH_SETTINGS',
'vars' => [
'legend1' => 'GENERAL_SETTINGS',
+ 'webpush_enable' => ['lang' => 'WEBPUSH_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true],
'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true],
@@ -537,6 +539,27 @@ class acp_board
}
}
+ if ($mode == 'webpush')
+ {
+ // Create VAPID keys if keys are empty and web push is enabled
+ if ($submit && $cfg_array['webpush_enable'] && $cfg_array['webpush_enable'] != $config['webpush_enable']
+ && empty($cfg_array['webpush_vapid_public']) && empty($cfg_array['webpush_vapid_private'])
+ && empty($config['webpush_vapid_public']) && empty($config['webpush_vapid_private']))
+ {
+ try
+ {
+ $vapid_keys = VAPID::createVapidKeys();
+ $cfg_array['webpush_vapid_public'] = $vapid_keys['publicKey'];
+ $cfg_array['webpush_vapid_private'] = $vapid_keys['privateKey'];
+ }
+ catch (\ErrorException $exception)
+ {
+ // Nothing we can do about this, user will have to follow the
+ // documentation and manually create these.
+ }
+ }
+ }
+
// We validate the complete config if wished
validate_config_vars($display_vars['vars'], $cfg_array, $error);
diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql
index 844ba402b3..b924f70603 100644
--- a/phpBB/install/schemas/schema_data.sql
+++ b/phpBB/install/schemas/schema_data.sql
@@ -326,6 +326,9 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\pro
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\provider', 'phpbb\storage\provider\local');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\config\path', 'store');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', '');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', '');
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1);
diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php
index 37303d481a..8fe9f832f2 100644
--- a/phpBB/language/en/acp/board.php
+++ b/phpBB/language/en/acp/board.php
@@ -601,6 +601,8 @@ $lang = array_merge($lang, array(
$lang = array_merge($lang, [
'ACP_WEBPUSH_SETTINGS_EXPLAIN' => 'Here you can enable and control the use of Webpush for board notifications. Webpush is a simple protocol for the delivery of real-time events to user agents, more commonly known as push messages. It is supported by most modern browsers on desktop and mobile devices.',
+ 'WEBPUSH_ENABLE' => 'Enable Webpush',
+ 'WEBPUSH_ENABLE_EXPLAIN' => 'Allow receiving notifications via Webpush.
Note: If VAPID keys have not been set, phpBB will try to automatically create them when enabling Webpush.',
'WEBPUSH_VAPID_PUBLIC' => 'VAPID public key',
'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The VAPID public key will be shared to authenticate push messages sent by your site.
Warning: Changing the VAPID public key will automatically invalidate all webpush subscriptions.',
'WEBPUSH_VAPID_PRIVATE' => 'VAPID private key',
diff --git a/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php b/phpBB/phpbb/db/migration/data/v400/add_webpush.php
similarity index 88%
rename from phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php
rename to phpBB/phpbb/db/migration/data/v400/add_webpush.php
index e822a39405..3230acfc8d 100644
--- a/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php
+++ b/phpBB/phpbb/db/migration/data/v400/add_webpush.php
@@ -13,9 +13,10 @@
namespace phpbb\db\migration\data\v400;
+use Minishlink\WebPush\VAPID;
use phpbb\db\migration\migration;
-class add_notification_push_table extends migration
+class add_webpush extends migration
{
public static function depends_on(): array
{
@@ -56,6 +57,7 @@ class add_notification_push_table extends migration
public function update_data(): array
{
return [
+ ['config.add', ['webpush_enable', false]],
['config.add', ['webpush_vapid_public', '']],
['config.add', ['webpush_vapid_private', '']],
['module.add', [
@@ -75,8 +77,10 @@ class add_notification_push_table extends migration
public function revert_data(): array
{
return [
+ ['config.remove', ['webpush_enable']],
['config.remove', ['webpush_vapid_public']],
['config.remove', ['webpush_vapid_private']],
+ ['module.remove', ['acp', 'ACP_BOARD_CONFIGURATION', 'ACP_WEBPUSH_SETTINGS']]
];
}
}
diff --git a/tests/migrations/migrations_check_config_added_test.php b/tests/migrations/migrations_check_config_added_test.php
index 969a0f5e79..1472f9e370 100644
--- a/tests/migrations/migrations_check_config_added_test.php
+++ b/tests/migrations/migrations_check_config_added_test.php
@@ -142,7 +142,7 @@ class migrations_check_config_added_test extends phpbb_test_case
continue;
}
- // Fill error entries for configuration options which were not added to shema_data.sql
+ // Fill error entries for configuration options which were not added to schema_data.sql
if (!isset($config_names[$config_name]))
{
$config_names[$config_name] = [$config_name, $class];
@@ -160,7 +160,7 @@ class migrations_check_config_added_test extends phpbb_test_case
*/
public function test_config_option_exists_in_schema_data($config_name, $class)
{
- $message = 'Migration: %1$s, config_name: %2$s; not added to shema_data.sql';
+ $message = 'Migration: %1$s, config_name: %2$s; not added to schema_data.sql';
$this->assertNotFalse(strpos($this->schema_data, $config_name),
sprintf($message, $class, $config_name)