This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
profile.class.php
195 lines (173 loc) · 6.62 KB
/
profile.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/*
LICENSE
Copyright (C) 2016 Teclib'
Copyright (C) 2010-2016 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 Pineau
@copyright Copyright (c) 2016 Flyve MDM plugin team
@license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
@link https://github.com/flyve-mdm/flyve-mdm-glpi
@link http://www.glpi-project.org/
------------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* @since 0.1.0
*/
class PluginFlyvemdmProfile extends Profile {
const RIGHT_FLYVEMDM_USE = 128;
/**
* @var string $rightname name of the right in DB
*/
static $rightname = 'flyvemdm:flyvemdm';
public static function purgeProfiles(Profile $prof) {
$plugprof = new self();
$plugprof->deleteByCriteria(array('profiles_id' => $prof->getField("id")));
}
/**
* @see Profile::showForm()
*/
public function showForm($ID, $options = array()) {
if (!Profile::canView()) {
return false;
}
$canedit = Profile::canUpdate();
$profile = new Profile();
if ($ID) {
//$this->getFromDBByProfile($ID);
$profile->getFromDB($ID);
}
if ($canedit) {
echo "<form action='".$profile->getFormURL()."' method='post'>";
}
$rights = $this->getGeneralRights();
$profile->displayRightsChoiceMatrix($rights, array('canedit' => $canedit,
'default_class' => 'tab_bg_2',
'title' => __('General')
));
$rights = $this->getAssetsRights();
$profile->displayRightsChoiceMatrix($rights, array('canedit' => $canedit,
'default_class' => 'tab_bg_2',
'title' => __('Assets')
));
if ($canedit) {
echo "<div class='center'>";
echo "<input type='hidden' name='id' value=".$ID.">";
echo "<input type='submit' name='update' value=\""._sx('button', 'Save')."\" class='submit'>";
echo "</div>";
}
Html::closeForm();
$this->showLegend();
}
/**
* @see Profile::getTabNameForItem()
*/
public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
if ($item->getType() == 'Profile') {
return __('Flyve MDM', 'flyvemdm');
}
return '';
}
/**
* @deprecated
* @param CommonGLPI $item
* @param number $tabnum
* @param number $withtemplate
* @return boolean
*/
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Profile') {
$profile = new self();
$profile->showForm($item->getField('id'));
}
return true;
}
/**
* Get rights matrix for plugin
* @return array:array:string rights matrix
*/
public function getGeneralRights() {
$rights = array(
array('itemtype' => 'PluginFlyvemdmProfile',
'label' => parent::getTypeName(2),
'field' => self::$rightname,
'rights' => array(self::RIGHT_FLYVEMDM_USE => __('Use Flyve MDM'))
),
array('itemtype' => 'PluginFlyvemdmEntityconfig',
'label' => PluginFlyvemdmEntityconfig::getTypeName(2),
'field' => PluginFlyvemdmEntityconfig::$rightname,
'rights' => array(
READ => __('Read'),
PluginFlyvemdmEntityconfig::RIGHT_FLYVEMDM_DEVICE_COUNT_LIMIT => __('Write device limit'),
PluginFlyvemdmEntityconfig::RIGHT_FLYVEMDM_APP_DOWNLOAD_URL => __('Set agent download URL'),
PluginFlyvemdmEntityconfig::RIGHT_FLYVEMDM_INVITATION_TOKEN_LIFE => __('Set invitation tiken lifetime'),
)
),
array('itemtype' => 'PluginFlyvemdmInvitationLog',
'label' => PluginFlyvemdmInvitationLog::getTypeName(2),
'field' => PluginFlyvemdmInvitationLog::$rightname,
'rights' => array(
READ => __('Read'),
)
)
);
return $rights;
}
/**
* Get rights matrix for plugin's assets
* @return array:array:string rights matrix
*/
public function getAssetsRights() {
$itemtypes = array(
//'PluginFlyvemdmEntityconfig',
'PluginFlyvemdmAgent',
'PluginFlyvemdmInvitation',
'PluginFlyvemdmFleet',
'PluginFlyvemdmPackage',
'PluginFlyvemdmFile',
'PluginFlyvemdmGeolocation',
'PluginFlyvemdmPolicy',
'PluginFlyvemdmPolicyCategory',
'PluginFlyvemdmWellknownpath',
);
$rights = array();
foreach ($itemtypes as $itemtype) {
$rights[] = [
'itemtype' => $itemtype,
'label' => $itemtype::getTypeName(2),
'field' => $itemtype::$rightname
];
}
return $rights;
}
/**
* Callback when a user logins or switch profile
*/
public static function changeProfile() {
$rights = ProfileRight::getProfileRights($_SESSION['glpiactiveprofile']['id'], array(
self::$rightname
));
$config = Config::getConfigurationValues('flyvemdm', array('guest_profiles_id'));
if (isset($config['guest_profiles_id'])) {
$_SESSION['plugin_flyvemdm_guest_profiles_id'] = $config['guest_profiles_id'];
} else {
$_SESSION['plugin_flyvemdm_guest_profiles_id'] = '';
}
}
}