def update_account(): form = AccountDataForm() user = g.user if request.method == 'GET': form.email.data = user.email form.language.data = user.language form.timezone.data = user.timezone elif request.method == 'POST' and form.validate_on_submit(): if password_hash(form.old_password.data) != user.password: form.old_password.errors.append(_('Wrong password')) return render_template('update_account.html', form=form) if form.email.data != user.email: user.email = form.email.data user.confirmed = False user.confirmation_string = random_string(20) msg = message_confirmation(user.id, user.email, user.confirmation_string) mail.send(msg) flash(_('Confirmation message sent, check your e-mail')) if form.password.data: user.password = password_hash(form.password.data) flash(_('Password successfully changed')) user.language = form.language.data user.timezone = form.timezone.data db.session.commit() return redirect('update_account') return render_template('update_account.html', form=form)
def GET(self): qdict = web.input() web.header('Access-Control-Allow-Origin', '*') web.header('Content-Type', 'application/json') web.header('Cache-Control', 'no-cache') if not(qdict.has_key('pw')) or not(qdict.has_key('npw')) or not(qdict.has_key('cpw')): return json.dumps({"result":3}) if password_hash(qdict['pw'], gv.sd['salt']) == gv.sd['password']: if qdict['npw'] == "": return json.dumps({"result":3}) elif qdict['cpw'] !='' and qdict['cpw'] == qdict['npw']: gv.sd['password'] = password_hash(qdict['npw'], gv.sd['salt']) else: return json.dumps({"result":4}) else: return json.dumps({"result":2}) return json.dumps({"result":1})
def GET(self): qdict = web.input() web.header('Access-Control-Allow-Origin', '*') web.header('Content-Type', 'application/json') web.header('Cache-Control', 'no-cache') if not (qdict.has_key('pw')) or not (qdict.has_key('npw')) or not ( qdict.has_key('cpw')): return json.dumps({"result": 3}) if password_hash(qdict['pw'], gv.sd['salt']) == gv.sd['password']: if qdict['npw'] == "": return json.dumps({"result": 3}) elif qdict['cpw'] != '' and qdict['cpw'] == qdict['npw']: gv.sd['password'] = password_hash(qdict['npw'], gv.sd['salt']) else: return json.dumps({"result": 4}) else: return json.dumps({"result": 2}) return json.dumps({"result": 1})
def sign_in(): form = SignInForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data, password=password_hash(form.password.data)).first() if user is None: flash(_('Wrong email or password')) elif user.active is False: flash(_('Your account is deactivated')) elif user.confirmed is False: flash(_('Your account is not confirmed')) else: session['user_id'] = user.id user.signed_in = datetime.datetime.utcnow() db.session.commit() flash(_('Successfully signed in')) return redirect('') return render_template('sign_in.html', form=form)
def account_problem(): form = AccountProblemForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None: form.email.errors.append(_('Unknown e-mail address')) elif form.problem.data == 'confirmation': msg = message_confirmation(user.id, user.email, user.confirmation_string) mail.send(msg) flash(_('Confirmation message sent, check your e-mail')) return redirect('') elif form.problem.data == 'password': new_password = random_string(10) user.password = password_hash(new_password) db.session.commit() msg = message_reset_password(user.email, new_password) mail.send(msg) flash(_('Your password was reset, check your e-mail')) return redirect('') return render_template('account_problem.html', form=form)
def sign_up(): form = SignUpForm() if form.validate_on_submit(): user = User() user.email = form.email.data user.password = password_hash(form.password.data) user.signed_up = datetime.datetime.utcnow() user.language = form.language.data user.timezone = form.timezone.data user.confirmation_string = random_string(20) db.session.add(user) try: db.session.commit() except IntegrityError as err: if err.message.find(user.email) != -1: form.email.errors.append(_('E-mail address is in use')) else: msg = message_confirmation(user.id, user.email, user.confirmation_string) mail.send(msg) flash(_('Successful sign up, check your e-mail')) return redirect('') return render_template('sign_up.html', form=form)
u"mm": 0, u"mo": [0], u"rbt": 0, u"mtoff": 0, u"nprogs": 1, u"nbrd": 1, u"tu": u"C", u"snlen": 32, u"name": u"SIP", u"theme": u"basic", u"show": [255], u"salt": password_salt(), u"lang": u"default" } sd['password'] = password_hash('opendoor', sd['salt']) try: with open('./data/sd.json', 'r') as sdf: # A config file sd_temp = json.load(sdf) for key in sd: # If file loaded, replce default values in sd with values from file if key in sd_temp: sd[key] = sd_temp[key] except IOError: # If file does not exist, it will be created using defaults. with open('./data/sd.json', 'w') as sdf: # save file json.dump(sd, sdf) nowt = time.localtime() now = timegm(nowt) tz_offset = int( time.time() - timegm(time.localtime())
def POST(self): global error_msg, been_through_subconfig been_through_subconfig = False self.logger.debug('in Sub POST') save_last_get('Sub POST') error_msg = '' form = web.input() continuation = '/cn' try: gv.sd['master'] = 1 if 'Master Station' in form else 0 gv.sd['slave'] = 1 if 'Substation' in form else 0 gv.sd['subnet_only_substations'] = 0 if 'Enable Remote Substations' in form else 1 form['Radio Only Substation Name'] = form['Radio Only Substation Name'].strip() if 'Radio Only Substation Name' in form else '' radio_only_substation = len(form['Radio Only Substation Name']) > 0 if not radio_only_substation: gv.sd['remote_radio_substation'] = 1 if 'Only Radio Access' in form else 0 if not gv.sd['master'] and not gv.sd['slave'] and not radio_only_substation: error_msg = 'At least one of "Master Substation" or "Substation" must be checked.' raise web.seeother('/su') # back to form for f in ['Master IP', 'Master Port', 'System Network Name', 'Radio Power', 'Radio Network Name', 'Radio Router Number', 'Radio Only Substation Name']: if f in form: form[f] = form[f].strip() if not radio_only_substation and len(form['Master IP']) == 0: error_msg = '"Master IP" must not be blank' raise web.seeother('/su') # back to form gv.sd['master_ip'] = form['Master IP'] gv.sd['substation_network'] = form['System Network Name'] if 'Radio Power' in form: try: power = int(form['Radio Power']) except: power = -1 jsave(gv.sd, 'sd') actual_power = power & ~0x10 # disable the "hard power" bit if actual_power < 0 or actual_power > 5: error_msg = 'Error: "Radio Power" must be integer between 0 and 4 inclusive.' raise web.seeother('/su') # back to form # if len(form['Radio Network Name']) < 1: # error_msg = 'Error: "Radio Network Name" must be non-empty.' # raise web.seeother('/su') # back to form if len(form['Radio Network Name']) > 0: radio_network_hash = password_hash(form['Radio Network Name'], 'notarandomstring')[:16] cmd = ['python', 'substation_proxy.py', '--onetime', '--power='+str(power), '--key='+radio_network_hash] else: cmd = ['python', 'substation_proxy.py', '--onetime', '--power='+str(power)] router_id = 255 type = 'base' if not gv.sd['remote_radio_substation'] else 'remote' self.logger.info('initial radio type: ' + type) if len(form['Radio Router Number']) > 0 and form['Radio Router Number'] != '0': try: router_id = int(form['Radio Router Number']) except: router_id = 254 if router_id < 1 or router_id > 63: error_msg = 'Error: "Radio Router Number" must be between 1 and 63 inclusive.' raise web.seeother('/su') # back to form cmd.append('--radio_routing='+str(router_id)) type = 'router' if radio_only_substation: if len(form['Radio Only Substation Name']) > 12: error_msg = 'Error: "Radio Only Substation Name" must be unique and between 1 and 12 characters.' raise web.seeother('/su') # back to form elif form['Radio Only Substation Name'] == 'localhost': error_msg = 'Error: "Radio Only Substation Name" must not be "localhost".' raise web.seeother('/su') # back to form cmd.append('--radio_name='+form['Radio Only Substation Name']) type = 'remote' # radio only substations are never base radios cmd.append('--type='+type) # get pid of substation_proxy. # Tell sip_monitor to not restart it. # Kill it, then setparameters, then allow sip_monitor to restart it proxy_info = subprocess.check_output("/bin/ps auwx | /bin/grep -e substation_proxy", shell=True) l = proxy_info.split('\n') kill_list = ['kill', '-9'] for e in l: if 'grep -e' not in e and e != '': word_list = re.sub('[^\w]', ' ', e).split() kill_list.append(word_list[1]) subprocess.call(['touch', 'data/substation_proxy_pause']) try: if len(kill_list) > 2: subprocess.call(kill_list) self.logger.info('Executing cmd: ' + " ".join(cmd)) subprocess.call(cmd) self.logger.info('removing substation_proxy_pause') subprocess.call(['rm', 'data/substation_proxy_pause']) except Exception as ex: self.logger.info('removing substation_proxy_pause ex: ' + str(ex)) subprocess.call(['rm', 'data/substation_proxy_pause']) raise if radio_only_substation: continuation = '/cc' else: jsave(gv.sd, 'sd') except Exception as ex: self.logger.info('finish ex: ' + str(ex)) raise web.seeother('/su') # back to form if continuation != '/cc': regenerate_ssh_keys() self.logger.debug('Sub POST been_through True. continuation: ' + continuation) been_through_subconfig = True raise web.seeother(continuation) # configure network parameters
u"rst": 1, u"mm": 0, u"mo": [0], u"rbt": 0, u"mtoff": 0, u"nprogs": 1, u"nbrd": 1, u"tu": u"C", u"snlen": 32, u"name": u"OpenSprinkler Pi", u"theme": u"basic", u"show": [255], u"salt": password_salt() } sd['password'] = password_hash('opendoor', sd['salt']) try: with open('./data/sd.json', 'r') as sdf: # A config file sd_temp = json.load(sdf) for key in sd: # If file loaded, replce default values in sd with values from file if key in sd_temp: sd[key] = sd_temp[key] except IOError: # If file does not exist, it will be created using defaults. with open('./data/sd.json', 'w') as sdf: # save file json.dump(sd, sdf) now = timegm(time.localtime()) gmtnow = time.time() plugin_menu = [] # Empty list of lists for plugin links (e.g. ['name', 'URL'])
u"etok": 0, u"etbase": 7.0, u"etmin": 0, u"etmax": 200, u"ethistory": 1, u"etforecast": 1, u"etapi": u"", u"light_ip": 1, } for i in range(5): sd['teadr' + str(i)] = '' sd['tesmsnbr' + str(i)] = '' sd['tesmsprovider' + str(i)] = '' sd['password'] = password_hash('Irricloud', sd['salt']) remote_sensors = {} remote_zones = {} in_bootloader = {} # make no VSB look like in bootloader try: with open('./data/sd.json', 'r') as sdf: # A config file sd_temp = json.load(sdf) added_key = False for key in sd: # If file loaded, replce default values in sd with values from file if key in sd_temp: sd[key] = sd_temp[key] else: added_key = True if added_key: # force write
def POST(self): global error_msg, been_through_subconfig been_through_subconfig = False self.logger.debug('in Sub POST') save_last_get('Sub POST') error_msg = '' form = web.input() continuation = '/cn' try: gv.sd['master'] = 1 if 'Master Station' in form else 0 gv.sd['slave'] = 1 if 'Substation' in form else 0 gv.sd[ 'subnet_only_substations'] = 0 if 'Enable Remote Substations' in form else 1 if not gv.sd['master'] and not gv.sd[ 'slave'] and 'Radio Only Substation' not in form: error_msg = 'At least one of "Master Substation" or "Substation" must be checked.' raise web.seeother('/su') # back to form for f in [ 'Master IP', 'Master Port', 'System Network Name', 'Radio Power', 'Radio Network Name', 'Radio Router Number', 'Radio Only Substation Name' ]: if f in form: form[f] = form[f].strip() gv.sd['master_ip'] = form['Master IP'] gv.sd['substation_network'] = form['System Network Name'] if 'Radio Power' in form: try: power = int(form['Radio Power']) except: power = -1 jsave(gv.sd, 'sd') actual_power = power & ~0x10 # disable the "hard power" bit if actual_power < 0 or actual_power > 5: error_msg = 'Error: "Radio Power" must be integer between 0 and 4 inclusive.' raise web.seeother('/su') # back to form # if len(form['Radio Network Name']) < 1: # error_msg = 'Error: "Radio Network Name" must be non-empty.' # raise web.seeother('/su') # back to form if len(form['Radio Network Name']) > 0: radio_network_hash = password_hash( form['Radio Network Name'], 'notarandomstring')[:16] cmd = [ 'python', 'substation_proxy.py', '--onetime', '--power=' + str(power), '--key=' + radio_network_hash ] else: cmd = [ 'python', 'substation_proxy.py', '--onetime', '--power=' + str(power) ] router_id = 255 type = 'base' if gv.sd['master_ip'] else 'remote' self.logger.info('initial radio type: ' + type) if len(form['Radio Router Number'] ) > 0 and form['Radio Router Number'] != '0': try: router_id = int(form['Radio Router Number']) except: router_id = 254 if router_id < 1 or router_id > 63: error_msg = 'Error: "Radio Router Number" must be between 1 and 63 inclusive.' raise web.seeother('/su') # back to form cmd.append('--radio_routing=' + str(router_id)) type = 'router' if 'Radio Only Substation' in form: if len(form['Radio Only Substation Name']) > 12 or len( form['Radio Only Substation Name']) < 1: error_msg = 'Error: "Radio Only Substation Name" must be unique and between 1 and 12 characters.' raise web.seeother('/su') # back to form elif form['Radio Only Substation Name'] == 'localhost': error_msg = 'Error: "Radio Only Substation Name" must not be "localhost".' raise web.seeother('/su') # back to form cmd.append('--radio_name=' + form['Radio Only Substation Name']) type = 'remote' # radio only substations are never base radios cmd.append('--type=' + type) # get pid of substation_proxy. # Tell sip_monitor to not restart it. # Kill it, then setparameters, then allow sip_monitor to restart it proxy_info = subprocess.check_output( "/bin/ps auwx | /bin/grep -e substation_proxy", shell=True) l = proxy_info.split('\n') kill_list = ['kill', '-9'] for e in l: if 'grep -e' not in e and e != '': word_list = re.sub('[^\w]', ' ', e).split() kill_list.append(word_list[1]) subprocess.call(['touch', 'data/substation_proxy_pause']) try: if len(kill_list) > 2: subprocess.call(kill_list) self.logger.info('Executing cmd: ' + " ".join(cmd)) subprocess.call(cmd) self.logger.info('removing substation_proxy_pause') subprocess.call(['rm', 'data/substation_proxy_pause']) except Exception as ex: self.logger.info('removing substation_proxy_pause ex: ' + str(ex)) subprocess.call(['rm', 'data/substation_proxy_pause']) raise if 'Radio Only Substation' in form: continuation = '/cc' else: jsave(gv.sd, 'sd') except Exception as ex: self.logger.info('finish ex: ' + str(ex)) raise web.seeother('/su') # back to form if continuation != '/cc': regenerate_ssh_keys() self.logger.debug('Sub POST been_through True. continuation: ' + continuation) been_through_subconfig = True raise web.seeother(continuation) # configure network parameters
u"mm": 0, u"mo": [0], u"rbt": 0, u"mtoff": 0, u"nprogs": 1, u"nbrd": 1, u"tu": u"C", u"snlen": 32, u"name": u"SIP", u"theme": u"basic", u"show": [255], u"salt": password_salt(), u"lang": u"default", } sd["password"] = password_hash("opendoor", sd["salt"]) try: with open("./data/sd.json", "r") as sdf: # A config file sd_temp = json.load(sdf) for key in sd: # If file loaded, replce default values in sd with values from file if key in sd_temp: sd[key] = sd_temp[key] except IOError: # If file does not exist, it will be created using defaults. with open("./data/sd.json", "w") as sdf: # save file json.dump(sd, sdf) nowt = time.localtime() now = timegm(nowt) tz_offset = int(
u"ethistory":1, u"etforecast":1, u"etapi":u"", u"light_ip":1, u"extender_ssid":u"", u"extender_psk":u"", u"remote_radio_substation":0, } for i in range(5): sd['teadr'+str(i)] = '' sd['tesmsnbr'+str(i)] = '' sd['tesmsprovider'+str(i)] = '' subprocess.call(['touch', 'data/bdkg2']) sd['password'] = password_hash('Irricloud', sd['salt']) remote_sensors = {} remote_zones = {} in_bootloader = {} # make no VSB look like in bootloader try: with open('./data/sd.json', 'r') as sdf: # A config file sd_temp = json.load(sdf) added_key = False for key in sd: # If file loaded, replce default values in sd with values from file if key in sd_temp: sd[key] = sd_temp[key] else: added_key = True if added_key: # force write