Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ability to redirect to file

  • Loading branch information...
commit 0c445dda94625434812ec73e2d01d08d1687a172 1 parent f9e0be1
@phdesign authored
View
1  NetBash/CommandResult.cs
@@ -9,5 +9,6 @@ internal class CommandResult
{
public string Result { get; set; }
public bool IsHtml { get; set; }
+ public string FileName { get; set; }
}
}
View
9 NetBash/NetBash.cs
@@ -73,7 +73,14 @@ internal CommandResult Process(string commandText)
var webCommand = (IWebCommand)Activator.CreateInstance(commandType);
var result = new CommandResult() { IsHtml = webCommand.ReturnHtml };
- result.Result = webCommand.Process(split.Skip(1).ToArray());
+ // Check for file redirect
+ var args = split.Skip(1).ToArray();
+ if (args.Length >= 2 && args[args.Length - 2] == ">")
+ {
+ result.FileName = args[args.Length - 1];
+ Array.Resize(ref args, args.Length - 2);
+ }
+ result.Result = webCommand.Process(args);
return result;
}
View
25 NetBash/UI/NetBashHandler.cs
@@ -42,6 +42,7 @@ internal static void RegisterRoutes()
var urls = new[]
{
"netbash",
+ "netbash-export",
"netbash-jquery-js",
"netbash-keymaster-js",
"netbash-style-css",
@@ -108,6 +109,10 @@ public void ProcessRequest(HttpContext context)
output = RenderCommand(context);
break;
+ case "netbash-export":
+ output = ExportCommand(context);
+ break;
+
default:
output = NotFound(context);
break;
@@ -157,6 +162,26 @@ private static string RenderCommand(HttpContext context)
return sb.ToString();
}
+ private static string ExportCommand(HttpContext context)
+ {
+ if (NetBash.Settings.Authorize != null && !NetBash.Settings.Authorize(HttpContext.Current.Request))
+ throw new UnauthorizedAccessException();
+
+ try
+ {
+ var result = NetBash.Current.Process(context.Request.Params["Command"]);
+ context.Response.ContentType = "application/octet-stream";
+ context.Response.AddHeader(
+ "Content-Disposition",
+ "attachment; filename=" + (string.IsNullOrEmpty(result.FileName) ? "result.txt" : result.FileName));
+ return result.Result;
+ }
+ catch (Exception ex)
+ {
+ return ex.Message;
+ }
+ }
+
/// <summary>
/// Handles rendering static content files.
/// </summary>
View
13 NetBash/UI/script-js.js
@@ -101,7 +101,18 @@ function NetBash($, window, opt) {
if (text == "clear") {
$("#console-result").html("");
clearStorage();
- } else {
+ } else {
+ // Check for file redirect
+ var args = $.grep(text.split(/("[^"]*")|([^\s]+)/g), function(n) { return ($.trim(n)); });
+ if (args.length > 2 && args[args.length - 2] == ">") {
+ $('<form action="' + options.routeBasePath + 'netbash-export" method="post" style="display:none;"></form>')
+ .append($('<input type="text" name="Command"></input>').val(text))
+ .appendTo('body')
+ .submit()
+ .remove();
+ return;
+ }
+
self.startLoader();
//send command
Please sign in to comment.
Something went wrong with that request. Please try again.