コード例 #1
0
 /**
  * Create a new command instance.
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     if (config('df.managed')) {
         $this->cacheRoot = Managed::getCacheRoot();
     } else {
         $this->cacheRoot = storage_path('framework/cache');
     }
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: rajeshpillai/df-core
 public function __construct($dsn = '', $username = '', $password = '')
 {
     $file = substr($dsn, 7);
     if (false === strpos($file, DIRECTORY_SEPARATOR)) {
         // no directories involved, store it where we want to store it
         if (config('df.standalone')) {
             $storage = config('df.db.sqlite_storage');
         } else {
             $storage = Managed::getStoragePath();
             $storage = rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'databases';
         }
         if (!is_dir($storage)) {
             // Attempt
             @mkdir($storage);
         }
         if (!is_dir($storage)) {
             logger('Failed to access storage path ' . $storage);
             throw new InternalServerErrorException('Failed to access storage path.');
         }
         $dsn = 'sqlite:' . rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
     }
     parent::__construct($dsn, $username, $password);
 }
コード例 #3
0
ファイル: app.php プロジェクト: AxelKlarmann/dreamfactory
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton('Illuminate\\Contracts\\Http\\Kernel', 'DreamFactory\\Http\\Kernel');
$app->singleton('Illuminate\\Contracts\\Console\\Kernel', 'DreamFactory\\Console\\Kernel');
$app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'DreamFactory\\Exceptions\\Handler');
$app->configureMonologUsing(function ($monolog) {
    $logFile = storage_path('logs/dreamfactory.log');
    if (config('df.managed')) {
        $logFile = Managed::getLogFile();
    }
    $mode = config('app.log');
    if ($mode === 'syslog') {
        $monolog->pushHandler(new SyslogHandler('dreamfactory'));
    } else {
        if ($mode === 'single') {
            $handler = new StreamHandler($logFile);
        } else {
            if ($mode === 'errorlog') {
                $handler = new ErrorLogHandler();
            } else {
                $handler = new RotatingFileHandler($logFile, 5);
            }
        }
        $monolog->pushHandler($handler);
コード例 #4
0
 /**
  * Create a new command instance.
  */
 public function __construct()
 {
     parent::__construct();
     $this->cacheRoot = Managed::getCacheRoot();
 }
