Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NetBash/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ internal class CommandResult
{
public string Result { get; set; }
public bool IsHtml { get; set; }
public string FileName { get; set; }
}
}
9 changes: 8 additions & 1 deletion NetBash/NetBash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions NetBash/UI/NetBashHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal static void RegisterRoutes()
var urls = new[]
{
"netbash",
"netbash-export",
"netbash-jquery-js",
"netbash-keymaster-js",
"netbash-style-css",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down
13 changes: 12 additions & 1 deletion NetBash/UI/script-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down