diff options
author | Jogi Hofmüller <jogi@mur.at> | 2011-07-29 13:29:00 +0000 |
---|---|---|
committer | Jogi Hofmüller <jogi@mur.at> | 2011-07-29 13:29:00 +0000 |
commit | 82f837989f1c2d9995db2311b36d1e94c66f70cc (patch) | |
tree | cad6296eb7fa328b129d4c807bf6100edc7365d5 | |
parent | moved software tests to tools (diff) |
initial revision
git-svn-id: https://svn.spreadspace.org/mur.sat@71 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r-- | tools/mmd/MmdCommands.py | 66 | ||||
-rw-r--r-- | tools/mmd/MmdWidgets.py | 162 | ||||
-rw-r--r-- | tools/mmd/mmd.wsgi | 59 |
3 files changed, 287 insertions, 0 deletions
diff --git a/tools/mmd/MmdCommands.py b/tools/mmd/MmdCommands.py new file mode 100644 index 0000000..1af9422 --- /dev/null +++ b/tools/mmd/MmdCommands.py @@ -0,0 +1,66 @@ +""" +command methods for MURSAT1 Dashboard +""" + +from cgi import parse_qs, escape +from MmdWidgets import * + +def loginForm (data): + """ + display the login form + """ + return indexWidget (dataWidget (), loginFormWidget (), statusWidget (data['ip'])) + +def login (data): + """ + evaluate data from loginForm + """ + email = escape (data['qs'].get ('email', [''])[0]) + # check for account + # verify password + return indexWidget (dataWidget (), loginWidget (email), statusWidget (data['ip'], data['user'])) + +def registerForm (data): + """ + display the register form + """ + return indexWidget (dataWidget (), registerFormWidget (), statusWidget (data['ip'])) + +def register (data): + """ + evaluate data from registerForm + """ + return indexWidget (dataWidget (), loginWidget (), statusWidget (data['ip'])) + +def submitForm (data): + """ + display the form for data submission + """ + return indexWidget (dataWidget (), submitFormWidget (), statusWidget (data['ip'], data['user'])) + +def submit (data): + """ + evaluate data from submitForm + """ + return indexWidget (dataWidget (), submitWidget (), statusWidget (data['ip'])) + +def viewlog (data): + """ + show latest log entries/submissions + """ + return indexWidget (dataWidget (), logWidget (), statusWidget (data['ip'], data['user'])) + +def index (data): + """ + display the index page + """ + return indexWidget (dataWidget (), osmWidget (), statusWidget (data['ip'], data['user'])) + +def msdbtest (env): + body = '' + for key, value in sorted (env.items()): + body = '{0}{1}: {2}\n'.format (body, key, value) + return body + +# vim: tw=0 ts=2 expandtab +# EOF diff --git a/tools/mmd/MmdWidgets.py b/tools/mmd/MmdWidgets.py new file mode 100644 index 0000000..737b554 --- /dev/null +++ b/tools/mmd/MmdWidgets.py @@ -0,0 +1,162 @@ +""" +web templates for MURSAT1 Dashboard +""" + +import time + +def loginFormWidget (): + html = ''' + Please enter your email/callsign and your password in the form below. + <form method="post"> + <table> + <tr><td class="formfield">Email:</td><td><input type="text" name="email" /></td></tr> + <tr><td class="formfield">Password:</td><td><input type="password" name="password" /></td></tr> + <tr><td class="formfield"><input type="submit" value="Login" /></td><td></td></tr> + </table> + <input type="hidden" name="cmd" value="login" /> + </form> + Don't have an account yet? <a href="?cmd=registerForm">Register</a> here! + ''' + + return html + +def loginWidget (email): + html = ''' + login request for {0} + '''.format (email) + + return html + +def registerFormWidget (): + html = ''' + Please fill in the form below an click on Register. You will receive a confirmation email. + <form method="post"> + <table> + <tr><td class="formfield">Firstname*:</td><td><input type="text" name="firstname" /></td></tr> + <tr><td class="formfield">Lastname*: </td><td><input type="text" name="lastname" /></td></tr> + <tr><td class="formfield">Email*: </td><td><input type="text" name="email" /></td></tr> + <tr><td class="formfield">Callsign: </td><td><input type="text" name="callsign" /></td></tr> + <tr><td class="formfield">Longitude: </td><td><input type="text" name="latitude" /></td></tr> + <tr><td class="formfield">Latitude: </td><td><input type="text" name="longitude" /></td></tr> + <tr><td class="formfield">Password*: </td><td><input type="password" name="password" /></td></tr> + <tr><td class="formfield">Confirm Password*: </td><td><input type="password" name="confirm" /></td></tr> + <tr><td class="formfield"><input type="submit" value="Register" /></td><td></td></tr> + </table> + <input type="hidden" name="cmd" value="login" /> + </form> + Fields marked with a * are mandatory. + ''' + + return html + +def registerWidget (): + html = ''' + need processing of data + ''' + + return html + +def submitFormWidget (): + html = ''' + sorry, no form yet! + ''' + + return html + +def submitWidget (): + html = ''' + need processing of data + ''' + + return html + +def logWidget (): + html = ''' + Log data, lot's of log data ... + ''' + + return html + +def osmWidget (longitude = 15.4426, latitude = 47.06576): + html = ''' + <div id="osm"></div> + <script src="http://www.openlayers.org/api/OpenLayers.js"></script> + <script> + var from = new OpenLayers.Projection ("EPSG:4326"); + var to = new OpenLayers.Projection ("EPSG:900913"); + var lonlat = new OpenLayers.LonLat ({0}, {1}).transform (from, to); + + // create a map + map = new OpenLayers.Map ("osm"); + map.addLayer (new OpenLayers.Layer.OSM ()); + + // set a marker + var markers = new OpenLayers.Layer.Markers ("Markers"); + map.addLayer (markers); + markers.addMarker (new OpenLayers.Marker (lonlat)); + + // center the map + map.setCenter (lonlat, 2); + </script> + '''.format (longitude, latitude) + + return html + +def statusWidget (ip, user = 'Anonymous'): + html = ''' + <img src="http://sat.mur.at/pics/sat-logo-notext.png" alt="mur.sat logo" /> MURSAT1 Mission Dashboard + <div id="info"> + Hello {0} from {1}! Local time is {2} + </div> + '''.format (user, ip, time.strftime ('%c')) + + return html + +def indexWidget (lcol, rcol, status = statusWidget (None)): + html = ''' +<!Doctype html> +<html> + <head> + <title>MURSAT1 Dashboard</title> + <meta charset="utf-8" /> + <link rel="stylesheet" type="text/css" href="http://sat.mur.at/css/dashboard.css" /> + </head> + <body> + <div id="status"> + {0} + </div> + <div id="lcol"> + {1} + </div> + <div id="rcol"> + {2} + </div> + <div id="dev"> + Development version! + </div> + </body> +</html> + '''.format (status, lcol, rcol) + + return html + +def dataWidget (longitude = 15.44226, latitude = 47.06576): + html = ''' + <div id="datahead"> + Current Data + </div> + <div>Time: 00 D 00 H 00 M 00 S</div> + <div>Longitude: {0}</div> + <div>Latitude: {1}</div> + <hr /> + <div><a href="?cmd=submitForm">Submit</a> a report</div> + <div><a href="?cmd=loginForm">Login</a> to your personal account</div> + <div>View <a href="?cmd=viewlog">Log</a> of reports</div> + <hr /> + <div>Checkout the <a href="http://sat.mur.at/">project page</a>!</div> + '''.format (longitude, latitude) + + return html + +# vim: ft=html tw=0 ts=2 expandtab +# EOF diff --git a/tools/mmd/mmd.wsgi b/tools/mmd/mmd.wsgi new file mode 100644 index 0000000..a1c780b --- /dev/null +++ b/tools/mmd/mmd.wsgi @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +Check http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide +for server configuration guidelines +""" + +import sys +sys.path.append ('/var/www/hofos.at/mmd/') +from cgi import parse_qs, escape +from MmdCommands import * + +def application (environ, response): + """ + beginning of WSGI/python application for + MURSAT1 Dashboard + """ + + # dict data to be passed to command methods + data = {} + + try: + data['qs'] = parse_qs (environ['wsgi.input'].read (int (environ['CONTENT_LENGTH']))) + except KeyError: + data['qs'] = parse_qs (environ['QUERY_STRING']) + + data['ip'] = environ['REMOTE_ADDR'] + data['user'] = 'Anonymous' + cmd = data['qs'].get ('cmd', [''])[0] + cmd = escape (cmd) + + # always return 200 OK + status = '200 OK' + + if cmd == 'loginForm': + body = loginForm (data) + elif cmd == 'login': + body = login (data) + elif cmd == 'registerForm': + body = registerForm (data) + elif cmd == 'register': + body = register (data) + elif cmd == 'submitForm': + body = submitForm (data) + elif cmd == 'submit': + body = submit (data) + elif cmd == 'viewlog': + body = viewlog (data) + elif cmd == 'msdbtest': + body = msdbtest (environ) + else: + body = index (data) + + headers = [('Content-Type', 'text/html'), ('Content-Length', str (len (body)))] + response (status, headers) + return [body] + +# vim: tw=0 ts=2 expandtab +# EOF |