Пример #1
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)
        self.arch = detect_architecture()

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ''
        self._password = ''

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i' % self._step)
        ui.append('content', step)

        if self._step == 4:
            if self.arch[1] != 'Raspberry Pi':
                ui.remove('rpi-sdc')
                ui.remove('rpi-ogm')
            tz_sel = [
                UI.SelectOption(text=x, value=x, selected=False)
                for x in zonelist.zones
            ]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-' + k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui
Пример #2
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)
        self.arch = detect_architecture()

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ''
        self._password = ''

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 4:
            if self.arch[1] != 'Raspberry Pi':
                ui.remove('rpi-sdc')
                ui.remove('rpi-ogm')
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui
Пример #3
0
    def run(self):
        rm = RepositoryManager(self.app.config)

        while True:
            try:
                rm.update_list()
                self.feed = json.loads(download(FEED_URL))['results']
            except:
                pass
            time.sleep(60*60*12) # each 12 hrs
Пример #4
0
class FirstRun(CategoryPlugin, URLHandler):
    text = "First run wizard"
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ""
        self._password = ""

    def get_ui(self):
        ui = self.app.inflate("firstrun:main")
        step = self.app.inflate("firstrun:step%i" % self._step)
        ui.append("content", step)

        if self._step == 4:
            tz_sel = [UI.SelectOption(text=x, value=x, selected=False) for x in zonelist.zones]
            ui.appendAll("zoneselect", *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message("err", str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate("firstrun:item")
                row.find("name").set("text", k.name)
                row.find("desc").set("text", k.description)
                row.find("icon").set("class", k.icon)
                row.find("version").set("text", k.version)
                row.find("author").set("text", k.author)
                row.find("author").set("url", k.homepage)

                req = k.str_req()

                row.find("check").set("name", "install-" + k.id)
                if req != "":
                    row.append("reqs", UI.HelpIcon(text=req))

                ui.append("list", row)

        return ui
Пример #5
0
    def run(self):
        rm = RepositoryManager(self.app.log, self.app.config)
        feed_url = feedparser.parse('http://arkos.io/feed')

        while True:
            try:
                self.feed = []
                rm.update_list(crit=False)
                for e in feed_url.entries:
                    self.feed.append({'title': e.title, 'link': e.link, 
                        'time': e.published_parsed})
            except:
                pass
            time.sleep(60*60*12) # check once every 12 hours
Пример #6
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 3:
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 4:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui
Пример #7
0
    def get_ui(self):
        ui = self.app.inflate("firstrun:main")
        step = self.app.inflate("firstrun:step%i" % self._step)
        ui.append("content", step)

        if self._step == 4:
            tz_sel = [UI.SelectOption(text=x, value=x, selected=False) for x in zonelist.zones]
            ui.appendAll("zoneselect", *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message("err", str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate("firstrun:item")
                row.find("name").set("text", k.name)
                row.find("desc").set("text", k.description)
                row.find("icon").set("class", k.icon)
                row.find("version").set("text", k.version)
                row.find("author").set("text", k.author)
                row.find("author").set("url", k.homepage)

                req = k.str_req()

                row.find("check").set("name", "install-" + k.id)
                if req != "":
                    row.append("reqs", UI.HelpIcon(text=req))

                ui.append("list", row)
Пример #8
0
    def run(self):
        rm = RepositoryManager(self.app.config)
        feed_url = feedparser.parse('http://arkos.io/feed')

        while True:
            try:
                self.feed = []
                rm.update_list()
                for e in feed_url.entries:
                    self.feed.append({
                        'title': e.title,
                        'link': e.link,
                        'time': e.published_parsed
                    })
            except:
                pass
            time.sleep(60 * 60 * 12)  # check once every 12 hours
Пример #9
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i' % self._step)
        ui.append('content', step)

        if self._step == 4:
            if self.arch[1] != 'Raspberry Pi':
                ui.remove('rpi-sdc')
                ui.remove('rpi-ogm')
            tz_sel = [
                UI.SelectOption(text=x, value=x, selected=False)
                for x in zonelist.zones
            ]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-' + k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)
Пример #10
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 4:
            if self.arch[1] != 'Raspberry Pi':
                ui.remove('rpi-ogm')
            if self.arch[1] in ['Unknown', 'General']:
                ui.remove('sdc')
            if self.arch[1] not in ['Cubieboard2', 'Cubietruck']:
                ui.remove('cbb-mac')
            else:
                mac = ':'.join(map(lambda x: "%02x" % x, 
                    [0x54, 0xb3, 0xeb, random.randint(0x00, 0x7f), 
                    random.randint(0x00, 0xff), 
                    random.randint(0x00, 0xff)]))
                ui.find('macaddr').set('value', mac)
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)
Пример #11
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i' % self._step)
        ui.append('content', step)

        if self._step == 3:
            tz_sel = [
                UI.SelectOption(text=x, value=x, selected=False)
                for x in zonelist.zones
            ]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 4:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-' + k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui
Пример #12
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 4:
            if self.arch[1] != 'Raspberry Pi':
                ui.remove('rpi-sdc')
                ui.remove('rpi-ogm')
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)
Пример #13
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.log, self.app.config)
     self._nc = apis.networkcontrol(self.app)
     self._wa = apis.webapps(self.app)
     self._info = None
     self._metoo = []
Пример #14
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    icon = None
    folder = None

    def on_session_start(self):
        self._step = 1

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 2:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('file', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui

    @event('form/submit')
    def on_event(self, event, params, vars=None):
        if params[0] == 'frmChangePassword':
            login = vars.getvalue('login', '')
            password = vars.getvalue('password', '')
            if login == '' or password == '':
                self.put_message('err', 'Enter valid login and password')
            else:
                self.app.gconfig.remove_option('users', 'admin')
                self.app.gconfig.set('users', login, hashpw(password))
                self.app.gconfig.save()
                self._step = 2
        if params[0] == 'frmPlugins':
            lst = self._mgr.available

            for k in lst:
                if vars.getvalue('install-'+k.id, '0') == '1':
                    try:
                        self._mgr.install(k.id)
                    except:
                        pass
            ComponentManager.get().rescan()
            ConfManager.get().rescan();

            self.app.gconfig.set('genesis', 'firstrun', 'no')
            self.app.gconfig.save()
            self.put_message('info', 'Setup complete')
            self._step = 3
Пример #15
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.config)
Пример #16
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)

    def on_session_start(self):
        self._step = 1
        self._opts = {}
        self._veriferr = []

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self.app.platform == 'arkos':
            ui.find('welcomemsg').text = 'Welcome to arkOS'

        for x in self._veriferr:
            ui.append('veriferr', UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find('login').set('value', self._opts['username'] if self._opts.has_key('username') else '')
            ui.find('passwd').set('value', self._opts['userpasswd'] if self._opts.has_key('userpasswd') else '')

        if self._step == 3:
            ui.find('rootpasswd').set('value', self._opts['rootpasswd'] if self._opts.has_key('rootpasswd') else '')

        if self._step == 4:
            ui.find('hostname').set('value', self._opts['hostname'] if self._opts.has_key('hostname') else 'arkos')
            ui.find('ssh_as_root').set('checked', 'True' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] == '1' else 'False')

            if self.app.board == 'Raspberry Pi':
                ui.find('resize').set('checked', 'True' if self._opts.has_key('resize') and self._opts['resize'] == '1' else 'False')
                ui.find('gpumem').set('checked', 'True' if self._opts.has_key('gpumem') and self._opts['gpumem'] == '1' else 'False')
            else:
                ui.remove('rpi-ogm')
            if self.app.board in ['Unknown', 'General']:
                ui.remove('sdc')
            if self.app.board not in ['Cubieboard2', 'Cubietruck']:
                ui.remove('cbb-mac')
            else:
                mac = ':'.join(map(lambda x: "%02x" % x, 
                    [0x54, 0xb3, 0xeb, random.randint(0x00, 0x7f), 
                    random.randint(0x00, 0xff), 
                    random.randint(0x00, 0xff)]))
                ui.find('macaddr').set('value', mac)
            tz = self._opts['zone'] if self._opts.has_key('zone') else 'UTC'
            tz_sel = [UI.SelectOption(text = x, value = x,
                selected=(x==tz))
                for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                ui.append('ui-firstrun-appselectfield',
                    UI.AppSelect(
                        id=k.id,
                        name=k.name,
                        desc=k.description,
                        iconfont=k.icon,
                        version=k.version
                    ))

        if self._step == 6:
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Add User')), UI.DTD(UI.Label(text='Username: %s, Password: %s'%(self._opts['username'], '*'*len(self._opts['userpasswd']))))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Administrator Password')), UI.DTD(UI.Label(text='Password: %s'%('*'*len(self._opts['rootpasswd']))))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Hostname')), UI.DTD(UI.Label(text=self._opts['hostname']))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Timezone')), UI.DTD(UI.Label(text=self._opts['zone']))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Allow SSH as Root')), UI.DTD(UI.Label(text='Yes' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] != '0' else 'No'))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set MAC Address')), UI.DTD(UI.Label(text=self._opts['macaddr']))) if self._opts.has_key('macaddr') and self._opts['macaddr'] != '' else None)
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Expand to Fit SD Card')), UI.DTD(UI.Label(text='Yes'))) if self._opts.has_key('resize') and self._opts['resize'] != '0' else None)
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Adjust GPU Memory')), UI.DTD(UI.Label(text='Yes'))) if self._opts.has_key('gpumem') and self._opts['gpumem'] != '0' else None)
            for x in self._opts['toinst']+self._opts['metoo']:
                ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-download text-success')), UI.DTD(UI.Label(text='Install')), UI.DTD(UI.HContainer(UI.Iconfont(iconfont=x.icon), UI.Label(text=' '+x.name)))))

        if self._opts.has_key('metoo') and self._opts['metoo']:
            ui.append('veriferr', UI.DialogBox(
                UI.Label(text=('The applications you selected require some '
                    'additional applications to be installed in order to '
                    'function properly. These will also be installed; '
                    'click OK to do this automatically or Cancel to go '
                    'back and adjust your choices.')),
                UI.ScrollContainer(
                    UI.DT(id='prereqs', width='100%', noborder='True'), 
                    width="100%", height=300
                ),
                id='dlgMeToo'
            ))
            for x in self._opts['metoo']:
                ui.append('prereqs', UI.DTR(
                    UI.DTD(UI.IconFont(iconfont=x.icon), width='1'),
                    UI.DTD(UI.Label(text=x.name))
                ))

        return ui
