command

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2018 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DaemonCommand = BaseCommand{
	Arguments: "[--conf=ondevice.conf] [--pidfile=ondevice.pid] [--sock=unix://ondevice.sock]",
	ShortHelp: "Run the ondevice device daemon",
	RunFn:     daemonRun,
	LongHelp: `$ ondevice daemon [--conf=...] [--pidfile=...] [--sock=...]

Starts the ondevice daemon (the device side of the tunnels).

On debian based systems instead of running 'ondevice daemon' directly, you
should install the ondevice-daemon package instead (which will also take care
of setting up the credentials)

Make sure you run 'ondevice login' and authenticate with your device key first.

Usually you'll only want to have one 'ondevice daemon' instance per device.
If you want to run multiple, you'll have to specify the .conf, .pid and .sock
files manually.
Concurrent daemon instances can't use the same ondevice.conf file!!!

Options:
--conf=/path/to/ondevice.conf
  Path to the ondevice.conf file
  Default: ~/.config/ondevice/ondevice.conf

--pidfile=/path/to/ondevice.pid
  Path to the ondevice.pid file
  Default: ~/.config/ondevice/ondevice.pid

--sock=unix:///path/to/ondevice.sock
  Path to the ondevice.sock file
  Default: unix://~/.config/ondevice/ondevice.sock


Example Socket URLs:
- unix:///home/user/.config/ondevice/ondevice.sock
  User's ondevice.sock path - clients will use this URL first when connecting
- unix:///var/run/ondevice/ondevice.sock
  Default system-wide ondevice.sock path - if the above failed, clients will try
  this one instead.
- /var/run/ondevice/ondevice.sock
  Same as the above (since unix:// is the default URL scheme here)
- http://localhost:1234/
	Listen on TCP port 1234.
  Note that there's currently support for neither SSL nor authentication so use
  this only if absolutely necessary

On the client side, set the ONDEVICE_HOST environment variable to match the
socket parameter.
`,
}

DaemonCommand -- implements `ondevice daemon`

View Source
var DeviceCommand = BaseCommand{
	Arguments: "<devId> <props/set/rm> [key1=val1 ...]",
	ShortHelp: "List/manipulate device properties",
	RunFn:     deviceRun,
	LongHelp: `$ ondevice device <devId> props
$ ondevice device <devId> set [key1=val1 ...]
$ ondevice device <devId> rm [--yes/-y] [--delete] [key1 key2 ...]

This command allows you to change all your devices' properties.
It requires a client key with the 'manage' authorization.

Properties can be used to keep track of your devices, to manage their characteristics,
keep tracks of running maintenance scripts, etc.

- ondevice device $devId props
  lists that device's properties, one per line, as 'key=value' pairs
- ondevice device $devId set [key=val...]
  sets one or more device properties, again as 'key=value' pairs
- ondevice device $devId rm [key ...]
  removes one or more device properties by name

Some special cases are:
- ondevice device $devId set on:id=newId
  Rename (= change devId of) a device
- ondevice device $devId rm on:id
  Removing the special property 'on:id' will attempt to delete the device
  (will ask for confirmation unless you also specify --yes)
  Only devices that have been offline for at least an hour can be deleted.

Options:
--yes -y
  Don't ask before deleting a device

Each invocation will print the resulting property list.

Examples:
  $ ondevice device q5dkpm props
  $ ondevice device q5dkpm set test=1234 foo=bar
  test=1234
  foo=bar
  $ ondevice device q5dkpm rm foo
  test=1234

  # rename and then delete the device
  $ ondevice device q5dkpm set on:id=rpi
  $ ondevice device rpi rm on:id
  Do you really want to delete the device 'uyqsn4' (y/N):
`,
}

DeviceCommand -- implemnts `ondevice device`

