Ejemplo n.º 1
0
 def do_wizard(self):
     oe.winOeMain.set_wizard_title(oe._(32003))
     oe.winOeMain.set_wizard_text(oe._(32304))
     oe.winOeMain.set_wizard_button_title(oe._(32308))
     oe.winOeMain.set_wizard_button_1(
         self.struct['ident']['settings']['hostname']['value'], self,
         'wizard_set_hostname')
Ejemplo n.º 2
0
 def onInit(self):
     self.visible = True
     try:
         self.setProperty('arch', oe.ARCHITECTURE)
         self.setProperty('distri', oe.DISTRIBUTION)
         self.setProperty('version', oe.VERSION)
         self.setProperty('build', oe.BUILD)
         oe.dictModules['system'].do_init()
         self.getControl(self.wizWinTitle).setLabel(oe._(32300))
         self.getControl(self.buttons[3]['id']).setVisible(False)
         self.getControl(self.buttons[4]['id']).setVisible(False)
         self.getControl(self.radiobuttons[1]['id']).setVisible(False)
         self.getControl(self.radiobuttons[2]['id']).setVisible(False)
         self.getControl(self.buttons[2]['id']).setVisible(False)
         if oe.BOOT_STATUS == "SAFE":
           self.set_wizard_title(f"[COLOR red][B]{oe._(32393)}[/B][/COLOR]")
           self.set_wizard_text(oe._(32394))
         else:
           self.set_wizard_title(oe._(32301))
           self.set_wizard_text(oe._(32302))
           oe.winOeMain.set_wizard_button_title(oe._(32310))
           cur_lang = xbmc.getLanguage()
           oe.winOeMain.set_wizard_button_1(cur_lang, self, 'wizard_set_language')
         self.showButton(1, 32303)
         self.setFocusId(self.buttons[1]['id'])
     except Exception as e:
         oe.dbg_log('oeWindows.wizard::onInit()', f'ERROR: ({repr(e)})')
Ejemplo n.º 3
0
    def check_updates_v2(self, force=False):
        if hasattr(self, 'update_in_progress'):
            oe.dbg_log('updates::check_updates_v2', 'Update in progress (exit)', oe.LOGDEBUG)
            return
        if self.struct['update']['settings']['SubmitStats']['value'] == '1':
            systemid = oe.SYSTEMID
        else:
            systemid = "NOSTATS"
        if oe.BUILDER_VERSION:
            version = oe.BUILDER_VERSION
        else:
            version = oe.VERSION
        url = f'{self.UPDATE_REQUEST_URL}?i={oe.url_quote(systemid)}&d={oe.url_quote(oe.DISTRIBUTION)}&pa={oe.url_quote(oe.ARCHITECTURE)}&v={oe.url_quote(version)}&f={oe.url_quote(self.hardware_flags)}'
        if oe.BUILDER_NAME:
           url += f'&b={oe.url_quote(oe.BUILDER_NAME)}'

        oe.dbg_log('updates::check_updates_v2', f'URL: {url}', oe.LOGDEBUG)
        update_json = oe.load_url(url)
        oe.dbg_log('updates::check_updates_v2', f'RESULT: {repr(update_json)}', oe.LOGDEBUG)
        if update_json != '':
            update_json = json.loads(update_json)
            self.last_update_check = time.time()
            if 'update' in update_json['data'] and 'folder' in update_json['data']:
                self.update_file = self.UPDATE_DOWNLOAD_URL % (update_json['data']['folder'], update_json['data']['update'])
                if self.struct['update']['settings']['UpdateNotify']['value'] == '1':
                    oe.notify(oe._(32363), oe._(32364))
                if self.struct['update']['settings']['AutoUpdate']['value'] == 'auto' and force == False:
                    self.update_in_progress = True
                    self.do_autoupdate(None, True)
