function plugin_init_databases() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['databases'] = true; $PLUGIN_HOOKS['change_profile']['databases'] = array('PluginDatabasesProfile', 'initProfile'); $PLUGIN_HOOKS['assign_to_ticket']['databases'] = true; //$PLUGIN_HOOKS['assign_to_ticket_dropdown']['databases'] = true; //$PLUGIN_HOOKS['assign_to_ticket_itemtype']['databases'] = array('PluginDatabasesDatabase_Item'); Plugin::registerClass('PluginDatabasesDatabase', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'addtabon' => 'Supplier')); Plugin::registerClass('PluginDatabasesProfile', array('addtabon' => 'Profile')); //Plugin::registerClass('PluginDatabasesDatabase_Item', // array('ticket_types' => true)); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginDatabasesDatabase'); } if (Session::getLoginUserID()) { $plugin = new Plugin(); if (!$plugin->isActivated('environment') && Session::haveRight("plugin_databases", READ)) { $PLUGIN_HOOKS['menu_toadd']['databases'] = array('assets' => 'PluginDatabasesMenu'); } if (Session::haveRight("plugin_databases", UPDATE)) { $PLUGIN_HOOKS['use_massive_action']['databases'] = 1; } if (class_exists('PluginDatabasesDatabase_Item')) { // only if plugin activated $PLUGIN_HOOKS['plugin_datainjection_populate']['databases'] = 'plugin_datainjection_populate_databases'; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['databases'] = 'plugin_databases_postinit'; // Import from Data_Injection plugin $PLUGIN_HOOKS['migratetypes']['databases'] = 'plugin_datainjection_migratetypes_databases'; } }
static function getMenuContent() { global $CFG_GLPI; $image = "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/pics/cadenas.png' title='" . _n('Encryption key', 'Encryption keys', 2) . "' alt='" . _n('Encryption key', 'Encryption keys', 2, 'accounts') . "'>"; $menu = array(); $menu['title'] = self::getMenuName(); $menu['page'] = "/plugins/accounts/front/account.php"; $menu['page'] = "/plugins/accounts/front/account.php"; $menu['links']['search'] = PluginAccountsAccount::getSearchURL(false); $menu['links'][$image] = PluginAccountsHash::getSearchURL(false); if (PluginAccountsAccount::canCreate()) { $menu['links']['add'] = PluginAccountsAccount::getFormURL(false); } $menu['options']['account']['title'] = PluginAccountsAccount::getTypeName(2); $menu['options']['account']['page'] = PluginAccountsAccount::getSearchURL(false); $menu['options']['account']['links']['search'] = PluginAccountsAccount::getSearchURL(false); $menu['options']['account']['links'][$image] = PluginAccountsHash::getSearchURL(false); if (PluginAccountsAccount::canCreate()) { $menu['options']['account']['links']['add'] = PluginAccountsAccount::getFormURL(false); } $menu['options']['hash']['title'] = PluginAccountsHash::getTypeName(2); $menu['options']['hash']['page'] = PluginAccountsHash::getSearchURL(false); $menu['options']['hash']['links']['search'] = PluginAccountsHash::getSearchURL(false); $menu['options']['hash']['links'][$image] = PluginAccountsHash::getSearchURL(false); if (PluginAccountsHash::canCreate()) { $menu['options']['hash']['links']['add'] = PluginAccountsHash::getFormURL(false); } return $menu; }
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Profile') { return PluginAccountsAccount::getTypeName(2); } return ''; }
function plugin_init_certificates() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['certificates'] = true; $PLUGIN_HOOKS['change_profile']['certificates'] = array('PluginCertificatesProfile', 'initProfile'); $PLUGIN_HOOKS['assign_to_ticket']['certificates'] = true; if (Session::getLoginUserID()) { // Params : plugin name - string type - number - attributes Plugin::registerClass('PluginCertificatesCertificate', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'helpdesk_visible_types' => true, 'ticket_types' => true, 'contract_types' => true, 'notificationtemplates_types' => true)); Plugin::registerClass('PluginCertificatesConfig', array('addtabon' => 'CronTask')); Plugin::registerClass('PluginCertificatesProfile', array('addtabon' => 'Profile')); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginCertificatesCertificate'); } $plugin = new Plugin(); if (!$plugin->isActivated('environment') && Session::haveRight("plugin_certificates", READ)) { $PLUGIN_HOOKS['menu_toadd']['certificates'] = array('assets' => 'PluginCertificatesMenu'); } if (Session::haveRight("plugin_certificates", UPDATE)) { $PLUGIN_HOOKS['use_massive_action']['certificates'] = 1; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['certificates'] = 'plugin_certificates_postinit'; } }
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { global $CFG_GLPI; if ($item->getType() == 'CronTask') { $target = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/notification.state.php"; PluginAccountsAccount::configCron($target); } return true; }
function plugin_init_databases() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['databases'] = true; $PLUGIN_HOOKS['change_profile']['databases'] = array('PluginDatabasesProfile', 'changeProfile'); $PLUGIN_HOOKS['assign_to_ticket']['databases'] = true; if (Session::getLoginUserID()) { Plugin::registerClass('PluginDatabasesDatabase', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'addtabon' => 'Supplier')); Plugin::registerClass('PluginDatabasesProfile', array('addtabon' => 'Profile')); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginDatabasesDatabase'); } if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) { $_SESSION["glpi_plugin_environment_databases"] = 1; // Display a menu entry ? if (plugin_databases_haveRight("databases", "r")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['title'] = PluginDatabasesDatabase::getTypeName(2); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['page'] = '/plugins/databases/front/database.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['links']['search'] = '/plugins/databases/front/database.php'; } if (plugin_databases_haveRight("databases", "w")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['databases']['links']['add'] = '/plugins/databases/front/database.form.php'; $PLUGIN_HOOKS['use_massive_action']['databases'] = 1; } } else { // Display a menu entry ? if (plugin_databases_haveRight("databases", "r")) { $PLUGIN_HOOKS['menu_entry']['databases'] = 'front/database.php'; $PLUGIN_HOOKS['submenu_entry']['databases']['search'] = 'front/database.php'; } if (plugin_databases_haveRight("databases", "w")) { $PLUGIN_HOOKS['submenu_entry']['databases']['add'] = 'front/database.form.php?new=1'; $PLUGIN_HOOKS['use_massive_action']['databases'] = 1; } } if (class_exists('PluginDatabasesDatabase_Item')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['databases'] = array('Profile' => array('PluginDatabasesProfile', 'purgeProfiles')); $PLUGIN_HOOKS['plugin_datainjection_populate']['databases'] = 'plugin_datainjection_populate_databases'; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['databases'] = 'plugin_databases_postinit'; // Import from Data_Injection plugin $PLUGIN_HOOKS['migratetypes']['databases'] = 'plugin_datainjection_migratetypes_databases'; } }
function plugin_init_certificates() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['certificates'] = true; $PLUGIN_HOOKS['change_profile']['certificates'] = array('PluginCertificatesProfile', 'changeProfile'); $PLUGIN_HOOKS['assign_to_ticket']['certificates'] = true; if (Session::getLoginUserID()) { // Params : plugin name - string type - number - attributes Plugin::registerClass('PluginCertificatesCertificate', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'helpdesk_visible_types' => true, 'ticket_types' => true, 'contract_types' => true, 'notificationtemplates_types' => true)); Plugin::registerClass('PluginCertificatesConfig', array('addtabon' => 'CronTask')); Plugin::registerClass('PluginCertificatesProfile', array('addtabon' => 'Profile')); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginCertificatesCertificate'); } if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) { $_SESSION["glpi_plugin_environment_certificates"] = 1; // Display a menu entry ? if (plugin_certificates_haveRight("certificates", "r")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['certificates']['title'] = PluginCertificatesCertificate::getTypeName(2); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['certificates']['page'] = '/plugins/certificates/front/certificate.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['certificates']['links']['search'] = '/plugins/certificates/front/certificate.php'; } if (plugin_certificates_haveRight("certificates", "w")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['certificates']['links']['add'] = '/plugins/certificates/front/certificate.form.php'; $PLUGIN_HOOKS['use_massive_action']['certificates'] = 1; } } else { // Display a menu entry ? if (plugin_certificates_haveRight("certificates", "r")) { $PLUGIN_HOOKS['menu_entry']['certificates'] = 'front/certificate.php'; $PLUGIN_HOOKS['submenu_entry']['certificates']['search'] = 'front/certificate.php'; } if (plugin_certificates_haveRight("certificates", "w")) { $PLUGIN_HOOKS['submenu_entry']['certificates']['add'] = 'front/certificate.form.php?new=1'; $PLUGIN_HOOKS['use_massive_action']['certificates'] = 1; } } if (class_exists('PluginCertificatesCertificate_Item')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['certificates'] = array('Profile' => array('PluginCertificatesProfile', 'purgeProfiles')); } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['certificates'] = 'plugin_certificates_postinit'; } }
function plugin_init_webapplications() { global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['webapplications'] = true; //load changeprofile function $PLUGIN_HOOKS['change_profile']['webapplications'] = array('PluginWebapplicationsProfile', 'initProfile'); $PLUGIN_HOOKS['assign_to_ticket']['webapplications'] = true; if (class_exists('PluginWebapplicationsWebapplication_Item')) { // only if plugin activated $PLUGIN_HOOKS['plugin_datainjection_populate']['webapplications'] = 'plugin_datainjection_populate_webapplications'; } // Params : plugin name - string type - number - class - table - form page Plugin::registerClass('PluginWebapplicationsWebapplication', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'contract_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'addtabon' => 'Supplier')); Plugin::registerClass('PluginWebapplicationsProfile', array('addtabon' => array('Profile'))); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginWebapplicationsWebapplication'); } if (class_exists('PluginCertificatesCertificate')) { PluginCertificatesCertificate::registerType('PluginWebapplicationsWebapplication'); } //if glpi is loaded if (Session::getLoginUserID()) { //if environment plugin is installed $plugin = new Plugin(); if (!$plugin->isActivated('environment') && Session::haveRight("plugin_webapplications", READ)) { $PLUGIN_HOOKS['menu_toadd']['webapplications'] = array('assets' => 'PluginWebapplicationsMenu'); } if (Session::haveRight("plugin_webapplications", UPDATE)) { $PLUGIN_HOOKS['use_massive_action']['webapplications'] = 1; } if (Session::haveRight("plugin_webapplications", READ) || Session::haveRight("config", UPDATE)) { } // Import from Data_Injection plugin // $PLUGIN_HOOKS['migratetypes']['webapplications'] // = 'plugin_datainjection_migratetypes_webapplications'; $PLUGIN_HOOKS['plugin_pdf']['PluginWebapplicationsWebapplication'] = 'PluginWebapplicationsWebapplicationPDF'; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['webapplications'] = 'plugin_webapplications_postinit'; }
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'; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $account = new PluginAccountsAccount(); $account_item = new PluginAccountsAccount_Item(); if (isset($_POST["add"])) { $account->check(-1, 'w', $_POST); $newID = $account->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { $account->check($_POST['id'], 'w'); $account->update($_POST); Html::back(); } else { if (isset($_POST["delete"])) { $account->check($_POST['id'], 'w'); $account->delete($_POST); $account->redirectToList();
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'; Session::checkRight("config", "w"); $plugin = new plugin(); if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "environment", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "accounts"); } $PluginAccountsHash = new PluginAccountsHash(); $account = new PluginAccountsAccount(); if (isset($_POST["update_encrypted_password"]) && isset($_POST["item"])) { foreach ($_POST["upgrade_accounts"] as $key => $val) { foreach ($_POST["item"] as $key2 => $val2) { $encrypted_password = "******" . $key2; $_POST[$encrypted_password] = addslashes($_POST[$encrypted_password]); if (isset($_POST[$encrypted_password]) && $_POST[$encrypted_password]) { $query = "UPDATE `glpi_plugin_accounts_accounts`\n SET `encrypted_password` ='" . $_POST[$encrypted_password] . "'\n WHERE `id` ='" . $key2 . "' ;"; $result = $DB->query($query); $_SESSION['plugin_accounts']['upgrade'][] = $key2; } } } Html::back(); } else { $PluginAccountsHash->getFromDB(1);
(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'; if (!isset($_GET["id"])) { $_GET["id"] = ""; } $account = new PluginAccountsAccount(); $account->checkGlobal(UPDATE); $hashClass = new PluginAccountsHash(); $update = 0; if (countElementsInTable("glpi_plugin_accounts_accounts") > 0) { $update = 1; } if (isset($_POST["add"])) { $hashClass->check(-1, CREATE, $_POST); $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"];
public function showForm($ID, $options = array()) { if (!Session::haveRight("profile", "r")) { return false; } $prof = new Profile(); if ($ID) { $this->getFromDBByProfile($ID); $prof->getFromDB($ID); } $this->showFormHeader($options); echo "<tr class='tab_bg_2'>"; echo "<th colspan='4'>" . sprintf(__('%1$s - %2$s'), __('Rights management', 'accounts'), $prof->fields["name"]) . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . PluginAccountsAccount::getTypeName(2) . ":</td><td>"; Profile::dropdownNoneReadWrite("accounts", $this->fields["accounts"], 1, 1, 1); echo "</td>"; echo "<td>" . __('See accounts of my groups', 'accounts') . ":</td><td>"; Profile::dropdownNoneReadWrite("my_groups", $this->fields["my_groups"], 1, 1, 0); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('See all accounts', 'accounts') . ":</td><td>"; Profile::dropdownNoneReadWrite("all_users", $this->fields["all_users"], 1, 1, 0); echo "</td>"; echo "<td>" . __('Associable items to a ticket') . " - " . PluginAccountsAccount::getTypeName(2) . "</td><td>"; if ($prof->fields['create_ticket']) { Dropdown::showYesNo("open_ticket", $this->fields["open_ticket"]); } else { echo Dropdown::getYesNo(0); } echo "</td>"; echo "</tr>"; echo "<input type='hidden' name='id' value=" . $this->fields["id"] . ">"; $options['candel'] = false; $this->showFormButtons($options); }
function plugin_accounts_MassiveActionsDisplay($options = array()) { $PluginAccountsAccount = new PluginAccountsAccount(); if (in_array($options['itemtype'], PluginAccountsAccount::getTypes(true))) { $PluginAccountsAccount->dropdownAccounts("plugin_accounts_accounts_id"); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>"; } return ""; }
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'; $plugin = new plugin(); if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "assets", "pluginenvironmentdisplay", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "admin", "pluginaccountsmenu"); } } else { Html::helpHeader(PluginAccountsAccount::getTypeName(2)); } $account = new PluginAccountsAccount(); $account->checkGlobal(READ); if ($account->canView()) { if (Session::haveRight("plugin_accounts_see_all_users", 1)) { echo "<div align='center'>"; echo "<a onclick='add_file_modal.dialog(\"open\");' href='#modal_account_content' title='" . __s('Type view') . "'>" . __('Type view', 'accounts') . "</a>"; echo "</div>"; Ajax::createModalWindow('add_file_modal', $CFG_GLPI['root_doc'] . "/plugins/accounts/ajax/accounttree.php", array('title' => __('Type view', 'accounts'), 'width' => 800, 'height' => 400)); } Search::show("PluginAccountsAccount"); } else { Html::displayRightError(); } if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { Html::footer(); } else {
function plugin_accounts_MassiveActions($type) { if (in_array($type, PluginAccountsAccount::getTypes(true))) { return array('PluginAccountsAccount' . MassiveAction::CLASS_ACTION_SEPARATOR . "add_item" => __('Associate to account', 'accounts')); } return array(); }
} $plugin = new Plugin(); if ($plugin->isActivated("accounts")) { Session::checkRight("config", UPDATE); $PluginAccountsHash = new PluginAccountsHash(); $PluginAccountsHash->getFromDB(1); $hash = $PluginAccountsHash->fields["hash"]; $update = 0; if (countElementsInTable("glpi_plugin_accounts_accounts") > 0) { $update = 1; } if (empty($hash)) { if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "assets", "pluginenvironmentdisplay", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "assets", "pluginaccountsmenu", "account"); } if ($_SESSION['glpiactive_entity'] == 0) { if ($update == 1) { echo "<div class='center b'>" . __('Upgrade') . "</div><br><br>"; echo "<div class='center b'>" . __('1. Define the encryption key and create hash', 'accounts') . "</div><br><br>"; $options = array("update" => true, "upgrade" => 1); $PluginAccountsHash->showForm(1, $options); } } else { echo "<div class='center red'>" . __('Go to Root Entity', 'accounts') . "</div>"; } Html::footer(); } } else { Html::header(__('Setup'), '', "config", "plugins");
function plugin_init_webapplications() { global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['webapplications'] = true; //load changeprofile function $PLUGIN_HOOKS['change_profile']['webapplications'] = array('PluginWebapplicationsProfile', 'changeProfile'); $PLUGIN_HOOKS['assign_to_ticket']['webapplications'] = true; if (class_exists('PluginWebapplicationsWebapplication_Item')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['webapplications'] = array('Profile' => array('PluginWebapplicationsProfile', 'purgeProfiles')); $PLUGIN_HOOKS['plugin_datainjection_populate']['webapplications'] = 'plugin_datainjection_populate_webapplications'; } // Params : plugin name - string type - number - class - table - form page Plugin::registerClass('PluginWebapplicationsWebapplication', array('linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'contract_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'addtabon' => 'Supplier')); Plugin::registerClass('PluginWebapplicationsProfile', array('addtabon' => array('Profile'))); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginWebapplicationsWebapplication'); } if (class_exists('PluginCertificatesCertificate')) { PluginCertificatesCertificate::registerType('PluginWebapplicationsWebapplication'); } //if glpi is loaded if (Session::getLoginUserID()) { //if environment plugin is installed if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) { //init $_SESSION for environment using $_SESSION["glpi_plugin_environment_webapplications"] = 1; if (plugin_webapplications_haveRight("webapplications", "r")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['webapplications']['title'] = PluginWebapplicationsWebapplication::getTypeName(2); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['webapplications']['page'] = '/plugins/webapplications/front/webapplication.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['webapplications']['links']['search'] = '/plugins/webapplications/front/webapplication.php'; } if (plugin_webapplications_haveRight("webapplications", "w")) { //redirect link to add webapplications $PLUGIN_HOOKS['submenu_entry']['environment']['options']['webapplications']['links']['add'] = '/plugins/webapplications/front/webapplication.form.php'; //use massiveaction in the plugin $PLUGIN_HOOKS['use_massive_action']['webapplications'] = 1; } //if environment plugin isn't installed } else { // Display a menu entry ? if (plugin_webapplications_haveRight("webapplications", "r")) { //menu entry $PLUGIN_HOOKS['menu_entry']['webapplications'] = 'front/webapplication.php'; //search link $PLUGIN_HOOKS['submenu_entry']['webapplications']['search'] = 'front/webapplication.php'; } if (plugin_webapplications_haveRight("webapplications", "w")) { //add link $PLUGIN_HOOKS['submenu_entry']['webapplications']['add'] = 'front/webapplication.form.php'; //use massiveaction in the plugin $PLUGIN_HOOKS['use_massive_action']['webapplications'] = 1; } } if (plugin_webapplications_haveRight("webapplications", "r") || Session::haveRight("config", "w")) { } // Import from Data_Injection plugin // $PLUGIN_HOOKS['migratetypes']['webapplications'] // = 'plugin_datainjection_migratetypes_webapplications'; $PLUGIN_HOOKS['plugin_pdf']['PluginWebapplicationsWebapplication'] = 'PluginWebapplicationsWebapplicationPDF'; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['webapplications'] = 'plugin_webapplications_postinit'; }
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'; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $account = new PluginAccountsAccount(); $account_item = new PluginAccountsAccount_Item(); if (isset($_POST["add"])) { $account->check(-1, CREATE, $_POST); $newID = $account->add($_POST); if ($_SESSION['glpibackcreated']) { Html::redirect($account->getFormURL() . "?id=" . $newID); } Html::back(); } else { if (isset($_POST["update"])) { $account->check($_POST['id'], UPDATE); $account->update($_POST); Html::back(); } else { if (isset($_POST["delete"])) {
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!Session::haveRight("plugin_accounts", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && Session::haveRight("plugin_accounts_my_groups", 1)) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!Session::haveRight("plugin_accounts_see_all_users", 1)) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (Session::haveRight('plugin_accounts', READ) && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } PluginAccountsAccount::dropdownAccount(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); echo "<tr><th colspan='" . (8 + $colsup) . "'>"; if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { _e('Encryption key', 'accounts'); echo "<input type='password' name='aeskey' id='aeskey' autocomplete='off'>"; } else { echo Html::hidden('aeskey', array('value' => $aeskey->fields["name"], 'id' => 'aeskey', 'autocomplete' => 'off')); } } else { echo __('Encryption key', 'accounts'); echo "<div class='red'>"; echo $alert; echo "</div>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo "<input type='text' id='hidden_password{$accountID}' value='' size='30' >"; echo Html::scriptBlock("\n if (!check_hash()) {\n \$('#hidden_password{$accountID}')\n .after('" . __('Wrong encryption key', 'accounts') . "')\n .remove();\n } else {\n decrypt_password('{$accountID}');\n }\n "); } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypt_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit'>"; echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo Html::scriptBlock("\$(document).on('click', '#decrypt_link{$accountID}', function(event) {\n if (!check_hash()) {\n alert('" . __('Wrong encryption key', 'accounts') . "');\n } else {\n var decrypted_password = decrypt_password('{$accountID}');\n \$('#decrypt_link{$accountID}')\n .after(decrypted_password)\n .remove();\n }\n });"); } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; echo Html::hidden('good_hash', array('value' => $hash, 'id' => 'good_hash')); if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
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); } } }
} $plugin = new Plugin(); if ($plugin->isActivated("accounts")) { Session::checkRight("config", "w"); $PluginAccountsHash = new PluginAccountsHash(); $PluginAccountsHash->getFromDB(1); $hash = $PluginAccountsHash->fields["hash"]; $update = 0; if (countElementsInTable("glpi_plugin_accounts_accounts") > 0) { $update = 1; } if (empty($hash)) { if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "environment", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "accounts"); } if ($_SESSION['glpiactive_entity'] == 0) { if ($update == 1) { echo "<div class='center b'>" . __('Upgrade') . "</div><br><br>"; echo "<div class='center b'>" . __('1. Define the encryption key and create hash', 'accounts') . "</div><br><br>"; $options = array("update" => true, "upgrade" => 1); $PluginAccountsHash->showForm(1, $options); } } else { echo "<div class='center red'>" . __('Go to Root Entity', 'accounts') . "</div>"; } Html::footer(); } } else { Html::header(__('Setup'), '', "config", "plugins");
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'; $plugin = new plugin(); if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "environment", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "accounts"); } } else { Html::helpHeader(PluginAccountsAccount::getTypeName(2)); } $account = new PluginAccountsAccount(); $account->checkGlobal("r"); if ($account->canView()) { if (plugin_accounts_haveRight("all_users", "r")) { echo "<div align='center'><script type='text/javascript'>"; echo "cleanhide('modal_account_content');"; echo "var account_window=new Ext.Window({\n layout:'fit',\n width:800,\n height:400,\n closeAction:'hide',\n modal: true,\n autoScroll: true,\n title: \"" . __('Type view', 'accounts') . "\",\n autoLoad: '" . $CFG_GLPI['root_doc'] . "/plugins/accounts/ajax/accounttree.php'\n });"; echo "</script>"; echo "<a onclick='account_window.show();' href='#modal_account_content' title='" . __s('Type view') . "'>" . __('Type view', 'accounts') . "</a>"; echo "</div>"; } Search::show("PluginAccountsAccount"); } else { Html::displayRightError(); } if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
function plugin_init_appliances() { global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['appliances'] = true; // Params : plugin name - string type - number - attributes Plugin::registerClass('PluginAppliancesAppliance', array('linkuser_types' => true, 'linkuser_tech_types' => true, 'linkgroup_types' => true, 'linkgroup_tech_types' => true, 'infocom_types' => true, 'document_types' => true, 'contract_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true)); Plugin::registerClass('PluginAppliancesProfile', array('addtabon' => 'Profile')); Plugin::registerClass('PluginAppliancesEnvironment'); Plugin::registerClass('PluginAppliancesApplianceType'); Plugin::registerClass('PluginAppliancesAppliance_Item'); Plugin::registerClass('PluginAppliancesOptvalue'); Plugin::registerClass('PluginAppliancesOptvalue_Item'); Plugin::registerClass('PluginAppliancesRelation'); if (class_exists('PluginAccountsAccount')) { PluginAccountsAccount::registerType('PluginAppliancesAppliance'); } if (class_exists('PluginCertificatesCertificate')) { PluginCertificatesCertificate::registerType('PluginAppliancesAppliance'); } if (class_exists('PluginDatabasesDatabase')) { PluginDatabasesDatabase::registerType('PluginAppliancesAppliance'); } if (class_exists('PluginDomainsDomain')) { PluginDomainsDomain::registerType('PluginAppliancesAppliance'); } if (class_exists('PluginWebapplicationsWebapplication')) { PluginWebapplicationsWebapplication::registerType('PluginAppliancesAppliance'); } // Define the type for which we know how to generate PDF, need : $PLUGIN_HOOKS['plugin_pdf']['PluginAppliancesAppliance'] = 'PluginAppliancesAppliancePDF'; $PLUGIN_HOOKS['migratetypes']['appliances'] = 'plugin_datainjection_migratetypes_appliances'; $PLUGIN_HOOKS['change_profile']['appliances'] = array('PluginAppliancesProfile', 'select'); $PLUGIN_HOOKS['assign_to_ticket']['appliances'] = true; if (class_exists('PluginAppliancesAppliance')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['appliances'] = array('Profile' => array('PluginAppliancesProfile', 'cleanProfile')); $PLUGIN_HOOKS['item_clone']['appliances'] = array('Profile' => array('PluginAppliancesProfile', 'cloneProfile')); $PLUGIN_HOOKS['plugin_datainjection_populate']['appliances'] = 'plugin_datainjection_populate_appliances'; } if (isset($_SESSION["glpiID"])) { if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) { $_SESSION["glpi_plugin_environment_appliances"] = 1; // Display a menu entry ? if (plugin_appliances_haveRight("appliance", "r")) { $PLUGIN_HOOKS['menu_entry']['appliances'] = false; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['appliances']['title'] = _n('Appliance', 'Appliances', 2, 'appliances'); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['appliances']['page'] = '/plugins/appliances/front/appliance.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['appliances']['links']['search'] = '/plugins/appliances/front/appliance.php'; } if (plugin_appliances_haveRight("appliance", "w")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['appliances']['links']['add'] = '/plugins/appliances/front/appliance.form.php'; $PLUGIN_HOOKS['use_massive_action']['appliances'] = 1; } } else { // Display a menu entry ? if (plugin_appliances_haveRight("appliance", "r")) { $PLUGIN_HOOKS['menu_entry']['appliances'] = 'front/appliance.php'; $PLUGIN_HOOKS['submenu_entry']['appliances']['search'] = 'front/appliance.php'; } if (plugin_appliances_haveRight("appliance", "w")) { $PLUGIN_HOOKS['submenu_entry']['appliances']['add'] = 'front/appliance.form.php?new=1'; $PLUGIN_HOOKS['use_massive_action']['appliances'] = 1; } } } // Import from Data_Injection plugin $PLUGIN_HOOKS['data_injection']['appliances'] = "plugin_appliances_data_injection_variables"; // Import webservice $PLUGIN_HOOKS['webservices']['appliances'] = 'plugin_appliances_registerMethods'; // End init, when all types are registered $PLUGIN_HOOKS['post_init']['appliances'] = 'plugin_appliances_postinit'; }
------------------------------------------------------------------------- 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'; $account = new PluginAccountsAccount(); $account->checkGlobal("w"); $plugin = new plugin(); if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "environment", "hash"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "plugins", "accounts", "hash"); } Search::show("PluginAccountsHash"); Html::footer();
https://forge.indepnet.net/projects/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/>. -------------------------------------------------------------------------- */ $AJAX_INCLUDE = 1; include '../../../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkLoginUser(); if (!isset($_GET['target'])) { $_GET['target'] = $CFG_GLPI['root_doc'] . "/plugins/accounts/front/account.php"; } PluginAccountsAccount::showSelector($_GET['target']); Html::ajaxFooter();
https://forge.indepnet.net/projects/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'; Session::checkRight("config", UPDATE); $plugin = new plugin(); if ($plugin->isActivated("environment")) { Html::header(PluginAccountsAccount::getTypeName(2), '', "assets", "pluginenvironmentdisplay", "accounts"); } else { Html::header(PluginAccountsAccount::getTypeName(2), '', "admin", "pluginaccountsmenu", "hash"); } Search::show("PluginAccountsAesKey"); Html::footer();
function plugin_init_accounts() { global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['accounts'] = true; $PLUGIN_HOOKS['change_profile']['accounts'] = array('PluginAccountsProfile', 'changeProfile'); $PLUGIN_HOOKS['assign_to_ticket']['accounts'] = true; if (Session::getLoginUserID()) { // Params : plugin name - string type - number - attributes Plugin::registerClass('PluginAccountsAccount', array('linkgroup_types' => true, 'linkuser_types' => true, 'linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'document_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true, 'notificationtemplates_types' => true, 'header_types' => true)); Plugin::registerClass('PluginAccountsConfig', array('addtabon' => 'CronTask')); Plugin::registerClass('PluginAccountsProfile', array('addtabon' => 'Profile')); if (isset($_SESSION["glpi_plugin_environment_installed"]) && $_SESSION["glpi_plugin_environment_installed"] == 1) { $_SESSION["glpi_plugin_environment_accounts"] = 1; if (plugin_accounts_haveRight("accounts", "r")) { $PLUGIN_HOOKS['helpdesk_menu_entry']['accounts'] = '/front/account.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['accounts']['title'] = PluginAccountsAccount::getTypeName(2); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['accounts']['page'] = '/plugins/accounts/front/account.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['accounts']['links']['search'] = '/plugins/accounts/front/account.php'; $PLUGIN_HOOKS['redirect_page']['accounts'] = "front/account.form.php"; } if (plugin_accounts_haveRight("accounts", "w")) { $PLUGIN_HOOKS['submenu_entry']['environment']['options']['accounts']['links']['add'] = '/plugins/accounts/front/account.form.php'; $PLUGIN_HOOKS['use_massive_action']['accounts'] = 1; if (Session::haveRight("config", "w") && plugin_accounts_haveRight("accounts", "w")) { //TODO check it $PLUGIN_HOOKS['submenu_entry']['environment']['options']['accounts']['links']["<img src='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/pics/cadenas.png' title='" . _n('Encryption key', 'Encryption keys', 2) . "' alt='" . _n('Encryption key', 'Encryption keys', 2, 'accounts') . "'>"] = '/plugins/accounts/front/hash.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['hash']['page'] = '/plugins/accounts/front/hash.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['hash']['title'] = _n('Encryption key', 'Encryption keys', 2, 'accounts'); $PLUGIN_HOOKS['submenu_entry']['environment']['options']['hash']['links']['add'] = '/plugins/accounts/front/hash.form.php'; $PLUGIN_HOOKS['submenu_entry']['environment']['options']['hash']['links']['search'] = '/plugins/accounts/front/hash.php'; } } } else { // Display a menu entry ? if (plugin_accounts_haveRight("accounts", "r")) { $PLUGIN_HOOKS['menu_entry']['accounts'] = 'front/account.php'; $PLUGIN_HOOKS['helpdesk_menu_entry']['accounts'] = '/front/account.php'; $PLUGIN_HOOKS['submenu_entry']['accounts']['search'] = 'front/account.php'; $PLUGIN_HOOKS['redirect_page']['accounts'] = "front/account.form.php"; } if (plugin_accounts_haveRight("accounts", "w")) { $PLUGIN_HOOKS['submenu_entry']['accounts']['add'] = 'front/account.form.php'; $PLUGIN_HOOKS['header_entry']['accounts'] = array(__('New account') => '/plugins/accounts/front/account.form.php'); $PLUGIN_HOOKS['header_action']['accounts'] = 'plugin_accounts_header_action'; $PLUGIN_HOOKS['use_massive_action']['accounts'] = 1; if (Session::haveRight("config", "w") && plugin_accounts_haveRight("accounts", "w")) { $PLUGIN_HOOKS['submenu_entry']['accounts']["<img src='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/pics/cadenas.png' title='" . _n('Encryption key', 'Encryption keys', 2) . "' alt='" . _n('Encryption key', 'Encryption keys', 2, 'accounts') . "'>"] = 'front/hash.php'; $PLUGIN_HOOKS['submenu_entry']['accounts']['options']['hash']['page'] = '/plugins/accounts/front/hash.php'; $PLUGIN_HOOKS['submenu_entry']['accounts']['options']['hash']['title'] = _n('Encryption key', 'Encryption keys', 2, 'accounts'); $PLUGIN_HOOKS['submenu_entry']['accounts']['options']['hash']['links']['add'] = '/plugins/accounts/front/hash.form.php'; $PLUGIN_HOOKS['submenu_entry']['accounts']['options']['hash']['links']['search'] = '/plugins/accounts/front/hash.php'; } } } //Clean Plugin on Profile delete if (class_exists('PluginAccountsAccount_Item')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['accounts'] = array('Profile' => array('PluginAccountsProfile', 'purgeProfiles')); $PLUGIN_HOOKS['plugin_datainjection_populate']['accounts'] = 'plugin_datainjection_populate_accounts'; } // Add specific files to add to the header : javascript or css //$PLUGIN_HOOKS['add_javascript']['example']="example.js"; $PLUGIN_HOOKS['add_javascript']['accounts'] = "lightcrypt.js"; $PLUGIN_HOOKS['migratetypes']['accounts'] = 'plugin_datainjection_migratetypes_accounts'; // End init, when all types are registered $PLUGIN_HOOKS['post_init']['accounts'] = 'plugin_accounts_postinit'; } }
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_accounts_haveRight('accounts', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && plugin_accounts_haveRight("my_groups", "r")) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!plugin_accounts_haveRight("all_users", "r")) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_accounts_haveRight('accounts', 'r') && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } $account->dropdownAccounts("plugin_accounts_accounts_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; _e('Encryption key', 'accounts'); echo "<input type='password' name='aescrypted_key' id= 'aescrypted_key' autocomplete='off'>"; echo "</th></tr>"; } } else { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; echo __('Encryption key', 'accounts') . "<div class='red'>"; echo $alert; echo "</div>"; echo "</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo "<input type='hidden' name='aeskey' id= 'aeskey'\n value='" . $aeskey->fields["name"] . "' class='' autocomplete='off'>"; echo "<input type='hidden' autocomplete='off'\n name='encrypted_password\${$accountID}' value='" . $data["encrypted_password"] . "'>"; echo "<input type='text' name='hidden_password\${$accountID}' value='' size='30' >"; echo "<script language='javascript'>\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aeskey\").value));\n if (hash != good_hash) {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=\"" . __s('Wrong encryption key', 'accounts') . "\";\n } else {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=AESDecryptCtr(document.getElementsByName(\"encrypted_password\${$accountID}\").\n item(0).value,SHA256(document.getElementById(\"aeskey\").value), 256)};</script>"; } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypte_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit' onclick='return false;'>"; echo "<script type='text/javascript'>\n Ext.get('decrypte_link{$accountID}').on('click', function () {\n\n Ext.Ajax.request({\n url: '../plugins/accounts/ajax/get_new_crsf_token.php',\n success: function(response, opts) {\n var token = response.responseText;\n Ext.select('#account_form input[name=_glpi_csrf_token]')\n .set({'value': token});\n\n },\n failure: function(response, opts) {\n console.log('server-side failure with status code ' + response.status);\n }\n });\n\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aescrypted_key\").value));\n if (hash != good_hash) {\n alert(\"" . __('Wrong encryption key', 'accounts') . "\");\n return false;\n };\n alert(AESDecryptCtr(\"" . $data['encrypted_password'] . "\",\n SHA256(document.getElementById(\"aescrypted_key\").value),\n 256));\n\n callAjax(\"{$url}\",\n \"{$accountID}\" ,\n document.getElementsByName(\"name\").item(0).value,\n document.getElementsByName(\"_glpi_csrf_token\").item(0).value);\n\n });\n </script>"; } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }