def GET(self): qdict = web.input() try: ddict = json.loads(qdict['data']) except: raise web.unauthorized() validate_remote(ddict) # may raise unauthorized subj = '' body = '' try: subj = ddict['subject'] body = ddict['body'] if gv.sd['master']: email(subj, body) ret_str = json.dumps({'status':0}) else: gv.logger.error('mail not sent by slave body: ' + body) ret_str = json.dumps({'status':1}) except: gv.logger.exception('could not send email. subject: ' + subj + ' body: ' + body) ret_str = json.dumps({'status':2}) web.header('Content-Type', 'application/json') return ret_str
def GET(self): qdict = web.input() try: ddict = json.loads(qdict['data']) except: raise web.unauthorized() validate_remote(ddict) # may raise unauthorized ddict['last_join'] = gv.now ddict['status'] = 'ok' # gv.logger.debug('joining ip: ' + ddict['ip'] + ' name: ' + ddict['name'] + ' proxy: ' + ddict['proxy']) found_slave = 0 for i,d in enumerate(gv.plugin_data['su']['subinfo']): if i == 0: continue if d['name'] == ddict['name']: if d['ip'] != ddict['ip'] or d['port'] != ddict['port'] or d['proxy'] != ddict['proxy']: gv.logger.info('Substation ' + ddict['name'] + ' changed address from: ' + \ d['ip'] + ':' + str(d['port']) + ' to: ' + \ ddict['ip'] + ':' + str(ddict['port']) + \ '; proxy from: ' + d['proxy'] + ' to: ' + ddict['proxy']) su_strip = gv.plugin_data['su'].copy() for p in ['ip', 'port', 'proxy']: su_strip['subinfo'][i][p] = ddict[p] del su_strip['subdesc'] # dont save active data jsave(su_strip, 'substations') for p in ['ip', 'port', 'proxy', 'status', 'last_join']: gv.plugin_data['su']['subinfo'][i][p] = ddict[p] found_slave = i break if found_slave == 0: gv.logger.info('join_master adding substation: ' + ddict['name'] + ' at ip: ' + ddict['ip'] + ' proxy: ' + ddict['proxy']) mkdir_p('./data/imported_logs/'+ddict['name']+'/sensors') # get structure in place for log files gv.plugin_data['su']['subinfo'].append(ddict) found_slave = len(gv.plugin_data['su']['subinfo']) - 1 if gv.substation == '': gv.substation = ddict['name'] gv.substation_index = found_slave gv.plugin_data['su']['subdesc'].append(gv.plugin_data['su']['subdesc'][0].copy()) su_strip = gv.plugin_data['su'].copy() del su_strip['subdesc'] # dont save active data jsave(su_strip, 'substations') result = {'sd':{}, 'other':{}} web.header('Content-Type', 'application/json') for entry in gv.options: f = entry[2] if f in ['name', 'htp', 'nbrd', 'opw', 'npw', 'cpw', 'external_htp', 'enable_upnp', 'remote_support_port']: continue if len(f) > 2 and (f[0:2] == 'te' or f[0:2] == 'et'): # filter out email and et stuff unless explicitly added below continue result['sd'][f] = gv.sd[f] for f in ['tu', 'password', 'salt', 'wl_et_weather', 'teprogramrun', 'teipchange', 'tepoweron']: result['sd'][f] = gv.sd[f] result['other']['websession'] = web.config._session.user # capture login and logout result['other']['datetime'] = time.strftime("%a %d %b %Y %H:%M:%S", time.localtime()) return json.dumps(result)
def GET(self): qdict = web.input() try: ddict = json.loads(qdict['data']) except: raise web.unauthorized() validate_remote(ddict) # may raise unauthorized ddict['last_join'] = gv.now ddict['status'] = 'ok' # gv.logger.debug('joining ip: ' + ddict['ip'] + ' name: ' + ddict['name'] + ' proxy: ' + ddict['proxy']) found_slave = 0 for i,d in enumerate(gv.plugin_data['su']['subinfo']): if i == 0: continue if d['name'] == ddict['name']: if d['ip'] != ddict['ip'] or d['port'] != ddict['port'] or d['proxy'] != ddict['proxy']: gv.logger.info('Substation changed address from: ' + \ d['ip'] + ':' + str(d['port']) + ' to: ' + \ ddict['ip'] + ':' + str(ddict['port']) + \ '; proxy from: ' + d['proxy'] + ' to: ' + ddict['proxy']) su_strip = gv.plugin_data['su'].copy() for p in ['ip', 'port', 'proxy']: su_strip['subinfo'][i][p] = ddict[p] del su_strip['subdesc'] # dont save active data jsave(su_strip, 'substations') for p in ['ip', 'port', 'proxy', 'status', 'last_join']: gv.plugin_data['su']['subinfo'][i][p] = ddict[p] found_slave = i break if found_slave == 0: gv.logger.info('join_master adding substation: ' + ddict['name'] + ' at ip: ' + ddict['ip'] + ' proxy: ' + ddict['proxy']) gv.plugin_data['su']['subinfo'].append(ddict) found_slave = len(gv.plugin_data['su']['subinfo']) - 1 if gv.substation == '': gv.substation = ddict['name'] gv.substation_index = found_slave gv.plugin_data['su']['subdesc'].append(gv.plugin_data['su']['subdesc'][0].copy()) su_strip = gv.plugin_data['su'].copy() del su_strip['subdesc'] # dont save active data jsave(su_strip, 'substations') result = {'sd':{}, 'other':{}} web.header('Content-Type', 'application/json') for entry in gv.options: f = entry[2] if f in ['name', 'htp', 'nbrd', 'opw', 'npw', 'cpw', 'external_htp', 'enable_upnp', 'remote_support_port']: continue if len(f) > 2 and (f[0:2] == 'te' or f[0:2] == 'et'): # filter out email and et stuff unless explicitly added below continue result['sd'][f] = gv.sd[f] for f in ['tu', 'password', 'salt', 'wl_et_weather', 'teprogramrun', 'teipchange', 'tepoweron']: result['sd'][f] = gv.sd[f] result['other']['websession'] = web.config._session.user # capture login and logout result['other']['datetime'] = time.strftime("%a %d %b %Y %H:%M:%S", time.localtime()) return json.dumps(result)