mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-11 04:52:14 +09:00
Add configuration for uploading FCM v1 service account private key file
This commit is contained in:
parent
dee7ed34e9
commit
2c8ae717e1
7 changed files with 174 additions and 74 deletions
|
|
@ -7,7 +7,7 @@ use Rhymix\Framework\Push;
|
||||||
use Rhymix\Framework\Drivers\PushInterface;
|
use Rhymix\Framework\Drivers\PushInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The FCM Legacy HTTP API Push driver.
|
* The FCM Legacy API Push driver.
|
||||||
*/
|
*/
|
||||||
class FCM extends Base implements PushInterface
|
class FCM extends Base implements PushInterface
|
||||||
{
|
{
|
||||||
|
|
@ -24,7 +24,7 @@ class FCM extends Base implements PushInterface
|
||||||
*/
|
*/
|
||||||
public static function getName(): string
|
public static function getName(): string
|
||||||
{
|
{
|
||||||
return 'FCM Legacy HTTP API';
|
return 'FCM Legacy API';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
55
common/framework/drivers/push/fcmv1.php
Normal file
55
common/framework/drivers/push/fcmv1.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rhymix\Framework\Drivers\Push;
|
||||||
|
|
||||||
|
use Rhymix\Framework\HTTP;
|
||||||
|
use Rhymix\Framework\Push;
|
||||||
|
use Rhymix\Framework\Drivers\PushInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The FCM HTTP v1 API Push driver.
|
||||||
|
*/
|
||||||
|
class FCMv1 extends Base implements PushInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Config keys used by this driver are stored here.
|
||||||
|
*/
|
||||||
|
protected static $_required_config = array('service_account');
|
||||||
|
protected static $_optional_config = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the human-readable name of this Push driver.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getName(): string
|
||||||
|
{
|
||||||
|
return 'FCM HTTP v1 API';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current Push driver is supported on this server.
|
||||||
|
*
|
||||||
|
* This method returns true on success and false on failure.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isSupported(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message.
|
||||||
|
*
|
||||||
|
* This method returns true on success and false on failure.
|
||||||
|
*
|
||||||
|
* @param object $message
|
||||||
|
* @param array $tokens
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function send(Push $message, array $tokens): \stdClass
|
||||||
|
{
|
||||||
|
return new \stdClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -67,6 +67,12 @@ class Notification extends Base
|
||||||
$apns_certificate = Storage::read($apns_certificate_filename);
|
$apns_certificate = Storage::read($apns_certificate_filename);
|
||||||
}
|
}
|
||||||
Context::set('apns_certificate', $apns_certificate);
|
Context::set('apns_certificate', $apns_certificate);
|
||||||
|
$fcmv1_service_account = false;
|
||||||
|
if ($fcmv1_service_account_filename = config('push.fcmv1.service_account'))
|
||||||
|
{
|
||||||
|
$fcmv1_service_account = Storage::read($fcmv1_service_account_filename);
|
||||||
|
}
|
||||||
|
Context::set('fcmv1_service_account', $fcmv1_service_account);
|
||||||
|
|
||||||
// Workaround for compatibility with older version of Amazon SES driver.
|
// Workaround for compatibility with older version of Amazon SES driver.
|
||||||
config('mail.ses.api_key', config('mail.ses.api_user'));
|
config('mail.ses.api_key', config('mail.ses.api_user'));
|
||||||
|
|
@ -178,12 +184,19 @@ class Notification extends Base
|
||||||
$push_config[$driver_name][$conf_name] = $conf_value;
|
$push_config[$driver_name][$conf_name] = $conf_value;
|
||||||
|
|
||||||
// Save certificates in a separate file and only store the filename in config.php.
|
// Save certificates in a separate file and only store the filename in config.php.
|
||||||
if ($conf_name === 'certificate')
|
if ($conf_name === 'certificate' || $conf_name === 'service_account')
|
||||||
{
|
{
|
||||||
$filename = Config::get('push.' . $driver_name . '.certificate');
|
$filename = Config::get('push.' . $driver_name . '.' . $conf_name);
|
||||||
if (!$filename)
|
if (!$filename)
|
||||||
{
|
{
|
||||||
$filename = './files/config/' . $driver_name . '/cert-' . \Rhymix\Framework\Security::getRandom(32) . '.pem';
|
if ($conf_name === 'certificate')
|
||||||
|
{
|
||||||
|
$filename = './files/config/' . $driver_name . '/cert-' . \Rhymix\Framework\Security::getRandom(32) . '.pem';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$filename = './files/config/' . $driver_name . '/pkey-' . \Rhymix\Framework\Security::getRandom(32) . '.json';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($conf_value !== null)
|
if ($conf_value !== null)
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,10 @@
|
||||||
<label class="x_control-label">{$lang->cmd_admin_sending_method}</label>
|
<label class="x_control-label">{$lang->cmd_admin_sending_method}</label>
|
||||||
<div class="x_controls">
|
<div class="x_controls">
|
||||||
<!--@foreach($push_drivers as $driver_name => $driver_definition)-->
|
<!--@foreach($push_drivers as $driver_name => $driver_definition)-->
|
||||||
<label for="push_driver_{$driver_name}" class="x_inline"><input type="checkbox" name="push_driver[]" id="push_driver_{$driver_name}" value="{$driver_name}" checked="checked"|cond="isset($push_config['types'][$driver_name])" /> {$driver_definition['name']}</label>
|
<label for="push_driver_{$driver_name}" class="x_inline">
|
||||||
|
<input type="checkbox" class="push_driver_checkbox" name="push_driver[]" id="push_driver_{$driver_name}" value="{$driver_name}" checked="checked"|cond="isset($push_config['types'][$driver_name])" data-driver="{$driver_name}" value="Y" />
|
||||||
|
{$driver_definition['name']}
|
||||||
|
</label>
|
||||||
<!--@end-->
|
<!--@end-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -378,6 +381,17 @@
|
||||||
<label class="x_control-label" for="push_{$driver_name}_api_key">{$lang->cmd_advanced_mailer_fcm_api_key}</label>
|
<label class="x_control-label" for="push_{$driver_name}_api_key">{$lang->cmd_advanced_mailer_fcm_api_key}</label>
|
||||||
<div class="x_controls">
|
<div class="x_controls">
|
||||||
<input type="password" name="push_{$driver_name}_api_key" id="push_{$driver_name}_api_key" value="{$conf_value|escape}" autocomplete="new-password" />
|
<input type="password" name="push_{$driver_name}_api_key" id="push_{$driver_name}_api_key" value="{$conf_value|escape}" autocomplete="new-password" />
|
||||||
|
<p class="x_help-block">{$lang->msg_advanced_mailer_about_fcm_legacy}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--@end-->
|
||||||
|
|
||||||
|
<!--@if($conf_name === 'service_account')-->
|
||||||
|
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
||||||
|
<label class="x_control-label" for="push_{$driver_name}_service_account">{$lang->cmd_advanced_mailer_fcm_service_account}</label>
|
||||||
|
<div class="x_controls">
|
||||||
|
<textarea name="push_{$driver_name}_service_account" id="push_{$driver_name}_service_account" class="x_full-width" rows="10">{$fcmv1_service_account|escape}</textarea>
|
||||||
|
<p class="x_help-block">{$lang->msg_advanced_mailer_about_fcm_service_account}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--@end-->
|
<!--@end-->
|
||||||
|
|
@ -386,7 +400,7 @@
|
||||||
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
||||||
<label class="x_control-label" for="push_{$driver_name}_certificate">{$lang->cmd_advanced_mailer_apns_certificate}</label>
|
<label class="x_control-label" for="push_{$driver_name}_certificate">{$lang->cmd_advanced_mailer_apns_certificate}</label>
|
||||||
<div class="x_controls full-width">
|
<div class="x_controls full-width">
|
||||||
<textarea name="push_{$driver_name}_certificate" id="push_{$driver_name}_certificate">{$apns_certificate|escape}</textarea>
|
<textarea name="push_{$driver_name}_certificate" id="push_{$driver_name}_certificate" class="x_full-width" rows="10">{$apns_certificate|escape}</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--@end-->
|
<!--@end-->
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,18 @@
|
||||||
});
|
});
|
||||||
}).triggerHandler("change");
|
}).triggerHandler("change");
|
||||||
|
|
||||||
|
$(".push_driver_checkbox").on("change", function() {
|
||||||
|
$(".push_driver_checkbox").each(function() {
|
||||||
|
var driver_name = $(this).data('driver');
|
||||||
|
var is_checked = $(this).is(':checked');
|
||||||
|
$(this).parents("section").find("div.x_control-group.hidden-by-default, p.x_help-block.hidden-by-default").each(function() {
|
||||||
|
if ($(this).hasClass("show-for-" + driver_name)) {
|
||||||
|
is_checked ? $(this).show() : $(this).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).first().triggerHandler("change");
|
||||||
|
|
||||||
$("#mail_smtp_manual_entry").on("change", function() {
|
$("#mail_smtp_manual_entry").on("change", function() {
|
||||||
var auto_fill = $(this).val();
|
var auto_fill = $(this).val();
|
||||||
if (auto_fill === 'gmail') {
|
if (auto_fill === 'gmail') {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ $lang->cmd_advanced_mailer_api_type_free = 'Free account';
|
||||||
$lang->cmd_advanced_mailer_api_type_paid = 'Paid account';
|
$lang->cmd_advanced_mailer_api_type_paid = 'Paid account';
|
||||||
$lang->cmd_advanced_mailer_api_user = 'Username';
|
$lang->cmd_advanced_mailer_api_user = 'Username';
|
||||||
$lang->cmd_advanced_mailer_api_pass = 'Password';
|
$lang->cmd_advanced_mailer_api_pass = 'Password';
|
||||||
$lang->cmd_advanced_mailer_fcm_api_key = 'Google FCM API key';
|
$lang->cmd_advanced_mailer_fcm_api_key = 'FCM Legacy API key';
|
||||||
|
$lang->cmd_advanced_mailer_fcm_service_account = 'FCM service account file';
|
||||||
$lang->cmd_advanced_mailer_apns_certificate = 'APNs certificate file';
|
$lang->cmd_advanced_mailer_apns_certificate = 'APNs certificate file';
|
||||||
$lang->cmd_advanced_mailer_apns_passphrase = 'APNs certificate passphrase';
|
$lang->cmd_advanced_mailer_apns_passphrase = 'APNs certificate passphrase';
|
||||||
$lang->cmd_advanced_mailer_allow_guest_device = 'Register Guest Devices';
|
$lang->cmd_advanced_mailer_allow_guest_device = 'Register Guest Devices';
|
||||||
|
|
@ -150,3 +151,5 @@ $lang->cmd_advanced_mailer_success_count = 'Success';
|
||||||
$lang->cmd_advanced_mailer_deleted_count = 'Deleted';
|
$lang->cmd_advanced_mailer_deleted_count = 'Deleted';
|
||||||
$lang->cmd_advanced_mailer_updated_count = 'Updated';
|
$lang->cmd_advanced_mailer_updated_count = 'Updated';
|
||||||
$lang->cmd_advanced_mailer_not_rhymix = 'This module is for XE. It is incompatible with Rhymix. Please use the version included with Rhymix.';
|
$lang->cmd_advanced_mailer_not_rhymix = 'This module is for XE. It is incompatible with Rhymix. Please use the version included with Rhymix.';
|
||||||
|
$lang->msg_advanced_mailer_about_fcm_legacy = 'The Legacy API will stop working after June 2024. Please change to the HTTP v1 API.';
|
||||||
|
$lang->msg_advanced_mailer_about_fcm_service_account = 'Generate a new private key in the "Service accounts" menu of the Firebase console.<br>Then paste the contents of the downloaded JSON file above.';
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ $lang->cmd_advanced_mailer_api_type_free = '무료';
|
||||||
$lang->cmd_advanced_mailer_api_type_paid = '유료';
|
$lang->cmd_advanced_mailer_api_type_paid = '유료';
|
||||||
$lang->cmd_advanced_mailer_api_user = '아이디';
|
$lang->cmd_advanced_mailer_api_user = '아이디';
|
||||||
$lang->cmd_advanced_mailer_api_pass = '비밀번호';
|
$lang->cmd_advanced_mailer_api_pass = '비밀번호';
|
||||||
$lang->cmd_advanced_mailer_fcm_api_key = 'Google FCM API 키';
|
$lang->cmd_advanced_mailer_fcm_api_key = 'FCM Legacy API 키';
|
||||||
|
$lang->cmd_advanced_mailer_fcm_service_account = 'FCM 서비스 계정 파일';
|
||||||
$lang->cmd_advanced_mailer_apns_certificate = 'APNs 인증서 파일';
|
$lang->cmd_advanced_mailer_apns_certificate = 'APNs 인증서 파일';
|
||||||
$lang->cmd_advanced_mailer_apns_passphrase = 'APNs 인증서 암호';
|
$lang->cmd_advanced_mailer_apns_passphrase = 'APNs 인증서 암호';
|
||||||
$lang->cmd_advanced_mailer_allow_guest_device = '비회원 기기 등록';
|
$lang->cmd_advanced_mailer_allow_guest_device = '비회원 기기 등록';
|
||||||
|
|
@ -150,3 +151,5 @@ $lang->cmd_advanced_mailer_success_count = '성공';
|
||||||
$lang->cmd_advanced_mailer_deleted_count = '삭제';
|
$lang->cmd_advanced_mailer_deleted_count = '삭제';
|
||||||
$lang->cmd_advanced_mailer_updated_count = '변경';
|
$lang->cmd_advanced_mailer_updated_count = '변경';
|
||||||
$lang->cmd_advanced_mailer_not_rhymix = '이 모듈은 XE용으로, 라이믹스와는 호환되지 않습니다. 라이믹스에 기본 포함된 버전을 사용하시기 바랍니다.';
|
$lang->cmd_advanced_mailer_not_rhymix = '이 모듈은 XE용으로, 라이믹스와는 호환되지 않습니다. 라이믹스에 기본 포함된 버전을 사용하시기 바랍니다.';
|
||||||
|
$lang->msg_advanced_mailer_about_fcm_legacy = 'Legacy API는 2024년 6월 이후 사용할 수 없으니 HTTP v1 API로 변경하십시오.';
|
||||||
|
$lang->msg_advanced_mailer_about_fcm_service_account = 'Firebase 콘솔의 "서비스 계정" 메뉴에서 비공개 키를 생성한 후,<br>다운로드한 JSON 파일의 내용을 빈 칸에 붙여넣으십시오.';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue