/**
  * @test
  */
 public function ImportNetworkEquipment()
 {
     global $DB;
     self::restore_database();
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkEquipment = new NetworkEquipment();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1);
     $unmanageds_id = $pfUnmanaged->add($input);
     // * Add networkport
     $input = array();
     $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
     $input['items_id'] = $unmanageds_id;
     $input['instantiation_type'] = 'NetworkPortEthernet';
     $input['name'] = 'general';
     $input['mac'] = '00:00:00:43:ae:0f';
     $input['is_dynamic'] = 1;
     $networkports_id = $networkPort->add($input);
     $input = array();
     $input['items_id'] = $networkports_id;
     $input['itemtype'] = 'NetworkPort';
     $input['name'] = '';
     $input['is_dynamic'] = 1;
     $networknames_id = $networkName->add($input);
     $input = array();
     $input['entities_id'] = 0;
     $input['itemtype'] = 'NetworkName';
     $input['items_id'] = $networknames_id;
     $input['name'] = '192.168.20.1';
     $input['is_dynamic'] = 1;
     $iPAddress->add($input);
     $pfUnmanaged->import($unmanageds_id);
     $cnt = countElementsInTable("glpi_networkequipments");
     $this->assertEquals(1, $cnt, "May have network equipment added");
     $cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds");
     $this->assertEquals(0, $cnt, "Unknown device may be deleted");
     $networkEquipment->getFromDB(1);
     $this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial");
     $this->assertEquals('switch', $networkEquipment->fields['name'], "Name");
     $this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic");
     $this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id");
     $this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment");
     $networkPort->getFromDB(1);
     $a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1');
     $this->assertEquals($a_reference, $networkPort->fields, "Networkport");
     $networkName->getFromDB(1);
     $a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => '');
     $this->assertEquals($a_reference, $networkName->fields, "Networkname");
     $iPAddress->getFromDB(1);
     $a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment');
     $this->assertEquals($a_reference, $iPAddress->fields, "IPAddress");
 }
 /**
  * Override standard validation and sending notification to send the good PDF reports with 
  * appropriate rigths.
  * 
  * @see NotificationTarget::validateSendTo()
  * 
  * @param string $event notification event
  * @param Array $infos Current user informations
  * @param Boolean $notify_me Notify the current user of his own actions ?
  * 
  * @return boolean false to prevent standard mail sending
  */
 function validateSendTo($event, array $infos, $notify_me = false)
 {
     global $DB;
     if (isset($infos['users_id'])) {
         // save session variables
         $saved_session = $_SESSION;
         // Get current user full informations
         $user = new User();
         $user->getFromDB($infos['users_id']);
         // inialize session for user to build the proper PDF report
         unset($_SESSION['glpiprofiles'], $_SESSION['glpiactiveentities'], $_SESSION['glpiactiveprofile']);
         Session::initEntityProfiles($infos['users_id']);
         // Use default profile if exist
         if (isset($_SESSION['glpiprofiles'][$user->fields['profiles_id']])) {
             Session::changeProfile($user->fields['profiles_id']);
             // Else use first
         } else {
             Session::changeProfile(key($_SESSION['glpiprofiles']));
         }
         $user_name = $infos['username'] . '_';
         $file_name = $this->_buildPDF($user_name);
         $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications/' . $file_name;
         $mmail = new NotificationMail();
         $mmail->AddCustomHeader("Auto-Submitted: auto-generated");
         // For exchange
         $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN");
         // Get current entity administrator info to send the email from him
         $admin = $this->getSender();
         $mmail->From = $admin['email'];
         $mmail->FromName = $admin['name'];
         // Attach pdf to mail
         $mmail->AddAttachment($path, $file_name);
         // Get content infos
         $query = 'SELECT * 
               FROM glpi_notificationtemplatetranslations
               WHERE notificationtemplates_id = (
                  SELECT id 
                  FROM glpi_notificationtemplates 
                  WHERE itemtype = "PluginMreportingNotification"
               )
               AND (language LIKE "' . $_SESSION['glpilanguage'] . '" OR language LIKE "")
               ORDER BY language DESC
               LIMIT 0, 1';
         $result = $DB->query($query);
         $translation = $result->fetch_array();
         $mmail->isHTML(true);
         $mmail->Subject = $translation['subject'];
         $mmail->Body = $translation['content_html'];
         $mmail->AltBody = $translation['content_text'];
         $mmail->AddAddress($infos['email']);
         if ($mmail->Send()) {
         }
         //restore session
         unset($_SESSION);
         $_SESSION = $saved_session;
     }
     return false;
 }
                    $notfound["{$classname}"] = TRUE;
                }
            }
        }
    }
    spl_autoload_register('glpiautoload');
    include GLPI_ROOT . "/config/based_config.php";
    include GLPI_ROOT . "/inc/includes.php";
    restore_error_handler();
    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', 'On');
}
ini_set("memory_limit", "-1");
ini_set("max_execution_time", "0");
$_SESSION['glpiprofiles'] = array('4' => array('entities' => 0));
Session::changeProfile(4);
$_SESSION["glpi_plugin_fusioninventory_profile"]['unmanaged'] = 'w';
$_SESSION['glpiactiveentities'] = array(0, 1);
require_once 'GLPIInstall/AllTests.php';
require_once 'FusinvInstall/AllTests.php';
require_once 'GLPIlogs/AllTests.php';
require_once '1_Unit/FormatConvertData.php';
require_once '1_Unit/SoftwareUpdate.php';
require_once '1_Unit/ComputerTransformation.php';
require_once '1_Unit/ComputerUpdate.php';
require_once '1_Unit/PrinterTransformation.php';
require_once '1_Unit/PrinterUpdate.php';
require_once '1_Unit/NetworkEquipmentTransformation.php';
require_once '1_Unit/NetworkEquipmentUpdate.php';
require_once '1_Unit/NetworkEquipmentUpdateDiscovery.php';
require_once '1_Unit/ComputerLog.php';
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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
// Change profile system
if (isset($_POST['newprofile'])) {
    if (isset($_SESSION["glpiprofiles"][$_POST['newprofile']])) {
        Session::changeProfile($_POST['newprofile']);
        if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
            if ($_SESSION['glpiactiveprofile']['create_ticket_on_login']) {
                Html::redirect($CFG_GLPI['root_doc'] . "/front/helpdesk.public.php?create_ticket=1");
            } else {
                Html::redirect($CFG_GLPI['root_doc'] . "/front/helpdesk.public.php");
            }
        }
        Html::redirect($_SERVER['PHP_SELF']);
    }
    Html::redirect(preg_replace("/entities_id.*/", "", $_SERVER['HTTP_REFERER']));
}
// Manage entity change
if (isset($_GET["active_entity"])) {
    if (!isset($_GET["is_recursive"])) {
        $_GET["is_recursive"] = 0;
Esempio n. 5
0
 /**
  * set a profile to active
  *
  * @param $params with theses options :
  *    - profiles_id : identifier of profile to set
  *
  * @return     boolean
  **/
 protected function changeActiveProfile($params = array())
 {
     $this->initEndpoint();
     $profiles_id = intval($params['profiles_id']);
     if (isset($_SESSION['glpiprofiles'][$profiles_id])) {
         return Session::changeProfile($profiles_id);
     }
 }
 /**
  * Change the current profile of an authenticated user
  *
  * @param $params array of options
  *  - profile : ID of the new profile
  * @param $protocol the communication protocol used
  *
  * @return a response ready to be encode
  *  - ID
  *  - name of the new profile
  **/
 static function methodSetMyProfile($params, $protocol)
 {
     if (isset($params['help'])) {
         return array('profile' => 'integer,mandatory', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!isset($params['profile'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'profile');
     }
     // TODO search for profile name if not an ID.
     $id = $params['profile'];
     if (isset($_SESSION['glpiprofiles'][$id]) && count($_SESSION['glpiprofiles'][$id]['entities'])) {
         Session::changeProfile($id);
         $resp = array('id' => $_SESSION['glpiactiveprofile']['id'], 'name' => $_SESSION['glpiactiveprofile']['name']);
     } else {
         return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', "profile={$id}");
     }
     return $resp;
 }
Esempio n. 7
0
 /**
  * Check right on CommonDBRelation object
  */
 public function testContact_Supplier()
 {
     global $DB;
     $DB->connect();
     $ent0 = $this->sharedFixture['entity'][0];
     $ent1 = $this->sharedFixture['entity'][1];
     $ent2 = $this->sharedFixture['entity'][2];
     // Super admin
     Session::changeProfile(4);
     $this->assertEquals(4, $_SESSION['glpiactiveprofile']['id']);
     $this->assertEquals(31, $_SESSION['glpiactiveprofile']['contact_enterprise']);
     // See all
     $this->assertTrue(Session::changeActiveEntities("all"));
     // Create some contacts
     $contact = new Contact();
     $idc[0] = $contact->add(array('name' => "Contact 1", 'entities_id' => $ent0, 'is_recursive' => 0));
     $this->assertGreaterThan(0, $idc[0]);
     $idc[1] = $contact->add(array('name' => "Contact 2", 'entities_id' => $ent0, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $idc[1]);
     $idc[2] = $contact->add(array('name' => "Contact 3", 'entities_id' => $ent1, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $idc[2]);
     $idc[3] = $contact->add(array('name' => "Contact 4", 'entities_id' => $ent2));
     $this->assertGreaterThan(0, $idc[3]);
     // Create some suppliers
     $supplier = new Supplier();
     $ids[0] = $supplier->add(array('name' => "Supplier 1", 'entities_id' => $ent0, 'is_recursive' => 0));
     $this->assertGreaterThan(0, $ids[0]);
     $ids[1] = $supplier->add(array('name' => "Supplier 2", 'entities_id' => $ent0, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $ids[1]);
     $ids[2] = $supplier->add(array('name' => "Supplier 3", 'entities_id' => $ent1));
     $this->assertGreaterThan(0, $ids[2]);
     $ids[3] = $supplier->add(array('name' => "Supplier 4", 'entities_id' => $ent2));
     $this->assertGreaterThan(0, $ids[3]);
     // Relation
     $rel = new Contact_Supplier();
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[0]);
     // root
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[0] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[0]);
     $this->assertTrue($rel->can($idr[0], READ));
     $this->assertTrue($rel->canEdit($idr[0]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[1] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[1]);
     $this->assertTrue($rel->can($idr[1], READ));
     $this->assertTrue($rel->canEdit($idr[1]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[2]);
     // child 1
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[3]);
     // child 2
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[0]);
     // root
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[2] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[2]);
     $this->assertTrue($rel->can($idr[2], READ));
     $this->assertTrue($rel->canEdit($idr[2]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[3] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[3]);
     $this->assertTrue($rel->can($idr[3], READ));
     $this->assertTrue($rel->canEdit($idr[3]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[2]);
     // child 1
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[4] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[4]);
     $this->assertTrue($rel->can($idr[4], READ));
     $this->assertTrue($rel->canEdit($idr[4]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[3]);
     // child 2
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[5] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[5]);
     $this->assertTrue($rel->can($idr[5], READ));
     $this->assertTrue($rel->canEdit($idr[5]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[6] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[6]);
     $this->assertTrue($rel->can($idr[6], READ));
     $this->assertTrue($rel->canEdit($idr[6]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[2]);
     // Child 1
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[7] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[7]);
     $this->assertTrue($rel->can($idr[7], READ));
     $this->assertTrue($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[3]);
     // Child 2
     $this->assertFalse($rel->can(-1, CREATE, $input));
     // See only in child entity 2 + parent if recursive
     $this->assertTrue(Session::changeActiveEntities($ent2));
     $this->assertFalse($rel->can($idr[0], READ));
     // root / root
     $this->assertFalse($rel->canEdit($idr[0]));
     $this->assertFalse($rel->can($idr[1], READ));
     // root / root rec
     $this->assertFalse($rel->canEdit($idr[1]));
     $this->assertFalse($rel->can($idr[2], READ));
     // root rec / root
     $this->assertFalse($rel->canEdit($idr[2]));
     $this->assertTrue($rel->can($idr[3], READ));
     // root rec / root rec
     $this->assertFalse($rel->canEdit($idr[3]));
     $this->assertFalse($rel->can($idr[4], READ));
     // root rec / child 1
     $this->assertFalse($rel->canEdit($idr[4]));
     $this->assertTrue($rel->can($idr[5], READ));
     // root rec / child 2
     $this->assertTrue($rel->canEdit($idr[5]));
     $this->assertFalse($rel->can($idr[6], READ));
     // child 1 / root rec
     $this->assertFalse($rel->canEdit($idr[6]));
     $this->assertFalse($rel->can($idr[7], READ));
     // child 1 / child 1
     $this->assertFalse($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[7] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[7]);
     $this->assertTrue($rel->can($idr[7], READ));
     $this->assertTrue($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[2]);
     // Child 1
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[3]);
     // Child 3
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[8] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[8]);
     $this->assertTrue($rel->can($idr[8], READ));
     $this->assertTrue($rel->canEdit($idr[8]));
 }
 /**
  * @test
  */
 public function UpdateNetworkEquipment()
 {
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     // Update 2nd time
     $pfCND = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $networkEquipment = new NetworkEquipment();
     $networkEquipment->getFromDB(1);
     $_SESSION['SOURCE_XMLDEVICE'] = $this->source_xmldevice;
     $pfCND->importDevice($networkEquipment);
 }
Esempio n. 9
0
 public static function reloadProfileRights() {
    if (isset($_SESSION['glpiactiveprofile']['id'])) {
       Session::changeProfile($_SESSION['glpiactiveprofile']['id']);
    }
 }