aboutsummaryrefslogtreecommitdiffstats
path: root/torouterui
diff options
context:
space:
mode:
authorficus <ficus@robocracy.org>2012-11-24 02:46:55 +0100
committerficus <ficus@robocracy.org>2012-11-24 02:47:58 +0100
commitf31914f3e22b4982fcccd1634a8bb49dca0c155c (patch)
tree79f7f612bc78dabe9fb2b7c34d74612de5e8f78c /torouterui
parentc139513eeb2f6bf159b58770f26ec75d9dc021bf (diff)
downloadtui-f31914f3e22b4982fcccd1634a8bb49dca0c155c.tar.gz
tui-f31914f3e22b4982fcccd1634a8bb49dca0c155c.zip
fix logs 500 error (due to string encoding)
Diffstat (limited to 'torouterui')
-rw-r--r--torouterui/sysstatus.py25
-rw-r--r--torouterui/views.py6
2 files changed, 9 insertions, 22 deletions
diff --git a/torouterui/sysstatus.py b/torouterui/sysstatus.py
index efab9de..cc3af87 100644
--- a/torouterui/sysstatus.py
+++ b/torouterui/sysstatus.py
@@ -4,6 +4,7 @@ in system log files.
"""
import os
+import codecs
from util import *
@@ -58,30 +59,16 @@ def get_resources_status():
def get_dmesg():
try:
- return cli_read('dmesg')
+ return cli_read('dmesg').decode('utf-8')
except IOError:
- return "Couldn't read dmesg"
+ return None
-def get_authlog():
+def get_log(fname):
try:
- with open('/var/log/auth.log') as f:
+ with codecs.open(fname, 'r', 'utf-8') as f:
return ''.join(f.readlines())
except IOError:
- return "Couldn't read /var/log/auth.log"
-
-def get_syslog():
- try:
- with open('/var/log/syslog') as f:
- return ''.join(f.readlines())
- except IOError:
- return "Couldn't read /var/log/syslog"
-
-def get_torlog():
- try:
- with open('/var/log/tor/notices.log') as f:
- return ''.join(f.readlines())
- except IOError:
- return "Couldn't read /var/log/tor/notices.log"
+ return None
def get_process_list():
"""
diff --git a/torouterui/views.py b/torouterui/views.py
index 418c391..f52a89b 100644
--- a/torouterui/views.py
+++ b/torouterui/views.py
@@ -232,9 +232,9 @@ def torpage():
def logspage():
logs = dict()
logs['dmesg'] = sysstatus.get_dmesg()
- logs['syslog'] = sysstatus.get_syslog()
- logs['authlog'] = sysstatus.get_authlog()
- logs['tor'] = sysstatus.get_torlog()
+ logs['syslog'] = sysstatus.get_log("/var/log/syslog")
+ logs['authlog'] = sysstatus.get_log("/var/log/auth.log")
+ logs['tor'] = sysstatus.get_log("/var/log/tor/notices.log")
return render_template('logs.html', logs=logs)
@app.route('/processes/', methods=['GET'])