예제 #1
0
파일: Home.php 프로젝트: Monori/imgservice
 public function __construct($organisationId)
 {
     parent::__construct($organisationId);
     $this->bandwidthTotal = ModelActivity::getBandwidthByDate($organisationId);
     $this->bandwidthMonth = ModelActivity::getBandwidthByDate($organisationId, date('01-m-Y'));
     $this->bandwidthTotal = ModelActivity::getBandwidthByDate($organisationId);
     $this->bandwidthToday = ModelActivity::getBandwidthByDate($organisationId, Date::toDate());
     $this->bandwidthMonth = ModelActivity::getBandwidthByDate($organisationId, date('01-m-Y'));
     $this->bandwidthTotal = ModelActivity::getBandwidthByDate($organisationId);
     $this->masterImagesToday = ModelActivity::getMasterImagesBydate($organisationId, Date::toDate());
     $this->masterImagesMonth = ModelActivity::getMasterImagesBydate($organisationId, date('01-m-Y'));
     $this->masterImagesTotal = ModelActivity::getMasterImagesBydate($organisationId);
     $this->rendersToday = ModelActivity::getRendersByDate($organisationId, Date::toDate());
     $this->rendersMonth = ModelActivity::getRendersByDate($organisationId, date('01-m-Y'), date('01-m-Y'));
     $this->rendersTotal = ModelActivity::getRendersByDate($organisationId);
     if ($this->isPostBack()) {
         $action = strtolower($this->input('action'));
         if ($action === 'delete') {
             $this->organisation->deleted = !$this->organisation->deleted;
         }
         if ($action === 'disable') {
             $this->organisation->disabled = !$this->organisation->disabled;
         }
         $this->organisation->update();
         $this->setMessage(lang('Organisation updated'), 'success');
         response()->refresh();
     }
 }
예제 #2
0
 public function index()
 {
     $organisationId = request()->organisation->id;
     $bandwidthToday = ModelActivity::getBandwidthByDate($organisationId, Date::toDate());
     $bandwidthTotal = ModelActivity::getBandwidthByDate($organisationId);
     $masterImagesToday = ModelActivity::getMasterImagesBydate($organisationId, Date::toDate());
     $masterImagesTotal = ModelActivity::getMasterImagesBydate($organisationId);
     $rendersToday = ModelActivity::getRendersByDate($organisationId, Date::toDate());
     $rendersTotal = ModelActivity::getRendersByDate($organisationId);
     response()->json(['bandwidth_today' => $bandwidthToday, 'bandwidth_total' => $bandwidthTotal, 'masterimages_today' => $masterImagesToday, 'masterimages_total' => $masterImagesTotal, 'renders_today' => $rendersToday, 'renders_total' => $rendersTotal]);
 }
예제 #3
0
 public function __construct()
 {
     // Defines the table we are using
     $table = new DBTable();
     $table->column('id')->integer()->primary()->increment();
     $table->column('name')->string(255);
     $table->column('date')->datetime()->index();
     parent::__construct($table);
     // If we want any default values that is not required for the users to set we add them here.
     // We can always overwrite them later by doing $company->date = [NEW-VALUE]
     $this->date = \Pecee\Date::ToDateTime();
     $this->metadata = new ModelCompanyData();
 }
예제 #4
0
 public function __construct()
 {
     $table = new DBTable();
     $table->column('id')->bigint()->primary()->increment();
     $table->column('organisation_id')->bigint()->index();
     $table->column('amount')->float()->index();
     $table->column('currency')->string(40)->nullable();
     $table->column('transaction_id')->string()->nullable()->index();
     $table->column('period_start')->date()->index();
     $table->column('period_end')->date()->index();
     $table->column('payment_date')->datetime()->index();
     parent::__construct($table);
     $this->amount = 0;
     $this->payment_date = Date::toDateTime();
 }
예제 #5
0
 public function __construct()
 {
     $table = new DBTable();
     $table->column('id')->bigint()->increment()->primary();
     $table->column('source_id')->bigint()->index();
     $table->column('cdn')->string(255)->index();
     $table->column('name')->string(300)->index();
     $table->column('original_name')->string(300)->index();
     $table->column('path')->string(500)->index();
     $table->column('mime')->string(255)->index();
     $table->column('size')->integer()->index();
     $table->column('identifier')->string(32)->index();
     $table->column('last_activity')->datetime()->nullable()->index();
     $table->column('created')->datetime()->index();
     parent::__construct($table);
     $this->created = Date::toDateTime();
 }
