Skip to content

Commit

Permalink
delete deprecated with dbutils
Browse files Browse the repository at this point in the history
  • Loading branch information
amma35 committed Aug 7, 2018
1 parent 41ffbf1 commit cb22acd
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 353 deletions.
4 changes: 3 additions & 1 deletion ajax/accounttreetypes.php
Expand Up @@ -50,7 +50,9 @@
$entity = $_SESSION['glpiactive_entity'];

$where = " WHERE `glpi_plugin_accounts_accounts`.`is_deleted` = '0' ";
$where .= getEntitiesRestrictRequest("AND", "glpi_plugin_accounts_accounts");

$dbu = new DbUtils();
$where .= $dbu->getEntitiesRestrictRequest("AND", "glpi_plugin_accounts_accounts");

$query = "SELECT *
FROM `glpi_plugin_accounts_accounttypes`
Expand Down
70 changes: 0 additions & 70 deletions front/account.upgrade.php

This file was deleted.

18 changes: 3 additions & 15 deletions front/hash.form.php
Expand Up @@ -38,9 +38,10 @@
$account->checkGlobal(UPDATE);

$hashClass = new PluginAccountsHash();
$dbu = new DbUtils();

$update = 0;
if (countElementsInTable("glpi_plugin_accounts_accounts") > 0) {
if ($dbu->countElementsInTable("glpi_plugin_accounts_accounts") > 0) {
$update = 1;
}

Expand All @@ -50,19 +51,6 @@
$newID = $hashClass->add($_POST);
$hashClass->redirectToList();

} else if (isset($_POST["upgrade"])) {
if ($_POST["hash"]) {
include_once(GLPI_ROOT . "/plugins/accounts/hook.php");
$_SESSION['plugin_accounts']['aescrypted_key'] = $_POST["aeskey"];
$hashClass->update($_POST);

plugin_accounts_configure15();
$_SESSION['plugin_accounts']['upgrade'] = [];
Html::redirect("./account.upgrade.php");
} else {
Html::back();
}

} else if (isset($_POST["update"]) && $_POST["hash"]) {

$hashClass->check($_POST['id'], UPDATE);
Expand Down Expand Up @@ -115,7 +103,7 @@
Html::header(PluginAccountsAccount::getTypeName(2), '', "admin", "pluginaccountsmenu", "hash");
}

$options = ["id" => $_GET['id'], "update" => false, "upgrade" => 0];
$options = ["id" => $_GET['id'], "update" => false];
$hashClass->display($options);
Html::footer();

Expand Down
78 changes: 0 additions & 78 deletions front/upgrade.form.php

This file was deleted.

