当前位置: 首页>>代码示例>>PHP>>正文


PHP IPAddress类代码示例

本文整理汇总了PHP中IPAddress的典型用法代码示例。如果您正苦于以下问题:PHP IPAddress类的具体用法?PHP IPAddress怎么用?PHP IPAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IPAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ImportNetworkEquipment

 /**
  * @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");
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:61,代码来源:UnmanagedImportTest.php

示例2: addIPAddress

 /**
  * @param $ipaddress IPAddress object
  **/
 static function addIPAddress(IPAddress $ipaddress)
 {
     $linkObject = new self();
     $input = array('ipaddresses_id' => $ipaddress->getID());
     $entity = $ipaddress->getEntityID();
     $ipnetworks_ids = IPNetwork::searchNetworksContainingIP($ipaddress, $entity);
     if ($ipnetworks_ids !== false) {
         // Beware that invalid IPaddresses don't have any valid address !
         foreach (IPNetwork::searchNetworksContainingIP($ipaddress, $entity) as $ipnetworks_id) {
             $input['ipnetworks_id'] = $ipnetworks_id;
             $linkObject->add($input);
         }
     }
 }
开发者ID:gaforeror,项目名称:glpi,代码行数:17,代码来源:ipaddress_ipnetwork.class.php

示例3: fromBinary

 public static function fromBinary(&$binaryData, &$offsetIndex = 0)
 {
     self::parseIdentifier($binaryData[$offsetIndex], Identifier::OCTETSTRING, $offsetIndex++);
     $contentLength = self::parseContentLength($binaryData, $offsetIndex);
     if ($contentLength < 2) {
         throw new ParserException('Can not parse Subject Alternative Names: The Sequence within the octet string after the Object identifier ' . OID::CERT_EXT_SUBJECT_ALT_NAME . " is too short ({$contentLength} octets)", $offsetIndex);
     }
     $offsetOfSequence = $offsetIndex;
     $sequence = Sequence::fromBinary($binaryData, $offsetIndex);
     $offsetOfSequence += $sequence->getNumberOfLengthOctets() + 1;
     if ($sequence->getObjectLength() != $contentLength) {
         throw new ParserException('Can not parse Subject Alternative Names: The Sequence length does not match the length of the surrounding octet string', $offsetIndex);
     }
     $parsedObject = new self();
     /** @var \FG\ASN1\Object $object */
     foreach ($sequence as $object) {
         if ($object->getType() == DNSName::IDENTIFIER) {
             $domainName = DNSName::fromBinary($binaryData, $offsetOfSequence);
             $parsedObject->addDomainName($domainName);
         } elseif ($object->getType() == IPAddress::IDENTIFIER) {
             $ip = IPAddress::fromBinary($binaryData, $offsetOfSequence);
             $parsedObject->addIP($ip);
         } else {
             throw new ParserException('Could not parse Subject Alternative Name: Only DNSName and IP SANs are currently supported', $offsetIndex);
         }
     }
     $parsedObject->getBinary();
     // Determine the number of content octets and object sizes once (just to let the equality unit tests pass :/ )
     return $parsedObject;
 }
开发者ID:afk11,项目名称:phpasn1,代码行数:30,代码来源:SubjectAlternativeNames.php

示例4: __construct

 public function __construct()
 {
     parent::__construct();
     // Try to set better auth than AUTH_PUBLIC depending on the origin of the IP
     if (S::i('auth') < AUTH_INTERNAL && IPAddress::getInstance()->is_x_internal()) {
         S::set('auth', AUTH_INTERNAL);
     }
 }
开发者ID:netixx,项目名称:frankiz,代码行数:8,代码来源:frankizsession.php

