def GET(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Make the page myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Dump Configuration') myPage.setCSS(u'/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody( u'How do you want to dump the configuration database?<br>') myPage.setBody(u'<form method="post">') myPage.setBody(u'<select name="dumpMethod">') myPage.setBody( u'<option value="display">Display config database in browser</option>' ) myPage.setBody( u'<option value="download">Download a dump file of config database</option>' ) myPage.setBody(u'</select>') myPage.setBody('<input type="submit" value="Go >">') myPage.setBody('</form>') myPage.setBody('</div>') web.output(myPage.output())
def GET(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Shutdown') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') # Build the page myPage.setBody(u'<form method="post">') myPage.setBody(u'<select name="downMethod">') myPage.setBody(u'<option value="reboot" selected>Reboot</option>') myPage.setBody(u'<option value="halt">Shutdown</option>') myPage.setBody(u'</select> the appliance.') myPage.setBody(u' <input type="submit" value="Go >">') myPage.setBody(u'</form>') myPage.setBody('clientId: %s' % clientId) myPage.setBody(u'</div>') web.output(myPage.output())
def GET(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Build the page myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Status') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody(u'<p>Appliance Status</p>') myPage.setBody(u'<p>Hostname: %s.%s</p>' % (self.config.getVar('sys.hostname'), self.config.getVar('net.domain'))) myPage.setBody(u'<p>Time zone: %s</p>' % self.config.getVar('sys.tz')) myPage.setBody( u'<p>Virtual Memory: %s</p>' % escape(appliance.sysctl('vm.vmtotal')).replace('\n', '<br>')) myPage.setBody('clientId: %s' % clientId) myPage.setBody(u'</div>') web.output(myPage.output())
def POST(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Collect POST data input = web.input(_method='post') myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Shutdown') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') # Do stuff based on POST data if input['downMethod'] == 'reboot' or input['downMethod'] == 'halt': myPage.setHead(u'<meta http-equiv="refresh" content="70;url=/">') myPage.setBody(u'Performing action %s. Please wait.' % input['downMethod']) web.background(self.appliance.shutdown(input['downMethod'])) else: myPage.setHead(u'<meta http-equiv="refresh" content="5;url=/">') myPage.setBody( u'downMethod "%s" is not valid. Redirecting to front page.' % input['downMethod']) syslog.syslog( syslog.LOG_ERR, 'invalid shutdown option "%s" passed to web gui' % input['downMethod']) myPage.setBody(u'</div>') web.output(myPage.output())
def GET(self, logfile): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False allowed = ('/messages', '/access') myPage = page.Page() web.header('Content-Type', myPage.getContentType()) myPage.setTitle(u'Appliance Webgui') myPage.setCSS(u'/static/styles.css') if logfile in allowed: myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody(u'<div id="logtext">') if logfile == 'access': logfile = 'lighttpd.access.log' proc = subprocess.Popen(['cat', '/var/log/%s' % logfile], shell=False, stdin=None, stdout=subprocess.PIPE, stderr=None) logOutput = escape(proc.communicate()[0]) myPage.setBody(logOutput.replace('\n', '<br>')) myPage.setBody(u'</div>') myPage.setBody(u'</div>') web.output(myPage.output()) else: web.notfound()
def GET(self): iankiHTML = geniAnki(self) #if makeSlim: # iankiHTML = slimmer.xhtml_slimmer(iankiHTML) test64 = base64.b64encode(iankiHTML) import urllib #testUrlencode = urllib.urlencode(magicHTML) #dataURL = r'<a href="data:text/html;charset=utf-8;base64,%s" >Click here</a>' % test64 installHTML = r''' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <title>iAnki (%(version)s) - installer</title> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;" /> </head> <body> <div align='center'> <span style="font-size: 16px;">Bookmark the following link</span><br> <a style="font-size: 32px;" href="data:text/html;charset=utf-8;base64,%(payload)s" >iAnki (%(version)s)</a><br><br> <span style="font-size: 16px;">For Mobile, save the following</span><br> <a style="font-size: 32px;" href="/anki/mobile.html?loc=%(location)s" >iAnki Mobile (%(version)s)</a> </div> </body> </html> ''' % {'version':ui.__version__, 'payload':test64, 'location': urllib.quote(web.input(loc='').loc)} web.output(installHTML)
def GET(self, path): # Handle cookies cookies = web.cookies() clientId = cookies.get('clientId') # Make the page myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Login') myPage.setCSS(u'/static/styles.css') myPage.setBody(self._top()) myPage.setBody(u'<div id="login">') if clientMap.has_key(clientId): myPage.setBody(u'You are already logged in with ID %s.<br>' % clientId) myPage.setBody( u'Do you want to <a href="/logout">log out</a>?<br>') myPage.setBody( u'Do you want to <a href="javascript:history.back()">go back</a>?' ) else: myPage.setBody(u'<form method="post">') myPage.setBody( u'Username: <input type="text" name="username"><br>') myPage.setBody( u'Password: <input type="password" name="password"><br>') myPage.setBody(u'<input type="submit" value="Submit">') myPage.setBody(u'</form>') myPage.setBody(u'</div>') web.output(myPage.output())
def POST(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Collect POST data input = web.input(_method='post') # Do stuff based on POST data for key, val in input.iteritems(): self.config.setVar(key, val) # Create page myPage = page.Page() myPage.setTitle('Appliance Webgui - Login') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody('<div id="main">') if self.config.needCommit: myPage.setBody( 'Settings have changed. Be sure to commit new configuration to disk.<br>' ) for key, val in input.iteritems(): myPage.setBody('%s: %s<br>' % (key, val)) myPage.setBody('<a href="/">Go to the main page</a>') myPage.setBody('</div>') web.output(myPage.output())
def render(name, *args): #if config.run_mode is 'debug': _global_render_ = web.template.render(config.views_config['template']) template = getattr(_global_render_, name) web.header('Content-Type', 'text/html') web.output(template(*args)) return None
def write_array(self, value, varname): if value == None or len(value) == 0: web.output('<' + varname + ' />') else: for item in value: web.output('<' + varname + '>' + escape(str(item)) + '</' + varname + '>')
def GET(self, output_format): data = web.input() lats = data.lats.split(",") lons = data.lons.split(",") res = altitude.page_profile(db, utils, [lats,lons], output_format, "get") header = res[0] body = res[1] web.header('Content-Type', header) web.output(body)
def PUT(self): ans = [] title = web.input() ans = dis.calc(title) web.output("Heckles!") return ans
def GET(self, file, offset, length): offset = int(offset) length = int(length) web.header("Content-Type","application/octet-stream") r0, r1 = offset, offset+length-1 url = "http://archive.org/download/bpl_marc/" + file ureq = urllib2.Request(url, None, {'Range':'bytes=%d-%d'% (r0, r1)},) f = urllib2.urlopen(ureq) while 1: buf = f.read(1024) if not buf: break web.output(buf) f.close()
def GET(self): json = urllib.unquote(web.context.environ['QUERY_STRING']) newConfig = simplejson.loads(json) web.debug("new config IS ", newConfig) messages = validateConfig(newConfig) if messages: ret = {'success':False, 'messages':messages} web.output(simplejson.dumps(ret)) return global config config = newConfig saveConfig() web.output(simplejson.dumps({'success':True}))
def static_handler(self, url): static_file = os.path.join(config.web_root[0], * url.split('/')) import mimetypes if os.path.isfile(static_file): base, ext = os.path.splitext(static_file) web.header('Content-Type', mimetypes.types_map[ext]) f = open(static_file, 'rb') try: web.output(f.read(-1)) return True finally: f.close() return False
def GET(self): input = web.input(id=None, togo='0', payload='') #print >> sys.stderr, " id:", input.id #print >> sys.stderr, " togo:", input.togo #print >> sys.stderr, "payload:", input.payload id = input.id ret = "''" #ui.logMsg(' sync ' + id); if id: if id in syncData: sb = syncData[id] else: sb = SyncBlock(id) syncData[id] = sb if sb.working: #ui.logMsg(' working ' + id); if not sb.thread.isAlive(): #ui.logMsg(' thread done ' + id); #ui.logMsg(' response ' + sb.result); retStatus = "'done'" ret = sb.result del syncData[id] else: #ui.logMsg(' wait ' + id); retStatus = "'wait'" else: #ui.logMsg(' append ' + id); sb.request += input.payload if int(input.togo) == 0: sb.working = True sb.thread = SyncProcThread(sb) sb.thread.start() retStatus = "'wait'" #ui.logMsg(' start ' + id + sb.request); #print >> sys.stderr, "process:", syncData[id] #ret = procSync(syncData[id]) #del syncData[id] else: #ui.logMsg(' continue ' + id); retStatus = "'continue'" #data = simplejson.loads(input.json) out = u"request_callback(%s, %s);" % (retStatus, ret) web.header('Content-Type', 'text/javascript; charset=UTF-8') web.output(out)
def GET(self, file, offset, length): offset = int(offset) length = int(length) web.header("Content-Type","application/octet-stream") r0, r1 = offset, offset+length-1 url = "http://archive.org/download/bpl_marc/" + file ureq = urllib.request.Request(url, None, {'Range':'bytes=%d-%d'% (r0, r1)},) f = urllib.request.urlopen(ureq) while True: buf = f.read(1024) if not buf: break web.output(buf) f.close()
def GET(self): # The index just redirects to the installer, passing it the current location redirectHTML = ''' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>iAnki (%(version)s) - launcher</title> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;" /> <script type="text/javascript"> window.location = window.location + "anki/install.html?loc=" + escape(window.location) </script> </head> <body> </body> </html> ''' % {'version':ui.__version__} web.output(redirectHTML)
def GET(self, name): # Deduce the name & type of the file ext = name.split('.')[-1] contentType = { 'png': 'image/png', 'jpg': 'image/jpeg', 'gif': 'image/gif', 'ico': 'image/gif', 'css': 'text/css' } # Serve it if we got it! if os.path.exists("static") and name in os.listdir("static"): web.header(u'Content-Type', contentType[ext]) web.output(open('static/%s' % name, 'rb').read()) else: web.notfound()
def write_records(self, value, varname): # Header if len(value) > 0: for key in value[0]: web.output(key) web.output("\t") web.output("\n") # Each record for item in value: self.write_hash(item, varname) web.output("\n")
def POST(self, output_format, input_format): # Determine whether the post request is a protocol buffer or # an XML document. (I am sure there is a more elegant way) try: postdata = web.input()['protobuf'] except: try: postdata = '<?xml version=' + web.input()['<?xml version'] except: web.header('Content-Type', 'html/txt') web.output("Wrong input format") #web.internalerror() return res = altitude.page_profile(db, utils, postdata, output_format, input_format) header = res[0] body = res[1] web.header('Content-Type', header) web.output(body)
def GET(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Build the page myPage = page.Page() web.header("Content-Type", myPage.getContentType()) myPage.setTitle(u'Appliance Webgui - Network') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody(u'<p>This will eventually be the networking page.</p>') myPage.setBody('clientId: %s' % clientId) myPage.setBody(u'</div>') web.output(myPage.output())
def GET(self): template = open('template.html', 'rb').read() part1, part2 = template.split("%TRACKS_TABLE%") web.output(part1) web.output(safereadfile('tracks_table') or """<tbody><tr><td colspan=3 style="padding:10px;">Need to index files...""") web.output(part2)
def write_records(self, value, varname): if value == None or len(value) == 0: web.output('<' + varname + ' />') else: for item in value: web.output('<' + varname + '>') self.write_hash(item, varname) web.output('</' + varname + '>')
def POST(self, path): # Handle cookies cookies = web.cookies() clientId = cookies.get('clientId') if not clientId: clientId = web.to36(random.randint(1, 4294967295)) web.setcookie('clientId', clientId, self.sessionTimeo) clientMap[clientId] = {} clientMap[clientId]['date'] = int(time.time()) myPage = page.Page() myPage.setTitle(u'Appliance Webgui - Login') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(u'<div id="login">') input = web.input(_method='post') myPage.setBody(u'Username: %s<br>' % input.username) myPage.setBody(u'Password: %s<br>' % input.password) myPage.setBody(u'<a href="/">Go to the main page</a>') myPage.setBody(u'</div>') web.output(myPage.output())
def POST(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False input = web.input(_method='post') myPage = page.Page() myPage.setTitle(u'Appliance Webgui - Dump Configuration') if input['dumpMethod'] == 'display': web.header("Content-Type", myPage.getContentType()) myPage.setCSS(u'/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody(self.config.dump().replace('\n', '<br>')) myPage.setBody('</div>') elif input['dumpMethod'] == 'download': myPage.setContentType('application/octet-stream') web.header("Content-Type", myPage.getContentType()) web.output(myPage.output())
def GET(self): global config config = makeDefaultConfig() web.debug(config) saveConfig() web.output(simplejson.dumps(config))
def GET(self, path): cookies = web.cookies() clientId = self._ensureClientId(cookies) if not clientId: web.seeother('/login') return False # Build the page myPage = page.Page() web.header('Content-Type', myPage.getContentType()) myPage.setTitle('Appliance Webgui - System') myPage.setCSS('/static/styles.css') myPage.setBody(self._top()) myPage.setBody(self._navMenu(clientId)) myPage.setBody(u'<div id="main">') myPage.setBody(u'<p>System Preferences</p>') myPage.setBody(u'<form method="post">') # Passwords myPage.setBody(u'Passwords<br>') myPage.setBody( u'Reset admin password: <input type="password" name="adminPassword1"><br>' ) myPage.setBody( u'Confirm admin password: <input type="password" name="adminPassword2"><br>' ) myPage.setBody( u'Reset root password: <input type="password" name="rootPassword1"><br>' ) myPage.setBody( u'Confirm root password: <input type="password" name="rootPassword2">' ) myPage.setBody(u'<hr>') # Networking myPage.setBody(u'Networking<br>') myPage.setBody( u'IPv4 Gateway: <input type="text" name="net.gateway" value="%s"><br>' % self.config.getVar('net.gateway4')) myPage.setBody( u'IPv4 Nameserver: <input type="text" name="net.nameserver4" value="%s"><br>' % self.config.getVar('net.nameserver4')) for iface in netifaces.interfaces(): myPage.setBody('%s<br>' % iface) addresses = netifaces.ifaddresses(iface) myPage.setBody('%s<br>' % addresses[netifaces.AF_LINK][0]['addr']) myPage.setBody('%s<br>' % addresses[netifaces.AF_INET][0]['addr']) myPage.setBody(u'<hr>') # Syslog myPage.setBody(u'Syslog<br>') if self.config.getVar('svc.log.enable'): myPage.setBody( u'Enabled<input type="radio" name="svc.log.enable" value="True" checked="checked">' ) myPage.setBody( u'Disabled<input type="radio" name="svc.log.enable" value="False">' ) else: myPage.setBody( u'Enabled<input type="radio" name="svc.log.enable" value="True">' ) myPage.setBody( u'Disabled<input type="radio" name="svc.log.enable" value="False" checked="checked">' ) myPage.setBody(u'<br>') myPage.setBody( u'Server (optional): <input type="text" name="sys.log.server" value="%s">' % self.config.getVar('sys.log.server')) myPage.setBody(u'<hr>') # Language currLang = self.config.getVar('sys.lang') langs = { 'en_US': u'english', 'es_ES': u'espa\xf1ol', 'de_DE': u'deutsch', 'fr_FR': u'fran\xe7ais', 'jp_JP': u'japanese', 'zh_CN': u'chinese' } myPage.setBody(u'Language: <select name="sys.lang">') for key, val in langs.iteritems(): if key == currLang: myPage.setBody(u'<option selected value="%s">%s</option>' % (key, val)) else: myPage.setBody(u'<option value="%s">%s</option>' % (key, val)) myPage.setBody('</select>') myPage.setBody('<br>') myPage.setBody('<input type="submit" value="Save Options">') myPage.setBody('</form>') myPage.setBody('clientId: %s' % clientId) myPage.setBody('</div>') web.output(myPage.output())
def GET(self): web.header('Content-Type', 'text/cache-manifest') web.output(render.cache_manifest())
def GET(self): iankiHTML = geniAnki(self) web.output(iankiHTML)
def write_array(self, value, varname): for item in value: web.output(item) web.output("\t")
def write(self, value_type, value): web.output(value) web.output("\t")
def write_hash(self, value, varname): for key, val in value.iteritems(): web.output('<' + key + '>' + escape(str(val)) + '</' + key + '>')
def write_hash(self, value, varname): for key, val in value.iteritems(): web.output(val) web.output("\t")
def write(self, value_type, value): if value_type == 'LITERAL_XML' or value_type == 'dom': return web.output(value) else: return web.output(escape(str(value)))
def GET(self): web.header('Content-Type', 'text/html') web.output(altitude.page_main_get())
def GET(self): web.output(simplejson.dumps(config))