Ejemplo n.º 4
0
 def wizard_set_language(self):
     global lang_str
     global lang_new
     try:
         oe.dbg_log('oeWindows::wizard_set_language', 'enter_function', oe.LOGDEBUG)
         langCodes = {"Bulgarian":"resource.language.bg_bg","Czech":"resource.language.cs_cz","German":"resource.language.de_de","English":"resource.language.en_gb","Spanish":"resource.language.es_es","Basque":"resource.language.eu_es","Finnish":"resource.language.fi_fi","French":"resource.language.fr_fr","Hebrew":"resource.language.he_il","Hungarian":"resource.language.hu_hu","Italian":"resource.language.it_it","Lithuanian":"resource.language.lt_lt","Latvian":"resource.language.lv_lv","Norwegian":"resource.language.nb_no","Dutch":"resource.language.nl_nl","Polish":"resource.language.pl_pl","Portuguese (Brazil)":"resource.language.pt_br","Portuguese":"resource.language.pt_pt","Romanian":"resource.language.ro_ro","Russian":"resource.language.ru_ru","Slovak":"resource.language.sk_sk","Swedish":"resource.language.sv_se","Turkish":"resource.language.tr_tr","Ukrainian":"resource.language.uk_ua"}
         languagesList = sorted(list(langCodes.keys()))
         cur_lang = xbmc.getLanguage()
         for index, lang in enumerate(languagesList):
             if cur_lang in lang:
                 langIndex = index
                 break
             else:
                 pass
         selLanguage = xbmcDialog.select(oe._(32310), languagesList, preselect=langIndex)
         if selLanguage >= 0:
             langKey = languagesList[selLanguage]
             lang_new = langCodes[langKey]
             if lang_new == "resource.language.en_gb":
                 oe.write_setting("system", "language", "")
             else:
                 oe.write_setting("system", "language", str(lang_new))
             lang_str = 'SetGUILanguage(' + str(lang_new) + ')'
             self.getControl(self.wizWinTitle).setLabel(oe._(32300))
             self.set_wizard_title(oe._(32301))
             self.set_wizard_text(oe._(32302))
             oe.winOeMain.set_wizard_button_title(oe._(32310))
             oe.winOeMain.set_wizard_button_1(langKey, self, 'wizard_set_language')
             self.showButton(1, 32303)
             self.setFocusId(self.buttons[1]['id'])
         oe.dbg_log('oeWindows::wizard_set_language', 'exit_function', oe.LOGDEBUG)
     except Exception as e:
         oe.dbg_log('oeWindows::wizard_set_language', f'ERROR: ({repr(e)})')
Ejemplo n.º 5
0
 def set_wizard_buttons(self):
     if self.struct['ssh']['settings']['ssh_autostart']['value'] == '1':
         oe.winOeMain.set_wizard_radiobutton_1(oe._(32201), self, 'wizard_set_ssh', True)
     else:
         oe.winOeMain.set_wizard_radiobutton_1(oe._(32201), self, 'wizard_set_ssh')
     if not 'hidden' in self.struct['samba']:
         if self.struct['samba']['settings']['samba_autostart']['value'] == '1':
             oe.winOeMain.set_wizard_radiobutton_2(oe._(32200), self, 'wizard_set_samba', True)
         else:
             oe.winOeMain.set_wizard_radiobutton_2(oe._(32200), self, 'wizard_set_samba')
Ejemplo n.º 6
0
 def run(self):
     while self.stopped == False:
         if not xbmc.Player().isPlaying():
             oe.dictModules['updates'].check_updates_v2()
         if not hasattr(oe.dictModules['updates'], 'update_in_progress'):
             self.wait_evt.wait(21600)
         else:
             oe.notify(oe._(32363), oe._(32364))
             self.wait_evt.wait(3600)
         self.wait_evt.clear()
     oe.dbg_log('updates::updateThread', 'Stopped', oe.LOGINFO)
Ejemplo n.º 7
0
 def wizard_sshpasswd(self):
     SSHresult = False
     while SSHresult == False:
         changeSSH = xbmcDialog.yesno(oe._(32209), oe._(32210), yeslabel=oe._(32213), nolabel=oe._(32214))
         if changeSSH:
             SSHresult = True
         else:
             changeSSHresult = self.do_sshpasswd()
             if changeSSHresult:
                 SSHresult = True
     return
