Exemplo n.º 1
0
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("plugin_ocsinventoryng", UPDATE);
Html::header('OCS Inventory NG', '', "tools", "pluginocsinventoryngmenu", "sync");
$display_list = true;
if (isset($_SESSION["ocs_update"]['computers'])) {
    if ($count = count($_SESSION["ocs_update"]['computers'])) {
        $percent = min(100, round(100 * ($_SESSION["ocs_update_count"] - $count) / $_SESSION["ocs_update_count"], 0));
        $key = array_pop($_SESSION["ocs_update"]['computers']);
        $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($_SESSION["plugin_ocsinventoryng_ocsservers_id"]);
        $dohistory = isset($cfg_ocs['dohistory']) ? $cfg_ocs['dohistory'] : false;
        $action = PluginOcsinventoryngOcsServer::updateComputer($key, $_SESSION["plugin_ocsinventoryng_ocsservers_id"], $dohistory);
        PluginOcsinventoryngOcsServer::manageImportStatistics($_SESSION["ocs_update"]['statistics'], $action['status']);
        PluginOcsinventoryngOcsServer::showStatistics($_SESSION["ocs_update"]['statistics']);
        Html::displayProgressBar(400, $percent);
        Html::redirect($_SERVER['PHP_SELF']);
    } else {
        if (isset($_SESSION["ocs_update"]['statistics'])) {
            PluginOcsinventoryngOcsServer::showStatistics($_SESSION["ocs_update"]['statistics'], true);
        } else {
            echo "<div class='center b red'>";
            _e('No synchronization: the plugin will not synchronize these elements', 'ocsinventoryng');
            echo "</div>";
        }
        unset($_SESSION["ocs_update"]);
        $display_list = false;
        echo "<div class='center b'><br>";
Exemplo n.º 2
0
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
    $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();
Exemplo n.º 3
0
/**
 * @param $data   array
**/
function plugin_ocsinventoryng_MassiveActionsProcess($data)
{
    global $CFG_GLPI, $DB, $REDIRECT;
    $nbok = 0;
    $nbko = 0;
    $noright = 0;
    $notimport = new PluginOcsinventoryngNotimportedcomputer();
    if (!($item = getItemForItemtype($data['itemtype']))) {
        return;
    }
    switch ($data["action"]) {
        case "plugin_ocsinventoryng_import":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $key, 'force' => true, 'entity' => $data['entity']));
                }
            }
            break;
        case "plugin_ocsinventoryng_replayrules":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    PluginOcsinventoryngNotimportedcomputer::computerImport(array('id' => $key));
                }
            }
            break;
        case "plugin_ocsinventoryng_delete":
            $plugin = new Plugin();
            if ($plugin->isActivated("uninstall")) {
                foreach ($data["item"] as $key => $val) {
                    if ($val == 1) {
                        $notimport->deleteNotImportedComputer($key);
                    }
                }
            }
            break;
        case "plugin_ocsinventoryng_unlock_ocsng_field":
            $nbok = 0;
            $nbnoright = 0;
            $nbko = 0;
            $fields = PluginOcsinventoryngOcsServer::getLockableFields();
            if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) {
                foreach ($_POST["item"] as $key => $val) {
                    if ($val == 1) {
                        if ($item->can($key, 'w')) {
                            if ($_POST['field'] == 'all') {
                                if (PluginOcsinventoryngOcsServer::replaceOcsArray($key, array(), "computer_update")) {
                                    $nbok++;
                                } else {
                                    $nbko++;
                                }
                            } else {
                                if (PluginOcsinventoryngOcsServer::deleteInOcsArray($key, $_POST['field'], "computer_update", true)) {
                                    $nbok++;
                                } else {
                                    $nbko++;
                                }
                            }
                        } else {
                            $nbnoright++;
                        }
                    }
                }
            }
            break;
        case "plugin_ocsinventoryng_force_ocsng_update":
            // First time
            if (!isset($_GET['multiple_actions'])) {
                $_SESSION['glpi_massiveaction']['POST'] = $_POST;
                $_SESSION['glpi_massiveaction']['REDIRECT'] = $REDIRECT;
                $_SESSION['glpi_massiveaction']['items'] = array();
                foreach ($_POST["item"] as $key => $val) {
                    if ($val == 1) {
                        $_SESSION['glpi_massiveaction']['items'][$key] = $key;
                    }
                }
                $_SESSION['glpi_massiveaction']['item_count'] = count($_SESSION['glpi_massiveaction']['items']);
                $_SESSION['glpi_massiveaction']['items_ok'] = 0;
                $_SESSION['glpi_massiveaction']['items_ko'] = 0;
                $_SESSION['glpi_massiveaction']['items_nbnoright'] = 0;
                Html::redirect($_SERVER['PHP_SELF'] . '?multiple_actions=1');
            } else {
                if (count($_SESSION['glpi_massiveaction']['items']) > 0) {
                    $key = array_pop($_SESSION['glpi_massiveaction']['items']);
                    if ($item->can($key, 'w')) {
                        //Try to get the OCS server whose machine belongs
                        $query = "SELECT `plugin_ocsinventoryng_ocsservers_id`, `id`\n                            FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                            WHERE `computers_id` = '" . $key . "'";
                        $result = $DB->query($query);
                        if ($DB->numrows($result) == 1) {
                            $data = $DB->fetch_assoc($result);
                            if ($data['plugin_ocsinventoryng_ocsservers_id'] != -1) {
                                //Force update of the machine
                                PluginOcsinventoryngOcsServer::updateComputer($data['id'], $data['plugin_ocsinventoryng_ocsservers_id'], 1, 1);
                                $_SESSION['glpi_massiveaction']['items_ok']++;
                            } else {
                                $_SESSION['glpi_massiveaction']['items_ko']++;
                            }
                        } else {
                            $_SESSION['glpi_massiveaction']['items_ko']++;
                        }
                    } else {
                        $_SESSION['glpi_massiveaction']['items_nbnoright']++;
                    }
                    Html::redirect($_SERVER['PHP_SELF'] . '?multiple_actions=1');
                } else {
                    $REDIRECT = $_SESSION['glpi_massiveaction']['REDIRECT'];
                    $nbok = $_SESSION['glpi_massiveaction']['items_ok'];
                    $nbko = $_SESSION['glpi_massiveaction']['items_ko'];
                    $nbnoright = $_SESSION['glpi_massiveaction']['items_nbnoright'];
                    unset($_SESSION['glpi_massiveaction']);
                }
            }
            break;
    }
    return array('ok' => $nbok, 'ko' => $nbko, 'noright' => $noright);
}
Exemplo n.º 4
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());
Exemplo n.º 5
0
 static function syncOCS($objectId, $entities)
 {
     global $DB;
     $res = array('ok' => 0, 'ko' => 0);
     $object = new $objectId();
     $objecttable = getTableForItemType($objectId);
     $restrict = "";
     if ($object->maybeTemplate()) {
         $restrict = "`is_template` = '0'";
     }
     if ($object->isEntityAssign() && $entities != -1) {
         $restrict .= getEntitiesRestrictRequest(" AND ", $objecttable, '', $entities, $object->maybeRecursive());
     }
     $count = countElementsInTable($objecttable, $restrict);
     $items = getAllDatasFromTable($objecttable, $restrict);
     if (!empty($items)) {
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><td>";
         Html::createProgressBar(__('Work in progress...'));
         echo "</td></tr></table></div></br>\n";
         $i = 0;
         foreach ($items as $item) {
             //Try to get the OCS server whose machine belongs
             $query = "SELECT `plugin_ocsinventoryng_ocsservers_id`, `id`\n                        FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                        WHERE `computers_id` = '" . $item['id'] . "'\n                           AND `entities_id` = '" . $entities . "'";
             $result = $DB->query($query);
             if ($DB->numrows($result) == 1) {
                 $data = $DB->fetch_assoc($result);
                 if ($data['plugin_ocsinventoryng_ocsservers_id'] != -1) {
                     //Force update of the machine
                     if (PluginOcsinventoryngOcsServer::updateComputer($data['id'], $data['plugin_ocsinventoryng_ocsservers_id'], 0, 1)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             $i++;
             Html::changeProgressBarPosition($i, $count);
         }
         Html::changeProgressBarPosition($i, $count, __('Task completed.'));
     }
     return $res;
 }