pkg
lenel_s2

lenel_s2

Explore the following sections to learn more:

lenel_s2

import "github.com/gemini-oss/rego/pkg/lenel_s2"

pkg/lenel_s2/entities.go

pkg/lenel_s2/lenel_s2.go

Index

Constants

const (
    NetBoxAPI = "%s/nbws/goforms/nbapi"
)

Variables

var (
    BaseURL = fmt.Sprintf("http://%s", "%s") // https://
)

Commands is an instance of NBAPICommands populated with string constants for each command.

var NetboxCommands = netboxAPI{
    Actions: netboxActions{
        ActivateOutput:        "Activate Output",
        DeactivateOutput:      "Deactivate Output",
        DogOnNextExitPortal:   "DogOnNextExitPortal",
        LockPortal:            "LockPortal",
        MomentaryUnlockPortal: "MomentaryUnlockPortal",
        SetThreatLevel:        "SetThreatLevel",
        UnlockPortal:          "UnlockPortal",
    },
    Configuration: netboxConfiguration{
        AddAccessLevel:         "AddAccessLevel",
        AddAccessLevelGroup:    "AddAccessLevelGroup",
        AddHoliday:             "AddHoliday",
        AddPartition:           "AddPartition",
        AddPortalGroup:         "AddPortalGroup",
        AddReaderGroup:         "AddReaderGroup",
        AddTimeSpec:            "AddTimeSpec",
        AddTimeSpecGroup:       "AddTimeSpecGroup",
        AddThreatLevel:         "AddThreatLevel",
        AddThreatLevelGroup:    "AddThreatLevelGroup",
        DeleteAccessLevel:      "DeleteAccessLevel",
        DeleteAccessLevelGroup: "DeleteAccessLevelGroup",
        DeleteHoliday:          "DeleteHoliday",
        DeletePortalGroup:      "DeletePortalGroup",
        DeleteReaderGroup:      "DeleteReaderGroup",
        DeleteTimeSpec:         "DeleteTimeSpec",
        GetAccessLevel:         "GetAccessLevel",
        GetAccessLevels:        "GetAccessLevels",
        GetAccessLevelGroup:    "GetAccessLevelGroup",
        GetAccessLevelGroups:   "GetAccessLevelGroups",
        GetAccessLevelNames:    "GetAccessLevelNames",
        GetCardFormats:         "GetCardFormats",
        GetElevators:           "GetElevators",
        GetFloors:              "GetFloors",
        GetHoliday:             "GetHoliday",
        GetHolidays:            "GetHolidays",
        GetOutputs:             "GetOutputs",
        GetPartitions:          "GetPartitions",
        GetPortalGroup:         "GetPortalGroup",
        GetPortalGroups:        "GetPortalGroups",
        GetReaderGroup:         "GetReaderGroup",
        GetReaderGroups:        "GetReaderGroups",
        GetReaders:             "GetReaders",
        GetTimeSpecGroup:       "GetTimeSpecGroup",
        GetTimeSpecGroups:      "GetTimeSpecGroups",
        GetTimeSpecs:           "GetTimeSpecs",
        GetUDFLists:            "GetUDFLists",
        GetUDFListItems:        "GetUDFListItems",
        ModifyAccessLevelGroup: "ModifyAccessLevelGroup",
        ModifyHoliday:          "ModifyHoliday",
        ModifyPortalGroup:      "ModifyPortalGroup",
        ModifyReaderGroup:      "ModifyReaderGroup",
        ModifyThreatLevel:      "ModifyThreatLevel",
        ModifyThreatLevelGroup: "ModifyThreatLevelGroup",
        ModifyTimeSpec:         "ModifyTimeSpec",
        ModifyTimeSpecGroup:    "ModifyTimeSpecGroup",
        ModifyUDFListItems:     "ModifyUDFListItems",
        RemoveThreatLevel:      "RemoveThreatLevel",
        RemoveThreatLevelGroup: "RemoveThreatLevelGroup",
        SetThreatLevel:         "SetThreatLevel",
    },
    Events: netboxEvents{
        ListEvents:   "ListEvents",
        StreamEvents: "StreamEvents",
        TriggerEvent: "TriggerEvent",
    },
    History: netboxHistory{
        GetEventHistory:      "GetEventHistory",
        GetCardAccessDetails: "GetCardAccessDetails",
    },
    People: netboxPeople{
        AddAccessLevelGroup: "AddAccessLevelGroup",
        AddCredential:       "AddCredential",
        AddPerson:           "AddPerson",
        GetAccessLevelNames: "GetAccessLevelNames",
        GetPerson:           "GetPerson",
        GetPicture:          "GetPicture",
        ModifyAccessLevel:   "ModifyAccessLevel",
        ModifyCredential:    "ModifyCredential",
        ModifyPerson:        "ModifyPerson",
        RemoveCredential:    "RemoveCredential",
        RemovePerson:        "RemovePerson",
        SearchPersonData:    "SearchPersonData",
    },
    Portals: netboxPortals{
        AddPortalGroup:    "AddPortalGroup",
        AddReaderGroup:    "AddReaderGroup",
        DeletePortalGroup: "DeletePortalGroup",
        DeleteReaderGroup: "DeleteReaderGroup",
        GetPortalGroup:    "GetPortalGroup",
        GetPortalGroups:   "GetPortalGroups",
        GetReader:         "GetReader",
        GetReaders:        "GetReaders",
        GetReaderGroup:    "GetReaderGroup",
        GetReaderGroups:   "GetReaderGroups",
        ModifyPortalGroup: "ModifyPortalGroup",
        ModifyReaderGroup: "ModifyReaderGroup",
    },
    ThreatLevels: netboxThreatLevels{
        AddThreatLevel:         "AddThreatLevel",
        AddThreatLevelGroup:    "AddThreatLevelGroup",
        ModifyThreatLevel:      "ModifyThreatLevel",
        ModifyThreatLevelGroup: "ModifyThreatLevelGroup",
        SetThreatLevel:         "SetThreatLevel",
    },
    Utility: netboxUtility{
        GetAPIVersion:   "GetAPIVersion",
        GetPartitions:   "GetPartitions",
        Login:           "Login",
        Logout:          "Logout",
        PingApp:         "PingApp",
        SwitchPartition: "SwitchPartition",
    },
}