示例5: logm

 /**
  * Log an array of category/message pairs
  */
 public static function logm($categoryMessagePairs)
 {
     $scribe = Z_CONFIG::$LOG_TO_SCRIBE;
     $cli = Z_Core::isCommandLine();
     // Scribe and CLI need additional info
     if ($scribe || $cli) {
         // Parse timestamp into date and milliseconds
         $ts = microtime(true);
         if (strpos($ts, '.') === false) {
             $ts .= '.';
         }
         list($ts, $msec) = explode('.', $ts);
         $date = new DateTime(date(DATE_RFC822, $ts));
         $date->setTimezone(new DateTimeZone(Z_CONFIG::$LOG_TIMEZONE));
         $date = $date->format('Y-m-d H:i:s') . '.' . str_pad($msec, 4, '0');
         // Get remote IP address
         if (!$cli) {
             $ipAddress = IPAddress::getIP();
         }
         // Get server hostname
         if ($scribe) {
             $host = gethostname();
             if (strpos($host, '.') !== false) {
                 $host = substr($host, 0, strpos($host, '.'));
             }
         }
     }
     $messages = array();
     foreach ($categoryMessagePairs as $pair) {
         // Scribe
         if ($scribe) {
             $messages[] = array('category' => $pair[0], 'message' => "{$date} [{$ipAddress}] [{$host}] " . $pair[1]);
         } else {
             if ($cli) {
                 $messages[] = array('category' => $pair[0], 'message' => $date . " " . $pair[1]);
             } else {
                 $messages[] = array('category' => $pair[0], 'message' => $pair[1]);
             }
         }
     }
     if (Z_CONFIG::$LOG_TO_SCRIBE) {
         self::logToScribe($messages);
     } else {
         self::logToErrorLog($messages);
     }
 }
开发者ID:selenus,项目名称:dataserver,代码行数:49,代码来源:log.inc.php

