Пример #1
0
 public function init()
 {
     $expires = $this->model->expires;
     if (strtotime('+30 days', time()) < strtotime($expires)) {
         $this->color = 'none';
     } elseif (strtotime('+0 days', time()) < strtotime($expires)) {
         $this->color = 'warning';
     } else {
         $this->color = 'danger';
     }
     $this->addClass = 'text-nowrap';
     $this->label = \Yii::$app->formatter->asDate($expires);
     parent::init();
 }
 public static function defaultColumns()
 {
     return ['hdomain' => ['class' => MainColumn::class, 'filterAttribute' => 'domain_like', 'attribute' => 'domain'], 'hdomain_with_aliases' => ['format' => 'raw', 'attribute' => 'domain', 'filterAttribute' => 'domain_like', 'value' => function ($model) {
         $aliases = (array) $model->getAttribute('aliases');
         $html = Html::a($model->domain, ['view', 'id' => $model->id], ['class' => 'bold']) . '&nbsp;';
         $html .= ArraySpoiler::widget(['data' => $aliases, 'visibleCount' => 0, 'delimiter' => '<br />', 'button' => ['label' => Yii::t('hipanel', '+{0, plural, one{# alias} other{# aliases}}', count($aliases)), 'class' => 'badge progress-bar-info', 'popoverOptions' => ['html' => true]], 'formatter' => function ($value, $key) {
             return Html::a($value, ['view', 'id' => $key]);
         }]);
         return $html;
     }], 'account' => ['class' => AccountColumn::class], 'server' => ['class' => ServerColumn::class], 'ip' => ['enableSorting' => false, 'filter' => false, 'format' => 'raw', 'value' => function ($model) {
         $vhost = $model->getAttribute('vhost');
         $html = $vhost['ip'];
         if (isset($vhost['port']) && $vhost['port'] !== 80) {
             $html .= ':' . $vhost['port'];
         }
         if ($model->isProxied) {
             $backend = $vhost['backend'];
             $html .= ' ' . Html::tag('i', '', ['class' => 'fa fa-long-arrow-right']) . ' ' . $backend['ip'];
             if ($backend['port'] !== 80) {
                 $html .= ':' . $backend['port'];
             }
         }
         return $html;
     }], 'service' => ['label' => Yii::t('hipanel', 'Service'), 'value' => function ($model) {
         return $model->getAttribute('vhost')['service'];
     }], 'state' => ['class' => RefColumn::class, 'i18nDictionary' => 'hipanel:hosting', 'format' => 'raw', 'value' => function ($model) {
         $html = '';
         if ($model->dns_on && empty($model->dns_hdomain_id)) {
             $html .= Label::widget(['color' => 'success', 'label' => Yii::t('hipanel', 'DNS'), 'tag' => 'span', 'labelOptions' => ['title' => Yii::t('hipanel:hosting', 'DNS is enabled')]]);
         }
         $html .= ' ' . State::widget(compact('model'));
         return $html;
     }, 'gtype' => 'state,hdomain'], 'dns_on' => ['format' => 'raw', 'value' => function ($model) {
         return $model->dns_on ? Yii::t('hipanel', 'Enabled') : Yii::t('hipanel', 'Disabled');
     }], 'dns_switch' => ['attribute' => 'dns_on', 'label' => Yii::t('hipanel:hosting', 'DNS'), 'format' => 'raw', 'value' => function ($model) {
         if (empty($model->dns_hdomain_id)) {
             return XEditable::widget(['model' => $model, 'attribute' => 'dns_on', 'pluginOptions' => ['type' => 'select', 'title' => Yii::t('hipanel:hosting', 'Toggles DNS records upload on NS server'), 'source' => ['' => Yii::t('hipanel', 'Disabled'), '1' => Yii::t('hipanel', 'Enabled')], 'url' => Url::to('set-dns-on'), 'placement' => 'bottom'], 'linkOptions' => ['style' => ['word-break' => 'break-all']]]);
         } else {
             return Yii::t('hipanel:hosting', 'Belongs to {link}', ['link' => Html::a($model->dns_hdomain_domain, Url::to(['@hdomain/view', 'id' => $model->dns_hdomain_id]))]);
         }
     }], 'aliases' => ['label' => Yii::t('hipanel', 'Aliases'), 'format' => 'raw', 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => (array) $model->getAttribute('aliases'), 'delimiter' => '<br />', 'button' => ['popoverOptions' => ['html' => true]]]);
     }], 'backups_widget' => ['label' => Yii::t('hipanel:hosting', 'Backups'), 'format' => 'raw', 'value' => function ($model) {
         return BackupGridRow::widget(['model' => $model]);
     }], 'actions' => ['class' => ActionColumn::class, 'template' => '{view} {delete}']];
 }
