Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permit to add more than one encryption key by entity #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions accounts.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@
color: red;
font-weight: 900;
}

.default_encryption_key {
font-weight: bold;
color: red;
}
42 changes: 42 additions & 0 deletions ajax/getHashOnSelectEncryptionKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
accounts plugin for GLPI
Copyright (C) 2009-2016 by the accounts Development Team.

https://github.com/InfotelGLPI/accounts
-------------------------------------------------------------------------

LICENSE

This file is part of accounts.

accounts 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 2 of the License, or
(at your option) any later version.

accounts 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 accounts. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/


include('../../../inc/includes.php');

header("Content-Type: text/html; charset=UTF-8");

Session::checkLoginUser();

if (isset($_POST["id"])) {
$hashKey = new PluginAccountsHash();
$hashKey->getFromDB($_POST["id"]);
echo $hashKey->getField('hash');
}

224 changes: 117 additions & 107 deletions hook.php

Large diffs are not rendered by default.

83 changes: 68 additions & 15 deletions inc/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,37 +439,86 @@ public function showForm($ID, $options = []) {
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Key name', 'accounts') . "</td>";
echo "<td>";

if (empty($ID) || $ID < 0) {
$encryption_key_params = ['comments' =>false, 'name' => 'plugin_accounts_hash_id', 'value' => $this->fields["plugin_accounts_hash_id"],
'on_change' => 'checkInputIfNewEncryptionKey(this.value, '
. $this->fields["plugin_accounts_hash_id"] .')'];


$rand_hash = Dropdown::show('PluginAccountsHash', $encryption_key_params);

echo Html::scriptBlock("function checkInputIfNewEncryptionKey(newValue, currentValue) {
if (newValue != currentValue) {
$('#check-password').show();
$('#encryption-key').hide();
} else {
$('#check-password').hide();
$('#encryption-key').show();
}
};");

} else {
$hash_name = new PluginAccountsHash();
$hash_name->getFromDB($this->fields["plugin_accounts_hash_id"]);
echo "<span class='default_encryption_key' name='" . $hash_name->getField('name') . "' value='" . $hash_name->getField('name') . "' autocomplete='off'>
" . $hash_name->getField('name') . " </span>";
}
echo "</td>";
echo "<td colspan='2'>";
echo "</td>";
echo "</tr>";
echo "<tr id='check-password' class='tab_bg_1' style='display: none'>";
echo "<td>" . __('Encryption key', 'accounts') . "</div></td><td>";
echo "<input type='password' autocomplete='off' name='checkaeskey' id='checkaeskey'>";
echo "</td>";
echo "</tr>";

if (empty($ID) || $ID < 0) {
$params = ['id'=> '__VALUE__'];
Ajax::updateItemOnSelectEvent("dropdown_plugin_accounts_hash_id$rand_hash", "change_good_hash","../ajax/getHashOnSelectEncryptionKey.php", $params);
echo Html::hidden('change_good_hash', ['id' => 'change_good_hash']);
echo "<tr id='encryption-key' class='tab_bg_1'>";
}


//hash
$hash = 0;
$hash_id = 0;
$restrict = $dbu->getEntitiesRestrictCriteria("glpi_plugin_accounts_hashes", '',
$hash_account = new PluginAccountsHash();
$hash = 0;
$hash_id = 0;
$restrict = $dbu->getEntitiesRestrictCriteria("glpi_plugin_accounts_hashes", '',
$this->getEntityID(), $hashclass->maybeRecursive());
$hashes = $dbu->getAllDataFromTable("glpi_plugin_accounts_hashes", $restrict);
if (!empty($hashes)) {
foreach ($hashes as $hashe) {
$hash = $hashe["hash"];
$hash_id = $hashe["id"];
$hash_account->getFromDBByCrit(['id' => $this->fields["plugin_accounts_hash_id"]]);
if (count($hash_account->fields) > 0) {
$hash = $hash_account->getField("hash");
$hash_id = $hash_account->getField("id");
$alert = '';
} else {
$alert = __('There is no encryption key associated to this account, please select one above', 'accounts');
}
$alert = '';
} else {
$alert = __('There is no encryption key for this entity', 'accounts');
}

$aeskey = new PluginAccountsAesKey();

echo Html::hidden('encrypted_password', ['value' => $this->fields["encrypted_password"],
'id' => 'encrypted_password']);
echo Html::hidden('good_hash', ['value' => $hash,
'id' => 'good_hash']);
echo Html::hidden('wrong_key_locale', ['value' => __('Wrong encryption key', 'accounts'),
'id' => 'wrong_key_locale']);

//aeskey non enregistre
if ($hash) {
if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) {
echo "<td>" . __('Encryption key', 'accounts') . "</div></td><td>";
echo "<input type='password' autocomplete='off' name='aeskey' id='aeskey'>";

echo Html::hidden('encrypted_password', ['value' => $this->fields["encrypted_password"],
'id' => 'encrypted_password']);
echo Html::hidden('good_hash', ['value' => $hash,
'id' => 'good_hash']);
echo Html::hidden('wrong_key_locale', ['value' => __('Wrong encryption key', 'accounts'),
'id' => 'wrong_key_locale']);
if (!empty($ID) || $ID > 0) {
echo "&nbsp;<input type='submit' id='decrypte_link' name='decrypte' value='" . __s('Uncrypt & copy', 'accounts') . "'
class='submit'>";
Expand Down Expand Up @@ -648,7 +697,7 @@ class='submit'>";
echo "<input type='submit' name='add' id='account_add' value='" . _sx('button', 'Add') . "' class='submit'>";
echo "</div>";
echo Html::scriptBlock("$('#account_form').submit(function(event){
if ($('#hidden_password').val() == '' || $('#aeskey').val() == '') {
if ($('#hidden_password').val() == '' || $('#checkaeskey').val() == '') {
alert('" . __('You have not filled the password and encryption key', 'accounts') . "');
return false;
};
Expand All @@ -669,7 +718,11 @@ class='submit'>";
echo Html::hidden('id', ['value' => $ID]);
echo "<input type='submit' name='update' id='account_update' value=\"" . _sx('button', 'Save') . "\" class='submit' >";
echo Html::scriptBlock("$('#account_form').submit(function(event){
if ($('#hidden_password').val() == '' || $('#aeskey').val() == '') {
let checkAESKey = $('#checkaeskey').val();
let hiddenPassword = $('#hidden_password').val();
let aeskey = $('#aeskey').val();

if ((hiddenPassword == '' || aeskey == '') && checkAESKey == '') {
alert('" . __('Password will not be modified', 'accounts') . "');
} else if (!check_hash()) {
alert('" . __('Wrong encryption key', 'accounts') . "');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
132 changes: 132 additions & 0 deletions install/sql/empty-2.7.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
DROP TABLE IF EXISTS `glpi_plugin_accounts_accounts`;
CREATE TABLE `glpi_plugin_accounts_accounts` (
`id` int(11) NOT NULL auto_increment,
`entities_id` int(11) NOT NULL default '0',
`is_recursive` tinyint(1) NOT NULL default '0',
`name` varchar(255) collate utf8_unicode_ci default NULL,
`login` varchar(255) collate utf8_unicode_ci default NULL,
`encrypted_password` varchar(255) collate utf8_unicode_ci default NULL,
`others` varchar(255) collate utf8_unicode_ci default NULL,
`plugin_accounts_accounttypes_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_accounts_accounttypes (id)',
`plugin_accounts_accountstates_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_accounts_accountstates (id)',
`plugin_accounts_hash_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_accounts_hashes (id)',
`date_creation` timestamp NULL DEFAULT NULL,
`date_expiration` timestamp NULL DEFAULT NULL,
`users_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',
`groups_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_groups (id)',
`users_id_tech` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',
`groups_id_tech` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_groups (id)',
`locations_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_locations (id)',
`is_helpdesk_visible` int(11) NOT NULL default '1',
`date_mod` timestamp NULL DEFAULT NULL,
`comment` text collate utf8_unicode_ci,
`is_deleted` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `entities_id` (`entities_id`),
KEY `plugin_accounts_accounttypes_id` (`plugin_accounts_accounttypes_id`),
KEY `plugin_accounts_accountstates_id` (`plugin_accounts_accountstates_id`),
KEY `users_id` (`users_id`),
KEY `groups_id` (`groups_id`),
KEY `users_id_tech` (`users_id_tech`),
KEY `groups_id_tech` (`groups_id_tech`),
KEY `date_mod` (`date_mod`),
KEY `is_helpdesk_visible` (`is_helpdesk_visible`),
KEY `is_deleted` (`is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_accounttypes`;
CREATE TABLE `glpi_plugin_accounts_accounttypes` (
`id` int(11) NOT NULL auto_increment,
`entities_id` int(11) NOT NULL default '0',
`is_recursive` tinyint(1) NOT NULL default '0',
`name` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text collate utf8_unicode_ci,
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_accountstates`;
CREATE TABLE `glpi_plugin_accounts_accountstates` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text collate utf8_unicode_ci,
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_hashes`;
CREATE TABLE `glpi_plugin_accounts_hashes` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`entities_id` int(11) NOT NULL default '0',
`is_recursive` tinyint(1) NOT NULL default '0',
`hash` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text collate utf8_unicode_ci,
`date_mod` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `entities_id` (`entities_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_aeskeys`;
CREATE TABLE `glpi_plugin_accounts_aeskeys` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`plugin_accounts_hashes_id` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `plugin_accounts_hashes_id` (`plugin_accounts_hashes_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_accounts_items`;
CREATE TABLE `glpi_plugin_accounts_accounts_items` (
`id` int(11) NOT NULL auto_increment,
`plugin_accounts_accounts_id` int(11) NOT NULL default '0',
`items_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)',
`itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_accounts_accounts_id`,`itemtype`,`items_id`),
KEY `FK_device` (`items_id`,`itemtype`),
KEY `item` (`itemtype`,`items_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_accounts_configs`;
CREATE TABLE `glpi_plugin_accounts_configs` (
`id` int(11) NOT NULL auto_increment,
`delay_expired` varchar(50) collate utf8_unicode_ci NOT NULL default '30',
`delay_whichexpire` varchar(50) collate utf8_unicode_ci NOT NULL default '30',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `glpi_plugin_accounts_configs` ( `id` , `delay_expired` , `delay_whichexpire`) VALUES (1, '30', '30');

DROP TABLE IF EXISTS `glpi_plugin_accounts_notificationstates`;
CREATE TABLE `glpi_plugin_accounts_notificationstates` (
`id` int(11) NOT NULL auto_increment,
`plugin_accounts_accountstates_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_accounts_accountstates (id)',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `glpi_plugin_compte_mailing`;

INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','2','3','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','3','1','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','4','2','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','5','4','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','6','5','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsAccount','7','6','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','2','3','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','3','1','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','4','2','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','5','4','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','6','5','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsHelpdesk','7','6','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','2','3','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','3','1','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','4','2','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','5','4','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','6','5','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','7','6','0');
INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAccountsGroup','8','7','0');

INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'New Accounts', 'PluginAccountsAccount', '2010-02-17 22:36:46','',NULL, '2010-02-17 22:36:46');
INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'Alert Accounts', 'PluginAccountsAccount', '2010-02-23 11:37:46','',NULL, '2010-02-17 22:36:46');
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions install/sql/update-2.7.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `glpi_plugin_accounts_accounts`
ADD `plugin_accounts_hash_id` INT(11) NOT NULL default '0';
61 changes: 61 additions & 0 deletions install/update_270_migrateMultiHashEntities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/*
-------------------------------------------------------------------------
accounts plugin for GLPI
Copyright (C) 2015 by the accounts Development Team.
-------------------------------------------------------------------------

LICENSE

This file is part of accounts.

accounts 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 2 of the License, or
(at your option) any later version.

accounts 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 accounts. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

/**
* Update from 1.3.3 to 1.5.0
*
* @return bool for success (will die for most error)
* */
function update_270_migrateMultiHashEntities() {
global $DB;
$dbu = new DbUtils();
$entity = new Entity();
$hashes = new PluginAccountsHash();
$account = new PluginAccountsAccount();

$restrict = '';
$entities = $entity->find();
foreach ($entities as $e) {
$restrict = $dbu->getEntitiesRestrictCriteria("glpi_plugin_accounts_hashes", '', $e['id'], $hashes->maybeRecursive());
$hashesList = $dbu->getAllDataFromTable("glpi_plugin_accounts_hashes", $restrict);
$idHash = 0;

if (count($hashesList) > 0) {
foreach ($hashesList as $hashItem) {
$idHash = $hashItem['id'];
}

$accounts = $account->find(['entities_id' => $e['id']]);
foreach ($accounts as $a) {
$input = [];
$input['id'] = $a['id'];
$input['plugin_accounts_hash_id'] = $idHash;
$account->update($input);
}
}
}
return true;
}
4 changes: 2 additions & 2 deletions scripts/account.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ $(document).ready(function () {
}

// find the good element
var target = $($('.account_to_clipboard_wrapper'));
if (target.attr('class') == 'account_to_clipboard_wrapper') {
var target = $('.account_to_clipboard_wrapper');
if (target.attr('class') === 'account_to_clipboard_wrapper') {
target = target.find('*');
}

Expand Down
Loading