Skip to content

Commit

Permalink
Isolate taskmaster package to localmachine collector, to enable other…
Browse files Browse the repository at this point in the history
… OS builds again
  • Loading branch information
lkarlslund committed Mar 28, 2022
1 parent f2cd313 commit 195fb65
Show file tree
Hide file tree
Showing 4 changed files with 624 additions and 533 deletions.
2 changes: 1 addition & 1 deletion modules/integrations/localmachine/collect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func Collect(outputpath string) error {
Tasks: func() []localmachine.RegisteredTask {
tasks := make([]localmachine.RegisteredTask, len(scheduledtasksinfo))
for i, task := range scheduledtasksinfo {
tasks[i] = localmachine.ConvertRegisteredTask(task)
tasks[i] = ConvertRegisteredTask(task)
}
return tasks
}(),
Expand Down
74 changes: 74 additions & 0 deletions modules/integrations/localmachine/collect/taskmaster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package collect

import (
"github.com/amidaware/taskmaster"
"github.com/lkarlslund/adalanche/modules/integrations/localmachine"
)

func ConvertRegisteredTask(rt taskmaster.RegisteredTask) localmachine.RegisteredTask {
return localmachine.RegisteredTask{
Name: rt.Name,
Path: rt.Path,
Definition: localmachine.TaskDefinition{
Actions: func() []string {
a := make([]string, len(rt.Definition.Actions))
for i, v := range rt.Definition.Actions {
a[i] = v.GetType().String()
}
return a
}(),
Context: rt.Definition.Context,
Data: rt.Definition.Data,
Principal: localmachine.Principal{
Name: rt.Definition.Principal.Name,
GroupID: rt.Definition.Principal.GroupID,
ID: rt.Definition.Principal.ID,
LogonType: int(rt.Definition.Principal.LogonType),
RunLevel: int(rt.Definition.Principal.RunLevel),
UserID: rt.Definition.Principal.UserID,
},
RegistrationInfo: localmachine.RegistrationInfo{
Author: rt.Definition.RegistrationInfo.Author,
Date: rt.Definition.RegistrationInfo.Date,
Description: rt.Definition.RegistrationInfo.Description,
Documentation: rt.Definition.RegistrationInfo.Documentation,
SecurityDescriptor: rt.Definition.RegistrationInfo.SecurityDescriptor,
Source: rt.Definition.RegistrationInfo.Source,
URI: rt.Definition.RegistrationInfo.URI,
Version: rt.Definition.RegistrationInfo.Version,
},
// .Definition.RegistrationInfo,
Settings: localmachine.TaskSettings{
AllowDemandStart: rt.Definition.Settings.AllowDemandStart,
AllowHardTerminate: rt.Definition.Settings.AllowHardTerminate,
DeleteExpiredTaskAfter: rt.Definition.Settings.DeleteExpiredTaskAfter,
DontStartOnBatteries: rt.Definition.Settings.DontStartOnBatteries,
Enabled: rt.Definition.Settings.Enabled,
TimeLimit: rt.Definition.Settings.TimeLimit,
Hidden: rt.Definition.Settings.Hidden,
Priority: rt.Definition.Settings.Priority,
RestartCount: rt.Definition.Settings.RestartCount,
RestartInterval: rt.Definition.Settings.RestartInterval,
RunOnlyIfIdle: rt.Definition.Settings.RunOnlyIfIdle,
RunOnlyIfNetworkAvailable: rt.Definition.Settings.RunOnlyIfNetworkAvailable,
StartWhenAvailable: rt.Definition.Settings.StartWhenAvailable,
StopIfGoingOnBatteries: rt.Definition.Settings.StopIfGoingOnBatteries,
WakeToRun: rt.Definition.Settings.WakeToRun,
},
Triggers: func() []string {
a := make([]string, len(rt.Definition.Triggers))
for i, v := range rt.Definition.Triggers {
a[i] = v.GetType().String()
}
return a
}(),
XMLText: rt.Definition.XMLText,
},
Enabled: rt.Enabled,
State: rt.State.String(),
MissedRuns: rt.MissedRuns,
NextRunTime: rt.NextRunTime,
LastRunTime: rt.LastRunTime,
LastTaskResult: uint32(rt.LastTaskResult),
}
}
92 changes: 49 additions & 43 deletions modules/integrations/localmachine/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net"
"time"

"github.com/amidaware/taskmaster"
"github.com/lkarlslund/adalanche/modules/basedata"
"github.com/lkarlslund/go-win64api/shared"
"github.com/rickb777/date/period"
)

