# -*- coding: utf-8 -*- # Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. import logging import os import subprocess import werkzeug import flectra from flectra import http from flectra.tools import misc _logger = logging.getLogger(__name__) index_style = """ """ index_template = """ Flectra's PosBox """ + index_style + """

Your PosBox is up and running

The PosBox is a hardware adapter that allows you to use receipt printers and barcode scanners with Flectra's Point of Sale, version 8.0 or later. You can start an online free trial, or download and install it yourself.

For more information on how to setup the Point of Sale with the PosBox, please refer to the manual.

To see the status of the connected hardware, please refer to the hardware status page.

Wi-Fi can be configured by visiting the Wi-Fi configuration page.

If you need to grant remote debugging access to a developer, you can do it here.

%s

The PosBox software installed on this posbox is version 16, the posbox version number is independent from Flectra. You can upgrade the software on the upgrade page.

For any other question, please contact the Flectra support at

""" class PosboxHomepage(flectra.addons.web.controllers.main.Home): def get_hw_screen_message(self): return """

The activate the customer display feature, you will need to reinstall the PosBox software. You can find the latest images on the Flectra Nightly builds website. Make sure to download at least the version 16.
Flectra version 11, or above, is required to use the customer display feature.

""" @http.route('/', type='http', auth='none', website=True) def index(self): #return request.render('hw_posbox_homepage.index',mimetype='text/html') return index_template % self.get_hw_screen_message() @http.route('/wifi', type='http', auth='none', website=True) def wifi(self): wifi_template = """ Wifi configuration """ + index_style + """

Configure wifi

Here you can configure how the posbox should connect to wireless networks. Currently only Open and WPA networks are supported. When enabling the persistent checkbox, the chosen network will be saved and the posbox will attempt to connect to it every time it boots.

ESSID:
Password:
Persistent:

You can clear the persistent configuration by clicking below:

""" return wifi_template @http.route('/wifi_connect', type='http', auth='none', cors='*') def connect_to_wifi(self, essid, password, persistent=False): if persistent: persistent = "1" else: persistent = "" subprocess.call(['/home/pi/flectra/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh', essid, password, persistent]) return "connecting to " + essid @http.route('/wifi_clear', type='http', auth='none', cors='*') def clear_wifi_configuration(self): os.system('/home/pi/flectra/addons/point_of_sale/tools/posbox/configuration/clear_wifi_configuration.sh') return "configuration cleared" @http.route('/remote_connect', type='http', auth='none', cors='*') def remote_connect(self): ngrok_template = """ Remote debugging """ + index_style + """

Remote debugging

This allows someone to gain remote access to your Posbox, and thus your entire local network. Only enable this for someone you trust.


Enable remote debugging
""" 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'