mirror of
https://gitlab.crans.org/elkmaennchen/gitscord-webhook
synced 2025-10-11 02:00:04 +02:00
feature : add secret token handling
This commit is contained in:
parent
86e2d641b7
commit
c7ac65fc47
3 changed files with 48 additions and 31 deletions
|
@ -43,6 +43,8 @@ Définition des paramètres :
|
|||
* MR_manager : nom de l'utilisateur/rôle à mentionner lors d'une merge request
|
||||
* bot_name : nom du bot sur Discord (remplace le nom défini dans Discord)
|
||||
* bot_avatar : image de profil du bot sur Discord (remplace l'image défini dans Discord), mettre une URL absolue
|
||||
* message_highlight_color : code couleur hexadécimal de la bande sur le côté du message
|
||||
* secret : valeur du champ *confidentiel/secret token* dans la création du webhook dans Gitlab/Gitea pour plus de sécurité
|
||||
|
||||
Il suffit ensuite de mettre le fichier PHP (*gitscord_webhook.php*, mais vous pouvez le renommer à votre convenance) dans un des dossiers servis par votre serveur HTTP(S), avec le fichier *gitscord_webhook_config.json* juste a côté (ne pas renommer, ou changer le nom dans le script PHP également).
|
||||
|
||||
|
@ -89,7 +91,9 @@ Definición de los parámetros :
|
|||
* language : idioma de los mensajes enviados por el bot, elegir entre en, es y fr
|
||||
* MR_manager : nombre del usuario/rol que mencionar para una merge request
|
||||
* bot_name : nombre del bot en Discord (remplaza el nombre definido en Discord)
|
||||
* bot_avatar : imagen de perfil del bot en Discord (remplaza la imagen definida en Discord), poner una URL absoluta.
|
||||
* bot_avatar : imagen de perfil del bot en Discord (remplaza la imagen definida en Discord), poner una URL absoluta
|
||||
* message_highlight_color : código de color hexadecimal para la banda en el lado del mensaje
|
||||
* secret : *confidentiel/secret token* dado en la creación del webhook en Gitlab/Gitea para mas seguridad
|
||||
|
||||
Enseguida, solo poner el archivo PHP (*gitscord_webhook.php*, pero puede renombrar lo como quiere) en una de las carpetas de su servidor HTTP(S), con el archivo *gitscord_webhook_config.json* justo a su lado (no renombrar, o cambiar el nombre también en el script PHP).
|
||||
|
||||
|
@ -136,6 +140,8 @@ Definition of the parameters :
|
|||
* MR_manager : name of the user/role to be mentioned on a merge request
|
||||
* bot_name : name of the bot on Discord (override the name set in Discord)
|
||||
* bot_avatar : avatar image of the bot on Discord (override the image set in Discord), put an absolute URL
|
||||
* message_highlight_color : hexadecimal colour code of the message side band
|
||||
* secret : value of *confidential/secret token* given during webhook creation in Gitlab/Gitea to improve security
|
||||
|
||||
Put the PHP file (*gitscord_webhook.php*, but you can rename it as you want) in a folder of your HTTP(S) server, with the file *gitscord_webhook_config.json* in the same folder (do not rename it, or change the name in the PHP script too).
|
||||
|
||||
|
|
|
@ -31,6 +31,14 @@ if ($plainJSON != '') {
|
|||
else {
|
||||
$mhl_color = $configJSON['message_highlight_color'];
|
||||
}
|
||||
if ($configJSON['secret'] == '') { // if secret checking is not needed
|
||||
$is_secret_checked = true;
|
||||
$secret_value = "";
|
||||
}
|
||||
else {
|
||||
$is_secret_checked = false;
|
||||
$secret_value = $configJSON['secret'];
|
||||
}
|
||||
$messageJSON = array(); // JSON to send to Discord
|
||||
if ($configJSON['bot_name'] != '') {
|
||||
$messageJSON['username'] = $configJSON['bot_name'] ;
|
||||
|
@ -42,35 +50,37 @@ if ($plainJSON != '') {
|
|||
$JSON = json_decode($plainJSON, true);
|
||||
if (is_array($JSON)) { // valid JSON
|
||||
if (isset($_SERVER['HTTP_X_GITLAB_EVENT'])) { // comming from a gitlab instance
|
||||
switch ($JSON['object_kind']){ // type of event
|
||||
case "push": // push event
|
||||
$messageJSON = push_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "tag_push":
|
||||
$messageJSON = tag_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "issue": // do the same weather its confidential or not
|
||||
case "confidential_issue":
|
||||
$messageJSON = issue_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "note": // do the same weather its confidential or not
|
||||
case "confidential_note":
|
||||
$messageJSON = note_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "merge_request":
|
||||
// if somebody/somerole to hl, add him/it in the message
|
||||
if ($configJSON['MR_manager'] != '') { $hl = " @".$configJSON['MR_manager']." "; }
|
||||
else { $hl = ""; }
|
||||
$messageJSON = MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color);
|
||||
break;
|
||||
case "job":
|
||||
break;
|
||||
case "pipeline":
|
||||
break;
|
||||
case "wiki_page":
|
||||
break;
|
||||
default:
|
||||
send_error($url,"Unknown type of event");
|
||||
if ($is_secret_checked || $_SERVER['HTTP_X_GITLAB_TOKEN']==$secret_value) {
|
||||
switch ($JSON['object_kind']){ // type of event
|
||||
case "push": // push event
|
||||
$messageJSON = push_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "tag_push":
|
||||
$messageJSON = tag_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "issue": // do the same weather its confidential or not
|
||||
case "confidential_issue":
|
||||
$messageJSON = issue_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "note": // do the same weather its confidential or not
|
||||
case "confidential_note":
|
||||
$messageJSON = note_layout($messageJSON,$JSON,$lang,$mhl_color);
|
||||
break;
|
||||
case "merge_request":
|
||||
// if somebody/somerole to hl, add him/it in the message
|
||||
if ($configJSON['MR_manager'] != '') { $hl = " @".$configJSON['MR_manager']." "; }
|
||||
else { $hl = ""; }
|
||||
$messageJSON = MR_layout($messageJSON,$JSON,$lang,$hl,$mhl_color);
|
||||
break;
|
||||
case "job":
|
||||
break;
|
||||
case "pipeline":
|
||||
break;
|
||||
case "wiki_page":
|
||||
break;
|
||||
default:
|
||||
send_error($url,"Unknown type of event");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
"MR_manager":"role-in-charge-of-MR",
|
||||
"bot_name":"Git Stalk",
|
||||
"bot_avatar":"https://railsware.com/blog/wp-content/uploads/2014/08/git-housekeeping.png",
|
||||
"message_highlight_color":"FF7000"
|
||||
"message_highlight_color":"FF7000",
|
||||
"secret":"secret token"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue