/** * Get a zone based on location * * Second param is a list of zone IDs to check against. That list * is pulled from the #__tool_version_zone table. * * @param string $ip * @param array $allowed List of zone IDs to check against * @return object */ public function zoning($ip = null, $allowed = array()) { if (!$ip) { return new Zone(); } // Find by IP $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'ip' => $ip), true); if ($zones->total() > 0) { foreach ($zones as $zone) { return $zone; } } // Find by city // Find by region // Find by country $country = Geocode::ipcountry($ip); if (!$country) { return new Zone(); } $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'countrySHORT' => $country), true); if ($zones->total() > 0) { foreach ($zones as $zone) { return $zone; } } // Find by continent $continent = Geocode::getContinentByCountry($country); if (!$continent) { return new Zone(); } $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'continent' => $continent), true); if ($zones->total() > 0) { foreach ($zones as $zone) { return $zone; } } return new Zone(); }
/** * Check export controls * Is the user in a country that has access to this tool? * * @param string $exportcontrol Control [us, d1, pu] * @return boolean False if user does NOT have access */ private function _getToolExportControl($exportcontrol) { $exportcontrol = strtolower($exportcontrol); $ip = Request::ip(); $country = \Hubzero\Geocode\Geocode::ipcountry($ip); if (empty($country) && in_array($exportcontrol, array('us', 'd1', 'pu'))) { $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_UNKNOWN')); Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED location export control check"); return false; } if (\Hubzero\Geocode\Geocode::is_e1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) { $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_E1')); Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED E1 export control check"); return false; } switch ($exportcontrol) { case 'us': if (\Hubzero\Geocode\Geocode::ipcountry($ip) != 'us') { $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_USA_ONLY')); Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED US export control check"); return false; } break; case 'd1': if (\Hubzero\Geocode\Geocode::is_d1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) { $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_LICENSE')); Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED D1 export control check"); return false; } break; case 'pu': if (!\Hubzero\Geocode\Geocode::is_iplocation($ip, $exportcontrol)) { $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_PURDUE_ONLY')); Log::debug("mw::_getToolExportControl({$exportControl}) FAILED PURDUE export control check"); return false; } break; } return true; }
/** * Return a tool export access * * @param $export_control Export control level for tool * * @return BOOL */ public static function getToolExportAccess($export_control) { //instaniate objects $export_access = new stdClass(); $ip = Request::ip(); //get the export control level $export_control = strtolower($export_control); //get the users country based on ip address $country = \Hubzero\Geocode\Geocode::ipcountry($ip); //if we dont know the users location and its a restricted to we have to deny access if (empty($country) && in_array($export_control, array('us', 'd1', 'pu'))) { $export_access->valid = 0; $export_access->error->message = 'This tool may not be accessed from your unknown current location due to export/license restrictions.'; \Log::debug("mw::_getToolExportControl({$export_control}) FAILED location export control check"); return $export_access; } //if the user is in an E1 nation if (\Hubzero\Geocode\Geocode::is_e1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) { $export_access->valid = 0; $export_access->error->message = 'This tool may not be accessed from your current location due to E1 export/license restrictions.'; \Log::debug("mw::_getToolExportControl({$export_control}) FAILED E1 export control check"); return $export_access; } //run checks depending on the export ac switch ($export_control) { case 'us': if (\Hubzero\Geocode\Geocode::ipcountry($ip) != 'us') { $export_access->valid = 0; $export_access->error->message = 'This tool may only be accessed from within the U.S. due to export/licensing restrictions.'; \Log::debug("mw::_getToolExportControl({$export_control}) FAILED US export control check"); return $export_access; } break; case 'd1': if (\Hubzero\Geocode\Geocode::is_d1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) { $export_access->valid = 0; $export_access->error->message = 'This tool may not be accessed from your current location due to export/license restrictions.'; \Log::debug("mw::_getToolExportControl({$export_control}) FAILED D1 export control check"); return $export_access; } break; case 'pu': if (!\Hubzero\Geocode\Geocode::is_iplocation($ip, $export_control)) { $export_access->valid = 0; $export_access->error->message = 'This tool may only be accessed by authorized users while on the West Lafayette campus of Purdue University due to license restrictions.'; \Log::debug("mw::_getToolExportControl({$export_control}) FAILED PURDUE export control check"); return $export_access; } break; } //passed all checks $export_access->valid = 1; return $export_access; }
} echo '>' . htmlentities($c->name, ENT_COMPAT, 'UTF-8') . '</option>' . "\n"; } ?> </select> </div> </li> <?php } ?> <?php if (isset($row['countryresident'])) { ?> <li> <?php $country = isset($_POST['countryresident']) ? $_POST['countryresident'] : \Hubzero\Geocode\Geocode::ipcountry(Request::ip()); ?> <label>Do you currently live in the <abbr title="United States">US</abbr>?</label> <div class="indented"> <?php if (isset($errors['countryresident'])) { ?> <p class="warning">Please select your country of residency</p> <?php } ?> <label><input type="radio" class="option" name="countryresident_us" id="cores_usyes" value="yes" <?php if (strtolower($country) == 'us' || isset($_POST['countryresident_us']) && $_POST['countryresident_us'] == 'yes') { echo 'checked="checked"'; } ?>
</select> </label> </fieldset> <?php } ?> <?php if ($this->registrationResidency != REG_HIDE) { ?> <?php $message = !empty($this->xregistration->_invalid['countryresident']) ? '<span class="error">' . $this->xregistration->_invalid['countryresident'] . '</span>' : ''; $fieldclass = $message ? ' class="fieldsWithErrors"' : ''; if (!$this->registration['countryresident']) { if (!isset($userCountry) || !$userCountry) { $userCountry = \Hubzero\Geocode\Geocode::ipcountry(Request::ip()); } $this->registration['countryresident'] = $userCountry; } ?> <fieldset<?php echo $fieldclass; ?> > <legend> <?php echo Lang::txt('COM_MEMBERS_REGISTER_RESIDENT_OF_USA'); ?> <?php echo $this->registrationResidency == REG_REQUIRED ? '<span class="required">' . Lang::txt('COM_MEMBERS_REGISTER_FORM_REQUIRED') . '</span>' : ''; ?>