@@ -1277,91 +1277,46 @@ protected function enrollByInvitationToken($input) {
1277
1277
}
1278
1278
1279
1279
/**
1280
- * @param string $serial
1281
- * @param array $authFactors
1282
- * @param string $csr Certificate Signing Request from the agent
1283
- * @param &string $notFoundMessage Contains the error message if the enrollment failed
1284
- * @return boolean|PluginFlyvemdmAgent
1285
- *
1280
+ * Attemt to enroll with an entity invitation token
1281
+ * @param array $input Enrollment data
1282
+ * @return array|bool
1286
1283
*/
1287
- //protected static function enrollByEntityToken($serial, $authFactors, $csr, &$errorMessage) {
1288
- //global $DB;
1289
-
1290
- //$token = $DB->escape($authFactors['entityToken']);
1291
-
1292
- //// Find an entity matching the given token
1293
- //$entity = new PluginFlyvemdmEntityconfig();
1294
- //if (! $entity->getFromDBByQuery("WHERE `enroll_token`='$token'")) {
1295
- // $errorMessage = "no entity token not found";
1296
- // return false;
1297
- //}
1298
-
1299
- //// Create a new computer for the device being enrolled
1300
- //// TODO : Enable localization of the type
1301
- //$computerType = new ComputerType();
1302
- //$computerTypeId = $computerType->import(['name' => 'Smartphone']);
1303
- //if ($computerTypeId == -1 || $computerTypeId === false) {
1304
- // $computerTypeId = 0;
1305
- //}
1306
- //$computer = new Computer();
1307
- //$condition = "`serial`='" . $DB->escape($serial) . "' AND `entities_id`='" . $entity->getID() . "'";
1308
- //$computerCollection = $computer->find($condition);
1309
- //if (count($computerCollection) > 1) {
1310
- // $errorMessage = "failed to find the computer";
1311
- // return false;
1312
- //}
1313
- //if (count($computerCollection) == 1) {
1314
-
1315
- // reset($computerCollection);
1316
- // $computer->getFromDB(key($computerCollection));
1317
- // $computerId = $computer->getID();
1318
-
1319
- //} else {
1320
- // $computerId = $computer->add([
1321
- // 'entities_id' => $entity->getID(),
1322
- // 'serial' => $serial,
1323
- // 'computertypes_id' => $computerTypeId
1324
- // ]);
1325
-
1326
- // if ($computerId === false) {
1327
- // $errorMessage = "failed to create the computer";
1328
- // return false;
1329
- // }
1330
- //}
1331
-
1332
- //if (! $computerId > 0) {
1333
- // $errorMessage = "failed to update the computer";
1334
- // return false;
1335
- //}
1336
-
1337
- //// Create an agent for this device, linked to the new computer
1338
- //$agent = new PluginFlyvemdmAgent();
1339
- //$condition = "`computers_id`='$computerId'";
1340
- //$agentCollection = $agent->find($condition);
1341
- //if (count($agentCollection) > 1) {
1342
- // return false;
1343
- //}
1344
- //if (count($agentCollection) == 1) {
1345
-
1346
- // reset($agentCollection);
1347
- // $agent->getFromDB(key($agentCollection));
1348
- // $agentId = $agent->getId();
1349
-
1350
- //} else {
1351
- // $agentId = $agent->add([
1352
- // 'entities_id' => $entity->getID(),
1353
- // 'computers_id' => $computer->getID(),
1354
- // 'token_expire' => '0000-00-00 00:00:00'
1355
- // ]);
1356
- //}
1357
-
1358
- //if (! $agentId > 0) {
1359
- // return false;
1360
- //}
1361
-
1362
- //return $agent;
1363
-
1364
- //}
1284
+ protected function enrollByEntityToken ($ input ) {
1285
+ $ invitationToken = isset ($ input ['_invitation_token ' ]) ? $ input ['_invitation_token ' ] : null ;
1286
+ $ serial = isset ($ input ['_serial ' ]) ? $ input ['_serial ' ] : null ;
1287
+ $ uuid = isset ($ input ['_uuid ' ]) ? $ input ['_uuid ' ] : null ;
1288
+ $ csr = isset ($ input ['csr ' ]) ? $ input ['csr ' ] : null ;
1289
+ $ version = isset ($ input ['version ' ]) ? $ input ['version ' ] : null ;
1290
+ $ mdmType = isset ($ input ['type ' ]) ? $ input ['type ' ] : null ;
1291
+ $ inventory = isset ($ input ['inventory ' ]) ? htmlspecialchars_decode ($ input ['inventory ' ], ENT_XML1 ) : null ;
1292
+ $ systemPermission = isset ($ input ['has_system_permission ' ]) ? $ input ['has_system_permission ' ] : 0 ;
1293
+ // For non-android agents, system permssion might be forced to 1 depending on the lack of such cosntraint
1294
+
1295
+ $ input = [];
1296
+
1297
+ // Find the invitation
1298
+ $ entityConfig = new PluginFlyvemdmEntityconfig ();
1299
+ if (!$ entityConfig ->getFromDBByToken ($ invitationToken )) {
1300
+ $ this ->filterMessages (__ ('Invitation token invalid ' , 'flyvemdm ' ));
1301
+ return false ;
1302
+ }
1303
+
1304
+ // To be written
1305
+ // ...
1306
+
1307
+ $ input ['name ' ] = $ email ;
1308
+ $ input ['computers_id ' ] = $ computerId ;
1309
+ $ input ['entities_id ' ] = $ entityId ;
1310
+ $ input ['plugin_flyvemdm_fleets_id ' ] = $ defaultFleet ->getID ();
1311
+ $ input ['_invitations_id ' ] = $ invitation ->getID ();
1312
+ $ input ['enroll_status ' ] = 'enrolled ' ;
1313
+ $ input ['version ' ] = $ version ;
1314
+ $ input ['users_id ' ] = $ agentAccount ->getID ();
1315
+ $ input ['mdm_type ' ] = $ mdmType ;
1316
+ $ input ['$systemPermission ' ] = $ systemPermission ;
1317
+
1318
+ return $ input ;
1319
+ }
1365
1320
1366
1321
/**
1367
1322
* Erase delete persisted MQTT topics of the agent
0 commit comments