예제 #6
0
 public function __construct()
 {
     $table = new DBTable();
     $table->column('id')->bigint()->primary()->increment();
     $table->column('user_id')->bigint()->index();
     $table->column('organisation_id')->bigint()->index();
     $table->column('invoice_id')->integer()->index();
     $table->column('path')->string(300);
     $table->column('due_date')->date()->index();
     $table->column('amount_total')->integer()->index();
     $table->column('payed')->bool()->index();
     $table->column('created')->datetime()->index();
     parent::__construct($table);
     if (ModelUser::current()->isLoggedIn()) {
         $this->user_id = ModelUser::current()->id;
     }
     $this->created = Date::toDateTime();
 }
예제 #7
0
 public function __construct()
 {
     $table = new DBTable('source');
     $table->column('id')->bigint()->primary()->increment();
     $table->column('organisation_id')->integer()->index();
     $table->column('name')->string(255);
     $table->column('type')->string(255)->index();
     $table->column('subdomain')->string(255)->index();
     $table->column('require_ssl')->bool();
     $table->column('error_image_url')->string(400);
     $table->column('error_image_parameters')->text();
     $table->column('missing_image_url')->string(400);
     $table->column('missing_image_parameters')->text();
     $table->column('default_parameters')->text();
     $table->column('last_activity')->datetime()->index();
     parent::__construct($table);
     $this->cloudflareIds = array();
     $this->last_activity = Date::toDateTime();
 }