92 changes: 8 additions & 84 deletions hook.php
Expand Up @@ -52,7 +52,6 @@ function plugin_accounts_install() {
$update78 = true;
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.1.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
plugin_accounts_updatev14();
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
Expand All @@ -66,7 +65,6 @@ function plugin_accounts_install() {

$update78 = true;
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
plugin_accounts_updatev14();
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
Expand All @@ -79,7 +77,6 @@ function plugin_accounts_install() {
&& !$DB->fieldExists("glpi_plugin_compte_profiles", "my_groups")) {

$update78 = true;
plugin_accounts_updatev14();
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
Expand Down Expand Up @@ -298,13 +295,8 @@ function plugin_accounts_install() {

}

if (isset($_SESSION['plugin_acounts_upgrading'])) {
$msg = __('After plugin installation, you must do upgrade of your passwords from here : ', 'accounts');
$msg .= "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/front/upgrade.form.php'>" . __('Upgrading page', 'accounts') . "</a>";
Session::addMessageAfterRedirect($msg, ERROR);
}

$notepad_tables = ['glpi_plugin_accounts_accounts'];
$dbu = new DbUtils();

foreach ($notepad_tables as $t) {
// Migrate data
Expand All @@ -316,7 +308,7 @@ function plugin_accounts_install() {
foreach ($DB->request($query) as $data) {
$iq = "INSERT INTO `glpi_notepads`
(`itemtype`, `items_id`, `content`, `date`, `date_mod`)
VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',
VALUES ('" . $dbu->getItemTypeForTable($t) . "', '" . $data['id'] . "',
'" . addslashes($data['notepad']) . "', NOW(), NOW())";
$DB->queryOrDie($iq, "0.85 migrate notepad data");
}
Expand All @@ -334,77 +326,6 @@ function plugin_accounts_install() {
return true;
}

function plugin_accounts_updatev14() {
global $DB;

$DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.4.sql");

// crypt passwords
$query_ = "SELECT *
FROM `glpi_plugin_compte` ";
$result_ = $DB->query($query_);
if ($DB->numrows($result_) > 0) {

while ($data = $DB->fetch_array($result_)) {
$password = plugin_accounts_crypte($data["mdp"], 1);
$query = "UPDATE `glpi_plugin_compte`
SET `mdp` = '" . $password . "'
WHERE `ID` = '" . $data["ID"] . "';";
$DB->query($query);

}
}
}

/**
* @param $Texte
* @param $action
* @return string
*/
function plugin_accounts_crypte($Texte, $action) {
//$algo = "blowfish"; // ou la constante php MCRYPT_BLOWFISH
//$mode = "nofb"; // ou la constante php MCRYPT_MODE_NOFB
//$key_size = mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_256);
//$iv_size = mcrypt_get_iv_size($algo, $mode);
//$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$key = 'Ceci est une clé secrète';
if ($action == 1) {

$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $Texte, MCRYPT_MODE_ECB, $iv);
$crypttext = base64_encode($crypttext);
} else if ($action == 2) {
$crypttext = "<script language='javascript'>document.write(AESEncryptCtr($Texte,SHA256($key),256));</script>";
} else if ($action == 3) {
$Texte = base64_decode($Texte);
$crypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $Texte, MCRYPT_MODE_ECB, $iv);
}
return trim($crypttext);
}

function plugin_accounts_configure15() {
global $DB;

// uncrypt passwords for update
$query_ = "SELECT *
FROM `glpi_plugin_accounts_accounts` ";
$result_ = $DB->query($query_);
if ($DB->numrows($result_) > 0) {

while ($data = $DB->fetch_array($result_)) {

$password = addslashes(plugin_accounts_crypte($data['encrypted_password'], 3));

$PluginAccountsAccount = new PluginAccountsAccount();
$PluginAccountsAccount->update([
'id' => $data["id"],
'encrypted_password' => $password]);

}
}
}

/**
* @return bool
*/
Expand Down Expand Up @@ -756,6 +677,8 @@ function plugin_accounts_displayConfigItem($type, $ID, $data, $num) {
function plugin_accounts_giveItem($type, $ID, $data, $num) {
global $DB;

$dbu = new DbUtils();

$searchopt =& Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
Expand Down Expand Up @@ -784,7 +707,7 @@ function plugin_accounts_giveItem($type, $ID, $data, $num) {
}
$item = new $itemtype();
if ($item->canView()) {
$table_item = getTableForItemType($itemtype);
$table_item = $dbu->getTableForItemType($itemtype);
if ($itemtype != 'Entity') {
$query = "SELECT `" . $table_item . "`.*,
`glpi_plugin_accounts_accounts_items`.`id` AS items_id,
Expand All @@ -794,7 +717,8 @@ function plugin_accounts_giveItem($type, $ID, $data, $num) {
. " WHERE `" . $table_item . "`.`id` = `glpi_plugin_accounts_accounts_items`.`items_id`
AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '$itemtype'
AND `glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id` = '" . $accounts . "' ";
$query .= getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());

$query .= $dbu->getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());

if ($item->maybeTemplate()) {
$query .= " AND " . $table_item . ".is_template='0'";
Expand All @@ -808,7 +732,7 @@ function plugin_accounts_giveItem($type, $ID, $data, $num) {
. "` WHERE `" . $table_item . "`.`id` = `glpi_plugin_accounts_accounts_items`.`items_id`
AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '$itemtype'
AND `glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id` = '" . $accounts . "' "
. getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());
. $dbu->getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive());

if ($item->maybeTemplate()) {
$query .= " AND " . $table_item . ".is_template='0'";
Expand Down

0 comments on commit cb22acd

Please sign in to comment.