type Access

type Access struct {
    LogID     string `xml:"LOGID"`     // Number which identifies the data log record
    PersonID  string `xml:"PERSONID"`  // External Person ID associated with the person who owns the specified credential. This is the field in the person record labeled "ID #.
    Reader    string `xml:"READER"`    // Name of the card reader
    DTTM      string `xml:"DTTM"`      // System date and time associated with the data log
    NodeDTTM  string `xml:"NODEDTM"`   // Node date and time associated with the data log
    Type      int    `xml:"TYPE"`      // Reason type which specifies a valid or invalid access. And invalid access also returns a Reason code
    Reason    int    `xml:"REASON"`    // Reason code which specifies the reason for an invalid access
    ReaderKey string `xml:"READERKEY"` // Unique identifier for the reader
    PortalKey string `xml:"PORTALKEY"` // Unique identifier for the portal
}

type AccessCard

type AccessCard struct {
    EncodedNum     string `xml:"ENCODEDNUM"`            // ENDCODEDNUM is a representation of the actual data on the credential. Credentials are interpreted using a set of rules defined by the card format type
    HotStamp       string `xml:"HOTSTAMP,omitempty"`    // HOTSTAMP is a value optionally stamped on the card or recorded for reference. Some deployments will choose to have these fields use the same value
    Format         string `xml:"CARDFORMAT"`            // Name of the format to be used to decode the credential.
    Disabled       bool   `xml:"DISABLED,omitempty"`    // DISABLED is a flag that indicates if the credential is disabled
    Status         string `xml:"CARDSTATUS,omitempty"`  // Text string that specifies the status of the credential. If a CARDSTATUS is not included in the command, the default status ACTIVE is assigned to the CARDSTATUS parameter
    ExpirationDate string `xml:"CARDEXPDATE,omitempty"` // Expiration date for the credential.
}

type AccessHistory

