mirror of
https://github.com/CyanoFresh/SmartHomePHP.git
synced 2026-02-20 03:11:26 +01:00
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles adding remote_connection to table `board`.
|
||||
*/
|
||||
class m161210_213225_add_remote_connection_column_to_board_table extends Migration
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn('board', 'remote_connection', $this->boolean()->defaultValue(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->dropColumn('board', 'remote_connection');
|
||||
}
|
||||
}
|
||||
@@ -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', 'Удаленное подключение'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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) {
|
||||
|
||||
<?= $form->field($model, 'baseUrl')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'remote_connection')->checkbox() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<p>
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<?php Pjax::begin(); ?>
|
||||
<?= GridView::widget([
|
||||
@@ -38,6 +37,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
return $model->getTypeLabel();
|
||||
}
|
||||
],
|
||||
[
|
||||
'filter' => [
|
||||
0 => 'Нет',
|
||||
1 => 'Да',
|
||||
],
|
||||
'format' => 'boolean',
|
||||
'attribute' => 'remote_connection',
|
||||
],
|
||||
|
||||
['class' => 'app\components\ActionButtonColumn'],
|
||||
],
|
||||
|
||||
@@ -31,6 +31,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'typeLabel',
|
||||
'secret',
|
||||
'baseUrl',
|
||||
'remote_connection:boolean',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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']],
|
||||
|
||||
Reference in New Issue
Block a user