GithubHelp home page GithubHelp logo

fbxosctrl's Introduction

fbxosctrl

Description

Les détails de mise en oeuvre de fbxosctrl sont disponibles sur le wiki : https://github.com/skimpax/fbxosctrl/wiki

This command line utility handles some FreeboxOS commands which are sent to a freebox server to be executed within FreeboxOS app.

Free is a French DSL operator (free.fr) providing two set-top-box :

  • Freebox Server, connected to the ADSL wire
  • Freebox Player, connected to the TV

This tool applies to the server box of Freebox v6 (aka Freebox Revolution) only with latest firmware (v3.X). FreeboxOS is the name given by Free.fr to their software running inside the Freebox Server.

The Frebbox Server address is discovered via mDNS and HTTPS is used to dialog with it.

Supported services:

  • get current wifi radio status (ON/OFF)
  • set wifi radio ON/OFF
  • get current wifi planning status (ON/OFF)
  • set wifi planning ON/OFF
  • get current DHCP leases
  • get phone calls list (new only or all)
  • mark phone call as read
  • reboot the Freebox Server
  • display the system information
  • display the line ethernet information (bit rates)
  • display the line media information (xDSL/FTTH)
  • get storage status
  • get downloads status

Dependencies

python3-requests and python3-zeroconf You can use this command to install them:

apt-get install python3-requests python3-zeroconf

Output format

By default, output is printed in human readable format (iow. formated text), potentially with partial information extracted from the FreeboxOS response. By using option '-j', output is printed in JSON format, containing the whole FreeboxOS response. This allows further processing within upper layer scripts for instance.

Default format:

Server info:
 - Model:     Freebox Server (r2)
 - MAC:       68:A3:78:01:02:03
 - Firmware:  4.0.4
 - Uptime:    9 jours 51 minutes 56 secondes
 - Sensors:
   - Disque dur:          37°C
   - Température Switch:  53°C
   - Température CPU M:   63°C
   - Température CPU B:   58°C

JSON format:

{'result': {'serial': '7626000000000000', 'user_main_storage': '', 'temp_cpub': 60, 'temp_cpum': 66, 'uptime': '1 jour 1 heure 43 minutes 50 secondes', 'temp_sw': 55, 'disk_status': 'active', 'board_name': 'fbxgw2r', 'box_authenticated': True, 'firmware_version': '3.5.2', 'uptime_val': 92630, 'fan_rpm': 2570, 'box_flavor': 'full', 'mac': '68:A3:00:01:02:03'}, 'success': True}

Usage

usage: fbxosctrl.py [-h] [--version] [-v] [-j] [-c CONF_PATH]
                    (--regapp | --wrstatus | --wron | --wroff | --wpstatus | --wpon | --wpoff | --dhcpleases | --pfwd | --clist | --cnew | --cread | --reboot | --sinfo | --einfo | --linfo | --dlist | --dspace | --tlist)

Command line utility to control some FreeboxOS services.

optional arguments:
  -h, --help    show this help message and exit
  --version     show program's version number and exit
  -v            verbose mode
  -j            simply print Freebox Server reponse in JSON format
  -c CONF_PATH  path where to store/retrieve this app configuration files
                (default: local directory)
  --regapp      register this app to FreeboxOS and save result in
                configuration file (to be executed only once)
  --wrstatus    get FreeboxOS current Wifi Radio status
  --wron        turn FreeboxOS Wifi Radio ON
  --wroff       turn FreeboxOS Wifi Radio OFF
  --wpstatus    get FreeboxOS current Wifi Planning status
  --wpon        turn FreeboxOS Wifi Planning ON
  --wpoff       turn FreeboxOS Wifi Planning OFF
  --dhcpleases  display the current DHCP leases info
  --pfwd        display the list of port forwardings info
  --clist       display the list of received calls
  --cnew        display the list of new received calls
  --cread       set read status for all received calls
  --reboot      reboot the Freebox Server now!
  --sinfo       display the system information
  --einfo       display the line ethernet information
  --linfo       display the line media (ADSL/Fiber) information
  --dlist       display connected drives
  --dspace      display spaces (total/used/free) on connected drives
  --tlist       display downloads list

