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

Commit

Permalink
feat(enrollment): bug collector settings
Browse files Browse the repository at this point in the history
sends to devices an URL and credentiels to allow them to send bug
reports
  • Loading branch information
btry committed Dec 16, 2016
1 parent e9cd70d commit 4ec7a62
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
36 changes: 18 additions & 18 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1285,19 +1285,17 @@ protected function chooseEnrollMethod($input) {
*/
protected function setupMqttAccess() {
if ($user = $this->getOwner()) {
$config = Config::getConfigurationValues('storkmdm', array('guest_profiles_id'));
$config = Config::getConfigurationValues('storkmdm', array(
'guest_profiles_id',
'android_bugcollecctor_url',
'android_bugcollector_login',
'android_bugcollector_passwd',
'mqtt_broker_address',
'mqtt_broker_port',
'mqtt_broker_tls',
));
$guestProfileId = $config['guest_profiles_id'];
if ($user->getID() == $_SESSION['glpiID'] && $_SESSION['glpiactiveprofile']['id'] == $guestProfileId) {
// Read config for MQTT broker
$config = Config::getConfigurationValues(
'storkmdm',
array(
'mqtt_broker_address',
'mqtt_broker_port',
'mqtt_broker_tls',
)
);

$mqttClearPassword = '';

// Create, or re-eanble the mqtt user for the device
Expand Down Expand Up @@ -1328,9 +1326,9 @@ protected function setupMqttAccess() {
];

$mqttUser = new PluginStorkmdmMqttuser();
$mqttClearPassword = PluginStorkmdmMqttuser::getRandomPassword();
if (!$mqttUser->getByUser($serial)) {
// The user does not exists
$mqttClearPassword = PluginStorkmdmMqttuser::getRandomPassword();
$mqttUser->add([
'user' => $serial,
'enabled' => '1',
Expand All @@ -1340,7 +1338,6 @@ protected function setupMqttAccess() {
]);
} else {
// The user exists
$mqttClearPassword = PluginStorkmdmMqttuser::getRandomPassword();
$mqttUser->update([
'id' => $mqttUser->getID(),
'enabled' => '1',
Expand All @@ -1353,11 +1350,14 @@ protected function setupMqttAccess() {
}

// The request comes from the owner of the device or the device itself, mandated by the user
$this->fields['topic'] = $this->getTopic();
$this->fields['mqttpasswd'] = $mqttClearPassword;
$this->fields['broker'] = $config['mqtt_broker_address'];
$this->fields['port'] = $config['mqtt_broker_port'];
$this->fields['tls'] = $config['mqtt_broker_tls'];
$this->fields['topic'] = $this->getTopic();
$this->fields['mqttpasswd'] = $mqttClearPassword;
$this->fields['broker'] = $config['mqtt_broker_address'];
$this->fields['port'] = $config['mqtt_broker_port'];
$this->fields['tls'] = $config['mqtt_broker_tls'];
$this->fields['android_bugcollecctor_url'] = $config['android_bugcollecctor_url'];
$this->fields['android_bugcollector_login'] = $config['android_bugcollector_login'];
$this->fields['android_bugcollector_passwd'] = $config['android_bugcollector_passwd'];
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ public function showForm() {
echo '<td>'. '' .'</td>';
echo '</tr>';

echo '<tr><th colspan="3">'.__('Bug collector', "storkmdm").'</th></tr>';

echo '<tr class="tab_bg_1">';
echo '<td>'. __("Android bug collector URL", "storkmdm").'</td>';
echo '<td><input type="text" name="android_bugcollecctor_url"' .
'value="'. $config['android_bugcollecctor_url'] .'" />';
echo '</td>';
echo '<td>'. __("https://bugreport.flyvemdm.com/path/to/service", "storkmdm").'</td>';
echo '</tr>';

echo '<tr class="tab_bg_1">';
echo '<td>'. __("Android bug collector user", "storkmdm").'</td>';
echo '<td><input type="text" name="android_bugcollector_login"' .
'value="'. $config['android_bugcollector_login'] .'" />';
echo '</td>';
echo '<td></td>';
echo '</tr>';

echo '<tr class="tab_bg_1">';
echo '<td>'. __("Android bug collector password", "storkmdm").'</td>';
echo '<td><input type="password" name="android_bugcollector_passwd"' .
'value="'. $config['android_bugcollector_passwd'] .'" />';
echo '</td>';
echo '<td></td>';
echo '</tr>';

echo '<tr><th colspan="3">'.__('Restrictions', "storkmdm").'</th></tr>';

echo '<tr class="tab_bg_1">';
Expand Down
3 changes: 3 additions & 0 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ protected function createInitialConfig() {
'ssl_cert_url' => '',
'default_device_limit' => '0',
'default_agent_url' => PLUGIN_STORKMDM_AGENT_DOWNLOAD_URL,
'android_bugcollecctor_url' => '',
'android_bugcollector_login' => '',
'android_bugcollector_passwd' => '',
];
Config::setConfigurationValues("storkmdm", $newConfig);
$this->createBackendMqttUser(self::BACKEND_MQTT_USER, $MdmMqttPassword);
Expand Down
9 changes: 4 additions & 5 deletions tests/0010_Integration/DeviceEnrollmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ public function testGetEnrollData($agent) {
$this->assertTrue(isset($agent->fields['broker']));
$this->assertTrue(isset($agent->fields['port']));
$this->assertTrue(isset($agent->fields['tls']));
// test disabled for now
//$this->assertTrue(isset($agent->fields['android_bugcollecctor_url']));
//$this->assertTrue(isset($agent->fields['android_bugcollector_login']));
//$this->assertTrue(isset($agent->fields['android_bugcollector_passwd']));
//$this->assertTrue(isset($agent->fields['version']));
$this->assertTrue(isset($agent->fields['android_bugcollecctor_url']));
$this->assertTrue(isset($agent->fields['android_bugcollector_login']));
$this->assertTrue(isset($agent->fields['android_bugcollector_passwd']));
$this->assertTrue(isset($agent->fields['version']));

return $agent;
}
Expand Down

0 comments on commit 4ec7a62

Please sign in to comment.