### Lenel S2 (Netbox) Access Structs ---------------------------------------------------------------------

type AccessHistory struct {
    Accesses  []*Access `xml:"ACCESSES>ACCESS"`
    NextLogID string    `xml:"NEXTLOGID,omitempty"` // This field is used for pagination.
}

func (*AccessHistory) Append

func (ah *AccessHistory) Append(resp PaginatedResponse) PaginatedResponse

Append merges another AccessHistory into the receiver by appending its Accesses.

func (*AccessHistory) NextToken

func (ah *AccessHistory) NextToken() string

NextToken returns the token used for getting the next page of AccessHistory results. It handles the special case where “-1” (or an empty value) indicates no further pages.

func (*AccessHistory) SetCommand

func (ah *AccessHistory) SetCommand(nb *Client, cmd NetboxCommand) NetboxCommand

type CardFormats

type CardFormats struct {
    Formats []string `xml:"CARDFORMATS>CARDFORMAT"`
}

type Client

### Lenel S2 Client Structs --------------------------------------------------------------------- Credentials for S2

type Client struct {
    BaseURL string
    Session *NetboxResponse[any]
    HTTP    *requests.Client
    Log     *log.Logger
    Cache   *cache.Cache
}

func NewClient

func NewClient(baseURL string, verbosity int) *Client

- # Generate S2 Client

  • @param logger *log.Logger
  • @return *Client
  • Example:

```go

s := s2.NewClient(log.DEBUG)

```

func (*Client) BuildRequest

func (c *Client) BuildRequest(name string, params interface{}) NetboxCommand

BuildRequest creates a consistent XML request struct.

func (*Client) BuildURL

func (c *Client) BuildURL(endpoint string, identifiers ...string) string

BuildURL builds a URL for a given resource and identifiers.

func (*Client) GetAccessHistory

func (c *Client) GetAccessHistory(logID int) (*AccessHistory, error)

func (*Client) GetCache

func (c *Client) GetCache(key string, target interface{}) bool

* GetCache retrieves an S2 API response from the cache

func (*Client) GetCardAccessDetails

func (c *Client) GetCardAccessDetails(ac *AccessCard) (*AccessHistory, error)

func (*Client) GetEventHistory

func (c *Client) GetEventHistory(logID int) (any, error)

func (*Client) GetPerson

func (c *Client) GetPerson(personID string) (*Person, error)

func (*Client) ListAllUDFs

func (c *Client) ListAllUDFs() (*[]*UDF, error)

func (*Client) ListAllUsers

func (c *Client) ListAllUsers() (*[]*Person, error)

func (*Client) Logout

func (c *Client) Logout() error

Logout ends the current session

func (*Client) SetCache

func (c *Client) SetCache(key string, value interface{}, duration time.Duration)

* SetCache stores an S2 API response in the cache

func (*Client) StreamEvents

func (c *Client) StreamEvents() (any, error)

func (*Client) UseCache

func (c *Client) UseCache() *Client

UseCache() enables caching for the next method call.

type Command

type Command struct {
    Name       string      `xml:"name,attr"`
    Num        string      `xml:"num,attr"`
    DateFormat string      `xml:"dateformat,attr,omitempty"`
    Params     interface{} `xml:"PARAMS,omitempty"`
}

type Credentials

type Credentials struct {
    Username string
    Password string
}

type Events

type Events struct {
    ActivityID string `xml:"ACTIVITYID"` // Activity ID of the event
    DESCNAME   string `xml:"DESCNAME"`   // Description of the event
    CDT        string `xml:"CDT"`        // CDT of the event
    PARTNAME   string `xml:"PARTNAME"`   // Partition name of the event
}

type NetboxCommand

type NetboxCommand struct {
    XMLName   xml.Name `xml:"NETBOX-API"`
    SessionID string   `xml:"sessionid,attr,omitempty"`
    Command   Command  `xml:"COMMAND"`
}

type NetboxResponse

Session holds the session ID from login responses

type NetboxResponse[E any] struct {
    XMLName  xml.Name    `xml:"NETBOX"`
    ID       string      `xml:"sessionid,attr"`
    Response Response[E] `xml:"RESPONSE"`
}

