Exemple #1
0
    def saveAllParameter(self):
        for parname in self.config:
            self.config[parname]['file'] = self.config[parname]['value']
            elements = self.xmlconfig.getElementsByTagName(parname)
            if len(elements) != 1:
                log.debug('config: parameter ' + parname +
                          ' not in config file?')
                # TODO: create parameter!

                newparam = self.xmlconfig.createElement(parname)
                newparamvalue = self.xmlconfig.createTextNode(
                    str(self.config[parname]['file']))
                newparam.appendChild(newparamvalue)
                self.xmlconfig.childNodes[0].appendChild(newparam)
                linebreak = self.xmlconfig.createTextNode("\n\n    ")
            else:
                elements[0].childNodes[0].data = self.config[parname]['file']

        file_handle = open(self.xmlconfigfile, "w")
        self.xmlconfig.writexml(file_handle)
        # sync buffers
        os.fsync(file_handle)
        file_handle.close()
        # and sync os to prevent dataloss on powerloss
        os.sync()
Exemple #2
0
    def open(self):
        log.debug("WebSocket opened")
        self.nextIsBinary = None
        Websocket.websocket_clients.append(self)
        self.player = Player(self)

        ans = {"cmd": "version"}
        self.write_message(json.dumps(ans))  # hier ok!
Exemple #3
0
 def on_message(self, message):
     try:
         jsonmsg = json.loads(message)
     except:
         log.error("Websocket: json error in user data...")
         return
     log.debug("Websocket: received message: " + str(jsonmsg))
     from system.parser import Parser
     Parser.parse_user_command(self, jsonmsg)
Exemple #4
0
    def run(self, port=80):
        log.debug("Webserver: listen to http port: " + str(port))
        self.listen(port)
        if os.path.exists("../../fullchain.pem"):
            log.debug("Webserver: listen to https port: " + str(port + 1))
            self.listen(port + 1,
                        ssl_options={
                            "certfile": "../../fullchain.pem",
                            "keyfile": "../../privkey.pem",
                        })

        Webserver.main_loop = tornado.ioloop.IOLoop().current()
        Webserver.main_loop.start()
        print("Webserver: TORNADO STARTED")
Exemple #5
0
 def post(self):
     file1 = self.request.files['update'][0]
     original_fname = file1['filename']
     extension = os.path.splitext(original_fname)[1]
     fname = ''.join(
         random.choice(string.ascii_lowercase + string.digits)
         for x in range(6))
     final_filename = fname + extension
     if not os.path.exists(Config.workingpath + '/update'):
         os.makedirs(Config.workingpath + '/update')
         os.makedirs(Config.workingpath + '/update/download')
     output_file = open(
         Config.workingpath + "/update/download/" + final_filename, 'wb')
     output_file.write(file1['body'])
     log.debug("file" + final_filename + " is uploaded")
     self.write(Updater.check_update_and_give_web_response())
Exemple #6
0
    def get(self):
        config = Config.getSingleton()
        filename = config.get("device.name") + "." + config.get(
            "device.mac") + "." + str(datetime.datetime.now().date()) + ".tgz"
        filename = filename.replace(" ", "_")
        log.debug("Webserver: config filename: " + str(filename))

        if not os.path.exists(Config.workingpath + '/temp'):
            os.makedirs(Config.workingpath + '/temp')
        GetConfigHandler.delete_all_files_in_folder('/temp')
        mypath = Config.workingpath + "/temp"

        shutil.make_archive("config", "gztar", Config.workingpath, '.')
        self.add_header("Content-Disposition",
                        "attachment; filename=" + filename)
        data = open("config.tar.gz", "rb").read()
        self.write(data)
Exemple #7
0
    def init(self, pathname):
        pathname = pathname.strip()
        pathname.replace('\\', '/')
        if pathname.endswith('/'):
            pathname = pathname[0:-1]
        Config.workingpath = pathname

        self.xmlconfigfile = Config.workingpath + '/config.xml'
        log.debug('Config: read config file: ' + self.xmlconfigfile)
        self.xmlconfig = minidom.parse(self.xmlconfigfile)

        for parname in self.config:
            elements = self.xmlconfig.getElementsByTagName(parname)
            if len(elements) == 0:
                self.config[parname]['value'] = self.config[parname]['default']
                self.config[parname]['file'] = None
                log.debug('config: couldnt find ' + parname +
                          ', using defaut: ' + self.config[parname]['value'])
            if len(elements) > 1:
                log.warn('config: more than one ' + parname + ' in config!')
            if len(elements) == 1:
                self.config[parname]['value'] = elements[0].childNodes[0].data
                self.config[parname]['file'] = elements[0].childNodes[0].data
                log.debug('config: found ' + parname + ': ' +
                          self.config[parname]['value'])
Exemple #8
0
 def get_room(roomid):
     filename = Config.workingpath + "/rooms/" + str(roomid) + ".json"
     if not os.path.exists(filename):
         log.error("Serializer: room does not exists: id: " + str(roomid) +
                   " " + filename)
         from game.room import Room
         return Room(roomid)
     roomfile = open(filename, 'r')
     filecontent = roomfile.read()
     try:
         jsonobj = json.loads(filecontent)
     except:
         log.error("Serializer: JSON error: id: " + str(roomid) + " " +
                   filename)
         jsonobj = False
     log.debug("Serializer: loading room: id: " + str(roomid) + " " +
               str(jsonobj))
     from game.room import Room
     room = Room(roomid)
     if not jsonobj == False:
         room.fromJSON(jsonobj)
     return room
Exemple #9
0
 def get_area(areaid):
     filename = Config.workingpath + "/areas/" + str(areaid) + ".json"
     if not os.path.exists(filename):
         log.error("Serializer: area does not exists: id: " + str(areaid) +
                   " " + filename)
         from game.area import Area
         return Area(areaid)
     areafile = open(filename, 'r')
     filecontent = areafile.read()
     try:
         jsonobj = json.loads(filecontent)
     except:
         log.error("Serializer: JSON error: id: " + str(areaid) + " " +
                   filename)
         jsonobj = False
     log.debug("Serializer: loading area: id: " + str(areaid) + " " +
               str(jsonobj))
     from game.area import Area
     area = Area(areaid)
     if not jsonobj == False:
         area.fromJSON(jsonobj)
     return area
Exemple #10
0
 def on_close(self):
     log.debug("WebSocket closed")
     self.player.ws_disconnect()
     Websocket.websocket_clients.remove(self)
Exemple #11
0
 def ws_disconnect(self):
     for p in self.room.player:
         p.send_text(
             i18n(p.lang, {"en": "" + self.name + " disconnects..."}))
     log.debug("player " + self.name + " disconnects.")
     self.room.player.remove(self)
Exemple #12
0
 def on_close(self):
     log.debug("WebSocketRTC closed")
     WebsocketRTC.websocket_clients.remove(self)
Exemple #13
0
 def on_message(self, message):
     # process json messages
     jsonmsg = json.loads(message)
     log.debug("Websocket: received message: " + str(jsonmsg))
     self.write_all_but_me(message)
Exemple #14
0
 def open(self):
     log.debug("WebSocketRTC opened")
     WebsocketRTC.websocket_clients.append(self)