Пример #17
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'Applications'
    iconfont = 'gen-box-add'
    folder = None

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.config)

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        ui = self.app.inflate('plugins:main')

        inst = self._mgr.installed

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>'%k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('class', k.iconfont)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append('buttons', UI.TipIcon(
                        iconfont="gen-cancel-circle",
                        text='Uninstall',
                        id='remove/'+k.id,
                        warning='Completely remove plugin "%s"' % k.name,
                    ))

            if k.problem:
                row.find('status').set('iconfont', 'gen-close-2 text-error')
                row.find('status').set('text', 'Error')
                row.find('icon').set('class', k.iconfont + ' text-error')
                row.find('name').set('class', 'text-error')
                row.find('desc').set('class', 'text-error')
                row.append('reqs', UI.IconFont(iconfont="gen-warning text-error", text=k.problem))
            else:
                row.find('status').set('iconfont', 'gen-checkmark')
                row.find('status').set('text', 'Installed and Enabled')
            ui.append('list', row)


        lst = self._mgr.available

        btn = UI.Button(text='Check for updates', id='update')
        if len(lst) == 0:
            btn['text'] = 'Download plugin list'

        for k in lst:
            row = self.app.inflate('plugins:item')
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.description)
            row.find('icon').set('class', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)

            for p in inst:
                if k.id == p.id and not p.problem:
                    row.find('status').set('iconfont', 'gen-arrow-up-2')
                    row.find('status').set('text', 'Upgrade Available')

            reqs = k.str_req()

            url = 'http://%s/view/plugins.php?id=%s' % (
                    self.app.config.get('genesis', 'update_server'),
                    k.id
                   )

            if reqs == '':
                row.append('buttons', UI.TipIcon(
                        iconfont="gen-box-add",
                        text='Download and install',
                        id='install/'+k.id,
                    ))
            else:
                row.append('reqs', UI.Icon(iconfont="gen-warning", text=reqs))

            ui.append('avail', row)

        return ui

    def get_ui_upload(self):
        return UI.Uploader(
            url='/upload_plugin',
            text='Install'
        )

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            self._mgr.update_list()
            self.put_message('info', 'Plugin list updated')
        if params[0] == 'remove':
            self._mgr.remove(params[1])
            self.put_message('info', 'Plugin removed. Refresh page for changes to take effect.')
        if params[0] == 'reload':
            try:
                PluginLoader.unload(params[1])
            except:
                pass
            try:
                PluginLoader.load(params[1])
            except:
                pass
            self.put_message('info', 'Plugin reloaded. Refresh page for changes to take effect.')
        if params[0] == 'restart':
            self.app.restart()
        if params[0] == 'install':
            self._mgr.install(params[1], load=True)
            self.put_message('info', 'Plugin installed. Refresh page for changes to take effect.')
            ComponentManager.get().rescan()
            ConfManager.get().rescan();
