mirror of
https://github.com/Screenly/Anthias.git
synced 2026-03-06 15:57:00 -05:00
Merge pull request #812 from GreatFruitOmsk/Service-for-wifi-connect
Service for wifi-connect
This commit is contained in:
17
ansible/roles/network/files/wifi-connect.service
Normal file
17
ansible/roles/network/files/wifi-connect.service
Normal file
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Wifi Connect
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/home/pi/screenly
|
||||
User=pi
|
||||
Type=oneshot
|
||||
|
||||
ConditionPathExists=!/home/pi/.screenly/initialized
|
||||
|
||||
ExecStart=/usr/bin/python /home/pi/screenly/start_resin_wifi.py
|
||||
ExecStartPost=/usr/bin/touch /home/pi/.screenly/initialized
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -96,3 +96,11 @@
|
||||
- ui
|
||||
- resin-wifi-connect.tar.gz
|
||||
when: ansible_distribution_major_version|int >= 9 and not resin_wifi_version_file_exist
|
||||
|
||||
- name: Copy wifi-connect systemd unit
|
||||
copy:
|
||||
src: "wifi-connect.service"
|
||||
dest: "/etc/systemd/system/wifi-connect.service"
|
||||
|
||||
- name: Enable wifi-connect systemd service
|
||||
command: systemctl enable wifi-connect.service chdir=/etc/systemd/system
|
||||
|
||||
@@ -1 +1 @@
|
||||
resin_wifi_connect_version: 4.0.3
|
||||
resin_wifi_connect_version: 4.1.1
|
||||
|
||||
@@ -2,15 +2,39 @@ upstream ose {
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
|
||||
upstream wifi-connect {
|
||||
server 192.168.42.1:9090;
|
||||
}
|
||||
|
||||
server {
|
||||
server_tokens off;
|
||||
listen 80 default_server;
|
||||
|
||||
location / {
|
||||
if (-f /home/pi/.screenly/initialized) {
|
||||
proxy_pass http://ose;
|
||||
}
|
||||
if (!-f /home/pi/.screenly/initialized) {
|
||||
proxy_pass http://wifi-connect;
|
||||
}
|
||||
|
||||
client_max_body_size 4G;
|
||||
proxy_pass http://ose;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
}
|
||||
|
||||
location /static {
|
||||
proxy_pass http://ose/static;
|
||||
}
|
||||
|
||||
location /hotspot {
|
||||
allow 127.0.0.1;
|
||||
deny all;
|
||||
|
||||
if (!-f /home/pi/.screenly/initialized) {
|
||||
root /tmp;
|
||||
rewrite ^ /hotspot.html break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
mode: 644
|
||||
owner: root
|
||||
group: root
|
||||
force: no
|
||||
|
||||
- name: Modifies screenly-web service to only listen on localhost
|
||||
lineinfile:
|
||||
@@ -32,40 +31,3 @@
|
||||
state: absent
|
||||
dest: /etc/systemd/system/screenly-web.service
|
||||
when: no_ssl
|
||||
|
||||
# Disable Nginx
|
||||
- name: Remove Nginx
|
||||
apt:
|
||||
name: nginx-light
|
||||
state: absent
|
||||
update_cache: yes
|
||||
tags:
|
||||
- disable-nginx
|
||||
|
||||
- name: Remove nginx config
|
||||
file:
|
||||
path: /etc/nginx/sites-enabled/screenly.conf
|
||||
state: absent
|
||||
tags:
|
||||
- disable-nginx
|
||||
|
||||
- name: Turns off the ssl mode
|
||||
replace:
|
||||
replace: 'use_ssl = False'
|
||||
regexp: '^.*use_ssl.*'
|
||||
dest: /home/pi/.screenly/screenly.conf
|
||||
tags:
|
||||
- disable-nginx
|
||||
|
||||
- name: Modifies screenly-web service to listen on default gateway
|
||||
lineinfile:
|
||||
insertafter: '^\[Service\]'
|
||||
regexp: '^\[Service\]*;'
|
||||
line: Environment=LISTEN=0.0.0.0
|
||||
dest: /etc/systemd/system/screenly-web.service
|
||||
notify:
|
||||
- reload systemctl
|
||||
- restart-screenly-websocket_server_layer
|
||||
- restart-screenly-server
|
||||
tags:
|
||||
- disable-nginx
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
cd ~/screenly/ansible
|
||||
ansible-playbook -t disable-nginx site.yml
|
||||
|
||||
set +x
|
||||
echo "You should be all set. You should be able to access Screenly's management interface at http://<your IP>:<port>"
|
||||
@@ -44,9 +44,9 @@ fi
|
||||
|
||||
echo && read -p "Would you like to perform a full system upgrade as well? (y/N)" -n 1 -r -s UPGRADE && echo
|
||||
if [ "$UPGRADE" != 'y' ]; then
|
||||
EXTRA_ARGS="--skip-tags enable-ssl,disable-nginx,system-upgrade"
|
||||
EXTRA_ARGS="--skip-tags enable-ssl,system-upgrade"
|
||||
else
|
||||
EXTRA_ARGS="--skip-tags enable-ssl,disable-nginx"
|
||||
EXTRA_ARGS="--skip-tags enable-ssl"
|
||||
fi
|
||||
|
||||
set -x
|
||||
|
||||
37
server.py
37
server.py
@@ -640,6 +640,26 @@ class Recover(Resource):
|
||||
return "Recovery successful."
|
||||
|
||||
|
||||
class ResetWifiConfig(Resource):
|
||||
method_decorators = [api_response, auth_basic]
|
||||
|
||||
@swagger.doc({
|
||||
'responses': {
|
||||
'204': {
|
||||
'description': 'Deleted'
|
||||
}
|
||||
}
|
||||
})
|
||||
def get(self):
|
||||
home = getenv('HOME')
|
||||
file_path = path.join(home, '.screenly/initialized')
|
||||
|
||||
if path.isfile(file_path):
|
||||
remove(file_path)
|
||||
|
||||
return '', 204
|
||||
|
||||
|
||||
class Info(Resource):
|
||||
method_decorators = [api_response, auth_basic]
|
||||
|
||||
@@ -703,6 +723,7 @@ api.add_resource(Backup, '/api/v1/backup')
|
||||
api.add_resource(Recover, '/api/v1/recover')
|
||||
api.add_resource(AssetsControl, '/api/v1/assets/control/<command>')
|
||||
api.add_resource(Info, '/api/v1/info')
|
||||
api.add_resource(ResetWifiConfig, '/api/v1/reset_wifi')
|
||||
|
||||
try:
|
||||
my_ip = get_node_ip()
|
||||
@@ -844,22 +865,6 @@ def splash_page():
|
||||
return template('splash_page.html', ip_lookup=ip_lookup, msg=msg)
|
||||
|
||||
|
||||
@app.route('/hotspot')
|
||||
def hotspot_page():
|
||||
if LISTEN == '127.0.0.1':
|
||||
sh.sudo('nginx', '-s', 'stop')
|
||||
|
||||
ssid = "ScreenlyOSE-{}".format(pwgen(4, symbols=False))
|
||||
ssid_password = pwgen(8, symbols=False)
|
||||
|
||||
wifi_connect = sh.sudo('wifi-connect', '-s', ssid, '-p', ssid_password, _bg=True, _err_to_out=True)
|
||||
|
||||
while 'Starting HTTP server' not in wifi_connect.process.stdout:
|
||||
sleep(1)
|
||||
|
||||
return template('hotspot.html', network=ssid, ssid_pswd=ssid_password, address='screenly.io/wifi')
|
||||
|
||||
|
||||
@app.errorhandler(403)
|
||||
def mistake403(code):
|
||||
return 'The parameter you passed has the wrong format!'
|
||||
|
||||
@@ -31,8 +31,7 @@ DEFAULTS = {
|
||||
'default_duration': '10',
|
||||
'default_streaming_duration': '300',
|
||||
'debug_logging': False,
|
||||
'verify_ssl': True,
|
||||
'enable_offline_mode': False
|
||||
'verify_ssl': True
|
||||
},
|
||||
'auth': {
|
||||
'user': '',
|
||||
|
||||
34
start_resin_wifi.py
Normal file
34
start_resin_wifi.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from jinja2 import Template
|
||||
from netifaces import gateways
|
||||
from os import getenv, path
|
||||
from pwgen import pwgen
|
||||
import sh
|
||||
|
||||
|
||||
def generate_page(ssid, pswd, address):
|
||||
home = getenv('HOME')
|
||||
template_path = path.join(home, 'screenly/templates/hotspot.html')
|
||||
with open(template_path) as f:
|
||||
template = Template(f.read())
|
||||
|
||||
context = {
|
||||
'network': ssid,
|
||||
'ssid_pswd': pswd,
|
||||
'address': address
|
||||
}
|
||||
|
||||
with open('/tmp/hotspot.html', 'w') as out_file:
|
||||
out_file.write(template.render(context=context))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not gateways().get('default'):
|
||||
ssid = 'ScreenlyOSE-{}'.format(pwgen(4, symbols=False))
|
||||
ssid_password = pwgen(8, symbols=False)
|
||||
generate_page(ssid, ssid_password, 'screenly.io/wifi')
|
||||
|
||||
wifi_connect = sh.sudo('wifi-connect', '-s', ssid, '-p', ssid_password, '-o', '9090')
|
||||
else:
|
||||
pass
|
||||
@@ -64,3 +64,11 @@ $().ready ->
|
||||
$('.progress').hide()
|
||||
$('#btn-upload').show()
|
||||
$('#btn-backup').show()
|
||||
|
||||
$('#btn-reset').click (e) ->
|
||||
$.get '/api/v1/reset_wifi'
|
||||
.done (e) ->
|
||||
$('#request-error .alert').show()
|
||||
$('#request-error .alert').addClass 'alert-success'
|
||||
$('#request-error .alert').removeClass 'alert-error'
|
||||
($ '#request-error .msg').text 'Reset was successful. Please reboot the device.'
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.12.6
|
||||
// Generated by CoffeeScript 2.2.4
|
||||
(function() {
|
||||
$().ready(function() {
|
||||
$('#request-error .close').click(function(e) {
|
||||
@@ -34,7 +34,7 @@
|
||||
e.preventDefault();
|
||||
return $('[name="backup_upload"]').click();
|
||||
});
|
||||
return $('[name="backup_upload"]').fileupload({
|
||||
$('[name="backup_upload"]').fileupload({
|
||||
url: "api/v1/recover",
|
||||
progressall: function(e, data) {
|
||||
var valuenow;
|
||||
@@ -76,6 +76,14 @@
|
||||
return $('#btn-backup').show();
|
||||
}
|
||||
});
|
||||
return $('#btn-reset').click(function(e) {
|
||||
return $.get('/api/v1/reset_wifi').done(function(e) {
|
||||
$('#request-error .alert').show();
|
||||
$('#request-error .alert').addClass('alert-success');
|
||||
$('#request-error .alert').removeClass('alert-error');
|
||||
return ($('#request-error .msg')).text('Reset was successful. Please reboot the device.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
@@ -17,7 +17,7 @@
|
||||
<script src="/static/js/jquery-ui-1.10.1.custom.min.js"></script>
|
||||
<script src="/static/js/jquery.fileupload.js"></script> <!-- needs jqueryui.widget -->
|
||||
|
||||
<script src="/static/js/backup.js"></script>
|
||||
<script src="/static/js/settings.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -119,24 +119,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">Enable offline mode</label>
|
||||
<div class="controls">
|
||||
<label id="enable_offline_mode" class="checkbox toggle well">
|
||||
{% if context.enable_offline_mode %}
|
||||
<input name="enable_offline_mode" checked="checked" type="checkbox" />
|
||||
{% else %}
|
||||
<input name="enable_offline_mode" type="checkbox" />
|
||||
{% endif %}
|
||||
<p>
|
||||
<span class="on">On</span>
|
||||
<span class="off">Off</span>
|
||||
</p>
|
||||
<a class="btn btn-primary slide-button"></a>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">Audio output</label>
|
||||
<div class="controls">
|
||||
@@ -209,15 +191,27 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="wifi-section" class="span12">
|
||||
<h1 class="page-header">
|
||||
Reset wifi config
|
||||
</h1>
|
||||
<p>Run it, and if the next boot does not have a network connection, you will be prompted to select a WiFi network. <br><b>Warning:</b> after pressing, a reboot is required. Web interface will not be available until reboot.</p>
|
||||
<div class="form-actions">
|
||||
<button id="btn-reset" class="btn btn-primary" type="button">Re-run network detection</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="backup-section" class="span12">
|
||||
<h1 class="page-header">
|
||||
Backup
|
||||
</h1>
|
||||
<input name="backup_upload" style="display:none" type="file">
|
||||
<button id="btn-upload" class="btn btn-primary" type="button">Upload and Recover</button>
|
||||
<button id="btn-backup" class="btn">Get backup</button>
|
||||
<div class="progress progress-striped active" style="display:none">
|
||||
<div class="bar"></div>
|
||||
<div class="form-actions">
|
||||
<input name="backup_upload" style="display:none" type="file">
|
||||
<button id="btn-upload" class="btn btn-primary" type="button">Upload and Recover</button>
|
||||
<button id="btn-backup" class="btn">Get backup</button>
|
||||
<div class="progress progress-striped active" style="display:none">
|
||||
<div class="bar"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
11
viewer.py
11
viewer.py
@@ -34,6 +34,7 @@ __license__ = "Dual License: GPLv2 and Commercial License"
|
||||
SPLASH_DELAY = 60 # secs
|
||||
EMPTY_PL_DELAY = 5 # secs
|
||||
|
||||
INITIALIZED_FILE = '/.screenly/initialized'
|
||||
BLACK_PAGE = '/tmp/screenly_html/black_page.html'
|
||||
WATCHDOG_PATH = '/tmp/screenly.watchdog'
|
||||
SCREENLY_HTML = '/tmp/screenly_html/'
|
||||
@@ -426,14 +427,12 @@ def setup():
|
||||
def main():
|
||||
setup()
|
||||
|
||||
if not gateways().get('default') and not settings['enable_offline_mode']:
|
||||
url = 'http://{0}:{1}/hotspot'.format(LISTEN, PORT)
|
||||
if not path.isfile(HOME + INITIALIZED_FILE) and not gateways().get('default'):
|
||||
url = 'http://{0}/hotspot'.format(LISTEN)
|
||||
load_browser(url=url)
|
||||
|
||||
while not gateways().get('default'):
|
||||
sleep(2)
|
||||
if LISTEN == '127.0.0.1':
|
||||
sh.sudo('nginx')
|
||||
while not path.isfile(HOME + INITIALIZED_FILE):
|
||||
sleep(1)
|
||||
|
||||
url = 'http://{0}:{1}/splash_page'.format(LISTEN, PORT) if settings['show_splash'] else 'file://' + BLACK_PAGE
|
||||
browser_url(url=url)
|
||||
|
||||
Reference in New Issue
Block a user