update change up from server lite

This commit is contained in:
dongpd 2022-10-20 10:34:27 +07:00
parent c8e0bb7795
commit 8954a2fc25
11 changed files with 250 additions and 84 deletions

View File

@ -174,7 +174,8 @@ class ConfigController extends Controller {
}
return $this->render('index', [
"servermqtt" => $servermqtt === "" ? $ip . ":1883" : $servermqtt,
"url" => isset($temp[2]) ? $temp[2] : $ip . ":5001"
"url" => isset($temp[2]) ? $temp[2] : $ip . ":5001",
"menu" => $this->renderPartial("menu", ["tab" => "server_config"])
]);
}
@ -290,7 +291,8 @@ class ConfigController extends Controller {
$config_json = json_decode($checkConfig['data'], true);
return $this->render('config', [
"config_json" => \app\widgets\ConfigTree::widget(['configLists' => $config_json, 'isRoot' => true, 'parent_id' => 'node', 'parent_key' => ''])
"config_json" => \app\widgets\ConfigTree::widget(['configLists' => $config_json, 'isRoot' => true, 'parent_id' => 'node', 'parent_key' => '']),
"menu" => $this->renderPartial("menu", ["tab" => "engine_config"])
]);
}
}
@ -452,7 +454,8 @@ class ConfigController extends Controller {
}
return $this->render('device', [
"server_api" => \app\models\SyncUrl::findOne(['key_config' => 'server_api']),
"device_id" => \app\models\SyncUrl::findOne(['key_config' => 'device_id'])
"device_id" => \app\models\SyncUrl::findOne(['key_config' => 'device_id']),
"menu" => $this->renderPartial("menu", ["tab" => "device_config"])
]);
}
@ -486,4 +489,72 @@ class ConfigController extends Controller {
}
}
public $subnet = [
"0.0.0.0" => "/0",
"128.0.0.0" => "/1",
"192.0.0.0" => "/2",
"224.0.0.0" => "/3",
"240.0.0.0" => "/4",
"248.0.0.0" => "/5",
"252.0.0.0" => "/6",
"254.0.0.0" => "/7",
"255.0.0.0" => "/8",
"255.128.0.0" => "/9",
"255.192.0.0" => "/10",
"255.224.0.0" => "/11",
"255.240.0.0" => "/12",
"255.248.0.0" => "/13",
"255.252.0.0" => "/14",
"255.254.0.0" => "/15",
"255.255.0.0" => "/16",
"255.255.128.0" => "/17",
"255.255.192.0" => "/18",
"255.255.224.0" => "/19",
"255.255.240.0" => "/20",
"255.255.248.0" => "/21",
"255.255.252.0" => "/22",
"255.255.254.0" => "/23",
"255.255.255.0" => "/24",
"255.255.255.128" => "/25",
"255.255.255.192" => "/26",
"255.255.255.224" => "/27",
"255.255.255.240" => "/28",
"255.255.255.248" => "/29",
"255.255.255.252" => "/30",
"255.255.255.254" => "/31",
"255.255.255.255" => "/32"
];
public function actionCauHinhIp() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$post = Yii::$app->request->post();
if (!isset($this->subnet[$post['subnet_mask']]))
return ["status" => false];
$post['subnet_mask'] = $this->subnet[$post['subnet_mask']];
$options = [
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode($post),
]
];
json_decode(@file_get_contents("http://localhost:4004/SetIP", false, stream_context_create($options)), true);
return ["status" => true, "url" => "http://" . $post['device_ip']];
} else {
$this->view->title = Yii::t("app", "CAU_HINH_IP");
$options = [
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST"
]
];
$network = json_decode(@file_get_contents("http://localhost:4004/Network", false, stream_context_create($options)), true);
return $this->render('ip', [
"menu" => $this->renderPartial("menu", ["tab" => "ip_config"]),
"network" => $network
]);
}
}
}

View File

