Compare commits

..

1 Commits

Author SHA1 Message Date
6bfa6ceeb9 Update 'controllers/ConfigController.php'
fix config striptags
2020-12-15 04:04:16 +00:00
12 changed files with 32 additions and 249 deletions

View File

@ -10,8 +10,6 @@ namespace app\commands;
use yii\console\Controller; use yii\console\Controller;
use yii\console\ExitCode; use yii\console\ExitCode;
use yii\log\Logger;
use Yii;
/** /**
* This command echoes the first argument that you have entered. * This command echoes the first argument that you have entered.
@ -32,39 +30,30 @@ class SyncController extends Controller {
if ($this->is_connected()) { if ($this->is_connected()) {
$sync = \app\models\SyncUrl::find()->one(); $sync = \app\models\SyncUrl::find()->one();
if ($sync) { if ($sync) {
$logs = \app\models\WaitingReq::find()->all(); $logs = \app\models\FaceLogs::find()->all();
foreach ($logs as $key => $value) { 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 = [ $options = [
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
'content' => $newValue '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
]),
] ]
]; ];
$res = json_decode(file_get_contents($sync->data, false, stream_context_create($options)), true); file_get_contents($sync->data, false, stream_context_create($options));
if ($res['status'] == 1000) { $value->delete();
$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,5 +2,4 @@
return [ return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
"version" => "1.0.7"
]; ];

View File

@ -35,17 +35,6 @@ 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() { public function actionSyncUrl() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$post = Yii::$app->request->bodyParams; $post = Yii::$app->request->bodyParams;
@ -62,77 +51,4 @@ 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

@ -210,9 +210,9 @@ class ConfigController extends Controller {
$value['data'] = trim(strip_tags($value['data'])); $value['data'] = trim(strip_tags($value['data']));
$value['data'] = str_replace('&nbsp;', '', $value['data']); $value['data'] = str_replace('&nbsp;', '', $value['data']);
$value['data'] = preg_replace('/\s+/', ' ', $value['data']); $value['data'] = preg_replace('/\s+/', ' ', $value['data']);
// if (is_numeric($value['data'])) { if (is_numeric($value['data'])) {
// $value['data'] = floatval($value['data']); $value['data'] = floatval($value['data']);
// } }
$pr = explode("|", $value['parent']); $pr = explode("|", $value['parent']);
if (count($pr) == 1) { if (count($pr) == 1) {

BIN
db/app.db

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

View File

@ -1,60 +0,0 @@
<?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;
}
}
}
}

View File

@ -1,60 +0,0 @@
<?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.files=false
copy.src.on.open=false copy.src.on.open=false
copy.src.target= copy.src.target=
remote.connection=BiFace-99bab6 remote.connection=bf_local-799e1d
remote.directory=/BiFace_Server_Lite remote.directory=/BiFace_Server_Lite
remote.upload=ON_SAVE remote.upload=ON_SAVE
run.as=REMOTE run.as=REMOTE

View File

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

View File

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

View File

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