Module admin

This module implements a graphical administration interface for SmartHomeNG plugins.

class modules.admin.Admin(sh, testparam='')[source]

Bases: lib.model.module.Module

version = '1.6.0'
longname = 'Admin module for SmartHomeNG'
port = 0
start()[source]

If the module needs to startup threads or uses python modules that create threads, put thread creation code or the module startup code here.

Otherwise don’t enter code here

add_stop_method(method, classname='')[source]
stop()[source]

If the module has started threads or uses python modules that created threads, put cleanup code here.

Otherwise don’t enter code here

error_page(status, message, traceback, version)[source]

Error 404 page, that redirects to index.html of Angular application

Parameters
  • status

  • message

  • traceback

  • version

Returns

page to display (a redirect)

Return type

str

modules.admin.get_local_ipv4_address()[source]

Get’s local ipv4 address of the interface with the default gateway. Return ‘127.0.0.1’ if no suitable interface is found

Returns

IPv4 address as a string

Return type

string

modules.admin.translate(s)[source]
class modules.admin.WebInterface(webif_dir, module, shng_url_root, url_root)[source]

Bases: modules.admin.systemdata.SystemData, modules.admin.itemdata.ItemData, modules.admin.plugindata.PluginData

class modules.admin.WebApi(webif_dir, module, shng_url_root, url_root)[source]

Bases: modules.admin.rest.RESTResource

exposed = True
home()
index()[source]

A formatted version of the sample README.md can be found here:

A raw version of the README.md for copy and paste can be found below the metadata file.

The meta data file:

module.yaml
# Metadata for the plugin
module:
    # Global module attributes
    classname: Admin
    version: 1.6.0
    sh_minversion: 1.5b
#    sh_maxversion: 1.3             # maximum shNG version to use this plugin (leave empty if latest)
    description:
        de: 'Dieses Modul implementiert das Administrationinterface von SmartHomeNG'
        en: 'This module implements the administration interface for SmartHomeNG'
        fr: "Ce module implémente l'interface d'administration pour SmartHomeNG"

parameters:
    login_expiration:
        type: num
        default: 48
        description:
            de: 'Ablaufdauer des Logins in Stunden (ab Loginzeitpunkt)'
            en: 'Expiration time of the login in hours (counting from time of login)'
            fr: "Temps d'expiration de l'identification en heures (à partir du moment de l'identification)"

    login_autorenew:
        type: bool
        default: True
        description:
            de: 'Bestehendes Login-Token automatisch verlängern'
            en: 'Automatically extend an existing login-token'
#            fr: ""

    pypi_timeout:
        type: int
        default: 5
        description:
            de: 'Timeout bei der Abfrage der pypi Website'
            en: 'Timeout for getting data from the pypi website'
            fr: "Délai d'attente pour obtenir des données du site Web Pypi"

    itemtree_fullpath:
        type: bool
        default: True
        description:
            de: 'Im Item-Tree die Items mit vollem Pfad-Namen anzeigen'
            en: 'Display items with full path in item tree'
            fr: "Afficher le chemin complèt des objets dans l'arborescence"

    itemtree_searchstart:
        type: num
        default: 2
        description:
            de: 'Minimale Anzahl eingegebener Zeichen ab denen die Suche im Item-Tree beginnt'
            en: 'Minimum number of entered characters to start searching the item tree'
            fr: "Nombre minimum de caractères entrés pour démarrer la recherche dans l'arborescence"

    websocket_host:
        type: ip
        description:
            de: 'IP Adresse für den websocket Zugriff'
            en: 'ip address to use for websocket access'
            fr: "Adresse IP à utiliser pour l'accès websocket"

    websocket_port:
        type: int
        valid_min: 0
        valid_max: 65535
        default: 2424
        description:
            de: 'Port der für den Websocket Zugriff verwendet wird'
            en: 'Port that is used for the websocket protocol'
            fr: "Port à utiliser pour l'accès websocket"

    log_chunksize:
        type: int
        valid_min: 25
        valid_max: 5000
        default: 1000
        description:
            de: 'Größe der gelesenen Blöcke bei der Anzeige großer Logdateien'
            en: 'Size of blocks (chunks) read when displaying large logfiles'
            fr: "Taille des morceaux lus lors de l'affichage de fichiers journaux volumineux"
