Exemplo n.º 1
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    from ajenti.plugmgr import PluginLoader
    pr = ''
    for p in sorted(PluginLoader.list_plugins().keys()):
        pr += p + '\n'

    # Finalize the reported log
    app.log.blackbox.stop()

    return (('Ajenti %s bug report\n' +
           '--------------------\n\n' +
           'System: %s\n' +
           'Detected platform: %s\n' +
           'Detected distro: %s\n' +
           'Python: %s\n\n' +
           'Config path: %s\n\n' +
           '%s\n\n'
           'Loaded plugins:\n%s\n\n' +
           'Log:\n%s\n'
           )
            % (version(),
               shell('uname -a'),
               detect_platform(),
               detect_distro(),
               '.'.join([str(x) for x in platform.python_version_tuple()]),
               app.config.filename,
               err,
               pr,
               app.log.blackbox.buffer,
              ))
Exemplo n.º 2
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    from ajenti.plugmgr import PluginLoader
    pr = ''
    for p in sorted(PluginLoader.list_plugins().keys()):
        pr += p + '\n'

    # Finalize the reported log
    app.log.blackbox.stop()

    return (
        ('Ajenti %s bug report\n' + '--------------------\n\n' +
         'System: %s\n' + 'Detected platform: %s\n' + 'Detected distro: %s\n' +
         'Python: %s\n\n' + 'Config path: %s\n\n' + '%s\n\n'
         'Loaded plugins:\n%s\n\n' + 'Log:\n%s\n') % (
             version(),
             shell('uname -a'),
             detect_platform(),
             detect_distro(),
             '.'.join([str(x) for x in platform.python_version_tuple()]),
             app.config.filename,
             err,
             pr,
             app.log.blackbox.buffer,
         ))
Exemplo n.º 3
0
def send_stats(server, plugins, addplugin=None, delplugin=None):
    """
    Sends usage statistics to the server. Statistics include: OS name, list of
    installed plugins and Ajenti version.

    :param  server:     server URL
    :type   server:     str
    :param  addplugin:  plugin being currently installed or None
    :type   addplugin:  str
    :param  delplugin:  plugin being currently removed or None
    :type   delplugin:  str
    """
    plugs = []
    plugs.extend(plugins)
    if addplugin:
        plugs.append(addplugin)
    if delplugin and delplugin in plugs:
        plugs.remove(delplugin)
    plugs = ','.join(plugs)
    data = '1|%s|%s|%s|,%s,' % (uid, version(), detect_platform(mapping=False), plugs)
    data = base64.b64encode(data)
    download('http://%s/api/submit?data=%s' % (server, data))
Exemplo n.º 4
0
def send_stats(server, plugins, addplugin=None, delplugin=None):
    """
    Sends usage statistics to the server. Statistics include: OS name, list of
    installed plugins and Ajenti version.

    :param  server:     server URL
    :type   server:     str
    :param  addplugin:  plugin being currently installed or None
    :type   addplugin:  str
    :param  delplugin:  plugin being currently removed or None
    :type   delplugin:  str
    """
    plugs = []
    plugs.extend(plugins)
    if addplugin:
        plugs.append(addplugin)
    if delplugin and delplugin in plugs:
        plugs.remove(delplugin)
    plugs = ','.join(plugs)
    data = '1|%s|%s|%s|,%s,' % (uid, version(), detect_platform(mapping=False),
                                plugs)
    data = base64.b64encode(data)
    download('http://%s/api/submit?data=%s' % (server, data))
Exemplo n.º 5
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level == logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Ajenti %s' % version())

    # We need this early
    ajenti.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s' % config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)

    # Add log handler to config, so all plugins could access it
    config.set('log_facility', log)

    # Start recording log for the bug reports
    log.blackbox.start()

    platform = ajenti.utils.detect_platform()
    log.info('Detected platform: %s' % platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('ajenti', 'plugins'), platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app)  # Register permanent app
    ComponentManager.create(app)

    # Start server
    host = config.get('ajenti', 'bind_host')
    port = config.getint('ajenti', 'bind_port')
    log.info('Listening on %s:%d' % (host, port))

    # SSL params
    ssl = {}
    if config.getint('ajenti', 'ssl') == 1:
        ssl = {
            'keyfile': config.get('ajenti', 'cert_key'),
            'certfile': config.get('ajenti', 'cert_file'),
        }

    log.info('Using HTTP server: %s' % http_server)

    server = WSGIServer((host, port),
                        application=AppDispatcher(config).dispatcher,
                        **ssl)

    config.set('server', server)

    try:
        syslog.openlog(
            ident='ajenti',
            facility=syslog.LOG_AUTH,
        )
    except:
        syslog.openlog('ajenti')

    log.info('Starting server')

    server.serve_forever()

    ComponentManager.get().stop()

    if hasattr(server, 'restart_marker'):
        log.info('Restarting by request')

        fd = 20  # Close all descriptors. Creepy thing
        while fd > 2:
            try:
                os.close(fd)
                log.debug('Closed descriptor #%i' % fd)
            except:
                pass
            fd -= 1

        os.execv(sys.argv[0], sys.argv)
    else:
        log.info('Stopped by request')
