Beispiel #1
0
function plugin_fields_install()
{
    global $CFG_GLPI;
    set_time_limit(900);
    ini_set('memory_limit', '2048M');
    $plugin_fields = new Plugin();
    $plugin_fields->getFromDBbyDir('fields');
    $version = $plugin_fields->fields['version'];
    $classesToInstall = array('PluginFieldsDropdown', 'PluginFieldsField', 'PluginFieldsContainer', 'PluginFieldsContainer_Field', 'PluginFieldsValue', 'PluginFieldsProfile', 'PluginFieldsMigration');
    $migration = new Migration($version);
    echo "<center>";
    echo "<table class='tab_cadre_fixe'>";
    echo "<tr><th>" . __("MySQL tables installation", "fields") . "<th></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td align='center'>";
    foreach ($classesToInstall as $class) {
        if ($plug = isPluginItemType($class)) {
            $dir = GLPI_ROOT . "/plugins/fields/inc/";
            $item = strtolower($plug['class']);
            if (file_exists("{$dir}{$item}.class.php")) {
                include_once "{$dir}{$item}.class.php";
                if (!call_user_func(array($class, 'install'), $migration, $version)) {
                    return false;
                }
            }
        }
    }
    echo "</td>";
    echo "</tr>";
    echo "</table></center>";
    return true;
}
 /**
  * Return all injectable types
  *
  * @param $only_primary    return only primary types (false by default)
  *
  * @return an array which contains array(itemtype => itemtype name)
  **/
 static function getItemtypes($only_primary = false)
 {
     global $INJECTABLE_TYPES;
     getTypesToInject();
     $plugin = new Plugin();
     $values = array();
     foreach ($INJECTABLE_TYPES as $type => $from) {
         $injectionclass = new $type();
         if (class_exists($type) && (!$only_primary || $only_primary && $injectionclass->isPrimaryType())) {
             $instance = new $type();
             //If user has no right to create an object of this type, do not display type in the list
             if (!$instance->canCreate()) {
                 continue;
             }
             $typename = get_parent_class($type);
             $name = '';
             if ($from != 'datainjection') {
                 $plugin->getFromDBbyDir($from);
                 $name = $plugin->getName() . ': ';
             }
             $name .= call_user_func(array($type, 'getTypeName'));
             $values[$typename] = $name;
         }
     }
     asort($values);
     return $values;
 }
 static function methodTest($params, $protocol)
 {
     global $PLUGIN_HOOKS;
     if (isset($params['help'])) {
         return array('help' => 'bool,optional');
     }
     $resp = array('glpi' => GLPI_VERSION);
     $plugin = new Plugin();
     foreach ($PLUGIN_HOOKS['webservices'] as $name => $fct) {
         if ($plugin->getFromDBbyDir($name)) {
             $resp[$name] = $plugin->fields['version'];
         }
     }
     return $resp;
 }
