Exemplo n.º 1
0
 /** @inheritdoc */
 public function __construct(array $settings = [])
 {
     $this->_request = IfSet::get($settings, 'request', Request::createFromGlobals());
     $this->_response = IfSet::get($settings, 'response', Response::create());
     $this->_container = null;
     parent::__construct($settings);
 }
 /**
  * Sends an email
  *
  * @param int   $template The template to use
  * @param array $data
  *
  * @return bool
  * @throws \Exception
  */
 public function send($template, $data = [])
 {
     //	If we came in through a service call, make sure type is specified...
     if (!MailTemplates::contains($template)) {
         throw new \InvalidArgumentException('Invalid template "' . $template . '" specified.');
     }
     $_settings = config('services.smtp-mail', []);
     $_service = array_get($_settings, 'smtp-service', 'localhost');
     if (null === ($_mailTemplate = IfSet::getDeep($_settings, 'templates', $template))) {
         throw new \InvalidArgumentException('There was no associated template for type #' . $template);
     }
     if ('localhost' != $_service) {
         if (!isset($_settings['access-key']) || !isset($_settings['secret-key'])) {
             throw new \InvalidArgumentException('You must set both the "access-key" and "secret-key" in order to use this service.');
         }
     }
     //	Use template subject first, then local
     if (!isset($data['subject'])) {
         $data['subject'] = array_get($_mailTemplate, 'subject');
     }
     $_templateFile = base_path() . '/config/templates/' . $_mailTemplate['template'];
     if (!file_exists($_templateFile)) {
         throw new \InvalidArgumentException('Template "' . $_templateFile . '" cannot be found.');
     }
     //	Build the message
     $data['__smtp-mail.settings__'] = $_settings;
     $_message = $this->_createMessage($_templateFile, $data);
     try {
         switch ($_service) {
             case 'localhost':
                 $_transport = new \Swift_MailTransport();
                 break;
             default:
                 if (null === ($_settings = IfSet::getDeep($_settings, 'services', $_service))) {
                     throw new \RuntimeException('Service "' . $_service . '" is not properly configured.');
                 }
                 //	Create the transport
                 $_transport = \Swift_SmtpTransport::newInstance($_settings['server-name'], $_settings['server-port'])->setUsername($_settings['access-key'])->setPassword($_settings['secret-key']);
                 break;
         }
         //	And the mailer...
         $_mailer = new \Swift_Mailer($_transport);
         $_recipients = $_mailer->send($_message, $_bogus);
         if (!empty($_bogus)) {
             $this->logger->error('Failed recipients: ' . implode(', ', $_bogus));
         }
         if (empty($_recipients)) {
             $this->logger->error('Sending email to "' . $_message->getTo() . '" failed.');
         }
         return $_recipients;
     } catch (\Exception $_ex) {
         //	Something went awry
         $this->logger->error('Mail delivery exception: ' . $_ex->getMessage());
         throw $_ex;
     }
 }
Exemplo n.º 3
0
 /**
  * @param string $host         The host of the entry, or "*" for all
  * @param int    $port         The port of the entry
  * @param string $scheme       The scheme of the entry
  * @param array  $allowedVerbs The verbs allowed for the entry. Defaults to all verbs being allowed
  */
 public function __construct($host = null, $port = null, $scheme = null, $allowedVerbs = null)
 {
     $this->_host = strtolower($host ?: IfSet::get($_SERVER, 'HTTP_HOST'));
     if (static::WIDE_OPEN != $this->_host) {
         $this->_port = $port ?: IfSet::get($_SERVER, 'SERVER_PORT');
         $this->_scheme = $scheme ?: 'http' . (IfSet::getBool($_SERVER, 'HTTPS') ? 's' : null);
         //  Ignore standard ports
         'https' == $this->_scheme && 443 == $this->_port && ($this->_port = null);
         'http' == $this->_scheme && 80 == $this->_port && ($this->_port = null);
     }
     $this->_allowedVerbs = $allowedVerbs ?: [Verbs::GET, Verbs::POST, Verbs::PUT, Verbs::DELETE, Verbs::PATCH, Verbs::MERGE, Verbs::COPY, Verbs::OPTIONS];
 }
