From 7305bd35cf528fa4dbef49732ee6eac78bb4a2bb Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 3 Jun 2021 09:50:11 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 43 ++++++++++++++----------------------- composer.json | 3 ++- scripts/lib/ecomode.php | 8 ++++++- scripts/lib/homeconnect.php | 4 +++- scripts/lib/http.php | 4 +++- scripts/lib/pc.php | 8 +++---- scripts/lib/ssh.php | 2 ++ scripts/sleeppc.php | 2 +- 8 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 364a417..f777a34 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,14 @@ - - - - + + + + + - - - + diff --git a/composer.json b/composer.json index 78a5134..8a4750e 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "zendframework/zend-i18n-resources": "^2.6", "ext-json": "*", "ext-mysqli": "*", - "graze/telnet-client": "^2.3" + "graze/telnet-client": "^2.3", + "ext-ssh2": "*" } } diff --git a/scripts/lib/ecomode.php b/scripts/lib/ecomode.php index 7c13c22..a6fa483 100644 --- a/scripts/lib/ecomode.php +++ b/scripts/lib/ecomode.php @@ -32,13 +32,19 @@ function nightmode($mode) function getNightMode() { + if(config('DEVICE')==='sdb'){ + $h=date('G'); + if($h>6 && $h<21){ + return false; + } + } return getState('night') == '1'; } function getEcoMode() { $res = getState('ecomode','0'); - if ($res == '0' && getState('night') == '1') { + if ($res == '0' && getNightMode()) { $res = '1'; } return (string)$res; diff --git a/scripts/lib/homeconnect.php b/scripts/lib/homeconnect.php index 543a650..f4b50f1 100644 --- a/scripts/lib/homeconnect.php +++ b/scripts/lib/homeconnect.php @@ -12,9 +12,11 @@ function _hc_cmd($cmd, $data = [], $method = 'get', $auth = true) try { $res = httpRequest($uri, $method, $data, null, 10, true, $headers); } catch (Exception $e) { - if (stristr($e->getMessage(), 'The access token expired')) { + if (stristr($e->getMessage(), 'token')) { hc_connect(true); return _hc_cmd($cmd, $data, $method, $auth); + }else{ + echo $e->getMessage(); } } $c = $res->getBody()->getContents(); diff --git a/scripts/lib/http.php b/scripts/lib/http.php index 6db1664..9548190 100644 --- a/scripts/lib/http.php +++ b/scripts/lib/http.php @@ -60,6 +60,8 @@ function httpRequest($url, $method = 'get', $data = [], $auth = null, $timeout = } } $options['headers'] = $headers; + $res= $client->request($method, $url, $options); - return $client->request($method, $url, $options); + print_r($res); + return $res; } \ No newline at end of file diff --git a/scripts/lib/pc.php b/scripts/lib/pc.php index e30f41f..ce2a07e 100644 --- a/scripts/lib/pc.php +++ b/scripts/lib/pc.php @@ -18,20 +18,20 @@ function wakeupPC($device) setState($s, '1'); } -function sleepPC($device) +function sleepPC($device,$force=false) { $s = 'device_' . $device . '_awake'; - if (getState($s) == '0') { + if (!$force && getState($s) == '0') { echo 'already sleeping ' . $device . ' :: ' . $s; return; } setState($s, '0'); - $res = sshCommand('"C:\Program Files\Scripts\sleep.bat"', $device, false); + $res = sshCommand('"C:\Program Files\Scripts\sleep.bat"', $device, true,true); setState($s, '0'); return $res; } function pcScreensProfile($profile, $device) { - sshCommand('"C:\Program Files (x86)\DisplayFusion\DisplayFusionCommand.exe" -monitorloadprofile "' . $profile . '"', $device, false,true); + sshCommand('"C:\Program Files (x86)\DisplayFusion\DisplayFusionCommand.exe" -monitorloadprofile "' . $profile . '"', $device, false, true); } \ No newline at end of file diff --git a/scripts/lib/ssh.php b/scripts/lib/ssh.php index acbfb0a..d0a7d6a 100644 --- a/scripts/lib/ssh.php +++ b/scripts/lib/ssh.php @@ -24,6 +24,7 @@ function getSSHInstance($device = null, $sudo = false, $force = false) } $user = $sudo ? 'root' : $d['user']; //if (getState('device_' . $device . '_awake') == '1') { + print_r($d); $ssh[$instance_key] = ssh2_connect($d['host'], 22); if ($ssh[$instance_key]) { if (!ssh2_auth_password($ssh[$instance_key], $user, $d['password'])) { @@ -54,6 +55,7 @@ function sshCommand($command, $device = null, $blocking = true, $sudo = false) function sshRunCommand($command, $device = null, $blocking = true, $sudo = false) { $ssh = getSSHInstance($device, $sudo); + print_r($ssh); if ($ssh) { $stream = @ssh2_exec($ssh, $command); if (!$stream) { diff --git a/scripts/sleeppc.php b/scripts/sleeppc.php index 5b68eca..eb93ed2 100644 --- a/scripts/sleeppc.php +++ b/scripts/sleeppc.php @@ -1,3 +1,3 @@