Beispiel #4
0
    function PluginSccmSccmxml($data)
    {
        $plug = new Plugin();
        $plug->getFromDBbyDir("sccm");
        $this->data = $data;
        $this->device_id = $data['CSD-MachineID'];
        $this->agentbuildnumber = "SCCM-v" . $plug->fields['version'];
        $SXML = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<REQUEST>
   <CONTENT>
      <VERSIONCLIENT>{$this->agentbuildnumber}</VERSIONCLIENT>
   </CONTENT>
   <DEVICEID>{$this->device_id}</DEVICEID>
   <TOKEN>SOC_{$this->device_id}</TOKEN>
   <QUERY>INVENTORY</QUERY>
   <PROLOG></PROLOG>
</REQUEST>
XML;
        $this->sxml = new SimpleXMLElement($SXML);
    }
    $migration->displayWarning("***** Install process of plugin TIMELINETICKET *****");
} else {
    $migration->displayWarning("***** Update process of plugin TIMELINETICKET *****");
}
$migration->displayWarning("Current Timelineticket version: {$current_version}");
$migration->displayWarning("Version to update: " . PLUGIN_TIMELINETICKET_VERSION);
// To prevent problem of execution time
ini_set("max_execution_time", "0");
ini_set("memory_limit", "-1");
$mess = '';
if ($current_version != PLUGIN_TIMELINETICKET_VERSION and $current_version != '0') {
    $mess = "Update done.";
} else {
    if ($current_version == PLUGIN_TIMELINETICKET_VERSION) {
        $mess = "No migration needed.";
    } else {
        $mess = "installation done.";
    }
}
$plugin->getFromDBbyDir("timelineticket");
$plugin->install($plugin->fields['id']);
plugin_timelineticket_install();
$migration->displayWarning($mess);
$plugin->load("timelineticket");
$plugin->activate($plugin->fields['id']);
$plugin->load("timelineticket");
if (in_array('--optimize', $_SERVER['argv'])) {
    $migration->displayTitle("Optimizing tables");
    DBmysql::optimize_tables($migration);
    $migration->displayWarning("Optimize done.");
}
 function saveDatas($params)
 {
     global $DB;
     $tasks_id = $params['tasks_id'];
     $tasks = json_decode($params['tasks']);
     //remove old jobs from task
     $query = "DELETE FROM " . $this->getTable() . "\n      WHERE plugin_fusioninventory_deploytasks_id = '" . $tasks_id . "'";
     $res = $DB->query($query);
     //get plugin id
     $plug = new Plugin();
     $plug->getFromDBbyDir('fusinvdeploy');
     $plugins_id = $plug->getField('id');
     //insert new rows
     $sql_tasks = array();
     $i = 0;
     foreach ($tasks as $task) {
         $task = get_object_vars($task);
         //encode action and definition
         //$action = exportArrayToDB(array(array(
         //    $task['action_type'] => $task['action_selection'])));
         $action = exportArrayToDB($task['action']);
         $definition = exportArrayToDB(array(array('PluginFusioninventoryDeployPackage' => $task['package_id'])));
         $sql_tasks[] = "INSERT INTO " . $this->getTable() . "\n         (\n            plugin_fusioninventory_deploytasks_id, name, date_creation, entities_id,\n            plugins_id, method, definition, action,\n            retry_nb, retry_time, periodicity_type, periodicity_count\n         ) VALUES (\n            '{$tasks_id}', 'job_" . $tasks_id . "_{$i}', NOW(), '0',\n            '{$plugins_id}', '" . $task['method'] . "', '{$definition}', '{$action}',\n            '" . $task['retry_nb'] . "', '" . $task['retry_time'] . "', 'minutes', '0'\n         )";
         $i++;
     }
     foreach ($sql_tasks as $query) {
         $res = $DB->query($query);
     }
 }
