def POST(self): OPTIONS_FILE = './ospy/data/options.db' i = web.input(uploadfile={}) try: if i.uploadfile.filename == 'options.db': fout = open(OPTIONS_FILE, 'w') fout.write(i.uploadfile.file.read()) fout.close() if os.path.isfile( OPTIONS_FILE): # exists options.db after upload? if os.path.isfile(OPTIONS_FILE + '.bak'): # exists old options.db.bak os.remove(OPTIONS_FILE + '.bak') # remove old options.db.bak copyfile( OPTIONS_FILE, OPTIONS_FILE + '.bak') # copy new options.db to old options.db.bak log.debug( 'webpages.py', 'Upload, save, copy options.db file sucesfully, now restarting OSPy...' ) restart(3) return self.core_render.restarting(home_page) self._redirect_back() except Exception: self._redirect_back()
def perform_update(): global stats try: # ignore local chmod permission command = "git config core.filemode false" # http://superuser.com/questions/204757/git-chmod-problem-checkout-screws-exec-bit subprocess.check_output(command.split()) command = "git reset --hard" subprocess.check_output(command.split()) command = "git pull" output = subprocess.check_output(command.split()).decode('utf8') # Go back to master (refactor is old): if checker is not None: if checker.status['remote_branch'] == 'origin/refactor': command = 'git checkout master' subprocess.check_output(command.split()) log.debug(NAME, _(u'Update result') + ': ' + output) if options.run_logEV: logEV.save_events_log( _(u'System OSPy'), _(u'Updated to version') + ': {}'.format(str(stats['ver_new']))) report_restarted() restart(wait=4) except Exception: log.error(NAME, _(u'System update plug-in') + ':\n' + traceback.format_exc())
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): 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) msg = _( 'The Watchdog service will now started, OSPy is now restarted (restart started by the Watch-dog plugins), please wait for the page to reload.' ) return self.core_render.notice(plugin_url(status_page), msg)
def POST(self): logger.debug('POST ' + self.__class__.__name__) action = web.input().get('do', '').lower() if action == 'reboot': logger.info('System reboot requested via API') helpers.reboot() elif action == 'restart': logger.info('OSPy service restart requested via API') helpers.restart() elif action == 'poweroff': logger.info('System poweroff requested via API') helpers.poweroff() else: logger.error('Unknown system action: "%s"', action) raise badrequest()
def perform_update(): # ignore local chmod permission command = "git config core.filemode false" # http://superuser.com/questions/204757/git-chmod-problem-checkout-screws-exec-bit subprocess.check_output(command.split()) command = "git reset --hard" subprocess.check_output(command.split()) command = "git pull" output = subprocess.check_output(command.split()) # Go back to master (refactor is old): if checker is not None: if checker.status['remote_branch'] == 'origin/refactor': command = 'git checkout master' subprocess.check_output(command.split()) log.debug(NAME, _('Update result') + ': ' + output) restart(3)
def POST(self): OPTIONS_FILE = './ospy/data/options.db' i = web.input(uploadfile={}) try: if i.uploadfile.filename == 'options.db': fout = open(OPTIONS_FILE,'w') fout.write(i.uploadfile.file.read()) fout.close() if os.path.isfile(OPTIONS_FILE): # exists options.db after upload? if os.path.isfile(OPTIONS_FILE + '.bak'): # exists old options.db.bak os.remove(OPTIONS_FILE + '.bak') # remove old options.db.bak copyfile(OPTIONS_FILE, OPTIONS_FILE + '.bak') # copy new options.db to old options.db.bak log.debug('webpages.py', 'Upload, save, copy options.db file sucesfully, now restarting OSPy...') report_restarted() restart(3) return self.core_render.restarting(home_page) else: errorCode = "pw_filename" return self.core_render.options(errorCode) except Exception: return self.core_render.options()
def GET(self): restart(3) return self.core_render.restarting(plugin_url(status_page))
def GET(self): report_restarted() restart(wait=4) msg = _(u'OSPy is now restarted (invoked by the user). Please wait...') return self.core_render.notice('/', msg)
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('/')