コード例 #1
0
    def settings(self, s):
        public_url = PUBLIC_URL
        try:
            getDevices()
        except Exception as e:
            logger.error(
                'Connection to Domoticz refused!. Check configuration')

        if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel']:
            tunnels = getTunnelUrl()
            tunnel = tunnels[0].public_url
            if 'https' not in tunnel:
                public_url = tunnel.replace('http', 'https')
            else:
                public_url = tunnel

        user = self.getSessionUser()
        if user == None or user.get('uid', '') == '':
            s.redirect('/login?redirect_uri={0}'.format('/settings'))
            return
        message = ''
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
        code = readFile(CONFIGFILE)
        logs = readFile(LOGFILE)
        template = TEMPLATE.format(message=message,
                                   uptime=uptime(),
                                   list=deviceList,
                                   meta=meta,
                                   code=code,
                                   conf=confJSON,
                                   public_url=public_url,
                                   logs=logs,
                                   update=update)

        s.send_message(200, template)
コード例 #2
0
    def settings(self, s):
        try:
            getDevices()
        except Exception as e:
            logger.error(
                'Connection to Domoticz refused! Check configuration.')

        user = self.getSessionUser()
        if user == None or user.get('uid', '') == '':
            s.redirect('/login?redirect_uri={0}'.format('/settings'))
            return

        update = checkupdate()
        confJSON = json.dumps(configuration)
        public_url = getTunnelUrl()
        message = ''
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
        code = readFile(CONFIGFILE)
        logs = readFile(LOGFILE)
        template = TEMPLATE.format(message=message,
                                   uptime=uptime(),
                                   list=deviceList,
                                   meta=meta,
                                   code=code,
                                   conf=confJSON,
                                   public_url=public_url,
                                   logs=logs,
                                   update=update)

        s.send_message(200, template)
コード例 #3
0
    def settings(self, s):
        user = self.getSessionUser()
        if user is None or user.get('uid', '') == '':
            s.redirect('login?redirect_uri={0}'.format('settings'))
            return

        update = checkupdate()
        confJSON = json.dumps(configuration)
        public_url = getTunnelUrl()
        message = ''
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
        code = readFile(os.path.join(FILE_DIR, CONFIGFILE))
        logs = readFile(os.path.join(logfilepath, LOGFILE))
        template = TEMPLATE.format(message=message,
                                   uptime=uptime(),
                                   list=deviceList,
                                   meta=meta,
                                   code=code,
                                   conf=confJSON,
                                   public_url=public_url,
                                   logs=logs,
                                   update=update,
                                   branch=branch,
                                   dzversion=settings['dzversion'])

        s.send_message(200, template)
コード例 #4
0
    def settings_post(self, s):

        if (s.form.get("save")):
            textToSave = s.form.get("save", None)
            codeToSave = textToSave.replace("+", " ")
            saveFile(CONFIGFILE, codeToSave)

            message = 'Config saved'
            logger.info(message)
            meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if (s.form.get("backup")):
            codeToSave = readFile(CONFIGFILE)
            saveFile('config.yaml.bak', codeToSave)

            message = 'Backup saved'
            logger.info(message)
            meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if (s.form.get("restart")):
            message = 'Restart Server, please wait!'
            meta = '<meta http-equiv="refresh" content="5">'
            code = ''
            logs = ''
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)
            restartServer()

        if (s.form.get("sync")):
            r = self.forceDevicesSync()
            time.sleep(0.5)
            message = 'Devices syncronized'
            meta = '<!-- <meta http-equiv="refresh" content="10"> -->'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("reload")):
            message = ''
            meta = '<!-- <meta http-equiv="refresh" content="10"> -->'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("deletelogs")):
            logfile = os.path.join(FILE_DIR, LOGFILE)
            if os.path.exists(logfile):
                f = open(logfile, 'w')
                f.close()
            logger.info('Logs removed by user')
            message = ''
            meta = '<!-- <meta http-equiv="refresh" content="10"> -->'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("update")):
            os.system('bash ~/Domoticz-Google-Assistant/scripts/update.sh')
            message = 'Updated, Restarting Server, please wait!'
            meta = '<meta http-equiv="refresh" content="5">'
            code = readFile(CONFIGFILE)
            logs = readFile(LOGFILE)
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)
            restartServer()