Contributions

Contributions are welcome. Just ensure it passes the flake8 tool rules. It is expected that flake8 only complains about E501 rule (line larger than 79 chars) (ancestral rule in my opinion), and a single E122 ( for literal content of RSA certificate). All other non-conformance should be fixed.

apt-get install flake8
flake8 fbxosctrl.py

fbxosctrl's People

Contributors

afer92 avatar bousqi avatar kif avatar skimpax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fbxosctrl's Issues

Unable to register app: OSError: [Errno 101] Network is unreachable

OK, this is clearly my misunderstanding, this is my 1st (well 2nd-failed) attempt at using this repo.
Whilst "OSError: [Errno 101] Network is unreachable" sounds embarassingly like I'm doing something dumb I've no idea what that is.

I'm running on Ubuntu18.04 LTS, with Python 3.6.5.

I'm running command
/usr/bin/python3 ./fbxosctrl.py --regapp
to use the system Python which has zeroconf module installed.

It obtains the addressing and certificate files OK.
Below are the contents of the addressing file: (with my hostname masked)

{
 "api_base_url": "/api/",
 "api_domain": "****.fbxos.fr",
 "api_version": "6.0",
 "port": "46736",
 "protocol": "https"
}

but then the script barfs with a network connection issue - see below.
I tried pinging the address which works fine.
I tried nmap on the port which says it's filtered (didn't really expect anything else!).

What's happening?
What should I do to fix/debug?

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 83, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 852, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 284, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd4e56dba8>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='sd4gr1i9.fbxos.fr', port=46736): Max retries exceeded with url: /api/v6/login/authorize/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd4e56dba8>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./fbxosctrl.py", line 1204, in <module>
    rc = cli.dispatch(args)
  File "./fbxosctrl.py", line 1192, in dispatch
    return self._cmd_handlers.get(cmd, self._parser.print_help)()
  File "./fbxosctrl.py", line 564, in register_app
    resp = self._http.post(uri, data=data, no_login=True)
  File "./fbxosctrl.py", line 369, in post
    timeout=timeout if timeout is not None else self._http_timeout)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='sd4gr1i9.fbxos.fr', port=46736): Max retries exceeded with url: /api/v6/login/authorize/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fdd4e56dba8>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

mdns_info empty

Hello,
when i launch the registration, i have this error :
Traceback (most recent call last):
File "fbxosctrl.py", line 960, in
ctrl.conf.load()
File "fbxosctrl.py", line 125, in load
self._load_addressing_params()
File "fbxosctrl.py", line 182, in _load_addressing_params
self._addr_params['protocol'] = 'https' if mdns_info.properties[b'https_available'].decode() else 'http'
AttributeError: 'NoneType' object has no attribute 'properties

mdns_info is empty, and i don't know why.

Thanks

Hmac problem again?

Hello, thanks for your script.

I've already used your script on other machines, but I need to use it on an older nas with Alt -f software as SE.
I've installed SimpleJson and request, and registrated with success .

But when I try to reboot the Freebox, I've this error :

[root@dns320]# ./fbxosctrl.py -c fbxosctrl_registration.txt --reboot
Traceback (most recent call last):
File "./fbxosctrl.py", line 510, in
rc = cli.cmdExec(sys.argv[1:])
File "./fbxosctrl.py", line 497, in cmdExec
return self.dispatch(argsdict.keys())
File "./fbxosctrl.py", line 504, in dispatch
return self.cmdCallbacks.get(cmd, self.parser.print_help)()
File "./fbxosctrl.py", line 342, in reboot
self._login()
File "./fbxosctrl.py", line 162, in _login
h = hmac.new(apptoken, key, sha1)
File "build/bdist.linux-armv5tel/egg/hmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "build/bdist.linux-armv5tel/egg/hmac.py", line 72, in init
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

my python version is 2.7.2-4.

Thanks for your help.

Debian 11 fix

J'utilisais cette appli pendant 3 ans avec Debian 9 Stretch, qui utilise Python 3.5, mais lors du passage sur Debian 11 l'appli a cessé de fonctionner, étant préciser que la version de Python3 a changé:

