You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/27 23:14:28 UTC

svn commit: r1669695 - in /steve/trunk/pysteve: GETTING_STARTED.txt standalone.py

Author: humbedooh
Date: Fri Mar 27 22:14:28 2015
New Revision: 1669695

URL: http://svn.apache.org/r1669695
Log:
Add a very quick guide and a standalone http server for testing purposes.

Added:
    steve/trunk/pysteve/GETTING_STARTED.txt
    steve/trunk/pysteve/standalone.py   (with props)

Added: steve/trunk/pysteve/GETTING_STARTED.txt
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/GETTING_STARTED.txt?rev=1669695&view=auto
==============================================================================
--- steve/trunk/pysteve/GETTING_STARTED.txt (added)
+++ steve/trunk/pysteve/GETTING_STARTED.txt Fri Mar 27 22:14:28 2015
@@ -0,0 +1,11 @@
+Very Quick Start Guide:
+
+-    svn co https://svn.apache.org/repos/asf/steve/trunk/pysteve/
+-    Edit steve.cfg to suit your needs (karma, DB backend etc)
+	-    IF you choose ElasticSearch as backend, install the python module (pip install elasticsearch)
+	-    OR IF you choose files as your backend, run setup.py in the CLI directory.
+- EITHER:   Edit httpd.conf, add it to your existing httpd configuration
+	-    Set up authorization using htpasswd for admins, monitors etc
+- OR: run python standalone.py (remember to edit auth karma inside it)
+-    Go to http://steve.yourdomain.foo/admin and set up an election
+-    Start voting!

Added: steve/trunk/pysteve/standalone.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/standalone.py?rev=1669695&view=auto
==============================================================================
--- steve/trunk/pysteve/standalone.py (added)
+++ steve/trunk/pysteve/standalone.py Fri Mar 27 22:14:28 2015
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+""" Buggy standalone server for testing out pySTeVe """
+
+portno = 8080
+
+import BaseHTTPServer
+import CGIHTTPServer
+from SocketServer import ThreadingMixIn
+import cgitb
+import base64
+import os
+import sys, traceback
+
+cgitb.enable()
+server = BaseHTTPServer.HTTPServer
+
+handler = CGIHTTPServer.CGIHTTPRequestHandler
+server_address = ("", portno)
+handler.cgi_directories = ["/www/cgi-bin"]
+handler.cgi_info = {}
+
+path = os.path.abspath(os.getcwd())
+
+
+# EDIT THIS OR SOME SUCH!!!!
+karma = {
+    'admin': 'demo'
+}
+
+def doTraceBack():
+    exc_type, exc_value, exc_traceback = sys.exc_info()
+    traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
+    traceback.print_exception(exc_type, exc_value, exc_traceback,
+                              limit=2, file=sys.stdout)
+    traceback.print_exc()
+    
+ 
+class pysteveHTTPHandler(handler):
+    
+    cgi_directories = ["/www/cgi-bin"]
+    
+    def do_AUTHHEAD(self):
+        print "send header"
+        self.send_response(401)
+        self.send_header('WWW-Authenticate', 'Basic realm=\"STeVe Administration\"')
+        self.send_header('Content-type', 'text/html')
+        self.end_headers()
+        
+        
+    def do_GET(self):
+        try:
+            print(self.path)
+            if self.path.startswith("/steve/admin"):
+                if self.headers.getheader('Authorization') == None:
+                    self.do_AUTHHEAD()
+                    self.wfile.write('no auth header received')
+                    return
+                else:
+                    authed = False
+                    auth = self.headers.getheader('Authorization').strip("Basic ")
+                    arr = base64.decodestring(auth).split(":", 2)
+                    if len(arr) == 2:
+                        name = arr[0]
+                        password= arr[1]
+                        if karma.get(name) and karma[name] == password:
+                            authed = True
+                    if not authed:
+                        self.do_AUTHHEAD()
+                        self.wfile.write('Wrong user or pass received')
+                        return
+                path_info = self.path.replace("/steve/admin", "", 1)
+                os.chdir(path + "/www/cgi-bin")
+                self.cgi_info = ("/", "rest_admin.py" + path_info)
+                self.run_cgi()
+                return
+            elif self.path.startswith("/steve/voter"):
+                path_info = self.path.replace("/steve/voter", "", 1)
+                os.chdir(path + "/www/cgi-bin")
+                self.cgi_info = ("/", "rest_voter.py" + path_info)
+                self.run_cgi()
+                return
+            else:
+                os.chdir(path)
+                self.path = self.path = "/www/html" + self.path
+            print(self.path)
+            handler.do_GET(self)
+            
+        except Exception as err:
+            doTraceBack()
+       
+    def do_POST(self):
+        self.do_GET() #Same diff, eh...
+        
+class ThreadedHTTPServer(ThreadingMixIn, server):
+    """Moomins live here"""
+    
+
+if __name__ == '__main__':
+    server = ThreadedHTTPServer(('', portno), pysteveHTTPHandler)
+    print("Running at http://youriphere:%u/ ..." % portno)
+    server.serve_forever()
\ No newline at end of file

Propchange: steve/trunk/pysteve/standalone.py
------------------------------------------------------------------------------
    svn:executable = *