Ejemplo n.º 8
0
    def get_rpi_flashing_state(self):
        try:
            oe.dbg_log('updates::get_rpi_flashing_state', 'enter_function', oe.LOGDEBUG)

            jdata = {
                        'EXITCODE': 'EXIT_FAILED',
                        'BOOTLOADER_CURRENT': 0, 'BOOTLOADER_LATEST': 0,
                        'VL805_CURRENT': '', 'VL805_LATEST': ''
                    }

            state = {
                        'incompatible': True,
                        'bootloader': {'state': '', 'current': 'unknown', 'latest': 'unknown'},
                        'vl805': {'state': '', 'current': 'unknown', 'latest': 'unknown'}
                    }

            with tempfile.NamedTemporaryFile(mode='r', delete=True) as machine_out:
                console_output = oe.execute(f'/usr/bin/.rpi-eeprom-update.real -j -m "{machine_out.name}"', get_result=1).split('\n')
                if os.path.getsize(machine_out.name) != 0:
                    state['incompatible'] = False
                    jdata = json.load(machine_out)

            oe.dbg_log('updates::get_rpi_flashing_state', f'console output: {console_output}', oe.LOGDEBUG)
            oe.dbg_log('updates::get_rpi_flashing_state', f'json values: {jdata}', oe.LOGDEBUG)

            if jdata['BOOTLOADER_CURRENT'] != 0:
                state['bootloader']['current'] = datetime.datetime.utcfromtimestamp(jdata['BOOTLOADER_CURRENT']).strftime('%Y-%m-%d')

            if jdata['BOOTLOADER_LATEST'] != 0:
                state['bootloader']['latest'] = datetime.datetime.utcfromtimestamp(jdata['BOOTLOADER_LATEST']).strftime('%Y-%m-%d')

            if jdata['VL805_CURRENT']:
                state['vl805']['current'] = jdata['VL805_CURRENT']

            if jdata['VL805_LATEST']:
                state['vl805']['latest'] = jdata['VL805_LATEST']

            if jdata['EXITCODE'] in ['EXIT_SUCCESS', 'EXIT_UPDATE_REQUIRED']:
                if jdata['BOOTLOADER_LATEST'] > jdata['BOOTLOADER_CURRENT']:
                    state['bootloader']['state'] = oe._(32028) % (state['bootloader']['current'], state['bootloader']['latest'])
                else:
                    state['bootloader']['state'] = oe._(32029) % state['bootloader']['current']

                if jdata['VL805_LATEST'] and jdata['VL805_LATEST'] > jdata['VL805_CURRENT']:
                    state['vl805']['state'] = oe._(32028) % (state['vl805']['current'], state['vl805']['latest'])
                else:
                    state['vl805']['state'] = oe._(32029) % state['vl805']['current']

            oe.dbg_log('updates::get_rpi_flashing_state', f'state: {state}', oe.LOGDEBUG)
            oe.dbg_log('updates::get_rpi_flashing_state', 'exit_function', oe.LOGDEBUG)
            return state
        except Exception as e:
            oe.dbg_log('updates::get_rpi_flashing_state', f'ERROR: ({repr(e)})')
            return {'incompatible': True}
Ejemplo n.º 9
0
 def build_menu(self, struct, fltr=[], optional='0'):
     try:
         self.getControl(1100).reset()
         m_menu = []
         for category in sorted(struct, key=lambda x: struct[x]['order']):
             if not 'hidden' in struct[category]:
                 if fltr == []:
                     m_entry = {}
                     m_entry['name'] = oe._(struct[category]['name'])
                     m_entry['properties'] = {'typ': 'separator'}
                     m_entry['list'] = 1100
                     m_menu.append(m_entry)
                 else:
                     if category not in fltr:
                         continue
                 for entry in sorted(struct[category]['settings'], key=lambda x: struct[category]['settings'][x]['order']):
                     setting = struct[category]['settings'][entry]
                     if not 'hidden' in setting:
                         dictProperties = {
                             'value': setting['value'],
                             'typ': setting['type'],
                             'entry': entry,
                             'category': category,
                             'action': setting['action'],
                             }
                         if 'InfoText' in setting:
                             dictProperties['InfoText'] = oe._(setting['InfoText'])
                         if 'validate' in setting:
                             dictProperties['validate'] = setting['validate']
                         if 'values' in setting:
                             dictProperties['values'] = '|'.join(setting['values'])
                         if isinstance(setting['name'], str):
                             name = setting['name']
                         else:
                             name = oe._(setting['name'])
                             dictProperties['menuname'] = oe._(setting['name'])
                         m_entry = {}
                         if not 'parent' in setting:
                             m_entry['name'] = name
                             m_entry['properties'] = dictProperties
                             m_entry['list'] = 1100
                             m_menu.append(m_entry)
                         else:
                             if struct[category]['settings'][setting['parent']['entry']]['value'] in setting['parent']['value']:
                                 if not 'optional' in setting or 'optional' in setting and optional != '0':
                                     m_entry['name'] = name
                                     m_entry['properties'] = dictProperties
                                     m_entry['list'] = 1100
                                     m_menu.append(m_entry)
         for m_entry in m_menu:
             self.addConfigItem(m_entry['name'], m_entry['properties'], m_entry['list'])
     except Exception as e:
         oe.dbg_log('oeWindows.mainWindow::build_menu', f'ERROR: ({repr(e)})')
Ejemplo n.º 10
0
    def do_wizard(self):
        oe.winOeMain.set_wizard_title(oe._(32311))

        # Enable samba
        self.struct['samba']['settings']['samba_autostart']['value'] = '1'
        self.initialize_samba()

        if hasattr(self, 'samba'):
            oe.winOeMain.set_wizard_text(f'{oe._(32313)}[CR][CR]{oe._(32312)}')
        else:
            oe.winOeMain.set_wizard_text(oe._(32312))
        oe.winOeMain.set_wizard_button_title(oe._(32316))
        self.set_wizard_buttons()