README.md
# Module admin

This module implements the administration interface for SmartHomeNG.


## Requirements

This module is running under SmmartHomeNG versions beyond develop version v1.5d. It requires Python >= 3.4 as well as ... . You can install the libraries (python modules) with:

```
(sudo apt-get install ...)
sudo pip3 install ...
```

And please pay attention that the lib(s) are installed for Python3 and not an older Python 2.7 that is probably installed on your system. Be carefull to use `pip3` and nor `pip`.

> Note: This module needs the module handling in SmartHomeNG to be activated. Make sure, that `use_modules`in `etc/smarthome.yaml` is **not** set to False!


## Configuration

### etc/module.yaml


```yaml
# etc/module.yaml
admin:
    module_name: admin
```


## API of module admin

Im folgenden sind die einzelnen Teile des REST APIs beschrieben, 
welches das admin Modul zur Verfügung stellt und intern nutzt.

Wenn zur Nutzung des einzelen APIs eine Authentifizierung notwendig 
ist, ist dieses erwähnt.


### AUTH API -  Authentification for clients

#### POST /api/auth/
Authentifiziert den Client bei SmartHomeNG und erhält einen
Token (JWT) bei erfolgreicher Authentifizierung.


### CONFIG API - Get and update information about the core's configuration

#### GET /api/config
liefert die Konfiguration des Core von SmartHomeNG

#### GET /api/config/\<module (or 'common')>
liefert die Konfiguration der Modules oder des allgemeinen 
(common) Teils von SmartHomeNG

#### PUT /api/config/\<module (or 'common')>
Macht ein Update auf den entsprechenden Teil der Konfiguration

-> authentication_needed = True


### LOGICS API - xxx

#### ???


### LOGS API - Get information about logs and get log content

#### GET /api/logs
liefert die Liste der vorhandenen logs

#### GET /api/logs/\<logname>
liefert den Inhalt einer log-Datei


### PLUGINS API - Get information about installed or configured plugins

#### GET /api/plugins
liefert die Liste der installierten Plugins

#### GET /api/plugins/config
liefert die gesamte config


## PLUGIN API  -  Handle a single plugin configuration

#### POST /api/plugin/config/\<neu> 
legt eine neue Confic-section Namens ‚\<neu>‘ an

-> authentication_needed = True

#### PUT /api/plugin/config/\<plgsection>
Macht ein Update auf die Section ‚\<plgsection>‘

-> authentication_needed = True

#### DELETE /api/plugin/config/\<plgsection> 
Löscht die Section ‚\<plgsection>‘

-> authentication_needed = True


## SCENES API  -  Get information about configured scenes

####GET /api/scenes
liefert die Liste der konfigurierten Szenen


## SCHEDULER API  -  Get information about configured schedulers

####GET /api/sched
liefert die Liste der konfigurierten Scheduler


## SCHEDULER API  -  Get information about the SmartHomeNG server configuration

####GET /api/serverinfo
liefert Informationen über die Konfiguration des SmartHomeNG Servers


## THREADS API  -  Get information about running threads

####GET /api/threads
liefert die Liste der laufenden Threads


## STATUS API  -  Get running status of the SmartHomeNG server instance

####GET /api/status
liefert den aktuellen Status von SmartHomeNG


## RESTART API  -  Restart the SmartHomeNG server instance

####GET /api/restart
Startet die SmartHomeNG Server Instanz neu


##


### Test if module admin is loaded

`dummy` is a loadlable module. Therefore there is no guarantiee that it is present in every system. Before you can use this module, you have to make sure ist is loaded. You can do it by calling a method of the main smarthome object. Do it like this:

```
self.classname = self.__class__.__name__

try:
    self.mod_admin = self._sh.get_module('admin')
except:
    self.mod_admin = None
    
if self.mod_admin == None:
    # Do what is necessary if you can't use the admin interface
    # for your plugin. For example:
    self.logger.error('{}: Module ''admin'' not loaded - Abort loading of plugin {0}'.format(self.classname))
    return
```