Skip to content

Commit

Permalink
Implemented server blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Sep 22, 2015
1 parent d1e80bf commit 7b71771
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 52 deletions.
39 changes: 27 additions & 12 deletions src/controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
14 changes: 13 additions & 1 deletion src/models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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']],
];
}

Expand All @@ -93,7 +100,7 @@ public function rules()
*/
public function goodStates()
{
return ['ok', 'disabled'];
return [static::STATE_OK, static::STATE_DISABLED];
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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'),
]);
}
}
59 changes: 59 additions & 0 deletions src/views/server/_block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
use hipanel\helpers\Url;
use yii\helpers\Html;
use hipanel\widgets\ModalButton;

?>

<?php if (!$model->isBlocked) {
$modalButton = ModalButton::begin([
'model' => $model,
'scenario' => 'enable-block',
'button' => ['label' => '<i class="ion-locked"></i>' . 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',
]
]
]); ?>
<div class="callout callout-warning">
<h4><?= Yii::t('app', 'This will immediately reject new SSH, FTP and WEB connections to the server!') ?></h4>
</div>

<?php echo $modalButton->form->field($model, 'type')->dropDownList($blockReasons); ?>
<?php echo $modalButton->form->field($model, 'comment'); ?>

<?php $modalButton->end();
} else {
$modalButton = ModalButton::begin([
'model' => $model,
'scenario' => 'disable-block',
'button' => ['label' => '<i class="ion-unlocked"></i>' . 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',
]
]
]); ?>

<?php echo $modalButton->form->field($model, 'comment'); ?>

<?php $modalButton->end();
}

2 changes: 1 addition & 1 deletion src/views/server/_boot-live.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/views/server/_reinstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use yii\helpers\Html;
use yii\helpers\Json;

$model->scenario = 'reinstall';
ModalButton::begin([
'model' => $model,
'scenario' => 'reinstall',
'button' => ['label' => '<i class="ion-ios-cog-outline"></i>' . Yii::t('app', 'Reinstall OS')],
'modal' => [
'header' => Html::tag('h4', Yii::t('app', 'Please, select the operating system you want to install')),
Expand Down
37 changes: 0 additions & 37 deletions src/views/server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,7 @@
],
]) ?>
<?= $box->renderPerPage() ?>

<?php $box->endActions() ?>

<?php if (Yii::$app->user->can('support')) { ?>
<?= $box->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'
]
]
]
]
]),
]
]) ?>
<?php } ?>

<?= $box->renderSearchForm(compact('states')) ?>
<?php $box->end() ?>

Expand Down
9 changes: 9 additions & 0 deletions src/views/server/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
['label' => Yii::t('app', 'Servers'), 'url' => ['index']],
$this->title,
]);

Pjax::begin();

?>

<div class="row">
Expand All @@ -39,6 +42,11 @@
<li>
<?= $this->render('_reinstall', compact(['model', 'grouped_osimages', 'panels'])) ?>
</li>
<?php if (Yii::$app->user->can('support')) { ?>
<li>
<?= $this->render('_block', compact(['model', 'blockReasons'])); ?>
</li>
<?php } ?>
<?php if (Yii::$app->user->can('support')) { ?>
<li>
<?= $this->render('_delete', compact(['model'])) ?>
Expand Down Expand Up @@ -160,3 +168,4 @@

<?php
$this->registerCss("th { white-space: nowrap; }");
Pjax::end();

0 comments on commit 7b71771

Please sign in to comment.