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

Commit

Permalink
feat(ui): add missing features in regular GLPI UI
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Mar 30, 2017
1 parent cf0ae57 commit 8aebe25
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 86 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ The general steps to properly configure the whole infrastructure are :

## Dependencies

This plugin is depends on GLPi, FusionInventory for GLPi and a some packages
This plugin depends on GLPi, FusionInventory for GLPi and some packages

* Download our specific version of GLPi 9.1.1 (please refer to its documentation to install)
* Download our specific version of GLPi 9.1.2 (please refer to its documentation to install)
* Download FusionInventory 9.1+1.0 for GLPi and put it in glpi/plugins/
* Donwload Flyve MDM for GLPi and put it in glpi/plugins/

Expand All @@ -65,10 +65,10 @@ glpi
+ plugins
|
+ fusioninventory
+ storkmdm
+ flyvemdm
```

* Go in the directory glpi/plugins/storkmdm
* Go in the directory glpi/plugins/flyvemdm
* Run composer install --no-dev

## Configuration of GLPi
Expand All @@ -85,6 +85,10 @@ Ensure the system has PHP CLI, then setup a cron job similar to the example belo

Adjust the **path to PHP** and the **path to cron.php**

### Server configuration

Flyve MDM allows uploading files, Android packages and Uhuru Mobile packages. You should ensure php.ini allows reasonable upload sizes.

### Notifications

Login in GLPi with a super admin account
Expand Down Expand Up @@ -150,7 +154,7 @@ Expose to the world only the API of GLPi, and keep inacessible GLPi's user inter

Have a look into **glpi/.htaccess** if you can use Apache's mod_rewrite.

The directory **glpi/plugins/storkmdm/scripts** must be inaccessible from the webserver.
The directory **glpi/plugins/flyvemdm/scripts** must be inaccessible from the webserver.

* If running Apache, the .htaccess file in this directory will do the job.
* If running an other server like Nginx, please configure the host properly.
Expand Down Expand Up @@ -325,7 +329,7 @@ If you are not a developer you may contribute the project by [translating it](ht
* Go to the folder containing GLPi
* Run composer install
* Run php tools/cliinstall.php --tests --user=database-user --pass=database-pass --db=glpi-test
* Go to plugins/storkmdm
* Go to plugins/flyvemdm
* Run php tools/cliinstall.php --tests
* Run phpunit

Expand Down
100 changes: 99 additions & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,104 @@

class RoboFile extends Glpi\Tools\RoboFile
{
//Own plugin's robo stuff
protected static $banned = [
'dist',
'vendor',
'.git',
'.gitignore',
'.gitattributes',
'.github',
'.tx',
'.settings',
'.project',
'.buildpath',
'tools',
'tests',
'screenshot*.png',
'RoboFile*.php',
'plugin.xml',
'phpunit.xml.*',
'.travis.yml',
'save.sql',
];

protected function getPluginPath() {
return __DIR__;
}

protected function getPluginName() {
return basename($this->getPluginPath());
}

protected function getVersion() {
$setupFile = __DIR__ . "/setup.php";
$setupContent = file_get_contents($setupFile);
$pluginName = $this->getPluginName();
$constantName = "PLUGIN_" . strtoupper($this->getPluginName()) . "_VERSION";
$pattern = "#^define\('$constantName', '([^']*)'\);$#m";
preg_match($pattern, $setupContent, $matches);
if (isset($matches[1])) {
return $matches[1];
}
return null;
}

protected function getBannedFiles() {
return static::$banned;
}

protected function updateJsonFile($filename) {
// get Package JSON
$filename = __DIR__ . "/$filename";
$jsonContent = file_get_contents($filename);
$jsonContent = json_decode($jsonContent, true);

// update version
$version = $this->getVersion();
if (empty($version)) {
echo "Version not found in setup.php\n";
return;
}
$jsonContent['version'] = $version;
file_put_contents($filename, json_encode($jsonContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}

protected function sourceUpdatePackageJson() {
$this->updateJsonFile('package.json');
}

protected function sourceUpdateComposerJson() {
$this->updateJsonFile('composer.json');
}

public function test() {
$this->testUnit();
$this->testCS();
}

public function testUnit() {
$this->_exec(__DIR__ . '/vendor/bin/phpunit --verbose');
}

public function testCS() {
$this->_exec(__DIR__ . '/vendor/bin/phpcs -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/');
}

public function archiveBuild() {
// update version in package.json
$this->sourceUpdatePackageJson();
$this->sourceUpdateComposerJson();

// Build archive
$version = $this->getVersion();
$pluginName = $this->getPluginName();
$pluginPath = $this->getPluginPath();
$targetFile = __DIR__ . "/dist/glpi-" . $this->getPluginName() . "tar.bz2";
$targetFile = $this->getPluginPath() . "/dist/glpi-" . $this->getPluginName() . "-" . $version;
$exclude = "--exclude '" . implode("' --exclude '", $this->getBannedFiles()) ."'";
// each entry of banned path must match. If a path fails to match something, the archive will not build
@mkdir($this->getPluginPath() . "/dist");
$this->_exec("tar -cjf $targetFile.tar.bz2 --directory '$pluginPath' --transform='s/^\./$pluginName/' $exclude .");
}
}

75 changes: 75 additions & 0 deletions ajax/geolocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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/
------------------------------------------------------------------------------
*/

include ('../../../inc/includes.php');
$plugin = new Plugin();
if (!$plugin->isActivated('flyvemdm')) {
Html::displayNotFoundError();
}

Session::checkRight("flyvemdm:flyvemdm", PluginFlyvemdmProfile::RIGHT_FLYVEMDM_USE);

// a computer ID is mandatory
if (!isset($_REQUEST['computers_id'])) {
die();
}
$computerId = intval($_REQUEST['computers_id']);

if (!isset($_REQUEST['beginDate']) || empty(trim($_REQUEST['beginDate']))) {
$beginDate = '0000-00-00 00:00:00';
} else {
$beginDate = new DateTime($_REQUEST['beginDate']);
$beginDate = $beginDate->format('Y-m-d H:i:s');
}

if (!isset($_REQUEST['endDate']) || empty(trim($_REQUEST['endDate']))) {
$endDate = date('Y-m-d H:i:s');
} else {
$endDate = new DateTime($_REQUEST['endDate']);
$endDate = $endDate->format('Y-m-d H:i:s');
}

$geolocation = new PluginFlyvemdmGeolocation();
if ($beginDate == '0000-00-00 00:00:00') {
$rows = $geolocation->find("`computers_id`='$computerId' AND `date` < '$endDate'", '`date`', '100');
} else {
$rows = $geolocation->find("`computers_id`='$computerId' AND `date` BETWEEN '$beginDate' AND '$endDate'", '`date`');
}

$markers = [];
foreach ($rows as $row) {
$markers[] = [
'date' => $row['date'],
'latitude' => $row['latitude'],
'longitude' => $row['longitude'],
];
}
echo json_encode($markers);
2 changes: 2 additions & 0 deletions ajax/getGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
switch ($_REQUEST['graph']) {
case 'invitations':
echo $graph->showInvitationsGraph();
break;
case 'devicesPerOSVersion':
echo $graph->showDevicesPerOSVersion();
break;
}
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
"prefer-stable": true,
"title": "Flyve MDM",
"description": "Flyve MDM plugin for GLPI",
"version": "2.0.0-dev",
"type": "project",
"licence": "AGPLv3+",
"keywords": ["glpi", "flyve", "mdm"],
"keywords": [
"glpi",
"flyve",
"mdm"
],
"require": {
"php": ">= 5.6.0",
"ext-gd": "*",
Expand All @@ -27,9 +32,9 @@
"glpi-project/tools": "^0.1.2"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/flyve-mdm/flyve-mdm-glpi-test"
}
{
"type": "vcs",
"url": "https://github.com/flyve-mdm/flyve-mdm-glpi-test"
}
]
}
24 changes: 24 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@
content: none;
margin: inherit;
}

#plugin_flyvemdm_geolocationMap {
height: 480px;
}

ul#menu ul.ssmenu {
z-index: 10000;
}

.plugin_flyvemdm_clear::after {
content: "";
display: block;
clear: both;
}

#plugin_flyvemdm_geolocationMap {
float:left;
width: calc(100% - 200px);
}

#plugin_flyvemdm_geolocationList {
float: right;
width: 200px;
}
7 changes: 7 additions & 0 deletions front/agent.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
$agent->check($_POST['id'], PURGE);
$agent->delete($_POST, 1);
$agent->redirectToList();
} else if (isset($_POST['unenroll'])) {
$agent->check($_POST['id'], UPDATE);
$agent->update([
'id' => $_POST['id'],
'_unenroll' => '',
]);
Html::back();
} else {
$agent->check($_GET['id'], READ);
Html::header(
Expand Down
13 changes: 6 additions & 7 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
class PluginFlyvemdmAgent extends CommonDBTM implements PluginFlyvemdmNotifiable {

const ENROLL_DENY = 0;
//const ENROLL_AGENT_TOKEN = 1;
const ENROLL_INVITATION_TOKEN = 1;
const ENROLL_ENTITY_TOKEN = 2;

Expand Down Expand Up @@ -92,11 +91,11 @@ public function getRights($interface = 'central') {
* @see CommonGLPI::defineTabs()
*/
public function defineTabs($options = array()) {
// TODO : fluent interface in GLPI 9.2 +
// TODO : fluent interface in GLPI 9.2 + when GLPI 9.1 dropped
$tab = array();
$this->addDefaultFormTab($tab);
$this->addStandardTab('PluginFlyvemdmGeolocation', $tab, $options);
$this->addStandardTab(__CLASS__, $tab, $options);
$this->addStandardTab('PluginFlyvemdmAgent_Fleet', $tab, $options);
$this->addStandardTab('Notepad', $tab, $options);
$this->addStandardTab('Log', $tab, $options);

Expand All @@ -120,13 +119,13 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
case PluginFlyvemdmFleet::class:
if (!$withtemplate) {
$nb = 0;
$fleetId = $item->getID();
if ($_SESSION['glpishow_count_on_tabs']) {
if (version_compare(GLPI_VERSION, '9.2') < 0) {
$fleetId = $item->getID();

$nb = countElementsInTable(static::getTable(), "`plugin_flyvemdm_fleets_id` = '$fleetId'");
} else {
$nb = countElementsInTable(static::getTable(),
['plugin_flyvemdm_fleets_id' => $item->getID()]);
$nb = countElementsInTable(static::getTable(), ['plugin_flyvemdm_fleets_id' => $fleetId]);
}
}
return self::createTabEntry(self::getTypeName(1), $nb);
Expand Down Expand Up @@ -243,7 +242,7 @@ public static function showDangerZone(PluginFlyvemdmAgent $item) {
'isNewID' => $item->isNewID($ID),
'canUpdate' => (!$item->isNewID($ID)) && ($item->canUpdate() > 0),
'agent' => $fields,

'unenrollButton' => Html::submit(_x('button', 'Unenroll'), array('name' => 'unenroll')),
];

$twig = plugin_flyvemdm_getTemplateEngine();
Expand Down
Loading

0 comments on commit 8aebe25

Please sign in to comment.