Example #1
0
 public function __construct($sourceId)
 {
     parent::__construct();
     $this->source = SourceWebFolder::createType(Source::getById($sourceId));
     if (!$this->source->hasRow()) {
         redirect(url('controlpanel.source'));
     }
     if ($this->isPostBack()) {
         $this->post->type->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->name->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->subdomain->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->base_url->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputUri()]);
         if (!$this->hasErrors()) {
             $updateDns = false;
             // Update DNS if the subdomain has changed
             if ($this->source->subdomain != trim(strtolower($this->input('subdomain')))) {
                 $updateDns = true;
             }
             $this->subdomain = $this->source->subdomain;
             $this->source->name = $this->input('name');
             $this->source->type = $this->input('type');
             $this->source->setSubdomain($this->input('subdomain'));
             $this->source->require_ssl = $this->input('require_ssl');
             $this->source->default_parameters = $this->input('default_parameters');
             $this->source->error_image_url = $this->input('error_image_url');
             $this->source->error_image_parameters = $this->input('error_image_parameters');
             $this->source->missing_image_url = $this->input('missing_image_url');
             $this->source->missing_image_parameters = $this->input('missing_image_parameters');
             $this->source->organisation_id = $this->currentUser->getActiveOrganisation();
             $this->source->setBaseUrl($this->input('base_url'));
             $this->edit($updateDns);
         }
     }
 }
 public function sourceDelete($sourceId)
 {
     $source = Source::getById($sourceId);
     if ($source->hasRow()) {
         $source->delete();
         $this->setMessage('Source has been deleted', 'success');
     }
     redirect(url('controlpanel.source'));
 }
Example #3
0
 protected function getSources()
 {
     $sources = Source::get($this->organisation->id);
     $output = array('' => lang('All'));
     if ($sources->hasRows()) {
         foreach ($sources as $source) {
             $output[$source->id] = $source->name;
         }
     }
     return $output;
 }
Example #4
0
 protected function save(Source $source)
 {
     try {
         $cloudflareIdentifiers = array();
         if (!env('DEBUG', false)) {
             $cloudflareIdentifiers = $this->updateDns($this->input('subdomain'));
             if (count($cloudflareIdentifiers) === 0) {
                 $this->setError('Failed to create subdomain - please contact support');
             }
         }
         if (!$this->hasErrors()) {
             $source->setCloudflareIdentifiers($cloudflareIdentifiers);
             $source->save();
             $this->setMessage('Source has been added - please wait up to 30 minutes for the cache to get synchronized.', 'success');
         }
     } catch (SourceException $e) {
         $this->setError($e->getMessage());
         response()->refresh();
     }
     redirect(url('controlpanel.source'));
 }
Example #5
0
 public function __construct($sourceId)
 {
     parent::__construct();
     $this->source = SourceFtp::createType(Source::getById($sourceId));
     if (!$this->source->hasRow()) {
         redirect(url('controlpanel.source'));
     }
     if ($this->isPostBack()) {
         // TODO: add correct validation for subdomain + s3
         $this->post->type->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->name->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->subdomain->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->connect_type->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->host->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $updateDns = false;
             // Update DNS if the subdomain has changed
             if ($this->source->subdomain != trim(strtolower($this->input('subdomain')))) {
                 $updateDns = true;
             }
             $this->subdomain = $this->source->subdomain;
             $this->source->name = $this->input('name');
             $this->source->type = $this->input('type');
             $this->source->setSubdomain($this->input('subdomain'));
             $this->source->require_ssl = $this->input('require_ssl');
             $this->source->default_parameters = $this->input('default_parameters');
             $this->source->error_image_url = $this->input('error_image_url');
             $this->source->error_image_parameters = $this->input('error_image_parameters');
             $this->source->missing_image_url = $this->input('missing_image_url');
             $this->source->missing_image_parameters = $this->input('missing_image_parameters');
             $this->source->organisation_id = $this->currentUser->getActiveOrganisation();
             $this->source->setConnectType($this->input('connect_type'));
             $this->source->setHost($this->input('host'));
             $this->source->setPort($this->input('port'));
             $this->source->setUsername($this->input('username'));
             $this->source->setPassword($this->input('password'));
             $this->source->setStartDirectory($this->input('start_directory'));
             $this->edit($updateDns);
         }
     }
 }
Example #6
0
 public function __construct($sourceId)
 {
     parent::__construct();
     $source = Source::getById($sourceId);
     if ($source->hasRow()) {
         // Delete thumbnails
         $thumbnails = ModelThumbnail::getBySourceId($source->id);
         if ($thumbnails->hasRows()) {
             foreach ($thumbnails->getRows() as $thumbnail) {
                 $thumbnail->delete();
             }
         }
         Memcache::getInstance()->clear('source_' . $source->subdomain);
         /*$cache = new Cache(getenv('CLOUDFLARE_API_EMAIL'), getenv('CLOUDFLARE_API_KEY'));
           $cache->purge_files(getenv('CLOUDFLARE_ZONE_ID'), array(
               'files' => sprintf('http://%s/*', $source->subdomain)
           ));*/
         $this->setMessage('The cache has been purged', 'success');
         redirect(url('controlpanel.source'));
     }
 }
