Esempio n. 1
0
            // Unlink the computer
            $sql = "DELETE\n                 FROM `glpi_ocslinks`\n                 WHERE `computers_id` = '" . $event["items_id"] . "'";
            if ($debug) {
                echo "DEBUG: {$sql} \n";
            }
            if ($run) {
                // Restore previous state
                $comp->update($input);
                // Unlink the computer
                $resupd = $DB->query($sql);
                if ($res) {
                    $nbupd += $DB->affected_rows();
                    $changes[0] = 0;
                    $changes[2] = "Rollback: restauration statut au {$maxti}";
                    $changes[1] = "";
                    Log::history($event["items_id"], 'Computer', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
                } else {
                    echo "*** MySQL : {$sql}\n*** Error : " . $DB->error() . "\n";
                }
            }
        }
        // Else
    }
    // If PC
}
// foreach event
printf("=> %d computers, %d updates\n", $nb, $nbupd);
echo "Saving reports in " . GLPI_LOG_DIR . "\n";
$nbc = 0;
foreach ($tabres as $ent => $comps) {
    $name = Dropdown::getDropdownName("glpi_entities", $ent);
Esempio n. 2
0
 public function addHistory($type, $old_value = '', $new_value = '', $ID)
 {
     $changes[0] = 0;
     $changes[1] = $old_value;
     $changes[2] = $new_value;
     Log::history($ID, $type, $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
 }
 function post_addItem()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     //       if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
     //          $donotif = false;
     //       }
     $this->input["_job"]->updateDateMod($this->input["tickets_id"], false, $this->input["users_id"]);
     if (isset($this->input["_close"]) && $this->input["_close"] && $this->input["_job"]->fields["status"] == CommonITILObject::SOLVED) {
         $update['id'] = $this->input["_job"]->fields['id'];
         $update['status'] = CommonITILObject::CLOSED;
         $update['closedate'] = $_SESSION["glpi_currenttime"];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if (isset($this->input["_reopen"]) && $this->input["_reopen"] && in_array($this->input["_job"]->fields["status"], array(CommonITILObject::CLOSED, CommonITILObject::SOLVED, CommonITILObject::WAITING))) {
         if ($this->input["_job"]->countUsers(CommonITILActor::ASSIGN) > 0 || $this->input["_job"]->countGroups(CommonITILActor::ASSIGN) > 0 || $this->input["_job"]->countSuppliers(CommonITILActor::ASSIGN) > 0) {
             $update['status'] = CommonITILObject::ASSIGNED;
         } else {
             $update['status'] = CommonITILObject::INCOMING;
         }
         $update['id'] = $this->input["_job"]->fields['id'];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if ($donotif) {
         $options = array('followup_id' => $this->fields["id"], 'is_private' => $this->fields['is_private']);
         NotificationEvent::raiseEvent("add_followup", $this->input["_job"], $options);
     }
     // Add log entry in the ticket
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
 function post_deleteFromDB()
 {
     $vers = new SoftwareVersion();
     if (!$vers->getFromDB($this->fields['softwareversions_id'])) {
         return false;
     }
     /// Could not be possible : because several computers may be linked to a version
     // Update affected licenses
     //       $lic = new SoftwareLicense();
     //       $query = "SELECT `id`
     //                 FROM `glpi_softwarelicenses`
     //                 WHERE `softwares_id` = '".$vers->fields['softwares_id']."'
     //                   AND `computers_id` = '".$this->fields['computers_id']."'
     //                   AND `softwareversions_id_use` = '".$this->fields['softwareversions_id']."'";
     //       foreach ($DB->request($query) as $data) {
     //          $data['softwareversions_id_use'] = 0;
     //          $lic->update($data);
     //       }
     if (isset($this->input['_no_history']) && $this->input['_no_history']) {
         return false;
     }
     $soft = new Software();
     if ($soft->getFromDB($vers->fields['softwares_id'])) {
         $changes[0] = '0';
         $changes[1] = addslashes($soft->fields["name"] . " " . $vers->fields["name"]);
         $changes[2] = "";
         // Log on Computer history
         Log::history($this->fields['computers_id'], 'Computer', $changes, 0, HISTORY_UNINSTALL_SOFTWARE);
     }
     $comp = new Computer();
     if ($comp->getFromDB($this->fields['computers_id'])) {
         $changes[0] = '0';
         $changes[1] = addslashes($comp->fields["name"]);
         $changes[2] = "";
         // Log on SoftwareVersion history
         Log::history($this->fields['softwareversions_id'], 'SoftwareVersion', $changes, 0, HISTORY_UNINSTALL_SOFTWARE);
     }
 }
 /**
  * Actions done after the DELETE of the item in the database
  *
  * @since version 0.84
  *
  *@return nothing
  **/
 function post_deleteFromDB()
 {
     if (isset($this->input['_no_history']) && $this->input['_no_history'] || !static::$logs_for_item_1 && !static::$logs_for_item_2) {
         return;
     }
     $item1 = $this->getConnexityItem(static::$itemtype_1, static::$items_id_1);
     $item2 = $this->getConnexityItem(static::$itemtype_2, static::$items_id_2);
     if ($item1 !== false && $item2 !== false) {
         if ($item1->dohistory && static::$logs_for_item_1) {
             $changes[0] = '0';
             $changes[1] = addslashes($this->getHistoryNameForItem1($item2, 'delete'));
             $changes[2] = "";
             Log::history($item1->getID(), $item1->getType(), $changes, $item2->getType(), static::$log_history_1_delete);
         }
         if ($item2->dohistory && static::$logs_for_item_2) {
             $changes[0] = '0';
             $changes[1] = addslashes($this->getHistoryNameForItem2($item1, 'delete'));
             $changes[2] = "";
             Log::history($item2->getID(), $item2->getType(), $changes, $item1->getType(), static::$log_history_2_delete);
         }
     }
 }
Esempio n. 6
0
 /**
  * Add an history entry to a computer
  *
  * @param $computers_id Integer, ID of the computer
  * @param $changes      Array, see Log::history
  * @param $action       Integer in PluginOcsinventoryngOcslink::HISTORY_OCS_*
  *
  * @return Integer id of the inserted entry
  **/
 static function history($computers_id, $changes, $action)
 {
     return Log::history($computers_id, 'Computer', $changes, __CLASS__, Log::HISTORY_PLUGIN + $action);
 }
 function post_deleteFromDB()
 {
     global $LANG;
     // Add log entry in the ticket
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = addslashes($LANG['validation'][30] . " " . getUserName($this->fields["users_id_validate"]));
     Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), HISTORY_LOG_SIMPLE_MESSAGE);
 }
Esempio n. 8
0
 static function cloneItem(array $param)
 {
     // Sanity check
     if (!isset($param['itemtype']) || !isset($param['id']) || !isset($param['name']) || !array_key_exists($param['itemtype'], self::$clone_types) || empty($param['name']) || !($item = getItemForItemtype($param['itemtype']))) {
         return false;
     }
     // Read original and prepare clone
     $item->check($param['id'], 'r');
     $input = ToolBox::addslashes_deep($item->fields);
     $input['name'] = $param['name'];
     $input['_add'] = 1;
     $input['_old_id'] = $input['id'];
     unset($input['id']);
     if ($item->isEntityAssign()) {
         $input['entities_id'] = $_SESSION['glpiactive_entity'];
     }
     // Manage NULL fields in original
     foreach ($input as $k => $v) {
         if (is_null($input[$k])) {
             $input[$k] = "NULL";
         }
     }
     // Specific to itemtype - before clone
     if (method_exists(self::$clone_types[$param['itemtype']], 'preClone')) {
         $input = call_user_func(array(self::$clone_types[$param['itemtype']], 'preClone'), $item, $input);
     }
     // Clone
     $clone = clone $item;
     $clone->check(-1, 'w', $input);
     $new = $clone->add($input);
     // Specific to itemtype - after clone
     if (method_exists(self::$clone_types[$param['itemtype']], 'postClone')) {
         call_user_func(array(self::$clone_types[$param['itemtype']], 'postClone'), $clone, $param['id']);
     }
     Plugin::doHook('item_clone', $clone);
     // History
     if ($clone->dohistory) {
         $changes[0] = '0';
         $changes[1] = '';
         $changes[2] = addslashes(sprintf(__('%1$s %2$s'), __('Clone of', 'behaviors'), $item->getNameID(0, true)));
         Log::history($clone->getID(), $clone->getType(), $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
     }
 }
 /**
  * Restore an item trashed in the database.
  *
  * @param $input array : the _POST vars returned by the item form when press restore
  * @param $history boolean : do history log ?
  *
  * @return boolean : true on success
  **/
 function restore($input, $history = 1)
 {
     if (!$this->getFromDB($input[$this->getIndexName()])) {
         return false;
     }
     if (isset($input['restore'])) {
         $input['_restore'] = $input['restore'];
         unset($input['restore']);
     }
     // Store input in the object to be available in all sub-method / hook
     $this->input = $input;
     doHook("pre_item_restore", $this);
     if ($this->restoreInDB()) {
         $this->addMessageOnRestoreAction();
         if ($this->dohistory && $history) {
             $changes[0] = 0;
             $changes[1] = $changes[2] = "";
             Log::history($this->input["id"], $this->getType(), $changes, 0, HISTORY_RESTORE_ITEM);
         }
         $this->post_restoreItem();
         doHook("item_restore", $this);
         return true;
     }
     return false;
 }
Esempio n. 10
0
 /**
  * Standard method execution : checks if client can execute method + manage session
  *
  * @param $method string method name
  * @param $params array the method parameters
  * @param $protocol the communication protocol used
  *
  * @return array the method response
  **/
 function execute($method, $params, $protocol)
 {
     global $DB, $WEBSERVICES_METHOD, $TIMER_DEBUG;
     // Don't display error in result
     set_error_handler(array('Toolbox', 'userErrorHandlerNormal'));
     ini_set('display_errors', 'Off');
     $iptxt = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
     $ipnum = strstr($iptxt, ':') === false ? ip2long($iptxt) : '';
     if (isset($_SESSION["MESSAGE_AFTER_REDIRECT"])) {
         // Avoid to keep "info" message between call
         $_SESSION["MESSAGE_AFTER_REDIRECT"] = '';
     }
     $plug = new Plugin();
     if ($plug->isActivated('webservices')) {
         if (isset($params['session'])) {
             self::setSession($params['session']);
         }
         // Build query for security check
         $sql = "SELECT *\n                 FROM `glpi_plugin_webservices_clients`\n                 WHERE '" . addslashes($method) . "' REGEXP pattern\n                       AND `is_active` = '1' ";
         if ($ipnum) {
             $sql .= " AND (`ip_start` IS NULL\n                            OR (`ip_start` <= '{$ipnum}' AND `ip_end` >= '{$ipnum}'))";
         } else {
             $sql .= " AND `ipv6` = '" . addslashes($iptxt) . "'";
         }
         if (isset($params["username"])) {
             $username = addslashes($params["username"]);
             $password = md5(isset($params["password"]) ? $params["password"] : '');
             $sql .= " AND (`username` IS NULL\n                               OR (`username` = '{$username}' AND `password` = '{$password}'))";
             unset($params["username"]);
             unset($params["password"]);
         } else {
             $username = '******';
             $sql .= " AND `username` IS NULL ";
         }
         $deflate = $debug = $log = false;
         $entities = array();
         if (Session::getLoginUserID() && isset($_SESSION['glpiactiveentities'])) {
             $username = $_SESSION['glpiname'];
             // for log (no t for SQL request)
         }
         foreach ($DB->request($sql) as $data) {
             // Check matching rules
             // Store entities for not authenticated user
             if (!Session::getLoginUserID()) {
                 if ($data['is_recursive']) {
                     foreach (getSonsOf("glpi_entities", $data['entities_id']) as $entity) {
                         $entities[$entity] = $entity;
                     }
                 } else {
                     $entities[$data['entities_id']] = $data['entities_id'];
                 }
             }
             // Where to log
             if ($data["do_log"] == 2) {
                 // Log to file
                 $log = LOGFILENAME;
             } else {
                 if ($data["do_log"] == 1) {
                     // Log to History
                     $log = $data["id"];
                 }
             }
             $debug = $data['debug'];
             $deflate = $data['deflate'];
         }
         $callname = '';
         // Always log when connection denied
         if (!Session::getLoginUserID() && !count($entities)) {
             $resp = self::Error($protocol, 1, __('Access denied'));
             // log to file (not macthing config to use history)
             Toolbox::logInFile(LOGFILENAME, __('Access denied') . " ({$username}, {$iptxt}, {$method}, {$protocol})\n");
         } else {
             // Allowed
             if (!Session::getLoginUserID()) {
                 // TODO : probably more data should be initialized here
                 $_SESSION['glpiactiveentities'] = $entities;
             }
             // Log if configured
             if (is_numeric($log)) {
                 $changes[0] = 0;
                 $changes[1] = "";
                 $changes[2] = __('Connection') . " ({$username}, {$iptxt}, {$method}, {$protocol})";
                 Log::history($log, 'PluginWebservicesClient', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
             } else {
                 if ($log && !$debug) {
                     Toolbox::logInFile($log, __('Connection') . " ({$username}, {$iptxt}, {$method})\n");
                 }
             }
             $defserver = ini_get('zlib.output_compression');
             if ($deflate && !$defserver) {
                 // Globally off, try to enable for this client
                 // This only work on PHP > 5.3.0
                 ini_set('zlib.output_compression', 'On');
             }
             if (!$deflate && $defserver) {
                 // Globally on, disable for this client
                 ini_set('zlib.output_compression', 'Off');
             }
             if (!isset($WEBSERVICES_METHOD[$method])) {
                 $resp = self::Error($protocol, 2, "Unknown method ({$method})");
                 Toolbox::logInFile(LOGFILENAME, "Unknown method ({$method})\n");
             } else {
                 if (is_callable($call = $WEBSERVICES_METHOD[$method], false, $callname)) {
                     $resp = call_user_func($WEBSERVICES_METHOD[$method], $params, $protocol);
                     Toolbox::logInFile(LOGFILENAME, "Execute method:{$method} ({$protocol}), function:{$callname}, " . "duration:" . $TIMER_DEBUG->getTime() . ", size:" . strlen(serialize($resp)) . "\n");
                 } else {
                     $resp = self::Error($protocol, 3, "Unknown internal function for {$method}", $protocol);
                     Toolbox::logInFile(LOGFILENAME, "Unknown internal function for {$method}\n");
                 }
             }
         }
         // Allowed
         if ($debug) {
             Toolbox::logInFile(LOGFILENAME, __('Connection') . ": {$username}, {$iptxt}\n" . "Protocol: {$protocol}, Method: {$method}, Function: {$callname}\n" . "Params: " . (count($params) ? print_r($params, true) : "none\n") . "Compression: Server:{$defserver}/" . ini_get('zlib.output_compression') . ", Config:{$deflate}, Agent:" . (isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '?') . "\nDuration: " . $TIMER_DEBUG->getTime() . "\nResponse size: " . strlen(serialize($resp)) . "\nResponse content: " . print_r($resp, true));
         }
     } else {
         $resp = self::Error($protocol, 4, "Server not ready", $protocol);
     }
     // Activated
     return $resp;
 }
Esempio n. 11
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['_planningrecall'])) {
         $this->input['_planningrecall']['items_id'] = $this->fields['id'];
         PlanningRecall::manageDatas($this->input['_planningrecall']);
     }
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->fields["begin"]) && !empty($this->fields["begin"])) {
         Planning::checkAlreadyPlanned($this->fields["users_id_tech"], $this->fields["begin"], $this->fields["end"], array($this->getType() => array($this->fields["id"])));
     }
     if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
         $donotif = false;
     }
     $this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()]);
     if (isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
     }
     if (!empty($this->fields['begin']) && ($this->input["_job"]->fields["status"] == CommonITILObject::INCOMING || $this->input["_job"]->fields["status"] == CommonITILObject::ASSIGNED)) {
         $input2['id'] = $this->input["_job"]->getID();
         $input2['status'] = CommonITILObject::PLANNED;
         $input2['_disablenotif'] = true;
         $this->input["_job"]->update($input2);
     }
     if ($donotif) {
         $options = array('task_id' => $this->fields["id"], 'is_private' => $this->isPrivate());
         NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
     }
     // Add log entry in the ITIL object
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField($this->input["_job"]->getForeignKeyField()), $this->input["_job"]->getTYpe(), $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
Esempio n. 12
0
 function post_addItem()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
         $donotif = false;
     }
     $this->input["_job"]->updateDateMod($this->input["tickets_id"]);
     if (isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $this->input["_job"]->updateActionTime($this->input["tickets_id"]);
     }
     //      if ($this->input["_isadmin"] && $this->input["_type"]!="update") {
     if (isset($this->input["_plan"])) {
         $this->input["_plan"]['tickettasks_id'] = $this->fields['id'];
         $this->input["_plan"]['tickets_id'] = $this->input['tickets_id'];
         $this->input["_plan"]['_nomail'] = 1;
         $pt = new TicketPlanning();
         if (!$pt->add($this->input["_plan"])) {
             return false;
         }
     }
     if ($donotif) {
         $options = array('task_id' => $this->fields["id"]);
         NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
     }
     // Add log entry in the ticket
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), HISTORY_ADD_SUBITEM);
 }
 function post_deleteFromDB()
 {
     // Update to blank networking item
     // clean datas of linked ports if network one
     $np1 = new NetworkPort();
     $np2 = new NetworkPort();
     if ($np1->getFromDB($this->fields['networkports_id_1']) && $np2->getFromDB($this->fields['networkports_id_2'])) {
         $npnet = NULL;
         $npdev = NULL;
         if ($np1->fields["itemtype"] != 'NetworkEquipment' && $np2->fields["itemtype"] == 'NetworkEquipment') {
             $npnet = $np2;
             $npdev = $np1;
         }
         if ($np2->fields["itemtype"] != 'NetworkEquipment' && $np1->fields["itemtype"] == 'NetworkEquipment') {
             $npnet = $np2;
             $npdev = $np1;
         }
         if ($npnet && $npdev) {
             // If addresses are egal, was copied from device in GLPI 0.71 : clear it
             // Unset MAC and IP from networking device
             if ($npnet->fields['mac'] == $npdev->fields['mac']) {
                 $npnet->update(array('id' => $npnet->fields['id'], 'mac' => ''));
             }
             if ($np1->fields['ip'] == $np2->fields['ip']) {
                 $npnet->update(array('id' => $npnet->fields['id'], 'ip' => '', 'netmask' => '', 'subnet' => '', 'gateway' => ''));
             }
             // Unset netpoint from common device
             $npdev->update(array('id' => $npdev->fields['id'], 'netpoints_id' => 0));
         }
         // Manage history
         $name = NOT_AVAILABLE;
         $dohistory = false;
         if (class_exists($np2->fields["itemtype"])) {
             $item = new $np2->fields["itemtype"]();
             if ($item->getFromDB($np2->fields["items_id"])) {
                 $name = $item->getName();
                 $dohistory = $item->dohistory;
             }
         }
         if ($dohistory) {
             $changes[0] = 0;
             $changes[1] = $name;
             $changes[2] = '';
             if ($np1->fields["itemtype"] == 'NetworkEquipment') {
                 $changes[1] = "#" . $np1->fields["name"] . " > " . $changes[1];
             }
             if ($np2->fields["itemtype"] == 'NetworkEquipment') {
                 $changes[1] = $changes[1] . " > #" . $np2->fields["name"];
             }
             Log::history($np1->fields["items_id"], $np1->fields["itemtype"], $changes, $np2->fields["itemtype"], HISTORY_DISCONNECT_DEVICE);
         }
         $name = NOT_AVAILABLE;
         $dohistory = false;
         if (class_exists($np1->fields["itemtype"])) {
             $item = new $np1->fields["itemtype"]();
             if ($item->getFromDB($np1->fields["items_id"])) {
                 $name = $item->getName();
                 $dohistory = $item->dohistory;
             }
         }
         if ($dohistory) {
             $changes[0] = 0;
             $changes[1] = $name;
             $changes[2] = '';
             if ($np2->fields["itemtype"] == 'NetworkEquipment') {
                 $changes[1] = "#" . $np2->fields["name"] . " > " . $changes[1];
             }
             if ($np1->fields["itemtype"] == 'NetworkEquipment') {
                 $changes[1] = $changes[1] . " > #" . $np1->fields["name"];
             }
             Log::history($np2->fields["items_id"], $np2->fields["itemtype"], $changes, $np1->fields["itemtype"], HISTORY_DISCONNECT_DEVICE);
         }
     }
 }
Esempio n. 14
0
 /**
  * Restore an item put in the dustbin in the database.
  *
  * @param $input     array    the _POST vars returned by the item form when press restore
  * @param $history   boolean  do history log ? (default 1)
  *
  * @return boolean : true on success
  **/
 function restore(array $input, $history = 1)
 {
     if (!$this->getFromDB($input[static::getIndexName()])) {
         return false;
     }
     if (isset($input['restore'])) {
         $input['_restore'] = $input['restore'];
         unset($input['restore']);
     }
     // Store input in the object to be available in all sub-method / hook
     $this->input = $input;
     Plugin::doHook("pre_item_restore", $this);
     if ($this->restoreInDB()) {
         $this->addMessageOnRestoreAction();
         if ($this->dohistory && $history) {
             $changes[0] = 0;
             $changes[1] = $changes[2] = "";
             $logaction = Log::HISTORY_RESTORE_ITEM;
             if ($this->useDeletedToLockIfDynamic() && $this->isDynamic()) {
                 $logaction = Log::HISTORY_UNLOCK_ITEM;
             }
             Log::history($this->input["id"], $this->getType(), $changes, 0, $logaction);
         }
         $this->post_restoreItem();
         Plugin::doHook("item_restore", $this);
         if ($this->mailqueueonaction) {
             QueuedMail::forceSendFor($this->getType(), $this->fields['id']);
         }
         return true;
     }
     return false;
 }