Exemplo n.º 6
0
    def process(self, req, start_response):
        self.do_init()

        templ = self.app.get_template("index.xml")

        cat = None
        v = UI.VContainer(spacing=0)

        # Sort plugins by name
        cats = self.app.grab_plugins(ICategoryProvider)
        cats = sorted(cats, key=lambda p: p.text)

        for fld in self.folder_ids:
            cat_vc = UI.VContainer(spacing=0)
            if self.folders[fld] == "":
                cat_folder = cat_vc  # Omit wrapper for special folders
            else:
                cat_folder = UI.CategoryFolder(
                    cat_vc,
                    text=self.folders[fld],
                    icon="/dl/core/ui/catfolders/" + fld + ".png" if self.folders[fld] != "" else "",
                    id=fld,
                )
            # cat_vc will be VContainer or CategoryFolder

            exp = False
            empty = True
            for c in cats:
                if c.folder == fld:  # Put corresponding plugins in this folder
                    empty = False
                    if c == self.selected_category:
                        exp = True
                    cat_vc.append(
                        UI.Category(
                            icon=c.icon,
                            name=c.text,
                            id=c.plugin_id,
                            counter=c.get_counter(),
                            selected=c == self.selected_category,
                        )
                    )

            if not empty:
                v.append(cat_folder)
            cat_folder["expanded"] = exp

        for c in cats:
            if c.folder in ["top", "bottom"]:
                templ.append(
                    "topplaceholder-" + c.folder,
                    UI.TopCategory(
                        text=c.text,
                        id=c.plugin_id,
                        icon=c.icon,
                        counter=c.get_counter(),
                        selected=c == self.selected_category,
                    ),
                )

        templ.append("_head", UI.HeadTitle(text="Ajenti @ %s" % platform.node()))
        templ.append("leftplaceholder", v)
        templ.append("version", UI.Label(text="Ajenti " + version(), size=2))
        templ.insertText("cat-username", self.app.auth.user)
        templ.appendAll(
            "links",
            UI.LinkLabel(text="About", id="about"),
            UI.OutLinkLabel(text="License", url="http://www.gnu.org/licenses/lgpl.html"),
        )

        return templ.render()
Exemplo n.º 7
0
 def get_ui_about(self):
     ui = self.app.inflate("core:about")
     ui.find("ver").set("text", version())
     return ui
Exemplo n.º 8
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level==logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Ajenti %s' % version())

    # We need this early
    ajenti.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s'%config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)
    
    # Add log handler to config, so all plugins could access it
    config.set('log_facility',log)

    # Start recording log for the bug reports
    log.blackbox.start()

    platform = ajenti.utils.detect_platform()
    log.info('Detected platform: %s'%platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('ajenti', 'plugins'), platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app) # Register permanent app
    ComponentManager.create(app)

    # Start server
    host = config.get('ajenti','bind_host')
    port = config.getint('ajenti','bind_port')
    log.info('Listening on %s:%d'%(host, port))

    # SSL params
    ssl = {}
    if config.getint('ajenti', 'ssl') == 1:
        ssl = {
    	    'keyfile':  config.get('ajenti','cert_key'),
    	    'certfile': config.get('ajenti','cert_file'),
    	}

    log.info('Using HTTP server: %s'%http_server)

    server = WSGIServer(
        (host, port),
        application=AppDispatcher(config).dispatcher,
        **ssl
    )

    config.set('server', server)

    try:
        syslog.openlog(
            ident='ajenti',
            facility=syslog.LOG_AUTH,
        )
    except:
        syslog.openlog('ajenti')

    log.info('Starting server')

    server.serve_forever()

    ComponentManager.get().stop()

    if hasattr(server, 'restart_marker'):
        log.info('Restarting by request')

        fd = 20 # Close all descriptors. Creepy thing
        while fd > 2:
            try:
                os.close(fd)
                log.debug('Closed descriptor #%i'%fd)
            except:
                pass
            fd -= 1

        os.execv(sys.argv[0], sys.argv)
    else:
        log.info('Stopped by request')