type Info struct {
Expand Down Expand Up @@ -169,56 +169,62 @@ type RegisteredTask struct {
Path string // the path to where the registered task is stored
Definition TaskDefinition
Enabled bool
State taskmaster.TaskState // the operational state of the registered task
MissedRuns uint // the number of times the registered task has missed a scheduled run
NextRunTime time.Time // the time when the registered task is next scheduled to run
LastRunTime time.Time // the time the registered task was last run
LastTaskResult taskmaster.TaskResult // the results that were returned the last time the registered task was run
State string // the operational state of the registered task
MissedRuns uint // the number of times the registered task has missed a scheduled run
NextRunTime time.Time // the time when the registered task is next scheduled to run
LastRunTime time.Time // the time the registered task was last run
LastTaskResult uint32 // the results that were returned the last time the registered task was run
}

type TaskDefinition struct {
Actions []string
Context string // specifies the security context under which the actions of the task are performed
Data string // the data that is associated with the task
Principal taskmaster.Principal
RegistrationInfo taskmaster.RegistrationInfo
Settings taskmaster.TaskSettings
Principal Principal
RegistrationInfo RegistrationInfo
Settings TaskSettings
Triggers []string
XMLText string // the XML-formatted definition of the task
}

func ConvertRegisteredTask(rt taskmaster.RegisteredTask) RegisteredTask {
return RegisteredTask{
Name: rt.Name,
Path: rt.Path,
Definition: TaskDefinition{
Actions: func() []string {
a := make([]string, len(rt.Definition.Actions))
for i, v := range rt.Definition.Actions {
a[i] = v.GetType().String()
}
return a
}(),
Context: rt.Definition.Context,
Data: rt.Definition.Data,
Principal: rt.Definition.Principal,
RegistrationInfo: rt.Definition.RegistrationInfo,
Settings: rt.Definition.Settings,
Triggers: func() []string {
a := make([]string, len(rt.Definition.Triggers))
for i, v := range rt.Definition.Triggers {
a[i] = v.GetType().String()
}
return a
}(),
XMLText: rt.Definition.XMLText,
},
Enabled: rt.Enabled,
State: rt.State,
MissedRuns: rt.MissedRuns,
NextRunTime: rt.NextRunTime,
LastRunTime: rt.LastRunTime,
LastTaskResult: rt.LastTaskResult,
}

type Principal struct {
Name string // the name of the principal
GroupID string // the identifier of the user group that is required to run the tasks
ID string // the identifier of the principal
LogonType int // the security logon method that is required to run the tasks
RunLevel int // the identifier that is used to specify the privilege level that is required to run the tasks
UserID string // the user identifier that is required to run the tasks
}

type RegistrationInfo struct {
Author string
Date time.Time
Description string
Documentation string
SecurityDescriptor string
Source string
URI string
Version string
}

type TaskSettings struct {
AllowDemandStart bool // indicates that the task can be started by using either the Run command or the Context menu
AllowHardTerminate bool // indicates that the task may be terminated by the Task Scheduler service using TerminateProcess
// Compatibility TaskCompatibility // indicates which version of Task Scheduler a task is compatible with
DeleteExpiredTaskAfter string // the amount of time that the Task Scheduler will wait before deleting the task after it expires
DontStartOnBatteries bool // indicates that the task will not be started if the computer is running on batteries
Enabled bool // indicates that the task is enabled
TimeLimit period.Period // the amount of time that is allowed to complete the task
Hidden bool // indicates that the task will not be visible in the UI
// IdleSettings
// MultipleInstances TaskInstancesPolicy // defines how the Task Scheduler deals with multiple instances of the task
// NetworkSettings
Priority uint // the priority level of the task, ranging from 0 - 10, where 0 is the highest priority, and 10 is the lowest. Only applies to ComHandler, Email, and MessageBox actions
RestartCount uint // the number of times that the Task Scheduler will attempt to restart the task
RestartInterval period.Period // specifies how long the Task Scheduler will attempt to restart the task
RunOnlyIfIdle bool // indicates that the Task Scheduler will run the task only if the computer is in an idle condition
RunOnlyIfNetworkAvailable bool // indicates that the Task Scheduler will run the task only when a network is available
StartWhenAvailable bool // indicates that the Task Scheduler can start the task at any time after its scheduled time has passed
StopIfGoingOnBatteries bool // indicates that the task will be stopped if the computer is going onto batteries
WakeToRun bool // indicates that the Task Scheduler will wake the computer when it is time to run the task, and keep the computer awake until the task is completed
}
Loading

0 comments on commit 195fb65

Please sign in to comment.