func Login

func Login(baseURL string) (*NetboxResponse[any], error)

* # Create a new S2 SessionID based on the credentials provided

  • <COMMAND name=“Login” num=“1” dateformat=“tzoffset”>

type PaginatedResponse

PaginatedResponse defines methods needed for handling pagination.

type PaginatedResponse interface {
    // NextToken returns the token to be used for the next request.
    NextToken() string
    // Append merges a new page of results with the existing result set.
    Append(resp PaginatedResponse) PaginatedResponse

    SetCommand(nb *Client, cmd NetboxCommand) NetboxCommand
}

type PartName

type PartName struct {
    Filters []string `xml:"FILTERS>FILTER"`
}

type People

type People struct {
    People []*Person `xml:"PEOPLE>PERSON"`
}

type Person

type Person struct {
    PersonID         string       `xml:"PERSONID"`                 // ID number of the person whose record information is to be returned
    FirstName        string       `xml:"FIRSTNAME"`                // The person's first name
    MiddleName       string       `xml:"MIDDLENAME"`               // Middle name
    LastName         string       `xml:"LASTNAME"`                 // The person's last name
    Username         string       `xml:"USERNAME"`                 // Username associated with a person’s NetBox login account
    Role             string       `xml:"ROLE"`                     // Role for a person’s record when they login to the NetBox
    AuthType         string       `xml:"AUTHTYPE"`                 // (Required) Authorization type for a person’s record. Valid values are `DB`, `LDAP`, or `SSO`
    Partition        string       `xml:"PARTITION"`                // Partition of person record
    ActivationDate   string       `xml:"ACTDATE"`                  // Activation date of the person record
    ExpirationDate   string       `xml:"EXPDATE"`                  // Expiration date for the person record
    UDF1             string       `xml:"UDF1"`                     // UDF1 through UDF20: User defined fields (20)
    UDF2             string       `xml:"UDF2"`                     // User Defined Field 2
    UDF3             string       `xml:"UDF3"`                     // User Defined Field 3
    UDF4             string       `xml:"UDF4"`                     // User Defined Field 4
    UDF5             string       `xml:"UDF5"`                     // User Defined Field 5
    UDF6             string       `xml:"UDF6"`                     // User Defined Field 6
    UDF7             string       `xml:"UDF7"`                     // User Defined Field 7
    UDF8             string       `xml:"UDF8"`                     // User Defined Field 8
    UDF9             string       `xml:"UDF9"`                     // User Defined Field 9
    UDF10            string       `xml:"UDF10"`                    // User Defined Field 10
    UDF11            string       `xml:"UDF11"`                    // User Defined Field 11
    UDF12            string       `xml:"UDF12"`                    // User Defined Field 12
    UDF13            string       `xml:"UDF13"`                    // User Defined Field 13
    UDF14            string       `xml:"UDF14"`                    // User Defined Field 14
    UDF15            string       `xml:"UDF15"`                    // User Defined Field 15
    UDF16            string       `xml:"UDF16"`                    // User Defined Field 16
    UDF17            string       `xml:"UDF17"`                    // User Defined Field 17
    UDF18            string       `xml:"UDF18"`                    // User Defined Field 18
    UDF19            string       `xml:"UDF19"`                    // User Defined Field 19
    UDF20            string       `xml:"UDF20"`                    // User Defined Field 20
    Pin              string       `xml:"PIN"`                      // PIN number that may be required for a card reader with a numeric pad
    Notes            string       `xml:"NOTES"`                    // Notes field of the person record
    Deleted          bool         `xml:"DELETED"`                  // Specifies if the person record has been deleted
    PictureURL       string       `xml:"PICTUREURL"`               // The picture data file returned as text between the PICTUREURL elements. The data file is stored in the following directory on the system: /usr/local/s2/web/upload/pics
    BadgeLayout      string       `xml:"BADGELAYOUT"`              // Name of the photo ID badging layout file.
    LastModified     string       `xml:"LASTMOD"`                  // (Deprecated) Last time the person was modified in YYYY-MM-DD format.
    LastEdit         string       `xml:"LASTEDIT"`                 // Date and time the contents of the person record were last changed, in YYYY-MM-DD HH:MM:SS format.
    LastEditPersonID string       `xml:"LASTEDITPERSONID"`         // ID of the person who last edited the person record.
    Phone            string       `xml:"CONTACTPHONE"`             // Office phone number
    Mobile           string       `xml:"MOBILEPHONE"`              // Mobile phone number
    Email            string       `xml:"CONTACTEMAIL"`             // Office email address
    SMSEmail         string       `xml:"CONTACTSMSEMAIL"`          // Office SMS email address
    Location         string       `xml:"CONTACTLOCATION"`          // Emergency contact location
    OtherName        string       `xml:"OTHERCONTACTNAME"`         // Emergency contact name
    OtherPhone       string       `xml:"OTHERCONTACTPHONE"`        // Emergency contact phone number
    Vehicles         []Vehicle    `xml:"VEHICLES>VEHICLE"`         // Element blocks containing a VEHICLE element block for each vehicle defined in the person record
    AccessLevels     []string     `xml:"ACCESSLEVELS>ACCESSLEVEL"` // Element block containing one or more access levels (maximum of 32) to be associated with the person. Only the access levels currently assigned are returned, and if there are none assigned, none are returned
    AccessCards      []AccessCard `xml:"ACCESSCARDS>ACCESSCARD"`   // Element block containing one or more credentials to be associated with the person. Only the credentials currently assigned are returned, and if there are none assigned, none are returned
}

