mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-05-15 12:36:26 +02:00
Compare commits
No commits in common. "8843df9f4632db69a339ab611d17385dbadb7499" and "3b5733e31a2746bade73cd70e1d6a7d27b86d76a" have entirely different histories.
8843df9f46
...
3b5733e31a
1 changed files with 0 additions and 18 deletions
|
@ -13,8 +13,6 @@ namespace controllers\internals;
|
||||||
|
|
||||||
class Webhook extends StandardController
|
class Webhook extends StandardController
|
||||||
{
|
{
|
||||||
const HMAC_ALGO = 'sha256';
|
|
||||||
|
|
||||||
protected $bdd;
|
protected $bdd;
|
||||||
protected $model;
|
protected $model;
|
||||||
|
|
||||||
|
@ -107,7 +105,6 @@ class Webhook extends StandardController
|
||||||
public function trigger(int $id_user, string $type, array $sms)
|
public function trigger(int $id_user, string $type, array $sms)
|
||||||
{
|
{
|
||||||
$internal_setting = new Setting($this->bdd);
|
$internal_setting = new Setting($this->bdd);
|
||||||
$internal_user = new User($this->bdd);
|
|
||||||
$settings = $internal_setting->gets_for_user($id_user);
|
$settings = $internal_setting->gets_for_user($id_user);
|
||||||
|
|
||||||
if (!$settings['webhook'] ?? false)
|
if (!$settings['webhook'] ?? false)
|
||||||
|
@ -115,28 +112,13 @@ class Webhook extends StandardController
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $internal_user->get($id_user);
|
|
||||||
if (!$user)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$webhooks = $this->gets_for_type_and_user($id_user, $type);
|
$webhooks = $this->gets_for_type_and_user($id_user, $type);
|
||||||
foreach ($webhooks as $webhook)
|
foreach ($webhooks as $webhook)
|
||||||
{
|
{
|
||||||
$timestamp = time();
|
|
||||||
$webhook_random_id = $timestamp . '-' . bin2hex(openssl_random_pseudo_bytes(16));
|
|
||||||
|
|
||||||
//signature is hexa string representing hmac sha256 of webhook_random_id
|
|
||||||
$webhook_signature = hash_hmac(self::HMAC_ALGO, $webhook_random_id, $user['api_key']);
|
|
||||||
|
|
||||||
$message = [
|
$message = [
|
||||||
'url' => $webhook['url'],
|
'url' => $webhook['url'],
|
||||||
'data' => [
|
'data' => [
|
||||||
'webhook_timestamp' => $timestamp,
|
|
||||||
'webhook_type' => $webhook['type'],
|
'webhook_type' => $webhook['type'],
|
||||||
'webhook_random_id' => $webhook_random_id,
|
|
||||||
'webhook_signature' => $webhook_signature,
|
|
||||||
'id' => $sms['id'],
|
'id' => $sms['id'],
|
||||||
'at' => $sms['at'],
|
'at' => $sms['at'],
|
||||||
'text' => $sms['text'],
|
'text' => $sms['text'],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue