diverse Anpassungen

This commit is contained in:
2017-11-09 17:10:57 +01:00
parent e3e1387117
commit 4610ba3792
7 changed files with 386 additions and 7 deletions
+2
View File
@@ -2,5 +2,7 @@
systemctl stop gammu-smsd
pon rnet
sleep 3
# Nameserver statisch eintragen...
echo "nameserver 8.8.8.8" >/etc/resolv.conf
# Wir wollen sicher sein, dass die Verbindung steht...
ping -c 1 -w 30 8.8.8.8 >/dev/null
+65 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/python
from bottle import Bottle, run, template, static_file, error, redirect
from bottle import Bottle, run, template, static_file, error, redirect, post, request
import yaml
import glob
import re
@@ -8,6 +8,7 @@ import random
import string
import os
import shutil
import subprocess
app = Bottle()
@@ -88,6 +89,39 @@ def CreateDatafile(scale_uuid,infotime):
for line in ifile:
file.write(line)
def GetInfoText():
with open('%s/bin/beielimon-config.yaml' % (APP_ROOT), 'r') as f:
config_file_lines = f.read()
# Wir maskieren das Passwort
config_file_lines = re.sub(r"mailpwd:.*\n", "mailpwd: MASKED\n", config_file_lines)
commands_output = ""
for comm_arr in [ ['uptime','--pretty'],
['df','-h','/boot','/root'],
['free','-m'],
['ip','a'] ]:
commands_output = "%s\n# %s\n%s" % (commands_output,' '.join(comm_arr),subprocess.check_output(comm_arr))
res = """Konfigurationsfile:<br />
<pre>%s</pre>
Diverse Befehle: <pre>%s</pre>
""" % (config_file_lines, commands_output)
return res
def is_valid_yaml(yaml_string):
res = True
try:
data_parsed = yaml.safe_load(yaml_string)
except yaml.YAMLError:
res = False
return res
@app.route('/')
def index():
@@ -95,11 +129,40 @@ def index():
data = {
'scales': hash_scales,
'infotime': time.strftime("%Y", time.localtime()),
'beielipi_mobile_number': config_data['beielipi_mobile_number']
'beielipi_mobile_number': config_data['beielipi_mobile_number'],
'infotext': GetInfoText()
}
return template('%s/web-root/index.tpl' % (APP_ROOT), data)
@app.get('/upload_config')
def upload_config():
my_message = request.GET.get('message', '').strip()
my_level = request.GET.get('level', '').strip()
data = {
'message': my_message,
'level': my_level
}
return template('%s/web-root/upload_config.tpl' % (APP_ROOT), data)
@app.post('/upload_config')
def do_upload_config():
config_yaml = request.forms.get('config_yaml')
if is_valid_yaml(config_yaml):
# Wir machen noch ein Backup vor dem Ueberschreiben
date_format_string = "+%Y%m%d-%H%M%S"
os.system('cp %s/bin/beielimon-config.yaml %s/config-backups/beielimon-config.yaml.$(date %s)' % (APP_ROOT,APP_ROOT,date_format_string))
with open('%s/bin/beielimon-config.yaml' % (APP_ROOT), 'w') as file:
file.write(string.replace(config_yaml,'\r',''))
redirect("/upload_config?message=Konfiguration%20erfolgreich%20ersetzt.%20Bitte%20BeieliPi%20rebooten%20mit%20http%3A%2F%2Fbeielipi.local%2Freboot_beielipi&level=success")
else:
redirect("/upload_config?message=Fehler%20mit%20YAML-Syntax&level=danger")
@app.route('/reboot_beielipi')
def reboot_beielipi():
os.system('/sbin/init 6')
@app.route('/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='%s/web-root/static' % (APP_ROOT))