Ejemplo n.º 11
0
 def init_netfilter(self, **kwargs):
     if 'listItem' in kwargs:
         self.set_value(kwargs['listItem'])
     state = 1
     options = {}
     if self.struct['advanced']['settings']['netfilter']['value'] == oe._(32396):
         options['RULES'] = "custom"
     elif self.struct['advanced']['settings']['netfilter']['value'] == oe._(32398):
         options['RULES'] = "home"
     elif self.struct['advanced']['settings']['netfilter']['value'] == oe._(32399):
         options['RULES'] = "public"
     else:
         state = 0
     oe.set_service('iptables', options, state)
Ejemplo n.º 12
0
 def do_manual_update(self, listItem=None):
     self.struct['update']['settings']['Build']['value'] = ''
     update_json = self.build_json(notify_error=True)
     if update_json is None:
         return
     self.update_json = update_json
     builds = self.get_available_builds()
     self.struct['update']['settings']['Build']['values'] = builds
     xbmcDialog = xbmcgui.Dialog()
     buildSel = xbmcDialog.select(oe._(32020), builds)
     if buildSel > -1:
         listItem = builds[buildSel]
         self.struct['update']['settings']['Build']['value'] = listItem
         channel = self.struct['update']['settings']['Channel']['value']
         regex = re.compile(self.update_json[channel]['prettyname_regex'])
         longname = '-'.join([oe.DISTRIBUTION, oe.ARCHITECTURE, oe.VERSION])
         if regex.search(longname):
             version = regex.findall(longname)[0]
         else:
             version = oe.VERSION
         if self.struct['update']['settings']['Build']['value'] != '':
             self.update_file = self.update_json[
                 self.struct['update']['settings']['Channel']
                 ['value']]['url'] + self.get_available_builds(
                     self.struct['update']['settings']['Build']['value'])
             message = f"{oe._(32188)}: {version}\n{oe._(32187)}: {self.struct['update']['settings']['Build']['value']}\n{oe._(32180)}"
             answer = xbmcDialog.yesno('LibreELEC Update', message)
             xbmcDialog = None
             del xbmcDialog
             if answer:
                 self.update_in_progress = True
                 self.do_autoupdate()
         self.struct['update']['settings']['Build']['value'] = ''
Ejemplo n.º 13
0
    def do_wizard(self):
        oe.winOeMain.set_wizard_title(oe._(32305))
        oe.winOeMain.set_wizard_text(oe._(32306))
        oe.winOeMain.set_wizard_button_title('')
        oe.winOeMain.set_wizard_list_title(oe._(32309))
        oe.winOeMain.getControl(1391).setLabel('show')

        oe.winOeMain.getControl(oe.winOeMain.buttons[2]['id']).controlUp(
            oe.winOeMain.getControl(oe.winOeMain.guiNetList))
        oe.winOeMain.getControl(oe.winOeMain.buttons[2]['id']).controlRight(
            oe.winOeMain.getControl(oe.winOeMain.buttons[1]['id']))
        oe.winOeMain.getControl(oe.winOeMain.buttons[1]['id']).controlUp(
            oe.winOeMain.getControl(oe.winOeMain.guiNetList))
        oe.winOeMain.getControl(oe.winOeMain.buttons[1]['id']).controlLeft(
            oe.winOeMain.getControl(oe.winOeMain.buttons[2]['id']))
        self.menu_connections(None)
Ejemplo n.º 14
0
 def open_pinkey_window(self, runtime=60, title=32343):
     self.pinkey_window = oeWindows.pinkeyWindow(
         'service-LibreELEC-Settings-getPasskey.xml', oe.__cwd__, 'Default')
     self.pinkey_window.show()
     self.pinkey_window.set_title(oe._(title))
     self.pinkey_timer = pinkeyTimer(self, runtime)
     self.pinkey_timer.start()
Ejemplo n.º 15
0
 def showButton(self, number, name):
     try:
         button = self.getControl(self.buttons[number]['id'])
         button.setLabel(oe._(name))
         button.setVisible(True)
     except Exception as e:
         oe.dbg_log(f'oeWindows.wizard::showButton({str(number)})', f'ERROR: ({repr(e)})')
