Permalink
Browse files

Added Authentication and updated status xml format

  • Loading branch information...
1 parent 376bb06 commit 9692593f5ef8f36a24bff511341236b93db8be62 unknown committed May 31, 2012
Showing with 62 additions and 7 deletions.
  1. +2 −1 README.md
  2. +3 −0 auth.config
  3. +0 −3 http.config
  4. +57 −3 webinterface.py
View
@@ -13,7 +13,8 @@ command prompt there and running python setup.py install. You can also download
## Webinterface Configuration
* The Web interface port / ip is configurable in http.config
-
+ * The Default User / Password can be set in auth.config
+
## Webinterface Styling
* css/style.css can be modified to change the style of the Web Interface.
View
@@ -0,0 +1,3 @@
+[user]
+user = admin
+pass = password
View
@@ -2,6 +2,3 @@
server.socket_host: "localhost"
server.socket_port: 8080
-[/css/style.css]
-tools.staticfile.on = True
-tools.staticfile.filename = "C:\Printrun-web\Printrun\css\style.css"
View
@@ -1,7 +1,9 @@
#!/usr/bin/python
-import cherrypy, pronterface, re
+import cherrypy, pronterface, re, ConfigParser, io
import os.path
+users = {}
+
def PrintHeader():
return '<html>\n<head>\n<title>Pronterface-Web</title>\n<link rel="stylesheet" type="text/css" href="/css/style.css" type="text/css"></link>\n</head>\n<body>\n'
@@ -14,6 +16,9 @@ def PrintFooter():
def ReloadPage(action):
return "<html><head><meta http-equiv='refresh' content='0;url=/'></head><body>"+action+"</body></html>"
+def clear_text(mypass):
+ return mypass
+
gPronterPtr = 0
gWeblog = ""
gLogRefresh =5
@@ -65,44 +70,93 @@ def index(self):
gPronterPtr.connect(0)
return ReloadPage("Connect...")
index.exposed = True
-
+ index._cp_config = {'tools.basic_auth.on': True,
+ 'tools.basic_auth.realm': 'My Print Server',
+ 'tools.basic_auth.users': users,
+ 'tools.basic_auth.encrypt': clear_text}
+
class DisconnectButton(object):
def index(self):
#handle connect push, then reload page
gPronterPtr.disconnect(0)
return ReloadPage("Disconnect...")
index.exposed = True
+ index._cp_config = {'tools.basic_auth.on': True,
+ 'tools.basic_auth.realm': 'My Print Server',
+ 'tools.basic_auth.users': users,
+ 'tools.basic_auth.encrypt': clear_text}
class ResetButton(object):
def index(self):
#handle connect push, then reload page
gPronterPtr.reset(0)
return ReloadPage("Reset...")
index.exposed = True
+ index._cp_config = {'tools.basic_auth.on': True,
+ 'tools.basic_auth.realm': 'My Print Server',
+ 'tools.basic_auth.users': users,
+ 'tools.basic_auth.encrypt': clear_text}
class PrintButton(object):
def index(self):
#handle connect push, then reload page
gPronterPtr.printfile(0)
return ReloadPage("Print...")
index.exposed = True
+ index._cp_config = {'tools.basic_auth.on': True,
+ 'tools.basic_auth.realm': 'My Print Server',
+ 'tools.basic_auth.users': users,
+ 'tools.basic_auth.encrypt': clear_text}
class PauseButton(object):
def index(self):
#handle connect push, then reload page
gPronterPtr.pause(0)
return ReloadPage("Pause...")
index.exposed = True
+ index._cp_config = {'tools.basic_auth.on': True,
+ 'tools.basic_auth.realm': 'My Print Server',
+ 'tools.basic_auth.users': users,
+ 'tools.basic_auth.encrypt': clear_text}
class XMLstatus(object):
def index(self):
#handle connect push, then reload page
- return '<?xml version="1.0"?>\n<xml>\n <status>'+gPronterPtr.status.GetStatusText()+'</status>\n</xml>';
+ txt='<?xml version="1.0"?>\n<pronterface>\n'
+ txt=txt+'<file>'+str(gPronterPtr.filename)+'</file>\n'
+ txt=txt+'<status>'+str(gPronterPtr.status.GetStatusText())+'</status>\n'
+ try:
+ temp = str(float(filter(lambda x:x.startswith("T:"),gPronterPtr.tempreport.split())[0].split(":")[1]))
+ txt=txt+'<hotend>'+temp+'</hotend>\n'
+ except:
+ txt=txt+'<hotend>NA</hotend>\n'
+ pass
+ try:
+ temp = str(float(filter(lambda x:x.startswith("B:"),gPronterPtr.tempreport.split())[0].split(":")[1]))
+ txt=txt+'<bed>'+temp+'</bed>\n'
+ except:
+ txt=txt+'<bed>NA</bed>\n'
+ pass
+ if gPronterPtr.sdprinting:
+ fractioncomplete = float(gPronterPtr.percentdone/100.0)
+ txt+= _("<progress>%04.2f %%") % (gPronterPtr.percentdone,)
+ txt+="</progress>\n"
+ elif gPronterPtr.p.printing:
+ fractioncomplete = float(gPronterPtr.p.queueindex)/len(gPronterPtr.p.mainqueue)
+ txt+= _("<progress>%04.2f %% |") % (100*float(gPronterPtr.p.queueindex)/len(gPronterPtr.p.mainqueue),)
+ txt+="</progress>\n"
+ else:
+ txt+="<progress>NA</progress>\n"
+ txt+='</pronterface>'
+ return txt
index.exposed = True
class WebInterface(object):
def __init__(self, pface):
+ config = ConfigParser.SafeConfigParser(allow_no_value=True)
+ config.read('auth.config')
+ users[config.get("user", "user")] = config.get("user", "pass")
self.pface = pface
global gPronterPtr
global gWeblog

0 comments on commit 9692593

Please sign in to comment.