diff --git a/migrations/m161210_213225_add_remote_connection_column_to_board_table.php b/migrations/m161210_213225_add_remote_connection_column_to_board_table.php new file mode 100644 index 0000000..d250bbb --- /dev/null +++ b/migrations/m161210_213225_add_remote_connection_column_to_board_table.php @@ -0,0 +1,25 @@ +addColumn('board', 'remote_connection', $this->boolean()->defaultValue(false)); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('board', 'remote_connection'); + } +} diff --git a/models/Board.php b/models/Board.php index bf034d8..b2def0d 100644 --- a/models/Board.php +++ b/models/Board.php @@ -14,6 +14,7 @@ use yii\helpers\ArrayHelper; * @property string $name * @property string $secret * @property string $baseUrl + * @property boolean $remote_connection * * @property Item[] $items */ @@ -41,6 +42,8 @@ class Board extends ActiveRecord [['baseUrl'], 'string'], [['name', 'secret'], 'string', 'max' => 255], [['secret'], 'default', 'value' => md5(time())], + [['remote_connection'], 'boolean'], + [['remote_connection'], 'default', 'value' => false], ]; } @@ -55,6 +58,7 @@ class Board extends ActiveRecord 'name' => Yii::t('app', 'Название'), 'secret' => Yii::t('app', 'Ключ'), 'baseUrl' => Yii::t('app', 'API URL'), + 'remote_connection' => Yii::t('app', 'Удаленное подключение'), ]; } diff --git a/modules/admin/models/BoardSearch.php b/modules/admin/models/BoardSearch.php index 2864f0e..73999c8 100644 --- a/modules/admin/models/BoardSearch.php +++ b/modules/admin/models/BoardSearch.php @@ -18,7 +18,7 @@ class BoardSearch extends Board public function rules() { return [ - [['id', 'type'], 'integer'], + [['id', 'type', 'remote_connection'], 'integer'], [['name', 'baseUrl', 'secret'], 'safe'], ]; } @@ -61,6 +61,7 @@ class BoardSearch extends Board $query->andFilterWhere([ 'id' => $this->id, 'type' => $this->type, + 'remote_connection' => $this->remote_connection, ]); $query->andFilterWhere(['like', 'name', $this->name]) diff --git a/modules/admin/views/board/_form.php b/modules/admin/views/board/_form.php index 91184d6..88ac1ef 100644 --- a/modules/admin/views/board/_form.php +++ b/modules/admin/views/board/_form.php @@ -10,6 +10,7 @@ use yii\widgets\ActiveForm; if ($model->isNewRecord) { $model->secret = md5(time()); + $model->remote_connection = false; } ?> @@ -28,6 +29,8 @@ if ($model->isNewRecord) { field($model, 'baseUrl')->textInput(['maxlength' => true]) ?> + field($model, 'remote_connection')->checkbox() ?> +
isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/modules/admin/views/board/index.php b/modules/admin/views/board/index.php index 6c0e4b4..720ed10 100644 --- a/modules/admin/views/board/index.php +++ b/modules/admin/views/board/index.php @@ -17,7 +17,6 @@ $this->params['breadcrumbs'][] = $this->title;

'btn btn-success']) ?>

- render('_search', ['model' => $searchModel]); ?> params['breadcrumbs'][] = $this->title; return $model->getTypeLabel(); } ], + [ + 'filter' => [ + 0 => 'Нет', + 1 => 'Да', + ], + 'format' => 'boolean', + 'attribute' => 'remote_connection', + ], ['class' => 'app\components\ActionButtonColumn'], ], diff --git a/modules/admin/views/board/view.php b/modules/admin/views/board/view.php index 5db6c5a..d32a463 100644 --- a/modules/admin/views/board/view.php +++ b/modules/admin/views/board/view.php @@ -31,6 +31,7 @@ $this->params['breadcrumbs'][] = $this->title; 'typeLabel', 'secret', 'baseUrl', + 'remote_connection:boolean', ], ]) ?> diff --git a/servers/Panel.php b/servers/Panel.php index b58bbad..169aac3 100644 --- a/servers/Panel.php +++ b/servers/Panel.php @@ -158,7 +158,7 @@ class Panel implements MessageComponentInterface // API request $api = false; - if ($conn->remoteAddress && $conn->remoteAddress == '127.0.0.1') { + if ($conn->remoteAddress == '127.0.0.1') { $api = true; } @@ -190,7 +190,7 @@ class Panel implements MessageComponentInterface $boardSecret = $query->get('secret'); if (!$boardID or !$boardSecret) { - $this->log('Wrong login data!'); + $this->log('Wrong login data'); return $conn->close(); } @@ -205,6 +205,11 @@ class Panel implements MessageComponentInterface return $conn->close(); } + if ($conn->remoteAddress != '127.0.0.1' && !$board->remote_connection) { + $this->log("Remote connection blocked for board [$board->id]"); + return $conn->close(); + } + // Attach to boards $conn->Board = $board; $this->board_clients[$board->id] = $conn; diff --git a/views/layouts/_left.php b/views/layouts/_left.php index 5f06c9b..35335da 100644 --- a/views/layouts/_left.php +++ b/views/layouts/_left.php @@ -22,11 +22,11 @@ ['label' => 'Панель Управления', 'icon' => 'fa fa-sliders', 'url' => ['/panel/index']], ['label' => 'Информация', 'options' => ['class' => 'header']], - ['label' => 'История', 'icon' => 'fa fa-bar-chart', 'url' => ['/history/index']], + ['label' => 'История', 'icon' => 'fa fa-th-list', 'url' => ['/history/index']], ['label' => 'Настройки', 'options' => ['class' => 'header']], - ['label' => 'Элементы', 'icon' => 'fa fa-cubes', 'url' => ['/admin/item/index']], - ['label' => 'Платы', 'icon' => 'fa fa-cogs', 'url' => ['/admin/board/index']], + ['label' => 'Элементы', 'icon' => 'fa fa-toggle-on', 'url' => ['/admin/item/index']], + ['label' => 'Платы', 'icon' => 'fa fa-hdd-o', 'url' => ['/admin/board/index']], ['label' => 'Triggers', 'icon' => 'fa fa-feed', 'url' => ['/admin/trigger/index']], ['label' => 'Задачи', 'icon' => 'fa fa-check', 'url' => ['/admin/task/index']], ['label' => 'Комнаты', 'icon' => 'fa fa-folder-open', 'url' => ['/admin/room/index']],