Пример #18
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self.app.platform == 'arkos':
            ui.find('welcomemsg').text = 'Welcome to arkOS'

        for x in self._veriferr:
            ui.append('veriferr', UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find('login').set('value', self._opts['username'] if self._opts.has_key('username') else '')
            ui.find('passwd').set('value', self._opts['userpasswd'] if self._opts.has_key('userpasswd') else '')

        if self._step == 3:
            ui.find('rootpasswd').set('value', self._opts['rootpasswd'] if self._opts.has_key('rootpasswd') else '')

        if self._step == 4:
            ui.find('hostname').set('value', self._opts['hostname'] if self._opts.has_key('hostname') else 'arkos')
            ui.find('ssh_as_root').set('checked', 'True' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] == '1' else 'False')

            if self.app.board == 'Raspberry Pi':
                ui.find('resize').set('checked', 'True' if self._opts.has_key('resize') and self._opts['resize'] == '1' else 'False')
                ui.find('gpumem').set('checked', 'True' if self._opts.has_key('gpumem') and self._opts['gpumem'] == '1' else 'False')
            else:
                ui.remove('rpi-ogm')
            if self.app.board in ['Unknown', 'General']:
                ui.remove('sdc')
            if self.app.board not in ['Cubieboard2', 'Cubietruck']:
                ui.remove('cbb-mac')
            else:
                mac = ':'.join(map(lambda x: "%02x" % x, 
                    [0x54, 0xb3, 0xeb, random.randint(0x00, 0x7f), 
                    random.randint(0x00, 0xff), 
                    random.randint(0x00, 0xff)]))
                ui.find('macaddr').set('value', mac)
            tz = self._opts['zone'] if self._opts.has_key('zone') else 'UTC'
            tz_sel = [UI.SelectOption(text = x, value = x,
                selected=(x==tz))
                for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                ui.append('ui-firstrun-appselectfield',
                    UI.AppSelect(
                        id=k.id,
                        name=k.name,
                        desc=k.description,
                        iconfont=k.icon,
                        version=k.version
                    ))
Пример #19
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ''
        self._password = ''

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 4:
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui

    def resize(self):
        shell_stdin('fdisk /dev/mmcblk0', 'd\n2\nn\np\n2\n\n\nw\n')
        f = open('/etc/cron.d/resize', 'w')
        f.write('@reboot root resize2fs /dev/mmcblk0p2\n')
        f.write('@reboot root rm /etc/cron.d/resize\n')
        f.close()
        self.app.gconfig.set('genesis', 'restartmsg', 'yes')
        self.app.gconfig.save()

    @event('form/submit')
    def on_event(self, event, params, vars=None):
        reboot = False
        if params[0] == 'splash':
            self._step = 2
        if params[0] == 'frmChangePassword':
            self._username = vars.getvalue('login', '')
            self._password = vars.getvalue('password', '')
            self._password_again = vars.getvalue('password_again', '')
            if self._username == '':
                self.put_message('err', 'The username can\'t be empty')
            elif self._password == '':
                self.put_message('err', 'The password can\'t be empty')
            elif self._password != self._password_again:
                self.put_message('err', 'The passwords don\'t match')
            else:
                # add Unix user
                self.backend = UsersBackend(self.app)
                users = self.backend.get_all_users()
                for u in users:
                    if u.login == self._username:
                        self.put_message('err', 'Duplicate name, please choose another')
                        self._editing = ''
                        return
                self._step = 3
        if params[0] == 'frmChangeRootPassword':
            self._root_password = vars.getvalue('root_password', '')
            self._root_password_again = vars.getvalue('root_password_again', '')
            if self._root_password == '':
                self.put_message('err', 'The password can\'t be empty')
            elif self._root_password != self._root_password_again:
                self.put_message('err', 'The passwords don\'t match')
            else:
                self._step = 4
        if params[0] == 'frmSettings':
            hostname = vars.getvalue('hostname', '')
            zone = vars.getvalue('zoneselect', 'UTC')
            resize = vars.getvalue('resize', 'False')
            gpumem = vars.getvalue('gpumem', 'False')
            ssh_as_root = vars.getvalue('ssh_as_root', 'False')
            
            if resize != '0':
                reboot = self.resize()
                self.put_message('info', 'Remember to restart your arkOS node after this wizard. To do this, click "Settings > Reboot".')
           
            if ssh_as_root != '0':
                shell('sed -i "/PermitRootLogin no/c\PermitRootLogin yes" /etc/ssh/sshd_config')
            else:
                shell('sed -i "/PermitRootLogin yes/c\PermitRootLogin no" /etc/ssh/sshd_config')
            
            if hostname != '0':
                shell('echo "' + hostname + '" > /etc/hostname')

            if gpumem != '0':
                shell('mount /dev/mmcblk0p1 /boot')
                if os.path.exists('/boot/config.txt'):
                    shell('sed -i "/gpu_mem=/c\gpu_mem=16" /boot/config.txt')
                else:
                    shell('echo "gpu_mem=16" >> /boot/config.txt')

            zone = zone.split('/')
            try:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0], zone[1])
            except IndexError:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0])
            if os.path.exists('/etc/localtime'):
                os.remove('/etc/localtime')
            os.symlink(zonepath, '/etc/localtime')
            self._step = 5
        if params[0] == 'frmPlugins':
            lst = self._mgr.available

            toinst = []

            for k in lst:
                if vars.getvalue('install-'+k.id, '0') == '1':
                    toinst.append(k.id)

            t = self._mgr.list_available()
            for y in toinst:
                for i in eval(t[y].deps):
                    for dep in i[1]:
                        if dep[0] == 'plugin' and dep[1] not in toinst:
                            self.put_message('err', ('%s can\'t be installed, as it depends on %s. Please '
                                'install that also.' % (t[y].name, t[dep[1]].name)))
                            return

            for k in lst:
                if vars.getvalue('install-'+k.id, '0') == '1':
                    try:
                        self._mgr.install(k.id)
                    except:
                        pass
            ComponentManager.get().rescan()
            ConfManager.get().rescan();

            self.app.gconfig.set('genesis', 'firstrun', 'no')
            self.app.gconfig.save()
            self.put_message('info', 'Setup complete!')

            # change root password, add Unix user, and allow sudo use
            self.backend = UsersBackend(self.app)
            self.backend.change_user_password('root', self._root_password)            
            self.backend.add_user(self._username)
            self.backend.change_user_password(self._username, self._password)
            sudofile = open('/etc/sudoers', 'r+')
            filedata = sudofile.readlines()
            filedata = ["%sudo ALL=(ALL) ALL\n" if "# %sudo" in line else line for line in filedata]
            sudofile.close()
            sudofile = open('/etc/sudoers', 'w')
            for thing in filedata:
                sudofile.write(thing)
            sudofile.close()
            shell('groupadd sudo')
            shell('usermod -a -G sudo ' + self._username)

            # add user to Genesis config
            self.app.gconfig.remove_option('users', 'admin')
            self.app.gconfig.set('users', self._username, hashpw(self._password))
            self.app.gconfig.save()
            self._step = 6
Пример #20
0
class FirstRun(CategoryPlugin, URLHandler):
    text = "First run wizard"
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)

    def on_session_start(self):
        self._step = 1
        self._opts = {}
        self._veriferr = []

    def get_ui(self):
        ui = self.app.inflate("firstrun:main")
        step = self.app.inflate("firstrun:step%i" % self._step)
        ui.append("content", step)

        if self.app.platform == "arkos":
            ui.find("welcomemsg").text = "Welcome to arkOS"

        for x in self._veriferr:
            ui.append("veriferr", UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find("login").set("value", self._opts["username"] if self._opts.has_key("username") else "")
            ui.find("passwd").set("value", self._opts["userpasswd"] if self._opts.has_key("userpasswd") else "")

        if self._step == 3:
            ui.find("rootpasswd").set("value", self._opts["rootpasswd"] if self._opts.has_key("rootpasswd") else "")

        if self._step == 4:
            ui.find("hostname").set("value", self._opts["hostname"] if self._opts.has_key("hostname") else "arkos")
            ui.find("ssh_as_root").set(
                "checked", "True" if self._opts.has_key("ssh_as_root") and self._opts["ssh_as_root"] == "1" else "False"
            )

            if self.app.board == "Raspberry Pi":
                ui.find("resize").set(
                    "checked", "True" if self._opts.has_key("resize") and self._opts["resize"] == "1" else "False"
                )
                ui.find("gpumem").set(
                    "checked", "True" if self._opts.has_key("gpumem") and self._opts["gpumem"] == "1" else "False"
                )
            else:
                ui.remove("sdc")
                ui.remove("rpi-ogm")
            if self.app.board in ["Unknown", "General"]:
                ui.remove("sdc")
            if self.app.board not in ["Cubieboard2", "Cubietruck"]:
                ui.remove("cbb-mac")
            else:
                mac = ":".join(
                    map(
                        lambda x: "%02x" % x,
                        [
                            0x54,
                            0xB3,
                            0xEB,
                            random.randint(0x00, 0x7F),
                            random.randint(0x00, 0xFF),
                            random.randint(0x00, 0xFF),
                        ],
                    )
                )
                ui.find("macaddr").set("value", mac)
            tz = self._opts["zone"] if self._opts.has_key("zone") else "UTC"
            tz_sel = [UI.SelectOption(text=x, value=x, selected=(x == tz)) for x in zonelist.zones]
            ui.appendAll("zoneselect", *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message("err", str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                ui.append(
                    "ui-firstrun-appselectfield",
                    UI.AppSelect(id=k.id, name=k.name, desc=k.description, iconfont=k.icon, version=k.version),
                )

        if self._step == 6:
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Add User")),
                    UI.DTD(
                        UI.Label(
                            text="Username: %s, Password: %s"
                            % (self._opts["username"], "*" * len(self._opts["userpasswd"]))
                        )
                    ),
                ),
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Set Administrator Password")),
                    UI.DTD(UI.Label(text="Password: %s" % ("*" * len(self._opts["rootpasswd"])))),
                ),
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Set Hostname")),
                    UI.DTD(UI.Label(text=self._opts["hostname"])),
                ),
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Set Timezone")),
                    UI.DTD(UI.Label(text=self._opts["zone"])),
                ),
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Allow SSH as Root")),
                    UI.DTD(
                        UI.Label(
                            text="Yes"
                            if self._opts.has_key("ssh_as_root") and self._opts["ssh_as_root"] != "0"
                            else "No"
                        )
                    ),
                ),
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Expand to Fit SD Card")),
                    UI.DTD(UI.Label(text="Yes")),
                )
                if self._opts.has_key("resize") and self._opts["resize"] != "0"
                else None,
            )
            ui.append(
                "todo",
                UI.DTR(
                    UI.DTD(UI.IconFont(iconfont="gen-checkmark text-success")),
                    UI.DTD(UI.Label(text="Adjust GPU Memory")),
                    UI.DTD(UI.Label(text="Yes")),
                )
                if self._opts.has_key("gpumem") and self._opts["gpumem"] != "0"
                else None,
            )
            for x in self._opts["toinst"] + self._opts["metoo"]:
                ui.append(
                    "todo",
                    UI.DTR(
                        UI.DTD(UI.IconFont(iconfont="gen-download text-success")),
                        UI.DTD(UI.Label(text="Install")),
                        UI.DTD(UI.HContainer(UI.Iconfont(iconfont=x.icon), UI.Label(text=" " + x.name))),
                    ),
                )

        if self._opts.has_key("metoo") and self._opts["metoo"]:
            ui.append(
                "veriferr",
                UI.DialogBox(
                    UI.Label(
                        text=(
                            "The applications you selected require some "
                            "additional applications to be installed in order to "
                            "function properly. These will also be installed; "
                            "click OK to do this automatically or Cancel to go "
                            "back and adjust your choices."
                        )
                    ),
                    UI.ScrollContainer(UI.DT(id="prereqs", width="100%", noborder="True"), width=300, height=300),
                    id="dlgMeToo",
                ),
            )
            for x in self._opts["metoo"]:
                ui.append(
                    "prereqs", UI.DTR(UI.DTD(UI.IconFont(iconfont=x.icon), width="1"), UI.DTD(UI.Label(text=x.name)))
                )

        return ui
