Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit b6b28a0

Browse files
committed
feat(config): lock mqtt prefix if new data is created
Signed-off-by: Domingo Oropeza <[email protected]>
1 parent 44a68e3 commit b6b28a0

6 files changed

+26
-2
lines changed

inc/agent.class.php

+4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ public function prepareInputForUpdate($input) {
548548
public function post_addItem() {
549549
// Notify the agent about its fleets
550550
$this->updateSubscription();
551+
552+
if (PluginFlyvemdmConfig::canUpdate()) {
553+
// Here we must update mqtt_prefix_locked
554+
}
551555
}
552556

553557
public function post_getFromDB() {

inc/config.class.php

+7
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,11 @@ public function isGlpiConfigured() {
531531

532532
return true;
533533
}
534+
535+
public function prepareInputForUpdate($input) {
536+
if ($input['mqtt_prefix'] != $this->fields['mqtt_prefix'] && $this->fields['mqtt_prefix_locked'] == 0) {
537+
$input['mqtt_prefix_locked'] = 1;
538+
}
539+
return $input;
540+
}
534541
}

inc/fleet.class.php

+4
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ public function post_addItem() {
315315
$topic = $this->getTopic();
316316
$this->notify("$topic/Policy/$policyName", null, 0, 1);
317317
}
318+
319+
if (PluginFlyvemdmConfig::canUpdate()) {
320+
// Here we must update mqtt_prefix_locked
321+
}
318322
}
319323

320324
/**

inc/invitation.class.php

+4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ public function post_addItem() {
244244

245245
// Sent invitation email
246246
$this->sendInvitation();
247+
248+
if (PluginFlyvemdmConfig::canUpdate()) {
249+
// Here we must update mqtt_prefix_locked
250+
}
247251
}
248252

249253
public function post_updateItem($history = 1) {

install/installer.class.php

+1
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ protected function createInitialConfig() {
601601
'mqtt_user' => self::BACKEND_MQTT_USER,
602602
'mqtt_passwd' => $MdmMqttPassword,
603603
'mqtt_prefix' => '',
604+
'mqtt_prefix_locked' => '0',
604605
'instance_id' => $instanceId,
605606
'registered_profiles_id' => '',
606607
'guest_profiles_id' => '',

tpl/config-messagequeue.html.twig

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
</tr>
2323
<tr class="tab_bg_1">
2424
<td>{{ __('MQTT prefix', 'flyvemdm') }}</td>
25-
<td><input type="text" name="mqtt_prefix" value="{{ config.mqtt_prefix }}"></td>
26-
<td>{{ __('Prepend all topics with a prefix (useful if a MQTT broker is mutualized). The mqtt daemon must be restarted.', 'flyvemdm') }}</td>
25+
<td><input type="text" name="mqtt_prefix" value="{{ config.mqtt_prefix }}"
26+
{% if (config.mqtt_prefix_locked) == 1 %}disabled{% endif %}></td>
27+
<td>{{ __('Prepend all topics with a prefix (useful if a MQTT broker is mutualized). The mqtt daemon must be restarted after the change.', 'flyvemdm') }}
28+
<br>
29+
<span class="red">{{ __('Note: This value can be changed only once and if no new invitation, agent or fleet has been created.', 'flyvemdm') }}</span>
30+
</td>
2731
</tr>
2832
<tr class="tab_bg_1">
2933
<td>{{ __('MQTT broker port for TLS', 'flyvemdm') }}</td>

0 commit comments

Comments
 (0)