Exemple #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     try {
         $data = $this->argument('data');
         if (filter_var($data, FILTER_VALIDATE_URL)) {
             // need to download file
             $data = FileUtilities::importUrlFileToTemp($data);
         }
         if (is_file($data)) {
             $data = file_get_contents($data);
         }
         $format = $this->option('format');
         $format = DataFormats::toNumeric($format);
         $this->comment($format);
         $service = $this->option('service');
         $resource = $this->option('resource');
         $result = ServiceHandler::handleRequest(Verbs::POST, $service, $resource, [], $data, $format);
         $this->info('Import complete!');
     } catch (\Exception $e) {
         $this->error($e->getMessage());
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (!class_exists('DreamFactory\\Core\\ADLdap\\Services\\ADLdap')) {
         $this->error('Command unavailable. Please install \'dreamfactory/df-adldap\' package to use this command.');
         return;
     }
     try {
         $serviceName = $this->argument('service');
         $username = $this->option('username');
         $password = $this->option('password');
         /** @type ADLdap $service */
         $service = ServiceHandler::getService($serviceName);
         $serviceModel = Service::find($service->getServiceId());
         $serviceType = $serviceModel->serviceType()->first();
         $serviceGroup = $serviceType->group;
         if ($serviceGroup !== ServiceTypeGroups::LDAP) {
             throw new BadRequestException('Invalid service name [' . $serviceName . ']. Please use a valid Active Directory service');
         }
         $this->line('Contacting your Active Directory server...');
         $service->authenticateAdminUser($username, $password);
         $this->line('Fetching Active Directory groups...');
         $groups = $service->getDriver()->listGroup(['dn', 'description']);
         $roles = [];
         foreach ($groups as $group) {
             $dfRole = RoleADLdap::whereDn($group['dn'])->first();
             if (empty($dfRole)) {
                 $role = ['name' => static::dnToRoleName($group['dn']), 'description' => $group['description'], 'is_active' => true, 'role_adldap_by_role_id' => [['dn' => $group['dn']]]];
                 $this->info('|--------------------------------------------------------------------');
                 $this->info('| DN: ' . $group['dn']);
                 $this->info('| Role Name: ' . $role['name']);
                 $this->info('| Description: ' . $role['description']);
                 $this->info('|--------------------------------------------------------------------');
                 $roles[] = $role;
             }
         }
         $roleCount = count($roles);
         if ($roleCount > 0) {
             $this->warn('Total Roles to import: [' . $roleCount . ']');
             if ($this->confirm('The above roles will be imported into your DreamFactroy instance based on your Active Directory groups. Do you wish to continue?')) {
                 $this->line('Importing Roles...');
                 $payload = ResourcesWrapper::wrapResources($roles);
                 ServiceHandler::handleRequest(Verbs::POST, 'system', 'role', ['continue' => true], $payload);
                 $this->info('Successfully imported all Active Directory groups as Roles.');
             } else {
                 $this->info('Aborted import process. No Roles were imported');
             }
         } else {
             if (count($groups) > 0 && $roleCount === 0) {
                 $this->info('All groups found on the Active Directory server are already imported.');
             } else {
                 $this->warn('No group was found on Active Directory server.');
             }
         }
     } catch (RestException $e) {
         $this->error($e->getMessage());
         if ($this->option('verbose')) {
             $this->error(print_r($e->getContext(), true));
         }
     } catch (\Exception $e) {
         $this->error($e->getMessage());
     }
 }
Exemple #3
0
 /**
  * Package schemas for export.
  *
  * @return bool
  * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
  */
 private function packageSchemas()
 {
     if (!empty($this->exportSchemas)) {
         $schemas = [];
         foreach ($this->exportSchemas as $serviceName => $component) {
             if (is_array($component)) {
                 $component = implode(',', $component);
             }
             if (is_numeric($serviceName)) {
                 /** @type Service $service */
                 $service = Service::find($serviceName);
             } else {
                 /** @type Service $service */
                 $service = Service::whereName($serviceName)->whereDeletable(1)->first();
             }
             if (!empty($service) && !empty($component)) {
                 if ($service->type === 'sql_db') {
                     $schema = ServiceHandler::handleRequest(Verbs::GET, $serviceName, '_schema', ['ids' => $component]);
                     $schemas[] = ['name' => $serviceName, 'table' => $this->resourceWrapped ? $schema[$this->resourceWrapper] : $schema];
                 }
             }
         }
         if (!empty($schemas) && !$this->zip->addFromString('schema.json', json_encode(['service' => $schemas], JSON_UNESCAPED_SLASHES))) {
             throw new InternalServerErrorException("Can not include database schema in package file.");
         }
         return true;
     }
     return false;
 }