Пример #21
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.log, self.app.config)
     self._nc = apis.networkcontrol(self.app)
     self._reloadfw = False
Пример #22
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.log, self.app.config)
     self._nc = apis.networkcontrol(self.app)
     self._reloadfw = False
Пример #23
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.config)
Пример #24
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ''
        self._password = ''

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i' % self._step)
        ui.append('content', step)

        if self._step == 3:
            tz_sel = [
                UI.SelectOption(text=x, value=x, selected=False)
                for x in zonelist.zones
            ]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 4:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-' + k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui

    def resize(self):
        shell_stdin('fdisk /dev/mmcblk0', 'd\n2\nn\np\n2\n\n\nw\n')
        shell('resize2fs /dev/mmcblk0p2')
        shell('e2fsck -fy /dev/mmcblk0p2')
        self.app.gconfig.set('genesis', 'restartmsg', 'yes')
        self.app.gconfig.save()

    @event('form/submit')
    def on_event(self, event, params, vars=None):
        reboot = False
        if params[0] == 'splash':
            self._step = 2
        if params[0] == 'frmChangePassword':
            self._username = vars.getvalue('login', '')
            self._password = vars.getvalue('password', '')
            if self._username == '' or self._password == '':
                self.put_message('err', 'Enter valid login and password')
            else:
                # add Unix user
                self.backend = UsersBackend(self.app)
                users = self.backend.get_all_users()
                for u in users:
                    if u.login == self._username:
                        self.put_message(
                            'err', 'Duplicate name, please choose another')
                        self._editing = ''
                        return
                self._step = 3
        if params[0] == 'frmSettings':
            hostname = vars.getvalue('hostname', '')
            zone = vars.getvalue('zoneselect', 'UTC')
            resize = vars.getvalue('resize', 'False')
            ssh = vars.getvalue('ssh', 'False')
            if resize:
                reboot = self.resize()
                self.put_message(
                    'info',
                    'Remember to restart your arkOS node after this wizard. To do this, click "Settings > Reboot".'
                )
            if not ssh:
                shell(
                    'sed -i "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config'
                )
            if hostname:
                shell('echo "' + hostname + '" > /etc/hostname')
            zone = zone.split('/')
            try:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0],
                                        zone[1])
            except IndexError:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0])
            if os.path.exists('/etc/localtime'):
                os.remove('/etc/localtime')
            os.symlink(zonepath, '/etc/localtime')
            self._step = 4
        if params[0] == 'frmPlugins':
            lst = self._mgr.available

            for k in lst:
                if vars.getvalue('install-' + k.id, '0') == '1':
                    try:
                        self._mgr.install(k.id)
                    except:
                        pass
            ComponentManager.get().rescan()
            ConfManager.get().rescan()

            self.app.gconfig.set('genesis', 'firstrun', 'no')
            self.app.gconfig.save()
            self.put_message('info', 'Setup complete!')

            # add Unix user and allow sudo use
            self.backend = UsersBackend(self.app)
            self.backend.add_user(self._username)
            self.backend.change_user_password(self._username, self._password)
            sudofile = open('/etc/sudoers', 'r+')
            filedata = sudofile.readlines()
            filedata = [
                "%sudo ALL=(ALL) ALL\n" if "# %sudo" in line else line
                for line in filedata
            ]
            sudofile.close()
            sudofile = open('/etc/sudoers', 'w')
            for thing in filedata:
                sudofile.write(thing)
            sudofile.close()
            shell('usermod -a -G sudo ' + self._username)

            # add user to Genesis config
            self.app.gconfig.remove_option('users', 'admin')
            self.app.gconfig.set('users', self._username,
                                 hashpw(self._password))
            self.app.gconfig.save()
            self._step = 5
Пример #25
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'Applications'
    iconfont = 'gen-box-add'
    folder = None

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.log, self.app.config)
        self._nc = apis.networkcontrol(self.app)
        self._reloadfw = False

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        if self._reloadfw == True:
            self._nc.refresh()
            self._reloadfw = False

        ui = self.app.inflate('plugins:main')

        inst = sorted(self._mgr.installed, key=lambda x: x.name.lower())

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>'%k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('class', k.iconfont)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append('buttons', UI.TipIcon(
                        iconfont="gen-cancel-circle",
                        text='Uninstall',
                        id='remove/'+k.id,
                        warning='Are you sure you wish to remove "%s"? Software and data associated with this application will be removed.' % k.name,
                    ))

            if k.problem:
                row.find('status').set('iconfont', 'gen-close-2 text-error')
                row.find('status').set('text', 'Error')
                row.find('icon').set('class', k.iconfont + ' text-error')
                row.find('name').set('class', 'text-error')
                row.find('desc').set('class', 'text-error')
                row.append('reqs', UI.IconFont(iconfont="gen-warning text-error", text=k.problem))
            else:
                row.find('status').set('iconfont', 'gen-checkmark')
                row.find('status').set('text', 'Installed and Enabled')
            ui.append('list', row)


        lst = sorted(self._mgr.available, key=lambda x: x.name.lower())

        btn = UI.Button(text='Check for updates', id='update')
        if len(lst) == 0:
            btn['text'] = 'Download plugin list'

        for k in lst:
            row = self.app.inflate('plugins:item')
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.description)
            row.find('icon').set('class', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)

            for p in inst:
                if k.id == p.id and not p.problem:
                    row.find('status').set('iconfont', 'gen-arrow-up-2')
                    row.find('status').set('text', 'Upgrade Available')

            reqs = k.str_req()

            url = 'http://%s/view/plugins.php?id=%s' % (
                    self.app.config.get('genesis', 'update_server'),
                    k.id
                   )

            if reqs == '':
                row.append('buttons', UI.TipIcon(
                        iconfont="gen-box-add",
                        text='Download and install',
                        id='install/'+k.id,
                    ))
            else:
                row.append('reqs', UI.Icon(iconfont="gen-warning", text=reqs))

            ui.append('avail', row)

        return ui

    def get_ui_upload(self):
        return UI.Uploader(
            url='/upload_plugin',
            text='Install'
        )

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))
            else:
                self.put_message('info', 'Plugin list updated')
        if params[0] == 'remove':
            try:
                self._mgr.check_conflict(params[1], 'remove')
                lr = LiveRemove(self._mgr, params[1], self)
                lr.start()
                self._nc.remove(params[1])
            except ImSorryDave, e:
                self.put_message('err', str(e))
