コード例 #1
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)
コード例 #2
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)
コード例 #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(self, s):
        user = self.getSessionUser()
        if user is None or user.get('uid', '') == '':
            s.redirect('login?redirect_uri={0}'.format('settings'))
            return

        enableReport = ReportState.enable_report_state()
        update = checkupdate()
        public_url = getTunnelUrl()
        message = ''
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
        code = readFile(os.path.join(FILE_DIR, CONFIGFILE))

        templatepage = env.get_template('home.html')
        s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))
コード例 #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):
        enableReport = ReportState.enable_report_state()
        update = checkupdate()
        public_url = getTunnelUrl()
        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 = 'Configuration saved. Restart DZGA for the settings to take effect'
            logger.info(message)
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

        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)
            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

        if s.form.get("restart"):
            meta = '<meta http-equiv="refresh" content="10">'
            message = 'Restarts DZGA server'

            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))
            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 in the UI! You can still sync by voice eg. "Hey Google, Sync my devices".'
            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

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

            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

        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'
            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))

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

            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))
            
            subprocess.call(['pip3', 'install','-r', os.path.join(FILE_DIR, 'requirements/pip-requirements.txt')])
            restartServer()
            
        if s.form.get("saveSettings"):
            savedSettings = json.loads(s.form.get("saveSettings", None))
            with open(os.path.join(FILE_DIR, CONFIGFILE), 'r') as conf_file:
                newsettings = yaml.safe_load(conf_file)
                newsettings.update(savedSettings)
                
            saveFile(CONFIGFILE, yaml.safe_dump(newsettings, allow_unicode=True))
            logger.info(yaml.dump(savedSettings))
            message = 'Settings saved. Restart DZGA for the settings to take effect'
            logger.info(message)
            logs = readFile(os.path.join(logfilepath, LOGFILE))
            templatepage = env.get_template('home.html')
            s.send_message(200, templatepage.render(message=message, uptime=uptime(), meta=meta, code=code,
                                       conf=configuration, public_url=public_url, update=update, keyfile=enableReport,
                                       branch=branch, dzversion=settings['dzversion'], dzgaversion=VERSION))
コード例 #7
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()