MCPcopy Create free account
hub / github.com/Macmod/godap / GetAttrCellColor

Function GetAttrCellColor

tui/theme.go:236–385  ·  view source on GitHub ↗
(cellName string, cellValue ldaputils.FormattedAttrValue)

Source from the content-addressed store, hash-verified

234}
235
236func GetAttrCellColor(cellName string, cellValue ldaputils.FormattedAttrValue) (string, bool) {
237 var color string = ""
238
239 switch cellName {
240 case "lastLogonTimestamp", "accountExpires", "badPasswordTime", "lastLogoff", "lastLogon", "pwdLastSet", "creationTime", "lockoutTime":
241 intValue, err := strconv.ParseInt(cellValue.OriginalValue, 10, 64)
242 if err == nil {
243 unixTime := (intValue - 116444736000000000) / 10000000
244 t := time.Unix(unixTime, 0).UTC()
245
246 daysDiff := int(time.Since(t).Hours() / 24)
247
248 if daysDiff <= 7 {
249 color = "green"
250 } else if daysDiff <= 90 {
251 color = "yellow"
252 } else {
253 color = "red"
254 }
255 }
256 case "objectGUID", "objectSid":
257 color = "gray"
258 case "whenCreated", "whenChanged":
259 layout := "20060102150405.0Z"
260 t, err := time.Parse(layout, cellValue.OriginalValue)
261 if err == nil {
262 daysDiff := int(time.Since(t).Hours() / 24)
263
264 if daysDiff <= 7 {
265 color = "green"
266 } else if daysDiff <= 90 {
267 color = "yellow"
268 } else {
269 color = "red"
270 }
271 }
272 case "lockoutDuration", "msDS-LockoutDuration", "lockOutObservationWindow", "msDS-LockoutObservationWindow":
273 duration, err := ldaputils.ParseMSDuration(cellValue.OriginalValue)
274 if err == nil {
275 if duration <= 5*60*time.Second {
276 color = "green"
277 } else if duration <= 30*60*time.Second {
278 color = "yellow"
279 } else {
280 color = "red"
281 }
282 }
283 case "maxPwdAge", "msDS-MaximumPasswordAge":
284 duration, err := ldaputils.ParseMSDuration(cellValue.OriginalValue)
285 if err == nil {
286 if duration <= 30*24*time.Hour {
287 color = "red"
288 } else if duration <= 90*24*time.Hour {
289 color = "yellow"
290 } else {
291 color = "green"
292 }
293 }

Callers 2

handleAttrsKeyEnterFunction · 0.85
reloadAttributesPanelFunction · 0.85

Calls 2

ParseMSDurationFunction · 0.92
ParseMethod · 0.65

Tested by

no test coverage detected