python3 -V

Python 3.9.2
En cherchant des solutions, j'ai modifié le programme tout légèrement:

diff fbxosctrl.py fbxosctrl.py.v.2.4.4.before.py.3.9.fix

157,158c157,158
< self._reg_params.get('track_id') != None and
< self._reg_params.get('app_token') != ''):

            self._reg_params.get('track_id') is not None and
            self._reg_params.get('app_token') is not ''):

244c244
< elif self._resp.get('success') != True and self._resp['success'] != False:

    elif self._resp.get('success') is not True and self._resp['success'] is not False:

304c304
< if self._session_token != None:

    if self._session_token is not None:

321c321
< timeout=timeout if timeout != None else self._http_timeout)

        timeout=timeout if timeout is not None else self._http_timeout)

345c345
< timeout=timeout if timeout != None else self._http_timeout)

        timeout=timeout if timeout is not None else self._http_timeout)

369c369
< timeout=timeout if timeout != None else self._http_timeout)

        timeout=timeout if timeout is not None else self._http_timeout)

714c714
< if resp.result['has_sfp'] != True and resp.result['sfp_present'] != True:

    if resp.result['has_sfp'] is not True and resp.result['sfp_present'] is not True:

727c727
< if resp.result['link'] != True:

    if resp.result['link'] is not True:

Apres cette modification tout refonctionne comme avant 👍

./fbxosctrl.py --version

fbxosctrl.py 2.4.4

Il faut peut-être modifier les sources sur ce git.

HMAC problem ?

This is the code I get when I try to set the Wifi off :

>>> setWifiOff
>>> _setWifiStatus
>>> _login
>>> isRegistered
>>> hasRegistrationParams
>>> _loadRegistrationParams: file: fbxosctrl_registration.txt
>>> getRegistrationStatus
>>> hasRegistrationParams
http://mafreebox.freebox.fr/api/v1/login/authorize/1
GET url: http://mafreebox.freebox.fr/api/v1/login/authorize/1
GET response: {"success":true,"result":{"status":"granted","challenge":"rF7pTgHX8flUZ9TFqa6+Yr\/+0N0yCO3M","password_salt":"KpDAqdZIgRdDX7IXKqkFccT4taWFZ8+Y"}}
GET url: http://mafreebox.freebox.fr/api/v1/login/
GET response: {"success":true,"result":{"logged_in":false,"challenge":"rF7pTgHX8flUZ9TFqa6+Yr\/+0N0yCO3M","password_salt":"KpDAqdZIgRdDX7IXKqkFccT4taWFZ8+Y"}}
challenge: rF7pTgHX8flUZ9TFqa6+Yr/+0N0yCO3M, apptoken: a4a7K0S5iPwboVUaWmfalFd3/pHoYYawljcAvhHzRBn3dZD9gM6rAX5lMXZRElZI
Traceback (most recent call last):
  File "fbxosctrl.py", line 467, in <module>
    rc = cli.cmdExec(sys.argv[1:])
  File "fbxosctrl.py", line 454, in cmdExec
    return self.dispatch(argsdict.keys())
  File "fbxosctrl.py", line 461, in dispatch
    return self.cmdCallbacks.get(cmd, self.parser.print_help)()
  File "fbxosctrl.py", line 397, in setWifiOff
    return self._setWifiStatus(False)
  File "fbxosctrl.py", line 212, in _setWifiStatus
    self._login()
  File "fbxosctrl.py", line 159, in _login
    h = hmac.new(apptoken, key, sha1)
  File "/volume1/@appstore/python/lib/python2.7/hmac.py", line 133, in new
    return HMAC(key, msg, digestmod)
  File "/volume1/@appstore/python/lib/python2.7/hmac.py", line 72, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

Readme Typos

I just upgraded to last version, and I noticed typos in the readme file, dependencies section :

DependEncies:
python3-requests and python3-zeroconf You can use this command to install them:
apt-get install python3-requests python3-zeroconf

bridged mode ...

Hi,

I tried your application as apparently it does everything I need but it does not work in bridged mode as Zeroconf is unable to retrieve the conf.

Is it supposed to work ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.