Ejemplo n.º 16
0
 def request_input(self, path, fields):
     oe.input_request = True
     response = {}
     input_fields = {
         'Name': 32146,
         'Passphrase': 32147,
         'Username': 32148,
         'Password': 32148,
     }
     for field, label in input_fields.items():
         if field in fields:
             xbmcKeyboard = xbmc.Keyboard('', oe._(label))
             xbmcKeyboard.doModal()
             if xbmcKeyboard.isConfirmed() and xbmcKeyboard.getText():
                 response[field] = xbmcKeyboard.getText()
             else:
                 dbus_connman.agent_abort()
     passphrase = response.get('Passphrase')
     if passphrase:
         if 'Identity' in fields:
             response['Identity'] = passphrase
         if 'wpspin' in fields:
             response['wpspin'] = passphrase
     oe.input_request = False
     return response
Ejemplo n.º 17
0
 def onInit(self):
     self.visible = True
     try:
         if self.isChild:
             self.setFocusId(self.guiMenList)
             self.onFocus(self.guiMenList)
             return
         self.setProperty('arch', oe.ARCHITECTURE)
         self.setProperty('distri', oe.DISTRIBUTION)
         self.setProperty('version', oe.VERSION)
         self.setProperty('build', oe.BUILD)
         oe.winOeMain = self
         for strModule in sorted(oe.dictModules, key=lambda x: list(oe.dictModules[x].menu.keys())):
             module = oe.dictModules[strModule]
             oe.dbg_log('init module', strModule, oe.LOGDEBUG)
             if module.ENABLED:
                 if hasattr(module, 'do_init'):
                     Thread(target=module.do_init(), args=()).start()
                 for men in module.menu:
                     if 'listTyp' in module.menu[men] and 'menuLoader' in module.menu[men]:
                         dictProperties = {
                             'modul': strModule,
                             'listTyp': oe.listObject[module.menu[men]['listTyp']],
                             'menuLoader': module.menu[men]['menuLoader'],
                             }
                         if 'InfoText' in module.menu[men]:
                             dictProperties['InfoText'] = oe._(module.menu[men]['InfoText'])
                         self.addMenuItem(module.menu[men]['name'], dictProperties)
         self.setFocusId(self.guiMenList)
         self.onFocus(self.guiMenList)
     except Exception as e:
         oe.dbg_log('oeWindows.mainWindow::onInit', f'ERROR: ({repr(e)})')
Ejemplo n.º 18
0
 def addMenuItem(self, strName, dictProperties):
     try:
         lstItem = xbmcgui.ListItem(label=oe._(strName))
         for strProp in dictProperties:
             lstItem.setProperty(strProp, str(dictProperties[strProp]))
         self.getControl(self.guiMenList).addItem(lstItem)
     except Exception as e:
         oe.dbg_log(f'oeWindows.mainWindow::addMenuItem({str(strName)})', f'ERROR: ({repr(e)})')
Ejemplo n.º 19
0
 def do_autoupdate(self, listItem=None, silent=False):
     if hasattr(self, 'update_file'):
         if not os.path.exists(self.LOCAL_UPDATE_DIR):
             os.makedirs(self.LOCAL_UPDATE_DIR)
         downloaded = oe.download_file(self.update_file, oe.TEMP + 'update_file', silent)
         if not downloaded is None:
             self.update_file = self.update_file.split('/')[-1]
             if self.struct['update']['settings']['UpdateNotify']['value'] == '1':
                 oe.notify(oe._(32363), oe._(32366))
             shutil.move(oe.TEMP + 'update_file', self.LOCAL_UPDATE_DIR + self.update_file)
             os.sync()
             if silent == False:
                 oe.winOeMain.close()
                 oe.xbmcm.waitForAbort(1)
                 subprocess.call(['/usr/bin/systemctl', '--no-block', 'reboot'], close_fds=True)
         else:
             delattr(self, 'update_in_progress')
Ejemplo n.º 20
0
 def ask_sure_reset(self, part):
     answer = xbmcDialog.yesno(f'{part} Reset',
                               f'{oe._(32326)}\n\n{oe._(32328)}')
     if answer == 1:
         if oe.reboot_counter(30, oe._(32323)) == 1:
             return 1
         else:
             return 0
