/**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     /*
      * Provide a method to override the default configuration per environment. We only accept three named
      * environments called development, testing and production. Each of these environments has a directory
      * inside config where an config override can be made.
      */
     $envConfig = Config::get(app()->environment());
     if (!empty($envConfig) && is_array($envConfig)) {
         foreach ($envConfig as $configKey => $configElement) {
             $overrideConfig = $envConfig[$configKey];
             $defaultConfig = Config::get($configKey);
             $configWithOverrides = array_replace_recursive($defaultConfig, $overrideConfig);
             Config::set($configKey, $configWithOverrides);
         }
     }
     /*
      * Were updating the timezone manually because we are updating the config later then boot. Using method from:
      * vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
      * This enforces the timezone we use in the override config file.
      */
     date_default_timezone_set(config('app.timezone'));
     // Publish config files of all installed Parsers
     // All parser configs we will put into the master 'parsers' tree of the config
     // So we can easily walk through all of them based on the active configuration
     $parserList = ParserFactory::getParsers();
     $this->buildConfig($parserList, 'parser');
     // Publish config files of all installed Collectors the same way
     $collectorList = CollectorFactory::getCollectors();
     $this->buildConfig($collectorList, 'collector');
     // Publish config files of all installed Collectors the same way
     $notificationList = NotificationFactory::getNotification();
     $this->buildConfig($notificationList, 'notification');
 }
示例#2
0
 /**
  * Create and return a Parser class and it's configuration
  * @param  \PhpMimeMailParser\Parser $parsedMail
  * @param  array $arfMail
  * @return object parser
  */
 public static function create($parsedMail, $arfMail)
 {
     /**
      * Loop through the parser list and try to find a match by
      * validating the send or the body according to the parsers'
      * configuration.
      */
     $parsers = Factory::getParsers();
     foreach ($parsers as $parserName) {
         $parserClass = 'AbuseIO\\Parsers\\' . $parserName;
         // Parser is enabled, see if we can match it's sender_map or body_map
         if (config("parsers.{$parserName}.parser.enabled") === true) {
             // Check validity of the 'report_file' setting before we continue
             // If no report_file is used, continue w/o validation
             $report_file = config("parsers.{$parserName}.parser.report_file");
             if ($report_file == null || is_string($report_file) && isValidRegex($report_file)) {
                 $isValidReport = true;
             } else {
                 $isValidReport = false;
                 Log::warning('AbuseIO\\Parsers\\Factory: ' . "The parser {$parserName} has an invalid value for 'report_file' (not a regex).");
                 break;
             }
             // Check the sender address
             foreach (config("parsers.{$parserName}.parser.sender_map") as $senderMap) {
                 if (isValidRegex($senderMap)) {
                     if (preg_match($senderMap, $parsedMail->getHeader('from')) && $isValidReport) {
                         return new $parserClass($parsedMail, $arfMail);
                     }
                 } else {
                     Log::warning('AbuseIO\\Parsers\\Factory: ' . "The parser {$parserName} has an invalid value for 'sender_map' (not a regex).");
                 }
             }
             // If no valid sender is found, check the body
             foreach (config("parsers.{$parserName}.parser.body_map") as $bodyMap) {
                 if (isValidRegex($bodyMap)) {
                     if (preg_match($bodyMap, $parsedMail->getMessageBody()) && $isValidReport) {
                         return new $parserClass($parsedMail, $arfMail);
                     }
                     if ($arfMail !== false) {
                         foreach ($arfMail as $mailPart) {
                             if (preg_match($bodyMap, $mailPart)) {
                                 return new $parserClass($parsedMail, $arfMail);
                             }
                         }
                     }
                 } else {
                     Log::warning('AbuseIO\\Parsers\\Factory: ' . "The parser {$parserName} has an invalid value for 'body_map' (not a regex).");
                 }
             }
         } else {
             Log::info('AbuseIO\\Parsers\\Factory: ' . "The parser {$parserName} has been disabled and will not be used for this message.");
         }
     }
     // No valid parsers found
     return false;
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     // Publish config files of all installed Parsers
     // All parser configs we will put into the master 'parsers' tree of the config
     // So we can easily walk through all of them based on the active configuration
     $parserList = Factory::getParsers();
     foreach ($parserList as $parser) {
         $basePath = base_path() . '/vendor/abuseio/parser-' . strtolower($parser) . '/config';
         $parserConfig = $basePath . "/{$parser}.php";
         if (File::exists($parserConfig)) {
             $this->mergeConfigFrom($parserConfig, 'parsers.' . $parser);
         }
         $parserOverride = $basePath . '/' . app()->environment() . "/{$parser}.php";
         if (File::exists($parserOverride)) {
             $this->mergeConfigFrom($parserOverride, app()->environment() . '.parsers.' . $parser);
         }
     }
 }