kpmenulib

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PromptDmenu  = "dmenu"
	PromptRofi   = "rofi"
	PromptWofi   = "wofi"
	PromptCustom = "custom"
)

Menu tools used for prompts

View Source
const (
	ClipboardToolXsel        = "xsel"
	ClipboardToolWlclipboard = "wl-clipboard"
	ClipboardToolCustom      = "custom"
)

Clipboard tools used for clipboard manager

View Source
const (
	OTP          = "otp"
	TOTPSEED     = "TOTP Seed"
	TOTPSETTINGS = "TOTP Settings"
	TOTP         = "totp"
	OTPAUTH      = "otpauth"
)

OTP constants

View Source
const (
	MenuShow   = MenuSelection(iota) // Show entries
	MenuReload                       // Reload database
	MenuExit                         // Exit
)

MenuSelections enum values

View Source
const Version = "1.4.0"

Version is the version of kpmenu

Variables

This section is empty.

Functions

func CleanClipboard

func CleanClipboard(menu *Menu, text string)

CleanClipboard cleans the clipboard, if not changed

func CopyToClipboard

func CopyToClipboard(menu *Menu, text string) error

CopyToClipboard copies text into the clipboar

func CreateOTP added in v1.4.0

func CreateOTP(a gokeepasslib.Entry, time int64) (otp string, err error)

CreateOTP generates a time-sensitive TOTP code for a database entry.

Modern versions of KeepassXC and Keepass2Android store this URL in the `otp` key. A historic version stored data ds:

TOTP Seed = SECRET
TOTP Settings = PERIOD;DIGITS

If the `otp` key exists, it should be used and the TOTP values ignored; otherwise, the legacy values can be used.

entry is the DB entry for which to generate a code; time is the Unix time to generate for the code -- generally time.Now().Unix()

func Execute

func Execute(menu *Menu) bool

Execute is the function used to open the database (if necessary) and open the menu returns true if the program should exit

func GetClipboard

func GetClipboard(menu *Menu) (string, error)

GetClipboard gets the current clipboard

func PromptEntries

func PromptEntries(menu *Menu) (*Entry, ErrorPrompt)

PromptEntries executes dmenu to ask for an entry selection Returns the selected entry

func PromptMenu

func PromptMenu(menu *Menu) (MenuSelection, ErrorPrompt)

PromptMenu executes dmenu to ask for menu selection Returns the MenuSelection chosen

func Show

func Show(menu *Menu) bool

Show checks if the database configuration is changed, if so it will re-open the database returns true if the program should exit

func StartClient

func StartClient() error

StartClient sends a packet to the server listener

func StartServer

func StartServer(m *Menu) (err error)

StartServer starts to listen for client packets

Types

type Configuration

type Configuration struct {
	General    ConfigurationGeneral
	Executable ConfigurationExecutable
	Style      ConfigurationStyle
	Database   ConfigurationDatabase
	Flags      Flags
}

Configuration is the main structure of kpmenu config

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration initializes a new Configuration pointer

func (*Configuration) InitializeFlags

func (c *Configuration) InitializeFlags()

InitializeFlags prepare cli flags

func (*Configuration) LoadConfig

func (c *Configuration) LoadConfig() error

LoadConfig loads the configuration into Configuration

func (*Configuration) ParseFlags

func (c *Configuration) ParseFlags(args []string)

ParseFlags parses cli flags with given arguments

type ConfigurationDatabase

type ConfigurationDatabase struct {
	Database        string
	KeyFile         string
	Password        string
	FieldOrder      string
	FillOtherFields bool
	FillBlacklist   string
}

ConfigurationDatabase is the sub-structure of the configuration related to database settings

type ConfigurationExecutable added in v1.3.0

type ConfigurationExecutable struct {
	CustomPromptPassword string // Custom executable for prompt password
	CustomPromptMenu     string // Custom executable for prompt menu
	CustomPromptEntries  string // Custom executable for prompt entries
	CustomPromptFields   string // Custom executable for prompt fields
	CustomClipboardCopy  string // Custom executable for clipboard copy
	CustomClipboardPaste string // Custom executable for clipboard paste
	CustomClipboardClean string // Custom executable for clipboard clean
}

ConfigurationExecutable is the sub-structure of the configuration related to tools executed by kpmenu

type ConfigurationGeneral

type ConfigurationGeneral struct {
	Menu             string // Which menu to use
	ClipboardTool    string // Clipboard tool to use
	ClipboardTimeout int    // Clipboard timeout before clean it
	NoCache          bool   // Flag to do not cache master password
	CacheOneTime     bool   // Cache the password only the first time you write it
	CacheTimeout     int    // Timeout of cache
	NoOTP            bool   // Flag to do not handle OTPs
}