Esempio n. 15
0
 /**
  * UnLink a cartridge linked to a printer
  *
  * UnLink the cartridge identified by $ID
  *
  * @param $ID : cartridge identifier
  *
  * @return boolean
  **/
 function uninstall($ID)
 {
     global $DB;
     if ($this->getFromDB($ID)) {
         $printer = new Printer();
         $toadd = '';
         if ($printer->getFromDB($this->getField("printers_id"))) {
             $toadd .= ", `pages` = '" . $printer->fields['last_pages_counter'] . "' ";
         }
         $query = "UPDATE`" . $this->getTable() . "`\n                   SET `date_out` = '" . date("Y-m-d") . "'\n                       {$toadd}\n                   WHERE `id`='{$ID}'";
         if ($result = $DB->query($query) && $DB->affected_rows() > 0) {
             $changes[0] = '0';
             $changes[1] = '';
             $changes[2] = __('Uninstalling a cartridge');
             Log::history($this->getField("printers_id"), 'Printer', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
             return true;
         }
         return false;
     }
 }
Esempio n. 16
0
 function post_deleteFromDB()
 {
     $parent = $this->fields[$this->getForeignKeyField()];
     if ($parent && $this->dohistory) {
         $changes[0] = '0';
         $changes[1] = addslashes($this->getNameID());
         $changes[2] = '';
         Log::history($parent, $this->getType(), $changes, $this->getType(), Log::HISTORY_DELETE_SUBITEM);
     }
 }
Esempio n. 17
0
 if (isset($_POST["restore"])) {
     $account->check($_POST['id'], 'w');
     $account->restore($_POST);
     $account->redirectToList();
 } else {
     if (isset($_POST["purge"])) {
         $account->check($_POST['id'], 'w');
         $account->delete($_POST, 1);
         $account->redirectToList();
     } else {
         if (isset($_POST['idcrypt'])) {
             //History log
             $changes[0] = 15;
             $changes[1] = $_POST['nameP'];
             $changes[2] = __('Uncrypted', 'accounts');
             Log::history($_POST['idcrypt'], "PluginAccountsAccount", $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
         } else {
             if (isset($_POST["additem"])) {
                 if (!empty($_POST['itemtype'])) {
                     $account_item->check(-1, 'w', $_POST);
                     $account_item->addItem($_POST);
                 }
                 Html::back();
             } else {
                 if (isset($_POST["deleteitem"])) {
                     foreach ($_POST["item"] as $key => $val) {
                         $input = array('id' => $key);
                         if ($val == 1) {
                             $account_item->check($key, 'w');
                             $account_item->delete($input);
                         }
 public function post_purgeItem($history = 1)
 {
     $changes[0] = '0';
     $changes[1] = '';
     $changes[2] = sprintf(__('%1$s deleted closing informations', 'moreticket'), getUserName(Session::getLoginUserID()));
     Log::history($this->fields['tickets_id'], 'Ticket', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
     parent::post_updateItem();
 }
 public function deleteItem($input)
 {
     $this->check($input['id'], UPDATE);
     $connections_id = $this->getField('plugin_connections_connections_id');
     $items_id = $this->getField('items_id');
     if ($this->delete($input)) {
         // History Log into PluginConnectionsConnection
         $item = new NetworkEquipment();
         $item->getFromDB($items_id);
         $changes[0] = 0;
         $changes[1] = $item->getNameID(array('forceid' => true));
         $changes[2] = '';
         Log::history($connections_id, 'PluginConnectionsConnection', $changes, 'NetworkEquipment', 16);
         // History Log into NetworkEquipment
         $item = new PluginConnectionsConnection();
         $item->getFromDB($connections_id);
         $changes[0] = 0;
         $changes[1] = $item->getNameID(array('forceid' => true));
         $changes[2] = '';
         Log::history($items_id, 'NetworkEquipment', $changes, 'PluginConnectionsConnection', 16);
     }
 }
Esempio n. 20
0
// here we are going to try to unlock the given object
// url should be of the form: 'http://.../.../unlockobject.php?unlock=1[&force=1]&id=xxxxxx'
// or url should be of the form 'http://.../.../unlockobject.php?requestunlock=1&id=xxxxxx'
// to send notification to locker of object
$AJAX_INCLUDE = 1;
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$ret = 0;
if (isset($_GET['unlock']) && isset($_GET["id"])) {
    // then we may have something to unlock
    $ol = new ObjectLock();
    if ($ol->getFromDB($_GET["id"]) && $ol->deleteFromDB(1)) {
        if (isset($_GET['force'])) {
            Log::history($ol->fields['items_id'], $ol->fields['itemtype'], array(0, '', ''), 0, Log::HISTORY_UNLOCK_ITEM);
        }
        $ret = 1;
    }
} else {
    if (isset($_GET['requestunlock']) && isset($_GET["id"])) {
        // the we must ask for unlock
        $ol = new ObjectLock();
        if ($ol->getFromDB($_GET["id"])) {
            NotificationEvent::raiseEvent('unlock', $ol);
            $ret = 1;
        }
    } else {
        if (isset($_GET['lockstatus']) && isset($_GET["id"])) {
            $ol = new ObjectLock();
            if ($ol->getFromDB($_GET["id"])) {
Esempio n. 21
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['_planningrecall'])) {
         $this->input['_planningrecall']['items_id'] = $this->fields['id'];
         PlanningRecall::manageDatas($this->input['_planningrecall']);
     }
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->fields["begin"]) && !empty($this->fields["begin"])) {
         Planning::checkAlreadyPlanned($this->fields["users_id_tech"], $this->fields["begin"], $this->fields["end"], array($this->getType() => array($this->fields["id"])));
         $calendars_id = Entity::getUsedConfig('calendars_id', $this->input["_job"]->fields['entities_id']);
         $calendar = new Calendar();
         // Using calendar
         if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
             if (!$calendar->isAWorkingHour(strtotime($this->fields["begin"]))) {
                 Session::addMessageAfterRedirect(__('Start of the selected timeframe is not a working hour.'), false, ERROR);
             }
             if (!$calendar->isAWorkingHour(strtotime($this->fields["end"]))) {
                 Session::addMessageAfterRedirect(__('End of the selected timeframe is not a working hour.'), false, ERROR);
             }
         }
     }
     $this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()]);
     if (isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
     }
     //change status only if input change
     if (isset($this->input['_status']) && $this->input['_status'] != $this->input['_job']->fields['status']) {
         $update['status'] = $this->input['_status'];
         $update['id'] = $this->input['_job']->fields['id'];
         $update['_disablenotif'] = true;
         $this->input['_job']->update($update);
     }
     if (!empty($this->fields['begin']) && $this->input["_job"]->isStatusExists(CommonITILObject::PLANNED) && ($this->input["_job"]->fields["status"] == CommonITILObject::INCOMING || $this->input["_job"]->fields["status"] == CommonITILObject::ASSIGNED)) {
         $input2['id'] = $this->input["_job"]->getID();
         $input2['status'] = CommonITILObject::PLANNED;
         $input2['_disablenotif'] = true;
         $this->input["_job"]->update($input2);
     }
     if ($donotif) {
         $options = array('task_id' => $this->fields["id"], 'is_private' => $this->isPrivate());
         NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
     }
     // Add log entry in the ITIL object
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField($this->input["_job"]->getForeignKeyField()), $this->input["_job"]->getTYpe(), $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
 function post_addItem()
 {
     global $CFG_GLPI, $LANG;
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
         $donotif = false;
     }
     $this->input["_job"]->updateDateMod($this->input["tickets_id"]);
     if (isset($this->input["_close"]) && $this->input["_close"] && $this->input["_job"]->fields["status"] == 'solved') {
         $update['id'] = $this->input["_job"]->fields['id'];
         $update['status'] = 'closed';
         $update['closedate'] = $_SESSION["glpi_currenttime"];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if (isset($this->input["_reopen"]) && $this->input["_reopen"] && in_array($this->input["_job"]->fields["status"], array('solved', 'waiting'))) {
         if ($this->input["_job"]->countUsers(Ticket::ASSIGN) > 0 || $this->input["_job"]->countGroups(Ticket::ASSIGN) > 0 || $this->input["_job"]->fields["suppliers_id_assign"] > 0) {
             $update['status'] = 'assign';
         } else {
             $update['status'] = 'new';
         }
         $update['id'] = $this->input["_job"]->fields['id'];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if ($donotif) {
         $options = array('followup_id' => $this->fields["id"]);
         NotificationEvent::raiseEvent("add_followup", $this->input["_job"], $options);
     }
     // Add log entry in the ticket
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), HISTORY_ADD_SUBITEM);
 }
Esempio n. 23
0
 function post_deleteFromDB()
 {
     $parent = $this->fields['locations_id'];
     if ($parent) {
         $changes[0] = '0';
         $changes[1] = addslashes($this->getNameID());
         $changes[2] = '';
         Log::history($parent, 'Location', $changes, $this->getType(), Log::HISTORY_DELETE_SUBITEM);
     }
 }
 /**
  * Create a ticket based on ticket recurrent infos
  *
  * @param $data array data of a entry of glpi_ticketrecurrents
  *
  * @return boolean
  **/
 static function createTicket($data)
 {
     $result = false;
     $tt = new TicketTemplate();
     // Create ticket based on ticket template and entity information of ticketrecurrent
     if ($tt->getFromDB($data['tickettemplates_id'])) {
         // Get default values for ticket
         $input = Ticket::getDefaultValues($data['entities_id']);
         // Apply tickettemplates predefined values
         $ttp = new TicketTemplatePredefinedField();
         $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true);
         if (count($predefined)) {
             foreach ($predefined as $predeffield => $predefvalue) {
                 $input[$predeffield] = $predefvalue;
             }
         }
         // Set date to creation date
         $createtime = strtotime($data['next_creation_date']) + $data['create_before'];
         $input['date'] = date('Y-m-d H:i:s', $createtime);
         if (isset($predefined['date'])) {
             $input['date'] = Html::computeGenericDateTimeSearch($predefined['date'], false, $createtime);
         }
         // Compute due_date if predefined based on create date
         if (isset($predefined['due_date'])) {
             $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime);
         }
         // Set entity
         $input['entities_id'] = $data['entities_id'];
         $input['_auto_import'] = true;
         $ticket = new Ticket();
         $input = Toolbox::addslashes_deep($input);
         if ($tid = $ticket->add($input)) {
             $msg = sprintf(__('Ticket %d successfully created'), $tid);
             $result = true;
         } else {
             $msg = __('Ticket creation failed (check mandatory fields)');
         }
     } else {
         $msg = __('Ticket creation failed (no template)');
     }
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = addslashes($msg);
     Log::history($data['id'], __CLASS__, $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
     // Compute next creation date
     $tr = new self();
     if ($tr->getFromDB($data['id'])) {
         $input = array();
         $input['id'] = $data['id'];
         $input['next_creation_date'] = $tr->computeNextCreationDate($data['begin_date'], $data['end_date'], $data['periodicity'], $data['create_before'], $data['calendars_id']);
         $tr->update($input);
     }
     return $result;
 }
Esempio n. 25
0
 /**
  * @param type
  * @param $computer_id
  * @param $action          (default 'uninstall'
  * @param $ocs_id          (default '')
  **/
 static function addUninstallLog($type, $computer_id, $action = 'uninstall', $ocs_id = '')
 {
     $changes[0] = 0;
     $changes[1] = "";
     switch ($action) {
         case 'uninstall':
             $changes[2] = __('Item is now uninstalled', 'uninstall');
             break;
         case 'replaced_by':
             $changes[2] = __('Item replaced by a new one', 'uninstall');
             break;
         case 'replace':
             $changes[2] = __('Item replacing an old one', 'uninstall');
             break;
         case 'removeFromOCS':
             $changes[2] = addslashes(sprintf(__('%1$s %2$s'), __('Removed from OCSNG with ID', 'uninstall'), $ocs_id));
             break;
     }
     Log::history($computer_id, $type, $changes, __CLASS__, Log::HISTORY_PLUGIN);
 }
 function post_deleteFromDB()
 {
     if (isset($this->input['_no_history'])) {
         return false;
     }
     $changes[0] = '0';
     $changes[1] = addslashes($this->getName());
     $changes[2] = '';
     Log::history($this->fields['users_id'], 'User', $changes, get_class($this), HISTORY_DELETE_SUBITEM);
 }
Esempio n. 27
0
 /**
  * @param $IDs       array
  * @param $authtype        (default 1)
  * @param $server          (default -1)
  *
  * @return boolean
  **/
 static function changeAuthMethod($IDs = array(), $authtype = 1, $server = -1)
 {
     global $DB;
     if (!Session::haveRight(self::$rightname, self::UPDATEAUTHENT)) {
         return false;
     }
     if (!empty($IDs) && in_array($authtype, array(Auth::DB_GLPI, Auth::LDAP, Auth::MAIL, Auth::EXTERNAL))) {
         $where = implode("','", $IDs);
         $query = "UPDATE `glpi_users`\n                   SET `authtype` = '{$authtype}',\n                       `auths_id` = '{$server}',\n                       `password` = '',\n                       `is_deleted_ldap` = '0'\n                   WHERE `id` IN ('{$where}')";
         if ($DB->query($query)) {
             foreach ($IDs as $ID) {
                 $changes[0] = 0;
                 $changes[1] = '';
                 $changes[2] = addslashes(sprintf(__('%1$s: %2$s'), __('Update authentification method to'), Auth::getMethodName($authtype, $server)));
                 Log::history($ID, __CLASS__, $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
             }
             return true;
         }
     }
     return false;
 }
Esempio n. 28
0
 /**
  * Log usage of the api into glpi historical or log files (defined by api config)
  * It stores the ip and the username of the current session.
  *
  * @param $endpoint   string  function called by api to log (default '')
  */
 private function logEndpointUsage($endpoint = "")
 {
     $username = "";
     if (isset($_SESSION['glpiname'])) {
         $username = "******" . $_SESSION['glpiname'] . ")";
     }
     $apiclient = new APIClient();
     if ($apiclient->getFromDB($this->apiclients_id)) {
         $changes[0] = 0;
         $changes[1] = "";
         $changes[2] = "Enpoint '{$endpoint}' called by " . $this->iptxt . " {$username}";
         switch ($apiclient->fields['dolog_method']) {
             case APIClient::DOLOG_HISTORICAL:
                 Log::history($this->apiclients_id, 'APIClient', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
                 break;
             case APIClient::DOLOG_LOGS:
                 Toolbox::logInFile("api", $changes[2] . "\n");
                 break;
         }
     }
 }
Esempio n. 29
0
 /**
  * @param $users_id
  **/
 static function manageDeletedUserInLdap($users_id)
 {
     global $CFG_GLPI;
     //User is present in DB but not in the directory : it's been deleted in LDAP
     $tmp['id'] = $users_id;
     $myuser = new User();
     switch ($CFG_GLPI['user_deleted_ldap']) {
         //DO nothing
         default:
         case 0:
             break;
             //Put user in dustbin
         //Put user in dustbin
         case 1:
             $myuser->delete($tmp);
             break;
             //Delete all user dynamic habilitations and groups
         //Delete all user dynamic habilitations and groups
         case 2:
             Profile_User::deleteRights($users_id, true);
             Group_User::deleteGroups($users_id, true);
             break;
             //Deactivate the user
         //Deactivate the user
         case 3:
             $tmp['is_active'] = 0;
             $myuser->update($tmp);
             break;
     }
     $changes[0] = '0';
     $changes[1] = '';
     $changes[2] = __('Deleted user in LDAP directory');
     Log::history($users_id, 'User', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
 }
 function post_updateItem($history = 1)
 {
     if (!$history || isset($this->input['_no_history']) && $this->input['_no_history'] || !in_array('specificity', $this->updates)) {
         return false;
     }
     $changes[0] = 0;
     $changes[1] = addslashes($this->oldvalues['specificity']);
     $changes[2] = $this->fields['specificity'];
     // history log
     Log::history($this->fields['computers_id'], 'Computer', $changes, $this->input['_itemtype'], HISTORY_UPDATE_DEVICE);
 }