Compare commits

...

14 Commits

Author SHA1 Message Date
3e7bd8d0dd update is_connected with dynamic server 2023-01-16 16:09:58 +07:00
b9388a9308 Update 'widgets/ConfigTree.php' 2022-04-04 04:44:35 +00:00
571b194ddc Update 'widgets/ConfigTree.php' 2022-04-04 04:35:44 +00:00
1fad90072a Update 'widgets/ConfigTree.php' 2022-04-04 04:10:15 +00:00
6c29581ded update version 2021-03-16 16:48:30 +07:00
5bed09b67f Update 'controllers/ConfigController.php' 2021-02-05 03:09:41 +00:00
631948f314 update api auto sync data 2021-01-21 09:52:42 +07:00
151b86ee6b Update 'controllers/ConfigController.php' 2020-12-15 04:04:50 +00:00
4fbf2e21aa clear db 2020-12-02 09:37:50 +07:00
976e89c129 image folder 2020-09-25 12:40:47 +07:00
1196ad712b update sync data to serrver 2020-09-25 12:34:10 +07:00
db801e7d96 update save response req 2020-09-24 10:30:52 +07:00
aade992cf9 update waiting req 2020-09-23 09:52:39 +07:00
c175187f4f init cloud 2020-09-22 15:56:13 +07:00
12 changed files with 252 additions and 32 deletions

View File