Example #7
0
 public function __construct($sourceId)
 {
     parent::__construct();
     $this->source = SourceAmazonS3::createType(Source::getById($sourceId));
     if (!$this->source->hasRow()) {
         redirect(url('controlpanel.source'));
     }
     if ($this->isPostBack()) {
         // TODO: add correct validation for subdomain + s3
         $this->post->type->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->name->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->subdomain->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->access_key->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->secret_key->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->s3_bucket->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $updateDns = false;
             // Update DNS if the subdomain has changed
             if ($this->source->subdomain != trim(strtolower($this->input('subdomain')))) {
                 $updateDns = true;
             }
             $this->subdomain = $this->source->subdomain;
             $this->source->name = $this->input('name');
             $this->source->type = $this->input('type');
             $this->source->setSubdomain($this->input('subdomain'));
             $this->source->require_ssl = $this->input('require_ssl');
             $this->source->default_parameters = $this->input('default_parameters');
             $this->source->error_image_url = $this->input('error_image_url');
             $this->source->error_image_parameters = $this->input('error_image_parameters');
             $this->source->missing_image_url = $this->input('missing_image_url');
             $this->source->missing_image_parameters = $this->input('missing_image_parameters');
             $this->source->organisation_id = $this->currentUser->getActiveOrganisation();
             $this->source->setKey($this->input('access_key'));
             $this->source->setSecret($this->input('secret_key'));
             $this->source->setBucket($this->input('s3_bucket'));
             $this->source->setPrefix($this->input('prefix'));
             $this->edit($updateDns);
         }
     }
 }
Example #8
0
 public function __construct($sourceId)
 {
     parent::__construct();
     $this->source = SourceDropbox::createType(Source::getById($sourceId));
     if (!$this->source->hasRow()) {
         redirect(url('controlpanel.source'));
     }
     if ($this->isPostBack()) {
         $this->post->type->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->name->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->subdomain->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->access_token->addValidation([new ValidateInputNotNullOrEmpty()]);
         $this->post->client_identifier->addValidation([new ValidateInputNotNullOrEmpty()]);
         if (!$this->hasErrors()) {
             $updateDns = false;
             // Update DNS if the subdomain has changed
             if ($this->source->subdomain != trim(strtolower($this->input('subdomain')))) {
                 $updateDns = true;
             }
             $this->source->name = $this->input('name');
             $this->source->type = $this->input('type');
             $this->source->setSubdomain($this->input('subdomain'));
             $this->source->require_ssl = $this->input('require_ssl');
             $this->source->default_parameters = $this->input('default_parameters');
             $this->source->error_image_url = $this->input('error_image_url');
             $this->source->error_image_parameters = $this->input('error_image_parameters');
             $this->source->missing_image_url = $this->input('missing_image_url');
             $this->source->missing_image_parameters = $this->input('missing_image_parameters');
             $this->source->organisation_id = $this->currentUser->getActiveOrganisation();
             $this->source->setAccessToken($this->input('access_token'));
             $this->source->setClientIdentifier($this->input('client_identifier'));
             $this->source->setStartDirectory($this->input('start_directory'));
             $this->edit($updateDns);
         }
     }
 }
Example #9
0
 public function handle(Request $request)
 {
     $domain = env('DEBUG', false) ? 'dscuz' : str_ireplace('.' . Registry::getInstance()->get('host'), '', $request->getHost());
     $request->source = Memcache::getInstance()->put('source_' . $domain, 60 * 60, function () use($domain) {
         return Source::getBySubdomain($domain);
     });
     $this->setParameters($request);
     if (!$request->source->hasRow()) {
         throw new \ErrorException('Invalid source.');
     }
     if ($request->source->getOrganisation() !== null && $request->source->getOrganisation()->disabled) {
         throw new OrganisationDisabledException('Source has been disabled');
     }
     if ($request->source->require_ssl && !$request->getIsSecure()) {
         redirect('https://' . $request->getHost() . $request->getUri(), 101);
     }
     // Check for valid api-token if posting
     if ($request->getMethod() !== 'get') {
         $token = request()->getHeader('X-Auth-Token');
         if ($token === null || $token !== $request->source->getOrganisation()->api_token) {
             throw new \InvalidArgumentException('Invalid X-Auth-Token.');
         }
     }
 }
Example #10
0
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Sources'));
     $this->sources = Source::get($this->activeOrganisation->id, 20);
 }
Example #11
0
 public static function createType(Source $source)
 {
     $type = new static();
     $type->setResults($source->getResults());
     $type->data = $source->data;
     return $type;
 }
Example #12
0
 public function getSource()
 {
     return Source::getById($this->source_id);
 }