Ejemplo n.º 21
0
 def do_sshpasswd(self, **kwargs):
     SSHchange = False
     newpwd = xbmcDialog.input(oe._(746))
     if newpwd:
         if newpwd == "libreelec":
             oe.execute('cp -fp /usr/cache/shadow /storage/.cache/shadow')
             readout3 = "Retype password"
         else:
             ssh = subprocess.Popen(["passwd"], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=0)
             readout1 = ssh.stdout.readline()
             ssh.stdin.write(f'{newpwd}\n')
             readout2 = ssh.stdout.readline()
             ssh.stdin.write(f'{newpwd}\n')
             readout3 = ssh.stdout.readline()
         if "Bad password" in readout3:
             xbmcDialog.ok(oe._(32220), oe._(32221))
             log.log('Password too weak')
             return
         elif "Retype password" in readout3:
             xbmcDialog.ok(oe._(32222), oe._(32223))
             SSHchange = True
         else:
             xbmcDialog.ok(oe._(32224), oe._(32225))
     else:
         log.log('User cancelled')
     return SSHchange
Ejemplo n.º 22
0
 def do_restore(self, listItem=None):
     copy_success = 0
     restore_file_path = xbmcDialog.browse(1, oe._(32373), 'files',
                                           '??????????????.tar', False,
                                           False, self.BACKUP_DESTINATION)
     # Do nothing if the dialog is cancelled - path will be the backup destination
     if not os.path.isfile(restore_file_path):
         return
     log.log(f'Restore file: {restore_file_path}', log.INFO)
     restore_file_name = restore_file_path.split('/')[-1]
     if os.path.exists(self.RESTORE_DIR):
         oe.execute(f'rm -rf {self.RESTORE_DIR}')
     os.makedirs(self.RESTORE_DIR)
     folder_stat = os.statvfs(self.RESTORE_DIR)
     file_size = os.path.getsize(restore_file_path)
     free_space = folder_stat.f_frsize * folder_stat.f_bavail
     if free_space > file_size * 2:
         if os.path.exists(self.RESTORE_DIR + restore_file_name):
             os.remove(self.RESTORE_DIR + restore_file_name)
         if oe.copy_file(restore_file_path,
                         self.RESTORE_DIR + restore_file_name) != None:
             copy_success = 1
             log.log('Restore file successfully copied.', log.INFO)
         else:
             log.log(f'Failed to copy restore file to: {self.RESTORE_DIR}',
                     log.ERROR)
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
     else:
         txt = oe.split_dialog_text(oe._(32379))
         answer = xbmcDialog.ok('Restore', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
     if copy_success == 1:
         txt = oe.split_dialog_text(oe._(32380))
         answer = xbmcDialog.yesno('Restore',
                                   f'{txt[0]}\n{txt[1]}\n{txt[2]}')
         if answer == 1:
             if oe.reboot_counter(10, oe._(32371)) == 1:
                 oe.winOeMain.close()
                 oe.xbmcm.waitForAbort(1)
                 subprocess.call(
                     ['/usr/bin/systemctl', '--no-block', 'reboot'],
                     close_fds=True)
         else:
             log.log('User Abort!')
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
Ejemplo n.º 23
0
 def load_values(self):
     # Network Wait
     self.struct['advanced']['settings']['wait_for_network']['value'] = '0'
     self.struct['advanced']['settings']['wait_for_network_time'][
         'value'] = '10'
     if os.path.exists(self.WAIT_CONF_FILE):
         wait_file = open(self.WAIT_CONF_FILE, 'r')
         for line in wait_file:
             if 'WAIT_NETWORK=' in line:
                 if line.split('=')[-1].lower().strip().replace(
                         '"', '') == 'true':
                     self.struct['advanced']['settings'][
                         'wait_for_network']['value'] = '1'
                 else:
                     self.struct['advanced']['settings'][
                         'wait_for_network']['value'] = '0'
             if 'WAIT_NETWORK_TIME=' in line:
                 self.struct['advanced']['settings'][
                     'wait_for_network_time']['value'] = line.split(
                         '=')[-1].lower().strip().replace('"', '')
         wait_file.close()
     # IPTABLES
     nf_values = [oe._(32397), oe._(32398), oe._(32399)]
     nf_custom_rules = [
         self.NF_CUSTOM_PATH + "rules.v4", self.NF_CUSTOM_PATH + "rules.v6"
     ]
     for custom_rule in nf_custom_rules:
         if os.path.exists(custom_rule):
             nf_values.append(oe._(32396))
             break
     self.struct['advanced']['settings']['netfilter']['values'] = nf_values
     if oe.get_service_state('iptables') == '1':
         nf_option = oe.get_service_option('iptables', 'RULES', 'home')
         if nf_option == "custom":
             nf_option_str = oe._(32396)
         elif nf_option == "home":
             nf_option_str = oe._(32398)
         elif nf_option == "public":
             nf_option_str = oe._(32399)
     else:
         nf_option_str = oe._(32397)
     self.struct['advanced']['settings']['netfilter'][
         'value'] = nf_option_str
     # regdom
     self.struct[dbus_connman.PATH_TECH_WIFI]['settings']['regdom'][
         'values'] = regdom.REGDOM_LIST
     regValue = regdom.get_regdom()
     self.struct[dbus_connman.PATH_TECH_WIFI]['settings']['regdom'][
         'value'] = str(regValue)
Ejemplo n.º 24
0
 def do_restore(self, listItem=None):
     copy_success = 0
     restore_file_path = xbmcDialog.browse(1, oe._(32373), 'files',
                                           '??????????????.tar', False,
                                           False, self.BACKUP_DESTINATION)
     # Do nothing if the dialog is cancelled - path will be the backup destination
     if not os.path.isfile(restore_file_path):
         return
     restore_file_name = restore_file_path.split('/')[-1]
     if os.path.exists(self.RESTORE_DIR):
         oe.execute('rm -rf %s' % self.RESTORE_DIR)
     os.makedirs(self.RESTORE_DIR)
     folder_stat = os.statvfs(self.RESTORE_DIR)
     file_size = os.path.getsize(restore_file_path)
     free_space = folder_stat.f_frsize * folder_stat.f_bavail
     if free_space > file_size * 2:
         if os.path.exists(self.RESTORE_DIR + restore_file_name):
             os.remove(self.RESTORE_DIR + restore_file_name)
         if oe.copy_file(restore_file_path,
                         self.RESTORE_DIR + restore_file_name) != None:
             copy_success = 1
         else:
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
     else:
         txt = oe.split_dialog_text(oe._(32379))
         answer = xbmcDialog.ok('Restore', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
     if copy_success == 1:
         txt = oe.split_dialog_text(oe._(32380))
         answer = xbmcDialog.yesno('Restore',
                                   f'{txt[0]}\n{txt[1]}\n{txt[2]}')
         if answer == 1:
             if oe.reboot_counter(10, oe._(32371)) == 1:
                 oe.winOeMain.close()
                 oe.xbmcm.waitForAbort(1)
                 xbmc.executebuiltin('Reboot')
         else:
             log.log('User Abort!')
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
Ejemplo n.º 25
0
 def tar_add_folder(self, tar, folder):
     try:
         print_folder = log.asciify(folder)
         for item in os.listdir(folder):
             if item == self.backup_file:
                 continue
             if self.backup_dlg.iscanceled():
                 return
             itempath = os.path.join(folder, item)
             if itempath in self.BACKUP_FILTER:
                 continue
             elif os.path.islink(itempath):
                 tar.add(itempath)
             elif os.path.ismount(itempath):
                 tar.add(itempath, recursive=False)
             elif os.path.isdir(itempath):
                 if os.listdir(itempath) == []:
                     tar.add(itempath)
                 else:
                     self.tar_add_folder(tar, itempath)
                     if self.backup_dlg is None:
                         return
             else:
                 self.done_backup_size += os.path.getsize(itempath)
                 log.log(f'Adding to backup: {log.asciify(itempath)}',
                         log.DEBUG)
                 tar.add(itempath)
                 if hasattr(self, 'backup_dlg'):
                     progress = round(1.0 * self.done_backup_size /
                                      self.total_backup_size * 100)
                     self.backup_dlg.update(
                         int(progress),
                         f'{print_folder}\n{log.asciify(item)}')
     except:
         self.backup_dlg.close()
         self.backup_dlg = None
         xbmcDialog.ok(oe._(32371), oe._(32402))
         raise
Ejemplo n.º 26
0
    def do_backup(self, listItem=None):
        try:
            self.total_backup_size = 1
            self.done_backup_size = 1
            try:
                for directory in self.BACKUP_DIRS:
                    self.get_folder_size(directory)
            except:
                pass
            bckDir = xbmcDialog.browse(0, oe._(32371), 'files', '', False,
                                       False, self.BACKUP_DESTINATION)

            if bckDir and os.path.exists(bckDir):
                # free space check
                try:
                    folder_stat = os.statvfs(bckDir)
                    free_space = folder_stat.f_frsize * folder_stat.f_bavail
                    if self.total_backup_size > free_space:
                        txt = oe.split_dialog_text(oe._(32379))
                        answer = xbmcDialog.ok(
                            'Backup', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
                        return 0
                except:
                    pass
                self.backup_dlg = xbmcgui.DialogProgress()
                self.backup_dlg.create('LibreELEC', oe._(32375))
                if not os.path.exists(self.BACKUP_DESTINATION):
                    os.makedirs(self.BACKUP_DESTINATION)
                self.backup_file = oe.timestamp() + '.tar'
                tar = tarfile.open(bckDir + self.backup_file, 'w')
                for directory in self.BACKUP_DIRS:
                    self.tar_add_folder(tar, directory)
                tar.close()
                self.backup_dlg.close()
                del self.backup_dlg
        finally:
            self.backup_dlg.close()
Ejemplo n.º 27
0
 def showButton(self, number, name, module, action, onup=None, onleft=None):
     try:
         oe.dbg_log('oeWindows::showButton', 'enter_function', oe.LOGDEBUG)
         button = self.getControl(self.buttons[number]['id'])
         self.buttons[number]['modul'] = module
         self.buttons[number]['action'] = action
         button.setLabel(oe._(name))
         if onup != None:
             button.controlUp(self.getControl(onup))
         if onleft != None:
             button.controlLeft(self.getControl(onleft))
         button.setVisible(True)
         oe.dbg_log('oeWindows::showButton', 'exit_function', oe.LOGDEBUG)
     except Exception as e:
         oe.dbg_log(f'oeWindows.mainWindow::showButton({str(number)}, {str(action)})', f'ERROR: ({repr(e)})')
Ejemplo n.º 28
0
 def set_pinlock(self, listItem=None):
     newpin = xbmcDialog.input(oe._(32226), type=xbmcgui.INPUT_NUMERIC)
     if len(newpin) == 4:
         newpinConfirm = xbmcDialog.input(oe._(32227),
                                          type=xbmcgui.INPUT_NUMERIC)
         if newpin != newpinConfirm:
             xbmcDialog.ok(oe._(32228), oe._(32229))
         else:
             oe.PIN.set(newpin)
             xbmcDialog.ok(oe._(32230), f'{oe._(32231)}\n\n{newpin}')
     else:
         xbmcDialog.ok(oe._(32232), oe._(32229))
     if oe.PIN.isSet() == False:
         self.struct['pinlock']['settings']['pinlock_enable']['value'] = '0'
         oe.PIN.disable()
Ejemplo n.º 29
0
 def TransferChanged(self, path, interface, dummy):
     if 'Status' in interface:
         if interface['Status'] == 'active':
             self.parent.download_start = time.time()
             self.parent.download = xbmcgui.DialogProgress()
             self.parent.download.create(
                 'Bluetooth Filetransfer',
                 f'{oe._(32181)}: {self.parent.download_file}')
         else:
             if hasattr(self.parent, 'download'):
                 self.parent.download.close()
                 del self.parent.download
                 del self.parent.download_path
                 del self.parent.download_size
                 del self.parent.download_start
             if interface['Status'] == 'complete':
                 xbmcDialog = xbmcgui.Dialog()
                 answer = xbmcDialog.yesno('Bluetooth Filetransfer',
                                           oe._(32383))
                 if answer == 1:
                     fil = f'{oe.DOWNLOAD_DIR}/{self.parent.download_file}'
                     if 'image' in self.parent.download_type:
                         xbmc.executebuiltin(f'showpicture({fil})')
                     else:
                         xbmc.Player().play(fil)
                 del self.parent.download_type
                 del self.parent.download_file
     if hasattr(self.parent, 'download'):
         if 'Transferred' in interface:
             transferred = int(interface['Transferred'] / 1024)
             speed = transferred / (time.time() -
                                    self.parent.download_start)
             percent = int(
                 round(
                     100 / self.parent.download_size *
                     (interface['Transferred'] / 1024), 0))
             message = f'{oe._(32181)}: {self.parent.download_file}\n{oe._(32382)}: {speed} KB/s'
             self.parent.download.update(percent, message)
         if self.parent.download.iscanceled():
             obj = oe.dbusSystemBus.get_object(
                 'org.bluez.obex', self.parent.download_path)
             itf = dbus.Interface(obj, 'org.bluez.obex.Transfer1')
             itf.Cancel()
             obj = None
             itf = None
Ejemplo n.º 30
0
 def build_json(self, notify_error=False):
     update_json = self.get_json()
     if self.struct['update']['settings']['ShowCustomChannels']['value'] == '1':
         custom_urls = []
         for i in 1,2,3:
             custom_urls.append(self.struct['update']['settings'][f'CustomChannel{str(i)}']['value'])
         for custom_url in custom_urls:
             if custom_url != '':
                 custom_update_json = self.get_json(custom_url)
                 if not custom_update_json is None:
                     for channel in custom_update_json:
                         update_json[channel] = custom_update_json[channel]
                 elif notify_error:
                     ok_window = xbmcgui.Dialog()
                     answer = ok_window.ok(oe._(32191), f'Custom URL is invalid, or currently inaccessible.\n\n{custom_url}')
                     if not answer:
                         return
     return update_json