static void install(final Env env, final Config conf) { String path = conf.getString("crash.httpshell.path"); Router router = env.router(); router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> { MediaType type = req.accepts(MediaType.json) .map(it -> MediaType.json) .orElse(MediaType.html); PluginContext ctx = req.require(PluginContext.class); ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class); Shell shell = shellFactory.create(null); String cmd = req.param("cmd").value().replaceAll("/", " "); ShellProcess process = shell.createProcess(cmd); ShellProcessContext spc = new SimpleProcessContext( result -> deferred.resolve(result.type(type))); process.execute(spc); })); }
Integer port = getContext().getProperty(SSH_PORT); if (port == null) { log.log(Level.INFO, "Could not boot SSHD due to missing due to missing port configuration"); Integer idleTimeout = getContext().getProperty(SSH_SERVER_IDLE_TIMEOUT); if (idleTimeout == null) { idleTimeout = SSH_SERVER_IDLE_DEFAULT_TIMEOUT; Integer authTimeout = getContext().getProperty(SSH_SERVER_AUTH_TIMEOUT); if (authTimeout == null) { authTimeout = SSH_SERVER_AUTH_DEFAULT_TIMEOUT; Resource serverKeyRes = getContext().loadResource("hostkey.pem", ResourceKind.CONFIG); if (serverKeyRes != null) { serverKey = serverKeyRes; String serverKeyPath = getContext().getProperty(SSH_SERVER_KEYPATH); if (serverKeyPath != null) { log.log(Level.FINE, "Found server key path " + serverKeyPath); File f = new File(serverKeyPath); String keyGen = getContext().getProperty(SSH_SERVER_KEYGEN); if (keyGen != null && keyGen.equals("true")) { keyPairProvider = new PEMGeneratorHostKeyProvider(serverKeyPath, "RSA"); List authentication = getContext().getProperty(AuthenticationPlugin.AUTH); if (authentication != null) { for (AuthenticationPlugin authenticationPlugin : getContext().getPlugins(AuthenticationPlugin.class)) { if (authentication.contains(authenticationPlugin.getName())) { authPlugins.add(authenticationPlugin);
public PluginContext start(final ClassLoader loader, final Properties props, final Map<String, Object> attributes, final Set<CRaSHPlugin<?>> plugins) throws IOException { FS conffs = newFS(CrashFSDriver.parse(loader, asList(new CrashPredicate("crash", ACCEPT)))); FS cmdfs = newFS(CrashFSDriver.parse(loader, asList( new CrashPredicate("cmd", ACCEPT), new CrashPredicate("org/jooby/crash", ACCEPT), new CrashPredicate("crash/commands", noneOf("jndi.groovy", "jdbc.groovy", "jpa.groovy", "jul.groovy"))))); setConfig(props); PluginContext ctx = new PluginContext(executor("crash"), scanner("crash-scanner"), () -> plugins, attributes, cmdfs, conffs, loader); ctx.refresh(); start(ctx); return ctx; }
private void configureProperty(PluginContext context, Properties props, PropertyDescriptor<?> desc) { String key = "crash." + desc.name; String value = props.getProperty(key); if (value != null) { try { if (context.getProperty(desc) == null) { log.log(Level.INFO, "Configuring property " + desc.name + "=" + value + " from properties"); context.setProperty(desc, value); } } catch (IllegalArgumentException e) { log.log(Level.SEVERE, "Could not configure property", e); } } } }
String configPath = getContext().getProperty(CRON_CONFIG_PATH); if (configPath != null) { File configFile = new File(configPath); Resource res = getContext().loadResource("crontab", ResourceKind.CONFIG); if (res != null) { config = res;
@Override public void init() { PluginContext context = getContext(); this.username = context.getProperty(SIMPLE_USERNAME); this.password = context.getProperty(SIMPLE_PASSWORD); }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
public void init() { try { ShellFactory factory = context.getPlugin(ShellFactory.class); for (SubsystemFactoryPlugin plugin : context.getPlugins(SubsystemFactoryPlugin.class)) { namedFactoryList.add(plugin.getFactory());
public final TermIOHandler getHandler() { Iterator<TermIOHandler> handlers = context.getPlugins(TermIOHandler.class).iterator(); if (handlers.hasNext()) { return handlers.next(); } else { return null; } }
public void run() { refresh(); } }, 0, refreshRate, tu);
Resource res = context.loadResource("crash.properties", ResourceKind.CONFIG); if (res != null) { try { context.start();
PluginContext ctx = new PluginContext( new ServiceLoaderDiscovery(Thread.currentThread().getContextClassLoader()), Collections.<String, Object>emptyMap(), confFS, Thread.currentThread().getContextClassLoader()); ctx.refresh(); CRaSH crash = new CRaSH(ctx); for (String s : ctx.listResourceId(ResourceKind.COMMAND)) { ShellCommand cmd = crash.getCommand(s); StringBuilder man = new StringBuilder();
private Resource getResource(String name) { return context.loadResource(name, kind); }
/** * Create the plugin context, allow subclasses to customize it. * * @param discovery the plugin discovery * @return the plugin context */ protected PluginContext create(Map<String, Object> attributes, PluginDiscovery discovery, ClassLoader loader) { // FS cmdFS; FS confFS; try { cmdFS = createCommandFS(); confFS = createConfFS(); } catch (IOException e) { log.log(Level.SEVERE, "Coult not initialize the file system", e); return null; } // return new PluginContext(discovery, attributes, cmdFS, confFS, loader); }
public Shell create(Principal principal, boolean async) { CRaSHSession session = crash.createSession(principal); if (async) { return new AsyncShell(getContext().getExecutor(), session); } else { return session; } }
public <T> void setProperty(PropertyDescriptor<T> desc, T value) throws NullPointerException { context.setProperty(desc, value); }
Resource res = getContext().loadResource("telnet.properties", ResourceKind.CONFIG); if (res != null) { config = res; Integer port = context.getProperty(TELNET_PORT); if (port == null) { port = TELNET_PORT.defaultValue;
@Override public void init() { smtpHost = getContext().getProperty(SMTP_HOST); smtpPort = getContext().getProperty(SMTP_PORT); smtpSecure = getContext().getProperty(SMTP_SECURE); smtpUsername = getContext().getProperty(SMTP_USERNAME); smtpPassword = getContext().getProperty(SMTP_PASSWORD); smtpFrom = getContext().getProperty(SMTP_FROM); debug = getContext().getProperty(DEBUG); }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
public void init() { try { ShellFactory factory = context.getPlugin(ShellFactory.class); for (SubsystemFactoryPlugin plugin : context.getPlugins(SubsystemFactoryPlugin.class)) { namedFactoryList.add(plugin.getFactory());