From 7b717715158e7bf2762da228408f85ee02f255e4 Mon Sep 17 00:00:00 2001 From: SilverFire - Dima Naumenko Date: Tue, 22 Sep 2015 21:05:27 +0300 Subject: [PATCH] Implemented server blocking --- src/controllers/ServerController.php | 39 ++++++++++++------ src/models/Server.php | 14 ++++++- src/views/server/_block.php | 59 ++++++++++++++++++++++++++++ src/views/server/_boot-live.php | 2 +- src/views/server/_reinstall.php | 2 +- src/views/server/index.php | 37 ----------------- src/views/server/view.php | 9 +++++ 7 files changed, 110 insertions(+), 52 deletions(-) create mode 100644 src/views/server/_block.php diff --git a/src/controllers/ServerController.php b/src/controllers/ServerController.php index b0b0f1f6..93271af9 100644 --- a/src/controllers/ServerController.php +++ b/src/controllers/ServerController.php @@ -57,7 +57,9 @@ public function actions() $osimageslivecd = $controller->getOsimagesLiveCd(); } - return compact('model', 'osimages', 'osimageslivecd', 'grouped_osimages', 'panels'); + $blockReasons = $controller->getBlockReasons(); + + return compact(['model', 'osimages', 'osimageslivecd', 'grouped_osimages', 'panels', 'blockReasons']); }, ], 'requests-state' => [ @@ -108,42 +110,52 @@ public function actions() 'reboot' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Reboot task has been successfully added to queue', - 'error' => 'Error while rebooting', + 'error' => 'Error during the rebooting', ], 'reset' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Reset task has been successfully added to queue', - 'error' => 'Error while resetting', + 'error' => 'Error during the resetting', ], 'shutdown' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Shutdown task has been successfully added to queue', - 'error' => 'Error while shutting down', + 'error' => 'Error during the shutting down', ], 'power-off' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Power off task has been successfully added to queue', - 'error' => 'Error while turning power off', + 'error' => 'Error during the turning power off', ], 'power-on' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Power on task has been successfully added to queue', - 'error' => 'Error while turning power on', + 'error' => 'Error during the turning power on', ], 'reset-password' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Root password reset task has been successfully added to queue', - 'error' => 'Error while resetting root password', + 'error' => 'Error during the resetting root password', + ], + 'enable-block' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => 'Server was blocked successfully', + 'error' => 'Error during the server blocking', + ], + 'disable-block' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => 'Server was unblocked successfully', + 'error' => 'Error during the server unblocking', ], 'refuse' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'You have refused the service', - 'error' => 'Error while refusing the service', + 'error' => 'Error during the refusing the service', ], 'enable-autorenewal' => [ 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => 'Server renewal enabled successfully', - 'error' => 'Error while renewing the service', + 'error' => 'Error during the renewing the service', ], 'reinstall' => [ 'class' => 'hipanel\actions\SmartUpdateAction', @@ -154,7 +166,7 @@ public function actions() } }, 'success' => 'Server reinstalling task has been successfully added to queue', - 'error' => 'Error while server reinstalling', + 'error' => 'Error during the server reinstalling', ], 'boot-live' => [ 'class' => 'hipanel\actions\SmartUpdateAction', @@ -163,8 +175,11 @@ public function actions() $model->osmage = Yii::$app->request->post('osimage'); } }, - 'errorMessage' => 'Error while booting live CD', - 'successMessage' => 'Live CD booting task has been successfully added to queue', + 'success' => 'Live CD booting task has been successfully added to queue', + 'error' => 'Error during the booting live CD', + ], + 'validate-form' => [ + 'class' => 'hipanel\actions\ValidateFormAction', ], 'buy' => [ 'class' => 'hipanel\actions\RedirectAction', diff --git a/src/models/Server.php b/src/models/Server.php index eaaf21ab..8c55122d 100644 --- a/src/models/Server.php +++ b/src/models/Server.php @@ -16,6 +16,11 @@ class Server extends \hipanel\base\Model { use \hipanel\base\ModelTrait; + const STATE_OK = 'ok'; + const STATE_DISABLED = 'disabled'; + const STATE_BLOCKED = 'blocked'; + const STATE_DELETED = 'deleted'; + /** * @return array the list of attributes for this record */ @@ -83,6 +88,8 @@ public function rules() [['id'], 'required', 'on' => ['refuse']], [['id', 'osimage', 'panel'], 'required', 'on' => ['reinstall']], [['id', 'osimage'], 'required', 'on' => ['boot-live']], + [['type', 'comment'], 'required', 'on' => ['enable-block']], + [['comment'], 'safe', 'on' => ['disable-block']], ]; } @@ -93,7 +100,7 @@ public function rules() */ public function goodStates() { - return ['ok', 'disabled']; + return [static::STATE_OK, static::STATE_DISABLED]; } /** @@ -137,6 +144,10 @@ public function isLiveCDSupported() return $this->type != 'ovds'; } + public function getIsBlocked() { + return $this->state === static::STATE_BLOCKED; + } + /** * Checks whether server can be operated not * @@ -187,6 +198,7 @@ public function attributeLabels() 'ips' => Yii::t('app', 'IP addresses'), 'label' => Yii::t('app', 'Internal note'), 'os' => Yii::t('app', 'OS'), + 'comment' => Yii::t('app', 'Comment'), ]); } } diff --git a/src/views/server/_block.php b/src/views/server/_block.php new file mode 100644 index 00000000..195f1e8a --- /dev/null +++ b/src/views/server/_block.php @@ -0,0 +1,59 @@ + + +isBlocked) { + $modalButton = ModalButton::begin([ + 'model' => $model, + 'scenario' => 'enable-block', + 'button' => ['label' => '' . Yii::t('app', 'Block server')], + 'form' => [ + 'enableAjaxValidation' => true, + 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => 'enable-block']), + ], + 'modal' => [ + 'header' => Html::tag('h4', Yii::t('app', 'Confirm server blocking')), + 'headerOptions' => ['class' => 'label-danger'], + 'footer' => [ + 'label' => Yii::t('app', 'Block'), + 'data-loading-text' => Yii::t('app', 'Blocking...'), + 'class' => 'btn btn-danger', + ] + ] + ]); ?> +
+

+
+ + form->field($model, 'type')->dropDownList($blockReasons); ?> + form->field($model, 'comment'); ?> + + end(); +} else { + $modalButton = ModalButton::begin([ + 'model' => $model, + 'scenario' => 'disable-block', + 'button' => ['label' => '' . Yii::t('app', 'Unblock server')], + 'form' => [ + 'enableClientValidation' => true, + 'validateOnBlur' => true, + ], + 'modal' => [ + 'header' => Html::tag('h4', Yii::t('app', 'Confirm server unblocking')), + 'headerOptions' => ['class' => 'label-info'], + 'footer' => [ + 'label' => Yii::t('app', 'Unblock'), + 'data-loading-text' => Yii::t('app', 'Unblocking...'), + 'class' => 'btn btn-info', + ] + ] + ]); ?> + + form->field($model, 'comment'); ?> + + end(); +} + diff --git a/src/views/server/_boot-live.php b/src/views/server/_boot-live.php index 4133481c..08fcb15f 100644 --- a/src/views/server/_boot-live.php +++ b/src/views/server/_boot-live.php @@ -14,9 +14,9 @@ } + $model->scenario = 'bool-live'; ModalButton::begin([ 'model' => $model, - 'scenario' => 'boot-live', 'button' => [ 'label' => Yii::t('app', 'Boot LiveCD'), 'class' => 'btn btn-default', diff --git a/src/views/server/_reinstall.php b/src/views/server/_reinstall.php index 50f69ebd..9e78331a 100644 --- a/src/views/server/_reinstall.php +++ b/src/views/server/_reinstall.php @@ -6,9 +6,9 @@ use yii\helpers\Html; use yii\helpers\Json; +$model->scenario = 'reinstall'; ModalButton::begin([ 'model' => $model, - 'scenario' => 'reinstall', 'button' => ['label' => '' . Yii::t('app', 'Reinstall OS')], 'modal' => [ 'header' => Html::tag('h4', Yii::t('app', 'Please, select the operating system you want to install')), diff --git a/src/views/server/index.php b/src/views/server/index.php index 3cd37793..233f31c1 100644 --- a/src/views/server/index.php +++ b/src/views/server/index.php @@ -41,44 +41,7 @@ ], ]) ?> renderPerPage() ?> - endActions() ?> - -user->can('support')) { ?> - renderBulkActions([ - 'items' => [ - ButtonDropdown::widget([ - 'label' => Yii::t('app', 'Lock'), - 'dropdown' => [ - 'options' => ['class' => 'pull-right'], - 'items' => [ - [ - 'label' => Yii::t('app', 'Enable lock'), - 'url' => '#', - 'linkOptions' => [ - 'class' => 'bulk-action', - 'data-attribute' => 'is_secured', - 'data-value' => '1', - 'data-url' => 'set-lock' - ] - ], - [ - 'label' => Yii::t('app', 'Disable lock'), - 'url' => '#', - 'linkOptions' => [ - 'class' => 'bulk-action', - 'data-attribute' => 'is_secured', - 'data-value' => '0', - 'data-url' => 'set-lock' - ] - ] - ] - ] - ]), - ] - ]) ?> - - renderSearchForm(compact('states')) ?> end() ?> diff --git a/src/views/server/view.php b/src/views/server/view.php index 34fe3a3c..bb36704c 100644 --- a/src/views/server/view.php +++ b/src/views/server/view.php @@ -15,6 +15,9 @@ ['label' => Yii::t('app', 'Servers'), 'url' => ['index']], $this->title, ]); + +Pjax::begin(); + ?>
@@ -39,6 +42,11 @@
  • render('_reinstall', compact(['model', 'grouped_osimages', 'panels'])) ?>
  • + user->can('support')) { ?> +
  • + render('_block', compact(['model', 'blockReasons'])); ?> +
  • + user->can('support')) { ?>
  • render('_delete', compact(['model'])) ?> @@ -160,3 +168,4 @@ registerCss("th { white-space: nowrap; }"); +Pjax::end(); \ No newline at end of file