Skip to content

Commit 829faa8

Browse files
committed
notificationeventwebhook : htmlentities suppressed for url
1 parent 156e948 commit 829faa8

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

inc/config.class.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ class PluginWebhookConfig extends CommonDBTM {
3535
protected $usenotepad = true;
3636
const WEBHOOK_TYPE = 99;
3737

38+
protected $plugin_webhook_configs_id_field = 'plugin_webhook_configs_id';
39+
3840
static function getTypeName($nb=0) {
3941

4042
return __('Webhooks Config', 'webhook');
4143
}
4244

45+
/**
46+
* called by children (PluginWebhookConfigHeader)
47+
**/
48+
public function getPluginWebhookConfigIdField()
49+
{
50+
return $this->plugin_webhook_configs_id_field;
51+
}
52+
53+
4354
// search fields from GLPI 9.3 on
4455
function rawSearchOptions() {
4556

@@ -60,7 +71,7 @@ function rawSearchOptions() {
6071
'massiveaction' => false
6172
];
6273

63-
$tab[] = [
74+
/* $tab[] = [
6475
'id' => '3',
6576
'table' => $this->getTable(),
6677
'field' => 'address',
@@ -84,7 +95,7 @@ function rawSearchOptions() {
8495
'name' => PluginWebhookSecretType::getTypeName(1),
8596
'datatype' => 'dropdown'
8697
];
87-
98+
*/
8899
$tab[] = [
89100
'id' => '10',
90101
'table' => $this->getTable(),
@@ -109,6 +120,7 @@ function defineTabs($options=[]) {
109120

110121
$ong = [];
111122
$this->addDefaultFormTab($ong);
123+
$this->addStandardTab('PluginWebhookConfigRequest', $ong, $options);
112124
$this->addStandardTab('Log', $ong, $options);
113125

114126
return $ong;
@@ -127,7 +139,7 @@ function showForm ($ID, $options=[]) {
127139
echo "</td>";
128140
echo "</tr>";
129141

130-
echo "<tr class='tab_bg_1'>";
142+
/* echo "<tr class='tab_bg_1'>";
131143
//operation
132144
echo "<td>".__('REST Verb').": </td>";
133145
echo "<td>";
@@ -152,19 +164,19 @@ function showForm ($ID, $options=[]) {
152164
echo Html::input('secret',['value' => $this->fields['secret'], 'id' => "secret" , 'width' => '100%']);
153165
echo "</td>";
154166
echo "</tr>";
155-
167+
*/
156168
echo "<tr class='tab_bg_1'>";
157169
//debug mode
158170
echo "<td>".__('Debug mode', 'webhook')."</td>";
159171
echo "<td>";
160172
Dropdown::showYesNo('debug',$this->fields['debug']);
161173
echo "</td>";
162174
//user
163-
echo "<td>".__('User')."</td>";
175+
/* echo "<td>".__('User')."</td>";
164176
echo "<td>";
165177
echo Html::input('user',['value' => $this->fields['user'], 'id' => "user" , 'size' => 50]);
166178
echo "</td>";
167-
echo "</tr>";
179+
*/ echo "</tr>";
168180

169181
$this->showFormButtons($options);
170182

inc/notificationeventwebhook.class.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
}
3131

3232
function str_replace_deep($search, $replace, $subject) {
33+
if (is_null($subject))
34+
return '';
3335
if (is_array($subject))
3436
{
3537
foreach($subject as &$oneSubject)
@@ -158,7 +160,8 @@ static public function extraRaise($params) {
158160
$key = $webhook_infos[static::getTargetFieldName()];
159161
$url = $webhook_infos['additionnaloption']['address'];
160162
$url = NotificationTemplate::process($webhook_infos['additionnaloption']['address'], $data); // substitute variables in url
161-
$url = str_replace(["\n", "\r", "\t"], ['', '', ''], htmlentities($url)); // translate HTML-significant characters and suppress remaining escape characters
163+
// $url = str_replace(["\n", "\r", "\t"], ['', '', ''], htmlentities($url)); // translate HTML-significant characters and suppress remaining escape characters
164+
$url = str_replace(["\n", "\r", "\t"], ['', '', ''], $url); // suppress remaining escape characters
162165
if ($template_datas = $template->getByLanguage($webhook_infos['language']))
163166
{
164167
$template_datas = Sanitizer::unsanitize($template_datas); // unescape html from DB
@@ -169,11 +172,12 @@ static public function extraRaise($params) {
169172
$template = $template_datas['content_html'];
170173

171174
// escape double quotes (as the LF, CR and TAB characters)
172-
$data = str_replace_deep(["\n", "\r", "\t", '"'], ['\\n', '\\r', '\\t', '\\"'], $data);
175+
$data = str_replace_deep(["\\","\n", "\r", "\t", '"'], ['\\\\', '\\n', '\\r', '\\t', '\\"'], $data);
173176

174177
$content = NotificationTemplate::process($template, $data);
175178
$curl = curl_init($url);
176-
$secrettype = $webhook_infos['additionnaloption']['plugin_webhook_secrettypes_id'];
179+
$secrettype = $webhook_infos['additionnaloption']['plugin_webhook_secrettypes_id'];
180+
$headers = array();
177181
switch ($secrettype)
178182
{
179183
case 1: // No Authentication
@@ -213,7 +217,7 @@ static public function extraRaise($params) {
213217

214218
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
215219

216-
if ( $status != 200 && $status != 201 ) {
220+
if ( $status < 200 || $status >= 300) {
217221
Session::addMessageAfterRedirect("<font color='red'>"."Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)."</font>", false, ERROR);
218222
Toolbox::logInFile("webhook", "Error : call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl).PHP_EOL."HTTP Headers : ".print_r($headers,true).PHP_EOL."POST Content : ".print_r($content,true).PHP_EOL);
219223
}

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function plugin_version_webhook() {
111111

112112
return [
113113
'name' => _n('Webhook', 'Webhooks', 2, 'webhook'),
114-
'version' => '1.0.18',
114+
'version' => '1.0.19',
115115
'author' => "Eric Feron",
116116
'license' => 'GPLv2+',
117117
'homepage'=> 'https://github.com/ericferon/glpi-webhook',

webhook.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<author>Eric Feron</author>
2323
</authors>
2424
<versions>
25+
<version>
26+
<num>1.0.19</num>
27+
<compatibility>>=10.0.3</compatibility>
28+
<download_url>https://github.com/ericferon/glpi-webhook/releases/download/v1.0.19/webhook-v1.0.19.tar.gz</download_url>
29+
</version>
2530
<version>
2631
<num>1.0.18</num>
2732
<compatibility>>=10.0.3</compatibility>

0 commit comments

Comments
 (0)