Пример #26
0
 def on_session_start(self):
     self._mgr = RepositoryManager(self.app.log, self.app.config)
     self._nc = apis.networkcontrol(self.app)
     self._wa = apis.webapps(self.app)
     self._info = None
     self._metoo = []
Пример #27
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'Applications'
    iconfont = 'gen-box-add'
    folder = None

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.log, self.app.config)
        self._nc = apis.networkcontrol(self.app)
        self._reloadfw = False

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        if self._reloadfw == True:
            self._nc.refresh()
            self._reloadfw = False

        ui = self.app.inflate('plugins:main')

        inst = sorted(self._mgr.installed, key=lambda x: x.name.lower())

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>' % k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('class', k.iconfont)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append(
                'buttons',
                UI.TipIcon(
                    iconfont="gen-cancel-circle",
                    text='Uninstall',
                    id='remove/' + k.id,
                    warning=
                    'Are you sure you wish to remove "%s"? Software and data associated with this application will be removed.'
                    % k.name,
                ))

            if k.problem:
                row.find('status').set('iconfont', 'gen-close-2 text-error')
                row.find('status').set('text', 'Error')
                row.find('icon').set('class', k.iconfont + ' text-error')
                row.find('name').set('class', 'text-error')
                row.find('desc').set('class', 'text-error')
                row.append(
                    'reqs',
                    UI.IconFont(iconfont="gen-warning text-error",
                                text=k.problem))
            else:
                row.find('status').set('iconfont', 'gen-checkmark')
                row.find('status').set('text', 'Installed and Enabled')
            ui.append('list', row)

        lst = sorted(self._mgr.available, key=lambda x: x.name.lower())

        btn = UI.Button(text='Check for updates', id='update')
        if len(lst) == 0:
            btn['text'] = 'Download plugin list'

        for k in lst:
            row = self.app.inflate('plugins:item')
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.description)
            row.find('icon').set('class', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)

            for p in inst:
                if k.id == p.id and not p.problem:
                    row.find('status').set('iconfont', 'gen-arrow-up-2')
                    row.find('status').set('text', 'Upgrade Available')

            reqs = k.str_req()

            url = 'http://%s/view/plugins.php?id=%s' % (self.app.config.get(
                'genesis', 'update_server'), k.id)

            if reqs == '':
                row.append(
                    'buttons',
                    UI.TipIcon(
                        iconfont="gen-box-add",
                        text='Download and install',
                        id='install/' + k.id,
                    ))
            else:
                row.append('reqs', UI.Icon(iconfont="gen-warning", text=reqs))

            ui.append('avail', row)

        return ui

    def get_ui_upload(self):
        return UI.Uploader(url='/upload_plugin', text='Install')

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))
            else:
                self.put_message('info', 'Plugin list updated')
        if params[0] == 'remove':
            try:
                self._mgr.check_conflict(params[1], 'remove')
                lr = LiveRemove(self._mgr, params[1], self)
                lr.start()
                self._nc.remove(params[1])
            except ImSorryDave, e:
                self.put_message('err', str(e))
