Skip to content

Commit

Permalink
Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Nov 28, 2019
1 parent 6668377 commit 70023ee
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/TuringMachine.Core/Helpers/EnumeratorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;

namespace TuringMachine.Core.Helpers
{
public static class EnumeratorHelper
{
/// <summary>
/// To arryy
/// </summary>
/// <typeparam name="T">Type</typeparam>
/// <param name="index">Index</param>
/// <param name="count">Count</param>
/// <returns>Array</returns>
public static T[] ToArray<T>(this IEnumerable<T> input, int index = -1, int count = -1)
{
if (index > 0) input = input.Skip(index);
if (count >= 0) input = input.Take(count);

return Enumerable.ToArray(input);
}
}
}
11 changes: 9 additions & 2 deletions src/TuringMachine/RPC/Controllers/ConfigsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TuringMachine.Core.Helpers;
using TuringMachine.Core.Interfaces;
using TuringMachine.Core.Logs;

Expand Down Expand Up @@ -42,10 +43,16 @@ public ActionResult<bool> Remove(Guid id)
return false;
}

[HttpGet("count")]
public ActionResult<int> Count()
{
return _server.Server.Configurations.Count;
}

[HttpGet("all")]
public ActionResult<IEnumerable<FuzzingConfigBase>> GetAll()
public ActionResult<IEnumerable<FuzzingConfigBase>> GetAll(int index = -1, int count = -1)
{
return _server.Server.Configurations.Values.Select(u => u.Source).ToArray();
return _server.Server.Configurations.Values.Select(u => u.Source).ToArray(index, count);
}

[HttpGet("stat")]
Expand Down
13 changes: 10 additions & 3 deletions src/TuringMachine/RPC/Controllers/ConnectionsController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using TuringMachine.Core.Fuzzers;
using TuringMachine.Core.Helpers;
using TuringMachine.Core.Logs;

namespace TuringMachine.RPC.Controllers
Expand All @@ -23,10 +24,16 @@ public ConnectionsController(RpcServer server)
_server = server;
}

[HttpGet("count")]
public ActionResult<int> Count()
{
return _server.Server.Connections.Count;
}

[HttpGet("all")]
public ActionResult<IEnumerable<FuzzerClientInfo>> GetAll()
public ActionResult<IEnumerable<FuzzerClientInfo>> GetAll(int index = -1, int count = -1)
{
return _server.Server.Connections.Values.Select(u => u.Source).ToArray();
return _server.Server.Connections.Values.Select(u => u.Source).ToArray(index, count);
}

[HttpGet("stat")]
Expand Down
11 changes: 9 additions & 2 deletions src/TuringMachine/RPC/Controllers/InputsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TuringMachine.Core.Helpers;
using TuringMachine.Core.Interfaces;
using TuringMachine.Core.Logs;

Expand Down Expand Up @@ -42,10 +43,16 @@ public ActionResult<bool> Remove(Guid id)
return false;
}

[HttpGet("count")]
public ActionResult<int> Count()
{
return _server.Server.Inputs.Count;
}

[HttpGet("all")]
public ActionResult<IEnumerable<FuzzingInputBase>> GetAll()
public ActionResult<IEnumerable<FuzzingInputBase>> GetAll(int index = -1, int count = -1)
{
return _server.Server.Inputs.Values.Select(u => u.Source).ToArray();
return _server.Server.Inputs.Values.Select(u => u.Source).ToArray(index, count);
}

[HttpGet("stat")]
Expand Down
37 changes: 37 additions & 0 deletions src/TuringMachine/RPC/Controllers/ResultsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using TuringMachine.Core.Helpers;
using TuringMachine.Core.Logs;

namespace TuringMachine.RPC.Controllers
{
[ApiController, Route("results")]
public class ResultsController : ControllerBase
{
/// <summary>
/// Server
/// </summary>
private readonly RpcServer _server;

/// <summary>
/// Controller
/// </summary>
public ResultsController(RpcServer server)
{
_server = server;
}

[HttpGet("count")]
public ActionResult<int> Count()
{
return _server.Server.Logs.Count;
}

[HttpGet("all")]
public ActionResult<IEnumerable<FuzzerLog>> GetAll(int index = -1, int count = -1)
{
return _server.Server.Logs.Values.ToArray(index, count);
}
}
}

0 comments on commit 70023ee

Please sign in to comment.