Skip to content

Commit

Permalink
Issue #148: Sniffing to multiple interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed May 21, 2020
1 parent bad3ade commit 46b3ed0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 81 deletions.
44 changes: 37 additions & 7 deletions amazon_dash/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def print_version(ctx, param, value):
@click.option('--verbose', 'loglevel', help='set logging to COMM',
flag_value=5)
@click.option('--version', is_flag=True, callback=print_version,
expose_value=False, is_eager=True)
expose_value=False, is_eager=True,
help='Get amazon-dash version')
def cli(loglevel):
"""Hack your Amazon Dash to run what you want."""
from amazon_dash import __version__
click.secho('Welcome to Amazon-dash v{} using Python {}'.format(__version__, sys.version.split()[0]),
fg='cyan')
Expand All @@ -121,9 +123,17 @@ def run(config, root_allowed, ignore_perms):
Listener(config, ignore_perms).run(root_allowed=root_allowed)


@cli.command('check-config', help='Validate the configuration file.')
@cli.command('check-config')
@click.option('--config', type=click.Path(), help='Path to config file.', default=CONFIG_FILE)
def check_config(config):
"""Check the configuration file before starting the program. For example:
.. code-block:: shell
amazon-dash check-config --config /etc/amazon-dash.yml
The syntax is:
"""
from amazon_dash.config import check_config
check_config(config)

Expand All @@ -134,14 +144,32 @@ def check_config(config):
@click.option('--root-allowed', is_flag=True, default=False,
help='Allow execute commands on config file as root')
def test_device(device, config, root_allowed):
"""Test device execution without pressing the associated button. Useful for
testing and debugging. For example:
.. code-block:: shell
amazon-dash test-device 00:11:22:33:44:55 --config /etc/amazon-dash.yml
The syntax is:
"""
from amazon_dash.listener import test_device
test_device(device, config, root_allowed)


@cli.command(help='Discover Amazon Dash device on network.')
@cli.command()
@click.option('--interface', help='Network interface. Use this parameter for each interface to listen on',
multiple=True)
def discovery(interface):
"""Use *discovery mode* **to know the mac of your Dash** (Run the program,
and then press the button). For example:
.. code-block:: shell
sudo amazon-dash discovery
The syntax is:
"""
interface = list(interface) or None
from amazon_dash.discovery import discover
discover(interface)
Expand All @@ -151,8 +179,10 @@ def discovery(interface):
@click.option('--ssid', type=str, prompt='SSID (Wireless network name)')
@click.option('--password', prompt='Network password', hide_input=True,
help='Password of the wifi network to configure on the device')
@click.option('--no-enable-wifi', is_flag=True)
@click.option('--no-input', is_flag=True)
@click.option('--no-enable-wifi', is_flag=True,
help='Do not activate wifi connection. You must connect manually '
'if you use this option')
@click.option('--no-input', is_flag=True, help='Answer yes to all questions')
def configure(ssid, password, no_enable_wifi, no_input):
click.echo('This command allows you to configure the Wi-Fi network of an amazon-dash device.')
click.secho('During the configuration you will have to block the Internet connection of the device.',
Expand Down Expand Up @@ -180,8 +210,8 @@ def configure(ssid, password, no_enable_wifi, no_input):


@cli.command('hack-device', help='Hack an amazon-dash device that has never been connected to amazon servers.')
@click.option('--no-input', is_flag=True)
@click.option('--loop', type= int, default=5)
@click.option('--no-input', is_flag=True, help='Answer yes to all questions')
@click.option('--loop', type= int, default=5, help='Number of times the audio will play')
def hack_device(no_input, loop):
click.echo('This command allows you to hack a Amazon-dash device built on May 2016 and earlier. '
'Even if your device was purchased later, it is likely that it has an older firmware installed. ')
Expand Down
1 change: 1 addition & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ clean:
rm -rf $(BUILDDIR)/*

html:
rm -rf $(BUILDDIR)
$(SPHINXAPIDOC) -o . ../amazon_dash
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
Expand Down
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx_click.ext'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
80 changes: 8 additions & 72 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,10 @@
=====
Usage
=====
To see the available help run::

$ amazon-dash --help

Example::

Usage: amazon-dash [OPTIONS] COMMAND [ARGS]...

Options:
--info set logging to info
--warning set logging to warning
--quiet set logging to ERROR
--debug set logging to DEBUG
--verbose set logging to COMM
--help Show this message and exit.

Commands:
run* Run server
check-config Validate the configuration file.
discovery Discover Amazon Dash device on network.
test-device Test a configured device without press...


To see the help of a command::

$ amazon-dash <command> --help

For example::

$ amazon-dash run --help

Usage: amazon-dash run [OPTIONS]

Run server

Options:
--config PATH Path to config file.
--root-allowed Allow execute commands on config file as root
--ignore-perms Do not check the permissions of the configuration file. Use
this option at your own risk in secure environments (like
Docker).
--help Show this message and exit.


Discovery mode
--------------
Use *discovery mode* **to know the mac of your Dash** (Run the program, and then press the button)::

$ sudo amazon-dash discovery
.. click:: amazon_dash.management:cli
:prog: amazon-dash
:show-nested:


Daemon mode
Expand All @@ -66,27 +21,27 @@ Systemd
Most modern Linux systems use Systemd by default. Some exceptions are Slackware and Gentoo. To run amazon-dash using
Systemd::

$ sudo systemctl start amazon-dash
sudo systemctl start amazon-dash

To check if it has been executed correctly::

$ sudo systemctl status amazon-dash
sudo systemctl status amazon-dash

.. hint::
Run ``$ sudo amazon-dash check-config --config /etc/amazon-dash.yml`` to verify that the configuration is correct
before running amazon-dash

To restart amazon-dash after modifying the configuration file to apply the changes::

$ sudo systemctl restart amazon-dash
sudo systemctl restart amazon-dash

To see the log::

$ sudo journalctl -r -u amazon-dash
sudo journalctl -r -u amazon-dash

To run Amazon-dash at startup::

$ sudo systemctl enable amazon-dash
sudo systemctl enable amazon-dash



Expand Down Expand Up @@ -117,22 +72,3 @@ By default it is forbidden to execute commands as root in your configuration fil
avoid escalation privileges. If you are going to run amazon-dash as root it is highly recommended to define a
user by each cmd config device. You can disable this security measure using ``--root-allowed``.


Check config
------------
If you have edited the configuration file you can check that the file is ok before starting the program::

$ sudo amazon-dash check-config --config /etc/amazon-dash.yml


Test device
-----------
Sometimes you may want to test the execution of a device without pressing the associated button. This is useful for
testing and debugging::

$ sudo amazon-dash test-device <device mac address>[ --root-allowed][ --config <config file>]

For example::

$ sudo amazon-dash test-device 00:11:22:33:44:55 --config /etc/amazon-dash.yml

3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pyfakefs==4.0.2
requests-mock>=1.4.0
Sphinx
Sphinx
sphinx-click

0 comments on commit 46b3ed0

Please sign in to comment.