/**
  * @param $computers_id
  * @param $date
  * @param $computer_updates
  * @return array
  */
 static function addInfocomsForComputer($computers_id, $date, $computer_updates)
 {
     global $DB;
     $infocom = new Infocom();
     $use_date = substr($date, 0, 10);
     if ($infocom->getFromDBByQuery("WHERE `items_id` = {$computers_id} AND `itemtype` = 'Computer'")) {
         if (empty($infocom->fields['use_date']) || $infocom->fields['use_date'] == 'NULL') {
             //add use_date
             $infocom->update(array('id' => $infocom->fields['id'], 'use_date' => $use_date));
         }
     } else {
         //add infocom
         $infocom->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'use_date' => $use_date));
     }
     //Add lock
     $ocslink = new PluginOcsinventoryngOcslink();
     if ($ocslink->getFromDBforComputer($computers_id)) {
         $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]);
         if ($cfg_ocs["use_locks"]) {
             $computer_updates[] = "use_date";
             $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                         SET `computer_update` = '" . addslashes(exportArrayToDB($computer_updates)) . "'\n                         WHERE `computers_id` = '{$computers_id}'";
             $DB->query($query);
         }
     }
     return $computer_updates;
 }
Пример #2
0
Session::checkRight("computer", READ);
if (isset($_POST["force_ocs_resynch"])) {
    $computer = new Computer();
    $computer->check($_POST['id'], UPDATE);
    //Get the ocs server id associated with the machine
    $ocsservers_id = PluginOcsinventoryngOcsServer::getByMachineID($_POST["id"]);
    //Update the computer
    $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id);
    $dohistory = isset($cfg_ocs['dohistory']) ? $cfg_ocs['dohistory'] : false;
    PluginOcsinventoryngOcsServer::updateComputer($_POST["resynch_id"], $ocsservers_id, $dohistory, 1);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $link = new PluginOcsinventoryngOcslink();
        $values["id"] = $_POST["link_id"];
        $values["use_auto_update"] = $_POST["use_auto_update"];
        $link->update($values);
        Html::back();
    } else {
        if (isset($_POST["delete_link"])) {
            $comp = new Computer();
            $link = new PluginOcsinventoryngOcslink();
            if ($comp->getFromDB($_POST["items_id"])) {
                $link->purgeComputer($comp);
                Html::back();
            }
        } else {
            Html::displayErrorAndDie("lost");
        }
    }
}
Пример #3
0
 /**
  * Function to uninstall an object
  *
  * @param $computers_id the computer's ID in GLPI
  *
  * @return nothing
  **/
 static function deleteOcsLink($computers_id)
 {
     $link = new PluginOcsinventoryngOcslink();
     $link->dohistory = false;
     $link->deleteByCriteria(array('computers_id' => $computers_id));
     $reg = new PluginOcsinventoryngRegistryKey();
     $reg->deleteByCriteria(array('computers_id' => $computers_id));
 }
Пример #4
0
(at your option) any later version.

Ocsinventoryng plugin 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------- */
include '../../../inc/includes.php';
Session::checkRight("computer", READ);
if (isset($_POST["force_ocs_resynch"])) {
    $computer = new Computer();
    $computer->check($_POST['id'], UPDATE);
    //Get the ocs server id associated with the machine
    $ocsservers_id = PluginOcsinventoryngOcsServer::getByMachineID($_POST["id"]);
    //Update the computer
    PluginOcsinventoryngOcsServer::updateComputer($_POST["resynch_id"], $ocsservers_id, 1, 1);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $link = new PluginOcsinventoryngOcslink();
        $values["id"] = $_POST["link_id"];
        $values["use_auto_update"] = $_POST["use_auto_update"];
        $link->update($values);
        Html::back();
    } else {
        Html::displayErrorAndDie("lost");
    }
}
Пример #5
0
 /**
  * Update TAG information in glpi_plugin_ocsinventoryng_ocslinks table
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @param $line_ocs array : data from ocs tables
  *
  * @return string : current tag of computer on update
  **/
 static function updateTag($line_links, $line_ocs)
 {
     global $DB, $PluginOcsinventoryngDBocs;
     $query_ocs = "SELECT `accountinfo`.`TAG` AS TAG\n                    FROM `hardware`\n                    INNER JOIN `accountinfo`\n                        ON (`hardware`.`ID` = `accountinfo`.`HARDWARE_ID`)\n                    WHERE `hardware`.`ID` = '" . $line_links["ocsid"] . "'";
     $result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs);
     if ($PluginOcsinventoryngDBocs->numrows($result_ocs) == 1) {
         $data_ocs = Toolbox::addslashes_deep($PluginOcsinventoryngDBocs->fetch_array($result_ocs));
         $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                   SET `tag` = '" . $data_ocs["TAG"] . "'\n                   WHERE `id` = '" . $line_links["id"] . "'";
         if ($DB->query($query)) {
             $changes[0] = '0';
             $changes[1] = $line_links["tag"];
             $changes[2] = $data_ocs["TAG"];
             PluginOcsinventoryngOcslink::history($line_links["computers_id"], $changes, PluginOcsinventoryngOcslink::HISTORY_OCS_TAGCHANGED);
             return $data_ocs["TAG"];
         }
     }
 }