type Response

type Response[E any] struct {
    APIError int    `xml:"APIERROR"`         // APIError holds API-level error codes if present (e.g. "1", "2", etc.)
    Code     string `xml:"CODE"`             // // CODE is the command response code ("SUCCESS" or "FAIL")
    Details  *E     `xml:"DETAILS"`          // Can be an object of any type
    Error    string `xml:"ERRMSG,omitempty"` // Error stores a human-readable error message from command-level failures.
}

func (*Response[E]) UnmarshalXML

func (r *Response[E]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML provides a custom unmarshaller that reads the elements within <RESPONSE> only once. It will process:

  • <APIERROR>: Decodes API-level errors (e.g., authentication failure).
  • <CODE>: Decodes the command-level code.
  • <DETAILS>: Depending on the previously decoded CODE, either:
  • For “FAIL”, decode only <ERRMSG> inside DETAILS.
  • Otherwise, decode the full DETAILS into the generic type.

type TagNames

type TagNames struct {
    ACName       string   `xml:"ACNAME,omitempty"`
    ActivityID   string   `xml:"ACTIVITYID,omitempty"`
    CDT          string   `xml:"CDT,omitempty"`
    DescName     string   `xml:"DESCNAME,omitempty"`
    LoginAddress string   `xml:"LOGINADDRESS,omitempty"`
    PersonName   string   `xml:"PERSONNAME,omitempty"`
    Detail       string   `xml:"DETAIL,omitempty"`
    PartName     PartName `xml:"PARTNAME,omitempty"`
}

type UDF

type UDF struct {
    Key         string `xml:"UDFLISTKEY"`  // The unique key for the UDF value list
    Name        string `xml:"NAME"`        // The name of the UDF value list
    Description string `xml:"DESCRIPTION"` // A description of the UDF value list, if available
}

type UDFLists

type UDFLists struct {
    UserDefinedFields []*UDF `xml:"UDFLISTS>UDFLIST"` // Element block containing one or more user defined fields (maximum of 20) to be associated with the person. Only the user defined fields currently assigned are returned, and if there are none assigned, none are returned
}

type Vehicle

type Vehicle struct {
    Color   string `xml:"VEHICLECOLOR"`  // The vehicle color
    Make    string `xml:"VEHICLEMAKE"`   // The vehicle make
    Model   string `xml:"VEHICLEMODEL"`  // The vehicle model
    State   string `xml:"VEHICLESTATE"`  // The vehicle state
    License string `xml:"VEHICLELICNUM"` // The vehicle license number
    Tag     string `xml:"VEHICLETAGNUM"` // The vehicle tag number
}

Generated by gomarkdoc