def UpdateConfig(self, adrs, cnfxml, override): """ Update configuration of specified WebBrick from specified file. Returns None if the operation is completed successfully, otherwise returns a page to be displayed describing the reason for non-completion. 'adrs' is the IP address of the WebBrick top be updated. 'cnfxml' is the text of the WebBrick XML configuration file to be uploaded. 'override' is a dictionary of values that can be used to override values in the supplied DOM when generating the configuration commands; e.g. "password" - overrides password used with "LG" command "IP" - overrides IP addresss set with "IA" command """ #TODO: may need to add logic to allow rejection of commands/command forms # not supported by older WebBricks? try: wbcfg = WebBrickConfig() dom = parseXmlString(cnfxml) configcmds = wbcfg.makeConfigCommands(dom, override) # configcmds.append("RU") # Reboot WebBrick to work around RU command bug in some WebBrick firmware versions # TODO: # Consider: should the RU command be withdrawn? # How many buggy webbricks are in the wild? configcmds.append("RB") errs = "" for line in configcmds: if line[0] != '#': SendHTTPCmd(adrs,line) err = Wb6Status(adrs).getCmdStatus() msg = None if err == ERR_NotLoggedIn: msg = "Incorrect WebBrick password ("+line+")" err = 0 if err: errs += "WebBrick command error: "+str(err)+", ("+line+")\n" if msg: Warn(msg, "WbCfgManagerForm.UpdateConfig") raise WbAccessException(msg) except Exception, e: return self.wbConfigError( "Failed to update WebBrick at %s" % (adrs), escapeTextForHtml(str(e)))
# Copyright L.P.Klyne 2013 # Licenced under 3 clause BSD licence # $Id: DumpCommands.py 2612 2008-08-11 20:08:49Z graham.klyne $ # # I'm not sure what this is, but it appears to be a quick-and-dirty utility to dump # out Webbrick commands for a configuration file named on the command line, with # no provision for specifying an initial dictionary of default values. # -- #g # import sys sys.path.append("..") sys.path.append("../../../../WebBrickLibs/src/main/python") from DomHelpers import parseXmlFile from WebBrickConfig import WebBrickConfig if __name__ == "__main__": cfg = WebBrickConfig() for cmd in cfg.makeConfigCommands( parseXmlFile( sys.argv[1] ), dict() ): print cmd