Skip to content

Commit b7b1d6d

Browse files
committed
Add configuration for proxy exclusions
1 parent 1bc9714 commit b7b1d6d

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

install/empty_data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function getEmptyData(): array
198198
'proxy_name' => '',
199199
'proxy_port' => '8080',
200200
'proxy_user' => '',
201+
'proxy_exclusions' => '',
201202
'add_followup_on_update_ticket' => '1',
202203
'keep_tickets_on_delete' => '0',
203204
'time_step' => '5',
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
12+
*
13+
* ---------------------------------------------------------------------
14+
*
15+
* LICENSE
16+
*
17+
* This file is part of GLPI.
18+
*
19+
* This program is free software: you can redistribute it and/or modify
20+
* it under the terms of the GNU General Public License as published by
21+
* the Free Software Foundation, either version 3 of the License, or
22+
* (at your option) any later version.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
31+
*
32+
* ---------------------------------------------------------------------
33+
*/
34+
/**
35+
* @var Migration $migration
36+
*/
37+
$migration->addConfig(['proxy_exclusions' => exportArrayToDB([])]);

src/Agent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ public function getAgentURLs(): array
690690
*/
691691
public function requestAgent($endpoint): Response
692692
{
693+
global $CFG_GLPI;
694+
693695
if (self::$found_address !== false) {
694696
$addresses = [self::$found_address];
695697
} else {
@@ -703,6 +705,10 @@ public function requestAgent($endpoint): Response
703705
'base_uri' => $address,
704706
];
705707

708+
if (in_array(self::class, $CFG_GLPI['proxy_exclusions'])) {
709+
$options['proxy_excluded'] = true;
710+
}
711+
706712
// init guzzle client with base options
707713
$httpClient = Toolbox::getGuzzleClient($options);
708714
try {

src/Config.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ public function prepareInputForUpdate($input)
274274
);
275275
}
276276

277+
if (isset($input['proxy_exclusions'])) {
278+
$input['proxy_exclusions'] = exportArrayToDB(
279+
ArrayNormalizer::normalizeValues($input['proxy_exclusions'] ?: [], 'strval')
280+
);
281+
}
282+
277283
// lock mechanism update
278284
if (isset($input['lock_use_lock_item']) && isset($input['lock_item_list'])) {
279285
$input['lock_item_list'] = exportArrayToDB(
@@ -860,6 +866,12 @@ public function showSystemInformations()
860866
TemplateRenderer::getInstance()->display('pages/setup/general/systeminfo_form.html.twig', [
861867
'config' => $CFG_GLPI,
862868
'canedit' => static::canUpdate(),
869+
'possible_proxy_exclusions' => array_merge(
870+
[
871+
Agent::class => Agent::getTypeName(),
872+
],
873+
$CFG_GLPI['possible_proxy_exclusions']
874+
),
863875
]);
864876
self::showSystemInfoTable();
865877
}
@@ -1368,6 +1380,10 @@ public static function loadLegacyConfiguration()
13681380
$CFG_GLPI['lock_item_list'] = importArrayFromDB($CFG_GLPI['lock_item_list']);
13691381
}
13701382

1383+
if (isset($CFG_GLPI['proxy_exclusions'])) {
1384+
$CFG_GLPI['proxy_exclusions'] = importArrayFromDB($CFG_GLPI['proxy_exclusions']);
1385+
}
1386+
13711387
if (
13721388
isset($CFG_GLPI['lock_lockprofile_id'])
13731389
&& $CFG_GLPI['lock_use_lock_item']
@@ -1728,6 +1744,7 @@ public function post_updateItem($history = true)
17281744
'lock_item_list',
17291745
'planning_work_days',
17301746
Impact::CONF_ENABLED,
1747+
'proxy_exclusions',
17311748
];
17321749
if (in_array($this->fields['name'], $array_fields, true)) {
17331750
$CFG_GLPI[$this->fields['name']] = importArrayFromDB($newvalue);

src/Toolbox.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,8 @@ public static function getGuzzleClient(array $extra_options = []): Client
13381338
global $CFG_GLPI;
13391339

13401340
$options = $extra_options + ['connect_timeout' => 5];
1341-
// add proxy string if configured in glpi
1342-
if (!empty($CFG_GLPI["proxy_name"])) {
1341+
// add proxy string if configured in glpi - and not excluded
1342+
if (!empty($CFG_GLPI["proxy_name"]) && ($extra_options['proxy_excluded'] ?? false) === false) {
13431343
$proxy_creds = "";
13441344
if (!empty($CFG_GLPI["proxy_user"])) {
13451345
$proxy_user = rawurlencode($CFG_GLPI["proxy_user"]);
@@ -1379,7 +1379,7 @@ public static function callCurl(
13791379
$PHPLOGGER->error($e->getMessage(), ['exception' => $e]);
13801380

13811381
$curl_error = $e->getMessage();
1382-
if (empty($CFG_GLPI["proxy_name"])) {
1382+
if (empty($CFG_GLPI["proxy_name"]) || ($eopts['proxy_excluded'] ?? false)) {
13831383
$msgerr = sprintf(
13841384
__('Connection failed. If you use a proxy, please configure it. (%s)'),
13851385
$curl_error
@@ -1446,6 +1446,11 @@ private static function doCallCurl(
14461446
}
14471447

14481448
$ch = curl_init($url);
1449+
$proxy_excluded = false;
1450+
if (isset($eopts['proxy_excluded'])) {
1451+
$proxy_excluded = (bool) $eopts['proxy_excluded'];
1452+
unset($eopts['proxy_excluded']);
1453+
}
14491454
$opts = [
14501455
CURLOPT_URL => $url,
14511456
CURLOPT_USERAGENT => "GLPI/" . trim($CFG_GLPI["version"]),
@@ -1457,7 +1462,7 @@ private static function doCallCurl(
14571462
$opts[CURLOPT_FOLLOWLOCATION] = false;
14581463
}
14591464

1460-
if (!empty($CFG_GLPI["proxy_name"])) {
1465+
if (!empty($CFG_GLPI["proxy_name"]) && !$proxy_excluded) {
14611466
// Connection using proxy
14621467
$opts += [
14631468
CURLOPT_PROXY => $CFG_GLPI['proxy_name'],

src/autoload/CFG_GLPI.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,5 @@
645645

646646
$CFG_GLPI['process_types'] = [Computer::class];
647647
$CFG_GLPI['environment_types'] = [Computer::class];
648+
649+
$CFG_GLPI['possible_proxy_exclusions'] = [];

templates/pages/setup/general/systeminfo_form.html.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@
6565
}
6666
}) }}
6767

68+
{{ fields.dropdownArrayField(
69+
'proxy_exclusions',
70+
null,
71+
possible_proxy_exclusions,
72+
__('Proxy exclusions'),
73+
{
74+
multiple: true,
75+
size: 3,
76+
values: config['proxy_exclusions']
77+
}
78+
) }}
79+
6880
{{ fields.smallTitle(__('Telemetry data')) }}
6981
{% set telemetry_enabled = call('Telemetry::isEnabled') %}
7082
{{ fields.htmlField('', telemetry_enabled ? __('Yes') : __('No'), __('Telemetry enabled'), {

0 commit comments

Comments
 (0)