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

Commit 0ff79c1

Browse files
committed
fix(agent): updated code for not register invalid user agents
1 parent 5399fde commit 0ff79c1

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

inc/agent.class.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,33 +1124,6 @@ protected function enrollByInvitationToken($input) {
11241124

11251125
$entityId = $invitation->getField('entities_id');
11261126

1127-
//create agent user account
1128-
$agentAccount = new User();
1129-
$agentAccount->add([
1130-
'usercategories_id' => $config['agentusercategories_id'],
1131-
'name' => 'flyvemdm-' . PluginFlyvemdmCommon::generateUUID(),
1132-
'realname' => $serial,
1133-
'_profiles_id' => $config['agent_profiles_id'],
1134-
'profiles_id' => $config['agent_profiles_id'], // Default profile when user logs in
1135-
'_entities_id' => $entityId,
1136-
'_is_recursive' => 0,
1137-
]);
1138-
1139-
if ($agentAccount->isNewItem()) {
1140-
$event = __('Cannot create a user account for the agent', 'flyvemdm');
1141-
$this->filterMessages($event);
1142-
$this->logInvitationEvent($invitation, $event);
1143-
return false;
1144-
}
1145-
1146-
$agentToken = User::getToken($agentAccount->getID(), 'api_token');
1147-
if ($agentToken === false) {
1148-
$event = __('Cannot create the API token for the agent', 'flyvemdm');
1149-
$this->filterMessages($event);
1150-
$this->logInvitationEvent($invitation, $event);
1151-
return false;
1152-
}
1153-
11541127
//sign the agent's certificate (if TLS enabled)
11551128
if ($config['mqtt_tls_for_clients'] != '0' && $config['mqtt_use_client_cert'] != '0') {
11561129
$answer = self::signCertificate($csr);
@@ -1239,6 +1212,33 @@ protected function enrollByInvitationToken($input) {
12391212
'users_id' => $userId,
12401213
]);
12411214

1215+
//create agent user account
1216+
$agentAccount = new User();
1217+
$agentAccount->add([
1218+
'usercategories_id' => $config['agentusercategories_id'],
1219+
'name' => 'flyvemdm-' . PluginFlyvemdmCommon::generateUUID(),
1220+
'realname' => $serial,
1221+
'_profiles_id' => $config['agent_profiles_id'],
1222+
'profiles_id' => $config['agent_profiles_id'], // Default profile when user logs in
1223+
'_entities_id' => $entityId,
1224+
'_is_recursive' => 0,
1225+
]);
1226+
1227+
if ($agentAccount->isNewItem()) {
1228+
$event = __('Cannot create a user account for the agent', 'flyvemdm');
1229+
$this->filterMessages($event);
1230+
$this->logInvitationEvent($invitation, $event);
1231+
return false;
1232+
}
1233+
1234+
$agentToken = User::getToken($agentAccount->getID(), 'api_token');
1235+
if ($agentToken === false) {
1236+
$event = __('Cannot create the API token for the agent', 'flyvemdm');
1237+
$this->filterMessages($event);
1238+
$this->logInvitationEvent($invitation, $event);
1239+
return false;
1240+
}
1241+
12421242
// Create the agent
12431243
$defaultFleet = PluginFlyvemdmFleet::getDefaultFleet();
12441244
if ($defaultFleet === null) {

0 commit comments

Comments
 (0)