Пример #28
0
    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self.app.platform == 'arkos':
            ui.find('welcomemsg').text = 'Welcome to arkOS'

        for x in self._veriferr:
            ui.append('veriferr', UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find('login').set('value', self._opts['username'] if self._opts.has_key('username') else '')
            ui.find('passwd').set('value', self._opts['userpasswd'] if self._opts.has_key('userpasswd') else '')

        if self._step == 3:
            ui.find('rootpasswd').set('value', self._opts['rootpasswd'] if self._opts.has_key('rootpasswd') else '')

        if self._step == 4:
            ui.find('hostname').set('value', self._opts['hostname'] if self._opts.has_key('hostname') else 'arkos')
            ui.find('ssh_as_root').set('checked', 'True' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] == '1' else 'False')

            if self.app.board == 'Raspberry Pi':
                ui.find('resize').set('checked', 'True' if self._opts.has_key('resize') and self._opts['resize'] == '1' else 'False')
                ui.find('gpumem').set('checked', 'True' if self._opts.has_key('gpumem') and self._opts['gpumem'] == '1' else 'False')
            else:
                ui.remove('rpi-ogm')
            if self.app.board in ['Unknown', 'General']:
                ui.remove('sdc')
            if self.app.board not in ['Cubieboard2', 'Cubietruck']:
                ui.remove('cbb-mac')
            else:
                mac = ':'.join(map(lambda x: "%02x" % x, 
                    [0x54, 0xb3, 0xeb, random.randint(0x00, 0x7f), 
                    random.randint(0x00, 0xff), 
                    random.randint(0x00, 0xff)]))
                ui.find('macaddr').set('value', mac)
            tz = self._opts['zone'] if self._opts.has_key('zone') else 'UTC'
            tz_sel = [UI.SelectOption(text = x, value = x,
                selected=(x==tz))
                for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                ui.append('ui-firstrun-appselectfield',
                    UI.AppSelect(
                        id=k.id,
                        name=k.name,
                        desc=k.description,
                        iconfont=k.icon,
                        version=k.version
                    ))
Пример #29
0
    def get_ui(self):
        ui = self.app.inflate("firstrun:main")
        step = self.app.inflate("firstrun:step%i" % self._step)
        ui.append("content", step)

        if self.app.platform == "arkos":
            ui.find("welcomemsg").text = "Welcome to arkOS"

        for x in self._veriferr:
            ui.append("veriferr", UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find("login").set("value", self._opts["username"] if self._opts.has_key("username") else "")
            ui.find("passwd").set("value", self._opts["userpasswd"] if self._opts.has_key("userpasswd") else "")

        if self._step == 3:
            ui.find("rootpasswd").set("value", self._opts["rootpasswd"] if self._opts.has_key("rootpasswd") else "")

        if self._step == 4:
            ui.find("hostname").set("value", self._opts["hostname"] if self._opts.has_key("hostname") else "arkos")
            ui.find("ssh_as_root").set(
                "checked", "True" if self._opts.has_key("ssh_as_root") and self._opts["ssh_as_root"] == "1" else "False"
            )

            if self.app.board == "Raspberry Pi":
                ui.find("resize").set(
                    "checked", "True" if self._opts.has_key("resize") and self._opts["resize"] == "1" else "False"
                )
                ui.find("gpumem").set(
                    "checked", "True" if self._opts.has_key("gpumem") and self._opts["gpumem"] == "1" else "False"
                )
            else:
                ui.remove("sdc")
                ui.remove("rpi-ogm")
            if self.app.board in ["Unknown", "General"]:
                ui.remove("sdc")
            if self.app.board not in ["Cubieboard2", "Cubietruck"]:
                ui.remove("cbb-mac")
            else:
                mac = ":".join(
                    map(
                        lambda x: "%02x" % x,
                        [
                            0x54,
                            0xB3,
                            0xEB,
                            random.randint(0x00, 0x7F),
                            random.randint(0x00, 0xFF),
                            random.randint(0x00, 0xFF),
                        ],
                    )
                )
                ui.find("macaddr").set("value", mac)
            tz = self._opts["zone"] if self._opts.has_key("zone") else "UTC"
            tz_sel = [UI.SelectOption(text=x, value=x, selected=(x == tz)) for x in zonelist.zones]
            ui.appendAll("zoneselect", *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message("err", str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x: x.name):
                ui.append(
                    "ui-firstrun-appselectfield",
                    UI.AppSelect(id=k.id, name=k.name, desc=k.description, iconfont=k.icon, version=k.version),
                )
Пример #30
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_session_start(self):
        self._step = 1
        self._tree = TreeManager()
        self._reboot = True
        self._username = ''
        self._password = ''

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self._step == 3:
            tz_sel = [UI.SelectOption(text = x, value = x,
                        selected = False)
                        for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 4:
            self._mgr = RepositoryManager(self.app.config)
            self._mgr.update_list()

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                row = self.app.inflate('firstrun:item')
                row.find('name').set('text', k.name)
                row.find('desc').set('text', k.description)
                row.find('icon').set('class', k.icon)
                row.find('version').set('text', k.version)
                row.find('author').set('text', k.author)
                row.find('author').set('url', k.homepage)

                req = k.str_req()

                row.find('check').set('name', 'install-'+k.id)
                if req != '':
                    row.append('reqs', UI.HelpIcon(text=req))

                ui.append('list', row)

        return ui

    def resize(self):
        shell_stdin('fdisk /dev/mmcblk0', 'd\n2\nn\np\n2\n\n\nw\n')
        shell('resize2fs /dev/mmcblk0p2')
        shell('e2fsck -fy /dev/mmcblk0p2')
        self.app.gconfig.set('genesis', 'restartmsg', 'yes')
        self.app.gconfig.save()

    @event('form/submit')
    def on_event(self, event, params, vars=None):
        reboot = False
        if params[0] == 'splash':
            self._step = 2
        if params[0] == 'frmChangePassword':
            self._username = vars.getvalue('login', '')
            self._password = vars.getvalue('password', '')
            if self._username == '' or self._password == '':
                self.put_message('err', 'Enter valid login and password')
            else:
                # add Unix user
                self.backend = UsersBackend(self.app)
                users = self.backend.get_all_users()
                for u in users:
                    if u.login == self._username:
                        self.put_message('err', 'Duplicate name, please choose another')
                        self._editing = ''
                        return
                self._step = 3
        if params[0] == 'frmSettings':
            hostname = vars.getvalue('hostname', '')
            zone = vars.getvalue('zoneselect', 'UTC')
            resize = vars.getvalue('resize', 'False')
            ssh = vars.getvalue('ssh', 'False')
            if resize:
                reboot = self.resize()
                self.put_message('info', 'Remember to restart your arkOS node after this wizard. To do this, click "Settings > Reboot".')
            if not ssh:
                shell('sed -i "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config')
            if hostname:
                shell('echo "' + hostname + '" > /etc/hostname')
            zone = zone.split('/')
            try:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0], zone[1])
            except IndexError:
                zonepath = os.path.join('/usr/share/zoneinfo', zone[0])
            if os.path.exists('/etc/localtime'):
                os.remove('/etc/localtime')
            os.symlink(zonepath, '/etc/localtime')
            self._step = 4
        if params[0] == 'frmPlugins':
            lst = self._mgr.available

            for k in lst:
                if vars.getvalue('install-'+k.id, '0') == '1':
                    try:
                        self._mgr.install(k.id)
                    except:
                        pass
            ComponentManager.get().rescan()
            ConfManager.get().rescan();

            self.app.gconfig.set('genesis', 'firstrun', 'no')
            self.app.gconfig.save()
            self.put_message('info', 'Setup complete!')

            # add Unix user and allow sudo use
            self.backend = UsersBackend(self.app)
            self.backend.add_user(self._username)
            self.backend.change_user_password(self._username, self._password)
            sudofile = open('/etc/sudoers', 'r+')
            filedata = sudofile.readlines()
            filedata = ["%sudo ALL=(ALL) ALL\n" if "# %sudo" in line else line for line in filedata]
            sudofile.close()
            sudofile = open('/etc/sudoers', 'w')
            for thing in filedata:
                sudofile.write(thing)
            sudofile.close()
            shell('usermod -a -G sudo ' + self._username)

            # add user to Genesis config
            self.app.gconfig.remove_option('users', 'admin')
            self.app.gconfig.set('users', self._username, hashpw(self._password))
            self.app.gconfig.save()
            self._step = 5
Пример #31
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'App Store'
    iconfont = 'gen-box-add'
    folder = 'top'

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.log, self.app.config)
        self._nc = apis.networkcontrol(self.app)
        self._wa = apis.webapps(self.app)
        self._info = None
        self._metoo = []

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        ui = self.app.inflate('plugins:main')

        inst = sorted(self._mgr.installed, key=lambda x: x.name.lower())

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>' % k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('class', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append(
                'buttons',
                UI.TipIcon(
                    iconfont="gen-cancel-circle",
                    text='Uninstall',
                    id='remove/' + k.id,
                    warning=
                    'Are you sure you wish to remove "%s"? Software and data associated with this application will be removed.'
                    % k.name,
                ))

            if k.problem:
                row.find('status').set('iconfont', 'gen-close-2 text-error')
                row.find('status').set('text', k.problem)
                row.find('icon').set('class', k.icon + ' text-error')
                row.find('name').set('class', 'text-error')
                row.find('desc').set('class', 'text-error')
                row.append(
                    'reqs',
                    UI.IconFont(iconfont="gen-warning text-error",
                                text=k.problem))
            else:
                row.find('status').set('iconfont', 'gen-checkmark')
                row.find('status').set('text', 'Installed and Enabled')
            ui.append('list', row)

        lst = {}
        for x in self._mgr.available:
            if x in self._mgr.upgradable:
                continue
            for y in x.categories:
                if not lst.has_key(y['primary']):
                    lst[y['primary']] = []
                lst[y['primary']].append(x)

        if self._mgr.upgradable:
            ui.append('upg', UI.Label(size=3, text="Updates Available"))
            for x in self._mgr.upgradable:
                ui.append(
                    'upg',
                    UI.AppButton(id=x.id,
                                 name=x.name,
                                 iconfont=x.icon,
                                 version=x.version))

        for x in lst:
            ui.append('avail', UI.Label(size=3, text=x))
            for y in sorted(lst[x], key=lambda z: z.name.lower()):
                ui.append(
                    'avail',
                    UI.AppButton(id=y.id,
                                 name=y.name,
                                 iconfont=y.icon,
                                 version=y.version))

        if self._info:
            info = [x for x in self._mgr.available if x.id == self._info][0]
            if info.assets:
                try:
                    data = send_json(
                        'https://%s/' %
                        self.app.gconfig.get('genesis', 'update_server'), {
                            'get': 'assets',
                            'id': info.id
                        })
                    ui.find('app-logo').append(
                        UI.Image(file="data:image/png;base64,%s" %
                                 data['logo'],
                                 cls='app-logo'))
                    for x in data['screenshots']:
                        ui.find('app-screens').append(
                            UI.Image(
                                file="data:image/jpeg;base64,%s" % x,
                                cls=
                                "img-responsive img-thumbnail app-screenshot",
                                lightbox=self._info))
                except:
                    pass
            ui.find('app-short').set('text', info.description)
            ui.find('app-version').set('text', info.version)
            ui.find('app-cats').set(
                'text', '; '.join([
                    '%s: %s' % (x['primary'], ', '.join(x['secondary']))
                    for x in info.categories
                ]))
            ui.find('app-name').set('text', info.name)
            ui.find('app-desc').set('text', info.long_description)
            if info.app_author:
                ui.find('app-plugauthor').set('text', info.app_author)
                ui.find('app-plughomepage').set('text', info.app_homepage)
                ui.find('app-plughomepage').set('url', info.app_homepage)
            else:
                ui.remove('app-plugauth')
            ui.find('app-author').set('text', info.author)
            ui.find('app-homepage').set('text', info.homepage)
            ui.find('app-homepage').set('url', info.homepage)
        else:
            ui.remove('dlgInfo')

        if self._metoo:
            for x in self._metoo:
                ui.append(
                    'prereqs',
                    UI.DTR(UI.DTD(UI.IconFont(iconfont=x[1].icon), width='1'),
                           UI.DTD(UI.Label(text=x[0], bold=True)),
                           UI.DTD(UI.Label(text=x[1].name))))
        else:
            ui.remove('dlgMeToo')

        return ui

    def get_ui_upload(self):
        return UI.Uploader(url='/upload_plugin', text='Install')

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))
            else:
                self.put_message('success', 'Application list updated')
        elif params[0] == 'remove':
            metoo = self._mgr.check_conflict(params[1], 'remove')
            if metoo:
                self._metoo = metoo
                self._metoo.append(('Remove',
                                    next(x for x in self._mgr.installed
                                         if x.id == params[1])))
            else:
                try:
                    self._mgr.remove(params[1], self)
                    self._nc.remove(params[1])
                except Exception, e:
                    self.put_message('err', str(e))
                finally:
