From d32b5e19f52dbfce63be404b8cf7bcc9f33cb6f2 Mon Sep 17 00:00:00 2001 From: Julian Tatsch Date: Fri, 30 Dec 2022 13:35:02 +0100 Subject: [PATCH] fixes #1833 --- .../controlscripts/{ftp_server => ftp-server} | 0 .../{telnet_server => telnet-server} | 0 firmware_mod/scripts/common_functions.sh | 23 +-- firmware_mod/www/cgi-bin/ui_control.cgi | 2 +- firmware_mod/www/js/control.js | 145 +++++++++--------- 5 files changed, 86 insertions(+), 84 deletions(-) rename firmware_mod/controlscripts/{ftp_server => ftp-server} (100%) rename firmware_mod/controlscripts/{telnet_server => telnet-server} (100%) diff --git a/firmware_mod/controlscripts/ftp_server b/firmware_mod/controlscripts/ftp-server similarity index 100% rename from firmware_mod/controlscripts/ftp_server rename to firmware_mod/controlscripts/ftp-server diff --git a/firmware_mod/controlscripts/telnet_server b/firmware_mod/controlscripts/telnet-server similarity index 100% rename from firmware_mod/controlscripts/telnet_server rename to firmware_mod/controlscripts/telnet-server diff --git a/firmware_mod/scripts/common_functions.sh b/firmware_mod/scripts/common_functions.sh index 208dc25..ab83596 100755 --- a/firmware_mod/scripts/common_functions.sh +++ b/firmware_mod/scripts/common_functions.sh @@ -177,6 +177,9 @@ ir_cut(){ # Calibrate and control the motor # use like: motor up 100 motor(){ + ov=$(onvif_srvd status) + [ "${ov}" == "ON" ] && onvif_srvd off + if [ -z "$2" ] then steps=$STEP @@ -212,7 +215,7 @@ motor(){ fi ;; esac - + [ "${ov}" == "ON" ] && onvif_srvd on } update_motor_pos(){ @@ -319,13 +322,13 @@ recording(){ ftp_server(){ case "$1" in on) - /system/sdcard/controlscripts/ftp_server start + /system/sdcard/controlscripts/ftp-server start ;; off) - /system/sdcard/controlscripts/ftp_server stop + /system/sdcard/controlscripts/ftp-server stop ;; status) - if /system/sdcard/controlscripts/ftp_server status | grep -q "PID" + if /system/sdcard/controlscripts/ftp-server status | grep -q "PID" then echo "ON" else @@ -339,13 +342,13 @@ ftp_server(){ mqtt_control(){ case "$1" in on) - /system/sdcard/controlscripts/mqtt_control start + /system/sdcard/controlscripts/mqtt-control start ;; off) - /system/sdcard/controlscripts/mqtt_control stop + /system/sdcard/controlscripts/mqtt-control stop ;; status) - if /system/sdcard/controlscripts/mqtt_control status | grep -q "PID" + if /system/sdcard/controlscripts/mqtt-control status | grep -q "PID" then echo "ON" else @@ -379,13 +382,13 @@ mqtt_status(){ onvif_srvd(){ case "$1" in on) - /system/sdcard/controlscripts/onvif-srvd.sh start + /system/sdcard/controlscripts/onvif-srvd start ;; off) - /system/sdcard/controlscripts/onvif-srvd.sh stop + /system/sdcard/controlscripts/onvif-srvd stop ;; status) - if /system/sdcard/controlscripts/onvif-srvd.sh status | grep -q "PID" + if /system/sdcard/controlscripts/onvif-srvd status | grep -q "PID" then echo "ON" else diff --git a/firmware_mod/www/cgi-bin/ui_control.cgi b/firmware_mod/www/cgi-bin/ui_control.cgi index 51db5aa..41c531f 100755 --- a/firmware_mod/www/cgi-bin/ui_control.cgi +++ b/firmware_mod/www/cgi-bin/ui_control.cgi @@ -13,7 +13,7 @@ echo "" if [ -n "$F_cmd" ]; then case "$F_cmd" in get_services) - services="auto-night-detection debug-on-osd ftp_server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup dropbear telegram-bot timelapse lighttpd" + services="auto-night-detection debug-on-osd ftp-server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup dropbear telegram-bot timelapse lighttpd" for service in $services ; do echo "${service}#:#$(test -f /run/${service}.pid && echo 'started' || echo 'stopped')#:#$(test -f /system/sdcard/config/autostart/${service} && echo 'true' || echo 'false')#:#false" done diff --git a/firmware_mod/www/js/control.js b/firmware_mod/www/js/control.js index ca5b533..01f9f3c 100755 --- a/firmware_mod/www/js/control.js +++ b/firmware_mod/www/js/control.js @@ -5,7 +5,7 @@ function timedRefresh(timeoutPeriod) { if (timeoutPeriod == 0) { window.location.href = window.location.href; } else { - setTimeout(function() { + setTimeout(function () { timedRefresh(timeoutPeriod) }, 1000); } @@ -14,17 +14,16 @@ function timedRefresh(timeoutPeriod) { function update(onStart) { $.ajax({ 'url': 'cgi-bin/action.cgi?cmd=show_updateProgress' - }).done(function(log) { + }).done(function (log) { if (log < 0) { - if (onStart != true) - { + if (onStart != true) { $('#message').text("Error starting update process"); } } else { $('#message').text("Update in progress"); $('#progress').removeAttr('style'); - $('#progress').attr('style','width:'+log+'%'); - $('#progressValue').html(log+'%'); + $('#progress').attr('style', 'width:' + log + '%'); + $('#progressValue').html(log + '%'); // This is the end, start the reboot count down if (log >= 100) { timedRefresh(30); @@ -48,10 +47,10 @@ function accordionUpdate(param) { } function startCustom(el) { - var repo = $('#custom_repo').val(); - var branch = $('#custom_branch').val(); - var mode = $('#custom_full').is(":checked") ? 'full' : 'cumul'; - start(repo, branch, mode); + var repo = $('#custom_repo').val(); + var branch = $('#custom_branch').val(); + var mode = $('#custom_full').is(":checked") ? 'full' : 'cumul'; + start(repo, branch, mode); } function showupdatepage(result) { @@ -59,12 +58,12 @@ function showupdatepage(result) { $.ajax({ 'url': 'cgi-bin/action.cgi?cmd=check_update' - }).done(function(result){ + }).done(function (result) { var update = result.split(":") var repo = update[0]; var branch = update[1]; - var update_status = parseInt(update[2],10); + var update_status = parseInt(update[2], 10); var custom = '
\