@ -11,9 +11,11 @@ return [
"CAU_HINH_THIET_BI" => "Device Configuration",
"CAU_HINH_MAY_CHU" => "Server Configuration",
"CAU_HINH_NHAN_DIEN" => "Recognition Configuration",
"CAU_HINH_IP" => "IP Configuration",
"DEVICE_CONFIG" => "",
"SERVER_CONFIG" => "",
"ENGINE_CONFIG" => "",
"IP_CONFIG" => "",
"SERVER_MQTT" => "server_mqtt",
"URL" => "url",
"LUU_LAI" => "Save",
@ -157,5 +159,6 @@ return [
"AP_DUNG_CHO_TAT_CA_DOI_TUONG_DA_CHON" => "Apply to all selected objects",
"XOA_LICH_TRINH" => "Delete schedule",
"BAN_CO_CHAC_CHAN_MUON_XOA_LICH_TRINH_NAY_KHONG" => "Are you sure you want to delete this schedule?",
"SO_SANH_MAT" => "Face comparison"
"SO_SANH_MAT" => "Face comparison",
"BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "Are you sure you want to change the device's IP address?"
];

View File

@ -11,9 +11,11 @@ return [
"CAU_HINH_THIET_BI" => "デバイス構成",
"CAU_HINH_MAY_CHU" => " サーバ構成",
"CAU_HINH_NHAN_DIEN" => "認識構成",
"CAU_HINH_IP" => "IP 構成",
"DEVICE_CONFIG" => "Device config",
"SERVER_CONFIG" => "Server config",
"ENGINE_CONFIG" => "Engine config",
"IP_CONFIG" => "IP config",
"SERVER_MQTT" => "server_mqtt",
"URL" => "url",
"LUU_LAI" => "保存する",
@ -157,5 +159,6 @@ return [
"AP_DUNG_CHO_TAT_CA_DOI_TUONG_DA_CHON" => "選択したすべてのオブジェクトに適用",
"XOA_LICH_TRINH" => "スケジュールを削除",
"BAN_CO_CHAC_CHAN_MUON_XOA_LICH_TRINH_NAY_KHONG" => "このスケジュールを削除してもよろしいですか?",
"SO_SANH_MAT" => "顔比較"
"SO_SANH_MAT" => "顔比較",
"BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "デバイスの IP アドレスを変更してもよろしいですか?"
];

View File

@ -11,9 +11,11 @@ return [
"CAU_HINH_THIET_BI" => "Cấu hình thiết bị",
"CAU_HINH_MAY_CHU" => "Cấu hình máy chủ",
"CAU_HINH_NHAN_DIEN" => "Cấu hình nhận diện",
"CAU_HINH_IP" => "Cấu hình IP",
"DEVICE_CONFIG" => "Device config",
"SERVER_CONFIG" => "Server config",
"ENGINE_CONFIG" => "Engine config",
"IP_CONFIG" => "IP config",
"SERVER_MQTT" => "server_mqtt",
"URL" => "url",
"LUU_LAI" => "Lưu lại",
@ -157,5 +159,6 @@ return [
"AP_DUNG_CHO_TAT_CA_DOI_TUONG_DA_CHON" => "Áp dụng cho tất cả đối tượng đã chọn",
"XOA_LICH_TRINH" => "Xóa lịch trình",
"BAN_CO_CHAC_CHAN_MUON_XOA_LICH_TRINH_NAY_KHONG" => "Bạn có chắc chắn muốn xóa lịch trình này không?",
"SO_SANH_MAT" => "So sánh mặt"
"SO_SANH_MAT" => "So sánh mặt",
"BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "Bạn có chắc chắn muốn thay đổi địa chỉ IP của thiết bị không?"
];

View File

@ -142,32 +142,8 @@
<div class="container-fluid">
<br>
<div class="row">
<div class="col-md-8">
<div class="mt-element-step">
<div class="row step-thin">
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">1</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-thiet-bi'])}';">
{Yii::t("app", "CAU_HINH_THIET_BI")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "DEVICE_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">2</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config'])}';">
{Yii::t("app", "CAU_HINH_MAY_CHU")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "SERVER_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col active">
<div class="mt-step-number bg-white font-grey">3</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-nhan-dien'])}';">
{Yii::t("app", "CAU_HINH_NHAN_DIEN")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "ENGINE_CONFIG")}</div>
</div>
</div>
</div>
<div class="col-md-10">
{$menu}
</div>
</div>
<br>

View File

@ -16,32 +16,8 @@
<div class="container-fluid">
<br>
<div class="row">
<div class="col-md-8">
<div class="mt-element-step">
<div class="row step-thin">
<div class="col-md-4 bg-grey mt-step-col active">
<div class="mt-step-number bg-white font-grey">1</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-thiet-bi'])}';">
{Yii::t("app", "CAU_HINH_THIET_BI")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "DEVICE_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">2</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config'])}';">
{Yii::t("app", "CAU_HINH_MAY_CHU")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "SERVER_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">3</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-nhan-dien'])}';">
{Yii::t("app", "CAU_HINH_NHAN_DIEN")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "ENGINE_CONFIG")}</div>
</div>
</div>
</div>
<div class="col-md-10">
{$menu}
</div>
</div>
<br>

View File

@ -16,32 +16,8 @@
<div class="container-fluid">
<br>
<div class="row">
<div class="col-md-8">
<div class="mt-element-step">
<div class="row step-thin">
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">1</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-thiet-bi'])}';">
{Yii::t("app", "CAU_HINH_THIET_BI")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "DEVICE_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col active">
<div class="mt-step-number bg-white font-grey">2</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config'])}';">
{Yii::t("app", "CAU_HINH_MAY_CHU")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "SERVER_CONFIG")}</div>
</div>
<div class="col-md-4 bg-grey mt-step-col">
<div class="mt-step-number bg-white font-grey">3</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-nhan-dien'])}';">
{Yii::t("app", "CAU_HINH_NHAN_DIEN")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "ENGINE_CONFIG")}</div>
</div>
</div>
</div>
<div class="col-md-10">
{$menu}
</div>
</div>
<br>

65
views/config/ip.tpl Normal file
View File

@ -0,0 +1,65 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
{use class="app\assets\ConfigAsset"}
{ConfigAsset::register($this)|void}
{block name='content'}
<style>
.input-group-addon{
width: 120px;
font-weight: bold;
}
.input-group{
width: 100%;
}
</style>
<div class="container-fluid">
<br>
<div class="row">
<div class="col-md-10">
{$menu}
</div>
</div>
<br>
<div class="row">
<div class="col-md-3">
<div class="form-group" id="device_ip">
<div class="input-group">
<div class="input-group-addon">{Yii::t("app", "IP Address")}</div>
<input type="input" class="form-control" name="device_ip" value="{$network.ip_address|default:""}">
</div>
</div>
<div class="form-group" id="subnet_mask">
<div class="input-group">
<div class="input-group-addon">{Yii::t("app", "Subnet Mask")}</div>
<input type="input" class="form-control" name="subnet_mask" value="{$network.subnet_mask|default:""}">
</div>
</div>
<div class="form-group" id="gateway">
<div class="input-group">
<div class="input-group-addon">{Yii::t("app", "Gateway")}</div>
<input type="input" class="form-control" name="gateway" value="{$network.gateway|default:""}">
</div>
</div>
<div class="form-group" id="dns1">
<div class="input-group">
<div class="input-group-addon">{Yii::t("app", "DNS1")}</div>
<input type="input" class="form-control" name="dns1" value="{$network.dns[0]|default:""}">
</div>
</div>
<div class="form-group" id="dns2">
<div class="input-group">
<div class="input-group-addon">{Yii::t("app", "DNS2")}</div>
<input type="input" class="form-control" name="dns2" value="{$network.dns[1]|default:""}">
</div>
</div>
<div class="text-center">
<button class="btn btn-primary" onclick="changeIP(this);" data-href="{Url::to(['/config/cau-hinh-ip'])}">
<i class="fa fa-floppy-o"></i> {Yii::t("app", "LUU_LAI")}
</button>
</div>
</div>
</div>
</div>
</div>
{/block}

33
views/config/menu.tpl Normal file
View File

@ -0,0 +1,33 @@
{use class="yii\helpers\Url"}
<div class="mt-element-step">
<div class="row step-thin">
<div class="col-md-3 bg-grey mt-step-col {if $tab=="device_config"}active{/if}">
<div class="mt-step-number bg-white font-grey">1</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-thiet-bi'])}';">
{Yii::t("app", "CAU_HINH_THIET_BI")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "DEVICE_CONFIG")}</div>
</div>
<div class="col-md-3 bg-grey mt-step-col {if $tab=="server_config"}active{/if}">
<div class="mt-step-number bg-white font-grey">2</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config'])}';">
{Yii::t("app", "CAU_HINH_MAY_CHU")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "SERVER_CONFIG")}</div>
</div>
<div class="col-md-3 bg-grey mt-step-col {if $tab=="engine_config"}active{/if}">
<div class="mt-step-number bg-white font-grey">3</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-nhan-dien'])}';">
{Yii::t("app", "CAU_HINH_NHAN_DIEN")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "ENGINE_CONFIG")}</div>
</div>
<div class="col-md-3 bg-grey mt-step-col {if $tab=="ip_config"}active{/if}">
<div class="mt-step-number bg-white font-grey">4</div>
<div class="mt-step-title uppercase font-grey-cascade" style="cursor: pointer;" onclick="window.location = '{Url::to(['/config/cau-hinh-ip'])}';">
{Yii::t("app", "CAU_HINH_IP")}
</div>
<div class="mt-step-content font-grey-cascade">{Yii::t("app", "IP_CONFIG")}</div>
</div>
</div>
</div>

View File

@ -32,6 +32,7 @@
<input type="hidden" name="ENGINE_KHONG_HOAT_DONG" value="{Yii::t("app", "ENGINE_KHONG_HOAT_DONG")}">
<input type="hidden" name="HAY_CHON_DOI_TUONG_DE_GAN_LICH_TRINH" value="{Yii::t("app", "HAY_CHON_DOI_TUONG_DE_GAN_LICH_TRINH")}">
<input type="hidden" name="BAN_CO_CHAC_CHAN_MUON_XOA_LICH_TRINH_NAY_KHONG" value="{Yii::t("app", "BAN_CO_CHAC_CHAN_MUON_XOA_LICH_TRINH_NAY_KHONG")}">
<input type="hidden" name="BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" value="{Yii::t("app", "BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG")}">
<div id="blocking" class="fade modal" role="dialog" tabindex="-1">
<div class="modal-dialog" style="top: 50%;margin-top: -45px;">

View File

@ -116,3 +116,62 @@ function SaveConfigDevice(e) {
}
});
}
function ValidateIPaddress(ipaddress) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
return true;
return false;
}
function validData(inputName) {
var ip = $("input[name='" + inputName + "']").val();
if (!ValidateIPaddress(ip)) {
common.error(inputName, "");
return false;
} else {
common.success(inputName);
return true;
}
}
function validDNS(inputName) {
var dns = $("input[name='" + inputName + "']").val();
if (dns == "")
return true;
return validData(inputName);
}
function changeIP(e) {
var valid = validData("device_ip");
valid = validData("subnet_mask");
valid = validData("gateway");
valid = validDNS("dns1");
valid = validDNS("dns2");
if (!valid)
return;
if (confirm($("input[name='BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG']").val())) {
common.modalBlock(true);
$.ajax({
url: $(e).attr("data-href"),
type: 'POST',
data: {
device_ip: $("input[name='device_ip']").val(),
subnet_mask: $("input[name='subnet_mask']").val(),
gateway: $("input[name='gateway']").val(),
dns1: $("input[name='dns1']").val(),
dns2: $("input[name='dns2']").val(),
},
success: function (data) {
common.modalBlock(false);
if (!data.status)
common.error("subnet_mask", "");
else
window.location = data.url;
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
}