View Source
var EventCommand = eventCommand{
	BaseCommand: BaseCommand{
		Arguments: "[--json] [--since=eventId] [--until=eventId] [--count=50] [--type=...] [--device=...] [--timeout=30] [--await=eventType]",
		ShortHelp: "Prints past (and listens for live) account events",
		RunFn:     nil,
		LongHelp: `$ ondevice event [options]
  Subscribe to your account's event stream.
$ ondevice event --until=<eventId> [--count=50]
  List past events up until the given eventId (useful for paging)

Options:
--json
  Prints the events as JSON objects, one per line
--since=eventId
  Specify the last eventId you've seen when invoking 'ondevice event' the last
  time.
  The event with the given ID will be included in the output (unless there have
  been more than --count events since then)
--until=eventId
  Only list past events, up until the given eventId (exits immediately)
  Can't be used in conjunction with --since, --timeout or --await
--count=n
  Display n existing events for --since or --until.
  Defaults to 50
--type=eventType[,...]
  Filters the output by event type (comma-separated list).
  Some types: deviceOnline, deviceOffline, connect, accept, close,
  For a full list of event types, have a look at the ondevice.io documentation.

--device=devId[,...]
  Filters the output for one or more devices (comma-separated list)
--timeout=n
  Stops the event stream after n seconds.
  0 means 'exit immediately' (will only print existing events), negative values
  disable timeouts.
  Exits with code 2.
  (To start where you left off, use the --since option)
--await=eventType
  Waits for an event of type eventType to happen (and exits with code 0 as soon
  as such an event was received).
  If both --timeout and --await are present, whichever one happens first will
  cause the program to exit (check the return code to see what happened first).
  If --since was specified, that event will be printed but won't trigger an exit


Examples:
  ondevice event --json --timeout=30 --since=1234
    List events for 30 seconds (you could run this in a loop, )
  ondevice event --json --device=dev1,dev2 --await=deviceOnline
    Exit as soon as one of the specified devices comes online (have a look at
    the output to see which one it is)
  ondevice event --count=50 --timeout=0
    List the 50 most recent events (and exit immediately)
  ondevice event --until=1234 --count=50
    List event 1234 and the 50 events before it (and exit immediately)
`,
	},
}

EventCommand -- implements `ondevice event`

View Source
var ListCommand = listCommand{
	BaseCommand: BaseCommand{
		Arguments: "[--json] [--props] [--status=<online/offline>] [--print-ids] [filters...]",
		ShortHelp: "List your devices",
		RunFn:     nil,
		LongHelp: `$ ondevice list [--options] [filters...]

List your devices

Options:
--json
  output JSON, one line/object per device
--props
  include properties (only affects JSON output)
--state <online/offline>
  limit to devices that are on/offline
--print-ids
	Print one devId per line (instead of tabular or JSON output)
	Can be used as input to

Filters:

With filters you can limit the output based on device properties.

Filters have the format:
  propertyName[operator[value]]
e.g.:
  somePackageVersion<2.3.4
  foo=

All comparisons are string-based (e.g. "234" is less than "99")
Missing properties are treated like the empty string ("arch=" lists devices with
empty or missing 'arch' property).


The following comparison operators are supported (comma-separated):
"=,==,!=,<,<<,<=,>,>>,>="

The one-character operators ("=,<,>") each have a two-character alias ("==,<<,>>"
respectively). These are provided to fix ambiguities (if the value to c start with "")
Note that you might have to escape '>' and '<' to shell redirection


Example:
  $ ondevice list
  ID            State   IP             Version         Name
  demo.7t91ta   offline                ondevice v0.4.3
  demo.fbqh2p   offline 192.168.1.23   ondevice v0.3.9
  demo.q5dkpm   online  127.0.0.1      ondevice v0.4.2
  demo.thm7br   offline 10.0.0.127     ondevice v0.4.3 My Raspberry PI

Example: Filters
  $ ondevice list 'fooVersion<2.3.4' 'foo=' --print-ids
	demo.7t91ta
  demo.fbqh2p
	demo.thm7br

	Only lists devices with the "fooVersion" property less than "2.3.4" (simple
	string comparison, so "2.3.4" < "2.34.5") and without the "foo" property
	(unset is equivalent to "")

Example: JSON output
  $ ondevice list --json --props
  {"id":"demo.7t91ta",state":"offline","stateTs":1490197318991,"version":"ondevice v0.4.3"}
  {"id":"demo.fbqh2p","ip":"192.168.1.23","state":"offline","stateTs":1485721709598,"version":"ondevice v0.3.9"}
  {"id":"demo.q5dkpm","ip":"127.0.0.1","state":"offline","stateTs":1487068641353,"version":"ondevice v0.4.2","props":{"test":"1234"}}
  {"id":"demo.thm7br","ip":"10.0.0.127","state":"offline", "": "My Raspberry PI","stateTs":1490963689912,"version":"ondevice v0.4.3"}

  Note that JSON fields may be missing or null

`,
	},
}

ListCommand -- implements `ondevice list`