예제 #8
0
function shutdownAccount(\NinjaImg\Model\ModelOrganisation $organisation, $amount)
{
    $lastMonthDate = date('Y-m-01', strtotime('-1 month'));
    $currency = \NinjaImg\Model\ModelSettings::getInstance()->getCurrency();
    $lastPaymentDate = \NinjaImg\Model\ModelPayment::getLastPaymentDate($organisation->id, $lastMonthDate);
    if (!$lastPaymentDate) {
        $lastPaymentDate = \Pecee\Date::toDateTime();
        savePayment($organisation->id, $amount, $lastMonthDate);
    }
    $lastTryDaysAgo = daysAgo($lastPaymentDate, \Pecee\Date::toDateTime());
    if ($lastTryDaysAgo > MAX_PAYMENT_ATTEMPTS_DAYS) {
        echo sprintf('disabled due to no payment in %s days', MAX_PAYMENT_ATTEMPTS_DAYS);
        mailAdmins('[WARNING] ' . $organisation->name . ' shut down warning', sprintf("Hi bitches!\n\nThe organisation {$organisation->name} has been shut down due to invalid and/or no payment in over %s days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // TODO: Send notification to user about shutting down
        $organisation->disabled = true;
        $organisation->update();
    } else {
        $shutdownDays = MAX_PAYMENT_ATTEMPTS_DAYS - $lastTryDaysAgo;
        echo sprintf('%s days before shutting down account', $shutdownDays);
        mailAdmins('[INFO] ' . $organisation->name . ' payment not received', sprintf("Hi bitches!\n\nFailed to charge {$organisation->name} and will be automatically disabled in {$shutdownDays} days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // Register try
    }
}
예제 #9
0
 public function __construct()
 {
     $table = new DBTable('activity');
     $table->column('id')->bigint()->increment()->primary();
     $table->column('source_id')->bigint()->index();
     $table->column('thumbnail_id')->bigint()->nullable()->index();
     $table->column('path')->string(400);
     $table->column('method')->string(30);
     $table->column('agent')->string()->nullable();
     $table->column('referer')->string()->nullable();
     $table->column('ip')->string()->index();
     /**
      * NOTE: identifier is the file's unique id - based on the "path" column.
      * It is used as a faster way to determinate if a path has been accessed multiple times,
      * when calculating statistics - and might speed up things when inserting instead of
      * creating an index to the path column.
      **/
     $table->column('identifier')->string(36)->index();
     $table->column('filesize')->integer()->nullable()->index();
     $table->column('master')->bool()->index();
     $table->column('created')->datetime()->index();
     parent::__construct($table);
     $this->created = Date::toDateTime();
 }
예제 #10
0
    $capacity = round(disk_free_space($cdn->path) / 1024 / 1024 / 1024);
    $leftPercentage = round($capacity / $total * 100);
    $lastRun = isset($settings['last_run']) ? $settings['last_run'] : 'Not available';
    /**
     * Send warning if the storage left is <= NOTIFY_MIN_SPACE_PERCENTAGE
     * OTHERWISE
     * send notification if change is > NOTIFY_PERCENTAGE_CHANGE
     */
    $cdn->active = true;
    if ($leftPercentage <= NOTIFY_MIN_SPACE_PERCENTAGE) {
        echo '      - [WARNING] Storage critical: ' . $cdn->capacity_free_gb . '/' . $total . 'GB left' . chr(10);
        mailAdmins('WARNING: STORAGE ALMOST EMPTY ' . $cdn->name, "Yo, bitches!\n\nWARNING: content-provider \"{$cdn->name}\" has almost exceeded it's disk space and has disabled automatically.\n\nLast recorded date:         {$lastRun}\nLast recorded diskspace:    " . round($cdn->capacity_free_gb) . "GB\nDiskspace available:        " . round($capacity) . "GB\nDiskspace limit:            " . round($total) . "GB\n\n- The Ninja Robot");
        $cdn->active = false;
    } else {
        if ($cdn->capacity_free_gb > 0) {
            $beforePercentage = round($cdn->capacity_free_gb / $total * 100);
            $change = $leftPercentage - $beforePercentage;
            echo '      - [INFO] Storage changed by ' . $change . '%' . chr(10);
            if ($change >= NOTIFY_PERCENTAGE_CHANGE) {
                mailAdmins('Storage notification for ' . $cdn->name, "Yo, bitches!\n\nPlease be aware that content-provider \"{$cdn->name}\" has expanded it's storage by {$change}%.\n\nLast recorded date:         {$lastRun}\nLast recorded diskspace:    " . round($cdn->capacity_free_gb) . "GB\nDiskspace available:        " . round($capacity) . "GB\nDiskspace limit:            " . round($total) . "GB\nIncrease percentage:        {$change}%\n\nA warning will be sent when the storage-provider has " . NOTIFY_MIN_SPACE_PERCENTAGE . "% storage left.\n\n- The Ninja Robot");
            }
        }
    }
    echo chr(10);
    $cdn->capacity_free_gb = $capacity;
    $cdn->capacity_max_gb = $total;
    $cdn->update();
}
// Update settings
$settings['last_run'] = \Pecee\Date::toDateTime();
writeSettings();
예제 #11
0
 public static function getByEmail($email)
 {
     return self::fetchOne('SELECT * FROM {table} WHERE `email` = %s && `created` > %s', $email, Date::toDateTime(strtotime('-5 day')));
 }
예제 #12
0
 public static function daysAgo($date1, $date2)
 {
     $diff = Date::toDate(strtotime($date1)) - Date::toDate(strtotime($date2));
     return floor($diff / (60 * 60 * 24));
 }
예제 #13
0
 protected function update()
 {
     $this->post->invoice_id->addValidation(new ValidateInputNotNullOrEmpty());
     $this->post->due_date->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputDate()]);
     $this->post->amount->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputFloat()]);
     if (!$this->hasErrors()) {
         $this->invoice->invoice_id = $this->input('invoice_id');
         $this->invoice->due_date = Date::toDate(strtotime($this->input('due_date')));
         $this->invoice->amount_total = $this->input('amount');
         $this->invoice->payed = $this->input('payed');
         if ($this->file->invoice instanceof InputFile) {
             // Delete old invoice
             $tmp = explode('?', basename($this->invoice->path));
             $this->deleteS3($tmp[0]);
             $path = $this->uploadS3($this->file->invoice->tmpname, $this->input('invoice_id') . '.' . File::getExtension($this->invoice->invoide_id));
             $this->invoice->path = $path;
         }
         $this->invoice->update();
         $this->setMessage(lang('Invoice has been updated'), 'success');
         response()->refresh();
     }
 }