function send_get($ip, $port, $param = "") { $url = $ip . ":" . $port; // Проверка доступности хоста if (MyPing($url)) { // Если доступен, то отправляем param через HTTP log_cam(date('H:i:s') . " - Webcam {$ip} port {$port} is Ok "); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); return true; } else { return false; } /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); // echo "http://{$ip}:8080/{$param}"; // test $ansver = file_get_contents('ok'); // curl_close($ch); return $ansver; */ }
function ssh_exec($ip, $port, $param) { // HTTP version $url = $ip . ":" . $port; // Проверка доступности хоста if (MyPing($url)) { // Если доступен, то отправляем param через HTTP log_cam("Webcam {$ip} port {$port} is [ On-line ]", 'on-line'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); // var_dump($res); // print_r($res); return $res; } else { log_cam("Webcam {$ip} port {$port} is [ Off-line ]", 'off-line'); return false; } // end HTTP version // -- функция ssh_exec с подключение через SSH - работает, но не нужно /* // echo send_get($ip,$port); // Проверка доступности хоста в Винде или Линуксе. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { exec ("ping -n 2 -w 200 {$ip}", $output, $status); } else { exec ("ping -c 2 -w 200 {$ip}", $output, $status); } // Если доступен, то подключаемся через SSH if ($status == 0) { log_cam(date('H:i:s')." - Webcam {$ip} port {$port} is Ok "); //echo "Webcam {$ip} port {$port} is Ok <br />"; $connection = ssh2_connect($ip, $port); if ($connection){ if (ssh2_auth_password($connection, 'root', 'admin')) { ssh2_exec($connection, $command); return true; } else { return false; // Не прошла проверка логина_пароля // die('Public Key Authentication Failed'); } } else { log_cam(date('H:i:s')." - <b>Webcam {$ip} port {$port} is Off-line </b>"); //echo "<b>Webcam {$ip} port {$port} is Off-line </b><br />"; return false; // Не подключились к серверу } } */ // end с подключением через SSH }
/** * @param $period * @param $gain * @param $hour_lable * @param $sw */ function set_night_cam($period, $gain, $hour_lable, $sw) { // if ((date("Hi") == $period) && (file_get_contents("st") == 'on')){ if ($period <= date('Hi') && date('Hi') <= $period + 1 && file_get_contents("./st") == 'on') { // echo "wer"; global $ip_adresses; global $cam_gain; foreach ($ip_adresses as $ip_adress) { if (!file_exists($ip_adress['file'])) { file_put_contents($ip_adress['file'], ''); } if (file_get_contents($ip_adress['file']) != $hour_lable) { // echo "add"; log_cam("-----------------------------------------"); if (ssh_exec($ip_adress['ip'], $ip_adress['port_cam'], "settings/night_vision?set={$sw}")) { log_cam("Night: Sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_{$sw} ]"); // echo date('H:i:s')." - "."Night: Sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_{$sw} ] <br>"; if ($sw === 'on') { $gain = $cam_gain[$hour_lable][$ip_adress['name']]; if (ssh_exec($ip_adress['ip'], $ip_adress['port_cam'], "settings/night_vision_gain?set={$gain}")) { log_cam("Night: Sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_gain = {$gain} ]"); // echo date('H:i:s')." - "."Sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_gain = {$gain} ]<br />"; file_put_contents($ip_adress['file'], $hour_lable); } else { log_cam("Night: Error sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_gain = {$gain} ]", 'error'); // echo date('H:i:s')." - "."Night: Error sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_gain = {$gain} ]<br>"; } } elseif ($sw === 'off') { file_put_contents($ip_adress['file'], $hour_lable); } } else { log_cam("Night: Error sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_{$sw} ]", 'error'); // echo date('H:i:s')." - "."<b>Night: Error sent to {$ip_adress['ip']} port {$ip_adress['port_cam']} [ night_{$sw} ]</b><br>"; } } } } }
<?php include "ssh_cam.php"; //header('Refresh:1;url=./cam.php'); header('Location: cam.php'); $file_name = 'st'; if (isset($_POST['status'])) { $st = $_POST['status']; if ($st == "off" || $st == "on") { file_put_contents($file_name, $st); foreach ($ip_adresses as $ip_adress) { log_cam("-----------------------------------------"); if (ssh_exec($ip_adress['ip'], $ip_adress['port_ssh'], "index.php?status={$st}")) { log_cam("Webcam {$ip_adress['ip']} port {$ip_adress['port_ssh']} is [ {$st} ]", 'send'); // echo date('H:i:s')." - "."Webcam {$ip_adress['ip']} port {$ip_adress['port_ssh']} is [ {$st} ]<br />"; } else { log_cam("Error [ send {$st} ] Webcam {$ip_adress['ip']} port {$ip_adress['port_ssh']}", 'error'); // echo date('H:i:s')." - "."<b>Error [ send {$st} ] Webcam {$ip_adress['ip']} port {$ip_adress['port_ssh']}</b><br />"; } } } } //echo file_get_contents($file_name);