View Source
var ListOpts struct {
	Properties bool   `short:"p" long:"props" description:"Include properties in the JSON output"`
	JSON       bool   `short:"j" long:"json" description:"JSON output, on object/device per line"`
	State      string `long:"state" description:"Filter output by device state, one of online/offline"`
	User       string `long:"user" description:"List devices of another user"`
	PrintIDs   bool   `long:"print-ids" description:"Print only "`
}

ListOpts -- commandline arguments for `ondevice list`

View Source
var LoginCommand = BaseCommand{
	Arguments: "[--batch=username]",
	ShortHelp: "Log in to the ondevice.io service",
	RunFn:     loginRun,
	LongHelp: `$ ondevice login

Log in to the ondevice.io service using one of your API keys.

Options:
--batch=username
  Run in batch mode, using the given username and reading the authentication key
  from stdin, e.g.:
    echo '5h42l5xylznw'|ondevice login --batch=demo


Example:
  $ ondevice login
  User: <enter your user name>
  Auth: <enter your credentials>
`,
}

LoginCommand -- implements `ondevice login`

View Source
var PipeCommand = pipeCommand{
	BaseCommand: BaseCommand{
		Arguments: "<devId> <service>",
		ShortHelp: "Pipes a device's service to stdout/stdin",
		RunFn:     nil,
		LongHelp: `$ ondevice pipe <devId> <service>

Sends data from stdin to the specified service - and prints whatever it gets in
return to stdout.

This command is used internally by 'ondevice ssh' to serve as ssh's ProxyCommand.

Example:
  $ echo hello world | ondevice pipe <devId> echo
  hello world

	Sends 'hello world' to q5dkpm's 'echo' service. The echo service simply returns
	the data it gets back to the sender. Therefore the above command is equivalent
	to simply calling 'echo hello world' (as long as your device is online).
`,
	},
}

PipeCommand -- Implements `ondevice pipe`

View Source
var RsyncCommand = BaseCommand{
	Arguments: "[rsync args...]",
	ShortHelp: "Copy files from/to your devices using rsync",
	RunFn:     rsyncRun,
	LongHelp: `$ ondevice rsync [rsync-options...]

Copy files from/to devices using rsync

Examples:

- ondevice rsync -av /source/path/ root@myDev:/target/path/
    copy the local /src/path to myDev's /target/path/ as root
    (and pass the -a and -v options to rsync)
- ondevice rsync me@otherDev:/etc/motd /tmp/other.motd
    copy otherDev's /etc/motd file to /tmp/other.motd (and login as 'me')

This command is only a thin wrapper around the 'rsync' client (using its '-e'
argument to make it use 'ondevice ssh' internally).
`,
}

RsyncCommand -- implements `ondevice rsync`

View Source
var SCPCommand = BaseCommand{
	Arguments: "[scp args...] [[user1@]host1:]file1 ... [[userN@]hostN:]fileN",
	ShortHelp: "Copy files from/to your devices using scp",
	RunFn:     scpRun,
	LongHelp: `$ ondevice scp [scp-options...]

Copy files from/to devices using scp

Examples:

- ondevice scp -pv /source/path/ root@myDev:/target/path/
    copy the local /src/path to myDev's /target/path/ as root
    (and pass the -p and -v options to scp)
- ondevice scp me@otherDev:/etc/motd /tmp/other.motd
    copy otherDev's /etc/motd file to /tmp/other.motd (and login as 'me')

Notes:
- while it is possible to copy files between two servers, scp will initiate
  both connections simultaneously causing two concurrent password prompts
	which won't work (unless of course you've set up ssh_agent properly).
- uses scp's '-3' flag (allowing files to be copied between two remote devices)
- We use our own known_hosts file (in ~/.config/ondevice/known_hosts).
  Override with ''-oUserKnownHostsFile=...'
`,
}

SCPCommand -- implements `ondevice scp`

View Source
var SFTPCommand = BaseCommand{
	Arguments: "[sftp-flags] [user@]devId",
	ShortHelp: "copy files from/to a device using sftp",
	RunFn:     runSFTP,
	LongHelp: `
  $ ondevice sftp [sftp-options...] [user@]devId

  Interactively copy files from/to devices using scp

  Examples:
  - ondevice sftp user@myDev
    open an sftp session to 'myDev', logging in as 'user'

  Notes:
  - We use our own known_hosts file (in ~/.config/ondevice/known_hosts).
  Override with ''-oUserKnownHostsFile=...'
`,
}