ConfigurationGeneral is the sub-structure of the configuration related to general kpmenu settings

type ConfigurationStyle

type ConfigurationStyle struct {
	PasswordBackground string
	TextPassword       string
	TextMenu           string
	TextEntry          string
	TextField          string
	FormatEntry        string
	ArgsPassword       string
	ArgsMenu           string
	ArgsEntry          string
	ArgsField          string
}

ConfigurationStyle is the sub-structure of the configuration related to style of dmenu

type Database

type Database struct {
	Loaded  bool
	Keepass *gokeepasslib.Database
	Entries []Entry
}

Database contains the KeePass database and its entry list

func NewDatabase

func NewDatabase() *Database

NewDatabase initializes the Database struct

func (*Database) AddCredentialsToDatabase

func (db *Database) AddCredentialsToDatabase(cfg *Configuration, password string)

AddCredentialsToDatabase adds credentials into gokeepasslib credentials struct

func (*Database) IterateDatabase

func (db *Database) IterateDatabase()

IterateDatabase iterates the database and makes a list of entries

func (*Database) OpenDatabase

func (db *Database) OpenDatabase(cfg *Configuration) error

OpenDatabase decodes the database with the given configuration

type Entry

type Entry struct {
	UUID      gokeepasslib.UUID
	FullEntry gokeepasslib.Entry
}

Entry is a container for keepass entry

type ErrParseConfiguration

type ErrParseConfiguration struct {
	Message       string
	OriginalError error
}

ErrParseConfiguration is the error return if the configuration loading fails

func NewErrorParseConfiguration

func NewErrorParseConfiguration(message string, err error) ErrParseConfiguration

NewErrorParseConfiguration initializes the error

func (ErrParseConfiguration) Error

func (err ErrParseConfiguration) Error() string

type ErrorDatabase

type ErrorDatabase struct {
	Message       string
	OriginalError error
	Fatal         bool
}

ErrorDatabase is an error that can be fatal or non-fatal

func NewErrorDatabase

func NewErrorDatabase(message string, err error, fatal bool) *ErrorDatabase

NewErrorDatabase makes an ErrorDatabase

func (*ErrorDatabase) String

func (err *ErrorDatabase) String() string

type ErrorPrompt

type ErrorPrompt struct {
	Cancelled bool
	Error     error
}

ErrorPrompt is a structure that handle an error of dmenu/rofi

func PromptFields

func PromptFields(menu *Menu, entry *Entry) (string, ErrorPrompt)

PromptFields executes dmenu to ask for a field selection Returns the selected field value as string

func PromptPassword

func PromptPassword(menu *Menu) (string, ErrorPrompt)

PromptPassword executes dmenu to ask for database password Returns the written password

type Flags

type Flags struct {
	Daemon  bool
	Version bool
}

Flags is the sub-structure of the configuration used to handle flags that aren't into the config file

type Menu struct {
	CacheStart    time.Time       // Cache start time
	CliArguments  []string        // Arguments of kpmenu
	Configuration *Configuration  // Configuration of kpmenu
	Database      *Database       // Database
	WaitGroup     *sync.WaitGroup // WaitGroup used for goroutines
}

Menu is the main structure of kpmenu

func Initialize

func Initialize() *Menu

Initialize is the function that initialize a menu, handle config and parse cli arguments

func NewMenu

func NewMenu() *Menu

NewMenu initializes a Menu struct

func (m *Menu) OpenDatabase() *ErrorDatabase

OpenDatabase asks for password and populates the database

func (m *Menu) OpenMenu() *ErrorDatabase

OpenMenu executes dmenu to interface the user with the database

type MenuSelection int

MenuSelection is an enum used for prompt menu selection

func (el MenuSelection) String() string

type OTPAuth added in v1.4.0

type OTPAuth struct {
	Type    string
	Account string
	Issuer  string
	Period  int
	Digits  int
	// contains filtered or unexported fields
}

OTPAuth supports only TOTP (at the moment)

func CreateOTPAuth added in v1.4.0

func CreateOTPAuth(a gokeepasslib.Entry) (otp OTPAuth, err error)

func (OTPAuth) Create added in v1.4.0

func (o OTPAuth) Create(time int64) (otp string, err error)

type OTPError added in v1.4.0

type OTPError struct {
	// contains filtered or unexported fields
}

OTPError is a structure that handle an error of otp

func (OTPError) Error added in v1.4.0

func (o OTPError) Error() string

type Packet

type Packet struct {
	CliArguments []string
}

Packet is the data sent by the client to the server listener

Jump to

Keyboard shortcuts

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