Skip to content

Commit 8abf78c

Browse files
authored
Merge pull request #368 from cmu-sei/v8
V8
2 parents e2373d8 + 351ba12 commit 8abf78c

File tree

19 files changed

+690
-122
lines changed

19 files changed

+690
-122
lines changed

src/Ghosts.Client/Ghosts.Client.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@
162162
<Compile Include="Comms\ClientSocket\BackgroundTaskQueue.cs" />
163163
<Compile Include="Comms\ClientSocket\ClientSocketConnection.cs" />
164164
<Compile Include="Comms\ClientSocket\QueueEntry.cs" />
165-
<Compile Include="Handlers\AwsCli.cs" />
165+
<Compile Include="Handlers\Aws.cs" />
166+
<Compile Include="Handlers\Azure.cs" />
166167
<Compile Include="Handlers\BaseBrowserHandler.cs" />
167168
<Compile Include="Handlers\BlogHelper.cs" />
168169
<Compile Include="Handlers\BlogHelperDrupal.cs" />
@@ -280,6 +281,9 @@
280281
<None Include="kill-ghosts.bat">
281282
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
282283
</None>
284+
<None Include="Sample Timelines\Aws.json" />
285+
<None Include="Sample Timelines\Browser Crawl.json" />
286+
<None Include="Sample Timelines\Browser upload.json" />
283287
<None Include="Sample Timelines\BrowserFirefoxSocial.json" />
284288
<None Include="Sample Timelines\Cron.json" />
285289
<None Include="Sample Timelines\Administrative Commands.json" />
@@ -301,6 +305,7 @@
301305
<Compile Include="TimelineManager\Orchestrator.cs" />
302306
<Compile Include="Program.cs" />
303307
<Compile Include="Properties\AssemblyInfo.cs" />
308+
<None Include="Sample Timelines\NpcSystem.json" />
304309
<None Include="Sample Timelines\outlook.json" />
305310
<None Include="Sample Timelines\Outlookv2.json" />
306311
<None Include="Sample Timelines\Pidgin.json" />

src/Ghosts.Client/Handlers/Aws.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.
2+
3+
using System;
4+
using System.Diagnostics;
5+
using System.Threading;
6+
using Ghosts.Domain;
7+
using Ghosts.Domain.Code;
8+
using Ghosts.Domain.Code.Helpers;
9+
10+
namespace Ghosts.Client.Handlers
11+
{
12+
public class Aws : BaseHandler
13+
{
14+
private string Result { get; set; }
15+
private readonly TimelineHandler _handler;
16+
17+
public Aws(TimelineHandler handler)
18+
{
19+
_handler = handler;
20+
21+
try
22+
{
23+
if (_handler.Loop)
24+
{
25+
while (true)
26+
{
27+
Ex();
28+
}
29+
}
30+
31+
Ex();
32+
}
33+
catch (Exception e)
34+
{
35+
Log.Error(e);
36+
}
37+
}
38+
39+
private void Ex()
40+
{
41+
var handlerArgs = BuildHandlerArgVariables.BuildHandlerArgs(_handler);
42+
foreach (var timelineEvent in _handler.TimeLineEvents)
43+
{
44+
WorkingHours.Is(_handler);
45+
46+
if (timelineEvent.DelayBeforeActual > 0)
47+
Thread.Sleep(timelineEvent.DelayBeforeActual);
48+
49+
switch (timelineEvent.Command)
50+
{
51+
default:
52+
foreach (var cmdObj in timelineEvent.CommandArgs)
53+
{
54+
var cmd = cmdObj?.ToString();
55+
if (!string.IsNullOrEmpty(cmd))
56+
{
57+
cmd = BuildHandlerArgVariables.ReplaceCommandVariables(cmd, handlerArgs);
58+
this.Command(cmd);
59+
}
60+
}
61+
62+
break;
63+
}
64+
if (timelineEvent.DelayAfterActual <= 0) continue;
65+
Thread.Sleep(timelineEvent.DelayAfterActual);
66+
}
67+
}
68+
69+
private void Command(string command)
70+
{
71+
this.Result = string.Empty;
72+
73+
command = $"{command} --no-verify";
74+
75+
try
76+
{
77+
var p = new Process
78+
{
79+
EnableRaisingEvents = false,
80+
StartInfo =
81+
{
82+
FileName = "aws",
83+
Arguments = command,
84+
UseShellExecute = false,
85+
RedirectStandardOutput = true,
86+
RedirectStandardError = true,
87+
CreateNoWindow = true
88+
}
89+
};
90+
p.Start();
91+
92+
while (!p.StandardOutput.EndOfStream)
93+
{
94+
this.Result += p.StandardOutput.ReadToEnd();
95+
}
96+
97+
var err = string.Empty;
98+
while (!p.StandardError.EndOfStream)
99+
{
100+
err += p.StandardError.ReadToEnd();
101+
}
102+
err = err.RemoveTextBetweenMarkers("urllib3/connectionpool", "#ssl-warnings");
103+
if (err.Length > 0)
104+
{
105+
Log.Error($"{err} on {command}");
106+
}
107+
108+
Report(new ReportItem {Handler = HandlerType.Aws.ToString(), Command = command, Result = this.Result});
109+
}
110+
catch (Exception exc)
111+
{
112+
Log.Debug(exc);
113+
}
114+
}
115+
}
116+
}

