def GET(self): global sender qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) state = helpers.get_input(qdict, 'state', False, lambda x: True) if sender is not None and 'test' in qdict: test = qdict['test'] if state: log.clear(NAME) log.info(NAME, _(u'Test CMD: {} ON.').format(int(test) + 1)) command = plugin_options['on'] data = command[int(test)] if data: run_command(data) else: log.clear(NAME) log.info(NAME, _(u'Test CMD: {} OFF.').format(int(test) + 1)) command = plugin_options['off'] data = command[int(test)] if data: run_command(data) if sender is not None and delete: write_log([]) log.info(NAME, _(u'Deleted all log files OK')) raise web.seeother(plugin_url(settings_page), True) if sender is not None and show: raise web.seeother(plugin_url(log_page), True) return self.plugin_render.cli_control(plugin_options, log.events(NAME))
def GET(self): global wind_sender qdict = web.input() reset = helpers.get_input(qdict, 'reset', False, lambda x: True) delete = helpers.get_input(qdict, 'delete', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) if wind_sender is not None and reset: wind_sender.status['max_meter'] = 0 wind_sender.status['log_date_maxspeed'] = datetime_string() log.clear(NAME) log.info( NAME, datetime_string() + ' ' + _(u'Maximal speed has reseted.')) raise web.seeother(plugin_url(settings_page), True) if wind_sender is not None and delete: write_log([]) create_default_graph() log.info(NAME, datetime_string() + ' ' + _(u'Deleted all log files OK')) raise web.seeother(plugin_url(settings_page), True) if wind_sender is not None and 'history' in qdict: history = qdict['history'] wind_options.__setitem__('history', int(history)) if wind_sender is not None and show: raise web.seeother(plugin_url(log_page), True) return self.plugin_render.wind_monitor(wind_options, wind_sender.status, log.events(NAME))
def POST(self): global saved_emails email_options.web_update(web.input()) qdict = web.input() test = get_input(qdict, 'test', False, lambda x: True) delete = get_input(qdict, 'del', False, lambda x: True) if email_sender is not None: email_sender.update() if test: regex = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+') # SMTP username if not re.fullmatch(regex, email_options['emlusr']): log.clear(NAME) log.info(NAME,datetime_string() + ': ' + _(u'Sender e-mail address appears to be invalid!')) raise web.seeother(plugin_url(settings_page), True) body = datetime_string() + ': ' + _(u'This is test e-mail from OSPy. You can ignore it.') logtext = _(u'This is test e-mail from OSPy. You can ignore it.') try_mail(body, logtext) if delete: log.info(NAME, datetime_string() + ': ' + _(u'Email Queue was deleted.')) write_email([]) saved_emails = 0 raise web.seeother(plugin_url(settings_page), True)
def POST(self): x = web.input(myfile={}) #web.debug(x['myfile'].filename) # This is the filename #web.debug(x['myfile'].value) # This is the file contents #web.debug(x['myfile'].file.read()) # Or use a file(-like) object try: name = '' name = x['myfile'].filename if name in ('voice.mp3', 'voice0.mp3', 'voice1.mp3', 'voice2.mp3', 'voice3.mp3', 'voice4.mp3', 'voice5.mp3', 'voice6.mp3', 'voice7.mp3', 'voice8.mp3', 'voice9.mp3', 'voice10.mp3', 'voice11.mp3', 'voice12.mp3', 'voice13.mp3', 'voice14.mp3', 'voice15.mp3', 'voice16.mp3', 'voice17.mp3', 'voice18.mp3', 'voice19.mp3', 'voice20.mp3'): fout = open(os.path.join(MP3_FILE_FOLDER, name), 'w') fout.write(x['myfile'].file.read()) fout.close() log.info(NAME, _('Saving MP3 %s file OK.') % name) else: log.info( NAME, _('Error. MP3 file: %s name is not voice.mp3 or voice0.mp3...voice20.mp3' ) % name) except Exception: log.error( NAME, _('Voice Notification plug-in') + ':\n' + traceback.format_exc()) raise web.seeother(plugin_url(settings_page), True)
def POST(self): remote_options.web_update(web.input()) qdict = web.input() test = get_input(qdict, 'test', False, lambda x: True) if remote_sender is not None: remote_sender.update() if test: body = ('tank=256') body += ('&percent=100') body += ('&ping=25') body += ('&volume=10.2') body += ('&rain=0') body += ('&humi=25') body += ('&line=1') body += ('&lastrun=2019-09-06_08:00:00') body += ('&station=test') body += ('&duration=00:59') body += ('&program=test_data') body += ('&temp1=28.5') body += ('&temp2=12') body += ('&temp3=-51') body += ('&temp4=23.5') body += ('&temp5=45') body += ('&temp6=-127') body += ('&tempDHT=27') body += ('&humiDHT=50') body += ('&api=' + remote_options['api']) # API password remote_sender.try_send(body) raise web.seeother(plugin_url(settings_page), True)
def GET(self): global sender qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) test = helpers.get_input(qdict, 'test', False, lambda x: True) msg = 'none' position = None test_btn = None if sender is not None and delete: write_log([]) log.info(NAME, _('Deleted all log files OK.')) raise web.seeother(plugin_url(setup_page), True) if sender is not None and test: if 'pos' in qdict: position = int(qdict['pos']) test_btn = int(qdict['test']) if position is not None and position == -1: pos_msg = _('close') elif position is not None and position == 0: pos_msg = _('stop') elif position is not None and position == 1: pos_msg = _('open') else: pos_msg = _('unkown state.') log.info( NAME, _('Test for blind {}, position {}.').format( test_btn + 1, pos_msg)) msg = send_cmd_to_blind(test_btn, position) #raise web.seeother(plugin_url(setup_page), True) return self.plugin_render.venetian_blind_setup(plugin_options, msg) return self.plugin_render.venetian_blind_setup(plugin_options, msg)
def POST(self): plugin_options.web_update(web.input()) if checker is not None: checker.update() checker.update_wait() raise web.seeother(plugin_url(status_page), True)
def POST(self): qdict = web.input() #print 'qdict: ', qdict try: ### add code to update commands ### if 'use_control' in qdict: if qdict['use_control'] == 'on': plugin_options.__setitem__( 'use_control', True) #__setitem__(self, key, value) else: plugin_options.__setitem__('use_control', False) commands = {u'on': [], u'off': []} for i in range(options.output_count): commands['on'].append(qdict['con' + str(i)]) commands['off'].append(qdict['coff' + str(i)]) #print 'commands: ', commands plugin_options.__setitem__('on', commands['on']) plugin_options.__setitem__('off', commands['off']) #print 'plugin_options:', plugin_options if sender is not None: sender.update() except Exception: log.error( NAME, _('CLI Control plug-in') + ':\n' + traceback.format_exc()) raise web.seeother(plugin_url(settings_page), True)
def POST(self): lcd_options.web_update(web.input()) if lcd_sender is not None: lcd_sender.update() raise web.seeother(plugin_url(settings_page), True)
def GET(self): global sender qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) test = helpers.get_input(qdict, 'test', False, lambda x: True) if sender is not None and delete: write_log([]) create_default_graph() raise web.seeother(plugin_url(settings_page), True) if sender is not None and test: log.clear(NAME) try: new_speeds = get_new_speeds() sender._sleep(2) tempText = _( 'Ping {} ms, Download {} Mb/s, Upload {} Mb/s').format( sender.status['ping'], sender.status['down'], sender.status['up']) except: new_speeds = 0, 0, 0 tempText = _('Cannot be loaded') log.error( NAME, _('Speed Monitor plug-in') + ':\n' + traceback.format_exc()) pass sender.status['ping'] = new_speeds[0] # Ping (ms) sender.status['down'] = new_speeds[1] # Download (Mb/s) sender.status['up'] = new_speeds[2] # Upload (Mb/s) log.info( NAME, datetime_string() + ' ' + _('Test button') + '\n' + tempText) raise web.seeother(plugin_url(settings_page), True) if sender is not None and 'history' in qdict: history = qdict['history'] speed_options.__setitem__('history', int(history)) if sender is not None and show: raise web.seeother(plugin_url(log_page), True) return self.plugin_render.speed_monitor(speed_options, log.events(NAME))
def GET(self): log.clear(NAME) cmd = "sudo echo 'bcm2708_wdog' >> /etc/modules" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo echo 'bcm2835_wdog' >> /etc/modules" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo echo 'bcm2711_wdt' >> /etc/modules" log.debug(NAME, cmd) run_process(cmd) try: cmd = "sudo modprobe bcm2708_wdog" log.debug(NAME, cmd) run_process(cmd) except: try: cmd = "sudo modprobe bcm2835_wdog" log.debug(NAME, cmd) run_process(cmd) except: cmd = "sudo modprobe bcm2711_wdog" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo apt-get install -y watchdog chkconfig" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo chkconfig watchdog on" log.debug(NAME, cmd) run_process(cmd) log.debug(NAME, _('Saving config to /etc/watchdog.conf')) # http://linux.die.net/man/5/watchdog.conf f = open("/etc/watchdog.conf", "wb") f.write("watchdog-device = /dev/watchdog\n") f.write("watchdog-timeout = 14\n") f.write("realtime = yes\n") f.write("priority = 1\n") f.write("interval = 4\n") f.write("max-load-1 = 24\n") f.close() cmd = "sudo systemctl enable watchdog" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo systemctl daemon-reload" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo systemctl start watchdog" log.debug(NAME, cmd) run_process(cmd) reboot(True) # reboot HW software after instal watchdog msg = _( 'The system (Linux) will now restart (restart started by the user in the Watch-dog plugins), please wait for the page to reload.' ) return self.core_render.notice(plugin_url(status_page), msg)
def GET(self): global sender, status, avg_lst, avg_cnt, avg_rdy qdict = web.input() reset = helpers.get_input(qdict, 'reset', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) debug = helpers.get_input(qdict, 'debug', False, lambda x: True) del_rain = helpers.get_input(qdict, 'del_rain', False, lambda x: True) log_now = helpers.get_input(qdict, 'log_now', False, lambda x: True) if sender is not None and reset: status['minlevel'] = status['level'] status['maxlevel'] = status['level'] tank_options['saved_max'] = status['level'] tank_options['saved_min'] = status['level'] status['minlevel_datetime'] = datetime_string() status['maxlevel_datetime'] = datetime_string() log.info( NAME, datetime_string() + ': ' + _(u'Minimum and maximum has reseted.')) raise web.seeother(plugin_url(settings_page), True) if sender is not None and log_now: update_log() if sender is not None and 'history' in qdict: history = qdict['history'] tank_options.__setitem__('history', int(history)) if sender is not None and show: raise web.seeother(plugin_url(log_page), True) if sender is not None and debug: raise web.seeother(plugin_url(log_debug_page), True) if sender is not None and del_rain: if NAME in rain_blocks: del rain_blocks[NAME] log.info( NAME, datetime_string() + ': ' + _(u'Removing Rain Delay') + '.') raise web.seeother(plugin_url(settings_page), True) return self.plugin_render.tank_monitor(tank_options, log.events(NAME))
def POST(self): plugin_options.web_update(web.input()) if checker is not None: checker.update() msg = _( u'OSPy is now updated from Github and restarted. Please wait...') raise web.seeother(plugin_url(update_page), msg) # ((status_page), True)
def GET(self): web.header('Access-Control-Allow-Origin', '*') web.header('Content-Type', 'image/jpeg') try: with open(get_image_location()) as f: return f.read() except: log.info(NAME, _('No image file from downloading. Retry')) raise web.seeother(plugin_url(settings_page), True)
def POST(self): global sender plugin_options.web_update(web.input()) if sender is not None: sender.update() log.clear(NAME) raise web.seeother(plugin_url(settings_page), True)
def POST(self): global sender plugin_options.web_update(web.input()) if sender is not None: sender.join(5) sender = PluginSender() raise web.seeother(plugin_url(start_page), True)
def POST(self): qdict = web.input() months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] vals = {} for index, month in enumerate(months): vals[index] = max(0, min(10000, int(float(qdict[month])))) plugin_options.web_update(vals) if checker is not None: checker.update() raise web.seeother(plugin_url(settings_page), True)
def POST(self): speed_options.web_update( web.input(**speed_options)) #for save multiple select if sender is not None: sender.update() log.clear(NAME) log.info(NAME, _(u'Options has updated.')) raise web.seeother(plugin_url(settings_page), True)
def POST(self): options.__setitem__('sum', 0) log.clear(NAME) log.info(NAME, _('Water summary was reseting...')) log.info(NAME, _('Water in liters')) log.info(NAME, _('Water summary') + ': ' + str(options['sum'])) if water_sender is not None: water_sender.update() raise web.seeother(plugin_url(settings_page), True)
def GET(self): qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) if delete: try: os.remove(log.EVENT_FILE) except Exception: pass raise web.seeother(plugin_url(status_page), True) return self.plugin_render.system_debug(debug_options, get_overview())
def GET(self): global sender qdict = web.input() stop = helpers.get_input(qdict, 'stop', False, lambda x: True) if sender is not None and stop: sender.stop() sender.join(5) sender = None raise web.seeother(plugin_url(start_page), True) return self.plugin_render.pulse(pulse_options, log.events(NAME))
def GET(self): global ups_sender qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) if ups_sender is not None and delete: write_log([]) create_default_graph() raise web.seeother(plugin_url(settings_page), True) if ups_sender is not None and 'history' in qdict: history = qdict['history'] ups_options.__setitem__('history', int(history)) if ups_sender is not None and show: raise web.seeother(plugin_url(log_page), True) return self.plugin_render.ups_adj(ups_options, ups_sender.status, log.events(NAME))
def POST(self): qdict = web.input( skip_stations=[]) # skip_stations [] for multiple select try: if 'enabled' in qdict: if qdict['enabled'] == 'on': plugin_options.__setitem__('enabled', True) else: plugin_options.__setitem__('enabled', False) if 'voice_start_station' in qdict: plugin_options.__setitem__('voice_start_station', qdict['voice_start_station']) if 'pre_time' in qdict: plugin_options.__setitem__('pre_time', qdict['pre_time']) if 'repeating' in qdict: plugin_options.__setitem__('repeating', qdict['repeating']) if 'skip_stations' in qdict: plugin_options.__setitem__('skip_stations', qdict['skip_stations']) if 'volume' in qdict: plugin_options.__setitem__('volume', qdict['volume']) if 'start_hour' in qdict: plugin_options.__setitem__('start_hour', qdict['start_hour']) if 'stop_hour' in qdict: plugin_options.__setitem__('stop_hour', qdict['stop_hour']) commands = {'on': [], 'off': []} for i in range(0, options.output_count): if 'con' + str(i) in qdict: commands['on'].append(int(qdict['con' + str(i)])) else: commands['on'].append(-1) plugin_options.__setitem__('on', commands['on']) if checker is not None: checker.update() except Exception: log.error( NAME, _(u'Voice Notification plug-in') + ':\n' + traceback.format_exc()) raise web.seeother(plugin_url(settings_page), True)
def GET(self): global lcd_sender qdict = web.input() refind = helpers.get_input(qdict, 'refind', False, lambda x: True) if lcd_sender is not None and refind: lcd_options['address'] = 0 log.clear(NAME) log.info(NAME, _('I2C address has re-finded.')) find_lcd_address() raise web.seeother(plugin_url(settings_page), True) return self.plugin_render.lcd_display(lcd_options, log.events(NAME))
def GET(self): log.clear(NAME) cmd = "sudo systemctl start watchdog" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo systemctl enable watchdog" log.debug(NAME, cmd) run_process(cmd) cmd = "sudo systemctl daemon-reload" log.debug(NAME, cmd) run_process(cmd) restart(3) return self.core_render.restarting(plugin_url(status_page))
def GET(self): try: web.header('Access-Control-Allow-Origin', '*') content = mimetypes.guess_type(get_image_location())[0] web.header('Content-type', content) web.header( 'Content-Disposition', 'attachment; filename=' + u'OSPy camera {}.jpg'.format(options.name)) with open(get_image_location()) as f: return f.read() except: log.info(NAME, _(u'No image file from downloading. Retry')) raise web.seeother(plugin_url(settings_page), True)
def POST(self): email_options.web_update(web.input()) qdict = web.input() test = get_input(qdict, 'test', False, lambda x: True) if email_sender is not None: email_sender.update() if test: body = (datetime_string() + ': Test e-mail from e-mail notification plugin :-).') email_sender.try_mail(body) raise web.seeother(plugin_url(settings_page), True)
def GET(self): global sender qdict = web.input() delete = helpers.get_input(qdict, 'delete', False, lambda x: True) show = helpers.get_input(qdict, 'show', False, lambda x: True) if sender is not None and delete: write_log([]) create_default_graph() log.info(NAME, _(u'Deleted all log files OK')) raise web.seeother(plugin_url(settings_page), True) if sender is not None and 'history' in qdict: history = qdict['history'] plugin_options.__setitem__( 'history', int(history)) #__setitem__(self, key, value) if sender is not None and show: raise web.seeother(plugin_url(log_page), True) return self.plugin_render.air_temp_humi(plugin_options, log.events(NAME))
def POST(self): plugin_options.web_update(web.input()) if checker is not None: checker.update() if plugin_options['enabled']: log.clear(NAME) log.info(NAME, _('Pressurizer is enabled.')) else: log.clear(NAME) log.info(NAME, _('Pressurizer is disabled.')) log.info(NAME, _('Options has updated.')) raise web.seeother(plugin_url(settings_page), True)
def GET(self): global sender, status qdict = web.input() reset = helpers.get_input(qdict, 'reset', False, lambda x: True) if sender is not None and reset: plugin_options.__setitem__('sum_one', 0) plugin_options.__setitem__('sum_two', 0) plugin_options.__setitem__('last_reset', datetime_string()) log.clear(NAME) log.info(NAME, datetime_string() + ': ' + _(u'Counter has reseted')) raise web.seeother(plugin_url(settings_page), True) return self.plugin_render.water_consumption_counter(plugin_options, log.events(NAME))