Exemplo n.º 9
0
    def process(self, req, start_response):
        self.do_init()

        templ = self.app.get_template('index.xml')

        cat = None
        v = UI.VContainer(spacing=0)

        # Sort plugins by name
        cats = self.app.grab_plugins(ICategoryProvider)
        cats = sorted(cats, key=lambda p: p.text)

        for fld in self.folder_ids:
            cat_vc = UI.VContainer(spacing=0)
            if self.folders[fld] == '':
                cat_folder = cat_vc # Omit wrapper for special folders
            else:
                cat_folder = UI.CategoryFolder(
                                cat_vc,
                                text=self.folders[fld],
                                icon='/dl/core/ui/catfolders/'+ fld + '.png'
                                    if self.folders[fld] != '' else '',
                                id=fld
                             )
            # cat_vc will be VContainer or CategoryFolder

            exp = False
            empty = True
            for c in cats:
                if c.folder == fld: # Put corresponding plugins in this folder
                    empty = False
                    if c == self.selected_category:
                        exp = True
                    cat_vc.append(UI.Category(
                        icon=c.icon,
                        name=c.text,
                        id=c.plugin_id,
                        counter=c.get_counter(),
                        selected=c == self.selected_category
                    ))

            if not empty: v.append(cat_folder)
            cat_folder['expanded'] = exp

        for c in cats:
            if c.folder in ['top', 'bottom']:
                templ.append(
                    'topplaceholder-'+c.folder,
                    UI.TopCategory(
                        text=c.text,
                        id=c.plugin_id,
                        icon=c.icon,
                        counter=c.get_counter(),
                        selected=c==self.selected_category
                    )
                )

        templ.append('_head', UI.HeadTitle(text='Ajenti @ %s'%platform.node()))
        templ.append('leftplaceholder', v)
        templ.append('version', UI.Label(text='Ajenti '+version(), size=2))
        templ.insertText('cat-username', self.app.auth.user)
        templ.appendAll('links', 
                UI.LinkLabel(text='About', id='about'),
                UI.OutLinkLabel(text='License', url='http://www.gnu.org/licenses/lgpl.html')
            )

        return templ.render()
Exemplo n.º 10
0
 def get_ui_about(self):
     ui = self.app.inflate('core:about')
     ui.find('ver').set('text', version())
     return ui
Exemplo n.º 11
0
Arquivo: root.py Projeto: vlara/ajenti
    def process(self, req, start_response):
        self.do_init()

        templ = self.app.get_template('index.xml')

        cat = None
        v = UI.VContainer(spacing=0)

        # Sort plugins by name
        cats = self.app.grab_plugins(ICategoryProvider)
        cats = sorted(cats, key=lambda p: p.text)

        for fld in self.folder_ids:
            cat_vc = UI.VContainer(spacing=0)
            if self.folders[fld] == '':
                cat_folder = cat_vc # Omit wrapper for special folders
            else:
                cat_folder = UI.CategoryFolder(
                                cat_vc,
                                text=self.folders[fld],
                                icon='/dl/core/ui/catfolders/'+ fld + '.png'
                                    if self.folders[fld] != '' else '',
                                id=fld
                             )
            # cat_vc will be VContainer or CategoryFolder

            exp = False
            empty = True
            for c in cats:
                if c.folder == fld: # Put corresponding plugins in this folder
                    empty = False
                    if c == self.selected_category:
                        exp = True
                    cat_vc.append(UI.Category(
                        icon=c.icon,
                        name=c.text,
                        id=c.plugin_id,
                        counter=c.get_counter(),
                        selected=c == self.selected_category
                    ))

            if not empty: v.append(cat_folder)
            cat_folder['expanded'] = exp

        for c in cats:
            if c.folder in ['top', 'bottom']:
                templ.append(
                    'topplaceholder-'+c.folder,
                    UI.TopCategory(
                        text=c.text,
                        id=c.plugin_id,
                        icon=c.icon,
                        counter=c.get_counter(),
                        selected=c==self.selected_category
                    )
                )

        templ.append('_head', UI.HeadTitle(text='Ajenti @ %s'%platform.node()))
        templ.append('leftplaceholder', v)
        templ.append('version', UI.Label(text='Ajenti '+version(), size=2))
        templ.insertText('cat-username', self.app.auth.user)
        templ.appendAll('links', 
                UI.LinkLabel(text='About', id='about'),
                UI.OutLinkLabel(text='License', url='http://www.gnu.org/licenses/lgpl.html')
            )

        return templ.render()
Exemplo n.º 12
0
Arquivo: root.py Projeto: vlara/ajenti
 def get_ui_about(self):
     ui = self.app.inflate('core:about')
     ui.find('ver').set('text', version())
     return ui