Пример #32
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'Plugins'
    icon = '/dl/plugins/icon.png'
    folder = 'bottom'

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.config)

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        ui = self.app.inflate('plugins:main')

        inst = self._mgr.installed

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>'%k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('file', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append('buttons', UI.TipIcon(
                        icon='/dl/core/ui/stock/delete.png',
                        text='Uninstall',
                        id='remove/'+k.id,
                        warning='Completely remove plugin "%s"'%k.name,
                    ))

            if k.problem:
                row.find('status').set('file', '/dl/plugins/broken.png')
                row.append('reqs', UI.Icon(icon='/dl/core/ui/stock/warning.png', text=k.problem))
            else:
                row.find('status').set('file', '/dl/plugins/good.png')
            ui.append('list', row)


        lst = self._mgr.available

        btn = UI.Button(text='Check for updates', id='update')
        if len(lst) == 0:
            btn['text'] = 'Download plugin list'

        for k in lst:
            row = self.app.inflate('plugins:item')
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.description)
            row.find('icon').set('file', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)

            row.find('status').set('file', '/dl/plugins/none.png')
            for p in inst:
                if k.id == p.id and not p.problem:
                    row.find('status').set('file', '/dl/plugins/upgrade.png')

            reqs = k.str_req()

            url = 'http://%s/view/plugins.php?id=%s' % (
                    self.app.config.get('genesis', 'update_server'),
                    k.id
                   )

            if reqs == '':
                row.append('buttons', UI.TipIcon(
                        icon='/dl/core/ui/stock/download.png',
                        text='Download and install',
                        id='install/'+k.id,
                    ))
            else:
                row.append('reqs', UI.Icon(icon='/dl/core/ui/stock/warning.png', text=reqs))

            ui.append('avail', row)

        return ui

    def get_ui_upload(self):
        return UI.Uploader(
            url='/upload_plugin',
            text='Install'
        )

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            self._mgr.update_list()
            self.put_message('info', 'Plugin list updated')
        if params[0] == 'remove':
            self._mgr.remove(params[1])
            self.put_message('info', 'Plugin removed. Refresh page for changes to take effect.')
        if params[0] == 'reload':
            try:
                PluginLoader.unload(params[1])
            except:
                pass
            try:
                PluginLoader.load(params[1])
            except:
                pass
            self.put_message('info', 'Plugin reloaded. Refresh page for changes to take effect.')
        if params[0] == 'restart':
            self.app.restart()
        if params[0] == 'install':
            self._mgr.install(params[1], load=True)
            self.put_message('info', 'Plugin installed. Refresh page for changes to take effect.')
            ComponentManager.get().rescan()
            ConfManager.get().rescan();
Пример #33
0
class PluginManager(CategoryPlugin, URLHandler):
    text = 'App Store'
    iconfont = 'gen-box-add'
    folder = 'top'

    def on_session_start(self):
        self._mgr = RepositoryManager(self.app.log, self.app.config)
        self._nc = apis.networkcontrol(self.app)
        self._wa = apis.webapps(self.app)
        self._info = None
        self._metoo = []

    def on_init(self):
        self._mgr.refresh()

    def get_counter(self):
        return len(self._mgr.upgradable) or None

    def get_ui(self):
        ui = self.app.inflate('plugins:main')

        inst = sorted(self._mgr.installed, key=lambda x: x.name.lower())

        for k in inst:
            row = self.app.inflate('plugins:item')
            desc = '<span class="ui-el-label-1" style="padding-left: 5px;">%s</span>'%k.desc
            row.find('name').set('text', k.name)
            row.find('desc').set('text', k.desc)
            row.find('icon').set('class', k.icon)
            row.find('version').set('text', k.version)
            row.find('author').set('text', k.author)
            row.find('author').set('url', k.homepage)
            row.append('buttons', UI.TipIcon(
                        iconfont="gen-cancel-circle",
                        text='Uninstall',
                        id='remove/'+k.id,
                        warning='Are you sure you wish to remove "%s"? Software and data associated with this application will be removed.' % k.name,
                    ))

            if k.problem:
                row.find('status').set('iconfont', 'gen-close-2 text-error')
                row.find('status').set('text', k.problem)
                row.find('icon').set('class', k.icon + ' text-error')
                row.find('name').set('class', 'text-error')
                row.find('desc').set('class', 'text-error')
                row.append('reqs', UI.IconFont(iconfont="gen-warning text-error", text=k.problem))
            else:
                row.find('status').set('iconfont', 'gen-checkmark')
                row.find('status').set('text', 'Installed and Enabled')
            ui.append('list', row)

        lst = {}
        for x in self._mgr.available:
            if x in self._mgr.upgradable:
                continue
            for y in x.categories:
                if not lst.has_key(y['primary']):
                    lst[y['primary']] = []
                lst[y['primary']].append(x)

        if self._mgr.upgradable:
            ui.append('upg', UI.Label(size=3, text="Updates Available"))
            for x in self._mgr.upgradable:
                ui.append('upg', 
                    UI.AppButton(
                        id=x.id,
                        name=x.name,
                        iconfont=x.icon,
                        version=x.version
                        )
                    )
        
        for x in lst:
            ui.append('avail', UI.Label(size=3, text=x))
            for y in sorted(lst[x], key=lambda z: z.name.lower()):
                ui.append('avail', 
                    UI.AppButton(
                        id=y.id,
                        name=y.name,
                        iconfont=y.icon,
                        version=y.version
                        )
                    )

        if self._info:
            info = [x for x in self._mgr.available if x.id==self._info][0]
            if info.assets:
                try:
                    data = send_json('https://%s/' % self.app.gconfig.get('genesis', 'update_server'), 
                        {'get': 'assets', 'id': info.id})
                    ui.find('app-logo').append(UI.Image(file="data:image/png;base64,%s" % data['logo'], cls='app-logo'))
                    for x in data['screenshots']:
                        ui.find('app-screens').append(UI.Image(file="data:image/jpeg;base64,%s" % x, cls="img-responsive img-thumbnail app-screenshot", lightbox=self._info))
                except:
                    pass
            ui.find('app-short').set('text', info.description)
            ui.find('app-version').set('text', info.version)
            ui.find('app-cats').set('text', '; '.join(['%s: %s'%(x['primary'], ', '.join(x['secondary'])) for x in info.categories]))
            ui.find('app-name').set('text', info.name)
            ui.find('app-desc').set('text', info.long_description)
            if info.app_author:
                ui.find('app-plugauthor').set('text', info.app_author)
                ui.find('app-plughomepage').set('text', info.app_homepage)
                ui.find('app-plughomepage').set('url', info.app_homepage)
            else:
                ui.remove('app-plugauth')
            ui.find('app-author').set('text', info.author)
            ui.find('app-homepage').set('text', info.homepage)
            ui.find('app-homepage').set('url', info.homepage)
        else:
            ui.remove('dlgInfo')

        if self._metoo:
            for x in self._metoo:
                ui.append('prereqs', UI.DTR(
                    UI.DTD(UI.IconFont(iconfont=x[1].icon), width='1'),
                    UI.DTD(UI.Label(text=x[0], bold=True)),
                    UI.DTD(UI.Label(text=x[1].name))
                ))
        else:
            ui.remove('dlgMeToo')

        return ui

    def get_ui_upload(self):
        return UI.Uploader(
            url='/upload_plugin',
            text='Install'
        )

    @url('^/upload_plugin$')
    def upload(self, req, sr):
        vars = get_environment_vars(req)
        f = vars.getvalue('file', None)
        try:
            self._mgr.install_stream(f)
        except:
            pass
        sr('301 Moved Permanently', [('Location', '/')])
        return ''

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'update':
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))
            else:
                self.put_message('success', 'Application list updated')
        elif params[0] == 'remove':
            metoo = self._mgr.check_conflict(params[1], 'remove')
            if metoo:
                self._metoo = metoo
                self._metoo.append(('Remove', next(x for x in self._mgr.installed if x.id == params[1])))
            else:
                try:
                    self._mgr.remove(params[1], self)
                    self._nc.remove(params[1])
                except Exception, e:
                    self.put_message('err', str(e))
                finally:
Пример #34
0
class FirstRun(CategoryPlugin, URLHandler):
    text = 'First run wizard'
    iconfont = None
    folder = None

    def on_init(self):
        self.nb = backend.Config(self.app)
        self.ub = UsersBackend(self.app)

    def on_session_start(self):
        self._step = 1
        self._opts = {}
        self._veriferr = []

    def get_ui(self):
        ui = self.app.inflate('firstrun:main')
        step = self.app.inflate('firstrun:step%i'%self._step)
        ui.append('content', step)

        if self.app.platform == 'arkos':
            ui.find('welcomemsg').text = 'Welcome to arkOS'

        for x in self._veriferr:
            ui.append('veriferr', UI.SystemMessage(cls="danger", iconfont="gen-close", text=x))
        self._veriferr = []

        if self._step == 2:
            ui.find('login').set('value', self._opts['username'] if self._opts.has_key('username') else '')
            ui.find('passwd').set('value', self._opts['userpasswd'] if self._opts.has_key('userpasswd') else '')

        if self._step == 3:
            ui.find('rootpasswd').set('value', self._opts['rootpasswd'] if self._opts.has_key('rootpasswd') else '')

        if self._step == 4:
            ui.find('hostname').set('value', self._opts['hostname'] if self._opts.has_key('hostname') else 'arkos')
            ui.find('ssh_as_root').set('checked', 'True' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] == '1' else 'False')

            if self.app.board == 'Raspberry Pi':
                ui.find('resize').set('checked', 'True' if self._opts.has_key('resize') and self._opts['resize'] == '1' else 'False')
                ui.find('gpumem').set('checked', 'True' if self._opts.has_key('gpumem') and self._opts['gpumem'] == '1' else 'False')
            else:
                ui.remove('rpi-ogm')
            if self.app.board in ['Unknown', 'General']:
                ui.remove('sdc')
            if self.app.board not in ['Cubieboard2', 'Cubietruck']:
                ui.remove('cbb-mac')
            else:
                mac = ':'.join(map(lambda x: "%02x" % x, 
                    [0x54, 0xb3, 0xeb, random.randint(0x00, 0x7f), 
                    random.randint(0x00, 0xff), 
                    random.randint(0x00, 0xff)]))
                ui.find('macaddr').set('value', mac)
            tz = self._opts['zone'] if self._opts.has_key('zone') else 'UTC'
            tz_sel = [UI.SelectOption(text = x, value = x,
                selected=(x==tz))
                for x in zonelist.zones]
            ui.appendAll('zoneselect', *tz_sel)

        if self._step == 5:
            self._mgr = RepositoryManager(self.app.log, self.app.config)
            try:
                self._mgr.update_list(crit=True)
            except Exception, e:
                self.put_message('err', str(e))
                self.app.log.error(str(e))

            lst = self._mgr.available

            for k in sorted(lst, key=lambda x:x.name):
                ui.append('ui-firstrun-appselectfield',
                    UI.AppSelect(
                        id=k.id,
                        name=k.name,
                        desc=k.description,
                        iconfont=k.icon,
                        version=k.version
                    ))

        if self._step == 6:
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Add User')), UI.DTD(UI.Label(text='Username: %s, Password: %s'%(self._opts['username'], '*'*len(self._opts['userpasswd']))))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Administrator Password')), UI.DTD(UI.Label(text='Password: %s'%('*'*len(self._opts['rootpasswd']))))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Hostname')), UI.DTD(UI.Label(text=self._opts['hostname']))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set Timezone')), UI.DTD(UI.Label(text=self._opts['zone']))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Allow SSH as Root')), UI.DTD(UI.Label(text='Yes' if self._opts.has_key('ssh_as_root') and self._opts['ssh_as_root'] != '0' else 'No'))))
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Set MAC Address')), UI.DTD(UI.Label(text=self._opts['macaddr']))) if self._opts.has_key('macaddr') and self._opts['macaddr'] != '' else None)
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Expand to Fit SD Card')), UI.DTD(UI.Label(text='Yes'))) if self._opts.has_key('resize') and self._opts['resize'] != '0' else None)
            ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-checkmark text-success')), UI.DTD(UI.Label(text='Adjust GPU Memory')), UI.DTD(UI.Label(text='Yes'))) if self._opts.has_key('gpumem') and self._opts['gpumem'] != '0' else None)
            for x in self._opts['toinst']+self._opts['metoo']:
                ui.append('todo', UI.DTR(UI.DTD(UI.IconFont(iconfont='gen-download text-success')), UI.DTD(UI.Label(text='Install')), UI.DTD(UI.HContainer(UI.Iconfont(iconfont=x.icon), UI.Label(text=' '+x.name)))))

        if self._opts.has_key('metoo') and self._opts['metoo']:
            ui.append('veriferr', UI.DialogBox(
                UI.Label(text=('The applications you selected require some '
                    'additional applications to be installed in order to '
                    'function properly. These will also be installed; '
                    'click OK to do this automatically or Cancel to go '
                    'back and adjust your choices.')),
                UI.ScrollContainer(
                    UI.DT(id='prereqs', width='100%', noborder='True'), 
                    width="100%", height=300
                ),
                id='dlgMeToo'
            ))
            for x in self._opts['metoo']:
                ui.append('prereqs', UI.DTR(
                    UI.DTD(UI.IconFont(iconfont=x.icon), width='1'),
                    UI.DTD(UI.Label(text=x.name))
                ))

        return ui