示例6: getPortIDfromDeviceIP

 function getPortIDfromDeviceIP($IP, $ifDescr, $sysdescr, $sysname, $model)
 {
     global $DB;
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $NetworkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $PortID = "";
     // search port have ifdescr + ip (in most cases not find it)
     $queryPort = "SELECT `glpi_networkports`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkports`\n                    LEFT JOIN `glpi_networkports`\n                       ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                          `glpi_networkports`.`id`\n                    LEFT JOIN `glpi_networknames`\n                       ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                          AND `glpi_networknames`.`itemtype`='NetworkPort'\n                    LEFT JOIN `glpi_ipaddresses`\n                       ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                          AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                    WHERE (`ifdescr`='" . $ifDescr . "'\n                             OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n                          AND `glpi_ipaddresses`.`name`='" . $IP . "'";
     $resultPort = $DB->query($queryPort);
     if ($DB->numrows($resultPort) == 0) {
         // Search a management port of networkequipment have this IP
         $queryManagement = "SELECT `glpi_networkports`.`itemtype`,\n                        `glpi_networkports`.`items_id` FROM `glpi_networkports`\n                       LEFT JOIN `glpi_networknames`\n                          ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                             AND `glpi_networknames`.`itemtype`='NetworkPort'\n                       LEFT JOIN `glpi_ipaddresses`\n                          ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                             AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                       WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                          AND `instantiation_type`='NetworkPortAggregate'\n                       LIMIT 1";
         $resultManagement = $DB->query($queryManagement);
         if ($DB->numrows($resultManagement) == 1) {
             $dataManagement = $DB->fetch_assoc($resultManagement);
             // Seach a port have this ifdescr for this same networkequipment
             $queryPort = "SELECT `glpi_networkports`.`id`\n                          FROM `glpi_plugin_fusioninventory_networkports`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                                `glpi_networkports`.`id`\n                          WHERE `glpi_networkports`.`itemtype`='" . $dataManagement['itemtype'] . "'\n                              AND `glpi_networkports`.`items_id`='" . $dataManagement['items_id'] . "'\n                              AND (`ifdescr`='" . $ifDescr . "'\n                                   OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 $PortID = $dataPort["id"];
             }
         }
     } else {
         $dataPort = $DB->fetch_assoc($resultPort);
         $PortID = $dataPort['id'];
     }
     // Detect IP Phone
     if ($PortID == "") {
         if (strstr($model, "Phone") || $model == '') {
             $queryPort = "SELECT glpi_networkports.* FROM `glpi_phones`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_phones`.`id`=`glpi_networkports`.`items_id`\n                          LEFT JOIN `glpi_networknames`\n                             ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                                AND `glpi_networknames`.`itemtype`='NetworkPort'\n                          LEFT JOIN `glpi_ipaddresses`\n                             ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                                AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                          WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                                AND `glpi_networkports`.`itemtype`='Phone'\n                                AND `glpi_phones`.`name`='" . $sysname . "'\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 if (isset($dataPort['id'])) {
                     $PortID = $dataPort["id"];
                 }
             }
         }
     }
     if ($PortID == "") {
         $query = "SELECT * FROM `glpi_plugin_fusioninventory_unmanageds`\n            WHERE `ip`='" . $IP . "'\n            LIMIT 1";
         $result = $DB->query($query);
         if ($DB->numrows($result) == "1") {
             $data = $DB->fetch_assoc($result);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data['id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data['id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['ip'] = $IP;
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
             }
             // Update unmanaged device
             $input = array();
             $input['id'] = $data['id'];
             $input['ip'] = $IP;
             if (strstr($model, "Phone")) {
                 $input['item_type'] = 'Phone';
             }
             if ($sysname != '') {
                 $input['name'] = $sysname;
             }
             if ($sysdescr != '') {
                 $input['sysdescr'] = $sysdescr;
             }
             $pfUnmanaged->update($input);
             return $PortID;
         }
         $query0 = "SELECT `glpi_networkports`.* FROM `glpi_networkports`\n             LEFT JOIN `glpi_networknames`\n                 ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                    AND `glpi_networknames`.`itemtype`='NetworkPort'\n            LEFT JOIN `glpi_ipaddresses`\n                 ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                    AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n             WHERE `glpi_networkports`.`itemtype`='PluginFusioninventoryUnmanaged'\n               AND `glpi_ipaddresses`.`name`='" . $IP . "'\n             LIMIT 1";
         $result0 = $DB->query($query0);
         if ($DB->numrows($result0) == 1) {
             $data0 = $DB->fetch_assoc($result0);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data0['items_id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data0['items_id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
                 $input = array();
                 $input['itemtype'] = 'NetworkPort';
                 $input['items_id'] = $PortID;
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:networkport.class.php

示例7: vote

 public function vote($answer)
 {
     XDB::startTransaction();
     XDB::execute('INSERT INTO  qdj_votes
                           SET  qdj = {?}, uid = {?}, rank = 0, rule = "null"', $this->id(), S::user()->id());
     $vote = XDB::insertID();
     // Get the rank
     $rank = XDB::query('SELECT  COUNT(*)+1
                           FROM  qdj_votes
                          WHERE  qdj = {?} AND rank != 0', $this->id())->fetchOneCell();
     if ($rank == 1) {
         if ($this->writer === null) {
             $this->select(QDJSelect::all());
         }
         XDB::execute('INSERT INTO  qdj_votes
                               SET  qdj = {?}, uid = {?}, rank = 0, rule = 10', $this->id(), $this->writer->id());
     }
     $rule = null;
     switch ($rank) {
         case 1:
             $rule = '1';
             break;
         case 2:
             $rule = '2';
             break;
         case 3:
             $rule = '3';
             break;
         case 13:
             $rule = '4';
             break;
         case 42:
             $rule = '5';
             break;
         case 69:
             $rule = '6';
             break;
         case 314:
             $rule = '7';
             break;
         case substr(strrchr(IPAddress::get(), '.'), 1):
             $rule = '8';
             break;
         case date('d') + date('m'):
             $rule = '9';
             break;
     }
     XDB::execute('UPDATE qdj_votes
                      SET rank = {?}, rule = {?}
                    WHERE vote_id = {?}', $rank, $rule, $vote);
     XDB::commit();
     if ($answer == 1) {
         XDB::execute('UPDATE qdj SET count1 = count1+1 WHERE id={?}', $this->id());
     } else {
         XDB::execute('UPDATE qdj SET count2 = count2+1 WHERE id={?}', $this->id());
     }
 }
开发者ID:netixx,项目名称:frankiz,代码行数:57,代码来源:qdj.php

示例8: showForItem


//.........这里部分代码省略.........
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new NetworkName();
     $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_networknames' => 'id');
     foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new IPAddress();
     $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_ipaddresses' => 'id');
     foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $types = Item_Devices::getDeviceTypes();
     $nb = 0;
     foreach ($types as $old => $type) {
         $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n                                         AND `itemtype`='{$itemtype}'\n                                         AND `is_dynamic`='1'\n                                         AND `is_deleted`='1'");
     }
     if ($nb) {
         $header = true;
         echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
         foreach ($types as $old => $type) {
             $associated_type = str_replace('Item_', '', $type);
             $associated_table = getTableForItemType($associated_type);
             $fk = getForeignKeyFieldForTable($associated_table);
             $query = "SELECT `i`.`id`,\n                             `t`.`designation` AS `name`\n                      FROM `" . getTableForItemType($type) . "` AS i\n                      LEFT JOIN `{$associated_table}` AS t\n                         ON (`t`.`id` = `i`.`{$fk}`)\n                      WHERE `itemtype` = '{$itemtype}'\n                            AND `items_id` = '{$ID}'\n                            AND `is_dynamic` = '1'\n                            AND `is_deleted` = '1'";
             foreach ($DB->request($query) as $data) {
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>";
                 printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
                 echo "</td></tr>\n";
             }
         }
     }
     if ($header) {
         echo "</table>";
         Html::openArrowMassives('lock_form', true);
         Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
     } else {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>\n";
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:101,代码来源:lock.class.php

示例9: updateNetworkPort

 /**
  * @param $mac
  * @param $name
  * @param $computers_id
  * @param $instantiation_type
  * @param $inst_input
  * @param $ips
  * @param $check_name
  * @param $dohistory
  * @param $already_known_ports
  * @return ID
  */
 private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports)
 {
     global $DB;
     $network_port = new NetworkPort();
     // Then, find or create the base NetworkPort
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networkports`\n                WHERE `itemtype` = 'Computer'\n                   AND `items_id` = '{$computers_id}'\n                   AND `mac` = '{$mac}'";
     // If there is virtual ports, then, filter by port's name
     if ($check_name) {
         $query .= " AND `name` = '{$name}'";
     }
     if (count($already_known_ports) > 0) {
         $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")";
     }
     // We order by is_dynamic to be sure to get the static ones first !
     $query .= " ORDER BY `is_dynamic`, `id`";
     $ports = $DB->request($query);
     if ($ports->numrows() == 0) {
         $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0);
         $networkports_id = $network_port->add($port_input, array(), $dohistory);
         if ($networkports_id === false) {
             return -1;
         }
         $inst_input['networkports_id'] = $networkports_id;
         $instantiation = $network_port->getInstantiation();
         $instantiation->update($inst_input);
         unset($instantiation);
     } else {
         $line = $ports->next();
         $networkports_id = $line['id'];
         $network_port->getFromDB($networkports_id);
         if (!$check_name && $network_port->fields['name'] != $name) {
             $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1);
             $network_port->update($port_input);
         }
         if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) {
             $network_port->switchInstantiationType($instantiation_type);
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation = $network_port->getInstantiation();
             $instantiation->add($inst_input);
             unset($instantiation);
         }
         if ($network_port->fields['instantiation_type'] == $instantiation_type) {
             $instantiation = $network_port->getInstantiation();
             $inst_input['id'] = $instantiation->getID();
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation->update($inst_input);
             unset($instantiation);
         }
     }
     if ($network_port->isNewItem()) {
         return -1;
     }
     $network_name = new NetworkName();
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networknames`\n                WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkports_id}'\n                ORDER BY `is_dynamic`";
     if (!$ips || count($ips) == 0) {
         foreach ($DB->request($query) as $line) {
             if ($line['is_dynamic']) {
                 $network_name->delete($line, true, $dohistory);
             }
         }
     } else {
         $names = $DB->request($query);
         if ($names->numrows() == 0) {
             $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG');
             $networknames_id = $network_name->add($name_input);
         } else {
             $line = $names->next();
             $networknames_id = $line['id'];
             foreach ($names as $line) {
                 if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) {
                     $network_port->delete($line, true, $dohistory);
                 }
             }
         }
         $ip_address = new IPAddress();
         $already_known_addresses = array();
         $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n                   FROM `glpi_ipaddresses`\n                   WHERE `itemtype` = 'NetworkName'\n                     AND `items_id` = '{$networknames_id}'\n                   ORDER BY `is_dynamic`";
         foreach ($DB->request($query) as $line) {
             if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) {
                 $already_known_addresses[] = $line['id'];
                 $ips = array_diff($ips, array($line['name']));
             } elseif ($line['is_dynamic'] == 1) {
                 $ip_address->delete($line, true, $dohistory);
             }
         }
     }
     if ($ips) {
         foreach ($ips as $ip) {
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:101,代码来源:networkport.class.php

示例10: _handleFileRequest

 /**
  * Handle S3 request
  *
  * Permission-checking provided by items()
  */
 private function _handleFileRequest($item)
 {
     if (!$this->permissions->canAccess($this->objectLibraryID, 'files')) {
         $this->e403();
     }
     $this->allowMethods(array('HEAD', 'GET', 'POST', 'PATCH'));
     if (!$item->isAttachment()) {
         $this->e400("Item is not an attachment");
     }
     // File info for client sync
     //
     // Use of HEAD method is deprecated after 2.0.8/2.1b1 due to
     // compatibility problems with proxies and security software
     if ($this->method == 'HEAD' || $this->method == 'GET' && $this->fileMode == 'info') {
         $info = Zotero_S3::getLocalFileItemInfo($item);
         if (!$info) {
             $this->e404();
         }
         /*
         header("Last-Modified: " . gmdate('r', $info['uploaded']));
         header("Content-Type: " . $info['type']);
         */
         header("Content-Length: " . $info['size']);
         header("ETag: " . $info['hash']);
         header("X-Zotero-Filename: " . $info['filename']);
         header("X-Zotero-Modification-Time: " . $info['mtime']);
         header("X-Zotero-Compressed: " . ($info['zip'] ? 'Yes' : 'No'));
         header_remove("X-Powered-By");
     } else {
         if ($this->method == 'GET' || $this->method == 'POST' && $this->fileView) {
             if ($this->fileView) {
                 $info = Zotero_S3::getLocalFileItemInfo($item);
                 if (!$info) {
                     $this->e404();
                 }
                 // For zip files, redirect to files domain
                 if ($info['zip']) {
                     $url = Zotero_Attachments::getTemporaryURL($item, !empty($_GET['int']));
                     if (!$url) {
                         $this->e500();
                     }
                     header("Location: {$url}");
                     exit;
                 }
             }
             // For single files, redirect to S3
             $url = Zotero_S3::getDownloadURL($item, 60);
             if (!$url) {
                 $this->e404();
             }
             Zotero_S3::logDownload($item, $this->userID, IPAddress::getIP());
             header("Location: {$url}");
             exit;
         } else {
             if ($this->method == 'POST' || $this->method == 'PATCH') {
                 if (!$item->isImportedAttachment()) {
                     $this->e400("Cannot upload file for linked file/URL attachment item");
                 }
                 $libraryID = $item->libraryID;
                 $type = Zotero_Libraries::getType($libraryID);
                 if ($type == 'group') {
                     $groupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
                     $group = Zotero_Groups::get($groupID);
                     if (!$group->userCanEditFiles($this->userID)) {
                         $this->e403("You do not have file editing access");
                     }
                 } else {
                     $group = null;
                 }
                 // If not the client, require If-Match or If-None-Match
                 if (!$this->httpAuth) {
                     if (empty($_SERVER['HTTP_IF_MATCH']) && empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
                         $this->e428("If-Match/If-None-Match header not provided");
                     }
                     if (!empty($_SERVER['HTTP_IF_MATCH'])) {
                         if (!preg_match('/^"?([a-f0-9]{32})"?$/', $_SERVER['HTTP_IF_MATCH'], $matches)) {
                             $this->e400("Invalid ETag in If-Match header");
                         }
                         if (!$item->attachmentStorageHash) {
                             $info = Zotero_S3::getLocalFileItemInfo($item);
                             $this->e412("ETag set but file does not exist");
                         }
                         if ($item->attachmentStorageHash != $matches[1]) {
                             $this->e412("ETag does not match current version of file");
                         }
                     } else {
                         if ($_SERVER['HTTP_IF_NONE_MATCH'] != "*") {
                             $this->e400("Invalid value for If-None-Match header");
                         }
                         if ($this->attachmentStorageHash) {
                             $this->e412("If-None-Match: * set but file exists");
                         }
                     }
                 }
                 //
//.........这里部分代码省略.........
开发者ID:robinpaulson,项目名称:dataserver,代码行数:101,代码来源:ApiController.php

示例11: filterValues

 /**
  * Check float and decimal values
  *
  * @param $display   display or not messages in and addAfterRedirect (true by default)
  *
  * @return input the data checked
  **/
 function filterValues($display = true)
 {
     // MoYo : comment it because do not understand why filtering is disable
     //       if (in_array('CommonDBRelation', class_parents($this))) {
     //          return true;
     //       }
     //Type mismatched fields
     $fails = array();
     if (isset($this->input) && is_array($this->input) && count($this->input)) {
         foreach ($this->input as $key => $value) {
             $unset = false;
             $regs = array();
             $searchOption = $this->getSearchOptionByField('field', $key);
             if (isset($searchOption['datatype']) && (is_null($value) || $value == '' || $value == 'NULL')) {
                 switch ($searchOption['datatype']) {
                     case 'date':
                     case 'datetime':
                         // don't use $unset', because this is not a failure
                         $this->input[$key] = 'NULL';
                         break;
                 }
             } else {
                 if (isset($searchOption['datatype']) && !is_null($value) && $value != '' && $value != 'NULL') {
                     switch ($searchOption['datatype']) {
                         case 'integer':
                         case 'count':
                         case 'number':
                         case 'decimal':
                             $value = str_replace(',', '.', $value);
                             if ($searchOption['datatype'] == 'decimal') {
                                 $this->input[$key] = floatval(Toolbox::cleanDecimal($value));
                             } else {
                                 $this->input[$key] = intval(Toolbox::cleanInteger($value));
                             }
                             if (!is_numeric($this->input[$key])) {
                                 $unset = true;
                             }
                             break;
                         case 'bool':
                             if (!in_array($value, array(0, 1))) {
                                 $unset = true;
                             }
                             break;
                         case 'ip':
                             $address = new IPAddress();
                             if (!$address->setAddressFromString($value)) {
                                 $unset = true;
                             } else {
                                 if (!$address->is_ipv4()) {
                                     $unset = true;
                                 }
                             }
                             break;
                         case 'mac':
                             preg_match("/([0-9a-fA-F]{1,2}([:-]|\$)){6}\$/", $value, $regs);
                             if (empty($regs)) {
                                 $unset = true;
                             }
                             // Define the MAC address to lower to reduce complexity of SQL queries
                             $this->input[$key] = strtolower($value);
                             break;
                         case 'date':
                         case 'datetime':
                             // Date is already "reformat" according to getDateFormat()
                             $pattern = "/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})";
                             $pattern .= "([_][01][0-9]|2[0-3]:[0-5][0-9]:[0-5]?[0-9])?/";
                             preg_match($pattern, $value, $regs);
                             if (empty($regs)) {
                                 $unset = true;
                             }
                             break;
                         case 'itemtype':
                             //Want to insert an itemtype, but the associated class doesn't exists
                             if (!class_exists($value)) {
                                 $unset = true;
                             }
                         case 'email':
                         case 'string':
                             if (strlen($value) > 255) {
                                 $this->input[$key] = substr($value, 0, 254);
                             }
                             break;
                         default:
                             //Plugins can implement their own checks
                             if (!$this->checkSpecificValues($searchOption['datatype'], $value)) {
                                 $unset = true;
                             }
                             // Copy value if check have update it
                             $this->input[$key] = $value;
                             break;
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:JULIO8,项目名称:respaldo_glpi,代码行数:101,代码来源:commondbtm.class.php

示例12: login

 public function login()
 {
     // TODO: Change to POST only
     if (empty($_REQUEST['username'])) {
         $this->error(403, 'NO_USER_NAME', "Username not provided");
     } else {
         if (empty($_REQUEST['password'])) {
             $this->error(403, 'NO_PASSWORD', "Password not provided");
         }
     }
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     $authData = array('username' => $username, 'password' => $password);
     $userID = Zotero_Users::authenticate('password', $authData);
     if (!$userID) {
         StatsD::increment("sync.login.failure");
         if (isset($_SERVER['HTTP_X_ZOTERO_VERSION']) && $_SERVER['HTTP_X_ZOTERO_VERSION'] == "2.0b6") {
             die("Username/password not accepted");
         }
         $this->error(403, 'INVALID_LOGIN', "Username/password not accepted");
     }
     StatsD::increment("sync.login.success");
     $sessionID = md5($userID . uniqid(rand(), true) . $password);
     $ip = IPAddress::getIP();
     $sql = "INSERT INTO sessions (sessionID, userID, ipAddress)\n\t\t\t\t\tVALUES (?,?,INET_ATON(?))";
     Zotero_DB::query($sql, array($sessionID, $userID, $ip));
     Z_Core::$MC->set("syncSession_{$sessionID}", array('sessionID' => $sessionID, 'userID' => $userID), $this->sessionLifetime - 600);
     $this->responseXML->sessionID = $sessionID;
     $this->end();
 }
开发者ID:selenus,项目名称:dataserver,代码行数:30,代码来源:SyncController.php

示例13: getAvailableDisplayOptions

 /**
  * Get available display options array
  *
  * @since version 0.84
  *
  * @return all the options
  **/
 static function getAvailableDisplayOptions()
 {
     $options[__('Global displays')] = array('characteristics' => array('name' => __('Characteristics'), 'default' => true), 'internet' => array('name' => __('Internet information'), 'default' => true), 'dynamic_import' => array('name' => __('Automatic inventory'), 'default' => false));
     $options[__('Common options')] = NetworkPortInstantiation::getGlobalInstantiationNetworkPortDisplayOptions();
     $options[__('Internet information')] = array('names' => array('name' => NetworkName::getTypeName(2), 'default' => false), 'aliases' => array('name' => NetworkAlias::getTypeName(2), 'default' => false), 'ipaddresses' => array('name' => IPAddress::getTypeName(2), 'default' => true), 'ipnetworks' => array('name' => IPNetwork::getTypeName(2), 'default' => true));
     foreach (self::getNetworkPortInstantiations() as $portType) {
         $portTypeName = $portType::getTypeName(0);
         $options[$portTypeName] = $portType::getInstantiationNetworkPortDisplayOptions();
     }
     return $options;
 }
开发者ID:gaforeror,项目名称:glpi,代码行数:18,代码来源:networkport.class.php

示例14: executeActions


//.........这里部分代码省略.........
                             break;
                         case 'groups_id_validate':
                             $output['_add_validation']['group'][] = $action->fields["value"];
                             break;
                         case 'users_id_validate':
                             $output['_add_validation'][] = $action->fields["value"];
                             break;
                         case 'validation_percent':
                             $output[$action->fields["field"]] = $action->fields["value"];
                             break;
                         default:
                             $output['_add_validation'][] = $action->fields["value"];
                             break;
                     }
                     break;
                 case "assign":
                     $output[$action->fields["field"]] = $action->fields["value"];
                     // Special case of users_id_requester
                     if ($action->fields["field"] === '_users_id_requester') {
                         // Add groups of requester
                         if (!isset($output['_groups_id_of_requester'])) {
                             $output['_groups_id_of_requester'] = array();
                         }
                         foreach (Group_User::getUserGroups($action->fields["value"]) as $g) {
                             $output['_groups_id_of_requester'][$g['id']] = $g['id'];
                         }
                     }
                     break;
                 case "append":
                     $actions = $this->getActions();
                     $value = $action->fields["value"];
                     if (isset($actions[$action->fields["field"]]["appendtoarray"]) && isset($actions[$action->fields["field"]]["appendtoarrayfield"])) {
                         $value = $actions[$action->fields["field"]]["appendtoarray"];
                         $value[$actions[$action->fields["field"]]["appendtoarrayfield"]] = $action->fields["value"];
                     }
                     $output[$actions[$action->fields["field"]]["appendto"]][] = $value;
                     // Special case of users_id_requester
                     if ($action->fields["field"] === '_users_id_requester') {
                         // Add groups of requester
                         if (!isset($output['_groups_id_of_requester'])) {
                             $output['_groups_id_of_requester'] = array();
                         }
                         foreach (Group_User::getUserGroups($action->fields["value"]) as $g) {
                             $output['_groups_id_of_requester'][$g['id']] = $g['id'];
                         }
                     }
                     break;
                 case 'fromuser':
                     if ($action->fields['field'] == 'locations_id' && isset($output['users_locations'])) {
                         $output['locations_id'] = $output['users_locations'];
                     }
                     break;
                 case 'fromitem':
                     if ($action->fields['field'] == 'locations_id' && isset($output['items_locations'])) {
                         $output['locations_id'] = $output['items_locations'];
                     }
                     if ($action->fields['field'] == 'groups_id' && isset($output['items_groups'])) {
                         $output['groups_id'] = $output['items_groups'];
                     }
                     break;
                 case 'compute':
                     // Value could be not set (from test)
                     $urgency = isset($output['urgency']) ? $output['urgency'] : 3;
                     $impact = isset($output['impact']) ? $output['impact'] : 3;
                     // Apply priority_matrix from config
                     $output['priority'] = Ticket::computePriority($urgency, $impact);
                     break;
                 case "affectbyip":
                 case "affectbyfqdn":
                 case "affectbymac":
                     if (!isset($output["entities_id"])) {
                         $output["entities_id"] = $params["entities_id"];
                     }
                     if (isset($this->regex_results[0])) {
                         $regexvalue = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
                     } else {
                         $regexvalue = $action->fields["value"];
                     }
                     switch ($action->fields["action_type"]) {
                         case "affectbyip":
                             $result = IPAddress::getUniqueItemByIPAddress($regexvalue, $output["entities_id"]);
                             break;
                         case "affectbyfqdn":
                             $result = FQDNLabel::getUniqueItemByFQDN($regexvalue, $output["entities_id"]);
                             break;
                         case "affectbymac":
                             $result = NetworkPortInstantiation::getUniqueItemByMac($regexvalue, $output["entities_id"]);
                             break;
                         default:
                             $result = array();
                     }
                     if (!empty($result)) {
                         $output["items_id"][$result["itemtype"]][] = $result["id"];
                     }
                     break;
             }
         }
     }
     return $output;
 }
开发者ID:korial29,项目名称:glpi,代码行数:101,代码来源:ruleticket.class.php

示例15: getSearchOptions

 function getSearchOptions()
 {
     global $CFG_GLPI;
     $tab = parent::getSearchOptions();
     $optionIndex = 10;
     // From 10 to 14
     foreach (self::getMotives() as $motive => $name) {
         $tab[$optionIndex]['table'] = $this->getTable();
         $tab[$optionIndex]['field'] = $motive;
         $tab[$optionIndex]['name'] = $name;
         $tab[$optionIndex]['datatype'] = 'bool';
         $optionIndex++;
     }
     $tab[20]['table'] = $this->getTable();
     $tab[20]['field'] = 'ip';
     $tab[20]['datatype'] = 'ip';
     $tab[20]['name'] = IPAddress::getTypeName(1);
     $tab[21]['table'] = $this->getTable();
     $tab[21]['field'] = 'netmask';
     $tab[21]['datatype'] = 'string';
     $tab[21]['name'] = IPNetmask::getTypeName(1);
     $tab[22]['table'] = $this->getTable();
     $tab[22]['field'] = 'subnet';
     $tab[22]['datatype'] = 'string';
     $tab[22]['name'] = __('Network address');
     $tab[23]['table'] = $this->getTable();
     $tab[23]['field'] = 'gateway';
     $tab[23]['datatype'] = 'string';
     $tab[23]['name'] = IPAddress::getTypeName(1);
     if (TableExists('glpi_networkinterfaces')) {
         $tab[24]['table'] = 'glpi_networkinterfaces';
         $tab[24]['field'] = 'name';
         $tab[24]['datatype'] = 'dropdown';
         $tab[24]['name'] = __('Network interface');
     }
     return $tab;
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:37,代码来源:networkportmigration.class.php


注:本文中的IPAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。