src/Ghosts.Client/Handlers/AwsCli.cs

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/Ghosts.Client/Handlers/Azure.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.
2+
3+
using System;
4+
using System.Diagnostics;
5+
using System.Threading;
6+
using Ghosts.Domain;
7+
using Ghosts.Domain.Code;
8+
9+
namespace Ghosts.Client.Handlers
10+
{
11+
public class Azure : BaseHandler
12+
{
13+
private string Result { get; set; }
14+
private readonly TimelineHandler _handler;
15+
16+
public Azure(TimelineHandler handler)
17+
{
18+
_handler = handler;
19+
20+
try
21+
{
22+
if (_handler.Loop)
23+
{
24+
while (true)
25+
{
26+
Ex();
27+
}
28+
}
29+
30+
Ex();
31+
}
32+
catch (Exception e)
33+
{
34+
Log.Error(e);
35+
}
36+
}
37+
38+
private void Ex()
39+
{
40+
var handlerArgs = BuildHandlerArgVariables.BuildHandlerArgs(_handler);
41+
foreach (var timelineEvent in _handler.TimeLineEvents)
42+
{
43+
WorkingHours.Is(_handler);
44+
45+
if (timelineEvent.DelayBeforeActual > 0)
46+
Thread.Sleep(timelineEvent.DelayBeforeActual);
47+
48+
switch (timelineEvent.Command)
49+
{
50+
default:
51+
foreach (var cmdObj in timelineEvent.CommandArgs)
52+
{
53+
var cmd = cmdObj?.ToString();
54+
if (!string.IsNullOrEmpty(cmd))
55+
{
56+
cmd = BuildHandlerArgVariables.ReplaceCommandVariables(cmd, handlerArgs);
57+
this.Command(cmd);
58+
}
59+
}
60+
61+
break;
62+
}
63+
if (timelineEvent.DelayAfterActual <= 0) continue;
64+
Thread.Sleep(timelineEvent.DelayAfterActual);
65+
}
66+
}
67+
68+
private void Command(string command)
69+
{
70+
this.Result = string.Empty;
71+
72+
try
73+
{
74+
var p = new Process
75+
{
76+
EnableRaisingEvents = false,
77+
StartInfo =
78+
{
79+
FileName = "az",
80+
Arguments = command,
81+
UseShellExecute = false,
82+
RedirectStandardOutput = true,
83+
RedirectStandardError = true,
84+
CreateNoWindow = true
85+
}
86+
};
87+
p.Start();
88+
89+
while (!p.StandardOutput.EndOfStream)
90+
{
91+
this.Result += p.StandardOutput.ReadToEnd();
92+
}
93+
94+
var err = string.Empty;
95+
while (!p.StandardError.EndOfStream)
96+
{
97+
err += p.StandardError.ReadToEnd();
98+
}
99+
if (err.Length > 0)
100+
{
101+
Log.Error($"{err} on {command}");
102+
}
103+
104+
Report(new ReportItem {Handler = HandlerType.Azure.ToString(), Command = command, Result = this.Result});
105+
}
106+
catch (Exception exc)
107+
{
108+
Log.Debug(exc);
109+
}
110+
}
111+
}
112+
}

src/Ghosts.Client/Health/Check.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Threading;
7-
using Ghosts.Client.Infrastructure;
87
using Ghosts.Domain;
98
using Ghosts.Domain.Code;
109
using Newtonsoft.Json;
@@ -29,7 +28,7 @@ public Check()
2928
public void Run()
3029
{
3130
// now watch that file for changes
32-
_watcher = new FileSystemWatcher(ApplicationDetails.ConfigurationFiles.Path);
31+
_watcher = new FileSystemWatcher(ApplicationDetails.ConfigurationFiles.InstallPath);
3332
_watcher.Filter = Path.GetFileName(ApplicationDetails.ConfigurationFiles.Health);
3433
_log.Trace($"watching {_watcher.Path}");
3534
_watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName | NotifyFilters.Size;

src/Ghosts.Client/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("8.0.0.0")]
3636
[assembly: AssemblyInformationalVersion("8.0.0.0")]
37-
[assembly: AssemblyFileVersion("8.0.51.50")]
37+
[assembly: AssemblyFileVersion("8.1.0.0")]

0 commit comments

Comments
 (0)