diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9813e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +dist/ +node_modules/ +vendor/ +.gh_token +composer.lock +*.min.* + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f537fcf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,47 @@ +# Borgbase - GLPI Plugin CHANGELOG + +## 1.0.0 + +## 0.7.1 - 2022-11-23 +- Automatic link (#12348) + +### Bugfixes +- New KPI overwrite dashboard cards list (#12245) +- Dashboard card returns 0 repositories (#12310) + +## 0.6.2 - 2022-11-10 +### Features +- Dashboard graphs (#12093) + +### Bugfixes +- READ permissions (#12140) +- Fixing other errors (#12145) + +## 0.5.0 - 2022-11-08 +### Features +- API connection indicator (#12087) +- Confirm buttons (#12090) + +## 0.4.2 - 2022-11-07 +### Features +- Permissions (#12062) +- Historial (#11970) +- Spanish and Galician translations (#11957) + +### Bugfixes +- Changing mysql tables engine to InnoDB (#12027) +- Fixing wrong calculation in unit bytes (#12019) + +## 0.3.0 - 2022-10-28 +### Features +- Unlink repositories (#11865) +- Dropdowns instead classic inputs (#11880) +- Searcheable dropdown (#11930) + +## 0.2.0 - 2022-10-20 +### Features +- Automatic actions (#11755) + +## 0.1.0 - 2022-10-17 +### Features +- MVP (#11626) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..878e26e --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Borgbase GLPI Plugin + +Plugin with [Borgbase](https://www.borgbase.com/) integration for GLPI to link devices with their backups. + +[![License](https://img.shields.io/badge/License-GNU%20AGPLv3-blue.svg)](https://github.com/ticgal/taskdrop/blob/master/LICENSE) +[![Twitter](https://img.shields.io/badge/Twitter-TICgal-blue.svg)](https://twitter.com/ticgalcom) +[![TICgal](https://img.shields.io/badge/Web-TICgal-blue.svg)](https://tic.gal/) +[![Localazy](https://img.shields.io/badge/Translate-Localazy-cyan)](https://localazy.com/p/one-time-secret-glpi#translations) + +## Supported versions +- GLPI 10.0.x + +# How to configure it + +With the first installation you have to go to GLPI configuration panel (Setup > General > Borgbase) and add the Borgbase API key. + +Configure the permissions of the profiles that will manage the plugin: +- UPDATE: The user will be able to update the repository data manually. +- CREATE: The user will be able to create links between computer and repository, if the name does not match. +- PURGE: The user will be able to delete manually created links. + +## How to use it + +By default, if the computer name exactly matches the repository name in Borgbase, the relevant data is stored and can be reviewed in the tab of the computer itself. + +Each computer will have a tab with its own Borgbase repository. It can be linked manually in case they do not match. \ No newline at end of file diff --git a/borgbase.xml b/borgbase.xml new file mode 100644 index 0000000..e3e82d2 --- /dev/null +++ b/borgbase.xml @@ -0,0 +1,57 @@ + + Borgbase + borgbase + + stable + https://raw.githubusercontent.com/pluginsGLPI/borgbase/master/{LNAME}.png + + + + Borgbase GLPI plugin. + Plugin GLPI Borgbase + + + + A long description for Borgbase GLPI plugin. + Un description longue pour le plugin GLPI Borgbase + + + https://github.com/pluginsGLPI/borgbase + https://github.com/pluginsGLPI/borgbase/releases + https://github.com/pluginsGLPI/borgbase/issues + https://github.com/pluginsGLPI/borgbase/blob/master/README.md + + + Teclib' + + + + + 0.0.1 + + 9.4 + 9.3 + 9.2 + + + + + en_GB + fr_FR + + GPL V3+ + + + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..80f27e8 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "require": { + "php": ">=7.4" + }, + "require-dev": { + "glpi-project/tools": "^0.4" + }, + "config": { + "optimize-autoloader": true, + "platform": { + "php": "7.4.0" + }, + "sort-packages": true + } +} diff --git a/front/borgbase.form.php b/front/borgbase.form.php new file mode 100644 index 0000000..4b2e516 --- /dev/null +++ b/front/borgbase.form.php @@ -0,0 +1,94 @@ +. +-------------------------------------------------------------------------- +@package Borgbase +@author the TICgal team +@copyright Copyright (c) 2021-2022 TICgal team +@license AGPL License 3.0 or (at your option) any later version +http://www.gnu.org/licenses/agpl-3.0-standalone.html +@link https://www.tic.gal/ +@since 2021-2022 +---------------------------------------------------------------------- +*/ +include '../../../inc/includes.php'; + +$plugin = new Plugin(); +if (!$plugin->isInstalled('borgbase') || !$plugin->isActivated('borgbase')) { + Html::displayNotFoundError(); +} + +$borgbase = new PluginBorgbaseBorgbase(); + +if (isset($_POST['reload'])) { + if (Session::haveRight(PluginBorgbaseBorgbase::$rightname, UPDATE)) { + $computerId = $_POST['computerId']; + $repoId = $_POST['repoId']; + $borgbase->reloadRepo($repoId); + } + Html::back(); +} else if (isset($_POST['unlink'])) { + if (Session::haveRight(PluginBorgbaseBorgbase::$rightname, PURGE)) { + $computerId = $_POST['computerId']; + $repoId = $_POST['repoId']; + $unlink = $borgbase->unlinkRepo($computerId, $repoId); + if ($unlink) { + $changes[0] = $computerId; + $changes[1] = sprintf(__('%2$s, by user %1$s'), $_SESSION["glpiname"], $repoId); + $changes[2] = ""; + + Log::history( + $computerId, + 'Computer', + $changes, + 'PluginBorgbaseBorgbase', + LOG::HISTORY_DEL_RELATION + ); + } + } + Html::back(); +} + +if (isset($_POST['assoc']) && Session::haveRight(PluginBorgbaseBorgbase::$rightname, CREATE)) { + $computerId = isset($_POST['id']) ? intval($_POST['id']) : -1; + $repoId = $_POST['repoId']; + + if ($computerId === -1) { + Html::back(); + } + + $repo = $borgbase->getRepo($repoId); + $linked = $borgbase->linkRepo($repo, $computerId); + if ($linked) { + $changes[0] = $computerId; + $changes[1] = ""; + $changes[2] = sprintf(__('%2$s, by user %1$s'), $_SESSION["glpiname"], $repoId); + + Log::history( + $computerId, + 'Computer', + $changes, + 'PluginBorgbaseBorgbase', + LOG::HISTORY_ADD_RELATION + ); + } + Html::back(); +} + +Html::back(); \ No newline at end of file diff --git a/front/config.form.php b/front/config.form.php new file mode 100644 index 0000000..f45f07b --- /dev/null +++ b/front/config.form.php @@ -0,0 +1,62 @@ +. +-------------------------------------------------------------------------- +@package Borgbase +@author the TICgal team +@copyright Copyright (c) 2021-2022 TICgal team +@license AGPL License 3.0 or (at your option) any later version +http://www.gnu.org/licenses/agpl-3.0-standalone.html +@link https://www.tic.gal/ +@since 2021-2022 +---------------------------------------------------------------------- +*/ +include "../../../inc/includes.php"; + +$plugin = new Plugin(); +if (!$plugin->isInstalled('borgbase') || !$plugin->isActivated('borgbase')) { + Html::displayNotFoundError(); +} + +$borgbase = new PluginBorgbaseConfig; + +Session::checkRight('config', UPDATE); +if(isset($_POST['reload'])){ + $borgbase->linkAvailableRepos(); +} + +if (isset($_POST['update'])) { + $borgbase->check($_POST['id'], UPDATE); + $glpikey = new GLPIKey; + if ($_POST['apikey']) { + $_POST["apikey"] = $glpikey->encrypt($_POST["apikey"]); + } else { + unset($_POST['apikey']); + } + $borgbase->update($_POST); + + // Checking again, apikey needs to be updated + if($_POST['apikey']){ + $borgbase->linkAvailableRepos(); + } + + Html::back(); +} + +Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php?forcetab=" . urlencode('PluginBorgbaseConfig$1')); \ No newline at end of file diff --git a/hook.php b/hook.php new file mode 100644 index 0000000..a5a1243 --- /dev/null +++ b/hook.php @@ -0,0 +1,83 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +/** + * Plugin install process + * + * @return boolean + */ +function plugin_borgbase_install() +{ + $migration = new Migration(PLUGIN_BORGBASE_VERSION); + + // Parse inc directory + foreach (glob(dirname(__FILE__) . '/inc/*') as $filepath) { + // Load *.class.php files and get the class name + if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) { + $classname = 'PluginBorgbase' . ucfirst($matches[1]); + include_once $filepath; + // If the install method exists, load it + if (method_exists($classname, 'install')) { + $classname::install($migration); + } + } + } + + return true; +} + +/** + * Plugin uninstall process + * + * @return boolean + */ +function plugin_borgbase_uninstall() +{ + $migration = new Migration(PLUGIN_BORGBASE_VERSION); + + // Parse inc directory + foreach (glob(dirname(__FILE__) . '/inc/*') as $filepath) { + // Load *.class.php files and get the class name + if (preg_match("/inc.(.+)\.class.php/", $filepath, $matches)) { + $classname = 'PluginBorgbase' . ucfirst($matches[1]); + include_once $filepath; + // If the install method exists, load it + if (method_exists($classname, 'uninstall')) { + $classname::uninstall($migration); + } + } + } + return true; +} + +function plugin_borgbase_getAddSearchOptions($itemtype) +{ + return PluginBorgbaseBorgbase::getAddSearchOptions($itemtype); +} \ No newline at end of file diff --git a/inc/borgbase.class.php b/inc/borgbase.class.php new file mode 100644 index 0000000..f752d9d --- /dev/null +++ b/inc/borgbase.class.php @@ -0,0 +1,675 @@ +. +-------------------------------------------------------------------------- +@package Borgbase +@author the TICgal team +@copyright Copyright (c) 2021-2022 TICgal team +@license AGPL License 3.0 or (at your option) any later version +http://www.gnu.org/licenses/agpl-3.0-standalone.html +@link https://www.tic.gal/ +@since 2021-2022 +---------------------------------------------------------------------- +*/ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +use Glpi\Application\View\TemplateRenderer; + +class PluginBorgbaseBorgbase extends CommonDBTM +{ + static $rightname = 'Borgbase'; + static $itemtype_1 = 'borgbase'; + static $sopt = 1468; + public $dohistory = true; + + /** + * getTypeName + * + * @param mixed $nb + * @return string + */ + public static function getTypeName($nb = 0) + { + return 'Borgbase'; + } + + /** + * getIndexName + * + * @return string + */ + public static function getIndexName() + { + return 'Borgbase'; + } + + /** + * getIcon + * + * @return string + */ + public static function getIcon() + { + return 'fa-solid fa-hard-drive'; + } + + + // Display Tab + + /** + * getTabNameForItem + * + * @param CommonGLPI $item + * @param mixed $withtemplate + * @return string + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + switch ($item::getType()) { + case 'Computer': + return 'Borgbase'; + } + return ''; + } + + /** + * displayTabContentForItem + * + * @param CommonGLPI $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return boolean + */ + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + switch ($item::getType()) { + case 'Computer': + if (Session::haveRight(self::$rightname, READ)) { + self::displayTab(); + } + break; + } + return true; + } + + /** + * request + * + * @param mixed $query + * @return string + */ + public function request($query = '') + { + if ($query) { + $config = new PluginBorgbaseConfig; + $config->getFromDB(1); + $token = $config->fields['apikey']; + + if ($token) { + $glpikey = new GLPIKey; + + $header = [ + 'Content-Type: application/json', + "Authorization: Bearer " . $glpikey->decrypt($token), + ]; + $json = '{"query":"' . $query . '"}'; + $ch = curl_init($config->fields['server']); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($ch); + curl_close($ch); + + //if (str_contains($data, 'errors')) { + // echo ' ' . __('Check API connection', 'borgbase') . ''; + //} + return $data; + } + } + return ''; + } + + // Requests + + /** + * getRepo + * + * @param mixed $repoId + * @return array + */ + public function getRepo($repoId) + { + $query = '{ repo(repoId:\"' . $repoId . '\") {id,name,alertDays,borgVersion,region,encryption,createdAt,lastModified,compactionEnabled,compactionInterval,compactionIntervalUnit,compactionHour,compactionHourTimezone,repoPath,currentUsage}}'; + $repo = $this->request($query); + return $this->formatRawRequest($repo); + } + + /** + * getRepoByName + * + * @param string $name + * @return array + */ + public function getRepoByName($name) + { + $query = '{ repoList(name:\"' . $name . '\") {id, name,alertDays,borgVersion,encryption,region,createdAt,lastModified,compactionEnabled,compactionInterval, compactionIntervalUnit,compactionHour,compactionHourTimezone,repoPath,currentUsage}}'; + $repo = $this->request($query); + return $this->formatRawRequest($repo); + } + + /** + * getRepoList + * + * @return array + */ + public function getRepoList() + { + $query = '{ repoList {id,name,alertDays,borgVersion,region,encryption,createdAt,lastModified,compactionEnabled,compactionInterval,compactionIntervalUnit,compactionHour,compactionHourTimezone,repoPath,currentUsage}}'; + $repoList = $this->request($query); + return $this->formatRawRequest($repoList); + } + + /** + * getCurrentUsage + * + * @return array + */ + public function getCurrentUsage() + { + $query = '{ overageList {usedGb,date,plan{includedSize}}}'; + $req = $this->request($query); + return $this->formatRawRequest($req); + } + + /** + * checkComputerRepo + * + * @param mixed $id + * @return array + */ + public function checkComputerRepo($id) + { + // Check if exists in our database + global $DB; + + // Request all + $iterator = $DB->request([ + 'FROM' => $this->getTable(), + 'WHERE' => [ + 'computer_id' => $id + ] + ]); + + $rows = []; + foreach($iterator as $data){ + array_push($rows, $data); + } + + return $rows; + } + + /** + * checkLink + * + * @param mixed $repoID + * @return array + */ + public function checkLink($repoID) + { + // Check if exists relation // computer_id + global $DB; + + $iterator = $DB->request([ + 'SELECT' => 'computer_id', + 'FROM' => $this->getTable(), + 'WHERE' => [ + 'borg_id' => $repoID, + 'computer_id' => ['NOT LIKE', ''] + ] + ]); + + $rows = []; + foreach($iterator as $data){ + array_push($rows, $data); + } + + return $rows; + } + + /** + * linkRepo + * + * @param mixed $repo + * @param mixed $id + * @return boolean + */ + public function linkRepo($repo, $id) + { + global $DB; + $table = $this->getTable(); + + $res = $this->checkLink($repo['id']); + if (count($res) == 0) { + // Repository + $DB->insert( + $table, + [ + 'borg_id' => $repo['id'], + 'borg_name' => $repo['name'], + 'computer_id' => $id, + 'alertDays' => $repo['alertDays'], + 'borg_version' => $repo['borgVersion'], + 'is_encrypted' => $repo['encryption'], + 'region' => $repo['region'], + 'createdAt' => $repo['createdAt'], + 'lastModified' => $repo['lastModified'], + 'compactionInterval' => $repo['compactionInterval'], + 'compactionIntervalUnit' => $repo['compactionIntervalUnit'], + 'compactionHour' => $repo['compactionHour'], + 'compactionHourTimezone' => $repo['compactionHourTimezone'], + 'repoPath' => $repo['repoPath'], + 'currentUsage' => $repo['currentUsage'], + ] + ); + + // Relation + $lastId = $DB->insertId(); + $DB->insert( + PluginBorgbaseRelation::getTable(), + [ + 'items_id' => $id, + 'itemtype' => 'Computer', + 'plugin_borgbase_borgbases_id' => $lastId + ] + ); + + return true; + } + + return false; + } + + /** + * unlinkRepo + * + * @param mixed $computerId + * @param mixed $repoId + * @return void + */ + public function unlinkRepo($computerId, $repoId) + { + // Check if exists in our database + global $DB; + $table = $this->getTable(); + $DB->delete( + $table, + [ + 'borg_id' => $repoId + ] + ); + + $DB->delete( + PluginBorgbaseRelation::getTable(), + [ + 'items_id' => $computerId + ] + ); + + return true; + } + + /** + * reloadRepo + * + * @param mixed $repoId + * @return boolean + */ + public function reloadRepo($repoId) + { + global $DB; + $repo = $this->getRepo($repoId); + + if ($repo) { + $DB->update( + $this->getTable(), + [ + 'alertDays' => $repo['alertDays'], + 'borg_version' => $repo['borgVersion'], + 'is_encrypted' => $repo['encryption'], + 'region' => $repo['region'], + 'createdAt' => $repo['createdAt'], + 'lastModified' => $repo['lastModified'], + 'compactionInterval' => $repo['compactionInterval'], + 'compactionIntervalUnit' => $repo['compactionIntervalUnit'], + 'compactionHour' => $repo['compactionHour'], + 'compactionHourTimezone' => $repo['compactionHourTimezone'], + 'repoPath' => $repo['repoPath'], + 'currentUsage' => $repo['currentUsage'], + 'date_mod' => date('Y-m-d H:i:s'), + ], + [ + 'WHERE' => ['borg_id' => $repoId], + ] + ); + + return true; + } + + return ''; + } + + // Formating and display + + /** + * formatRawRequest + * + * @param mixed $raw + * @return array + */ + public function formatRawRequest($raw) + { + $array = json_decode($raw, true); + + // API returns always {"data":{"x"}} we only want x content + $format = []; + foreach ($array as $data) { + foreach ($data as $request) { + $format = $request; + } + } + + return $format; + } + + /** + * formatDate + * + * @param mixed $date + * @return string + */ + public function formatDate($date){ + $format = 'd F Y, h:i:s A'; + $newDate = date_create($date); + return date_format($newDate, $format); + } + + /** + * convertUsage + * + * @param mixed $usage + * @return array + */ + public function convertUsage($usage){ + $ints = strtok($usage, '.'); + $count = strlen($ints); + $conversedUsage = 0; + $unit = ''; + + switch ($count) { + case $count <= 3: + $conversedUsage = number_format($usage, 2, '.', ''); + $unit = 'MB'; + break; + case $count <= 6: + $conversedUsage = number_format($usage / 1000, 2, '.', ''); + $unit = 'GB'; + break; + case $count <= 9: + $conversedUsage = number_format($usage / 1000000, 2, '.', ''); + $unit = 'TB'; + break; + } + + return ['convert' => $conversedUsage, 'unit' => $unit ]; + } + + /** + * automaticLink + * + * @param Computer $computer + * @param array $repoList + * @return boolean + */ + public function automaticLink($computer, $repoList) + { + $config = new PluginBorgbaseConfig; + $config->getFromDB(1); + + $id = $computer->fields['id']; + // Automatic insert into BD + foreach ($repoList as $repo) { + // Trimming to ignore white spaces + if (strcmp(trim($computer->fields['name']), trim($repo['name'])) == 0) { + if ($config->fields['match']) { + $feedback = $this->linkRepo($repo, $id); + if ($feedback) { + // Changes + $changes[0] = $id; + $changes[1] = ""; + $changes[2] = sprintf(__('%s, ' . __('automatically linked')), $repo['id']); + + Log::history( + $id, + 'Computer', + $changes, + 'PluginBorgbaseBorgbase', + LOG::HISTORY_ADD_RELATION + ); + HTML::redirect("computer.form.php?id=" . $id); + exit; + } + } + } + } + + return false; + } + + /** + * displayTab + * + * @return boolean + */ + public static function displayTab() + { + if (!Session::haveRight(self::$rightname, READ)) { + return false; + } + + $borgbase = new self(); + $id = $_GET['id']; + $computer = new Computer(); + $computer->getFromDB($id); + $computerId = $computer->fields['id']; + $computerName = $computer->fields['name']; + + $data = []; + $elements = []; + $options = []; + + $res = $borgbase->checkComputerRepo($id); + + if (count($res) == 0) { + $repoListFounded = $borgbase->getRepoByName($computerName); + + $borgbase->automaticLink($computer, $repoListFounded); + + $repoList = $borgbase->getRepoList(); + foreach ($repoList as $repo) { + $req = $borgbase->checkLink($repo['id']); + if (count($req) == 0) { + $elements[$repo['id']] = $repo['name']; + } + } + + $templatePath = "@borgbase/dropdown.html.twig"; + } else { + $row = $res[0]; + + //Usage into KB/MG/GB + $usage = $borgbase->convertUsage($row['currentUsage']); + + // Modifications + $row['formatCreatedAt'] = $borgbase->formatDate($row['createdAt']); + $row['formatLastModified'] = $borgbase->formatDate($row['lastModified']); + $row['formatCompactionInterval'] = $row['compactionInterval'] . ' ' . $row['compactionIntervalUnit']; + $row['formatCompactionHour'] = $row['compactionHour'] . ':00 (' . $row['compactionHourTimezone'] . ')'; + $row['formatCurrentUsage'] = $usage['convert'] . ' ' . $usage['unit']; + $row['footerDateCreation'] = __('Created on', 'borgbase') . ' ' . $row['date_creation']; + $row['footerDateMod'] = __('Last update on', 'borgbase') . ' ' . $row['date_mod']; + + $data = $row; + $templatePath = "@borgbase/repository.html.twig"; + } + + $labels = [ + 'notRegistered' => __('Not registered', 'borgbase'), + 'selectRepo' => __('Select a repository', 'borgbase'), + 'name' => __('Name', 'borgbase'), + 'alertDays' => __('Alert Days', 'borgbase'), + 'version' => __('Version', 'borgbase'), + 'region' => __('Region', 'borgbase'), + 'compactionInterval' => __('Compaction Interval', 'borgbase'), + 'compactionHour' => __('Compaction Hour', 'borgbase'), + 'encryption' => __('Encryption', 'borgbase'), + 'usage' => __('Current Usage', 'borgbase'), + 'createdAt' => __('Creation Date', 'borgbase'), + 'lastBackup' => __('Last Backup', 'borgbase'), + 'confirmDeletion' => __('Confirm the final deletion?', 'borgbase'), + 'unlink' => __('Unlink repository', 'borgbase'), + 'reload' => __('Reload information', 'borgbase') + ]; + + TemplateRenderer::getInstance()->display( + $templatePath, + [ + 'item' => $borgbase, + 'elements' => $elements, + 'data' => $data, + 'value' => $computerId, + 'labels' => $labels, + 'params' => $options, + 'canCreate' => Session::haveRight(self::$rightname, CREATE), + 'canUpdate' => Session::haveRight(self::$rightname, UPDATE), + 'canPurge' => Session::haveRight(self::$rightname, PURGE) + ] + ); + + return true; + } + + /** + * getAddSearchOptions + * + * @param mixed $itemtype + * @return array + */ + public static function getAddSearchOptions($itemtype) + { + $sopt = []; + + if ($itemtype == 'Computer' && Session::haveRight(self::$rightname, READ)) { + $sopt[self::$sopt] = [ + 'table' => PluginBorgbaseBorgbase::getTable(), + 'field' => 'borg_name', + 'name' => 'Borgbase', + 'datatype' => 'text', + 'forcegroupby' => true, + 'usehaving' => true, + 'joinparams' => [ + 'beforejoin' => [ + 'table' => PluginBorgbaseRelation::getTable(), + 'joinparams' => [ + 'jointype' => 'itemtype_item', + ], + ], + ], + ]; + } + + return $sopt; + } + + /** + * install + * + * @param mixed $migration + * @return boolean + */ + public static function install(Migration $migration) + { + global $DB; + + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + + $table = getTableForItemtype('PluginBorgbaseBorgbase'); + if (!$DB->tableExists($table)) { + $migration->displayMessage("Installing $table"); + + $query = "CREATE TABLE `$table` ( + `id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT, + `borg_id` VARCHAR(8) NOT NULL, + `borg_name` VARCHAR(255) NOT NULL, + `computer_id` INT {$default_key_sign}, + `alertDays` INT(11), + `borg_version` VARCHAR(255), + `is_encrypted` VARCHAR(255), + `region` VARCHAR(255), + `createdAt` VARCHAR(255), + `lastModified` VARCHAR(255), + `compactionInterval` VARCHAR(255), + `compactionIntervalUnit` VARCHAR(255), + `compactionHour` VARCHAR(255), + `compactionHourTimezone` VARCHAR(255), + `repoPath` VARCHAR(255), + `currentUsage` VARCHAR(255) DEFAULT '0', + `date_creation` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `date_mod` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB + DEFAULT CHARSET={$default_charset} + COLLATE={$default_collation}"; + $DB->queryOrDie($query, $DB->error()); + } + + return true; + } + + /** + * uninstall + * + * @param mixed $migration + * @return boolean + */ + public static function uninstall(Migration $migration) + { + global $DB; + $table = self::getTable(); + //$migration->displayMessage('Uninstalling ' . $table); + + //$DB->queryOrDie("DROP TABLE `$table`", $DB->error()); + + return true; + } +} \ No newline at end of file diff --git a/inc/config.class.php b/inc/config.class.php new file mode 100644 index 0000000..3a4c333 --- /dev/null +++ b/inc/config.class.php @@ -0,0 +1,229 @@ +. +-------------------------------------------------------------------------- +@package Borgbase +@author the TICgal team +@copyright Copyright (c) 2021-2022 TICgal team +@license AGPL License 3.0 or (at your option) any later version +http://www.gnu.org/licenses/agpl-3.0-standalone.html +@link https://www.tic.gal/ +@since 2021-2022 +---------------------------------------------------------------------- +*/ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +use Glpi\Application\View\TemplateRenderer; + +class PluginBorgbaseConfig extends CommonDBTM +{ + static function canCreate() + { + return Session::haveRight('config', UPDATE); + } + + static function canView() + { + return Session::haveRight('config', READ); + } + + static function canUpdate() + { + return Session::haveRight('config', UPDATE); + } + + /** + * getTabNameForItem + * + * @param CommonGLPI $item + * @param mixed $withtemplate + * @return string + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + + if (!$withtemplate) { + if ($item->getType() == 'Config') { + return 'Borgbase'; + } + } + return ''; + } + + /** + * displayTabContentForItem + * + * @param CommonGLPI $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return boolean + */ + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + if ($item->getType() == 'Config') { + $config = new self(); + $config->showFormExample(); + return true; + } + return false; + } + + /** + * showFormExample + * + */ + public function showFormExample() + { + if (!Session::haveRight("config", UPDATE)) { + return false; + } + + $config = new PluginBorgbaseConfig; + $config->getFromDB(1); + + $connect = false; + $msg = "" . __('Established connection', 'borgbase') . ""; + $options = [ + 'full_width' => true + ]; + + $labels = [ + 'server' => __('Server endpoint', 'borgbase'), + 'apikey' => __('Authentication key', 'borgbase'), + 'match' => __('Computer name matches exactly with repository name', 'borgbase'), + 'reload' => __('Link repositories', 'borgbase') + ]; + + $borgbase = new PluginBorgbaseBorgbase; + $req = $borgbase->request('{isAuthenticated}'); + if (str_contains($req, 'true')) { + $connect = true; + } + + $templatePath = "@borgbase/config.html.twig"; + TemplateRenderer::getInstance()->display( + $templatePath, + [ + 'item' => $config, + 'connection' => $connect, + 'labels' => $labels, + 'msg' => $msg, + 'options' => $options, + ] + ); + } + + /** + * Summary of linkAvailableRepos + * @return int + */ + public function linkAvailableRepos() + { + global $DB; + $borgbase = new PluginBorgbaseBorgbase; + $repoList = $borgbase->getRepoList(); + $linkedRepos = 0; + + foreach ($repoList as $repo) { + $req = $DB->request([ + 'SELECT' => 'id', + 'FROM' => 'glpi_computers', + 'WHERE' => [ + 'name' => $repo['name'] + ] + ]); + + $computer = $req->current(); + if ($computer) { + $linked = $borgbase->linkRepo($repo, $computer['id']); + if($linked){ + $linkedRepos++; + } + } + } + + return $linkedRepos; + } + + /** + * install + * + * @param Migration $migration + * @return boolean + */ + public static function install(Migration $migration) + { + global $DB; + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + + $table = self::getTable(); + if (!$DB->tableExists($table)) { + $migration->displayMessage("Installing $table"); + $query = "CREATE TABLE IF NOT EXISTS $table ( + `id` int {$default_key_sign} NOT NULL auto_increment, + `server` VARCHAR(512) NOT NULL DEFAULT '', + `apikey` VARCHAR(640) NOT NULL DEFAULT '', + `match` tinyint(1) NOT NULL DEFAULT '0', + `debug` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) + )ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + + $DB->query($query) or die($DB->error()); + + // Default config + $DB->insert( + $table, + [ + 'server' => 'https://api.borgbase.com/graphql', + 'apikey' => '', + 'match' => '1', + 'debug' => '0', + ] + ); + } else { + //0.1.5 + $DB->queryOrDie("ALTER TABLE `${table}` ENGINE=InnoDB"); + $migration->executeMigration(); + } + + return true; + } + + /** + * uninstall + * + * @param Migration $migration + * @return boolean + */ + public static function uninstall(Migration $migration) + { + global $DB; + $table = self::getTable(); + //$migration->displayMessage('Uninstalling ' . $table); + + //$DB->queryOrDie("DROP TABLE `$table`", $DB->error()); + + return true; + } +} \ No newline at end of file diff --git a/inc/cron.class.php b/inc/cron.class.php new file mode 100644 index 0000000..085a13f --- /dev/null +++ b/inc/cron.class.php @@ -0,0 +1,70 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +class PluginBorgbaseCron extends CommonDBTM +{ + /** + * cronInfo + * + * @param string $name + * @return array + */ + static function cronInfo($name) + { + + switch ($name) { + case 'borgbaseUpdate': + return ['description' => __('Update borgbase records', 'borgbase')]; + } + return array(); + } + + /** + * cronBorgbaseUpdate + * + * @param mixed $task + * @return boolean + */ + static function cronBorgbaseUpdate($task = NULL) + { + global $DB; + $borgbase = new PluginBorgbaseBorgbase; + $table = PluginBorgbaseBorgbase::getTable(); + foreach ($DB->request(['SELECT' => 'borg_id', 'FROM' => $table]) as $id => $row) { + $borgbase->reloadRepo($row['borg_id']); + } + + return true; + } +} \ No newline at end of file diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php new file mode 100644 index 0000000..fbf4113 --- /dev/null +++ b/inc/dashboard.class.php @@ -0,0 +1,81 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access directly to this file"); +} + +class PluginBorgbaseDashboard extends CommonDBTM +{ + static function dashboardCards($cards) + { + $cards['plugin_borgbase_usagehistory'] = [ + 'widgettype' => ['bar', 'line'], + 'label' => __('Usage History', 'borgbase'), + 'group' => 'Borgbase', + 'filters' => ['dates'], + 'provider' => 'PluginBorgbaseProvider::usageHistory' + ]; + + $cards['plugin_borgbase_usedquotapercentage'] = [ + 'widgettype' => ['donut', 'pie', 'halfdonut', 'halfpie'], + 'label' => __('Used Quota', 'borgbase'), + 'group' => 'Borgbase', + 'filters' => [], + 'provider' => 'PluginBorgbaseProvider::usageQuotaPer' + ]; + + $cards['plugin_borgbase_numberrepositories'] = [ + 'widgettype' => ['bigNumber'], + 'label' => __('Number of Repositories', 'borgbase'), + 'group' => 'Borgbase', + 'filters' => [], + 'provider' => 'PluginBorgbaseProvider::numberrepositories' + ]; + + $cards['plugin_borgbase_currentuse'] = [ + 'widgettype' => ['bigNumber'], + 'label' => __('Current Use', 'borgbase'), + 'group' => 'Borgbase', + 'filters' => [], + 'provider' => 'PluginBorgbaseProvider::currentuse' + ]; + + $cards['plugin_borgbase_numberoflinkedrepositories'] = [ + 'widgettype' => ['bigNumber'], + 'label' => __('Number of Computers with a Repo Linked', 'borgbase'), + 'group' => 'Borgbase', + 'filters' => [], + 'provider' => 'PluginBorgbaseProvider::numberoflinkedrepositories' + ]; + + return $cards; + } +} \ No newline at end of file diff --git a/inc/profile.class.php b/inc/profile.class.php new file mode 100644 index 0000000..e04136c --- /dev/null +++ b/inc/profile.class.php @@ -0,0 +1,166 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +class PluginBorgbaseProfile extends CommonDBTM +{ + public static $rightname = 'profile'; + + /** + * getTypeName + * + * @param mixed $nb + * @return string + */ + static function getTypeName($nb = 0) + { + return "Borgbase"; + } + + /** + * getTabNameForItem + * + * @param CommonGLPI $item + * @param mixed $withtemplate + * @return array + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + if ($item instanceof Profile + && $item->getField('id')) { + return self::createTabEntry(self::getTypeName()); + } + return []; + } + + /** + * displayTabContentForItem + * + * @param CommonGLPI $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return boolean + */ + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + if ($item instanceof Profile + && $item->getField('id')) { + return self::showForProfile($item->getID()); + } + + return true; + } + + /** + * getAllRights + * + * @param mixed $all + * @return array + */ + static function getAllRights($all = false) + { + $rights = array( + array( + 'itemtype' => PluginBorgbaseBorgbase::class, + 'label' => PluginBorgbaseBorgbase::getTypeName(), + 'field' => PluginBorgbaseBorgbase::getIndexName() + ) + ); + + return $rights; + } + + /** + * showForProfile + * + * @param mixed $profiles_id + * @return boolean + */ + static function showForProfile($profiles_id = 0) + { + $canupdate = self::canUpdate(); + $profile = new Profile(); + $profile->getFromDB($profiles_id); + echo "
"; + echo "
"; + + $rights = self::getAllRights(); + $profile->displayRightsChoiceMatrix( + $rights, + array( + 'canedit' => $canupdate, + 'title' => self::getTypeName(), + ) + ); + + if ($canupdate) { + echo "
"; + echo Html::hidden('id', array('value' => $profiles_id)); + echo Html::submit(_sx('button', 'Save'), array('name' => 'update')); + echo "
\n"; + Html::closeForm(); + + echo "
"; + } + + return true; + } + + /** + * install + * + */ + public static function install() + { + global $DB; + + $query = "SELECT id FROM glpi_profilerights WHERE name = '" . PluginBorgbaseBorgbase::getIndexName() . "'"; + $numRights = $DB->queryOrDie($query)->num_rows; + if ($numRights == 0) { + foreach (PluginBorgbaseProfile::getAllRights() as $right) { + ProfileRight::addProfileRights([$right['field']]); + } + } + } + + /** + * uninstall + * + */ + public static function uninstall() + { + foreach (PluginBorgbaseProfile::getAllRights() as $right) { + //ProfileRight::deleteProfileRights([$right['field']]); + } + } +} \ No newline at end of file diff --git a/inc/provider.class.php b/inc/provider.class.php new file mode 100644 index 0000000..d27a11d --- /dev/null +++ b/inc/provider.class.php @@ -0,0 +1,182 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access directly to this file"); +} + +class PluginBorgbaseProvider extends CommonDBTM +{ + public static function usageHistory($params = []) + { + $data = []; + + $borgbase = new PluginBorgbaseBorgbase; + $usages = $borgbase->getCurrentUsage(); + + // New rows last + krsort($usages); + + foreach ($usages as $usage) { + $dateParts = explode("-", $usage['date']); + $date = $dateParts[2] . '/' . $dateParts[1]; // day/month + + $use = number_format($usage['usedGb'], 2, '.'); + + $data[] = [ + 'number' => $use, + 'label' => $date, + ]; + } + + if (count($data) === 0) { + $data = [ + 'nodata' => true + ]; + } + + $provide = [ + 'data' => $data, + 'label' => 'Borgbase - ' . __('Total Usage History') . ' (GB)', + 'icon' => PluginBorgbaseBorgbase::getIcon() + ]; + + return $provide; + } + + public static function usageQuotaPer($params = []) + { + $data = []; + + $borgbase = new PluginBorgbaseBorgbase; + $usages = $borgbase->getCurrentUsage(); + + $currentUsage = $usages[0]['usedGb']; + $limitUsage = $usages[0]['plan']['includedSize'] / 1000; //GB + + $calc = ($currentUsage * 100) / $limitUsage; + $percentage = number_format($calc, 2); + + $data[] = [ + 'number' => $percentage, + 'label' => __('Storage usage', 'borgbase'), + ]; + $data[] = [ + 'number' => 100 - $percentage, + 'label' => __('Free storage', 'borgbase'), + ]; + + if (count($data) === 0) { + $data = [ + 'nodata' => true + ]; + } + + $provide = [ + 'data' => $data, + 'label' => 'Borgbase - ' . __('Total Usage Percentage', 'borgbase'), + 'icon' => PluginBorgbaseBorgbase::getIcon() + ]; + + return $provide; + } + + public static function numberRepositories($params = []) + { + $borgbase = new PluginBorgbaseBorgbase; + $numRepos = count($borgbase->getRepoList()); + + $provide = [ + 'number' => $numRepos, + 'label' => 'Borgbase - ' . __('Number of Repositories', 'borgbase'), + 'icon' => PluginBorgbaseBorgbase::getIcon() + ]; + + return $provide; + } + + public static function currentUse($params = []) + { + $borgbase = new PluginBorgbaseBorgbase; + $currentUse = $borgbase->getCurrentUsage()[0]['usedGb']; + + $provide = [ + 'number' => $currentUse, + 'label' => 'Borgbase - ' . __('Current Use', 'borgbase') . ' (GB)', + 'icon' => PluginBorgbaseBorgbase::getIcon() + ]; + + return $provide; + } + + public static function numberOfLinkedRepositories($params = []) + { + global $DB; + + $sub_query = new \QuerySubQuery([ + 'SELECT' => 'items_id', + 'FROM' => PluginBorgbaseRelation::getTable() + ]); + + $iterator = $DB->request([ + 'SELECT' => ['COUNT DISTINCT' => 'id as count'], + 'FROM' => 'glpi_computers', + 'WHERE' => [ + 'id' => $sub_query + ] + ]); + + $result = $iterator->current(); + $linkedRepositories = $result['count']; + + $search_url = Computer::getSearchURL(); + $search_criteria['criteria'][] = [ + 'link' => '', + 'field' => PluginBorgbaseBorgbase::$sopt, + 'searchtype' => 'notcontains', + 'value' => 'null' + ]; + + $url = $search_url . (str_contains($search_url, '?') ? '&' : '?') . Toolbox::append_params([ + $search_criteria, + 'reset' => 'reset', + ]); + + + $provide = [ + 'number' => $linkedRepositories, + 'url' => $url, + 'label' => 'Borgbase - ' . __('Number of Computers with a Repo Linked', 'borgbase'), + 'icon' => PluginBorgbaseBorgbase::getIcon() + ]; + + return $provide; + } +} \ No newline at end of file diff --git a/inc/relation.class.php b/inc/relation.class.php new file mode 100644 index 0000000..faf8aaf --- /dev/null +++ b/inc/relation.class.php @@ -0,0 +1,100 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +class PluginBorgbaseRelation extends CommonDBRelation +{ + /** + * getTypeName + * + * @param mixed $nb + * @return string + */ + public static function getTypeName($nb = 0) + { + return 'Borgbase Relation'; + } + + /** + * install + * + * @param Migration $migration + * @return boolean + */ + public static function install(Migration $migration) + { + global $DB; + + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + + $table = getTableForItemtype('PluginBorgbaseRelation'); + if (!$DB->tableExists($table)) { + $migration->displayMessage("Installing $table"); + + $query = "CREATE TABLE `$table` ( + `id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT, + `items_id` INT {$default_key_sign} NOT NULL DEFAULT '0', + `itemtype` VARCHAR(255) DEFAULT NULL, + `plugin_borgbase_borgbases_id` INT {$default_key_sign} NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `items_id` (`items_id`), + KEY `itemtype` (`itemtype`,`items_id`), + KEY `plugin_borgbase_borgbases_id` (`plugin_borgbase_borgbases_id`) + ) ENGINE=InnoDB + DEFAULT CHARSET={$default_charset} + COLLATE={$default_collation}"; + $DB->queryOrDie($query, $DB->error()); + } + + return true; + } + + /** + * uninstall + * + * @param Migration $migration + * @return boolean + */ + public static function uninstall(Migration $migration) + { + global $DB; + $table = self::getTable(); + //$migration->displayMessage('Uninstalling ' . $table); + + //$DB->queryOrDie("DROP TABLE `$table`", $DB->error()); + + return true; + } +} \ No newline at end of file diff --git a/locales/.gitignore b/locales/.gitignore new file mode 100644 index 0000000..7948160 --- /dev/null +++ b/locales/.gitignore @@ -0,0 +1,2 @@ +localazy.keys.json +localazy.jar \ No newline at end of file diff --git a/locales/borgbase.pot b/locales/borgbase.pot new file mode 100644 index 0000000..b311a01 --- /dev/null +++ b/locales/borgbase.pot @@ -0,0 +1,146 @@ +# BORGBASE Glpi Plugin. +# Copyright (C) 2022 TICgal +# This file is distributed under the same license as the PACKAGE package. +# TICgal, 2022 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-11-23 13:23+0100\n" +"PO-Revision-Date: 2022-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: setup.php:152 +msgid "Installed / not configured" +msgstr "" + +#: inc/borgbase.class.php:537 +msgid "Created on" +msgstr "" + +#: inc/borgbase.class.php:538 +msgid "Last update on" +msgstr "" + +#: inc/borgbase.class.php:545 +msgid "Not registered" +msgstr "" + +#: inc/borgbase.class.php:546 +msgid "Select a repository" +msgstr "" + +#: inc/borgbase.class.php:547 +msgid "Name" +msgstr "" + +#: inc/borgbase.class.php:548 +msgid "Alert Days" +msgstr "" + +#: inc/borgbase.class.php:549 +msgid "Version" +msgstr "" + +#: inc/borgbase.class.php:550 +msgid "Region" +msgstr "" + +#: inc/borgbase.class.php:551 +msgid "Compaction Interval" +msgstr "" + +#: inc/borgbase.class.php:552 +msgid "Compaction Hour" +msgstr "" + +#: inc/borgbase.class.php:553 +msgid "Encryption" +msgstr "" + +#: inc/borgbase.class.php:554 +msgid "Current Usage" +msgstr "" + +#: inc/borgbase.class.php:555 +msgid "Creation Date" +msgstr "" + +#: inc/borgbase.class.php:556 +msgid "Last Backup" +msgstr "" + +#: inc/borgbase.class.php:557 +msgid "Confirm the final deletion?" +msgstr "" + +#: inc/borgbase.class.php:558 +msgid "Unlink repository" +msgstr "" + +#: inc/borgbase.class.php:559 +msgid "Reload information" +msgstr "" + +#: inc/config.class.php:104 +msgid "Established connection" +msgstr "" + +#: inc/config.class.php:110 +msgid "Server endpoint" +msgstr "" + +#: inc/config.class.php:111 +msgid "Authentication key" +msgstr "" + +#: inc/config.class.php:112 +msgid "Computer name matches exactly with repository name" +msgstr "" + +#: inc/config.class.php:113 +msgid "Link repositories" +msgstr "" + +#: inc/cron.class.php:48 +msgid "Update borgbase records" +msgstr "" + +#: inc/dashboard.class.php:41 +msgid "Usage History" +msgstr "" + +#: inc/dashboard.class.php:49 +msgid "Used Quota" +msgstr "" + +#: inc/dashboard.class.php:57 inc/provider.class.php:118 +msgid "Number of Repositories" +msgstr "" + +#: inc/dashboard.class.php:65 inc/provider.class.php:132 +msgid "Current Use" +msgstr "" + +#: inc/dashboard.class.php:73 inc/provider.class.php:176 +msgid "Number of Computers with a Repo Linked" +msgstr "" + +#: inc/provider.class.php:89 +msgid "Storage usage" +msgstr "" + +#: inc/provider.class.php:93 +msgid "Free storage" +msgstr "" + +#: inc/provider.class.php:104 +msgid "Total Usage Percentage" +msgstr "" diff --git a/locales/en_GB.mo b/locales/en_GB.mo new file mode 100644 index 0000000..0009d08 Binary files /dev/null and b/locales/en_GB.mo differ diff --git a/locales/en_GB.po b/locales/en_GB.po new file mode 100644 index 0000000..6eeb458 --- /dev/null +++ b/locales/en_GB.po @@ -0,0 +1,139 @@ +msgid "" +msgstr "" +"Project-Id-Version: Borgbase\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-11-23 13:23+0100\n" +"Language: en_GB\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Localazy (https://localazy.com)\n" +"Plural-Forms: nplurals=2; plural=(n==1) ? 0 : 1;\n" + +#: setup.php:152 +msgid "Installed / not configured" +msgstr "Installed / not configured" + +#: inc/borgbase.class.php:537 +msgid "Created on" +msgstr "Created on" + +#: inc/borgbase.class.php:538 +msgid "Last update on" +msgstr "Last update on" + +#: inc/borgbase.class.php:545 +msgid "Not registered" +msgstr "Not registered" + +#: inc/borgbase.class.php:546 +msgid "Select a repository" +msgstr "Select a repository" + +#: inc/borgbase.class.php:547 +msgid "Name" +msgstr "Name" + +#: inc/borgbase.class.php:548 +msgid "Alert Days" +msgstr "Alert Days" + +#: inc/borgbase.class.php:549 +msgid "Version" +msgstr "Version" + +#: inc/borgbase.class.php:550 +msgid "Region" +msgstr "Region" + +#: inc/borgbase.class.php:551 +msgid "Compaction Interval" +msgstr "Compaction Interval" + +#: inc/borgbase.class.php:552 +msgid "Compaction Hour" +msgstr "Compaction Hour" + +#: inc/borgbase.class.php:553 +msgid "Encryption" +msgstr "Encryption" + +#: inc/borgbase.class.php:554 +msgid "Current Usage" +msgstr "Current Usage" + +#: inc/borgbase.class.php:555 +msgid "Creation Date" +msgstr "Creation Date" + +#: inc/borgbase.class.php:556 +msgid "Last Backup" +msgstr "Last Backup" + +#: inc/borgbase.class.php:557 +msgid "Confirm the final deletion?" +msgstr "Confirm the final deletion?" + +#: inc/borgbase.class.php:558 +msgid "Unlink repository" +msgstr "Unlink repository" + +#: inc/borgbase.class.php:559 +msgid "Reload information" +msgstr "Reload information" + +#: inc/config.class.php:104 +msgid "Established connection" +msgstr "Established connection" + +#: inc/config.class.php:110 +msgid "Server endpoint" +msgstr "Server endpoint" + +#: inc/config.class.php:111 +msgid "Authentication key" +msgstr "Authentication key" + +#: inc/config.class.php:112 +msgid "Computer name matches exactly with repository name" +msgstr "Computer name matches exactly with repository name" + +#: inc/config.class.php:113 +msgid "Link repositories" +msgstr "Link repositories" + +#: inc/cron.class.php:48 +msgid "Update borgbase records" +msgstr "Update borgbase records" + +#: inc/dashboard.class.php:41 +msgid "Usage History" +msgstr "Usage History" + +#: inc/dashboard.class.php:49 +msgid "Used Quota" +msgstr "Used Quota" + +#: inc/dashboard.class.php:57 inc/provider.class.php:118 +msgid "Number of Repositories" +msgstr "Number of Repositories" + +#: inc/dashboard.class.php:65 inc/provider.class.php:132 +msgid "Current Use" +msgstr "Current Use" + +#: inc/dashboard.class.php:73 inc/provider.class.php:176 +msgid "Number of Computers with a Repo Linked" +msgstr "Number of Computers with a Repo Linked" + +#: inc/provider.class.php:89 +msgid "Storage usage" +msgstr "Storage usage" + +#: inc/provider.class.php:93 +msgid "Free storage" +msgstr "Free storage" + +#: inc/provider.class.php:104 +msgid "Total Usage Percentage" +msgstr "Total Usage Percentage" diff --git a/locales/es_ES.mo b/locales/es_ES.mo new file mode 100644 index 0000000..f6e088a Binary files /dev/null and b/locales/es_ES.mo differ diff --git a/locales/es_ES.po b/locales/es_ES.po new file mode 100644 index 0000000..cac67ff --- /dev/null +++ b/locales/es_ES.po @@ -0,0 +1,140 @@ +msgid "" +msgstr "" +"Project-Id-Version: Borgbase\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-11-23 13:23+0100\n" +"Language: es_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Localazy (https://localazy.com)\n" +"Plural-Forms: nplurals=2; plural=(n==1) ? 0 : 1;\n" + +#: setup.php:152 +msgid "Installed / not configured" +msgstr "Instalado / no configurado" + +#: inc/borgbase.class.php:537 +msgid "Created on" +msgstr "Creado el" + +#: inc/borgbase.class.php:538 +msgid "Last update on" +msgstr "Última actualización el" + +#: inc/borgbase.class.php:545 +msgid "Not registered" +msgstr "No registrado" + +#: inc/borgbase.class.php:546 +msgid "Select a repository" +msgstr "Seleccione un repositorio" + +#: inc/borgbase.class.php:547 +msgid "Name" +msgstr "Nombre" + +#: inc/borgbase.class.php:548 +msgid "Alert Days" +msgstr "Días de alerta" + +#: inc/borgbase.class.php:549 +msgid "Version" +msgstr "Versión" + +#: inc/borgbase.class.php:550 +msgid "Region" +msgstr "Región" + +#: inc/borgbase.class.php:551 +msgid "Compaction Interval" +msgstr "Intervalo de compactación" + +#: inc/borgbase.class.php:552 +msgid "Compaction Hour" +msgstr "Hora de compactación" + +#: inc/borgbase.class.php:553 +msgid "Encryption" +msgstr "Cifrado" + +#: inc/borgbase.class.php:554 +msgid "Current Usage" +msgstr "Uso actual" + +#: inc/borgbase.class.php:555 +msgid "Creation Date" +msgstr "Fecha de creación" + +#: inc/borgbase.class.php:556 +msgid "Last Backup" +msgstr "Último respaldo" + +#: inc/borgbase.class.php:557 +msgid "Confirm the final deletion?" +msgstr "¿Quieres confirmar la eliminación final?" + +#: inc/borgbase.class.php:558 +msgid "Unlink repository" +msgstr "Desvincular el repositorio" + +#: inc/borgbase.class.php:559 +msgid "Reload information" +msgstr "Recargar información" + +#: inc/config.class.php:104 +msgid "Established connection" +msgstr "Conexión establecida" + +#: inc/config.class.php:110 +msgid "Server endpoint" +msgstr "Punto de acceso al servidor" + +#: inc/config.class.php:111 +msgid "Authentication key" +msgstr "Clave de autenticación" + +#: inc/config.class.php:112 +msgid "Computer name matches exactly with repository name" +msgstr "" +"El nombre del ordenador coincide exactamente con el nombre del repositorio" + +#: inc/config.class.php:113 +msgid "Link repositories" +msgstr "Vincular los repositorios" + +#: inc/cron.class.php:48 +msgid "Update borgbase records" +msgstr "Actualizar registros de borgbase" + +#: inc/dashboard.class.php:41 +msgid "Usage History" +msgstr "Historial de uso" + +#: inc/dashboard.class.php:49 +msgid "Used Quota" +msgstr "Cuota usada" + +#: inc/dashboard.class.php:57 inc/provider.class.php:118 +msgid "Number of Repositories" +msgstr "Número de Repositorios" + +#: inc/dashboard.class.php:65 inc/provider.class.php:132 +msgid "Current Use" +msgstr "Uso actual" + +#: inc/dashboard.class.php:73 inc/provider.class.php:176 +msgid "Number of Computers with a Repo Linked" +msgstr "Número de equipos con un repositorio vinculado" + +#: inc/provider.class.php:89 +msgid "Storage usage" +msgstr "Uso del almacenamiento" + +#: inc/provider.class.php:93 +msgid "Free storage" +msgstr "Almacenamiento libre" + +#: inc/provider.class.php:104 +msgid "Total Usage Percentage" +msgstr "Porcentaje de uso total" diff --git a/locales/gl_ES.mo b/locales/gl_ES.mo new file mode 100644 index 0000000..19322ae Binary files /dev/null and b/locales/gl_ES.mo differ diff --git a/locales/gl_ES.po b/locales/gl_ES.po new file mode 100644 index 0000000..e9a937b --- /dev/null +++ b/locales/gl_ES.po @@ -0,0 +1,139 @@ +msgid "" +msgstr "" +"Project-Id-Version: Borgbase\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-11-23 13:23+0100\n" +"Language: gl_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Localazy (https://localazy.com)\n" +"Plural-Forms: nplurals=2; plural=(n==1) ? 0 : 1;\n" + +#: setup.php:152 +msgid "Installed / not configured" +msgstr "Instalado / non configurado" + +#: inc/borgbase.class.php:537 +msgid "Created on" +msgstr "Creado o" + +#: inc/borgbase.class.php:538 +msgid "Last update on" +msgstr "Última actualización o" + +#: inc/borgbase.class.php:545 +msgid "Not registered" +msgstr "Non rexistrado" + +#: inc/borgbase.class.php:546 +msgid "Select a repository" +msgstr "Seleccione un repositorio" + +#: inc/borgbase.class.php:547 +msgid "Name" +msgstr "Nome" + +#: inc/borgbase.class.php:548 +msgid "Alert Days" +msgstr "Días de alerta" + +#: inc/borgbase.class.php:549 +msgid "Version" +msgstr "Versión" + +#: inc/borgbase.class.php:550 +msgid "Region" +msgstr "Rexión" + +#: inc/borgbase.class.php:551 +msgid "Compaction Interval" +msgstr "Intervalo de compactación" + +#: inc/borgbase.class.php:552 +msgid "Compaction Hour" +msgstr "Hora de compactación" + +#: inc/borgbase.class.php:553 +msgid "Encryption" +msgstr "Cifrado" + +#: inc/borgbase.class.php:554 +msgid "Current Usage" +msgstr "Uso actual" + +#: inc/borgbase.class.php:555 +msgid "Creation Date" +msgstr "Data de creación" + +#: inc/borgbase.class.php:556 +msgid "Last Backup" +msgstr "Última copia de seguridade" + +#: inc/borgbase.class.php:557 +msgid "Confirm the final deletion?" +msgstr "¿Queres confirmar a eliminación definitiva?" + +#: inc/borgbase.class.php:558 +msgid "Unlink repository" +msgstr "Desvincular o repositorio" + +#: inc/borgbase.class.php:559 +msgid "Reload information" +msgstr "Recargar información" + +#: inc/config.class.php:104 +msgid "Established connection" +msgstr "Conexión establecida" + +#: inc/config.class.php:110 +msgid "Server endpoint" +msgstr "Punto de acceso ao servidor" + +#: inc/config.class.php:111 +msgid "Authentication key" +msgstr "Chave de autenticación" + +#: inc/config.class.php:112 +msgid "Computer name matches exactly with repository name" +msgstr "O nome do ordenador coincide exactamente co nome do repositorio" + +#: inc/config.class.php:113 +msgid "Link repositories" +msgstr "Vincular os repositorios" + +#: inc/cron.class.php:48 +msgid "Update borgbase records" +msgstr "Actualizar rexistros de borgbase" + +#: inc/dashboard.class.php:41 +msgid "Usage History" +msgstr "Historial de uso" + +#: inc/dashboard.class.php:49 +msgid "Used Quota" +msgstr "Cota usada" + +#: inc/dashboard.class.php:57 inc/provider.class.php:118 +msgid "Number of Repositories" +msgstr "Número de Repositorios" + +#: inc/dashboard.class.php:65 inc/provider.class.php:132 +msgid "Current Use" +msgstr "Uso actual" + +#: inc/dashboard.class.php:73 inc/provider.class.php:176 +msgid "Number of Computers with a Repo Linked" +msgstr "Número de ordenadores cun repositorio ligado" + +#: inc/provider.class.php:89 +msgid "Storage usage" +msgstr "Uso do almacenamento" + +#: inc/provider.class.php:93 +msgid "Free storage" +msgstr "Almacenamento libre" + +#: inc/provider.class.php:104 +msgid "Total Usage Percentage" +msgstr "Porcentaxe de uso total" diff --git a/locales/localazy.json b/locales/localazy.json new file mode 100644 index 0000000..0b24ea0 --- /dev/null +++ b/locales/localazy.json @@ -0,0 +1,11 @@ +{ + "upload": { + "type": "pot", + "deprecate": "project", + "files": "borgbase.pot" + }, + "download": { + "files": "${languageCode}_${regionCode}.po", + "includeSourceLang": true + } +} \ No newline at end of file diff --git a/setup.php b/setup.php new file mode 100644 index 0000000..ccf8494 --- /dev/null +++ b/setup.php @@ -0,0 +1,155 @@ +. + -------------------------------------------------------------------------- + @package Borgbase + @author the TICgal team + @copyright Copyright (c) 2021-2022 TICgal team + @license AGPL License 3.0 or (at your option) any later version + http://www.gnu.org/licenses/agpl-3.0-standalone.html + @link https://www.tic.gal/ + @since 2021-2022 + ---------------------------------------------------------------------- + */ + +use Glpi\Plugins; + +define('PLUGIN_BORGBASE_VERSION', '1.0.0'); +define("PLUGIN_BORGBASE_MIN_GLPI_VERSION", "10.0.0"); +define("PLUGIN_BORGBASE_MAX_GLPI_VERSION", "10.0.99"); + +/** + * Init hooks of the plugin. + * REQUIRED + * + * @return void + */ +function plugin_init_borgbase() +{ + global $PLUGIN_HOOKS; + + $PLUGIN_HOOKS['csrf_compliant']['borgbase'] = true; + + $plugin = new Plugin(); + if ($plugin->isActivated('borgbase')) { + Plugin::registerClass( + PluginBorgbaseConfig::class, + [ + 'addtabon' => [ + 'Config', + ] + ] + ); + if (Session::haveRight(PluginBorgbaseBorgbase::$rightname, READ)) { + Plugin::registerClass( + PluginBorgbaseBorgbase::class, + [ + 'addtabon' => [ + 'Computer', + ] + ] + ); + } + Plugin::registerClass( + PluginBorgbaseRelation::class, + [ + 'addtabon' => [ + 'Computer', + ] + ] + ); + Plugin::registerClass( + PluginBorgbaseProfile::class, + [ + 'addtabon' => [ + 'Profile', + ] + ] + ); + + CronTask::register( + PluginBorgbaseCron::class, + 'borgbaseUpdate', + DAY_TIMESTAMP, + [ + 'comment' => '', + 'mode' => CronTask::MODE_EXTERNAL + ] + ); + + // Config page + if (Session::haveRight('config', UPDATE)) { + $PLUGIN_HOOKS['config_page']['borgbase'] = 'front/config.form.php'; + } + $PLUGIN_HOOKS['dashboard_cards']['borgbase'] = ['PluginBorgbaseDashboard', 'dashboardCards']; + } +} + +/** + * Get the name and the version of the plugin + * REQUIRED + * + * @return array + */ +function plugin_version_borgbase() +{ + return [ + 'name' => 'Borgbase', + 'version' => PLUGIN_BORGBASE_VERSION, + 'author' => 'TICgal', + 'homepage' => 'https://tic.gal', + 'license' => 'AGPLv3+', + 'requirements' => [ + 'glpi' => [ + 'min' => PLUGIN_BORGBASE_MIN_GLPI_VERSION, + 'max' => PLUGIN_BORGBASE_MAX_GLPI_VERSION, + ], + ], + ]; +} + +/** + * Check pre-requisites before install + * OPTIONNAL, but recommanded + * + * @return boolean + */ +function plugin_borgbase_check_prerequisites() +{ + return true; +} + +/** + * Check configuration process + * + * @param boolean $verbose Whether to display message on failure. Defaults to false + * + * @return boolean + */ +function plugin_borgbase_check_config($verbose = false) +{ + if (true) { // Your configuration check + return true; + } + + if ($verbose) { + echo __('Installed / not configured', 'borgbase'); + } + return false; +} \ No newline at end of file diff --git a/templates/config.html.twig b/templates/config.html.twig new file mode 100644 index 0000000..3a085a8 --- /dev/null +++ b/templates/config.html.twig @@ -0,0 +1,103 @@ + + +{% import 'components/form/fields_macros.html.twig' as fields %} +{% import 'components/form/buttons.html.twig' as buttons %} + +{% set no_header = no_header|default(not item.isNewItem() and not _get._in_modal|default(false)) %} +{% set bg = '' %} +{% if item.isDeleted() %} + {% set bg = 'asset-deleted' %} +{% endif %} + +
+ + {{ include('components/form/header.html.twig', {'in_twig': true, 'no_header': true}) }} + {% set params = params ?? [] %} + +
+
+
+
+
+ + {% if item.isField('server') %} + {{ fields.textField( + 'server', + item.fields['server'], + labels['server'], + options + ) }} + {% endif %} + + {% if item.isField('apikey') %} + {{ fields.passwordField( + 'apikey', + item.fields['apikey'], + labels['apikey'], + options + ) }} + {% endif %} + + {% if connection %} + {{ fields.htmlField( + 'connection', + msg, + '' + ) }} + +
+ +
+ {% endif %} + + {% if item.isField('match') %} + {{ + fields.dropdownYesNo( + 'match', + item.fields['match'], + labels['match'], + options + ) }} + {% endif %} + +
{# .row #} +
{# .row #} +
{# .flex-row #} +
{# .flex-column #} +
{# .flex-wrap #} + + {{ include('components/form/buttons.html.twig') }} +
\ No newline at end of file diff --git a/templates/dropdown.html.twig b/templates/dropdown.html.twig new file mode 100644 index 0000000..79f5459 --- /dev/null +++ b/templates/dropdown.html.twig @@ -0,0 +1,77 @@ + + +{% import 'components/form/fields_macros.html.twig' as fields %} +{% import 'components/form/buttons.html.twig' as buttons %} + +{% set no_header = no_header|default(not item.isNewItem() and not _get._in_modal|default(false)) %} +{% set bg = '' %} +{% if item.isDeleted() %} + {% set bg = 'asset-deleted' %} +{% endif %} + +
+ + {{ include('components/form/header.html.twig', {'in_twig': true, 'no_header': true}) }} + {% set params = params ?? [] %} + {% set field_options = { + 'locked_fields': item.getLockedFields(), + } %} + +
+
+
+
+
+ +

{{ labels['notRegistered'] }}

+ + {% if canCreate %} + + + + {{ fields.dropdownArrayField( + 'repoId', + value, + elements, + labels['selectRepo'], + field_options + ) }} + {% endif %} + +
{# .row #} +
{# .row #} +
{# .flex-row #} +
{# .flex-column #} +
{# .flex-wrap #} + + {% if canCreate %} + {{ include('components/form/buttons.html.twig') }} + {% endif %} +
\ No newline at end of file diff --git a/templates/repository.html.twig b/templates/repository.html.twig new file mode 100644 index 0000000..25bb4cc --- /dev/null +++ b/templates/repository.html.twig @@ -0,0 +1,186 @@ + + +{% import 'components/form/fields_macros.html.twig' as fields %} + +{% set no_header = no_header|default(not item.isNewItem() and not _get._in_modal|default(false)) %} +{% set bg = '' %} +{% if item.isDeleted() %} + {% set bg = 'asset-deleted' %} +{% endif %} + +
+ {{ include('components/form/header.html.twig', {'in_twig': true, 'no_header': true}) }} + + {% set params = params ?? [] %} + {% set field_options = { + 'locked_fields': item.getLockedFields(), + } %} + +
+
+
+
+
+ + {% set field_options = field_options|merge(params) %} + + {% if item.isField('borg_name') %} + {{ fields.textField( + 'borg_name', + data['borg_name'], + labels['name'], + field_options + ) }} + {% endif %} + + {% if item.isField('alertDays') %} + {{ fields.textField( + 'alertDays', + data['alertDays'], + labels['alertDays'], + field_options + ) }} + {% endif %} + + {% if item.isField('borg_version') %} + {{ fields.textField( + 'borg_version', + data['borg_version'], + labels['version'], + field_options + ) }} + {% endif %} + + {% if item.isField('compactionInterval') %} + {{ fields.textField( + 'compactionInterval', + data['formatCompactionInterval'], + labels['compactionInterval'], + field_options + ) }} + {% endif %} + + {% if item.isField('region') %} + {{ fields.textField( + 'region', + data['region'], + labels['region'], + field_options + ) }} + {% endif %} + + {% if item.isField('compactionHour') %} + {{ fields.textField( + 'compactionHour', + data['formatCompactionHour'], + __('Compaction Hour', 'borgbase'), + field_options + ) }} + {% endif %} + + {% if item.isField('is_encrypted') %} + {{ fields.textField( + 'is_encrypted', + data['is_encrypted'], + labels['encryption'], + field_options + ) }} + {% endif %} + + {% if item.isField('currentUsage') %} + {{ fields.textField( + 'currentUsage', + data['formatCurrentUsage'], + labels['usage'], + field_options + ) }} + {% endif %} + + {% if item.isField('createdAt') %} + {{ fields.textField( + 'createdAt', + data['formatCreatedAt'], + labels['createdAt'], + field_options + ) }} + {% endif %} + + {% if item.isField('lastModified') %} + {{ fields.textField( + 'lastModified', + data['formatLastModified'], + labels['lastBackup'], + field_options + ) }} + {% endif %} + + + + + +
{# .row #} +
{# .row #} +
{# .flex-row #} +
{# .flex-column #} +
{# .flex-wrap #} + +
+ + {% if canPurge %} + + {% endif %} + + {% if canUpdate %} + + {% endif %} + +
+ +
+ + \ No newline at end of file diff --git a/tools/HEADER b/tools/HEADER new file mode 100644 index 0000000..a8359f2 --- /dev/null +++ b/tools/HEADER @@ -0,0 +1,28 @@ +------------------------------------------------------------------------- +Borgbase plugin for GLPI +------------------------------------------------------------------------- + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------- +@copyright Copyright (C) 2022 by the Borgbase plugin team. +@license MIT https://opensource.org/licenses/mit-license.php +@link https://github.com/pluginsGLPI/borgbase +------------------------------------------------------------------------- diff --git a/tools/generate_locales.sh b/tools/generate_locales.sh new file mode 100644 index 0000000..06866a3 --- /dev/null +++ b/tools/generate_locales.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +CUR_PATH="`dirname \"$0\"`" + +cd "$CUR_PATH/.." + +xgettext *.php */*.php -o locales/borgbase.pot -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po -k --keyword=__:1,2t --keyword=_x:1,2,3t --keyword=__s:1,2t --keyword=_sx:1,2,3t --keyword=_n:1,2,3,4t --keyword=_sn:1,2t --keyword=_nx:1,2,3t --copyright-holder "TICgal" + +cd locales + +sed -i "s/SOME DESCRIPTIVE TITLE/BORGBASE Glpi Plugin/" borgbase.pot +sed -i "s/FIRST AUTHOR , YEAR./TICgal, $(date +%Y)/" borgbase.pot +sed -i "s/YEAR/$(date +%Y)/" borgbase.pot + +localazy upload +localazy download + +for a in $(ls *.po); do + msgmerge -U $a borgbase.pot + msgfmt $a -o "${a%.*}.mo" +done +rm -f *.po~ \ No newline at end of file diff --git a/tools/make_release.sh b/tools/make_release.sh new file mode 100644 index 0000000..9a12efd --- /dev/null +++ b/tools/make_release.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +PLUGINNAME="borgbase" + +if [ ! "$#" -eq 2 ] +then + echo "Usage $0 fi_git_dir release" + exit +fi + +read -p "Are translations up to date? [Y/n] " -n 1 -r +echo # (optional) move to a new line +if [[ ! $REPLY =~ ^[Yy]$ ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell +fi + +INIT_DIR=$1 +RELEASE=$2 + +# remove old tmp files +if [ ! -e /tmp/$PLUGINNAME ] +then + echo "Deleting temp directory" + rm -rf /tmp/$PLUGINNAME +fi + +# test plugin_cvs_dir +if [ ! -e $INIT_DIR ] +then + echo "$1 does not exist" + exit +fi + +INIT_PWD=$PWD; + +if [ -e /tmp/$PLUGINNAME ] +then + echo "Delete existing temp directory" + rm -rf /tmp/$PLUGINNAME +fi + +echo "Copy to /tmp directory" +git checkout-index -a -f --prefix=/tmp/$PLUGINNAME/ + +echo "Move to this directory" +cd /tmp/$PLUGINNAME + +echo "Check version" +if grep --quiet $RELEASE setup.php; then + echo "$RELEASE found in setup.php, OK." +else + echo "$RELEASE has not been found in setup.php. Exiting." + exit 1 +fi + +echo "Compile locale files" +./tools/generate_locales.sh + +echo "Delete various scripts and directories" +rm -rf vendor +rm -rf RoboFile.php +rm -rf tools +rm -rf phpunit +rm -rf tests +rm -rf .gitignore +rm -rf .travis.yml +rm -rf .coveralls.yml +rm -rf phpunit.xml.dist +rm -rf composer.lock +rm -rf .composer.hash +rm -rf ISSUE_TEMPLATE.md +rm -rf PULL_REQUEST_TEMPLATE.md +rm -rf .tx +rm -rf $PLUGINNAME.xml +rm -rf screenshots +rm -rf locales/localazy* + +echo "Creating tarball" +cd .. +tar czf "glpi-$PLUGINNAME-$RELEASE.tar.tgz" $PLUGINNAME + +cd $INIT_PWD; + +echo "Deleting temp directory" +rm -rf /tmp/$PLUGINNAME + +echo "The Tarball is in the /tmp directory" \ No newline at end of file