'California - Los Angeles', 'SF' => 'California - San Francisco', 'IL' => 'Illinois', 'MD' => 'Maryland', 'NJ' => 'New Jersey - Mount Laurel', 'NY' => 'New York', 'TX' => 'Texas - Houston', 'FL' => 'Florida - Miami', 'DAL' => 'Texas - Dallas', 'AZ' => 'Arizona', 'GA' => 'Georgia', ); /** * Allowed access external ip address * * @static */ private static $allowIPs = array('170.178.140.197', '216.38.130.66', '50.208.102.65', '65.200.20.10', '65.200.20.100', '218.17.99.34', '50.234.221.186', '18.205.44.243', '76.93.76.210', '172.115.78.255', '23.239.27.249', '136.52.117.191', '47.176.147.237', '3.210.104.233', '167.216.131.180', '99.124.205.233', '47.41.206.149'); //172.115.78.255, 23.239.27.249, 136.52.117.191 and 76.93.76.210 are external contractor IP /** * Office IPs * * @static */ private static $officeIPs = array('65.200.20.100', '108.2.62.210', '96.72.90.61', '71.25.182.211', '96.91.103.65', '170.178.140.197', '216.38.130.66', '65.200.20.10', '65.200.20.118', '96.226.119.130', '96.92.220.188', '96.91.230.118', '50.208.102.65', '96.224.235.11', '184.179.14.253', '96.91.34.126', '50.234.221.186', '72.17.14.98', '47.190.62.52', '76.217.125.193', '98.0.153.27', '47.176.147.237', '167.216.131.180', '99.124.205.233'); /** * @var \Magento\Eav\Api\AttributeRepositoryInterface */ protected $attributeRepository; /** * Data constructor. * @param \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository */ public function __construct( \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository ) { $this->attributeRepository = $attributeRepository; } /** * Returns allow ips * * @static */ public static function getAllowIps() { return self::$allowIPs; } /** * Returns office ips * * @static */ public static function getOfficeIps() { return self::$officeIPs; } /** * Check if client IP is allowed * * @static */ public static function checkIP() { if (!self::canAccess()) { self::_403(); } } /** * Raise 400 Bad Request * * @static */ public static function _400() { header('HTTP/1.1 400 Bad Request'); die('Bad Request'); } /** * Raise 401 Unauthorized * * @static */ public static function _401() { header('HTTP/1.1 401 Unauthorized'); die('Unauthorized'); } /** * Raise 403 Forbidden * * @static */ public static function _403() { header('HTTP/1.1 403 Forbidden'); die('Forbidden'); } /** * Raise 404 Not Found * * @static */ public static function _404() { header('HTTP/1.1 404 Not Found'); die('Not Found'); } /** * Compare the external ip address if it is allowed, then returns the result * * @return bool Returns true if match ip address, otherwise false * @static */ public static function canAccess() { return in_array($_SERVER['REMOTE_ADDR'], self::$allowIPs); } /** * Check if office exists * * @param string @shortname Short Name of office * @result bool Returns true if office exists with this name, otherwise false * @static */ public static function hasOfficeName($shortname) { return isset(self::$offices[$shortname]); } /** * Gets the office name by givin location name * * @param int @code The office code * @return string Returns the name of the office location * @static */ public static function getOfficeNameByCode($code) { $result = array_search($code, self::$offices); return $result ? $result : 'UNKNOWN'; } /** * Gets the office code by givin name * * @param string $name Name of the office location * @return int Returns the code of the office * @static */ public static function getOfficeNameByShortName($shortname) { return self::$offices[$shortname]; } /** * Gets the office name by givin location name * * @param string @shortname The office short name * @return string Returns the name of the office location */ public function getOfficeValueByShortName($shortname) { $attribute = $this->attributeRepository->get('customer', 'lts_office'); $options = $attribute->getSource()->getAllOptions(false); $name = self::$offices[$shortname] ?? 'Doesn\'t matter'; foreach ($options as $option) { if ($option['label'] == $name) { return $option['value']; } } return ''; } }