reformatted, cleaned

This commit is contained in:
2021-12-10 11:50:51 +01:00
parent 0cde20881a
commit a4e71a8992
4 changed files with 275 additions and 328 deletions

View File

@@ -1,81 +1,39 @@
<?php
/*
------------------------------------------------------------------------
FusionInventory
Copyright (C) 2010-2011 by the FusionInventory Development Team.
include "../../../inc/includes.php";
http://www.fusioninventory.org/ http://forge.fusioninventory.org/
------------------------------------------------------------------------
declare (ticks = 1);
LICENSE
global $DB, $agents;
This file is part of FusionInventory project.
$check_arr = [];
$comps = [];
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
FusionInventory is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
$check = [];
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
FusionInventory 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with FusionInventory. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------
@package FusionInventory
@author Walid Nouh
@co-author
@copyright Copyright (c) 2010-2011 FusionInventory team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link http://www.fusioninventory.org/
@link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/
@since 2010
------------------------------------------------------------------------
*/
include ("../../../inc/includes.php");
declare(ticks=1);
global $DB,$agents;
$check_arr = [];
$comps = [];
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
$check = [];
$a_computerextend = $pfInventoryComputerComputer->hasAutomaticInventory($a["computers_id"]);
$check["url"] = "http://".$a_computerextend["remote_addr"].":62354/status";
$check["id"] = $a["id"];
$check["computers_id"] = $a["computers_id"];
$check["status"] = "unknown";
$check_arr[] = $check;
$comps[$a["computers_id"]] = $check;
//print_r($agent->getAgentStatusURLs());
}
$check["url"] = "http://" . $a_computerextend["remote_addr"] . ":62354/status";
$check["id"] = $a["id"];
$check["computers_id"] = $a["computers_id"];
$check["status"] = "unknown";
$check_arr[] = $check;
$comps[$a["computers_id"]] = $check;
//print_r($agent->getAgentStatusURLs());
}
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-output.txt", "a"), // stderr is a file to write to
);
$cwd = '/tmp';
$env = array('debug' => 'false');
$process = proc_open(__DIR__.'/check_status', $descriptorspec, $pipes, $cwd, $env);
$process = proc_open(__DIR__ . '/check_status', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
// $pipes now looks like this:
@@ -96,7 +54,7 @@ if (is_resource($process)) {
echo "command returned $return_value\n";
}
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => 'Offline']]);
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], ['OR' => ['name' => 'Online', 'name' => 'Offline']]);
$ret = $req->next();
$states_ids[$ret['name']] = $ret['id'];
@@ -104,27 +62,24 @@ $ret = $req->next();
$states_ids[$ret['name']] = $ret['id'];
print_r($states_ids);
$DB->update("glpi_computers", [
'states_id' => $states_ids["Offline"] ] ,
[ '1' => '1' ]
);
$DB->update("glpi_computers", [
'states_id' => $states_ids["Offline"]],
['1' => '1']
);
foreach ($checked as $s) {
echo $s->computers_id." ";
echo $s->computers_id . " ";
$comp = new Computer();
$comp->getFromDB($s->computers_id);
$comp->fields["states_id"] = $states_ids["Online"];
$DB->update("glpi_computers", [
'states_id' => $comp->fields["states_id"] ],
[ 'id' => $s->computers_id ]
);
echo $comp->fields["contact"]."\n";
$comp = new Computer();
$comp->getFromDB($s->computers_id);
$comp->fields["states_id"] = $states_ids["Online"];
$DB->update("glpi_computers", [
'states_id' => $comp->fields["states_id"]],
['id' => $s->computers_id]
);
echo $comp->fields["contact"] . "\n";
}
// print_r($a_computerextend);
// print_r($a_computerextend);
exit(0);