Пример #3
0
 public static function defaultColumns()
 {
     return ['zone' => ['class' => MainColumn::className(), 'label' => Yii::t('hipanel:dns', 'Zone'), 'attribute' => 'name'], 'domain' => ['class' => MainColumn::className(), 'filterAttribute' => 'domain_like'], 'idn' => ['class' => MainColumn::className(), 'filterAttribute' => 'idn_like'], 'actions' => ['class' => MenuColumn::class, 'menuClass' => DnsActionsMenu::class], 'nss' => ['format' => 'raw', 'attribute' => 'nss_like', 'label' => Yii::t('hipanel:dns', 'NS servers'), 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => $model->nss]);
     }], 'dns_on' => ['format' => 'raw', 'filter' => function ($column, $model, $attribute) {
         return Html::activeDropDownList($model, $attribute, ['' => Yii::t('hipanel:dns', '---'), '1' => Yii::t('hipanel:dns', 'Enabled'), '0' => Yii::t('hipanel:dns', 'Disabled')], ['class' => 'form-control']);
     }, 'value' => function ($model) {
         return Label::widget(['color' => $model->dns_on ? 'success' : '', 'label' => $model->dns_on ? Yii::t('hipanel:dns', 'Enabled') : Yii::t('hipanel:dns', 'Disabled'), 'labelOptions' => ['title' => Yii::t('hipanel:dns', 'Means that the panel will publish DNS records on the NS servers')]]);
     }], 'bound_to' => ['format' => 'raw', 'label' => Yii::t('hipanel:dns', 'Bound to'), 'value' => function ($model) {
         if (Yii::getAlias('@domain') !== null && $model->is_reg_domain) {
             return Html::a(Yii::t('hipanel:dns', 'Registered domain'), ['@domain/view', 'id' => $model->id]);
         } elseif ($model->server_id) {
             return Html::a($model->account . '@' . $model->server, ['@hdomain/view', 'id' => $model->id]);
         } else {
             return Yii::$app->formatter->nullDisplay;
         }
     }]];
 }
 public static function defaultColumns()
 {
     return ['mail' => ['class' => MainColumn::class, 'filterAttribute' => 'mail_like'], 'state' => ['class' => RefColumn::class, 'i18nDictionary' => 'hipanel:hosting', 'format' => 'raw', 'value' => function ($model) {
         return State::widget(compact('model'));
     }, 'gtype' => 'state,mail'], 'server' => ['class' => ServerColumn::class], 'domain' => ['attribute' => 'hdomain_id', 'format' => 'raw', 'value' => function ($model) {
         return Html::a($model->domain, ['@hdomain/view', 'id' => $model->hdomain_id]);
     }], 'type' => ['format' => 'raw', 'filter' => function ($column, $model, $attribute) {
         return Html::activeDropDownList($model, $attribute, ['' => '----------'] + Mail::getTypes(), ['class' => 'form-control']);
     }, 'value' => function ($model) {
         return Type::widget(compact('model'));
     }], 'forwards' => ['format' => 'raw', 'value' => function ($model) {
         return ArraySpoiler::widget(['delimiter' => '<br>', 'visibleCount' => 2, 'data' => $model->forwards, 'button' => ['label' => '+{count}', 'popoverOptions' => ['html' => true]]]);
     }], 'spam_action' => ['format' => 'raw', 'value' => function ($model) {
         /** @var $model Mail */
         if ($model->spam_action === $model::SPAM_ACTION_DELETE) {
             return Label::widget(['color' => 'danger', 'label' => Yii::t('hipanel', 'Delete')]);
         } elseif ($model->spam_action === '') {
             return Label::widget(['color' => 'info', 'label' => Yii::t('hipanel:hosting', 'Do nothing')]);
         } else {
             return Label::widget(['color' => 'primary', 'label' => Yii::t('hipanel:hosting', 'Forward to')]) . ' ' . ArraySpoiler::widget(['data' => $model->spam_action, 'visibleCount' => 2]);
         }
     }], 'actions' => ['class' => ActionColumn::class, 'template' => '{view} {delete}']];
 }
 public static function defaultColumns()
 {
     $osImages = self::$osImages;
     return ['server' => ['class' => MainColumn::class, 'attribute' => 'name', 'filterAttribute' => 'name_like', 'note' => Yii::$app->user->can('support') ? 'label' : 'note', 'noteOptions' => ['url' => Yii::$app->user->can('support') ? Url::to('set-label') : Url::to('set-note')], 'badges' => function ($model) {
         $badges = '';
         if (Yii::$app->user->can('support')) {
             if ($model->wizzarded) {
                 $badges .= Label::widget(['label' => 'W', 'tag' => 'sup', 'color' => 'success']);
             }
             /*if ($model->state === 'disabled') {
                   $badges .= ' ' . Label::widget(['label' => 'Panel OFF', 'tag' => 'sup', 'color' => 'danger', 'type' => 'text']);
               }*/
         }
         return $badges;
     }], 'dc' => ['attribute' => 'dc', 'filter' => false], 'state' => ['class' => RefColumn::class, 'i18nDictionary' => 'hipanel:server', 'format' => 'raw', 'gtype' => 'state,device', 'value' => function ($model) {
         $html = State::widget(compact('model'));
         if ($model->status_time) {
             $html .= ' ' . Html::tag('nobr', Yii::t('hipanel:server', 'since {date}', ['date' => Yii::$app->formatter->asDate($model->status_time)]));
         }
         return $html;
     }], 'panel' => ['attribute' => 'panel', 'format' => 'text', 'contentOptions' => ['class' => 'text-uppercase'], 'value' => function ($model) {
         return $model->panel ? Yii::t('hipanel:server:panel', $model->panel) : Yii::t('hipanel:server:panel', 'No control panel');
     }], 'os' => ['attribute' => 'os', 'format' => 'raw', 'value' => function ($model) use($osImages) {
         return OSFormatter::widget(['osimages' => $osImages, 'imageName' => $model->osimage]);
     }], 'os_and_panel' => ['attribute' => 'os', 'format' => 'raw', 'value' => function ($model) use($osImages) {
         $html = OSFormatter::widget(['osimages' => $osImages, 'imageName' => $model->osimage]);
         $html .= ' ' . $model->panel ?: '';
         return $html;
     }], 'discount' => ['attribute' => 'discount', 'label' => Yii::t('hipanel:server', 'Discount'), 'format' => 'raw', 'headerOptions' => ['style' => 'width: 1em'], 'value' => function ($model) {
         return DiscountFormatter::widget(['current' => $model->discounts['fee']['current'], 'next' => $model->discounts['fee']['next']]);
     }], 'expires' => ['filter' => false, 'format' => 'raw', 'headerOptions' => ['style' => 'width: 1em'], 'value' => function ($model) {
         return Expires::widget(compact('model'));
     }], 'tariff' => ['format' => 'raw', 'filterAttribute' => 'tariff_like', 'value' => function ($model) {
         return self::formatTariff($model);
     }], 'tariff_and_discount' => ['attribute' => 'tariff', 'filterAttribute' => 'tariff_like', 'format' => 'raw', 'value' => function ($model) {
         return self::formatTariff($model) . ' ' . DiscountFormatter::widget(['current' => $model->discounts['fee']['current'], 'next' => $model->discounts['fee']['next']]);
     }], 'ip' => ['filter' => false], 'mac' => ['filter' => false], 'ips' => ['format' => 'raw', 'attribute' => 'ips', 'filter' => false, 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => ArrayHelper::getColumn($model->ips, 'ip'), 'delimiter' => '<br />', 'visibleCount' => 3, 'button' => ['popoverOptions' => ['html' => true]]]);
     }], 'sale_time' => ['attribute' => 'sale_time', 'format' => 'datetime'], 'note' => ['class' => XEditableColumn::class, 'pluginOptions' => ['url' => Url::to('set-note')], 'widgetOptions' => ['linkOptions' => ['data-type' => 'textarea']]], 'label' => ['class' => XEditableColumn::class, 'visible' => Yii::$app->user->can('support'), 'pluginOptions' => ['url' => Url::to('set-label')], 'widgetOptions' => ['linkOptions' => ['data-type' => 'textarea']]], 'type' => ['format' => 'html', 'filter' => false, 'value' => function ($model) {
         return $model->type_label;
     }], 'rack' => ['format' => 'html', 'filter' => false, 'value' => function ($model) {
         return $model->switches['rack']['switch'];
     }], 'net' => ['format' => 'html', 'filter' => false, 'value' => function ($model) {
         return static::renderSwitchPort($model->switches['net']);
     }], 'kvm' => ['format' => 'html', 'filter' => false, 'value' => function ($model) {
         return static::renderSwitchPort($model->switches['kvm']);
     }], 'pdu' => ['format' => 'html', 'filter' => false, 'value' => function ($model) {
         return static::renderSwitchPort($model->switches['pdu']);
     }], 'ipmi' => ['format' => 'raw', 'filter' => false, 'value' => function ($model) {
         $ipmi = $model->switches['ipmi']['device_ip'];
         $link = $ipmi ? Html::a($ipmi, "http://{$ipmi}/", ['target' => '_blank']) . ' ' : '';
         return $link . static::renderSwitchPort($model->switches['ipmi']);
     }], 'nums' => ['label' => '', 'format' => 'raw', 'value' => function ($model) {
         $ips_num = $model->ips_num;
         $ips = $ips_num ? Html::a("{$ips_num} ips", IpController::getSearchUrl(['server' => $model->name])) : 'no ips';
         $act_acs_num = $model->acs_num - $model->del_acs_num;
         $del_acs_num = $model->del_acs_num;
         $acs_num = $act_acs_num . ($del_acs_num ? "+{$del_acs_num}" : '');
         $acs = $acs_num ? Html::a("{$acs_num} acc", AccountController::getSearchUrl(['server' => $model->name])) : 'no acc';
         return Html::tag('nobr', $ips) . ' ' . Html::tag('nobr', $acs);
     }], 'actions' => ['class' => ActionColumn::class, 'template' => '{view} {rrd} {switch-graph}', 'buttons' => ['switch-graph' => function ($url, $model) {
         return Html::a('<i class="fa fa-fw fa-area-chart"></i>' . Yii::t('hipanel:server', 'Switch graphs'), ['@switch-graph/view', 'id' => $model->id]);
     }, 'rrd' => function ($url, $model) {
         return Html::a('<i class="fa fa-fw fa-signal"></i>' . Yii::t('hipanel:server', 'Resources usage graphs'), ['@rrd/view', 'id' => $model->id]);
     }]]];
 }