Skip to content

Commit 23a2f6c

Browse files
committed
Add checks
Fix uninstall
1 parent 740fcc3 commit 23a2f6c

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

hook.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,17 @@ function plugin_addressing_uninstall()
331331
//Delete rights associated with the plugin
332332
$profileRight = new ProfileRight();
333333

334+
// getAllRights() only exposes the main 'plugin_addressing' right (both of its
335+
// entries share that $rightname); installation (createFirstAccess /
336+
// migrateProfiles) additionally registers the dedicated
337+
// 'plugin_addressing_use_ping_in_equipment' right. Purge both explicitly,
338+
// otherwise the ping right stays orphaned in glpi_profilerights after uninstall.
339+
$right_names = ['plugin_addressing_use_ping_in_equipment'];
334340
foreach (Profile::getAllRights() as $right) {
335-
$profileRight->deleteByCriteria(['name' => $right['field']]);
341+
$right_names[] = $right['field'];
342+
}
343+
foreach (array_unique($right_names) as $right_name) {
344+
$profileRight->deleteByCriteria(['name' => $right_name]);
336345
}
337346

338347
Profile::removeRightsFromSession();

src/Ping_Equipment.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public function ping($system, $ip, $return = "list")
159159
case 0:
160160
// linux ping
161161
if ($return == "true") {
162-
exec("ping -c 1 -w 1 " . escapeshellarg($ip), $list);
162+
exec("ping -n -c 1 -w 1 " . escapeshellarg($ip), $list);
163163
} else {
164-
exec("ping -c 1 -w 1 " . escapeshellarg($ip), $list, $error);
164+
exec("ping -n -c 1 -w 1 " . escapeshellarg($ip), $list, $error);
165165
}
166166
$nb = count($list);
167167
if (isset($nb) && $return == "true") {
@@ -210,9 +210,9 @@ public function ping($system, $ip, $return = "list")
210210
case 3:
211211
// BSD ping
212212
if ($return == "true") {
213-
exec("ping -c 1 -W 1 " . escapeshellarg($ip), $list);
213+
exec("ping -n -c 1 -W 1 " . escapeshellarg($ip), $list);
214214
} else {
215-
exec("ping -c 1 -W 1 " . escapeshellarg($ip), $list, $error);
215+
exec("ping -n -c 1 -W 1 " . escapeshellarg($ip), $list, $error);
216216
}
217217
$nb = count($list);
218218
if (isset($nb) && $return == "true") {
@@ -227,9 +227,9 @@ public function ping($system, $ip, $return = "list")
227227
case 4:
228228
// MacOSX ping
229229
if ($return == "true") {
230-
exec("ping -c 1 -t 1 " . escapeshellarg($ip), $list);
230+
exec("ping -n -c 1 -t 1 " . escapeshellarg($ip), $list);
231231
} else {
232-
exec("ping -c 1 -t 1 " . escapeshellarg($ip), $list, $error);
232+
exec("ping -n -c 1 -t 1 " . escapeshellarg($ip), $list, $error);
233233
}
234234
$nb = count($list);
235235
if (isset($nb) && $return == "true") {
@@ -242,7 +242,14 @@ public function ping($system, $ip, $return = "list")
242242
break;
243243
}
244244
if ($return == "list") {
245-
$list_str = implode('<br />', $list);
245+
// Ping output is external, attacker-influenced data (notably the reverse-DNS
246+
// PTR of the target IP on Unix). It is echoed as text/html by ajax/ping.php,
247+
// so escape every line before joining with the intended <br /> separators to
248+
// prevent reflected XSS; the <br /> tags stay as the only markup emitted.
249+
$list_str = implode('<br />', array_map(
250+
static fn($line): string => htmlspecialchars((string) $line, ENT_QUOTES, 'UTF-8'),
251+
$list,
252+
));
246253

247254
return [$list_str, $error];
248255
} else {

0 commit comments

Comments
 (0)