X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FHeavy.java;h=8fa72677a31461728dbd49e0dd6e437634f11d8c;hb=b4f8b90cdb5353c6862235bb799c620e6865ac28;hp=4dcd0fc4317723b6cc1740bb05bb1416f677d891;hpb=ba6b96a349051e64a04e8969bb1f907d9d4b01a7;p=fonbot.git diff --git a/src/ro/ieval/fonbot/Heavy.java b/src/ro/ieval/fonbot/Heavy.java index 4dcd0fc..8fa7267 100644 --- a/src/ro/ieval/fonbot/Heavy.java +++ b/src/ro/ieval/fonbot/Heavy.java @@ -3,11 +3,13 @@ package ro.ieval.fonbot; import static ro.ieval.fonbot.R.string.*; import static ro.ieval.fonbot.Utils.toNonNull; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; @@ -665,6 +667,17 @@ final class Heavy { case TORCH: Utils.sendMessage(context, replyTo, torch_help); break; + case GETFILE: + Utils.sendMessage(context, replyTo, getfile_help); + break; + case SH: + Utils.sendMessage(context, replyTo, sh_help); + break; + case ROOTSH: + Utils.sendMessage(context, replyTo, rootsh_help); + break; + default: + Utils.sendMessage(context, replyTo, command_not_documented); } } @@ -1927,4 +1940,30 @@ final class Heavy { public static void getfile(final Context context, final Address replyTo, final String filename, final String hostname, final int port){ new GetfileExecutableRunnable(context, replyTo, filename, hostname, port).execute(); } + + /** + * Execute a command using a given shell and reply with the output. + * + * @param context Context instance + * @param replyTo reply Address + * @param shell The shell to execute with. Usually sh or su. + * @param command The command to pass to the shell. + */ + public static void execute(final Context context, final Address replyTo, final String shell, final String command) { + try { + final Process proc = Runtime.getRuntime().exec(new String[]{ + shell, + "-c", + command + }); + final BufferedReader br = new BufferedReader (new InputStreamReader(proc.getInputStream())); + String line; + while((line = br.readLine()) != null) + Utils.sendMessage(context, replyTo, line); + proc.waitFor(); + } catch (final Exception e){ + Utils.sendMessage(context, replyTo, error_while_processing_command, e.getClass().getName(), e.getMessage()); + Log.w(Heavy.class.getName(), "Error while processing command", e); + } + } }