guacamole

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 9 Imported by: 0

README

Guacamole Golang Frontend API

Forked from mdanidl/guac-api

This package is built for (Apache Guacamole)[http://guacamole.apache.org].

I created it to access the built-in client application's frontend API in order to programatically add Users, Connections and Permissions for those connections. It's done by reverse engineering the AJAX calls from the webUI.

The Goal is to use this library in a terraform provider that creates these resources when needed.

In it's current state the style of the code is very raw, and a Work In Progress Also a caveat that i am by no means a software developer, and i'm doing this partly to get familiar with Golang.

PRs are most welcome.

Example

package main

import (
	guacamole "github.com/sszgr/guacamole-api"
	"os"
)

func main() {
	g := &guacamole.Guacamole{
		BaseUrl:    "https://127.0.0.1:10001/guacamole",
		Username:   os.Getenv("GUACAMOLE_USERNAME"),
		Password:   os.Getenv("GUACAMOLE_PASSWORD"),
		SkipVerify: true,
	}

	err := g.Connect()
	// ...
}

Documentation

Index

Constants

View Source
const (
	ErrBodyIsNil = "body is nil"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectResponse

type ConnectResponse struct {
	AuthToken            string   `json:"authToken"`
	Username             string   `json:"username"`
	DataSource           string   `json:"dataSource"`
	AvailableDataSources []string `json:"availableDataSource"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	// TranslatableMessage []map[string]string `json:"translatableMessage"`
	StatusCode string `json:"statusCode"`
	Expected   string `json:"expected"`
	Type       string `json:"type"`
}

type GuacConnection

type GuacConnection struct {
	Name              string                   `json:"name"`
	Identifier        string                   `json:"identifier,omitempty"`
	ParentIdentifier  string                   `json:"parentIdentifier"`
	Protocol          string                   `json:"protocol"`
	Attributes        GuacConnectionAttributes `json:"attributes"`
	Properties        GuacConnectionParameters `json:"parameters"`
	ActiveConnections int                      `json:"activeConnections,omitempty"`
	LastActive        int                      `json:"lastActive,omitempty"`
}

type GuacConnectionAttributes

type GuacConnectionAttributes struct {
	GuacdEncryption       string `json:"guacd-encryption"`
	FailoverOnly          string `json:"failover-only"`
	Weight                string `json:"weight"`
	MaxConnections        string `json:"max-connections"`
	GuacdHostname         string `json:"guacd-hostname,omitempty"`
	GuacdPort             string `json:"guacd-port"`
	MaxConnectionsPerUser string `json:"max-connections-per-user"`
}

type GuacConnectionGroup

type GuacConnectionGroup struct {
	Name              string                        `json:"name"`
	Identifier        string                        `json:"identifier"`
	ParentIdentifier  string                        `json:"parentIdentifier"`
	Type              string                        `json:"type"`
	ActiveConnections int                           `json:"activeConnections"`
	ChildConnections  []GuacConnection              `json:"childConnections"`
	ChildGroups       []GuacConnectionGroup         `json:"childConnectionGroups"`
	Attributes        GuacConnectionGroupAttributes `json:"attributes"`
}

type GuacConnectionGroupAttributes

type GuacConnectionGroupAttributes struct {
	MaxConnections        string `json:"max-connections"`
	MaxConnectionsPerUser string `json:"max-connections-per-user"`
	EnableSessionAffinity string `json:"enable-session-affinity"`
}

type GuacConnectionParameters

type GuacConnectionParameters struct {
	// rdp & kubernetes & ssh & telnet & vnc
	Port                   string `json:"port"`
	RecordingName          string `json:"recording-name"`
	RecordingExcludeMouse  string `json:"recording-exclude-mouse"`
	Hostname               string `json:"hostname"`
	ReadOnly               string `json:"read-only"`
	RecordingIncludeKeys   string `json:"recording-include-keys"`
	RecordingExcludeOutput string `json:"recording-exclude-output"`
	RecordingPath          string `json:"recording-path"`
	CreateRecordingPath    string `json:"create-recording-path"`

	// kubernetes
	TypescriptName       string `json:"typescript-name"`
	ScrollBack           string `json:"scrollback"`
	Pod                  string `json:"pod"`
	ExecCommand          string `json:"exec-command"`
	Backspace            string `json:"backspace"`
	UseSSL               string `json:"use-ssl"`
	CaCert               string `json:"ca-cert"`
	TypescriptPath       string `json:"typescript-path"`
	FontName             string `json:"font-name"`
	Namespace            string `json:"namespace"`
	CreateTypescriptPath string `json:"create-typescript-path"`
	FontSize             string `json:"font-size"`
	ClientCert           string `json:"client-cert"`
	ColorScheme          string `json:"color-scheme"`
	ClientKey            string `json:"client-key"`
	Container            string `json:"container"`
	IgnoreCert           string `json:"ignore-cert"`

	// rdp
	SftpRootDirectory        string `json:"sftp-root-directory"`
	SftpPassphrase           string `json:"sftp-passphrase"`
	ForceLossless            string `json:"force-lossless"`
	Width                    string `json:"width"`
	SftpPassword             string `json:"sftp-password"`
	Height                   string `json:"height"`
	DisableGlyphCaching      string `json:"disable-glyph-caching"`
	SftpUsername             string `json:"sftp-username"`
	WOLMACAddr               string `json:"wol-mac-addr"`
	SftpDisableUpload        string `json:"sftp-disable-upload"`
	RemoteApp                string `json:"remote-app"`
	DisableBitmapCaching     string `json:"disable-bitmap-caching"`
	DisableDownload          string `json:"disable-download"`
	EnableFontSmoothing      string `json:"enable-font-smoothing"`
	EnableWallpaper          string `json:"enable-wallpaper"`
	DPI                      string `json:"dpi"`
	SftpDirectory            string `json:"sftp-directory"`
	SftpPrivateKey           string `json:"sftp-private-key"`
	ServerLayout             string `json:"server-layout"`
	SftpPort                 string `json:"sftp-port"`
	EnableDrive              string `json:"enable-drive"`
	GatewayPassword          string `json:"gateway-password"`
	CertTOFU                 string `json:"cert-tofu"`
	WolUdpPort               string `json:"wol-udp-port"`
	PrinterName              string `json:"printer-name"`
	DrivePath                string `json:"drive-path"`
	GatewayHostname          string `json:"gateway-hostname"`
	GatewayPort              string `json:"gateway-port"`
	Timezone                 string `json:"timezone"`
	DisableUpload            string `json:"disable-upload"`
	ClientName               string `json:"client-name"`
	Password                 string `json:"password"`
	EnableSFTP               string `json:"enable-sftp"`
	StaticChannels           string `json:"static-channels"`
	SftpServerAliveInterval  string `json:"sftp-server-alive-interval"`
	ResizeMethod             string `json:"resize-method"`
	NormalizeClipboard       string `json:"normalize-clipboard"`
	LoadBalanceInfo          string `json:"load-balance-info"`
	SftpHostKey              string `json:"sftp-host-key"`
	EnableTheming            string `json:"enable-theming"`
	Console                  string `json:"console"`
	DisableCopy              string `json:"disable-copy"`
	DisableAuth              string `json:"disable-auth"`
	DisablePaste             string `json:"disable-paste"`
	EnableFullWindowDrag     string `json:"enable-full-window-drag"`
	DisableGFX               string `json:"disable-gfx"`
	ConsoleAudio             string `json:"console-audio"`
	GatewayUsername          string `json:"gateway-username"`
	CertFingerprints         string `json:"cert-fingerprints"`
	EnableAudioInput         string `json:"enable-audio-input"`
	WOLSendPacket            string `json:"wol-send-packet"`
	DisableOffscreenCaching  string `json:"disable-offscreen-caching"`
	EnablePrinting           string `json:"enable-printing"`
	PreConnectionBlob        string `json:"preconnection-blob"`
	DriveName                string `json:"drive-name"`
	Domain                   string `json:"domain"`
	WOLBroadcastAddr         string `json:"wol-broadcast-addr"`
	PreConnectionID          string `json:"preconnection-id"`
	ColorDepth               string `json:"color-depth"`
	EnableTouch              string `json:"enable-touch"`
	SftpDisableDownload      string `json:"sftp-disable-download"`
	Security                 string `json:"security"`
	InitialProgram           string `json:"initial-program"`
	RemoteAppDir             string `json:"remote-app-dir"`
	Username                 string `json:"username"`
	CreateDrivePath          string `json:"create-drive-path"`
	RemoteAppArgs            string `json:"remote-app-args"`
	GatewayDomain            string `json:"gateway-domain"`
	DisableAudio             string `json:"disable-audio"`
	RecordingExcludeTouch    string `json:"recording-exclude-touch"`
	EnableMenuAnimations     string `json:"enable-menu-animations"`
	SftpHostname             string `json:"sftp-hostname"`
	WOLWaitTime              string `json:"wol-wait-time"`
	EnableDesktopComposition string `json:"enable-desktop-composition"`

	// ssh
	PrivateKey          string `json:"private-key"`
	ServerAliveInterval string `json:"server-alive-interval"`
	Command             string `json:"command"`
	Locale              string `json:"locale"`
	TerminalType        string `json:"terminal-type"`

	// telnet
	LoginSuccessRegex string `json:"login-success-regex"`
	UsernameRegex     string `json:"username-regex"`
	LoginFailureRegex string `json:"login-failure-regex"`
	PasswordRegex     string `json:"password-regex"`

	// vnc
	Cursor          string `json:"cursor"`
	Encodings       string `json:"encodings"`
	AudioServername string `json:"audio-servername"`
	DestPort        string `json:"dest-port"`
	SwapRedBlue     string `json:"swap-red-blue"`
	DestHost        string `json:"dest-host"`
}

GuacConnectionParameters See also https://github.com/apache/guacamole-client/tree/master/guacamole-ext/src/main/resources/org/apache/guacamole/protocols

type GuacPermissionData

type GuacPermissionData struct {
	ConnectionPermissions       map[string][]string `json:"connectionPermissions"`
	ConnectionGroupPermissions  map[string][]string `json:"connectionGroupPermissions"`
	SharingProfilePermissions   map[string][]string `json:"sharingProfilePermissions"`
	UserPermissions             map[string][]string `json:"userPermissions"`
	UserGroupPermissions        map[string][]string `json:"userGroupPermissions"`
	SystemPermissions           []string            `json:"systemPermissions"`
	ActiveConnectionPermissions map[string][]string `json:"activeConnectionPermissions"`
}

GuacPermissionData a

type GuacPermissionItem

type GuacPermissionItem struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value string `json:"value"`
}

GuacPermissionItem a

type GuacUser

type GuacUser struct {
	Username   string             `json:"username"`
	Password   string             `json:"password"`
	Attributes GuacUserAttributes `json:"attributes"`
	LastActive int                `json:"lastActive"`
}

type GuacUserAttributes

type GuacUserAttributes struct {
	GuacEmailAddress       string `json:"guac-email-address"`
	GuacOrganization       string `json:"guac-organization"`
	GuacOrganizationalRole string `json:"guac-organizational-role"`
	GuacFullName           string `json:"guac-full-name"`
	Expired                string `json:"expired"`
	Timezone               string `json:"timezone"`
	AccessWindowStart      string `json:"access-window-start"`
	AccessWindowEnd        string `json:"access-window-end"`
	Disabled               string `json:"disabled"`
	ValidFrom              string `json:"valid-from"`
	ValidUntil             string `json:"valid-until"`
}

type GuacUserGroup

type GuacUserGroup struct {
	Identifier string                  `json:"identifier"`
	Attributes GuacUserGroupAttributes `json:"attributes"`
}

type GuacUserGroupAttributes

type GuacUserGroupAttributes struct {
	Disabled string `json:"disabled"`
}

type Guacamole

type Guacamole struct {
	BaseUrl  string
	Username string
	Password string

	SkipVerify bool
	// contains filtered or unexported fields
}

func (*Guacamole) Call

func (g *Guacamole) Call(method, uri string, xq map[string]string, body interface{}) ([]byte, error)

func (*Guacamole) Connect

func (g *Guacamole) Connect() error

func (*Guacamole) CreateConnection

func (g *Guacamole) CreateConnection(conn *GuacConnection) (GuacConnection, error)

func (*Guacamole) CreateConnectionGroup

func (g *Guacamole) CreateConnectionGroup(conn *GuacConnectionGroup) (GuacConnectionGroup, error)

func (*Guacamole) CreateUser

func (g *Guacamole) CreateUser(user *GuacUser) (GuacUser, error)

func (*Guacamole) CreateUserGroup

func (g *Guacamole) CreateUserGroup(group *GuacUserGroup) (GuacUserGroup, error)

func (*Guacamole) DeleteConnection

func (g *Guacamole) DeleteConnection(conn *GuacConnection) error

func (*Guacamole) DeleteConnectionGroup

func (g *Guacamole) DeleteConnectionGroup(conn *GuacConnectionGroup) error

func (*Guacamole) DeleteUser

func (g *Guacamole) DeleteUser(user *GuacUser) error

func (*Guacamole) DeleteUserGroup

func (g *Guacamole) DeleteUserGroup(group *GuacUserGroup) error

func (*Guacamole) GetConnectionTree

func (g *Guacamole) GetConnectionTree() (GuacConnectionGroup, error)

func (*Guacamole) GetUserConnectionPermissions

func (g *Guacamole) GetUserConnectionPermissions(user string) (GuacPermissionData, error)

func (*Guacamole) ListConnectionGroups

func (g *Guacamole) ListConnectionGroups() ([]GuacConnectionGroup, error)

func (*Guacamole) ListConnections

func (g *Guacamole) ListConnections() ([]GuacConnection, error)

func (*Guacamole) ListUserGroups

func (g *Guacamole) ListUserGroups() ([]GuacUserGroup, error)

func (*Guacamole) ListUsers

func (g *Guacamole) ListUsers() ([]GuacUser, error)

func (*Guacamole) ReadConnection

func (g *Guacamole) ReadConnection(conn *GuacConnection) (GuacConnection, error)

func (*Guacamole) ReadConnectionGroup

func (g *Guacamole) ReadConnectionGroup(conn *GuacConnectionGroup) (GuacConnectionGroup, error)

func (*Guacamole) ReadUser

func (g *Guacamole) ReadUser(user *GuacUser) (GuacUser, error)

func (*Guacamole) ReadUserGroup

func (g *Guacamole) ReadUserGroup(group *GuacUserGroup) (GuacUserGroup, error)

func (*Guacamole) RefreshToken

func (g *Guacamole) RefreshToken() error

func (*Guacamole) SendUserConnectionPermissionChanges

func (g *Guacamole) SendUserConnectionPermissionChanges(user string, p []GuacPermissionItem) error

func (*Guacamole) UpdateConnection

func (g *Guacamole) UpdateConnection(conn *GuacConnection) error

func (*Guacamole) UpdateConnectionGroup

func (g *Guacamole) UpdateConnectionGroup(conn *GuacConnectionGroup) error

func (*Guacamole) UpdateUser

func (g *Guacamole) UpdateUser(user *GuacUser) error

func (*Guacamole) UpdateUserGroup

func (g *Guacamole) UpdateUserGroup(group *GuacUserGroup) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL