diff --git a/css/link.css b/css/link.css new file mode 100644 index 0000000..6332cb8 --- /dev/null +++ b/css/link.css @@ -0,0 +1,4 @@ +.action-PluginOnetimesecretLink_1, .action-PluginOnetimesecretLink_1:hover { + background-color: #DD4A22; + color: white; +} \ No newline at end of file diff --git a/front/config.form.php b/front/config.form.php index 09e0ade..2fa9b57 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ include('../../../inc/includes.php'); @@ -42,8 +42,10 @@ $config = new PluginOnetimesecretConfig(); if (isset($_POST["update"])) { $config->check($_POST['id'], UPDATE); - $_POST["apikey"] = (new GLPIKey())->encrypt($_POST["apikey"]); $config->update($_POST); Html::back(); } -Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php?forcetab=" . urlencode('PluginOnetimesecretConfig$1')); + +$redirect = $CFG_GLPI["root_doc"] . "/front/config.form.php"; +$redirect .= "?forcetab=" . urlencode('PluginOnetimesecretConfig$1'); +Html::redirect($redirect); diff --git a/front/link.form.php b/front/link.form.php index c6c4ff9..d09e495 100644 --- a/front/link.form.php +++ b/front/link.form.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ include('../../../inc/includes.php'); diff --git a/hook.php b/hook.php index 6ea1462..f3190ec 100644 --- a/hook.php +++ b/hook.php @@ -1,36 +1,41 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ -function plugin_onetimesecret_install() +/** + * plugin_onetimesecret_install + * + * @return bool + */ +function plugin_onetimesecret_install(): bool { $migration = new Migration(PLUGIN_ONETIMESECRET_VERSION); @@ -46,6 +51,7 @@ function plugin_onetimesecret_install() } } } + $conf = Config::getConfigurationValues('core', ['notifications_push']); if (!isset($conf['notifications_push'])) { Config::setConfigurationValues('core', ['notifications_push' => 0]); @@ -54,7 +60,12 @@ function plugin_onetimesecret_install() return true; } -function plugin_onetimesecret_uninstall() +/** + * plugin_onetimesecret_uninstall + * + * @return bool + */ +function plugin_onetimesecret_uninstall(): bool { $migration = new Migration(PLUGIN_ONETIMESECRET_VERSION); diff --git a/inc/config.class.php b/inc/config.class.php index b7e70f2..8082ab3 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); @@ -38,7 +38,9 @@ class PluginOnetimesecretConfig extends CommonDBTM { - private static $_instance = null; + private static $instance = null; + + public static $rightname = 'config'; public function __construct() { @@ -48,43 +50,50 @@ public function __construct() } } - public static function canCreate() - { - return Session::haveRight('config', UPDATE); - } - - public static function canView() - { - return Session::haveRight('config', READ); - } - - public static function canUpdate() - { - return Session::haveRight('config', UPDATE); - } - - public static function getTypeName($nb = 0) + /** + * getTypeName + * + * @param mixed $nb + * @return string + */ + public static function getTypeName($nb = 0): string { return 'One-Time Secret'; } - public static function getMenuName() + /** + * getMenuName + * + * @return string + */ + public static function getMenuName(): string { return 'One-Time Secret'; } - public static function getInstance() + /** + * getInstance + * + * @param mixed $n + * @return mixed + */ + public static function getInstance($n = 1): mixed { - if (!isset(self::$_instance)) { - self::$_instance = new self(); - if (!self::$_instance->getFromDB(1)) { - self::$_instance->getEmpty(); + if (!isset(self::$instance)) { + self::$instance = new self(); + if (!self::$instance->getFromDB($n)) { + self::$instance->getEmpty(); } } - return self::$_instance; + return self::$instance; } - public static function getLifetimes() + /** + * getLifetimes + * + * @return array + */ + public static function getLifetimes(): array { $one_day_in_sec = 86400; $one_hour_in_sec = 3600; @@ -104,7 +113,12 @@ public static function getLifetimes() return $lifetimes; } - public static function showConfigForm() + /** + * showConfigForm + * + * @return bool + */ + public static function showConfigForm(): bool { $config = self::getInstance(); @@ -113,14 +127,22 @@ public static function showConfigForm() $template = "@onetimesecret/config.html.twig"; $template_options = [ 'item' => $config, - 'lifetimes' => $lifetimes + 'lifetimes' => $lifetimes, + 'conn' => PluginOnetimesecretSecret::authentication() ]; TemplateRenderer::getInstance()->display($template, $template_options); return false; } - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + /** + * getTabNameForItem + * + * @param mixed $item + * @param mixed $withtemplate + * @return string + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0): string { if ($item->getType() == 'Config') { return self::getTypeName(); @@ -128,7 +150,15 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) return ''; } - public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + /** + * displayTabContentForItem + * + * @param mixed $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return bool + */ + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0): bool { if ($item->getType() == 'Config') { self::showConfigForm($item); @@ -136,7 +166,13 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ return true; } - public function prepareInputForUpdate($input) + /** + * prepareInputForUpdate + * + * @param mixed $input + * @return array + */ + public function prepareInputForUpdate($input): array { if (isset($input['apikey'])) { if (!empty($input['apikey'])) { @@ -148,10 +184,17 @@ public function prepareInputForUpdate($input) if (isset($input['_blank_apikey'])) { $input['apikey'] = ''; } + return $input; } - public static function install(Migration $migration) + /** + * install + * + * @param mixed $migration + * @return void + */ + public static function install(Migration $migration): void { global $DB; @@ -172,7 +215,8 @@ public static function install(Migration $migration) `debug` tinyint(1) NOT NULL default '1', `users_id` int {$default_key_sign} NOT NULL DEFAULT '0', PRIMARY KEY (`id`) - )ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + )ENGINE=InnoDB DEFAULT CHARSET={$default_charset} + COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die($DB->error()); diff --git a/inc/link.class.php b/inc/link.class.php index 980eb98..78d2a38 100644 --- a/inc/link.class.php +++ b/inc/link.class.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); @@ -40,23 +40,48 @@ class PluginOnetimesecretLink extends CommonDBTM { public static $rightname = 'followup'; - public function getItilObjectItemType() + /** + * getItilObjectItemType + * + * @return string + */ + public function getItilObjectItemType(): string { return str_replace('One-Time Secret', '', $this->getType()); } - public static function getTypeName($nb = 0) + /** + * getTypeName + * + * @param mixed $nb + * @return string + */ + public static function getTypeName($nb = 0): string { return __('One-Time Secret', 'onetimesecret'); } - public static function timelineAction($params = []) + /** + * getEmpty + * + * @return bool + */ + public function getEmpty(): bool + { + return true; + } + + /** + * timelineAction + * + * @param array $params + * @return array + */ + public static function timelineAction(array $params = []): array { global $DB; $item = $params['item']; - $config = PluginOnetimesecretConfig::getInstance(); - switch ($item::getType()) { case Ticket::getType(): $req = $DB->request( @@ -77,25 +102,25 @@ public static function timelineAction($params = []) 'label' => self::getTypeName() ]; - $color = 'DD4A22'; - $style = <<$style"; - + $href = Plugin::getWebDir('onetimesecret') . "/css/link.css"; + echo ""; return $timeline; } } break; } + return []; } - public function showForm($ID, array $params = []) + /** + * showForm + * + * @param mixed $ID + * @param mixed $params + * @return void + */ + public function showForm($ID, array $params = []): void { $config = PluginOnetimesecretConfig::getInstance(); @@ -117,12 +142,13 @@ public function showForm($ID, array $params = []) TemplateRenderer::getInstance()->display($template, $template_options); } - public function getEmpty() - { - return true; - } - - public static function install(Migration $migration) + /** + * install + * + * @param mixed $migration + * @return void + */ + public static function install(Migration $migration): void { global $DB; $default_charset = DBConnection::getDefaultCharset(); diff --git a/inc/profile.class.php b/inc/profile.class.php index ddbc203..dbfa348 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); @@ -36,18 +36,33 @@ class PluginOnetimesecretProfile extends Profile { - public static $rightname = "config"; + public static $rightname = "profile"; - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + /** + * getTabNameForItem + * + * @param mixed $item + * @param mixed $withtemplate + * @return string + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0): string { switch ($item->getType()) { case 'Profile': return self::createTabEntry("One-Time Secret"); - break; } + return ''; } - public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + /** + * displayTabContentForItem + * + * @param mixed $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return bool + */ + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0): bool { switch ($item->getType()) { case 'Profile': @@ -58,7 +73,15 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ return true; } - public function showForm($profiles_id = 0, $openform = true, $closeform = true) + /** + * showForm + * + * @param mixed $profiles_id + * @param mixed $openform + * @param mixed $closeform + * @return bool + */ + public function showForm($profiles_id = 0, $openform = true, $closeform = true): bool { $profile = new Profile(); $profile->getFromDB($profiles_id); @@ -89,14 +112,24 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) return true; } - public function getAllRights() + /** + * getAllRights + * + * @return array + */ + public function getAllRights(): array { $a_rights = []; $a_rights = array_merge($a_rights, $this->getRightsGeneral()); return $a_rights; } - public function getRightsGeneral() + /** + * getRightsGeneral + * + * @return array + */ + public function getRightsGeneral(): array { $rights = [ [ @@ -108,11 +141,23 @@ public function getRightsGeneral() return $rights; } - public static function addDefaultProfileInfos($profiles_id, $rights) + /** + * addDefaultProfileInfos + * + * @param mixed $profiles_id + * @param mixed $rights + * @return void + */ + public static function addDefaultProfileInfos($profiles_id, $rights): void { $profileRight = new ProfileRight(); foreach ($rights as $right => $value) { - if (!countElementsInTable('glpi_profilerights', ['profiles_id' => $profiles_id, 'name' => $right])) { + if ( + !countElementsInTable( + 'glpi_profilerights', + ['profiles_id' => $profiles_id, 'name' => $right] + ) + ) { $myright['profiles_id'] = $profiles_id; $myright['name'] = $right; $myright['rights'] = $value; @@ -123,7 +168,13 @@ public static function addDefaultProfileInfos($profiles_id, $rights) } } - public static function createFirstAccess($profiles_id) + /** + * createFirstAccess + * + * @param mixed $profiles_id + * @return void + */ + public static function createFirstAccess($profiles_id): void { $profile = new self(); foreach ($profile->getAllRights() as $right) { @@ -131,7 +182,12 @@ public static function createFirstAccess($profiles_id) } } - public static function removeRightsFromSession() + /** + * removeRightsFromSession + * + * @return void + */ + public static function removeRightsFromSession(): void { $profile = new self(); foreach ($profile->getAllRights() as $right) { @@ -142,7 +198,12 @@ public static function removeRightsFromSession() ProfileRight::deleteProfileRights([$right['field']]); } - public static function initProfile() + /** + * initProfile + * + * @return void + */ + public static function initProfile(): void { $pfProfile = new self(); $profile = new Profile(); @@ -159,7 +220,11 @@ public static function initProfile() $dataprofile['id'] = $_SESSION['glpiactiveprofile']['id']; $profile->getFromDB($_SESSION['glpiactiveprofile']['id']); foreach ($a_rights as $info) { - if (is_array($info) && ((!empty($info['itemtype'])) || (!empty($info['rights']))) && (!empty($info['label'])) && (!empty($info['field']))) { + if ( + is_array($info) && + ((!empty($info['itemtype'])) || (!empty($info['rights']))) && + (!empty($info['label'])) && (!empty($info['field'])) + ) { if (isset($info['rights'])) { $rights = $info['rights']; } else { @@ -175,15 +240,29 @@ public static function initProfile() } } - public static function install(Migration $migration) + /** + * install + * + * @param mixed $migration + * @return void + */ + public static function install(Migration $migration): void { + $migration->displayMessage("Init profiles"); self::initProfile(); } - public static function uninstall() + /** + * uninstall + * + * @param mixed $migration + * @return void + */ + public static function uninstall(Migration $migration): void { $pfProfile = new self(); $a_rights = $pfProfile->getAllRights(); + $migration->displayMessage("Delete profiles"); foreach ($a_rights as $data) { ProfileRight::deleteProfileRights([$data['field']]); } diff --git a/inc/secret.class.php b/inc/secret.class.php index e4d167c..e795752 100644 --- a/inc/secret.class.php +++ b/inc/secret.class.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ use Glpi\Toolbox\Sanitizer; @@ -36,17 +36,22 @@ die("Sorry. You can't access directly to this file"); } - class PluginOnetimesecretSecret extends CommonDBTM { - public static function authentication() + /** + * authentication + * + * @return array + */ + public static function authentication(): array { global $CFG_GLPI; $config = PluginOnetimesecretConfig::getInstance(); $apikey = (new GLPIKey())->decrypt($config->fields["apikey"]); $curl = curl_init(); - $server = "https://" . $config->fields["email"] . ":" . $apikey . "@" . $config->fields["server"] . "/api"; + $server = "https://" . $config->fields["email"] . ":" . $apikey; + $server .= "@" . $config->fields["server"] . "/api"; curl_setopt($curl, CURLOPT_URL, $server); if (!empty($CFG_GLPI["proxy_name"])) { @@ -80,9 +85,17 @@ public static function authentication() $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); + + return [$httpcode, $result]; } - public static function createSecret($params = []) + /** + * createSecret + * + * @param array $params + * @return bool|string + */ + public static function createSecret(array $params = []): bool|string { global $CFG_GLPI; @@ -139,14 +152,27 @@ public static function createSecret($params = []) } } - public static function hoursToSeconds($hours) + /** + * hoursToSeconds + * + * @param int $hours + * @return int + */ + public static function hoursToSeconds(int $hours): int { $minutes = $hours * 60; $seconds = $minutes * 60; return $seconds; } - public static function addFollowup($params, $text = '') + /** + * addFollowup + * + * @param array $params + * @param string $text + * @return bool + */ + public static function addFollowup(array $params, string $text = ''): bool { global $DB, $CFG_GLPI; diff --git a/setup.php b/setup.php index ac80c2c..0ac3eee 100644 --- a/setup.php +++ b/setup.php @@ -1,34 +1,34 @@ . --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- -*/ +/** + * ------------------------------------------------------------------------- + * OneTimeSecret plugin for GLPI + * Copyright (C) 2021-2024 by the TICgal Team. + * https://www.tic.gal + * ------------------------------------------------------------------------- + * LICENSE + * This file is part of the OneTimeSecret plugin. + * OneTimeSecret plugin is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * OneTimeSecret plugin 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with OneTimeSecret. If not, see + * . + * ------------------------------------------------------------------------- + * @package OneTimeSecret + * @author the TICgal team + * @copyright Copyright (c) 2021-2024 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 + * ------------------------------------------------------------------------- + */ use Glpi\Plugin\Hooks; @@ -41,7 +41,7 @@ * * @return void */ -function plugin_init_onetimesecret() +function plugin_init_onetimesecret(): void { global $PLUGIN_HOOKS; @@ -66,7 +66,7 @@ function plugin_init_onetimesecret() * * @return array */ -function plugin_version_onetimesecret() +function plugin_version_onetimesecret(): array { return [ 'name' => 'OneTimeSecret', @@ -89,7 +89,7 @@ function plugin_version_onetimesecret() * * @return boolean */ -function plugin_onetimesecret_check_prerequisites() +function plugin_onetimesecret_check_prerequisites(): bool { return true; } @@ -102,7 +102,7 @@ function plugin_onetimesecret_check_prerequisites() * * @return boolean */ -function plugin_onetimesecret_check_config($verbose = false) +function plugin_onetimesecret_check_config($verbose = false): bool { if (true) { // Your configuration check return true; @@ -111,5 +111,6 @@ function plugin_onetimesecret_check_config($verbose = false) if ($verbose) { echo "Installed, but not configured"; } + return false; } diff --git a/templates/config.html.twig b/templates/config.html.twig index aaadbee..c17add3 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -1,31 +1,31 @@ {# -------------------------------------------------------------------------- -OneTimeSecret plugin for GLPI -Copyright (C) 2021-2023 by the TICgal Team. -https://www.tic.gal -------------------------------------------------------------------------- -LICENSE -This file is part of the OneTimeSecret plugin. -OneTimeSecret plugin is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. -OneTimeSecret plugin 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 General Public License for more details. -You should have received a copy of the GNU General Public License -along with OneTimeSecret. If not, see -. --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- +# ------------------------------------------------------------------------- +# OneTimeSecret plugin for GLPI +# Copyright (C) 2021-2024 by the TICgal Team. +# https://www.tic.gal +# ------------------------------------------------------------------------- +# LICENSE +# This file is part of the OneTimeSecret plugin. +# OneTimeSecret plugin is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# OneTimeSecret plugin 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 General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with OneTimeSecret. If not, see +# . +# ------------------------------------------------------------------------- +# @package OneTimeSecret +# @author the TICgal team +# @copyright Copyright (c) 2021-2024 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 +# ------------------------------------------------------------------------- #} {% import 'components/form/fields_macros.html.twig' as fields %} @@ -41,63 +41,66 @@ http://www.gnu.org/licenses/agpl-3.0-standalone.html {{ include('components/form/header.html.twig', {'in_twig': true, 'no_header': true}) }} {% set params = params ?? [] %} - {% set field_options = {} %} + {% set field_options = {'full_width': true} %} -
-
-
-
-
- - +
+
+ + - {% if item.isfield('server') %} - {{ fields.textField( - 'server', - item.fields['server'], - __("Server"), - field_options - ) }} - {% endif %} + {% if item.isfield('server') %} + {{ fields.textField( + 'server', + item.fields['server'], + __("Server"), + field_options + ) }} + {% endif %} - {% if item.isfield('email') %} - {{ fields.textField( - 'email', - item.fields['email'], - __("Email"), - field_options - ) }} - {% endif %} + {% if item.isfield('email') %} + {{ fields.textField( + 'email', + item.fields['email'], + __("Email"), + field_options + ) }} + {% endif %} - {% if item.isField('apikey') %} - {{ fields.passwordField( - 'apikey', - item.fields['apikey'], - __('API key', 'onetimesecret'), - field_options - ) }} - {% endif %} + {% if item.isField('apikey') %} + {{ fields.passwordField( + 'apikey', + item.fields['apikey'], + __('API key', 'onetimesecret'), + field_options + ) }} + {% endif %} -
- - {{__('Lifetime', 'onetimesecret')}} -
+
+ + {{__('Lifetime', 'onetimesecret')}} +
- {% if item.isField('lifetime') %} - {{ fields.dropdownArrayField( - 'lifetime', - item.fields['lifetime'], - lifetimes, - __('Secret lifetime', 'onetimesecret'), - field_options - ) }} - {% endif %} + {% if item.isField('lifetime') %} + {{ fields.dropdownArrayField( + 'lifetime', + item.fields['lifetime'], + lifetimes, + __('Secret lifetime', 'onetimesecret'), + field_options|merge({'width': 'auto'}) + ) }} + {% endif %} +
-
{# .row #} -
{# .row #} -
{# .flex-row #} -
{# .flex-column #} -
{# .flex-wrap #} +
+ {% if conn and conn[0] matches '{^2\d{2}}' %} + + {% else %} + + {% endif %} +
+
{{ include('components/form/buttons.html.twig') }} \ No newline at end of file diff --git a/templates/link.html.twig b/templates/link.html.twig index 9f709ef..dcd8f0d 100644 --- a/templates/link.html.twig +++ b/templates/link.html.twig @@ -1,31 +1,31 @@ {# -------------------------------------------------------------------------- -OneTimeSecret plugin for GLPI -Copyright (C) 2021-2023 by the TICgal Team. -https://www.tic.gal -------------------------------------------------------------------------- -LICENSE -This file is part of the OneTimeSecret plugin. -OneTimeSecret plugin is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. -OneTimeSecret plugin 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 General Public License for more details. -You should have received a copy of the GNU General Public License -along with OneTimeSecret. If not, see -. --------------------------------------------------------------------------- -@package OneTimeSecret -@author the TICgal team -@copyright Copyright (c) 2021-2023 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-2023 ----------------------------------------------------------------------- +# ------------------------------------------------------------------------- +# OneTimeSecret plugin for GLPI +# Copyright (C) 2021-2024 by the TICgal Team. +# https://www.tic.gal +# ------------------------------------------------------------------------- +# LICENSE +# This file is part of the OneTimeSecret plugin. +# OneTimeSecret plugin is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# OneTimeSecret plugin 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 General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with OneTimeSecret. If not, see +# . +# ------------------------------------------------------------------------- +# @package OneTimeSecret +# @author the TICgal team +# @copyright Copyright (c) 2021-2024 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 +# ------------------------------------------------------------------------- #} {% import 'components/form/fields_macros.html.twig' as fields %}