SFTPCommand -- implements `ondevice sftp`

View Source
var SSHCommand = BaseCommand{
	Arguments: "[ssh-arguments...]",
	ShortHelp: "Connect to your devices using the ssh protocol",
	RunFn:     sshRun,
	LongHelp: `$ ondevice ssh [<user>@]<device> [ssh-arguments...]

Connect to your devices using the 'ssh' command.

This is a relatively thin wrapper around the 'ssh' command.
The main difference to invoking ssh directly is that instead of regular host names you'll have to specify an ondevice deviceId.
The connection is routed through the ondevice.io network.

ondevice ssh will try to parse ssh's arguments, the first non-argument has to be
the user@devId combo.

See ssh's documentation for further details.

Examples:
- ondevice ssh device1
  simply connect to device1
- ondevice ssh user@device1
  open an SSH connection to device1, logging in as 'user'
- ondevice ssh device1 echo hello world
  run 'echo hello world' on device1
- ondevice ssh device1 -N -L 1234:localhost:80
  Tunnel the HTTP server on device1 to the local port 1234 without opening
  a shell
- ondevice ssh device1 -D 1080
  Starting a SOCKS5 proxy listening on port 1080. It'll redirect all traffic
  to the target host.

Notes:
- We use our own known_hosts file (in ~/.config/ondevice/known_hosts).
  Override with ''-oUserKnownHostsFile=...'
`,
}

SSHCommand -- implements `ondevice ssh`

View Source
var StatusCommand = BaseCommand{
	Arguments: "[--json]",
	ShortHelp: "Prints the client and local device status",
	LongHelp: `$ ondevice status [--json]

Print status and version information on the local ondevice client/device

Options:
--json
  Prints JSON formatted instead of human readable output

Exit Codes:
0: daemon up and running
1: on error
2: daemon running but not online
3: daemon not running (or unreachable)

Examples:

  $ ondevice status
  Device:
    devID:  demo.q5dkpm
    state:  online
    version:  0.4.4

  Client:
    version:  0.4.4

  $ ondevice status --json
  {
    "version": "0.4.4",
    "client": {
      "version": "0.4.4"
    },
    "device": {
      "devId": "demo.q5dkpm",
      "state": "online"
    }
  }
`,
	RunFn: statusRun,
}

StatusCommand -- implements `ondevice status`

View Source
var StopCommand = BaseCommand{
	Arguments: "",
	LongHelp: `$ ondevice stop

Stops a running ondevice daemon (using the ondevice.pid file) and tries to
terminate it.

Returns 0 if the daemon was stopped, 1 if it wasn't running and 2 on error
(e.g. after a 30sec timeout)
`,
	ShortHelp: "Stops the local ondevice daemon (if running)",
	RunFn:     runStop,
}

StopCommand -- Stops the ondevice daemon (by sending SIGTERM)

Functions

func List

func List() map[string]Command

List -- list command names

func Register

func Register(cmdName string, cmd Command)

Register -- Registers a new (or replaces an existing) command

pass cmd=nil to remove a Command

func Run

func Run(cmdName string, args []string) int

Run -- Run a command with the specified arguments

Types

type BaseCommand

type BaseCommand struct {
	Arguments string
	ShortHelp string
	LongHelp  string
	RunFn     func(args []string) int
}

BaseCommand -- implements the Command interface

type Command

type Command interface {
	// contains filtered or unexported methods
}

Command - Defines a command

func Get

func Get(cmd string) Command

Get -- Return specified command (or nil if not found)

type DaemonOpts

type DaemonOpts struct {
	Configfile string `long:"conf" description:"Path to ondevice.conf (default: ~/.config/ondevice.conf)"`
	Pidfile    string `long:"pidfile" description:"Path to ondevice.pid (default: ~/.config/ondevice.pid)"`
	SocketURL  string `long:"sock" description:"ondevice.sock URL (default: unix://~/.config/ondevice.sock)"`
}

DaemonOpts -- commandline arguments for `ondevice daemon`

type DeviceOpts added in v0.6.0

type DeviceOpts struct {
	Yes bool `long:"yes" short:"y" description:"Confirm deletion noninteractively"`
}

type StatusCmd

type StatusCmd struct{}

StatusCmd -- implements 'ondevice status'

Jump to

Keyboard shortcuts

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