コード例 #5
0
    def settings_post(self, s):
        enableReport = ReportState.enable_report_state()
        update = checkupdate()
        confJSON = json.dumps(configuration)
        public_url = getTunnelUrl()
        logs = readFile(os.path.join(logfilepath, LOGFILE))
        code = readFile(os.path.join(FILE_DIR, CONFIGFILE))
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'

        if s.form.get("save"):
            textToSave = s.form.get("save", None)
            codeToSave = textToSave.replace("+", " ")
            saveFile(CONFIGFILE, codeToSave)
            message = 'Config saved'
            logger.info(message)
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            code = readFile(os.path.join(FILE_DIR, CONFIGFILE))
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if s.form.get("backup"):
            codeToSave = readFile(os.path.join(FILE_DIR, CONFIGFILE))
            saveFile('config/config.yaml.bak', codeToSave)
            message = 'Backup saved'
            logger.info(message)
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if s.form.get("restart"):
            message = 'Restart Server, please wait a minute!'
            meta = '<meta http-equiv="refresh" content="20">'
            code = ''
            logs = ''

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)
            restartServer()

        if s.form.get("sync"):
            if 'Homegraph_API_Key' in configuration and configuration[
                    'Homegraph_API_Key'] != 'ADD_YOUR HOMEGRAPH_API_KEY_HERE' or enableReport == True:
                r = self.forceDevicesSync()
                time.sleep(0.5)
                if r:
                    message = 'Devices syncronized'
                else:
                    message = 'Homegraph api key not valid!'
            else:
                message = 'Add Homegraph api key or a Homegraph Service Account json file to sync devices here!'
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if s.form.get("reload"):
            message = ''

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if s.form.get("deletelogs"):
            logfile = os.path.join(logfilepath, LOGFILE)
            if os.path.exists(logfile):
                f = open(logfile, 'w')
                f.close()
            logger.info('Logs removed by user')
            message = 'Logs removed'
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if s.form.get("update"):
            repo.git.reset('--hard')
            repo.remotes.origin.pull()
            message = 'Updating to latest ' + repo.active_branch.name + ', please wait a minute!'
            meta = '<meta http-equiv="refresh" content="20">'

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

            subprocess.call([
                'pip', 'install', '-r',
                os.path.join(FILE_DIR, 'requirements/pip-requirements.txt')
            ])
            restartServer()
コード例 #6
0
    def settings_post(self, s):
        update = checkupdate()
        confJSON = json.dumps(configuration)
        public_url = getTunnelUrl()
        logs = readFile(LOGFILE)
        code = readFile(CONFIGFILE)
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'

        if (s.form.get("save")):
            textToSave = s.form.get("save", None)
            codeToSave = textToSave.replace("+", " ")
            saveFile(CONFIGFILE, codeToSave)
            message = 'Config saved'
            logger.info(message)

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if (s.form.get("backup")):
            codeToSave = readFile(CONFIGFILE)
            saveFile('config.yaml.bak', codeToSave)
            message = 'Backup saved'
            logger.info(message)

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)

        if (s.form.get("restart")):
            message = 'Restart Server, please wait!'
            meta = '<meta http-equiv="refresh" content="5">'
            code = ''
            logs = ''

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)

            s.send_message(200, template)
            restartServer()

        if (s.form.get("sync")):
            if configuration[
                    'Homegraph_API_Key'] != 'ADD_YOUR HOMEGRAPH_API_KEY_HERE':
                r = self.forceDevicesSync()
                time.sleep(0.5)
                if r == True:
                    message = 'Devices syncronized'
                else:
                    message = 'Homegraph api key not valid!'
            else:
                message = 'Add Homegraph api key to sync devices here!'

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("reload")):
            message = ''

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("deletelogs")):
            logfile = os.path.join(FILE_DIR, LOGFILE)
            if os.path.exists(logfile):
                f = open(logfile, 'w')
                f.close()
            logger.info('Logs removed by user')
            message = ''

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)

        if (s.form.get("update")):
            repo.git.reset('--hard')
            repo.remotes.origin.pull()
            message = 'Updated, Restarting Server, please wait!'
            meta = '<meta http-equiv="refresh" content="5">'

            template = TEMPLATE.format(message=message,
                                       uptime=uptime(),
                                       list=deviceList,
                                       meta=meta,
                                       code=code,
                                       conf=confJSON,
                                       public_url=public_url,
                                       logs=logs,
                                       update=update)
            s.send_message(200, template)
            restartServer()