Example #1
0
 public function isExpired()
 {
     $now = new Carbon();
     if ($now->gte(new Carbon($this->expire_token))) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Check if the Feature is active
  *
  * @return bool
  */
 public function active()
 {
     $now = new Carbon();
     if ($this->start_time && $this->end_time) {
         return $now->gte($this->start_time) && $now->lte($this->end_time);
     } else {
         if ($this->start_time) {
             return $now->gte($this->start_time);
         } else {
             if ($this->end_time) {
                 return $now->lte($this->end_time);
             } else {
                 return true;
             }
         }
     }
 }
Example #3
0
 /**
  * Checks whether a battle is open for voting
  */
 public function isOpenVoting()
 {
     $trendingperiod = config('rap-battle.trendingperiod', 168);
     // battles after this date will be considered for trending
     $timeoldest = new Carbon();
     $timeoldest->subHours($trendingperiod);
     // creation date
     $cre = new Carbon($this->created_at);
     return $cre->gte($timeoldest);
 }
Example #4
0
 /**
  * Check if rule matches a period
  *
  * @param RedirectRule $rule
  * @return bool
  */
 private function matchesPeriod(RedirectRule $rule)
 {
     if ($rule->getFromDate() instanceof Carbon && $rule->getToDate() instanceof Carbon) {
         return $this->matchDate->between($rule->getFromDate(), $rule->getToDate());
     }
     if ($rule->getFromDate() instanceof Carbon && $rule->getToDate() === null) {
         return $this->matchDate->gte($rule->getFromDate());
     }
     if ($rule->getFromDate() === null && $rule->getToDate() instanceof Carbon) {
         return $this->matchDate->lte($rule->getToDate());
     }
     return true;
 }
Example #5
0
 /**
  * Datetime exact match check as well as between check
  * @param string $content
  * @param string $search
  * @param string $type
  * @return bool
  */
 public function filter($content, $search, $type)
 {
     $search = is_array($search) ? $search : [$search];
     $search = array_map(function ($searchValue) {
         return is_a($searchValue, Carbon::class) ? $searchValue : new Carbon($searchValue);
     }, $search);
     $current = new Carbon($content);
     switch ($type) {
         case 'in':
             return $current->gte($search[0]) && $current->lt($search[1]);
             break;
         default:
             return $current->eq($search[0]);
     }
 }
 public function update_time(Request $request)
 {
     if (!Auth::Check()) {
         return -2;
     }
     if (!Auth::user()->getAdmin()) {
         return -1;
     }
     if (empty($request->input('competition_start')) || empty($request->input('competition_end'))) {
         return 0;
     }
     $newstart = new Carbon($request->input('competition_start'));
     $newend = new Carbon($request->input('competition_end'));
     if ($newstart->gte($newend)) {
         DB::table('config')->where('name', '=', 'competition_start')->update(['val_datetime' => $newstart]);
         DB::table('config')->where('name', '=', 'competition_end')->update(['val_datetime' => '0000-00-00 00:00:00']);
     } else {
         // Verbose else
         DB::table('config')->where('name', '=', 'competition_start')->update(['val_datetime' => $newstart]);
         DB::table('config')->where('name', '=', 'competition_end')->update(['val_datetime' => $newend]);
     }
     return 1;
 }
 public function validateNotBeforeField($attribute, $value, $parameters)
 {
     $this->requireParameterCount(1, $parameters, 'before_field');
     $value2 = array_get($this->data, $parameters[0]);
     // make them Carbon dates
     if (!$value instanceof Carbon) {
         if (strtotime($value) === false) {
             return false;
         }
         $value = new Carbon($value);
     }
     if (!$value2 instanceof Carbon) {
         if (strtotime($value2) === false) {
             return false;
         }
         $value2 = new Carbon($value2);
     }
     return $value->gte($value2);
 }
Example #8
0
 protected function scanFile(FileRecord $file)
 {
     $virusTotal = new VirusTotalFile(config('virustotal.api_key'));
     if ($file->shouldCheckScan()) {
         $this->info(sprintf('Checking scan for file: %s (#%d)', $file->client_name, $file->id));
         $this->throttler->throttle(1);
         $result = $virusTotal->getReport($file->hash);
         $file->scan_checked_at = Carbon::now();
         $file->save();
         if ($result['response_code'] === 1) {
             $scannedAt = new Carbon($result['scan_date']);
             $cutoff = new Carbon('-2 weeks');
             // Check if this scan record already exists in DB
             $exists = Scan::where('virustotal_scan_id', '=', $result['scan_id'])->count() > 0;
             if ($scannedAt->gte($cutoff) && !$exists) {
                 /** @var Scan $scan */
                 $scan = Scan::create(['file_record_id' => $file->id, 'virustotal_scan_id' => $result['scan_id'], 'total' => $result['total'], 'positives' => $result['positives'], 'scanned_at' => $scannedAt, 'scans' => $result['scans']]);
                 $this->info(sprintf('Scan result: %d/%d', $scan->positives, $scan->total));
                 // We now have a report from a requested scan
                 $file->scan_requested_at = null;
                 $file->save();
                 $deleted = $this->actionScanResult($file, $scan);
                 if ($deleted) {
                     // Nothing else to do if deleted
                     return;
                 }
             }
         }
     }
     if ($file->shouldScanFile()) {
         // Max filesize for public API is 32mb
         if ($file->filesize <= 32 * pow(1024, 2)) {
             $this->info(sprintf('Uploading file for scan: %s (#%d)', $file->client_name, $file->id));
             $this->throttler->throttle(1);
             $result = $virusTotal->scan($file->filePath());
             if ($result['response_code'] === 1) {
                 $file->scan_requested_at = Carbon::now();
                 $file->save();
             }
         } else {
             // TODO: private API
         }
     } elseif ($file->shouldRescanFile()) {
         $this->info(sprintf('Requesting re-scan for file: %s (#%d)', $file->client_name, $file->id));
         $this->throttler->throttle(1);
         $result = $virusTotal->rescan($file->hash);
         if ($result['response_code'] === 1) {
             $file->scan_requested_at = Carbon::now();
             $file->save();
         }
     }
 }