def make_report(app, err): """ Formats a bug report. """ from netcontrol.plugmgr import PluginLoader pr = '' for p in sorted(PluginLoader.list_plugins().keys()): pr += p + '\n' # Finalize the reported log app.log.blackbox.stop() return ( ('Netcontrol %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, ))
def make_report(app, err): """ Formats a bug report. """ from netcontrol.plugmgr import PluginLoader pr = '' for p in sorted(PluginLoader.list_plugins().keys()): pr += p + '\n' # Finalize the reported log app.log.blackbox.stop() return (('Netcontrol %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, ))
def send_stats(server, plugins, addplugin=None, delplugin=None): """ Sends usage statistics to the server. Statistics include: OS name, list of installed plugins and Netcontrol 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)
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('Netcontrol %s' % version()) # We need this early netcontrol.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 = netcontrol.utils.detect_platform() log.info('Detected platform: %s' % platform) # Load external plugins PluginLoader.initialize(log, config.get('netcontrol', '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('netcontrol', 'bind_host') port = config.getint('netcontrol', 'bind_port') log.info('Listening on %s:%d' % (host, port)) # SSL params ssl = {} if config.getint('netcontrol', 'ssl') == 1: ssl = { 'keyfile': config.get('netcontrol', 'cert_key'), 'certfile': config.get('netcontrol', 'cert_file'), } server = gevent.pywsgi.WSGIServer( (host, port), application=AppDispatcher(config).dispatcher, **ssl) config.set('server', server) 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')
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("Netcontrol %s" % version()) # We need this early netcontrol.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 = netcontrol.utils.detect_platform() log.info("Detected platform: %s" % platform) # Load external plugins PluginLoader.initialize(log, config.get("netcontrol", "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("netcontrol", "bind_host") port = config.getint("netcontrol", "bind_port") log.info("Listening on %s:%d" % (host, port)) # SSL params ssl = {} if config.getint("netcontrol", "ssl") == 1: ssl = {"keyfile": config.get("netcontrol", "cert_key"), "certfile": config.get("netcontrol", "cert_file")} server = gevent.pywsgi.WSGIServer((host, port), application=AppDispatcher(config).dispatcher, **ssl) config.set("server", server) 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")
def get_ui_about(self): ui = self.app.inflate('core:about') ui.find('ver').set('text', version()) return ui
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='NetControl @ %s'%platform.node())) templ.append('leftplaceholder', v) templ.append('version', UI.Label(text='Netcontrol '+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()
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='NetControl @ %s' % platform.node())) templ.append('leftplaceholder', v) templ.append('version', UI.Label(text='Netcontrol ' + 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()