def __init__(self): self._values = {} self._write_timer = None self._callbacks = {} self._block = [] for info in self.OPTIONS: self._values[info["key"]] = info["default"] for ext in ['', '.tmp', '.bak']: try: db = shelve.open(OPTIONS_FILE + ext) if db.keys(): self._values.update(db) db.close() break else: db.close() except Exception: pass if not self.password_salt: # Password is not hashed yet from ospy.helpers import password_salt from ospy.helpers import password_hash self.password_salt = password_salt() self.password_hash = password_hash(self.password_hash, self.password_salt)
def POST(self): qdict = web.input() save_to_options(qdict) if 'master' in qdict: m = int(qdict['master']) if m < 0: stations.master = None elif m < stations.count(): stations.master = m if 'old_password' in qdict and qdict['old_password'] != "": try: if test_password(qdict['old_password']): if qdict['new_password'] == "": raise web.seeother('/options?errorCode=pw_blank') elif qdict['new_password'] == qdict['check_password']: options.password_salt = password_salt() # Make a new salt options.password_hash = password_hash(qdict['new_password'], options.password_salt) else: raise web.seeother('/options?errorCode=pw_mismatch') else: raise web.seeother('/options?errorCode=pw_wrong') except KeyError: pass raise web.seeother('/')
def check_password(): from ospy.options import options from ospy.helpers import test_password, password_salt, password_hash if not options.no_password and test_password('opendoor'): if yes_no('You are still using the default password, you should change it! Do you want to change it now?'): from getpass import getpass pw1 = pw2 = '' while True: pw1 = getpass('New password: '******'Repeat password: '******'' and pw1 == pw2: break print 'Invalid input!' options.password_salt = password_salt() # Make a new salt options.password_hash = password_hash(pw1, options.password_salt)
def check_password(): from ospy.options import options from ospy.helpers import test_password, password_salt, password_hash if not options.no_password and test_password('opendoor'): if yes_no( 'You are still using the default password, you should change it! Do you want to change it now?' ): from getpass import getpass pw1 = pw2 = '' while True: pw1 = getpass('New password: '******'Repeat password: '******'' and pw1 == pw2: break print 'Invalid input!' options.password_salt = password_salt() # Make a new salt options.password_hash = password_hash(pw1, options.password_salt)
def POST(self): qdict = web.input() change = False # if change language -> restart ospy if 'lang' in qdict and qdict['lang']: if options.lang != qdict['lang']: change = True qdict['name'] = qdict['name'] qdict['location'] = qdict['location'] qdict['darksky_key'] = qdict['darksky_key'] qdict['HTTP_web_ip'] = qdict['HTTP_web_ip'] save_to_options(qdict) if 'master' in qdict: m = int(qdict['master']) if m < 0: stations.master = None elif m < stations.count(): stations.master = m if 'master_two' in qdict: m = int(qdict['master_two']) if m < 0: stations.master_two = None elif m < stations.count(): stations.master_two = m if 'old_password' in qdict and qdict['old_password'] != "": try: if test_password(qdict['old_password']): if qdict['new_password'] == "": raise web.seeother('/options?errorCode=pw_blank') elif qdict['new_password'] == qdict['check_password']: options.password_salt = password_salt() # Make a new salt options.password_hash = password_hash(qdict['new_password'], options.password_salt) else: raise web.seeother('/options?errorCode=pw_mismatch') else: raise web.seeother('/options?errorCode=pw_wrong') except KeyError: pass if 'rbt' in qdict and qdict['rbt'] == '1': report_rebooted() reboot(True) # Linux HW software return self.core_render.home() if 'rstrt' in qdict and qdict['rstrt'] == '1': report_restarted() restart() # OSPy software return self.core_render.restarting(home_page) if 'pwrdwn' in qdict and qdict['pwrdwn'] == '1': poweroff() # shutdown HW system return self.core_render.restarting(home_page) if 'deldef' in qdict and qdict['deldef'] == '1': OPTIONS_FILE = './ospy/data' try: import shutil, time shutil.rmtree(OPTIONS_FILE) # delete data folder time.sleep(2) os.makedirs(OPTIONS_FILE) # create data folder report_restarted() restart() # restart OSPy software return self.core_render.restarting(home_page) except: pass if change: report_restarted() restart() # OSPy software return self.core_render.restarting(home_page) report_option_change() raise web.seeother('/')
def POST(self): qdict = web.input() change = False # if change language -> restart ospy if 'lang' in qdict and qdict['lang']: if options.lang != qdict['lang']: change = True newname = qdict['name'] # if name is asci char try: from ospy.helpers import ASCI_convert qdict['name'] = ASCI_convert(newname) except: qdict['name'] = ' ' save_to_options(qdict) if 'master' in qdict: m = int(qdict['master']) if m < 0: stations.master = None elif m < stations.count(): stations.master = m if 'master_two' in qdict: m = int(qdict['master_two']) if m < 0: stations.master_two = None elif m < stations.count(): stations.master_two = m if 'old_password' in qdict and qdict['old_password'] != "": try: if test_password(qdict['old_password']): if qdict['new_password'] == "": raise web.seeother('/options?errorCode=pw_blank') elif qdict['new_password'] == qdict['check_password']: options.password_salt = password_salt( ) # Make a new salt options.password_hash = password_hash( qdict['new_password'], options.password_salt) else: raise web.seeother('/options?errorCode=pw_mismatch') else: raise web.seeother('/options?errorCode=pw_wrong') except KeyError: pass if 'rbt' in qdict and qdict['rbt'] == '1': reboot(True) # Linux HW software return self.core_render.home() if 'rstrt' in qdict and qdict['rstrt'] == '1': restart() # OSPy software return self.core_render.restarting(home_page) if 'pwrdwn' in qdict and qdict['pwrdwn'] == '1': poweroff() # shutdown HW system return self.core_render.restarting(home_page) if 'deldef' in qdict and qdict['deldef'] == '1': OPTIONS_FILE = './ospy/data' try: import shutil, time shutil.rmtree(OPTIONS_FILE) # delete data folder time.sleep(2) os.makedirs(OPTIONS_FILE) # create data folder restart() # restart OSPy software return self.core_render.restarting(home_page) except: pass if change: restart() # OSPy software return self.core_render.restarting(home_page) raise web.seeother('/')