Custom Firmware

\ @@ -110,7 +109,7 @@ function showupdatepage(result) {
' + custom); } else if (update_status > 0) { - $('#updatemsg').html("You are "+ update_status +" commits behind the " + branch + " branch of the " + repo + " repo.") + $('#updatemsg').html("You are " + update_status + " commits behind the " + branch + " branch of the " + repo + " repo.") if (branch == "master") { $('#update').append('
'); $('#update').append(' \ @@ -146,38 +145,38 @@ function showupdatepage(result) { } function saveConfig() { - $.get("cgi-bin/ui_control.cgi",{cmd: "save_config"},function(result) { + $.get("cgi-bin/ui_control.cgi", { cmd: "save_config" }, function (result) { getFiles('config'); }); } -function deleteConfig(fileName,dir) { - var del = confirm("Confirm delete file: "+fileName); - if ( del ) { - $.get("cgi-bin/ui_control.cgi", {cmd: "del_config",file: fileName}); +function deleteConfig(fileName, dir) { + var del = confirm("Confirm delete file: " + fileName); + if (del) { + $.get("cgi-bin/ui_control.cgi", { cmd: "del_config", file: fileName }); getFiles(dir); } } function restoreConfig(fileName) { - var restore = confirm("Are you sure to restore config file: "+fileName+"\n Camera will reboot at the end of the process"); - if ( restore ) { - $.get("cgi-bin/ui_control.cgi",{cmd: "restore_config",file: fileName}); + var restore = confirm("Are you sure to restore config file: " + fileName + "\n Camera will reboot at the end of the process"); + if (restore) { + $.get("cgi-bin/ui_control.cgi", { cmd: "restore_config", file: fileName }); } } //Function to get video and images files from dir function getFiles(dir) { // Get files from dir - $('#'+dir).html("

"); - $.get("cgi-bin/ui_control.cgi", {cmd: "getFiles", dir: dir}, function(config){ + $('#' + dir).html("

"); + $.get("cgi-bin/ui_control.cgi", { cmd: "getFiles", dir: dir }, function (config) { var config_all = config.split("\n"); - if ( config_all.length == 1) - $('#'+dir).append("

No snapshot available.

"); + if (config_all.length == 1) + $('#' + dir).append("

No snapshot available.

"); else { - $('#'+dir).append("\ - \ + $('#' + dir).append("\ +
\ \ \ \ @@ -187,51 +186,51 @@ function getFiles(dir) { \ \ "); - for (var i = 0; i < config_all.length-1; i++) { + for (var i = 0; i < config_all.length - 1; i++) { var config_info = config_all[i].split("#:#"); var file_info = config_info[3].split("."); var html_photo = ""; - $('#result_'+dir).append(" \ - \ - \ - \ + $('#result_' + dir).append(" \ + \ + \ + \ "); } - $('#'+dir).append("
Filename
"+config_info[0]+""+config_info[1]+""+config_info[2]+"
"+ config_info[0] + ""+ config_info[1] + ""+ config_info[2] + " \ - \ - \ - \ + \ + \ + \

"); - var table = $('#result_'+dir).DataTable(); - $('#result'+dir).on( 'click', 'tr', function () { + $('#' + dir).append("

"); + var table = $('#result_' + dir).DataTable(); + $('#result' + dir).on('click', 'tr', function () { //$(this).toggleClass('selected'); - } ); - $('#result'+dir).click( function () { - //alert( table.rows('.selected').data().length +' row(s) selected' ); - } ); + }); + $('#result' + dir).click(function () { + //alert( table.rows('.selected').data().length +' row(s) selected' ); + }); } }); } -function start(repo,branch,mode) { +function start(repo, branch, mode) { var login = ""; // if ($('#login').val().length > 0) { // login = "login=" + $('#login').val() + ":" + $('#password').val(); // } //Open modal window - document.getElementById('modal_box').style.display='block' + document.getElementById('modal_box').style.display = 'block' $('#modal_title').html('Update in progress'); $('#modal_content').html('

Please note: at the end of this process the camera will reboot without notice!

\
0%

'); - var url = 'cgi-bin/action.cgi?cmd=update&repo='+repo+'&release='+branch+'&mode='+mode; + var url = 'cgi-bin/action.cgi?cmd=update&repo=' + repo + '&release=' + branch + '&mode=' + mode; $.ajax({ 'url': url, 'type': 'POST', 'data': login - }).done(function(result) { + }).done(function (result) { if (result.length > 0) { update(false); @@ -242,27 +241,27 @@ function start(repo,branch,mode) { } //Function control service (stop/start) -function controlService(action,serviceName) { - $.get("cgi-bin/ui_control.cgi", {cmd: "services",service: serviceName, action: action}, function(result){ - $('#control_'+serviceName).removeAttr('onclick'); +function controlService(action, serviceName) { + $.get("cgi-bin/ui_control.cgi", { cmd: "services", service: serviceName, action: action }, function (result) { + $('#control_' + serviceName).removeAttr('onclick'); if (action == 'start') { - $('#control_'+serviceName).attr('onclick','controlService("stop","'+serviceName+'")') + $('#control_' + serviceName).attr('onclick', 'controlService("stop","' + serviceName + '")') } else { - $('#control_'+serviceName).attr('onclick','controlService("start","'+serviceName+'")') + $('#control_' + serviceName).attr('onclick', 'controlService("start","' + serviceName + '")') } }); } //Function to control autostart -function autoStartService(action,serviceName) { - $.get("cgi-bin/ui_control.cgi", {cmd: "autoStartService",service: serviceName, action: action}); - $('#autoStart_'+serviceName).removeAttr('onclick'); - if(action == "true") { - $('#autoStart_'+serviceName).attr('onclick','autoStartService("false","'+serviceName+'")'); +function autoStartService(action, serviceName) { + $.get("cgi-bin/ui_control.cgi", { cmd: "autoStartService", service: serviceName, action: action }); + $('#autoStart_' + serviceName).removeAttr('onclick'); + if (action == "true") { + $('#autoStart_' + serviceName).attr('onclick', 'autoStartService("false","' + serviceName + '")'); } else { - $('#autoStart_'+serviceName).attr('onclick','autoStartService("true","'+serviceName+'")'); + $('#autoStart_' + serviceName).attr('onclick', 'autoStartService("true","' + serviceName + '")'); } } @@ -271,7 +270,7 @@ var serviceFriendlyNames = { "auto-night-detection": "Auto Night Detection", "dropbear": "SSH Server", "debug-on-osd": "Debug on OSD", - "ftp_server": "FTP Server", + "ftp-server": "FTP Server", "mdns-responder": "mDNSResponder", "mqtt-control": "MQTT Control", "mqtt-status": "MQTT Live Status Updates", @@ -287,21 +286,21 @@ var serviceFriendlyNames = { //Function get config function getServices() { // get config and put to hmtl elements - $.get("cgi-bin/ui_control.cgi", {cmd: "get_services"}, function(config){ + $.get("cgi-bin/ui_control.cgi", { cmd: "get_services" }, function (config) { var config_all = config.split("\n"); - for (var i = 0; i < config_all.length-1; i++) { - var config_info = config_all[i].split("#:#"); - // Select button color accrding status - var control_checked = "onclick='controlService(\"start\",\""+config_info[0]+"\")')"; - if (config_info[1] == "started") - control_checked = "checked onclick='controlService(\"stop\",\""+config_info[0]+"\")')"; - var autostart_checked = "onclick='autoStartService(\"true\",\""+config_info[0]+"\")')"; - if(config_info[2] == "true") - autostart_checked = "checked onclick='autoStartService(\"false\",\""+config_info[0]+"\")')"; - var friendly_name = serviceFriendlyNames[config_info[0]] || config_info[0]; - $('#tabServices').append(""+friendly_name+"\ - Stop Start\ - Off On"); + for (var i = 0; i < config_all.length - 1; i++) { + var config_info = config_all[i].split("#:#"); + // Select button color accrding status + var control_checked = "onclick='controlService(\"start\",\"" + config_info[0] + "\")')"; + if (config_info[1] == "started") + control_checked = "checked onclick='controlService(\"stop\",\"" + config_info[0] + "\")')"; + var autostart_checked = "onclick='autoStartService(\"true\",\"" + config_info[0] + "\")')"; + if (config_info[2] == "true") + autostart_checked = "checked onclick='autoStartService(\"false\",\"" + config_info[0] + "\")')"; + var friendly_name = serviceFriendlyNames[config_info[0]] || config_info[0]; + $('#tabServices').append("" + friendly_name + "\ + Stop Start\ + Off On"); } }); @@ -309,7 +308,7 @@ function getServices() { function system(command) { //Open modal window - document.getElementById('modal_box').style.display='block' + document.getElementById('modal_box').style.display = 'block' $('#modal_title').html(command); if (command == "reboot") { $('#modal_content').html("

");