update is_connected with dynamic server
This commit is contained in:
parent
5450124be9
commit
476f01098f
|
@ -85,7 +85,10 @@ class ApiController extends Controller {
|
||||||
$ip = "https://dev-dc.beetai.com";
|
$ip = "https://dev-dc.beetai.com";
|
||||||
if ($server_ip)
|
if ($server_ip)
|
||||||
$ip = $server_ip->data;
|
$ip = $server_ip->data;
|
||||||
if ($this->is_connected() && $logs) {
|
$parseUrl = parse_url($ip);
|
||||||
|
$host = $parseUrl['host'];
|
||||||
|
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
||||||
|
if ($this->is_connected($host, $port) && $logs) {
|
||||||
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||||
$id_camera = 0;
|
$id_camera = 0;
|
||||||
if ($device_id)
|
if ($device_id)
|
||||||
|
@ -337,17 +340,19 @@ class ApiController extends Controller {
|
||||||
|
|
||||||
public function actionSync() {
|
public function actionSync() {
|
||||||
Yii::$app->response->format = "json";
|
Yii::$app->response->format = "json";
|
||||||
if ($this->is_connected()) {
|
|
||||||
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||||
$ip = "https://dev-dc.beetai.com";
|
$ip = "https://dev-dc.beetai.com";
|
||||||
if ($server_ip)
|
if ($server_ip)
|
||||||
$ip = $server_ip->data;
|
$ip = $server_ip->data;
|
||||||
|
$parseUrl = parse_url($ip);
|
||||||
|
$host = $parseUrl['host'];
|
||||||
|
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
||||||
|
if ($this->is_connected($host, $port)) {
|
||||||
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||||
$id_camera = 0;
|
$id_camera = 0;
|
||||||
if ($device_id)
|
if ($device_id)
|
||||||
$id_camera = intval($device_id->data);
|
$id_camera = intval($device_id->data);
|
||||||
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
|
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
|
||||||
|
|
||||||
$tk = "";
|
$tk = "";
|
||||||
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
|
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
|
||||||
if ($token)
|
if ($token)
|
||||||
|
@ -384,9 +389,9 @@ class ApiController extends Controller {
|
||||||
return ["status" => true];
|
return ["status" => true];
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_connected($ip = "google.com") {
|
function is_connected($host, $port) {
|
||||||
$connected = @fsockopen($ip, 80);
|
$connected = @fsockopen($host, $port);
|
||||||
//website, port (try 80 or 443)
|
//website, port (try 80 or 443)
|
||||||
if ($connected) {
|
if ($connected) {
|
||||||
$is_conn = true; //action when connected
|
$is_conn = true; //action when connected
|
||||||
fclose($connected);
|
fclose($connected);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user