Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ public function cleanupSubtopics() {
/**
* list of topics to cleanup on unenrollment or on enrollment
*
* @return string[]
* @return array
*/
public static function getTopicsToCleanup() {
$policy = new PluginFlyvemdmPolicy();
Expand Down
8 changes: 4 additions & 4 deletions inc/policybase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface
protected $specificStatuses = [];

/**
* get common task statuses
* Gets common task statuses
*
* @return array
*/
Expand All @@ -90,7 +90,7 @@ public static final function getEnumBaseTaskStatus() {
}

/**
* get specific task statuses
* Gets specific task statuses
* To be overriden in child class
*
* @return array
Expand All @@ -117,9 +117,9 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
protected function jsonDecodeProperties($properties, array $defaultProperties) {
if (empty($properties)) {
return $defaultProperties;
} else {
$propertyCollection = json_decode($properties, true);
}

$propertyCollection = json_decode($properties, true);
if (empty($propertyCollection)) {
return $defaultProperties;
}
Expand Down
1 change: 1 addition & 0 deletions inc/policydeployapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
*
* @return array|boolean
*/
public function getMqttMessage($value, $itemtype, $itemId) {
Expand Down
4 changes: 4 additions & 0 deletions inc/policyfactory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function createFromPolicy(PluginFlyvemdmPolicy $policyData) {
$policy = new PluginFlyvemdmPolicyRemovefile($policyData);
break;

case 'm2m':
$policy = new PluginFlyvemdmPolicyM2m($policyData);
break;

default:
return null;
}
Expand Down
1 change: 1 addition & 0 deletions inc/policyinteger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
*
* @return bool
*/
public function integrityCheck($value, $itemtype, $itemId) {
Expand Down
128 changes: 128 additions & 0 deletions inc/policym2m.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* LICENSE
*
* Copyright © 2016-2018 Teclib'
* Copyright © 2010-2018 by the FusionInventory Development Team.
*
* This file is part of Flyve MDM Plugin for GLPI.
*
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile
* device management software.
*
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/.
* ------------------------------------------------------------------------------
* @author Thierry Bugier
* @copyright Copyright © 2018 Teclib
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
* @link https://github.com/flyve-mdm/glpi-plugin
* @link https://flyve-mdm.com/
* ------------------------------------------------------------------------------
*/

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}


class PluginFlyvemdmPolicyM2m extends PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface {

/** @var string $server name or IP of the server to use for M2M */

/** @var integer $port port to use for M2M */

/** @var integer $tls use TLS for M2M (1 for true, 0 for false) */

/**
* PluginFlyvemdmPolicyInteger constructor.
* @param PluginFlyvemdmPolicy $policy
*/
public function __construct(PluginFlyvemdmPolicy $policy) {
parent::__construct($policy);
$defaultProperties = [
'server' => '',
'port' => '0',
'tls' => '0',
];
$propertyCollection = $this->jsonDecodeProperties($policy->getField('type_data'),
$defaultProperties);
$this->server = $propertyCollection['server'];
$this->port = $propertyCollection['port'];
$this->tls = $propertyCollection['tls'];

$this->symbol = $policy->getField('symbol');
$this->unicityRequired = ($policy->getField('unicity') != '0');
$this->group = $policy->getField('group');
}

/**
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
*
* @return bool
*/
public function integrityCheck($value, $itemtype, $itemId) {
$keys = [
'server',
'port',
'tls'
];
$settingSufficient = false;
foreach ($keys as $key) {
if (!isset($value[$key])) {
Session::addMessageAfterRedirect(__('All parameters must be specified', 'flyvemdm'));
return false;
}
}

if (empty($value['server']) && empty($value['port'] && $value['tls'] != 0 && $value['tls'] != 1)) {
Session::addMessageAfterRedirect(__('At least one parameter must be set', 'flyvemdm'));
return false;
}

return true;
}

/**
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
*
* @return array|boolean
*/
public function getMqttMessage($value, $itemtype, $itemId) {
$decodedValue = json_decode($value, JSON_OBJECT_AS_ARRAY);
if (!$this->integrityCheck($decodedValue, $itemtype, $itemId)) {
return false;
}

$array = [
$this->symbol => $value['server'],
'port' => $value['port'],
'tls' => $value['tls'],
];

return $array;
}

public function showValueInput($value = '', $itemType = '', $itemId = 0) {
if ($value === '') {
$value = json_decode($this->policyData->getField('recommended_value'), JSON_OBJECT_AS_ARRAY);
}
$out = __('M2M server', 'flyvemdm') . '&nbsp;' . Html::input('value[server]', ['value' => $value['server']]);
$out .= '<br>' . __('Port', 'flyvemdm') . '&nbsp;' . Html::input('value[port]', ['value' => $value['port']]);
$out .= '<br>' . __('Use TLS', 'flyvemdm') . '&nbsp;' . Dropdown::showYesNo('value[tls]', $value['tls'], -1, ['display' => false]);

return $out;
}
}
23 changes: 23 additions & 0 deletions install/policies/mdm.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,27 @@

$category = 'Mobile Device Management';
return [
[
'name' => __('messaging server', 'flyvemdm'),
'symbol' => 'm2m',
'group' => 'MDM',
'type' => 'm2m',
'type_data' => '',
'unicity' => 1,
'plugin_flyvemdm_policycategories_id' => $category,
'comment' => __('messaging server', 'flyvemdm'),
'default_value' => '',
'recommended_value' => json_encode(
[
'server' => '',
'port' => '0',
'tls' => '1'
]),
'is_android_policy' => '1',
'is_android_system' => '0',
'android_min_version' => '1.0',
'android_max_version' => '0',
'apple_min_version' => '0',
'apple_max_version' => '0',
],
];
1 change: 1 addition & 0 deletions tests/src/Flyvemdm/Tests/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ public static function policyList() {
'Policy/removeFile',
'Policy/disableWifi',
'Policy/disableBluetooth',
'Policy/m2m',
'Policy/disableRoaming',
'Policy/disableGPS',
'Policy/disableUsbMtp',
Expand Down