本文整理汇总了PHP中Computer类的典型用法代码示例。如果您正苦于以下问题:PHP Computer类的具体用法?PHP Computer怎么用?PHP Computer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Computer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
static function getList($agents_id = NULL)
{
global $PF_CONFIG;
if (is_null($agents_id)) {
return array();
}
$pfAgent = new PluginFusioninventoryAgent();
$pfAgent->getFromDB($agents_id);
$agent = $pfAgent->fields;
$results = getAllDatasFromTable('glpi_plugin_fusioninventory_deploymirrors');
if (!isset($agent) || !isset($agent['computers_id'])) {
return array();
}
$computer = new Computer();
$computer->getFromDB($agent['computers_id']);
$mirrors = array();
foreach ($results as $result) {
if ($computer->fields['locations_id'] == $result['locations_id']) {
$mirrors[] = $result['url'];
}
}
//add default mirror (this server) if enabled in config
$entities_id = 0;
if (isset($agent['entities_id'])) {
$entities_id = $agent['entities_id'];
}
if (isset($PF_CONFIG['server_as_mirror']) && (bool) $PF_CONFIG['server_as_mirror'] == TRUE) {
$mirrors[] = PluginFusioninventoryAgentmodule::getUrlForModule('DEPLOY', $entities_id) . "?action=getFilePart&file=";
}
return $mirrors;
}
示例2: AddComputer
/**
* @test
*/
public function AddComputer()
{
global $DB;
$DB->connect();
$date = date('Y-m-d H:i:s');
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION['glpiactive_entity'] = 0;
$_SESSION['glpiactiveentities_string'] = 0;
$_SESSION['glpishowallentities'] = 1;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$a_inventory = $this->computer_inventory;
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
$a_inventory = $pfFormatconvert->replaceids($a_inventory);
$serialized = gzcompress(serialize($a_inventory));
$a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
$this->items_id = $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
$this->assertGreaterThan(0, $this->items_id, FALSE);
$pfiComputerLib->updateComputer($a_inventory, $this->items_id, TRUE);
// To be sure not have 2 same informations
$pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE);
$GLPIlog = new GLPIlogs();
$GLPIlog->testSQLlogs();
$GLPIlog->testPHPlogs();
}
示例3: show
function show()
{
global $DB;
$networkPort = new NetworkPort();
$computer = new Computer();
$pmHostconfig = new PluginMonitoringHostconfig();
// Shinken server
$source_id = $pmHostconfig->getValueAncestor('computers_id', '0');
$switches_id = 0;
$this->a_devices['Computer-' . $source_id] = "SHINKEN";
$a_networkports = $networkPort->find("`itemtype`='Computer'\n AND `items_id`='" . $source_id . "'");
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
if ($networkPort->fields['itemtype'] == 'NetworkEquipment') {
$this->a_devices['NetworkEquipment-' . $networkPort->fields['items_id']] = $this->getState('NetworkEquipment', $networkPort->fields['items_id']);
$this->a_devices_link['NetworkEquipment-' . $networkPort->fields['items_id']]['Computer-' . $source_id] = 1;
$this->getNetworkEquipments($networkPort->fields['items_id']);
$switches_id = $networkPort->fields['items_id'];
}
}
}
$this->addPoint('NetworkEquipment-' . $switches_id);
$computer->getFromDB($source_id);
$this->drawCanvas($computer, array(), array());
}
示例4: testLog
public function testLog()
{
global $DB;
$DB->connect();
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
$computer = new Computer();
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$date = date('Y-m-d H:i:s');
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION['glpiactiveentities_string'] = 0;
$_SESSION['glpishowallentities'] = 1;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$this->a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'SOFTWARES' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer');
$this->a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7D', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux');
$this->a_inventory['processor'] = array(array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400));
$this->a_inventory['memory'] = array(array('size' => 2048, 'serial' => '98F6FF18', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 1), array('size' => 2048, 'serial' => '95F1833E', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 2));
$this->a_inventory['monitor'] = array(array('name' => '', 'serial' => '', 'manufacturers_id' => ''));
$this->a_inventory['networkport'] = array('em0-00:23:18:cf:0d:93' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => '00:23:18:cf:0d:93', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 0, 'ipaddress' => array('192.168.30.198')), 'lo0-' => array('name' => 'lo0', 'virtualdev' => 1, 'mac' => '', 'instantiation_type' => 'NetworkPortLocal', 'subnet' => '', 'ssid' => '', 'gateway' => '', 'netmask' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('::1', 'fe80::1', '127.0.0.1')));
$this->a_inventory['software'] = array('gentiumbasic$$$$110$$$$1$$$$0' => array('name' => 'GentiumBasic', 'version' => 110, 'manufacturers_id' => 1, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'imagemagick$$$$6.8.0.7_1$$$$2$$$$0' => array('name' => 'ImageMagick', 'version' => '6.8.0.7_1', 'manufacturers_id' => 2, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'orbit2$$$$2.14.19$$$$3$$$$0' => array('name' => 'ORBit2', 'version' => '2.14.19', 'manufacturers_id' => 3, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1));
$this->a_inventory = $pfFormatconvert->replaceids($this->a_inventory);
$serialized = gzcompress(serialize($this->a_inventory));
$this->a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
$computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
// truncate glpi_logs
$DB->query('TRUNCATE TABLE `glpi_logs`;');
$this->assertEquals(0, countElementsInTable('glpi_logs'), "Log must be empty (truncate)");
$_SESSION['glpiactive_entity'] = 0;
$pfiComputerLib->updateComputer($this->a_inventory, 1, TRUE);
$a_logs = getAllDatasFromTable('glpi_logs');
foreach ($a_logs as $id => $data) {
unset($data['date_mod']);
$a_logs[$id] = $data;
}
$a_reference = array(1 => array('id' => 1, 'itemtype' => 'Software', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 2 => array('id' => 2, 'itemtype' => 'Software', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 3 => array('id' => 3, 'itemtype' => 'Software', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 4 => array('id' => 4, 'itemtype' => 'SoftwareVersion', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 5 => array('id' => 5, 'itemtype' => 'SoftwareVersion', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 6 => array('id' => 6, 'itemtype' => 'SoftwareVersion', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''));
$this->assertEquals($a_reference, $a_logs, "Log must be 6 " . print_r($a_logs, true));
$DB->query('TRUNCATE `glpi_logs`');
// Update a second time and must not have any new lines in glpi_logs
$pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE);
$a_logs = getAllDatasFromTable('glpi_logs');
$a_reference = array();
$this->assertEquals($a_reference, $a_logs, "Log may be empty at second update " . print_r($a_logs, true));
// * Modify: contact
// * remove a processor
// * Remove a software
$this->a_inventory['Computer']['contact'] = 'root';
unset($this->a_inventory['processor'][3]);
unset($this->a_inventory['software']['orbit2$$$$2.14.19$$$$3$$$$0']);
$DB->query('TRUNCATE `glpi_logs`');
$pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE);
$a_logs = getAllDatasFromTable('glpi_logs');
foreach ($a_logs as $id => $data) {
unset($data['date_mod']);
$a_logs[$id] = $data;
}
$a_reference = array(1 => array('id' => '1', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => '', 'linked_action' => '0', 'user_name' => '', 'id_search_option' => '7', 'old_value' => 'ddurieux', 'new_value' => 'root'), 2 => array('id' => '2', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'DeviceProcessor', 'linked_action' => '3', 'user_name' => '', 'id_search_option' => '0', 'old_value' => 'Core i3 (1)', 'new_value' => ''), 3 => array('id' => '3', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'SoftwareVersion', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'ORBit2 - 2.14.19 (3)', 'new_value' => ''), 4 => array('id' => '4', 'itemtype' => 'SoftwareVersion', 'items_id' => '3', 'itemtype_link' => 'Computer', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'pc (1)', 'new_value' => ''));
$this->assertEquals($a_reference, $a_logs, "May have 5 logs (update contact, remove processor\n and remove a software)");
}
示例5: pdfDevice
static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer)
{
global $DB;
$devtypes = Item_Devices::getDeviceTypes();
$ID = $computer->getField('id');
if (!$computer->can($ID, 'r')) {
return false;
}
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>');
$pdf->setColumnsSize(3, 14, 42, 41);
foreach ($devtypes as $itemtype) {
$devicetypes = new $itemtype();
$specificities = $devicetypes->getSpecificities();
$specif_fields = array_keys($specificities);
$specif_text = implode(',', $specif_fields);
if (!empty($specif_text)) {
$specif_text = " ," . $specif_text . " ";
}
$associated_type = str_replace('Item_', '', $itemtype);
$linktable = getTableForItemType($itemtype);
$fk = getForeignKeyFieldForTable(getTableForItemType($associated_type));
$query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n FROM `" . $linktable . "`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = 'Computer'\n GROUP BY `" . $fk . "`" . $specif_text;
$device = new $associated_type();
foreach ($DB->request($query) as $data) {
if ($device->getFromDB($data[$fk])) {
$spec = $device->getAdditionalFields();
$col4 = '';
if (count($spec)) {
$colspan = 60 / count($spec);
foreach ($spec as $i => $label) {
if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) {
if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) {
$table = getTableNameForForeignKeyField($label["name"]);
$value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]);
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " ");
} else {
$value = $device->fields[$label["name"]];
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " ");
}
} else {
if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) {
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " ");
}
}
}
}
$pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4);
}
}
}
$pdf->displaySpace();
}
示例6: MonitorUniqueSerialimport
/**
* @test
*/
public function MonitorUniqueSerialimport()
{
global $DB;
$DB->connect();
self::restore_database();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfConfig = new PluginFusioninventoryConfig();
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$a_computerinventory = $this->a_computer1;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links)');
// Second try (verify not create a second same monitor)
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (2)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (2)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (2)');
// Second computer with same monitor
$a_computerinventory = $this->a_computer2;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'Second computer');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'Second computer (links)');
// Retry first computer without monitor
$a_computerinventory = $this->a_computer1;
$a_computerinventory['monitor'] = array();
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (3)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (3)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (3)');
// * Retry first computer with monitor
$a_computerinventory = $this->a_computer1;
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (4)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (4)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (4)');
$this->assertEquals(0, countElementsInTable('glpi_computers_items', 'itemtype="Monitor" AND `id` > 3'), 'First computer (number id of links recreated) (4)');
}
示例7: pdfForComputer
static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
{
global $DB;
$ID = $item->getField('id');
// From ComputerVirtualMachine::showForComputer()
$virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}'");
$pdf->setColumnsSize(100);
if (count($virtualmachines)) {
$pdf->displayTitle("<b>" . __('List of virtual machines') . "</b>");
$pdf->setColumnsSize(20, 8, 8, 8, 25, 8, 8, 15);
$pdf->setColumnsAlign('left', 'center', 'center', 'center', 'left', 'right', 'right', 'left');
$typ = explode(' ', __('Virtualization system'));
$sys = explode(' ', __('Virtualization model'));
$sta = explode(' ', __('State of the virtual machine'));
$pdf->displayTitle(__('Name'), $typ[0], $sys[0], $sta[0], __('UUID'), __('CPU'), __('Mio'), __('Machine'));
foreach ($virtualmachines as $virtualmachine) {
$name = '';
if ($link_computer = ComputerVirtualMachine::findVirtualMachine($virtualmachine)) {
$computer = new Computer();
if ($computer->getFromDB($link_computer)) {
$name = $computer->getName();
}
}
$pdf->displayLine($virtualmachine['name'], Html::clean(Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id'])), $virtualmachine['uuid'], $virtualmachine['vcpu'], Html::clean(Html::formatNumber($virtualmachine['ram'], false, 0)), $name);
}
} else {
$pdf->displayTitle("<b>" . __('No virtual machine associated with the computer') . "</b>");
}
// From ComputerVirtualMachine::showForVirtualMachine()
if ($item->fields['uuid']) {
$where = "`uuid`" . ComputerVirtualMachine::getUUIDRestrictRequest($item->fields['uuid']);
$hosts = getAllDatasFromTable('glpi_computervirtualmachines', $where);
if (count($hosts)) {
$pdf->setColumnsSize(100);
$pdf->displayTitle("<b>" . __('List of host machines') . "</b>");
$pdf->setColumnsSize(26, 37, 37);
$pdf->displayTitle(__('Name'), __('Operating system'), __('Entity'));
$computer = new Computer();
foreach ($hosts as $host) {
if ($computer->getFromDB($host['computers_id'])) {
$pdf->displayLine($computer->getName(), Html::clean(Dropdown::getDropdownName('glpi_operatingsystems', $computer->getField('operatingsystems_id'))), Html::clean(Dropdown::getDropdownName('glpi_entities', $computer->getEntityID())));
}
}
}
}
$pdf->displaySpace();
}
示例8: prepareDB
/**
* @test
*/
public function prepareDB()
{
global $DB;
$DB->connect();
$computer = new Computer();
$pfAgent = new PluginFusioninventoryAgent();
$pfTask = new PluginFusioninventoryTask();
$pfTaskjob = new PluginFusioninventoryTaskjob();
$pfIPRange = new PluginFusioninventoryIPRange();
// Create computers + agents
$input = array('entities_id' => 0, 'name' => 'computer1');
$computers_id = $computer->add($input);
$input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
$pfAgent->add($input);
$input = array('entities_id' => 0, 'name' => 'computer2');
$computers_id = $computer->add($input);
$input = array('entities_id' => 0, 'name' => 'computer2', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer2', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
$pfAgent->add($input);
$input = array('entities_id' => 0, 'name' => 'computer3');
$computers_id = $computer->add($input);
$input = array('entities_id' => 0, 'name' => 'computer3', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer3', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
$pfAgent->add($input);
// Add IPRange
$input = array('entities_id' => 0, 'name' => 'Office', 'ip_start' => '10.0.0.1', 'ip_end' => '10.0.0.254');
$ipranges_id = $pfIPRange->add($input);
$input = array('entities_id' => 0, 'name' => 'Office2', 'ip_start' => '10.0.2.1', 'ip_end' => '10.0.2.254');
$ipranges_id2 = $pfIPRange->add($input);
// Allow all agents to do network discovery
$query = "UPDATE `glpi_plugin_fusioninventory_agentmodules` " . " SET `is_active`='1' " . " WHERE `modulename`='NETWORKDISCOVERY'";
$DB->query($query);
// create task
$input = array('entities_id' => 0, 'name' => 'network discovery', 'is_active' => 1);
$tasks_id = $pfTask->add($input);
// create taskjob
$input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'discovery', 'method' => 'networkdiscovery', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"2"}]');
$pfTaskjob->add($input);
// create task
$input = array('entities_id' => 0, 'name' => 'network discovery2', 'is_active' => 1);
$tasks2_id = $pfTask->add($input);
// create taskjob
$input = array('plugin_fusioninventory_tasks_id' => $tasks2_id, 'entities_id' => 0, 'name' => 'discovery', 'method' => 'networkdiscovery', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id2 . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"3"}]');
$pfTaskjob->add($input);
}
示例9: pdfForComputer
static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
{
global $DB;
$ID = $item->getField('id');
$query = "SELECT `glpi_filesystems`.`name` AS fsname, `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE (`computers_id` = '" . $ID . "')";
$result = $DB->query($query);
$pdf->setColumnsSize(100);
if ($DB->numrows($result) > 0) {
$pdf->displayTitle("<b>" . _n('Volume', 'Volumes', 2) . "</b>");
$pdf->setColumnsSize(22, 23, 22, 11, 11, 11);
$pdf->displayTitle('<b>' . __('Name'), __('Partition'), _('Mount point'), __('Type'), __('Global size'), __('Free size') . '</b>');
$pdf->setColumnsAlign('left', 'left', 'left', 'center', 'right', 'right');
while ($data = $DB->fetch_assoc($result)) {
$pdf->displayLine('<b>' . Toolbox::decodeFromUtf8(empty($data['name']) ? $data['ID'] : $data['name'], "windows-1252") . '</b>', $data['device'], $data['mountpoint'], Html::clean(Dropdown::getDropdownName('glpi_filesystems', $data["filesystems_id"])), sprintf(__('%s Mio'), Html::clean(Html::formatNumber($data['totalsize'], false, 0))), sprintf(__('%s Mio'), Html::clean(Html::formatNumber($data['freesize'], false, 0))));
}
} else {
$pdf->displayTitle("<b>" . __('No volume found', 'pdf') . "</b>");
}
$pdf->displaySpace();
}
示例10: showAdditionalInformation
/**
* @param $info array
* @param $option array
**/
function showAdditionalInformation($info = array(), $option = array())
{
$name = "info[" . $option['linkfield'] . "]";
switch ($option['displaytype']) {
case 'computer':
Computer::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false));
break;
case 'software':
Software::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false));
break;
default:
break;
}
}
示例11: Licenses
/**
* @test
*/
public function Licenses()
{
global $DB;
$DB->connect();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$GLPIlog = new GLPIlogs();
$a_computerinventory = $this->a_computer1;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$this->assertEquals(1, countElementsInTable('glpi_plugin_fusioninventory_computerlicenseinfos'), 'License may be added in fusion table');
$pfComputerLicenseInfo = new PluginFusioninventoryComputerLicenseInfo();
$pfComputerLicenseInfo->getFromDB(1);
$a_ref = array('id' => 1, 'computers_id' => 1, 'softwarelicenses_id' => 0, 'name' => 'Microsoft Office 2003', 'fullname' => 'Microsoft Office Professional Edition 2003', 'serial' => 'xxxxx-xxxxx-P6RC4-xxxxx-xxxxx', 'is_trial' => '0', 'is_update' => '0', 'is_oem' => '0', 'activation_date' => NULL);
$this->assertEquals($a_ref, $pfComputerLicenseInfo->fields, 'License data');
}
示例12: PeripheralUniqueSerialimport
/**
* @test
*/
public function PeripheralUniqueSerialimport()
{
global $DB;
$DB->connect();
self::restore_database();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfConfig = new PluginFusioninventoryConfig();
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$GLPIlog = new GLPIlogs();
$pxml = @simplexml_load_string($this->a_computer1_XML, 'SimpleXMLElement', LIBXML_NOCDATA);
$arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml);
$agent = new PluginFusioninventoryAgent();
$agents_id = $agent->importToken($arrayinventory);
$_SESSION['plugin_fusioninventory_agents_id'] = $agents_id;
$pfInventoryComputerInventory = new PluginFusioninventoryInventoryComputerInventory();
$pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$a_ref = array(1 => array('name' => 'Périphérique USB composite', 'id' => '1', 'serial' => '10075973', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 2 => array('name' => 'H5321 gw Mobile Broadband Device', 'id' => '2', 'serial' => '187A047919938CM0', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '7', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 3 => array('name' => 'Périphérique d’entrée USB', 'id' => '3', 'serial' => 'STM32_EMOTION2', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '8', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'));
$a_db_peripherals = getAllDatasFromTable('glpi_peripherals');
foreach ($a_db_peripherals as $id => $data) {
$data_temp = array('name' => $data['name'], 'id' => $data['id'], 'serial' => $data['serial'], 'peripheraltypes_id' => $data['peripheraltypes_id'], 'peripheralmodels_id' => $data['peripheralmodels_id'], 'manufacturers_id' => $data['manufacturers_id'], 'is_global' => $data['is_global'], 'is_deleted' => $data['is_deleted'], 'is_template' => $data['is_template'], 'is_dynamic' => $data['is_dynamic']);
$a_db_peripherals[$id] = $data_temp;
}
$this->assertEquals($a_ref, $a_db_peripherals, 'List of peripherals');
// Update computer and may not have new values in glpi_logs
$query = "SELECT * FROM `glpi_logs`\n ORDER BY `id` DESC LIMIT 1";
$result = $DB->query($query);
$data = $DB->fetch_assoc($result);
$last_id = $data['id'];
$pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
$data = getAllDatasFromTable('glpi_logs', "`id`>'" . $last_id . "'");
$this->assertEquals(array(), $data, 'On update peripherals, may not have new lines in glpi_logs');
}
示例13: showForComputer
/**
* Print the computers disks
*
* @param $comp Computer object
*
* @return Nothing (call to classes members)
**/
static function showForComputer(Computer $comp)
{
global $DB;
$ID = $comp->fields['id'];
if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) {
return false;
}
$canedit = $comp->can($ID, "w");
echo "<div class='spaced center'>";
$virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}' AND `is_deleted` = '0'");
echo "<table class='tab_cadre_fixe'>";
Session::initNavigateListItems('ComputerVirtualMachine', sprintf(__('%1$s = %2$s'), __('Computer'), empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name']));
if (empty($virtualmachines)) {
echo "<tr><th>" . __('No virtual machine associated with the computer') . "</th></tr>";
} else {
echo "<tr><th colspan='10'>" . __('List of virtual machines') . "</th></tr>";
echo "<tr><th>" . __('Name') . "</th>";
if (Plugin::haveImport()) {
echo "<th>" . __('Automatic inventory') . "</th>";
}
echo "<th>" . __('Virtualization system') . "</th>";
echo "<th>" . __('Virtualization model') . "</th>";
echo "<th>" . __('State of the virtual machine') . "</th>";
echo "<th>" . __('UUID') . "</th>";
echo "<th>" . _x('quantity', 'Processors number') . "</th>";
echo "<th>" . sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . "</th>";
echo "<th>" . __('Machine') . "</th>";
echo "</tr>";
$vm = new self();
foreach ($virtualmachines as $virtualmachine) {
$vm->getFromDB($virtualmachine['id']);
echo "<tr class='tab_bg_2'>";
echo "<td>" . $vm->getLink() . "</td>";
if (Plugin::haveImport()) {
echo "<td>";
echo Dropdown::getYesNo($vm->isDynamic());
echo "</td>";
}
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']);
echo "</td>";
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']);
echo "</td>";
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']);
echo "</td>";
echo "<td>" . $virtualmachine['uuid'] . "</a></td>";
echo "<td>" . $virtualmachine['vcpu'] . "</td>";
echo "<td>" . $virtualmachine['ram'] . "</td>";
echo "<td>";
if ($link_computer = self::findVirtualMachine($virtualmachine)) {
$computer = new Computer();
if ($computer->can($link_computer, 'r')) {
$url = "<a href='computer.form.php?id=" . $link_computer . "'>";
$url .= $computer->fields["name"] . "</a>";
$tooltip = "<table><tr><td>" . __('Name') . "</td><td>" . $computer->fields['name'] . '</td></tr>';
$tooltip .= "<tr><td>" . __('Serial number') . "</td><td>" . $computer->fields['serial'] . '</td></tr>';
$tooltip .= "<tr><td>" . __('Comments') . "</td><td>" . $computer->fields['comment'] . '</td></tr></table>';
$url .= " " . Html::showToolTip($tooltip, array('display' => false));
} else {
$url = $computer->fields['name'];
}
echo $url;
}
echo "</td>";
echo "</tr>";
Session::addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']);
}
}
if ($canedit) {
echo "<tr class='tab_bg_1'><td colspan='8' class='center'>";
echo "<a class='vsubmit' href='computervirtualmachine.form.php?computers_id={$ID}'>" . __('Add a virtual machine') . "</a></td></tr>";
}
echo "</table>";
echo "</div>";
}
示例14: dropdownService
static function dropdownService($ID, $options = array())
{
global $CFG_GLPI;
$p = array();
$p['name'] = 'networkports_id';
$p['comments'] = 1;
$p['entity'] = -1;
$p['entity_sons'] = false;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$p[$key] = $val;
}
}
// Manage entity_sons
if (!($p['entity'] < 0) && $p['entity_sons']) {
if (is_array($p['entity'])) {
echo "entity_sons options is not available with array of entity";
} else {
$p['entity'] = getSonsOf('glpi_entities', $p['entity']);
}
}
$rand = mt_rand();
echo "<select name='itemtype[{$ID}]' id='itemtype{$rand}'>";
echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
// $a_types =array();
echo "<option value='Computer'>" . Computer::getTypeName() . "</option>";
echo "<option value='NetworkEquipment'>" . NetworkEquipment::getTypeName() . "</option>";
echo "</select>";
$params = array('itemtype' => '__VALUE__', 'entity_restrict' => $p['entity'], 'current' => $ID, 'comments' => $p['comments'], 'myname' => $p['name'], 'rand' => $rand);
ajaxUpdateItemOnSelectEvent("itemtype{$rand}", "show_" . $p['name'] . "{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownServiceHostType.php", $params);
echo "<span id='show_" . $p['name'] . "{$rand}'><input type='hidden' name='services_id[]' value='0'/></span>\n";
return $rand;
}
示例15: pdfForComputer
static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp)
{
global $DB;
$ID = $comp->getField('id');
// From Computer_SoftwareVersion::showForComputer();
$query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`name` AS softname,\n `glpi_computers_softwareversions`.`id`,\n `glpi_states`.`name` AS state,\n `glpi_softwareversions`.`id` AS verid,\n `glpi_softwareversions`.`softwares_id`,\n `glpi_softwareversions`.`name` AS version\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$ID}'\n ORDER BY `softwarecategories_id`, `softname`, `version`";
$output = array();
$software_category = new SoftwareCategory();
$software_version = new SoftwareVersion();
foreach ($DB->request($query) as $softwareversion) {
$output[] = $softwareversion;
}
$installed = array();
if (count($output)) {
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . _n('Installed software', 'Installed software', 2, 'pdf') . '</b>');
$cat = -1;
foreach ($output as $soft) {
if ($soft["softwarecategories_id"] != $cat) {
$cat = $soft["softwarecategories_id"];
if ($cat && $software_category->getFromDB($cat)) {
$catname = $software_category->getName();
} else {
$catname = __('Uncategorized software');
}
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . $catname . '</b>');
$pdf->setColumnsSize(50, 13, 13, 24);
$pdf->displayTitle('<b>' . __('Name'), __('Status'), __('Version'), __('License') . '</b>');
}
// From Computer_SoftwareVersion::displaySoftsByCategory()
$verid = $soft['verid'];
$query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_softwarelicensetypes`.`name` AS type\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicenses`.`softwarelicensetypes_id`\n =`glpi_softwarelicensetypes`.`id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$ID}'\n AND (`glpi_softwarelicenses`.`softwareversions_id_use` = '{$verid}'\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy` = '{$verid}'))";
$lic = '';
foreach ($DB->request($query) as $licdata) {
$installed[] = $licdata['id'];
$lic .= (empty($lic) ? '' : ', ') . '<b>' . $licdata['name'] . '</b> ' . $licdata['serial'];
if (!empty($licdata['type'])) {
$lic = sprintf(__('%1$s (%2$s)'), $lic, $licdata['type']);
}
}
$pdf->displayLine($soft['softname'], $soft['state'], $soft['version'], $lic);
}
// Each version
} else {
$pdf->displayTitle('<b>' . __('No installed software', 'pdf') . '</b>');
}
// Affected licenses NOT installed
$query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_softwares`.`name` AS softname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_states`.`name` AS state\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_computers_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n = `glpi_softwareversions`.`id`\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n = `glpi_softwareversions`.`id`))\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$ID}' ";
if (count($installed)) {
$query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")";
}
$req = $DB->request($query);
if ($req->numrows()) {
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . __('Affected licenses of not installed software') . '</b>');
$pdf->setColumnsSize(50, 13, 13, 24);
$pdf->displayTitle('<b>' . __('Name'), __('Status'), __('Version'), __('License') . '</b>');
$lic = '';
foreach ($req as $data) {
$lic .= '<b>' . $data['name'] . '</b> ' . $data['serial'];
if (!empty($data['softwarelicensetypes_id'])) {
$lic = sprintf(__('%1$s (%2$s)'), $lic, Html::Clean(Dropdown::getDropdownName('glpi_softwarelicensetypes', $data['softwarelicensetypes_id'])));
}
$pdf->displayLine($data['softname'], $data['state'], $data['version'], $lic);
}
}
$pdf->displaySpace();
}