Пример #6
0
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.

Ocsinventoryng plugin 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------------------------------------------------------------------- */
// Ensure current directory when run from crontab
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
include '../../../inc/includes.php';
ini_set('display_errors', 1);
restore_error_handler();
if (!isset($_SERVER['argv'][1])) {
    die("usage testsync.php <computerid>\n");
}
$link = new PluginOcsinventoryngOcslink();
if (!$link->getFromDBforComputer($_SERVER['argv'][1])) {
    die("unknow computer\n");
}
printf("Device: %s\n", $link->getField('ocs_deviceid'));
$timer = new Timer();
$timer->start();
$prof = new XHProf("OCS sync");
PluginOcsinventoryngOcsServer::updateComputer($link->getID(), $link->getField('plugin_ocsinventoryng_ocsservers_id'), 1, 1);
unset($prof);
printf("Done in %s\n", $timer->getTime());
Пример #7
0
/**
 * Checking locks before updating
 * @param type $item
 */
function plugin_ocsinventoryng_pre_item_update($item)
{
    if ($item->fields['itemtype'] == "Computer") {
        $ocslink = new PluginOcsinventoryngOcslink();
        if ($ocslink->getFromDBforComputer($item->fields['items_id'])) {
            $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]);
            if ($cfg_ocs["use_locks"]) {
                $field_set = false;
                $computers_update = importArrayFromDB($ocslink->fields['computer_update']);
                if (in_array('use_date', $computers_update)) {
                    if (isset($item->input["use_date"]) && $item->input["use_date"] != $item->fields["use_date"]) {
                        $field_set = true;
                        $item->input["use_date"] = $item->fields["use_date"];
                    }
                }
                if ($field_set) {
                    Session::addMessageAfterRedirect(__("The startup date field is locked by ocsinventoryng please unlock it before update.", "ocsinventoryng"), true, ERROR);
                }
            }
        }
    }
}
Пример #8
0
 /**
  * Update TAG information in glpi_plugin_ocsinventoryng_ocslinks table
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @param $line_ocs array : data from ocs tables
  *
  * @return string : current tag of computer on update
  **/
 static function updateTag($line_links, $line_ocs)
 {
     global $DB;
     $ocsClient = self::getDBocs($line_links["plugin_ocsinventoryng_ocsservers_id"]);
     $options = array();
     $computer = $ocsClient->getComputer($line_links["ocsid"], $options);
     if ($computer) {
         $data_ocs = Toolbox::addslashes_deep($computer["META"]);
         if (isset($data_ocs["TAG"]) && isset($line_links["tag"]) && $data_ocs["TAG"] != $line_links["tag"]) {
             $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                      SET `tag` = '" . $data_ocs["TAG"] . "'\n                      WHERE `id` = '" . $line_links["id"] . "'";
             if ($DB->query($query)) {
                 $changes[0] = '0';
                 $changes[1] = $line_links["tag"];
                 $changes[2] = $data_ocs["TAG"];
                 PluginOcsinventoryngOcslink::history($line_links["computers_id"], $changes, PluginOcsinventoryngOcslink::HISTORY_OCS_TAGCHANGED);
                 return $data_ocs["TAG"];
             }
         }
     }
 }