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

Commit d463d93

Browse files
btryDIOHz0r
authored andcommitted
feat(policy): redesign use TLS policy
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 88d7a0c commit d463d93

File tree

8 files changed

+163
-5
lines changed

8 files changed

+163
-5
lines changed

inc/agent.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ public function cleanupSubtopics() {
14901490
/**
14911491
* list of topics to cleanup on unenrollment or on enrollment
14921492
*
1493-
* @return string[]
1493+
* @return array
14941494
*/
14951495
public static function getTopicsToCleanup() {
14961496
$policy = new PluginFlyvemdmPolicy();

inc/policybase.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface
6969
protected $specificStatuses = [];
7070

7171
/**
72-
* get common task statuses
72+
* Gets common task statuses
7373
*
7474
* @return array
7575
*/
@@ -90,7 +90,7 @@ public static final function getEnumBaseTaskStatus() {
9090
}
9191

9292
/**
93-
* get specific task statuses
93+
* Gets specific task statuses
9494
* To be overriden in child class
9595
*
9696
* @return array
@@ -117,9 +117,9 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
117117
protected function jsonDecodeProperties($properties, array $defaultProperties) {
118118
if (empty($properties)) {
119119
return $defaultProperties;
120-
} else {
121-
$propertyCollection = json_decode($properties, true);
122120
}
121+
122+
$propertyCollection = json_decode($properties, true);
123123
if (empty($propertyCollection)) {
124124
return $defaultProperties;
125125
}

inc/policydeployapplication.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
9191
* @param mixed $value
9292
* @param mixed $itemtype
9393
* @param integer $itemId
94+
*
9495
* @return array|boolean
9596
*/
9697
public function getMqttMessage($value, $itemtype, $itemId) {

inc/policyfactory.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public function createFromPolicy(PluginFlyvemdmPolicy $policyData) {
7979
$policy = new PluginFlyvemdmPolicyRemovefile($policyData);
8080
break;
8181

82+
case 'm2m':
83+
$policy = new PluginFlyvemdmPolicyM2m($policyData);
84+
break;
85+
8286
default:
8387
return null;
8488
}

inc/policyinteger.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
7272
* @param mixed $value
7373
* @param mixed $itemtype
7474
* @param integer $itemId
75+
*
7576
* @return bool
7677
*/
7778
public function integrityCheck($value, $itemtype, $itemId) {

inc/policym2m.class.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* LICENSE
4+
*
5+
* Copyright © 2016-2018 Teclib'
6+
* Copyright © 2010-2018 by the FusionInventory Development Team.
7+
*
8+
* This file is part of Flyve MDM Plugin for GLPI.
9+
*
10+
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile
11+
* device management software.
12+
*
13+
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or
14+
* modify it under the terms of the GNU Affero General Public License as published
15+
* by the Free Software Foundation, either version 3 of the License, or
16+
* (at your option) any later version.
17+
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/.
23+
* ------------------------------------------------------------------------------
24+
* @author Thierry Bugier
25+
* @copyright Copyright © 2018 Teclib
26+
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
27+
* @link https://github.com/flyve-mdm/glpi-plugin
28+
* @link https://flyve-mdm.com/
29+
* ------------------------------------------------------------------------------
30+
*/
31+
32+
if (!defined('GLPI_ROOT')) {
33+
die("Sorry. You can't access this file directly");
34+
}
35+
36+
37+
class PluginFlyvemdmPolicyM2m extends PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface {
38+
39+
/** @var string $server name or IP of the server to use for M2M */
40+
41+
/** @var integer $port port to use for M2M */
42+
43+
/** @var integer $tls use TLS for M2M (1 for true, 0 for false) */
44+
45+
/**
46+
* PluginFlyvemdmPolicyInteger constructor.
47+
* @param PluginFlyvemdmPolicy $policy
48+
*/
49+
public function __construct(PluginFlyvemdmPolicy $policy) {
50+
parent::__construct($policy);
51+
$defaultProperties = [
52+
'server' => '',
53+
'port' => '0',
54+
'tls' => '0',
55+
];
56+
$propertyCollection = $this->jsonDecodeProperties($policy->getField('type_data'),
57+
$defaultProperties);
58+
$this->server = $propertyCollection['server'];
59+
$this->port = $propertyCollection['port'];
60+
$this->tls = $propertyCollection['tls'];
61+
62+
$this->symbol = $policy->getField('symbol');
63+
$this->unicityRequired = ($policy->getField('unicity') != '0');
64+
$this->group = $policy->getField('group');
65+
}
66+
67+
/**
68+
* @param mixed $value
69+
* @param mixed $itemtype
70+
* @param integer $itemId
71+
*
72+
* @return bool
73+
*/
74+
public function integrityCheck($value, $itemtype, $itemId) {
75+
$keys = [
76+
'server',
77+
'port',
78+
'tls'
79+
];
80+
$settingSufficient = false;
81+
foreach ($keys as $key) {
82+
if (!isset($value[$key])) {
83+
Session::addMessageAfterRedirect(__('All parameters must be specified', 'flyvemdm'));
84+
return false;
85+
}
86+
}
87+
88+
if (empty($value['server']) && empty($value['port'] && $value['tls'] != 0 && $value['tls'] != 1)) {
89+
Session::addMessageAfterRedirect(__('At least one parameter must be set', 'flyvemdm'));
90+
return false;
91+
}
92+
93+
return true;
94+
}
95+
96+
/**
97+
* @param mixed $value
98+
* @param mixed $itemtype
99+
* @param integer $itemId
100+
*
101+
* @return array|boolean
102+
*/
103+
public function getMqttMessage($value, $itemtype, $itemId) {
104+
$decodedValue = json_decode($value, JSON_OBJECT_AS_ARRAY);
105+
if (!$this->integrityCheck($decodedValue, $itemtype, $itemId)) {
106+
return false;
107+
}
108+
109+
$array = [
110+
$this->symbol => $value['server'],
111+
'port' => $value['port'],
112+
'tls' => $value['tls'],
113+
];
114+
115+
return $array;
116+
}
117+
118+
public function showValueInput($value = '', $itemType = '', $itemId = 0) {
119+
if ($value === '') {
120+
$value = json_decode($this->policyData->getField('recommended_value'), JSON_OBJECT_AS_ARRAY);
121+
}
122+
$out = __('M2M server', 'flyvemdm') . '&nbsp;' . Html::input('value[server]', ['value' => $value['server']]);
123+
$out .= '<br>' . __('Port', 'flyvemdm') . '&nbsp;' . Html::input('value[port]', ['value' => $value['port']]);
124+
$out .= '<br>' . __('Use TLS', 'flyvemdm') . '&nbsp;' . Dropdown::showYesNo('value[tls]', $value['tls'], -1, ['display' => false]);
125+
126+
return $out;
127+
}
128+
}

install/policies/mdm.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,27 @@
3535

3636
$category = 'Mobile Device Management';
3737
return [
38+
[
39+
'name' => __('messaging server', 'flyvemdm'),
40+
'symbol' => 'm2m',
41+
'group' => 'MDM',
42+
'type' => 'm2m',
43+
'type_data' => '',
44+
'unicity' => 1,
45+
'plugin_flyvemdm_policycategories_id' => $category,
46+
'comment' => __('messaging server', 'flyvemdm'),
47+
'default_value' => '',
48+
'recommended_value' => json_encode(
49+
[
50+
'server' => '',
51+
'port' => '0',
52+
'tls' => '1'
53+
]),
54+
'is_android_policy' => '1',
55+
'is_android_system' => '0',
56+
'android_min_version' => '1.0',
57+
'android_max_version' => '0',
58+
'apple_min_version' => '0',
59+
'apple_max_version' => '0',
60+
],
3861
];

tests/src/Flyvemdm/Tests/CommonTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ public static function policyList() {
566566
'Policy/removeFile',
567567
'Policy/disableWifi',
568568
'Policy/disableBluetooth',
569+
'Policy/m2m',
569570
'Policy/disableRoaming',
570571
'Policy/disableGPS',
571572
'Policy/disableUsbMtp',

0 commit comments

Comments
 (0)