For my IPTV project usage, I need add a reboot button to a public html to reboot the set-top box. Easy way to do this work and just take notes.Overall:
Becaused we have command to reboot the stb. So we choose cgi to call reboot command by giving a ipadress as a parameter. And call this cgi by a HTTP GET method (as "/cgi-bin/rebootStb.cgi?rebootIP=192.168.xxx.xxx"). And I choose Ajax to send the GET url.
1. Our CGI scripts.
rebootStb.cgi
#!/bin/bash
ipaddress=`echo "$QUERY_STRING" | sed -n 's/^.*rebootIP=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`#get parameter
/usr/local/bin/STBremoteconf $ipaddress REBOOT
2. html to call scripts:
Although html also generated by a bash script, static testing testCgi.html:
< script >
function reboot(elementBtn,rebootIP)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.open('GET','/cgi-bin/rebootStb.cgi?rebootIP='+rebootIP,true);
xmlhttp.send();
processButton(elementBtn);
}
function processButton(elementBtn){
elementBtn.disabled=true;
setTimeout(function(){elementBtn.disabled=false},30000);
}
< / script >
< script src="jquery-1.9.1.min.js" >< / script >
IP: < input type=text value="192.168.188.150" id="inputBoxId"/>
< a href="javascript:reboot(this,document.getElementById('inputBoxId').value)">reboot< /a >
< input id="buttonId" type="button" value="reboot" onclick="reboot(this,document.getElementById('inputBoxId').value)" >
3. (Required when you have proxy setting to access the html)Apache Proxy setting.
I troubleshooting to why cannot execute the cgi script in production since it works well in my testing environment. Finally thought should be caused by firewall server proxy. So if need, just proxy the /cgi-bin also.
ProxyPass /stb http://192.168.10.4/stb
ProxyPassReverse /stb http://192.168.10.4/stb
#also need to add below code
ProxyPass /cgi-bin http://192.168.10.4/cgi-bin
ProxyPassReverse /cgi-bin http://192.168.10.4/cgi-bin
没有评论:
发表评论