[IMP] point_of_sale: add remote debugging capabilities to the posbox
Sometimes it's useful to ssh into a posbox to quickly troubleshoot an issue. Talking customers through port forwarding is very difficult however. We use ngrok to solve this issue. This implements an interface that allows a user to enter an ngrok authentication token. After this, ngrok can be started and we should be able to remotely connect. Note that ngrok does NOT run by default on the posbox. It can only be started manually by the user.
This commit is contained in:
parent
3726612735
commit
617ba72a9d
|
@ -13,11 +13,7 @@ from openerp.tools.translate import _
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
index_template = """
|
index_style = """
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Odoo's PosBox</title>
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
width: 480px;
|
width: 480px;
|
||||||
|
@ -26,7 +22,17 @@ index_template = """
|
||||||
text-align: justify;
|
text-align: justify;
|
||||||
color: #6B6B6B;
|
color: #6B6B6B;
|
||||||
}
|
}
|
||||||
|
.text-red {
|
||||||
|
color: #FF0000;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
"""
|
||||||
|
index_template = """
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Odoo's PosBox</title>
|
||||||
|
""" + index_style + """
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Your PosBox is up and running</h1>
|
<h1>Your PosBox is up and running</h1>
|
||||||
|
@ -73,15 +79,7 @@ class PosboxHomepage(openerp.addons.web.controllers.main.Home):
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Wifi configuration</title>
|
<title>Wifi configuration</title>
|
||||||
<style>
|
""" + index_style + """
|
||||||
body {
|
|
||||||
width: 480px;
|
|
||||||
margin: 60px auto;
|
|
||||||
font-family: sans-serif;
|
|
||||||
text-align: justify;
|
|
||||||
color: #6B6B6B;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Configure wifi</h1>
|
<h1>Configure wifi</h1>
|
||||||
|
@ -162,3 +160,79 @@ class PosboxHomepage(openerp.addons.web.controllers.main.Home):
|
||||||
def clear_wifi_configuration(self):
|
def clear_wifi_configuration(self):
|
||||||
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/clear_wifi_configuration.sh')
|
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/clear_wifi_configuration.sh')
|
||||||
return "configuration cleared"
|
return "configuration cleared"
|
||||||
|
|
||||||
|
@http.route('/remote_connect', type='http', auth='none', cors='*')
|
||||||
|
def remote_connect(self):
|
||||||
|
ngrok_template = """
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Remote debugging</title>
|
||||||
|
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
var upgrading = false;
|
||||||
|
$('#enable_debug').click(function () {
|
||||||
|
var auth_token = $('#auth_token').val();
|
||||||
|
if (auth_token == "") {
|
||||||
|
alert('Please provide an authentication token.');
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
url: '/enable_ngrok',
|
||||||
|
data: {
|
||||||
|
'auth_token': auth_token
|
||||||
|
}
|
||||||
|
}).always(function (response) {
|
||||||
|
if (response === 'already running') {
|
||||||
|
alert('Remote debugging already activated.');
|
||||||
|
} else {
|
||||||
|
$('#auth_token').attr('disabled','disabled');
|
||||||
|
$('#enable_debug').html('Enabled remote debugging');
|
||||||
|
$('#enable_debug').removeAttr('href', '')
|
||||||
|
$('#enable_debug').off('click');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
""" + index_style + """
|
||||||
|
<style>
|
||||||
|
#enable_debug {
|
||||||
|
padding: 10px;
|
||||||
|
background: rgb(121, 197, 107);
|
||||||
|
color: white;
|
||||||
|
border-radius: 3px;
|
||||||
|
text-align: center;
|
||||||
|
margin: 30px;
|
||||||
|
text-decoration: none;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.centering{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Remote debugging</h1>
|
||||||
|
<p class='text-red'>
|
||||||
|
This allows someone to gain remote access to your Posbox, and
|
||||||
|
thus your entire local network. Only enable this for someone
|
||||||
|
you trust.
|
||||||
|
</p>
|
||||||
|
<div class='centering'>
|
||||||
|
<input type="text" id="auth_token" size="42" placeholder="Authentication Token"/> <br/>
|
||||||
|
<a id="enable_debug" href="#">Enable remote debugging</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
return ngrok_template
|
||||||
|
|
||||||
|
@http.route('/enable_ngrok', type='http', auth='none', cors='*')
|
||||||
|
def enable_ngrok(self, auth_token):
|
||||||
|
if subprocess.call(['pgrep', 'ngrok']) == 1:
|
||||||
|
subprocess.Popen(['ngrok', 'tcp', '-authtoken', auth_token, '-log', '/tmp/ngrok.log', '22'])
|
||||||
|
return 'starting with ' + auth_token
|
||||||
|
else:
|
||||||
|
return 'already running'
|
||||||
|
|
|
@ -10,6 +10,7 @@ function connect () {
|
||||||
ESSID="${1}"
|
ESSID="${1}"
|
||||||
PASSWORD="${2}"
|
PASSWORD="${2}"
|
||||||
PERSIST="${3}"
|
PERSIST="${3}"
|
||||||
|
NO_AP="${4}"
|
||||||
|
|
||||||
sleep 3
|
sleep 3
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ function connect () {
|
||||||
# give dhcp some time
|
# give dhcp some time
|
||||||
timeout 30 sh -c 'until ifconfig wlan0 | grep "inet addr:" ; do sleep 0.1 ; done'
|
timeout 30 sh -c 'until ifconfig wlan0 | grep "inet addr:" ; do sleep 0.1 ; done'
|
||||||
|
|
||||||
if [ $? -eq 124 ] ; then
|
if [ $? -eq 124 ] && [ -z "${NO_AP}" ] ; then
|
||||||
logger -t posbox_connect_to_wifi "Failed to connect, forcing Posbox AP"
|
logger -t posbox_connect_to_wifi "Failed to connect, forcing Posbox AP"
|
||||||
sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh "force" &
|
sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh "force" &
|
||||||
else
|
else
|
||||||
|
@ -66,4 +67,4 @@ function connect () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
connect "${1}" "${2}" "${3}" &
|
connect "${1}" "${2}" "${3}" "${4}" &
|
||||||
|
|
|
@ -8,7 +8,7 @@ while true ; do
|
||||||
|
|
||||||
logger -t posbox_keep_wifi_alive "Lost wifi, trying to reconnect to ${ESSID}"
|
logger -t posbox_keep_wifi_alive "Lost wifi, trying to reconnect to ${ESSID}"
|
||||||
|
|
||||||
sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh "${ESSID}" "${PASSWORD}"
|
sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh "${ESSID}" "${PASSWORD}" "" "NO_AP"
|
||||||
|
|
||||||
sleep 30
|
sleep 30
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -41,6 +41,15 @@ odoo.py" | tee --append .git/info/sparse-checkout > /dev/null
|
||||||
git read-tree -mu HEAD
|
git read-tree -mu HEAD
|
||||||
cd "${__dir}"
|
cd "${__dir}"
|
||||||
|
|
||||||
|
USR_BIN="${OVERWRITE_FILES_BEFORE_INIT_DIR}/usr/bin/"
|
||||||
|
mkdir -p "${USR_BIN}"
|
||||||
|
cd "/tmp"
|
||||||
|
curl 'https://dl.ngrok.com/ngrok_2.0.19_linux_arm.zip' > ngrok.zip
|
||||||
|
unzip ngrok.zip
|
||||||
|
rm ngrok.zip
|
||||||
|
cd "${__dir}"
|
||||||
|
mv /tmp/ngrok "${USR_BIN}"
|
||||||
|
|
||||||
LOOP_MAPPER_PATH=$(kpartx -av posbox.img | tail -n 1 | cut -d ' ' -f 3)
|
LOOP_MAPPER_PATH=$(kpartx -av posbox.img | tail -n 1 | cut -d ' ' -f 3)
|
||||||
LOOP_MAPPER_PATH="/dev/mapper/${LOOP_MAPPER_PATH}"
|
LOOP_MAPPER_PATH="/dev/mapper/${LOOP_MAPPER_PATH}"
|
||||||
mkdir "${MOUNT_POINT}"
|
mkdir "${MOUNT_POINT}"
|
||||||
|
@ -51,6 +60,8 @@ cp -a "${OVERWRITE_FILES_BEFORE_INIT_DIR}"/* "${MOUNT_POINT}"
|
||||||
|
|
||||||
# get rid of the git clone
|
# get rid of the git clone
|
||||||
rm -rf "${CLONE_DIR}"
|
rm -rf "${CLONE_DIR}"
|
||||||
|
# and the ngrok usr/bin
|
||||||
|
rm -rf "${OVERWRITE_FILES_BEFORE_INIT_DIR}/usr"
|
||||||
|
|
||||||
# get rid of the mount, we have to remount it anyway because we have
|
# get rid of the mount, we have to remount it anyway because we have
|
||||||
# to "refresh" the filesystem after qemu modified it
|
# to "refresh" the filesystem after qemu modified it
|
||||||
|
|
Loading…
Reference in New Issue