@ -10,6 +10,8 @@ namespace app\commands;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\log\Logger;
use Yii;
/**
* This command echoes the first argument that you have entered.
@ -30,30 +32,39 @@ class SyncController extends Controller {
if ($this->is_connected()) {
$sync = \app\models\SyncUrl::find()->one();
if ($sync) {
$logs = \app\models\FaceLogs::find()->all();
$logs = \app\models\WaitingReq::find()->all();
foreach ($logs as $key => $value) {
// $start = round(microtime(true) * 1000);
$contentJSON = json_decode($value->content);
$imgPath = $contentJSON->image;
$imgBase64 = base64_encode(file_get_contents($imgPath));
$contentJSON->image = $imgBase64;
$newValue = json_encode($contentJSON);
$options = [
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"camera_id" => $value->camera_id,
"confidence" => $value->confidence,
"enable_door" => $value->enable_door,
"encoded_person_image" => $value->encoded_person_image,
"frametime" => $value->frametime,
"id" => $value->face_id,
"image" => $value->image,
"name" => $value->name,
"person_id" => $value->person_id,
"status" => $value->status,
"stt" => $value->stt,
"timezone" => $value->timezone
]),
'content' => $newValue
]
];
file_get_contents($sync->data, false, stream_context_create($options));
$value->delete();
$res = json_decode(file_get_contents($sync->data, false, stream_context_create($options)), true);
if ($res['status'] == 1000) {
$modelRes = new \app\models\ResponseReq();
$modelRes->create(json_encode($res));
$value->delete();
// Delete image
unlink($imgPath);
}
// $end = round(microtime(true) * 1000);
// $timeDuration = $end - $start;
// Yii::info("Time:" . $timeDuration . " - " . $res, "cloud-response");
// var_dump($res);
// var_dump($timeDuration);
}
}
}

View File

@ -2,4 +2,5 @@
return [
'adminEmail' => 'admin@example.com',
"version" => "1.0.7"
];

View File

@ -35,6 +35,17 @@ class ApiController extends Controller {
}
}
public function actionWaitingRecognize() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->bodyParams;
$model = new \app\models\WaitingReq();
$model->create($post);
\app\models\SyncUrl::find()->one();
Yii::$app->response->format = "json";
return ["stt" => true];
}
}
public function actionSyncUrl() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->bodyParams;
@ -51,4 +62,77 @@ class ApiController extends Controller {
}
}
public function actionTest() {
$sync = \app\models\SyncUrl::find()->one();
var_dump(parse_url($sync->data));
exit();
Yii::info("Hello");
// echo base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/imgs/test.jpg"));
// \app\models\WaitingReq::deleteAll();
// $test1 = \app\models\WaitingReq::find()->all();
$test = \app\models\ResponseReq::find()->orderBy(['time' => SORT_DESC])->all();
// echo "<pre>";
// var_dump($test1, count($test));
// echo "</pre>";
foreach ($test as $key => $value) {
var_dump($value->content);
echo "<br>";
}
return;
}
public function actionSync() {
Yii::$app->response->format = "json";
$sync = \app\models\SyncUrl::find()->one();
if ($sync) {
$parseUrl = parse_url($sync->data);
$host = $parseUrl['host'];
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
if ($this->is_connected($host, $port)) {
$logs = \app\models\WaitingReq::find()->all();
foreach ($logs as $key => $value) {
$contentJSON = json_decode($value->content);
$imgPath = $contentJSON->image;
$imgBase64 = file_exists($imgPath) ? base64_encode(file_get_contents($imgPath)) : "";
if ($imgBase64 == "") {
$value->delete();
continue;
}
$contentJSON->image = $imgBase64;
$newValue = json_encode($contentJSON);
$options = [
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => $newValue
]
];
$res = json_decode(file_get_contents($sync->data, false, stream_context_create($options)), true);
if (in_array($res['status'], [1000, 10000])) {
$modelRes = new \app\models\ResponseReq();
$modelRes->create(json_encode($res));
$value->delete();
unlink($imgPath);
}
}
}
}
return ["status" => true];
}
function is_connected($host, $port) {
$connected = @fsockopen($host, $port);
//website, port (try 80 or 443)
if ($connected) {
$is_conn = true; //action when connected
fclose($connected);
} else {
$is_conn = false; //action in connection failure
}
return $is_conn;
}
}

View File

@ -207,9 +207,12 @@ class ConfigController extends Controller {
$cfgData = $post['config'];
$config_json = [];
foreach ($cfgData as $key => $value) {
if (is_numeric($value['data'])) {
$value['data'] = floatval($value['data']);
}
$value['data'] = trim(strip_tags($value['data']));
$value['data'] = str_replace('&nbsp;', '', $value['data']);
$value['data'] = preg_replace('/\s+/', ' ', $value['data']);
// if (is_numeric($value['data'])) {
// $value['data'] = floatval($value['data']);
// }
$pr = explode("|", $value['parent']);
if (count($pr) == 1) {

BIN
db/app.db

Binary file not shown.

BIN
imgs/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

60
models/ResponseReq.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "response_req".
*
* @property int $id
* @property string $content
* @property int $time
*/
class ResponseReq extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'response_req';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['content', 'time'], 'required'],
[['content'], 'string'],
[['time'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'content' => 'Content',
'time' => 'Time',
];
}
public function create($data) {
$r = $this->load([
'content' => json_encode($data),
'time' => time()
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
}

60
models/WaitingReq.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "waiting_req".
*
* @property int $id
* @property string $content
* @property int $time
*/
class WaitingReq extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'waiting_req';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['content', 'time'], 'required'],
[['content'], 'string'],
[['time'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'content' => 'Content',
'time' => 'Time',
];
}
public function create($data) {
$r = $this->load([
'content' => json_encode($data),
'time' => time()
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
}

View File

@ -1,7 +1,7 @@
copy.src.files=false
copy.src.on.open=false
copy.src.target=
remote.connection=bf_local-799e1d
remote.connection=BiFace-99bab6
remote.directory=/BiFace_Server_Lite
remote.upload=ON_SAVE
run.as=REMOTE

View File

@ -1,28 +1,29 @@
<?php
use yii\widgets\Breadcrumbs;
use dmstr\widgets\Alert;
?>
<div class="content-wrapper">
<!-- <section class="content-header">
<?=
Breadcrumbs::widget(
<?=
Breadcrumbs::widget(
[
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]
) ?>
)
?>
</section>-->
<section class="content" style="padding: 0 0 15px 0;">
<input type="hidden" value="<?php echo Yii::$app->user->id; ?>" name="current_user_id">
<?= Alert::widget() ?>
<?= $content ?>
<?= $content ?>
</section>
</div>
<footer class="main-footer">
<div class="pull-right hidden-xs" style="margin-top: 10px;">
<!--<b>Hotline</b> <a href="tel:0912461556">091.246.1556</a>-->
<div class="pull-right hidden-xs">
<b>Version</b> <?php echo Yii::$app->params["version"]; ?>
</div>
<!--<strong>Copyright &copy; 2020 <a href="https://beetinnovators.com/"><img src="/images/BI_Logo.png" width="80px"></a> & <a href="https://tctech.vn/"><img src="/images/TCTech.jpg" width="80px"></a>.</strong> All rights reserved.-->
<strong>Copyright &copy; 2020 <a href="https://beetinnovators.com/">BEETINNOVATORS</a>.</strong> All rights reserved.

View File

@ -1,8 +1,8 @@
<?php
// comment out the following two lines when deployed to production
//defined('YII_DEBUG') or define('YII_DEBUG', true);
//defined('YII_ENV') or define('YII_ENV', 'dev');
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';

View File

@ -17,8 +17,8 @@ class ConfigTree extends Widget {
public function run() {
$public_root = ['engine', 'recognition', 'open_door', 'screen', 'lang'];
$public_cfg = ['engine|cam_id', 'engine|server_authen', 'recognition|server_recog', 'open_door|enable', 'open_door|port_name', 'screen|banner', 'lang'];
$public_root = ['engine', 'recognition', 'open_door', 'screen', 'lang', 'camera'];
$public_cfg = ['engine|cam_id', 'engine|server_authen', 'recognition|server_recog', 'open_door|enable', 'open_door|port_name', 'screen|banner', 'lang', 'camera|rgb', 'camera|ir', 'camera|rgb|url', 'camera|ir|url'];
return $this->render("config-tree", [
"configLists" => $this->configLists,