コード例 #5
0
 protected function setDriver($config)
 {
     $diskName = null;
     if (empty($config) || !isset($config['container'])) {
         $diskName = Config::get('filesystems.default');
     } else {
         $diskName = $config['container'];
     }
     if (empty($diskName)) {
         throw new InternalServerErrorException('Local file service driver/disk not configured. Please check configuration for file service - ' . $this->name . '.');
     }
     $disks = Config::get('filesystems.disks');
     if (!array_key_exists($diskName, $disks)) {
         throw new InternalServerErrorException('Local file service disk - ' . $diskName . ' not found.Please check configuration for file service - ' . $this->name . '.');
     }
     $disk = ArrayUtils::get($disks, $diskName);
     //  Replace any private lookups
     Session::replaceLookups($disk, true);
     if (!isset($disk['driver'])) {
         throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Driver not specified.');
     }
     switch ($disk['driver']) {
         case 'local':
             if (config('df.standalone')) {
                 $root = $disk['root'];
             } else {
                 $root = Managed::getStoragePath(config('df.local_file_service_container'));
             }
             if (!is_dir($root)) {
                 mkdir($root, 0775);
             }
             if (empty($root)) {
                 throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not specified.');
             }
             if (!is_dir($root)) {
                 throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not found.');
             }
             $this->driver = new LocalFileSystem($root);
             break;
         case 's3':
             $this->container = ArrayUtils::get($disk, 'bucket', ArrayUtils::get($disk, 'container'));
             ArrayUtils::set($disk, 'container', $this->container);
             if (empty($this->container)) {
                 throw new InternalServerErrorException('S3 file service bucket/container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new S3FileSystem($disk);
             break;
         case 'rackspace':
             $this->container = ArrayUtils::get($disk, 'container');
             if (empty($this->container)) {
                 throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new OpenStackObjectStorageSystem($disk);
             break;
         case 'azure':
             $this->container = ArrayUtils::get($disk, 'container');
             if (empty($this->container)) {
                 throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
             }
             $this->driver = new AzureBlobFileSystem($disk);
             break;
         default:
             break;
     }
 }
コード例 #6
0
ファイル: Limits.php プロジェクト: rajeshpillai/dreamfactory
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //Get the Console API Key
     $consoleApiKey = AccessCheck::getConsoleApiKey($request);
     // Get limits
     if (config('df.standalone') === true || $consoleApiKey === Managed::getConsoleKey()) {
         return $next($request);
     } else {
         $limits = Managed::getLimits();
         // The limits array comes across from the console as a bunch of Std Objects, need to turn it back
         // into an array
         $limits['api'] = (array) $limits['api'];
         foreach (array_keys($limits['api']) as $key) {
             $limits['api'][$key] = (array) $limits['api'][$key];
         }
     }
     if (!empty($limits) && is_null($this->_getServiceName()) === false) {
         $this->_inUnitTest = \Config::get('api_limits_test');
         $userName = $this->_getUser(Session::getCurrentUserId());
         $userRole = $this->_getRole(Session::getRoleId());
         $apiName = $this->_getApiKey(Session::getApiKey());
         $serviceName = $this->_getServiceName();
         $clusterName = Managed::getClusterName();
         // Build the list of API Hits to check
         $apiKeysToCheck = ['cluster.default' => 0, 'instance.default' => 0];
         $serviceKeys[$serviceName] = 0;
         if (is_null($userRole) === false) {
             $serviceKeys[$serviceName . '.' . $userRole] = 0;
         }
         if (is_null($userName) === false) {
             $serviceKeys[$serviceName . '.' . $userName] = 0;
         }
         if (is_null($apiName) === false) {
             $apiKeysToCheck[$apiName] = 0;
             if (is_null($userRole) === false) {
                 $apiKeysToCheck[$apiName . '.' . $userRole] = 0;
             }
             if (is_null($userName) === false) {
                 $apiKeysToCheck[$apiName . '.' . $userName] = 0;
             }
             foreach ($serviceKeys as $key => $value) {
                 $apiKeysToCheck[$apiName . '.' . $key] = $value;
             }
         }
         if (is_null($clusterName) === false) {
             $apiKeysToCheck[$clusterName] = 0;
             if (is_null($userRole) === false) {
                 $apiKeysToCheck[$clusterName . '.' . $userRole] = 0;
             }
             if (is_null($userName) === false) {
                 $apiKeysToCheck[$clusterName . '.' . $userName] = 0;
             }
             foreach ($serviceKeys as $key => $value) {
                 $apiKeysToCheck[$clusterName . '.' . $key] = $value;
             }
         }
         if (is_null($userName) === false) {
             $apiKeysToCheck[$userName] = 0;
         }
         if (is_null($userRole) === false) {
             $apiKeysToCheck[$userRole] = 0;
         }
         $apiKeysToCheck = array_merge($apiKeysToCheck, $serviceKeys);
         $timePeriods = ['minute', 'hour', 'day', '7-day', '30-day'];
         $overLimit = false;
         try {
             foreach (array_keys($apiKeysToCheck) as $key) {
                 foreach ($timePeriods as $period) {
                     $keyToCheck = $key . '.' . $period;
                     if (array_key_exists($keyToCheck, $limits['api']) === true) {
                         $cacheValue = \Cache::get($keyToCheck, 0);
                         $cacheValue++;
                         \Cache::put($keyToCheck, $cacheValue, $limits['api'][$keyToCheck]['period']);
                         if ($cacheValue > $limits['api'][$keyToCheck]['limit']) {
                             $overLimit = true;
                         }
                     }
                 }
             }
         } catch (\Exception $e) {
             return ResponseFactory::getException(new InternalServerErrorException('Unable to update cache'), $request);
         }
         if ($overLimit === true) {
             return ResponseFactory::getException(new TooManyRequestsException('Specified connection limit exceeded'), $request);
         }
     }
     return $next($request);
 }
コード例 #7
0
 /**
  * @param Request $request
  * @param Closure $next
  *
  * @return array|mixed|string
  */
 public function handle($request, Closure $next)
 {
     try {
         static::setExceptions();
         //Get the api key.
         $apiKey = static::getApiKey($request);
         Session::setApiKey($apiKey);
         $appId = App::getAppIdByApiKey($apiKey);
         //Get the JWT.
         $token = static::getJwt($request);
         Session::setSessionToken($token);
         //Get the Console API Key
         $consoleApiKey = static::getConsoleApiKey($request);
         //Check for basic auth attempt.
         $basicAuthUser = $request->getUser();
         $basicAuthPassword = $request->getPassword();
         if (config('df.managed') && !empty($consoleApiKey) && $consoleApiKey === Managed::getConsoleKey()) {
             //DFE Console request
             return $next($request);
         } elseif (!empty($basicAuthUser) && !empty($basicAuthPassword)) {
             //Attempting to login using basic auth.
             Auth::onceBasic();
             /** @var User $authenticatedUser */
             $authenticatedUser = Auth::user();
             if (!empty($authenticatedUser)) {
                 $userId = $authenticatedUser->id;
                 Session::setSessionData($appId, $userId);
             } else {
                 throw new UnauthorizedException('Unauthorized. User credentials did not match.');
             }
         } elseif (!empty($token)) {
             //JWT supplied meaning an authenticated user session/token.
             try {
                 JWTAuth::setToken($token);
                 /** @type Payload $payload */
                 $payload = JWTAuth::getPayload();
                 JWTUtilities::verifyUser($payload);
                 $userId = $payload->get('user_id');
                 Session::setSessionData($appId, $userId);
             } catch (TokenExpiredException $e) {
                 JWTUtilities::clearAllExpiredTokenMaps();
                 if (!static::isException($request)) {
                     throw new UnauthorizedException($e->getMessage());
                 }
             } catch (TokenBlacklistedException $e) {
                 throw new ForbiddenException($e->getMessage());
             } catch (TokenInvalidException $e) {
                 throw new BadRequestException('Invalid token: ' . $e->getMessage(), 401);
             }
         } elseif (!empty($apiKey)) {
             //Just Api Key is supplied. No authenticated session
             Session::setSessionData($appId);
         } elseif (static::isException($request)) {
             //Path exception.
             return $next($request);
         } else {
             throw new BadRequestException('Bad request. No token or api key provided.');
         }
         if (static::isAccessAllowed()) {
             return $next($request);
         } elseif (static::isException($request)) {
             //API key and/or (non-admin) user logged in, but if access is still not allowed then check for exception case.
             return $next($request);
         } else {
             if (!Session::isAuthenticated()) {
                 throw new UnauthorizedException('Unauthorized.');
             } else {
                 throw new ForbiddenException('Access Forbidden.');
             }
         }
     } catch (\Exception $e) {
         return ResponseFactory::getException($e, $request);
     }
 }
コード例 #8
0
ファイル: cache.php プロジェクト: AxelKlarmann/dreamfactory
<?php

use DreamFactory\Managed\Support\Managed;
return ['default' => env('CACHE_DRIVER', 'file'), 'stores' => ['apc' => ['driver' => 'apc'], 'array' => ['driver' => 'array'], 'database' => ['driver' => 'database', 'table' => 'cache', 'connection' => null], 'file' => ['driver' => 'file', 'path' => env('DF_MANAGED') ? Managed::getCachePath() : storage_path('framework/cache')], 'memcached' => ['driver' => 'memcached', 'servers' => [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100]]], 'redis' => ['driver' => 'redis', 'connection' => 'default']], 'prefix' => env('DF_MANAGED') ? Managed::getCacheKeyPrefix() : 'dreamfactory'];
コード例 #9
0
ファイル: cache.php プロジェクト: sadiq7753/dreamfactory
<?php

return ['default' => env('CACHE_DRIVER', 'file'), 'stores' => ['apc' => ['driver' => 'apc'], 'array' => ['driver' => 'array'], 'database' => ['driver' => 'database', 'table' => 'cache', 'connection' => null], 'file' => ['driver' => 'file', 'path' => DreamFactory\Managed\Support\Managed::getCachePath()], 'memcached' => ['driver' => 'memcached', 'servers' => [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100]]], 'redis' => ['driver' => 'redis', 'connection' => 'default']], 'prefix' => \DreamFactory\Managed\Support\Managed::getCacheKeyPrefix()];