def serveMotes(self, action, namedAction, qs, form): disabled = "" if self.getLevel() > 1 else 'disabled="disabled" ' c = "" for m in motes.getMotes(): name = "mote" + m.getPortBasename() if qs: if name in qs: m.isSelected = qs[name][0] == 'on' elif "action" in qs: m.isSelected = False elif form: if name in form: m.isSelected = form[name].value == "on" else: m.isSelected = False checked = ' checked="checked"' if m.isSelected else "" c += '<div class="mote"><strong>Mote: </strong>' + m.getPortName() c += ' (<strong>Platform: </strong>' + m.platform + ') ' c += ' <input type="checkbox" title="Select the mote" name="' + name + '"' c += checked + ' ' + disabled + '/>' + namedAction + '</div>\n' # remember which motes were selected and which were not motes.storeSelected() if c: c = '<div class="motes1">\nDirectly attached motes:\n<br/>\n' + c + '</div>\n' return c
def serveMotes(self, action, namedAction, qs, form, extra = False): disabled = "" if self.getLevel() > 1 else 'disabled="disabled" ' c = "" for m in motes.getMotesSorted(): name = "mote" + m.getFullBasename() if qs: if name in qs: m.isSelected = qs[name][0] == 'on' elif "action" in qs: m.isSelected = False elif form: if name in form: m.isSelected = form[name].value == "on" else: m.isSelected = False checked = ' checked="checked"' if m.isSelected else "" c += '<div class="mote"><strong>Mote: </strong>' if extra: c += "<a href='javascript:talkToMote(\"" + utils.urlEscape(m.getFullBasename()) +"\")' " + disabled + ">" arr = m.getFullName().split("@") if (len(arr) == 1): c += m.getFullName() else: c += arr[0] arr = m.getFullName().split("@") if arr[1] != "Local": c += " @ " + m.getFullName().split("@")[1][7:].split(":")[0] c += "</a>" else: c += m.getFullName() c += ' (<strong>Platform: </strong>' + m.platform + ') ' c += ' <input type="checkbox" title="Select the mote" name="' + name + '"' c += checked + ' ' + disabled + '/>' + namedAction c += '</div>\n' # remember which motes were selected and which were not motes.storeSelected() if c: c = '<div class="motes1">\nAttached motes:\n<br/>\n' + c + '</div>\n' return c
def serveUploadPost(self, qs, lastUploadCode, lastUploadConfig, lastUploadFile): global maybeIsInSubprocess global isPostEntered # Parse the form data posted form = cgi.FieldStorage( fp = self.rfile, headers = self.headers, environ = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'], }) # signal the upload result thread that we are are ready to start serving isPostEntered = True self.send_response(200) self.sendDefaultHeaders() self.end_headers() file_data = None isSEAL = False if "compile" in form: if "language" in form: isSEAL = form["language"].value.strip() == "SEAL" configuration.c.setCfgValue("isSealCode", isSEAL) if "slow" in form: slow = form["slow"].value == "on" else: slow = False configuration.c.setCfgValue("slowUpload", slow) configuration.c.save() if "code" in form.keys(): code = form["code"].value else: code = None if "file" in form.keys(): fileContents = form["file"].file.read() else: fileContents = None # check if what to upload is provided if not fileContents and not code: text = "Neither filename nor code specified!" maybeIsInSubprocess = False self.serveAnyPage("error:critical", qs, errorMsg = text) return for m in motes.getMotes(): name = "mote" + m.getPortBasename() if name in form: isChecked = form[name].value == "on" else: isChecked = False if isChecked: m.isSelected = True else: m.isSelected = False # remember which motes were selected and which not motes.storeSelected() # check if any motes are selected if not motes.anySelected(): text = "No motes selected!" maybeIsInSubprocess = False return self.serveAnyPage("error:critical", qs, errorMsg = text, generatedContentOnly = True) config = "" if "config" in form.keys(): lastUploadConfig = form["config"].value config = lastUploadConfig if slow: config += "\nSLOW_UPLOAD=y\n" retcode = self.compileAndUpload(code, config, fileContents, isSEAL) motesText = self.serveMotes("upload", "Upload", None, form) isSealCode = configuration.c.getCfgValueAsBool("isSealCode") isSlow = configuration.c.getCfgValueAsBool("slowUpload") if retcode == 0: infoMsg = "<div><strong>Upload done!</strong></div><br/>" else: infoMsg = "<div><strong>Upload failed!</strong></div><br/>" '''self.serveAnyPage("upload", qs, True, {"MOTES_TXT" : motesText, "CCODE_CHECKED": 'checked="checked"' if not isSealCode else "", "SEALCODE_CHECKED" : 'checked="checked"' if isSealCode else "", "UPLOAD_CODE" : lastUploadCode, "UPLOAD_CONFIG" : lastUploadConfig, "UPLOAD_FILENAME": lastUploadFile, "SLOW_CHECKED" : 'checked="checked"' if isSlow else ""}, infoMsg = infoMsg)''' self.writeChunk("ok")
def serveConfig(self, qs): self.setSession(qs) if not self.getLevel() > 1: self.serveDefault(qs, True) return self.send_response(200) self.sendDefaultHeaders() self.end_headers() if "platform_set" in qs: for m in motes.getMotes(): motename = "sel_mote" + m.getPortBasename() if motename in qs: m.platform = qs[motename][0] motes.storeSelected() text = '<strong>Mote platforms updated!</strong>\n' self.serveAnyPage("config", qs, content = text) return else: global isListening sensor_data.moteData.reset() ht.openAllSerial() isListening = True motePortName = None filesRequired = False for s in qs: if s[:4] == "mote": pair = s[4:].split('_') try: motePortName = pair[0] filesRequired = pair[1] == "files" except: pass break if motePortName is None: # or moteIndex >= len(motes.getMotes()): self.serveAnyPage("error:critical", qs, errorMsg = "Config page requested, but mote not specified!") return platform = None dropdownName = "sel_mote" + motePortName if dropdownName in qs: platform = qs[dropdownName][0] if platform not in moteconfig.supportedPlatforms: self.serveAnyPage("error:critical", qs, errorMsg = "Config page requested, but platform not specified or unknown!") return if os.name == "posix": fullMotePortName = "/dev/" + motePortName else: fullMotePortName = motePortName moteconfig.instance.setMote(motes.getMote(fullMotePortName), platform) (errmsg, ok) = moteconfig.instance.updateConfigValues(qs) if not ok: self.serveAnyPage("error:critical", qs, errorMsg = errmsg) return # fill config values from the mote / send new values to the mote if "get" in qs: reply = moteconfig.instance.getConfigValues() elif "set" in qs: reply = moteconfig.instance.setConfigValues() if filesRequired: if "filename" in qs: (text, ok) = moteconfig.instance.getFileContentsHTML(qs) else: (text, ok) = moteconfig.instance.getFileListHTML(motePortName) else: (text, ok) = moteconfig.instance.getConfigHTML() if not ok: self.serveAnyPage("error:critical", qs, errorMsg = text) return moteidQS = "?sel_mote" + motePortName + "=" + platform + "&" + "mote" + motePortName self.serveAnyPage("config", qs, isGeneric = False, content = text, replaceValues = { "MOTEID_CONFIG" : moteidQS + "_cfg=1", "MOTEID_FILES" : moteidQS + "_files=1"})
def serveConfig(self, qs): global isListening self.send_response(200) self.sendDefaultHeaders() self.end_headers() if "platform_set" in qs: for m in motes.getMotes(): motename = "sel_mote" + utils.urlEscape(m.getFullBasename()) if motename in qs: m.platform = qs[motename][0] motes.storeSelected() text = '<strong>Mote platforms updated!</strong>\n' self.writeChunk(self.serveAnyPage("config", qs, content = text, generatedContentOnly = True)) return else: sensor_data.moteData.reset() ht.openAllSerial() isListening = True motePortName = None filesRequired = False for s in qs: if s[:4] == "mote": pair = s[4:].split('_') try: motePortName = pair[0] filesRequired = pair[1] == "files" except: pass break if motePortName is None: # or moteIndex >= len(motes.getMotes()): self.writeChunk("<h4 class='err'>Config page requested, but mote not specified!</h4>") return motePortNameEsc = utils.urlEscape(motePortName) platform = None dropdownName = "sel_mote" + motePortNameEsc if dropdownName in qs: platform = qs[dropdownName][0] if platform not in moteconfig.supportedPlatforms: self.writeChunk("<h4 class='err'>Config page requested, but platform not specified or unknown!</h4>") return moteconfig.instance.setMote(motes.getMote(motePortName), platform) (errmsg, ok) = moteconfig.instance.updateConfigValues(qs) if not ok: self.writeChunk(errmsg) return # fill config values from the mote / send new values to the mote if "get" in qs: reply = moteconfig.instance.getConfigValues() elif "set" in qs: reply = moteconfig.instance.setConfigValues() if filesRequired: if "filename" in qs: (text, ok) = moteconfig.instance.getFileContentsHTML(qs) else: (text, ok) = moteconfig.instance.getFileListHTML(motePortNameEsc) else: (text, ok) = moteconfig.instance.getConfigHTML() if not ok: self.writeChunk("\n<h4 class='err'>Error: " + text + "</h4>\n") return moteidQS = "?sel_mote" + motePortNameEsc + "=" + platform + "&" + "mote" + motePortNameEsc replaceValues = { "MOTEID_CONFIG" : moteidQS + "_cfg=1", "MOTEID_FILES" : moteidQS + "_files=1" } if "update_sensors" in qs: configuration.c.selectSection("graph") graphConfig = [] storeConfig = [] try: graphSensors = json.loads(configuration.c.getCfgValue("graphsensors")) except: graphSensors = {} for s in moteconfig.instance.activePlatform.sensors: storeFlag = "store_" + s.varname graphFlag = "graph_" + s.varname if storeFlag in qs and qs[storeFlag][0] == 'on': storeConfig.append(s.varname) if graphFlag in qs and qs[graphFlag][0] == 'on': graphConfig.append(s.varname) configuration.c.selectSection("graph") graphSensors[motePortNameEsc] = graphConfig configuration.c.setCfgValue("graphsensors", json.dumps(graphSensors)) configuration.c.save() else: try: configuration.c.selectSection("graph") graphSensors = json.loads(configuration.c.getCfgValue("graphsensors")) graphConfig = graphSensors[motePortNameEsc] except: graphConfig = [] for s in moteconfig.instance.activePlatform.sensors: if s.varname in graphConfig: replaceValues["graph_" + s.varname] = "checked" else: replaceValues["graph_" + s.varname] = "" self.writeChunk(self.serveAnyPage("config", qs, isGeneric = False, content = text, replaceValues = replaceValues, generatedContentOnly = True))
def serveUploadPost(self, qs): #, lastUploadCode, lastUploadConfig, lastUploadFile): global maybeIsInSubprocess global forceInterrupt # TODO lastUploadCode = "" lastUploadConfig = "" lastUploadFile = "" # Parse the form data posted form = cgi.FieldStorage( fp = self.rfile, headers = self.headers, environ = { 'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'] }) self.send_response(200) self.sendDefaultHeaders() self.end_headers() file_data = None codeType = "C" if "compile" in form: if "language" in form: codeType = form["language"].value.strip().lower() configuration.c.setCfgValue("codeType", codeType) if "slow" in form: slow = form["slow"].value == "on" else: slow = False configuration.c.setCfgValue("slowUpload", slow) configuration.c.save() code = None fileContents = None fileName = None if "compile" in form and "code" in form: code = form["code"].value if "upload" in form and "file" in form: fileContents = form["file"].file.read() fileName = form["file"].filename # check if what to upload is provided if not fileContents and not code: infoMsg = "Neither filename nor code specified!" maybeIsInSubprocess = False forceInterrupt = True self.writeChunk(infoMsg); return for m in motes.getMotes(): name = "mote" + m.getFullBasename() if name in form: isChecked = form[name].value == "on" else: isChecked = False if isChecked: m.isSelected = True else: m.isSelected = False # remember which motes were selected and which not motes.storeSelected() # check if any motes are selected if not motes.anySelected(): infoMsg = "No motes selected!" maybeIsInSubprocess = False forceInterrupt = True self.writeChunk(infoMsg); return config = "" if "config" in form.keys(): lastUploadConfig = form["config"].value config = lastUploadConfig if slow: config += "\nSLOW_UPLOAD=y\n" retcode = self.compileAndUpload(code, config, fileName, fileContents, codeType) motesText = self.serveMotes("upload", "Upload", None, form) codeType = configuration.c.getCfgValue("codeType") isSlow = configuration.c.getCfgValueAsBool("slowUpload") if retcode == 0: infoMsg = "Upload done!" else: infoMsg = "Upload failed!" self.writeChunk(infoMsg);
def serveConfig(self, qs): global isListening self.send_response(200) self.sendDefaultHeaders() self.end_headers() if "platform_set" in qs: for m in motes.getMotes(): motename = "sel_mote" + utils.urlEscape(m.getFullBasename()) if motename in qs: m.platform = qs[motename][0] motes.storeSelected() text = '<strong>Mote platforms updated!</strong>\n' self.writeChunk( self.serveAnyPage("config", qs, content=text, generatedContentOnly=True)) return else: sensor_data.moteData.reset() ht.openAllSerial() isListening = True motePortName = None filesRequired = False for s in qs: if s[:4] == "mote": pair = s[4:].split('_') try: motePortName = pair[0] filesRequired = pair[1] == "files" except: pass break if motePortName is None: # or moteIndex >= len(motes.getMotes()): self.writeChunk( "<h4 class='err'>Config page requested, but mote not specified!</h4>" ) return motePortNameEsc = utils.urlEscape(motePortName) platform = None dropdownName = "sel_mote" + motePortNameEsc if dropdownName in qs: platform = qs[dropdownName][0] if platform not in moteconfig.supportedPlatforms: self.writeChunk( "<h4 class='err'>Config page requested, but platform not specified or unknown!</h4>" ) return moteconfig.instance.setMote(motes.getMote(motePortName), platform) (errmsg, ok) = moteconfig.instance.updateConfigValues(qs) if not ok: self.writeChunk(errmsg) return # fill config values from the mote / send new values to the mote if "get" in qs: reply = moteconfig.instance.getConfigValues() elif "set" in qs: reply = moteconfig.instance.setConfigValues() if filesRequired: if "filename" in qs: (text, ok) = moteconfig.instance.getFileContentsHTML(qs) else: (text, ok) = moteconfig.instance.getFileListHTML(motePortNameEsc) else: (text, ok) = moteconfig.instance.getConfigHTML() if not ok: self.writeChunk("\n<h4 class='err'>Error: " + text + "</h4>\n") return moteidQS = "?sel_mote" + motePortNameEsc + "=" + platform + "&" + "mote" + motePortNameEsc replaceValues = { "MOTEID_CONFIG": moteidQS + "_cfg=1", "MOTEID_FILES": moteidQS + "_files=1" } if "update_sensors" in qs: configuration.c.selectSection("graph") graphConfig = [] storeConfig = [] try: graphSensors = json.loads( configuration.c.getCfgValue("graphsensors")) except: graphSensors = {} for s in moteconfig.instance.activePlatform.sensors: storeFlag = "store_" + s.varname graphFlag = "graph_" + s.varname if storeFlag in qs and qs[storeFlag][0] == 'on': storeConfig.append(s.varname) if graphFlag in qs and qs[graphFlag][0] == 'on': graphConfig.append(s.varname) configuration.c.selectSection("graph") graphSensors[motePortNameEsc] = graphConfig configuration.c.setCfgValue("graphsensors", json.dumps(graphSensors)) configuration.c.save() else: try: configuration.c.selectSection("graph") graphSensors = json.loads( configuration.c.getCfgValue("graphsensors")) graphConfig = graphSensors[motePortNameEsc] except: graphConfig = [] for s in moteconfig.instance.activePlatform.sensors: if s.varname in graphConfig: replaceValues["graph_" + s.varname] = "checked" else: replaceValues["graph_" + s.varname] = "" self.writeChunk( self.serveAnyPage("config", qs, isGeneric=False, content=text, replaceValues=replaceValues, generatedContentOnly=True))
def serveUploadPost( self, qs): #, lastUploadCode, lastUploadConfig, lastUploadFile): global maybeIsInSubprocess global forceInterrupt # TODO lastUploadCode = "" lastUploadConfig = "" lastUploadFile = "" # Parse the form data posted form = cgi.FieldStorage(fp=self.rfile, headers=self.headers, environ={ 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': self.headers['Content-Type'] }) self.send_response(200) self.sendDefaultHeaders() self.end_headers() file_data = None codeType = "C" if "compile" in form: if "language" in form: codeType = form["language"].value.strip().lower() configuration.c.setCfgValue("codeType", codeType) if "slow" in form: slow = form["slow"].value == "on" else: slow = False configuration.c.setCfgValue("slowUpload", slow) configuration.c.save() code = None fileContents = None fileName = None if "compile" in form and "code" in form: code = form["code"].value if "upload" in form and "file" in form: fileContents = form["file"].file.read() fileName = form["file"].filename # check if what to upload is provided if not fileContents and not code: infoMsg = "Neither filename nor code specified!" maybeIsInSubprocess = False forceInterrupt = True self.writeChunk(infoMsg) return for m in motes.getMotes(): name = "mote" + m.getFullBasename() if name in form: isChecked = form[name].value == "on" else: isChecked = False if isChecked: m.isSelected = True else: m.isSelected = False # remember which motes were selected and which not motes.storeSelected() # check if any motes are selected if not motes.anySelected(): infoMsg = "No motes selected!" maybeIsInSubprocess = False forceInterrupt = True self.writeChunk(infoMsg) return config = "" if "config" in form.keys(): lastUploadConfig = form["config"].value config = lastUploadConfig if slow: config += "\nSLOW_UPLOAD=y\n" retcode = self.compileAndUpload(code, config, fileName, fileContents, codeType) motesText = self.serveMotes("upload", "Upload", None, form) codeType = configuration.c.getCfgValue("codeType") isSlow = configuration.c.getCfgValueAsBool("slowUpload") if retcode == 0: infoMsg = "Upload done!" else: infoMsg = "Upload failed!" self.writeChunk(infoMsg)