Exemplo n.º 4
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     $_command = new RegisterJob($this->argument('owner-id'), strtolower($this->argument('owner-type')));
     \Queue::push($_command);
     $_result = $_command->getResult();
     if (empty($_result) || null === ($_id = IfSet::getDeep($_result, 'success', 'id'))) {
         $this->error('Results not found for request. Please try again.');
         return 1;
     }
     try {
         /** @type AppKey $_key */
         $_key = AppKey::findOrFail($_id);
     } catch (ModelNotFoundException $_ex) {
         $this->error('The key has been misplaced. Please try again.');
         return 2;
     }
     $this->writeln('<info>Key pair id "' . $_id . '" created. Please keep secure.</info>');
     $this->writeln('    <comment>client_id</comment>: <info>' . $_key->client_id . '</info>');
     $this->writeln('<comment>client_secret</comment>: <info>' . $_key->client_secret . '</info>');
     return 0;
 }
Exemplo n.º 5
0
 /**
  * @param string|array $origin     The parse_url value of origin
  * @param array        $additional Additional origin(s) to allow
  * @param bool         $isStar     Set to true if the allowed origin is "*"
  *
  * @return bool|array false if not allowed, otherwise array of verbs allowed
  */
 protected function _checkOrigin($origin, array $additional = [], &$isStar = false)
 {
     $_checklist = array_merge($this->_whitelist, $additional);
     foreach ($_checklist as $_hostInfo) {
         //  Always start with defaults
         $_allowedVerbs = $this->_verbs;
         $_whiteGuy = $_hostInfo;
         if (is_array($_hostInfo)) {
             //	If is_enabled prop not there, assuming enabled.
             if (!Scalar::boolval(IfSet::get($_hostInfo, 'is_enabled', true))) {
                 continue;
             }
             if (null === ($_whiteGuy = IfSet::get($_hostInfo, 'host'))) {
                 $this->_logger->error('whitelist entry missing "host" parameter');
                 continue;
             }
             if (isset($_hostInfo['verbs'])) {
                 if (!in_array(Verbs::OPTIONS, $_hostInfo['verbs'])) {
                     // add OPTION to allowed list
                     $_hostInfo['verbs'][] = Verbs::OPTIONS;
                 }
                 $_allowedVerbs = $_hostInfo['verbs'];
             }
         }
         //	All allowed?
         if (static::ALLOW_ALL == $_whiteGuy) {
             $isStar = true;
             return $_allowedVerbs;
         }
         if (false === ($_whiteParts = Uri::parse($_whiteGuy))) {
             $this->_logger->error('unable to parse "' . $_whiteGuy . '" whitelist entry');
             continue;
         }
         $this->_logger->debug('whitelist "' . $_whiteGuy . '" > parts: ' . print_r($_whiteParts, true));
         //	Check for un-parsed origin, 'null' sent when testing js files locally
         if (is_array($origin) && Uri::compare($origin, $_whiteParts)) {
             //	This origin is on the whitelist
             return $_allowedVerbs;
         }
     }
     return false;
 }
Exemplo n.º 6
0
 /**
  * Parses inbound data request for limits and sort and search
  *
  * @param int|string $defaultSort Default sort column name or number
  * @param array      $columns
  */
 protected function parseDataRequest($defaultSort = null, array &$columns = null)
 {
     $this->setDataTables(isset($_REQUEST, $_REQUEST['length']));
     $this->setSkip(array_get($_REQUEST, 'start', 0));
     $this->limit = array_get($_REQUEST, 'length', EnterpriseDefaults::DEFAULT_ITEMS_PER_PAGE);
     $this->order = $defaultSort;
     $this->search = trim(str_replace('\'', null, IfSet::getDeep($_REQUEST, 'search', 'value')));
     if (null === ($_sortOrder = array_get($_REQUEST, 'order'))) {
         return;
     }
     //  Parse the columns
     if (empty($this->columns) && empty($columns)) {
         $_dataColumns = array_get($_REQUEST, 'columns', []);
         $_columns = [];
         foreach ($_dataColumns as $_column) {
             if (null !== ($_name = array_get($_column, 'data', array_get($_column, 'name')))) {
                 $_columns[] = $_name;
             }
         }
         if (!empty($_columns)) {
             $this->columns = $columns = $_columns;
         }
     }
     $_sort = [];
     if (is_array($_sortOrder)) {
         foreach ($_sortOrder as $_key => $_value) {
             if (isset($_value['column'])) {
                 $_sort[$_value['column'] + 1] = array_get($_value, 'dir', 'ASC');
             }
         }
     } elseif (is_string($_sortOrder)) {
         $this->order = $_sort[$_sortOrder] = array_get($_REQUEST, 'dir', 'ASC');
     }
     if (!empty($_sort)) {
         $this->order = $_sort;
     }
 }