function plugin_init_fusioninventory()
{
    global $PLUGIN_HOOKS, $CFG_GLPI;
    $PLUGIN_HOOKS['csrf_compliant']['fusioninventory'] = TRUE;
    $Plugin = new Plugin();
    $moduleId = 0;
    if (isset($_SESSION['glpi_use_mode'])) {
        $debug_mode = $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE;
    } else {
        $debug_mode = false;
    }
    if ($Plugin->isActivated('fusioninventory')) {
        // check if plugin is active
        // Register classes into GLPI plugin factory
        Plugin::registerClass('PluginFusioninventoryAgent', array('addtabon' => array('Computer', 'Printer', 'NetworkEquipment', 'PluginFusioninventoryCredentialIp')));
        Plugin::registerClass('PluginFusioninventoryAgentmodule');
        Plugin::registerClass('PluginFusioninventoryConfig');
        Plugin::registerClass('PluginFusioninventoryTask', array('addtabon' => array('Computer', 'Printer', 'NetworkEquipment', 'PluginFusioninventoryCredentialIp')));
        Plugin::registerClass('PluginFusioninventoryTaskjob', array('addtabon' => array('PluginFusioninventoryTask')));
        Plugin::registerClass('PluginFusioninventoryTaskjobstate', array('addtabon' => array('PluginFusioninventoryTask')));
        Plugin::registerClass('PluginFusioninventoryUnmanaged');
        Plugin::registerClass('PluginFusioninventoryModule');
        Plugin::registerClass('PluginFusioninventoryProfile', array('addtabon' => array('Profile')));
        Plugin::registerClass('PluginFusioninventoryEntity', array('addtabon' => array('Entity')));
        Plugin::registerClass('PluginFusioninventorySetup');
        Plugin::registerClass('PluginFusioninventoryIPRange');
        Plugin::registerClass('PluginFusioninventoryIPRange_ConfigSecurity', array('addtabon' => 'PluginFusioninventoryIPRange'));
        Plugin::registerClass('PluginFusioninventoryCredential');
        Plugin::registerClass('PluginFusioninventoryTimeslot');
        Plugin::registerClass('PluginFusioninventoryLock', array('addtabon' => array('Computer', 'Printer', 'NetworkEquipment')));
        Plugin::registerClass('PluginFusioninventoryInventoryComputerAntivirus', array('addtabon' => array('Computer')));
        Plugin::registerClass('PluginFusioninventoryInventoryComputerComputer', array('addtabon' => array('Computer')));
        Plugin::registerClass('PluginFusioninventoryInventoryComputerInventory');
        Plugin::registerClass('PluginFusioninventoryInventoryComputerStorage', array('addtabon' => array('Computer')));
        Plugin::registerClass('PluginFusioninventoryCollect');
        Plugin::registerClass('PluginFusioninventoryCollect_Registry', array('addtabon' => array('PluginFusioninventoryCollect')));
        Plugin::registerClass('PluginFusioninventoryCollect_Registry_Content', array('addtabon' => array('PluginFusioninventoryCollect', 'Computer')));
        Plugin::registerClass('PluginFusioninventoryCollect_Wmi', array('addtabon' => array('PluginFusioninventoryCollect')));
        Plugin::registerClass('PluginFusioninventoryCollect_Wmi_Content', array('addtabon' => array('PluginFusioninventoryCollect', 'Computer')));
        Plugin::registerClass('PluginFusioninventoryCollect_File', array('addtabon' => array('PluginFusioninventoryCollect')));
        Plugin::registerClass('PluginFusioninventoryCollect_File_Content', array('addtabon' => array('PluginFusioninventoryCollect', 'Computer')));
        Plugin::registerClass('PluginFusioninventoryComputerLicenseInfo', array('addtabon' => array('Computer')));
        //Classes for rulesengine
        Plugin::registerClass('PluginFusioninventoryInventoryRuleLocation');
        Plugin::registerClass('PluginFusioninventoryInventoryRuleLocationCollection', array('rulecollections_types' => TRUE));
        Plugin::registerClass('PluginFusioninventoryInventoryRuleEntity');
        Plugin::registerClass('PluginFusioninventoryInventoryRuleEntityCollection', array('rulecollections_types' => TRUE));
        Plugin::registerClass('PluginFusioninventoryRulematchedlog', array('addtabon' => array('Computer', 'PluginFusioninventoryAgent', 'PluginFusioninventoryUnmanaged', 'Printer', 'NetworkEquipment')));
        //Classes for rulesengine
        Plugin::registerClass('PluginFusioninventoryInventoryRuleImport');
        Plugin::registerClass('PluginFusioninventoryInventoryRuleImportCollection', array('rulecollections_types' => TRUE));
        Plugin::registerClass('PluginFusioninventoryConstructDevice');
        //Computer arch dictionnary
        Plugin::registerClass('PluginFusioninventoryRuleDictionnaryComputerArch');
        Plugin::registerClass('PluginFusioninventoryRuleDictionnaryComputerArchCollection', array('rulecollections_types' => TRUE));
        array_push($CFG_GLPI["dictionnary_types"], 'PluginFusioninventoryRuleDictionnaryComputerArchCollection');
        // Networkinventory and networkdiscovery
        Plugin::registerClass('PluginFusioninventorySnmpmodel');
        Plugin::registerClass('PluginFusioninventoryNetworkEquipment', array('addtabon' => array('NetworkEquipment')));
        Plugin::registerClass('PluginFusioninventoryPrinter', array('addtabon' => array('Printer')));
        Plugin::registerClass('PluginFusioninventoryPrinterCartridge');
        Plugin::registerClass('PluginFusioninventoryConfigSecurity');
        Plugin::registerClass('PluginFusioninventoryNetworkPortLog', array('addtabon' => array('NetworkPort')));
        Plugin::registerClass('PluginFusinvsnmpAgentconfig');
        Plugin::registerClass('PluginFusioninventoryNetworkPort', array('classname' => 'glpi_networkports'));
        Plugin::registerClass('PluginFusioninventoryStateDiscovery');
        Plugin::registerClass('PluginFusioninventoryPrinterLogReport');
        Plugin::registerClass('PluginFusioninventorySnmpmodelConstructdevice_User', array('addtabon' => array('User')));
        Plugin::registerClass('PluginFusioninventoryDeployGroup');
        Plugin::registerClass('PluginFusioninventoryDeployGroup_Staticdata', array('addtabon' => array('PluginFusioninventoryDeployGroup')));
        Plugin::registerClass('PluginFusioninventoryDeployGroup_Dynamicdata', array('addtabon' => array('PluginFusioninventoryDeployGroup')));
        $CFG_GLPI['glpitablesitemtype']["PluginFusioninventoryPrinterLogReport"] = "glpi_plugin_fusioninventory_printers";
        $CFG_GLPI['glpitablesitemtype']["PluginFusioninventoryComputer"] = "glpi_computers";
        // ##### 3. get informations of the plugin #####
        $Plugin->getFromDBbyDir('fusioninventory');
        $moduleId = $Plugin->fields['id'];
        // Load config
        PluginFusioninventoryConfig::loadCache();
        // ##### 5. Set in session XMLtags of methods #####
        $_SESSION['glpi_plugin_fusioninventory']['xmltags']['WAKEONLAN'] = '';
        $_SESSION['glpi_plugin_fusioninventory']['xmltags']['INVENTORY'] = 'PluginFusioninventoryInventoryComputerInventory';
        $_SESSION['glpi_plugin_fusioninventory']['xmltags']['NETWORKDISCOVERY'] = 'PluginFusioninventoryCommunicationNetworkDiscovery';
        $_SESSION['glpi_plugin_fusioninventory']['xmltags']['NETWORKINVENTORY'] = 'PluginFusioninventoryCommunicationNetworkInventory';
        $PLUGIN_HOOKS['import_item']['fusioninventory'] = array('Computer' => array('Plugin'));
        $CFG_GLPI["specif_entities_tables"][] = 'glpi_plugin_fusioninventory_ipranges';
        $CFG_GLPI["networkport_types"][] = 'PluginFusioninventoryUnmanaged';
        /**
         * Load the relevant javascript/css files only on pages that need them.
         */
        $PLUGIN_HOOKS['add_javascript']['fusioninventory'] = array();
        $PLUGIN_HOOKS['add_css']['fusioninventory'] = array();
        if (strpos($_SERVER['SCRIPT_FILENAME'], "plugins/fusioninventory") != false) {
            $PLUGIN_HOOKS['add_css']['fusioninventory'][] = "css/views.css";
            $PLUGIN_HOOKS['add_css']['fusioninventory'][] = "css/deploy.css";
            array_push($PLUGIN_HOOKS['add_javascript']['fusioninventory'], "lib/d3-3.4.3/d3" . ($debug_mode ? "" : ".min") . ".js", "lib/nvd3/nv.d3" . ($debug_mode ? "" : ".min") . ".js", "lib/expanding/expanding" . ($debug_mode ? "" : ".min") . ".js");
        }
        if (script_endswith("timeslot.form.php")) {
            $PLUGIN_HOOKS['add_javascript']['fusioninventory'][] = "lib/timeslot" . ($debug_mode ? "" : ".min") . ".js";
        }
        if (script_endswith("deploypackage.form.php")) {
            $PLUGIN_HOOKS['add_css']['fusioninventory'][] = "lib/extjs/resources/css/ext-all.css";
            array_push($PLUGIN_HOOKS['add_javascript']['fusioninventory'], "lib/extjs/adapter/ext/ext-base" . ($debug_mode ? "-debug" : "") . ".js", "lib/extjs/ext-all" . ($debug_mode ? "-debug" : "") . ".js", "lib/REDIPS_drag/redips-drag" . ($debug_mode ? "-source" : "-min") . ".js", "lib/REDIPS_drag/drag_table_rows.js", "lib/plusbutton" . ($debug_mode ? "" : ".min") . ".js", "lib/deploy_editsubtype" . ($debug_mode ? "" : ".min") . ".js");
        }
        if (script_endswith("task.form.php") || script_endswith("taskjob.php") || script_endswith("iprange.form.php")) {
            array_push($PLUGIN_HOOKS['add_javascript']['fusioninventory'], "lib/lazy.js-0.4.0/lazy" . ($debug_mode ? "" : ".min") . ".js", "lib/mustache.js-2.0.0/mustache" . ($debug_mode ? "" : ".min") . ".js", "js/taskjobs" . ($debug_mode ? "" : ".min") . ".js");
        }
        if (script_endswith("menu.php")) {
            $PLUGIN_HOOKS['add_javascript']['fusioninventory'][] = "js/stats" . ($debug_mode ? "" : ".min") . ".js";
        }
        if (Session::haveRight('plugin_fusioninventory_configuration', READ) || Session::haveRight('profile', UPDATE)) {
            // Config page
            $PLUGIN_HOOKS['config_page']['fusioninventory'] = 'front/config.form.php' . '?itemtype=pluginfusioninventoryconfig&glpi_tab=1';
        }
        $PLUGIN_HOOKS['autoinventory_information']['fusioninventory'] = array('Computer' => array('PluginFusioninventoryInventoryComputerComputer', 'showInfo'), 'NetworkEquipment' => array('PluginFusioninventoryNetworkEquipment', 'showInfo'), 'Printer' => array('PluginFusioninventoryPrinter', 'showInfo'));
        $PLUGIN_HOOKS['use_massive_action']['fusioninventory'] = 1;
        $PLUGIN_HOOKS['item_add']['fusioninventory'] = array('NetworkPort_NetworkPort' => 'plugin_item_add_fusioninventory', 'NetworkPort' => 'plugin_item_add_fusioninventory');
        $PLUGIN_HOOKS['pre_item_update']['fusioninventory'] = array('Plugin' => 'plugin_pre_item_update_fusioninventory');
        $PLUGIN_HOOKS['item_update']['fusioninventory'] = array('Computer' => 'plugin_item_update_fusioninventory', 'NetworkEquipment' => 'plugin_item_update_fusioninventory', 'Printer' => 'plugin_item_update_fusioninventory', 'Monitor' => 'plugin_item_update_fusioninventory', 'Peripheral' => 'plugin_item_update_fusioninventory', 'Phone' => 'plugin_item_update_fusioninventory', 'NetworkPort' => 'plugin_item_update_fusioninventory', 'PluginFusioninventoryInventoryComputerAntivirus' => array('PluginFusioninventoryInventoryComputerAntivirus', 'addhistory'), 'PluginFusioninventoryLock' => array('PluginFusioninventoryLock', 'deleteLock'));
        $PLUGIN_HOOKS['pre_item_purge']['fusioninventory'] = array('Computer' => 'plugin_pre_item_purge_fusioninventory', 'NetworkPort_NetworkPort' => 'plugin_pre_item_purge_fusioninventory', 'PluginFusioninventoryLock' => array('PluginFusioninventoryLock', 'deleteLock'));
        $p = array('NetworkPort_NetworkPort' => 'plugin_item_purge_fusioninventory', 'PluginFusioninventoryTask' => array('PluginFusioninventoryTask', 'purgeTask'), 'PluginFusioninventoryTaskjob' => array('PluginFusioninventoryTaskjob', 'purgeTaskjob'), 'PluginFusioninventoryUnmanaged' => array('PluginFusioninventoryUnmanaged', 'purgeUnmanaged'), 'NetworkEquipment' => 'plugin_item_purge_fusinvsnmp', 'Printer' => 'plugin_item_purge_fusinvsnmp', 'PluginFusioninventoryUnmanaged' => 'plugin_item_purge_fusinvsnmp');
        $PLUGIN_HOOKS['item_purge']['fusioninventory'] = $p;
        $PLUGIN_HOOKS['item_transfer']['fusioninventory'] = 'plugin_item_transfer_fusioninventory';
        if (Session::haveRight('plugin_fusioninventory_unmanaged', READ)) {
            $PLUGIN_HOOKS["menu_toadd"]['fusioninventory']['assets'] = 'PluginFusioninventoryUnmanaged';
        }
        if (Session::haveRight('plugin_fusioninventory_menu', READ)) {
            $PLUGIN_HOOKS["menu_toadd"]['fusioninventory']['plugins'] = 'PluginFusioninventoryMenu';
        }
        if (isset($_SESSION["glpiname"])) {
            $report_list = array();
            if (Session::haveRight('plugin_fusioninventory_reportprinter', READ)) {
                $report_list["front/printerlogreport.php"] = __('Printed page counter', 'fusioninventory');
            }
            if (Session::haveRight('plugin_fusioninventory_reportnetworkequipment', READ)) {
                $report_list["report/switch_ports.history.php"] = __('Switchs ports history', 'fusioninventory');
                $report_list["report/ports_date_connections.php"] = __('Unused switchs ports', 'fusioninventory');
                $report_list["report/not_queried_recently.php"] = __('Number of days since last inventory', 'fusioninventory');
            }
            if (Session::haveRight('computer', READ)) {
                $report_list["report/computer_last_inventory.php"] = __('Computers not inventoried since xx days', 'fusioninventory');
            }
            $PLUGIN_HOOKS['reports']['fusioninventory'] = $report_list;
            /*
             * Deploy submenu entries
             */
            if (Session::haveRight('plugin_fusioninventory_configuration', READ)) {
                // Config page
                $PLUGIN_HOOKS['submenu_entry']['fusioninventory']['config'] = 'front/config.form.php';
            }
            $PLUGIN_HOOKS['webservices']['fusioninventory'] = 'plugin_fusioninventory_registerMethods';
            // Hack for NetworkEquipment display ports
            if (strstr($_SERVER['PHP_SELF'], '/ajax/common.tabs.php')) {
                if (isset($_GET['_target']) && strstr($_GET['_target'], '/front/networkequipment.form.php') && $_GET['_itemtype'] == 'NetworkEquipment') {
                    if ($_GET['_glpi_tab'] == 'NetworkPort$1') {
                        $_GET['_glpi_tab'] = 'PluginFusioninventoryNetworkEquipment$1';
                    } else {
                        if ($_GET['_glpi_tab'] == 'PluginFusioninventoryNetworkEquipment$1') {
                            $_GET['displaysnmpinfo'] = 1;
                        }
                    }
                }
            }
            // Load nvd3 for printerpage counter graph
            if (strstr($_SERVER['PHP_SELF'], '/front/printer.form.php') || strstr($_SERVER['PHP_SELF'], 'fusioninventory/front/menu.php')) {
                // Add graph javascript
                $PLUGIN_HOOKS['add_javascript']['fusioninventory'] = array_merge($PLUGIN_HOOKS['add_javascript']['fusioninventory'], array("lib/nvd3/lib/d3.v2.min.js", "lib/nvd3/nv.d3.min.js", "lib/nvd3/src/tooltip.js", "lib/nvd3/src/utils.js", "lib/nvd3/src/models/legend.js", "lib/nvd3/src/models/axis.js", "lib/nvd3/src/models/scatter.js", "lib/nvd3/src/models/line.js", "lib/nvd3/src/models/multiBar.js", "lib/nvd3/src/models/multiBarChart.js", "lib/nvd3/src/models/lineChart.js"));
                // Add graph css
                $PLUGIN_HOOKS['add_css']['fusioninventory'] = array_merge($PLUGIN_HOOKS['add_css']['fusioninventory'], array("lib/nvd3/src/nv.d3.css"));
            }
        }
    } else {
        // plugin not active, need $moduleId for uninstall check
        include_once GLPI_ROOT . '/plugins/fusioninventory/inc/module.class.php';
        $moduleId = PluginFusioninventoryModule::getModuleId('fusioninventory');
    }
    // Check for uninstall
    if (isset($_GET['id']) && $_GET['id'] == $moduleId && (isset($_GET['action']) && $_GET['action'] == 'uninstall') && strstr($_SERVER['HTTP_REFERER'], "front/plugin.php")) {
        if (PluginFusioninventoryModule::getAll(TRUE)) {
            Session::addMessageAfterRedirect(__('Other FusionInventory plugins (fusinv...) must be uninstalled before removing the FusionInventory plugin'));
            Html::redirect($CFG_GLPI["root_doc"] . "/front/plugin.php");
            exit;
        }
    }
    // Add unmanaged devices in list of devices with networport
    $CFG_GLPI["netport_types"][] = "PluginFusioninventoryUnmanaged";
}
$migration->displayWarning("Current Monitoring version: {$current_version}");
$migration->displayWarning("Version to update: " . PLUGIN_MONITORING_VERSION);
// To prevent problem of execution time
ini_set("max_execution_time", "0");
ini_set("memory_limit", "-1");
$mess = '';
if ($current_version != PLUGIN_MONITORING_VERSION and $current_version != '0') {
    $mess = "Update needed.";
} else {
    if ($current_version == PLUGIN_MONITORING_VERSION) {
        $mess = "No migration needed.";
    } else {
        $mess = "installation done.";
    }
}
$migration->displayWarning($mess);
$plugin->getFromDBbyDir("monitoring");
print "Installing Plugin...\n";
$plugin->install($plugin->fields['id']);
print "Install Done\n";
print "Activating Plugin...\n";
$plugin->activate($plugin->fields['id']);
print "Activation Done\n";
print "Loading Plugin...\n";
$plugin->load("monitoring");
print "Load Done...\n";
if (in_array('--optimize', $_SERVER['argv'])) {
    $migration->displayTitle(__('Optimizing tables'));
    DBmysql::optimize_tables($migration);
    $migration->displayWarning("Optimize done.");
}
}
$migration->displayWarning($mess);
if ($args['--no-models-update']) {
    define('NO_MODELS_UPDATE', TRUE);
}
if ($args['--force-upgrade']) {
    define('FORCE_UPGRADE', TRUE);
}
if (!is_null($args['--as-user'])) {
    $user = new User();
    $user->getFromDBbyName($args['--as-user']);
    $auth = new Auth();
    $auth->auth_succeded = true;
    $auth->user = $user;
    Session::init($auth);
}
$plugin->getFromDBbyDir("fusioninventory");
print "Installing Plugin...\n";
$plugin->install($plugin->fields['id']);
print "Install Done\n";
print "Activating Plugin...\n";
$plugin->activate($plugin->fields['id']);
print "Activation Done\n";
print "Loading Plugin...\n";
$plugin->load("fusioninventory");
print "Load Done...\n";
if ($args['--optimize']) {
    $migration->displayTitle(__('Optimizing tables'));
    DBmysql::optimize_tables($migration);
    $migration->displayWarning("Optimize done.");
}
 protected function setUp()
 {
     global $CFG_GLPI, $DB;
     $DB = new DB();
     // Force profile in session to SuperAdmin
     $_SESSION['glpiprofiles'] = array('4' => array('entities' => 0));
     $_SESSION['glpi_plugin_fusioninventory_profile']['unmanaged'] = 'w';
     $_SESSION['glpiactiveentities'] = array(0, 1);
     $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
     require GLPI_ROOT . "/inc/includes.php";
     $plugin = new Plugin();
     $DB->connect();
     $plugin->getFromDBbyDir("fusioninventory");
     $plugin->activate($plugin->fields['id']);
     file_put_contents(GLPI_ROOT . "/files/_log/sql-errors.log", '');
     file_put_contents(GLPI_ROOT . "/files/_log/php-errors.log", '');
     $dir = GLPI_ROOT . "/files/_files/_plugins/fusioninventory";
     if (file_exists($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
             if ($object != "." && $object != "..") {
                 if (filetype($dir . "/" . $object) == "dir") {
                 } else {
                     unlink($dir . "/" . $object);
                 }
             }
         }
     }
     include_once GLPI_ROOT . "/inc/timer.class.php";
     // Security of PHP_SELF
     $_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']);
     //      function glpiautoload($classname) {
     //         global $DEBUG_AUTOLOAD, $CFG_GLPI;
     //         static $notfound = array();
     //
     //         // empty classname or non concerted plugin
     //         if (empty($classname) || is_numeric($classname)) {
     //            return FALSE;
     //         }
     //
     //         $dir=GLPI_ROOT . "/inc/";
     //         //$classname="PluginExampleProfile";
     //         if ($plug=isPluginItemType($classname)) {
     //            $plugname=strtolower($plug['plugin']);
     //            $dir=GLPI_ROOT . "/plugins/$plugname/inc/";
     //            $item=strtolower($plug['class']);
     //            // Is the plugin activate ?
     //            // Command line usage of GLPI : need to do a real check plugin activation
     //            if (isCommandLine()) {
     //               $plugin = new Plugin();
     //               if (count($plugin->find("directory='$plugname' AND state=".Plugin::ACTIVATED)) == 0) {
     //                  // Plugin does not exists or not activated
     //                  return FALSE;
     //               }
     //            } else {
     //               // Standard use of GLPI
     //               if (!in_array($plugname, $_SESSION['glpi_plugins'])) {
     //                  // Plugin not activated
     //                  return FALSE;
     //               }
     //            }
     //         } else {
     //            // Is ezComponent class ?
     //            $matches = array();
     //            if (preg_match('/^ezc([A-Z][a-z]+)/', $classname, $matches)) {
     //               include_once(GLPI_EZC_BASE);
     //               ezcBase::autoload($classname);
     //               return TRUE;
     //            } else {
     //               $item=strtolower($classname);
     //            }
     //         }
     //
     //         // No errors for missing classes due to implementation
     //         if (!isset($CFG_GLPI['missingclasses'])
     //                 OR !in_array($item, $CFG_GLPI['missingclasses'])){
     //            if (file_exists("$dir$item.class.php")) {
     //               include_once ("$dir$item.class.php");
     //               if ($_SESSION['glpi_use_mode']==Session::DEBUG_MODE) {
     //                  $DEBUG_AUTOLOAD[]=$classname;
     //               }
     //
     //            } else if (!isset($notfound["$classname"])) {
     //               // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case)
     //               //Toolbox::logInFile('debug', "file $dir$item.class.php not founded trying to load class $classname\n");
     //               trigger_error("GLPI autoload : file $dir$item.class.php not founded trying to load class '$classname'");
     //               $notfound["$classname"] = TRUE;
     //            }
     //         }
     //      }
     //
     //      spl_autoload_register('glpiautoload');
     //      restore_error_handler();
     //      error_reporting(E_ALL | E_STRICT);
     //      ini_set('display_errors', 'On');
     ini_set("memory_limit", "-1");
     ini_set("max_execution_time", "0");
 }
 private function manageTicket($closed = true)
 {
     global $DB, $CFG_GLPI;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.83/";
     $plugin = new Plugin();
     $plugin->getFromDBbyDir("timelineticket");
     $plugin->activate($plugin->fields['id']);
     Plugin::load("timelineticket");
     Session::loadLanguage("en_GB");
     $ticket = new Ticket();
     $group = new Group();
     $group_ticket = new Group_Ticket();
     $GLPIlog = new GLPIlogs();
     $ticket_User = new Ticket_User();
     $_SESSION['plugin_timelineticket_date'] = array();
     $group->add(array('name' => 'grtech1'));
     $group->add(array('name' => 'grtech2'));
     // * 01/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate = array('1' => $_SESSION["glpi_currenttime"]);
     $input = array();
     $input['name'] = 'Pb with the ticket';
     $input['content'] = 'I have a problem with the ticket';
     $tickets_id = $ticket->add($input);
     $GLPIlog->testSQLlogs('01/');
     $GLPIlog->testPHPlogs('01/');
     // * 02/
     sleep(2);
     // * 03/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[3] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('03/');
     $GLPIlog->testPHPlogs('03/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group1');
     $a_db = getAllDatasFromTable('glpi_tickets_users');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'users_id' => '2', 'type' => '1', 'use_notification' => '1', 'alternative_email' => '');
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'users_id' => '2', 'type' => '2', 'use_notification' => '1', 'alternative_email' => '');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to user 2 (glpi)');
     // * 04/
     sleep(2);
     // * 05/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[5] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('05/');
     $GLPIlog->testPHPlogs('05/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], 'May have status waiting');
     // * 06/
     sleep(1);
     // * 07/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[7] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $ticket_User->check($input['id'], 'w');
     $ticket_User->delete($input);
     $input = array();
     $input['id'] = 1;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('07/');
     $GLPIlog->testPHPlogs('07/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $this->assertEquals(array(), $a_db, 'May have no group assigned');
     // * 08/
     sleep(1);
     // * 09/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[9] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('09/');
     $GLPIlog->testPHPlogs('09/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'groups_id' => '2', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group2');
     $ticket->getFromDB(1);
     $this->assertEquals('assign', $ticket->fields['status'], '(09/) Status is assign');
     // * 10/
     sleep(1);
     // * 11/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[11] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 4;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('11/');
     $GLPIlog->testPHPlogs('11/');
     // * 12/
     sleep(1);
     // * 13/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[13] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('13/');
     $GLPIlog->testPHPlogs('13/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(13/)May have always status waiting');
     // * 14/
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('14/');
     $GLPIlog->testPHPlogs('14/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[3] = array('id' => '3', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, '(14/) May have ticket assigned to group1');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(14/) Status is waiting');
     // * 15/
     sleep(2);
     // * 16/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[16] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::ASSIGNED;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('16/');
     $GLPIlog->testPHPlogs('16/');
     // * 17/
     sleep(1);
     // * 18/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[18] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['solution'] = "solution";
     $ticket->update($input);
     $GLPIlog->testSQLlogs('18/');
     $GLPIlog->testPHPlogs('18/');
     $ticket->getFromDB(1);
     $this->assertEquals('solved', $ticket->fields['status'], '(18/) Status is solved');
     if ($closed) {
         // * 19/
         sleep(1);
         // * 20/
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
         $a_storedate[20] = $_SESSION["glpi_currenttime"];
         $fup = new TicketFollowup();
         $input = array();
         $input['tickets_id'] = $tickets_id;
         $input['add_close'] = 'add_close';
         $fup->add($input);
         $GLPIlog->testSQLlogs('20/');
         $GLPIlog->testPHPlogs('20/');
         $ticket->getFromDB(1);
         $this->assertEquals('closed', $ticket->fields['status'], '(19/) Status is closed');
     }
     self::$storedate = $a_storedate;
 }