1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-03 05:02:40 +02:00

Finish net services page

This commit is contained in:
gysmo38
2020-05-24 22:19:45 +02:00
committed by Julian Tatsch
parent 5d306a10f5
commit 936fc5fe91
4 changed files with 346 additions and 31 deletions

View File

@@ -0,0 +1,193 @@
#!/bin/sh
. /system/sdcard/www/cgi-bin/func.cgi
. /system/sdcard/scripts/common_functions.sh
export LD_LIBRARY_PATH=/system/lib
export LD_LIBRARY_PATH=/thirdlib:$LD_LIBRARY_PATH
echo "Content-type: text/html"
echo "Pragma: no-cache"
echo "Cache-Control: max-age=0, no-store, no-cache"
echo ""
if [ -n "$F_cmd" ]; then
case "$F_cmd" in
get_config_mqtt)
if [ ! -f "/system/sdcard/config/mqtt.conf" ]; then
$(cp /system/sdcard/config/mqtt.conf.dist /system/sdcard/config/mqtt.conf)
fi
source /system/sdcard/config/mqtt.conf
echo "mqttUser#:#${USER}"
echo "mqttPass#:#${PASS}"
echo "mqttHost#:#${HOST}"
echo "mqttPort#:#${PORT}"
echo "mqttLocation#:#${LOCATION}"
echo "mqttDeviceName#:#${DEVICE_NAME}"
echo "mqttAutodiscoveryPrefix#:#${AUTODISCOVERY_PREFIX}"
echo "mqttStatusInterval#:#${STATUSINTERVAL}"
;;
get_config_mail)
if [ ! -f "/system/sdcard/config/sendmail.conf" ]; then
$(cp /system/sdcard/config/sendmail.conf.dist /system/sdcard/config/sendmail.conf)
fi
source /system/sdcard/config/sendmail.conf
echo "from#:#${FROM}"
echo "fromName#:#${FROMNAME}"
echo "auth#:#${AUTH}"
echo "pass#:#${PASS}"
echo "to#:#${TO}"
echo "server#:#${SERVER}"
echo "port#:#${PORT}"
echo "subject#:#${SUBJECT}"
echo "body#:#${BODY}"
echo "numberOfPictures#:#${NUMBEROFPICTURES}"
echo "timeBetweenSnapshot#:#${TIMEBETWEENSNAPSHOT}"
echo "quality#:#${QUALITY}"
;;
get_config_telegram)
if [ ! -f "/system/sdcard/config/telegram.conf" ]; then
$(cp /system/sdcard/config/telegram.conf.dist /system/sdcard/config/telegram.conf)
fi
source /system/sdcard/config/telegram.conf
echo "apiToken#:#${apiToken}"
echo "userChatID#:#${userChatId}"
;;
get_config_matrix)
if [ ! -f "/system/sdcard/config/matrix.conf" ]; then
$(cp /system/sdcard/config/matrix.conf.dist /system/sdcard/config/matrix.conf)
fi
source /system/sdcard/config/matrix.conf
echo "host#:#${host}"
echo "portM#:#${port}"
echo "roomID#:#${room_id}"
echo "sender#:#${sender}"
echo "accessToken#:#${access_token}"
;;
save_config_mqtt)
echo "Save mqtt"
if [ -n "${F_mqttUser+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf USER $F_mqttUser
echo "MQTT user set to $F_mqttUser<br/>"
fi
if [ -n "${F_mqttPass+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf PASS $F_mqttPass
echo "MQTT password set<br/>"
fi
if [ -n "${F_mqttHost+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf HOST $F_mqttHost
echo "MQTT host set to $F_mqttHost<br/>"
fi
if [ -n "${F_mqttPort+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf PORT $F_mqttPort
echo "MQTT port set to $F_mqttPort<br/>"
fi
if [ -n "${F_mqttLocation+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf LOCATION "\"$F_mqttLocation\""
echo "MQTT location set to $F_mqttLocation<br/>"
fi
if [ -n "${F_mqttDeviceName+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf DEVICE_NAME "\"$F_mqttDeviceName\""
echo "MQTT device name set to $F_mqttDeviceName<br/>"
fi
if [ -n "${F_mqttAutodiscoveryPrefix+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf AUTODISCOVERY_PREFIX "\"$F_mqttAutodiscoveryPrefix\""
echo "MQTT autodiscovery topic set to $F_mqttAutodiscoveryPrefix<br/>"
fi
if [ -n "${F_mqttStatusInterval+x}" ]; then
rewrite_config /system/sdcard/config/mqtt.conf STATUSINTERVAL $F_mqttStatusInterval
echo "MQTT status interval set to $F_mqttStatusInterval<br/>"
fi
;;
save_config_mail)
if [ -n "${F_from+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf FROM "\"$F_from\""
echo "Sendmail from address set to $F_from<br/>"
fi
if [ -n "${F_fromName+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf FROMNAME "\"$F_fromName\""
echo "Sendmail from name set to $F_fromName<br/>"
fi
if [ -n "${F_auth+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf AUTH "\"$F_auth\""
echo "Sendmail auth user set to $F_auth<br/>"
fi
if [ -n "${F_pass+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf PASS "\"$F_pass\""
echo "Sendmail set password<br/>"
fi
if [ -n "${F_to+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf TO "\"$F_to\""
echo "Sendmail destination address set to $F_to<br/>"
fi
if [ -n "${F_server+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf SERVER $F_server
echo "Sendmail server hostname set to $F_server<br/>"
fi
if [ -n "${F_port+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf PORT $F_port
echo "Sendmail server port set to $F_port<br/>"
fi
if [ -n "${F_subject+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf SUBJECT "\"$F_subject\""
echo "Sendmail subject set to $F_subject<br/>"
fi
if [ -n "${F_body+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf BODY "\"$F_body\""
echo "Sendmail body set to $F_body<br/>"
fi
if [ -n "${F_numberOfPictures+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf NUMBEROFPICTURES $F_numberOfPictures
echo "Sendmail number of pictures set to $F_numberOfPictures<br/>"
fi
if [ -n "${F_timeBetweenSnapshot+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf TIMEBETWEENSNAPSHOT $F_timeBetweenSnapshot
echo "Sendmail time betweend snapshot set to $F_timeBetweenSnapshot<br/>"
fi
if [ -n "${F_quality+x}" ]; then
rewrite_config /system/sdcard/config/sendmail.conf QUALITY $F_quality
echo "Sendmail quality of pictures set to $F_quality<br/>"
fi
;;
save_config_telegram)
if [ -n "${F_apiToken+x}" ]; then
rewrite_config /system/sdcard/config/telegram.conf apiToken "\"$F_apiToken\""
echo "Telegram api token set to $F_apiToken<br/>"
fi
if [ -n "${F_userChatID+x}" ]; then
rewrite_config /system/sdcard/config/telegram.conf userChatId "\"$F_userChatID\""
echo "Matrix server host set to $F_userChatID<br/>"
fi
;;
save_config_matrix)
if [ -n "${F_host+x}" ]; then
rewrite_config /system/sdcard/config/matrix.conf host $F_host
echo "Matrix server host set to $F_host<br/>"
fi
if [ -n "${F_portM+x}" ]; then
rewrite_config /system/sdcard/config/matrix.conf port $F_portM
echo "Matrix server port set to $F_portM<br/>"
fi
if [ -n "${F_roomID+x}" ]; then
rewrite_config /system/sdcard/config/matrix.conf room_id $F_roomID
echo "Matrix room ID set to $F_roomID<br/>"
fi
if [ -n "${F_sender+x}" ]; then
rewrite_config /system/sdcard/config/matrix.conf sender $F_sender
echo "Matrix server sender set to $F_sender<br/>"
fi
if [ -n "${F_accessToken+x}" ]; then
rewrite_config /system/sdcard/config/matrix.conf access_token $F_accessToken
echo "Matrix server access token set<br/>"
fi
;;
*)
echo "Unsupported command '$F_cmd'"
;;
esac
fi
exit 0

View File

@@ -0,0 +1,55 @@
//Function save config
function saveConfig(elements) {
//Open modal window
document.getElementById('save_confirm').style.display='block'
$('#save_result').html("Waiting for save result...");
var postData = { cmd: "save_config_"+elements }
$("#"+elements+" input, #"+elements+" select").each(function(){
var input = $(this);
postData[input.attr('id')] = input.val();
});
$.post("cgi-bin/net_services.cgi",postData,function(result){
if ( result != "")
$('#save_result').html(result);
else
$('#save_result').html("Nothing to update");
});
}
//Function get config
function getConfig(service) {
// get config and put to hmtl elements
$.get("cgi-bin/net_services.cgi", {cmd: "get_config_"+service}, 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("#:#");
// If element is a select, selected good value
if ($('#'+config_info[0]).is('select'))
$('#'+config_info[0]+' > option').each(function() {
if($(this).val() == config_info[1])
$(this).attr('selected','selected');
});
else
$('#'+config_info[0]).attr("value",config_info[1]);
}
});
}
//Function loaded when script load
function onLoad() {
//Activate accordion
accordion();
//Get configuration
getConfig('mqtt');
}
onLoad();

View File

@@ -2,6 +2,7 @@
function getFiles(dir) {
// Get files from dir
$.get("cgi-bin/sdcard.cgi", {cmd: "getFiles", dir: dir}, function(config){
$('#tab'+dir+' > tbody').html("");
var config_all = config.split("\n");
if ( config_all.length == 1)
$('#tab'+dir).append("<tr><td colspan='4'>No files found</td></tr>");

View File

@@ -1,51 +1,117 @@
<!-- System card-->
<div class="w3-panel w3-card">
<form class="w3-container" onsubmit="saveConfig();return false;">
<h1> Network services configuration</h1>
<div class="w3-row">
<a href="javascript:void(0)" onclick="openTab(event, 'mqtt');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding w3-border-theme">MQTT</div>
<a href="javascript:void(0)" onclick="openTab(event, 'mqttTab');getConfig('mqtt');">
<div class="w3-quarter tablink w3-bottombar w3-hover-light-grey w3-padding w3-border-theme">MQTT</div>
</a>
<a href="javascript:void(0)" onclick="openTab(event, 'ftp');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding">FTP</div>
<a href="javascript:void(0)" onclick="openTab(event, 'mailTab');getConfig('mail');">
<div class="w3-quarter tablink w3-bottombar w3-hover-light-grey w3-padding">Mail</div>
</a>
<a href="javascript:void(0)" onclick="openTab(event, 'telegramTab');getConfig('telegram');">
<div class="w3-quarter tablink w3-bottombar w3-hover-light-grey w3-padding">Telegram</div>
</a>
<a href="javascript:void(0)" onclick="openTab(event, 'matrixTab');getConfig('matrix');">
<div class="w3-quarter tablink w3-bottombar w3-hover-light-grey w3-padding">Matrix</div>
</a>
</div>
<div id="mqtt" class="w3-container tab">
<p></p>
<!-- MQTT Tab -->
<div id="mqttTab" class="w3-container tab">
<p><form class="w3-container" onsubmit="saveConfig('mqtt');return false" id="mqtt"></p>
<label>Server address</label>
<input id="hostname" class="w3-input" type="text">
<input id="mqttHost" class="w3-input" type="text">
<br />
<label>Server port</label>
<input id="mqttPort" class="w3-input" type="text">
<br />
<label>MQTT user</label>
<input id="hostname" class="w3-input" type="text">
<input id="mqttUser" class="w3-input" type="text">
<br />
<label>MQTT password</label>
<input id="password" class="w3-input" type="password" value="*****">
<input id="mqttPass" class="w3-input" type="password">
<br />
<label>Location</label>
<input id="hostname" class="w3-input" type="text">
<input id="mqttLocation" class="w3-input" type="text">
<br />
<label>Device name</label>
<input id="hostname" class="w3-input" type="text">
<input id="mqttDeviceName" class="w3-input" type="text">
<br />
<label>Status interval</label>
<input id="hostname" class="w3-input" type="text">
<label>Autodiscovery topic</label>
<input id="mqttAutodiscoveryPrefix" class="w3-input" type="text">
<br />
<label>Status interval (in seconds)</label>
<input id="mqttStatusInterval" class="w3-input" type="text">
<p><button class="w3-btn w3-theme" >Save</button></form></p>
</div>
<!-- Mail Tab -->
<div id="mailTab" class="w3-container tab" style="display:none">
<p><form class="w3-container" onsubmit="saveConfig('mail');return false" id="mail"></p>
<!-- SMTP Server settings accordion-->
<button class="accordion" type='button'>SMTP Server settings</button>
<div class="panel">
<br />
<label>SMTP Server</label>
<input id="server" class="w3-input" type="text"><br />
<label>SMTP Port</label>
<input id="port" class="w3-input" type="text"><br />
<label>SMTP Authentication user</label>
<input id="auth" class="w3-input" type="text"><br />
<label>SMTP Authentication password</label>
<input id="pass" class="w3-input" type="password"><br />
</div>
<!-- Mail settings accordion-->
<button class="accordion" type='button'>Mail settings</button>
<div class="panel">
<br />
<label>From</label>
<input id="from" class="w3-input" type="text"><br />
<label>From name</label>
<input id="fromName" class="w3-input" type="text"><br />
<label>Destination</label>
<input id="to" class="w3-input" type="text"><br />
<label>Mail subject</label>
<input id="subject" class="w3-input" type="text"><br />
<label>Mail body</label>
<input id="body" class="w3-input" type="text"><br />
<label>Numbers of pictures</label>
<input id="numberOfPictures" class="w3-input" type="text"><br />
<label>Time betweens pictures (in seconds)</label>
<input id="timeBetweenSnapshot" class="w3-input" type="text"><br />
<label>Quality of compression (Valid quality values: 0 - 100, 100% is best)<br /> Set to -1 for no compression</label>
<input id="quality" class="w3-input" type="text"><br />
</div>
<p><button class="w3-btn w3-theme" >Save</button></form></p>
</div>
<div id="ftp" class="w3-container tab" style="display:none">
<p id='currenttime'></p>
<label>Port</label>
<select id="timezone" class="w3-select">
</select>
<br />
<label>NTP Server</label>
<input id="ntp" class="w3-input" type="text">
</div>
<p></p>
<button class="w3-btn w3-theme">Save</button>
<p></p>
<!-- Telegram Tab-->
<div id="telegramTab" class="w3-container tab" style="display:none">
<p><form class="w3-container" onsubmit="saveConfig('telegram');return false" id="telegram"></p>
<label>API Token</label>
<input id="apiToken" class="w3-input" type="text"><br />
<label>User chat ID</label>
<input id="userChatID" class="w3-input" type="text"><br />
<p><button class="w3-btn w3-theme" >Save</button></form></p>
</div>
<!-- Matrix Tab-->
<div id="matrixTab" class="w3-container tab" style="display:none">
<p><form class="w3-container" onsubmit="saveConfig('matrix');return false" id="matrix"></p>
<label>Server host</label>
<input id="host" class="w3-input" type="text"><br />
<label>Server port</label>
<input id="portM" class="w3-input" type="text"><br />
<label>Room ID</label>
<input id="roomID" class="w3-input" type="text"><br />
<label>Sender</label>
<input id="sender" class="w3-input" type="text"><br />
<label>Access token</label>
<input id="accessToken" class="w3-input" type="text"><br />
<p><button class="w3-btn w3-theme" >Save</button></form></p>
</div>
</div>
</div>
<div id="save_confirm" class="w3-modal">
<div class="w3-modal-content">
@@ -55,10 +121,10 @@
<h2>Save config</h2>
</header>
<div class="w3-container">
<p id="save_result">Waiting for save result...</p>
<p id="save_result"></p>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="js/system.js"></script>
<script type="text/javascript" src="js/net_services.js"></script>