public static function updateHash($oldaeskey, $newaeskey, $hash_id) { global $DB; $self = new self(); $self->getFromDB($hash_id); $entities = getSonsOf('glpi_entities', $self->fields['entities_id']); $account = new PluginAccountsAccount(); $aeskey = new PluginAccountsAesKey(); $oldhash = hash("sha256", $oldaeskey); $newhash = hash("sha256", $newaeskey); $newhashstore = hash("sha256", $newhash); // uncrypt passwords for update $query_ = "SELECT *\n FROM `glpi_plugin_accounts_accounts`\n WHERE "; $query_ .= getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_accounts", '', $entities); $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $oldpassword = addslashes(plugin_accounts_AESDecryptCtr($data['encrypted_password'], $oldhash, 256)); $newpassword = addslashes(plugin_accounts_AESEncryptCtr($oldpassword, $newhash, 256)); $account->update(array('id' => $data["id"], 'encrypted_password' => $newpassword)); } $self->update(array('id' => $hash_id, 'hash' => $newhashstore)); if ($aeskey->getFromDBByHash($hash_id) && isset($aeskey->fields["name"])) { $values["id"] = $aeskey->fields["id"]; $values["name"] = $newaeskey; $aeskey->update($values); } } }
$aeskey = new PluginAccountsAesKey(); $plugin = new plugin(); if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "environment", "accounts", "hash"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "accounts", "hash"); } if (isset($_POST["add"])) { if ($aeskey->canCreate()) { $newID = $aeskey->add($_POST); } Html::back(); } else { if (isset($_POST["update"])) { if ($aeskey->canCreate()) { $aeskey->update($_POST); } Html::back(); } else { if (isset($_POST["delete"])) { if ($aeskey->canCreate()) { foreach ($_POST["check"] as $ID => $value) { $aeskey->delete(array("id" => $ID), 1); } } Html::back(); } else { $aeskey->showForm($_GET["id"], array('plugin_accounts_hashes_id' => $_GET["plugin_accounts_hashes_id"])); } } }