PHP Module loxberry_system.php

Inclusion

require_once "loxberry_system.php";

It's not required to add a path to the PHP library.

Constants and Globals

Difference between global variables and constants

Constants are valid in the full PHP script and are specified without $ mark (e.g. LBHOMEDIR).  Disadvantage of constants is, that they are not expanded inside double-quotes. All LoxBerry constants are written in CAPITAL letters.

Global variables are available in the main script, but they need to be declared as global inside functions. They are, equivalent to the variables in the Perl modules, written in lowercase.

Variable example Quelle erweitern

# Usage of constants
 
// Using the constant LBHOMEDIR
print "1. LBHOMEDIR: " . LBHOMEDIR;
// Result: 1. LBHOMEDIR: /opt/loxberry
 
// Constants do not expand in strings - this cannot be used
print "2. LBPPLUGINDIR: LBPPLUGINDIR";
// Result: 2. LBPPLUGINDIR: LBPPLUGINDIR
 
// A function called testglobals using variables
testglobals();
 
function testglobals 
{
    global $lbpplugindir;
    // Using the declared $lbpplugindir
    print "3. lbpplugindir: $lbpplugindir";
    // Result: 3. lbpplugindir: myplugin
 
    // Without declaration - not working
    print "4. lbhomedir: $lbhomedir";
    // Result: 4. lbhomedir: 
}
 
 

The following table shows all global variables and all constants. Use variables or constants as you prefer. All plugin variables contain your plugin folder. Please remember that both constants and variables are case-sensitive (constants: CAPITAL without $; variables: lowercase with $).

In other languages like bash, you cannot access the PHP variables. For such cases you can use the system environment variables, that do not include the plugin folder. 


Variable Constant Usage
\\ $lbhomedir\\ 
\\ LBHOMEDIR\\ 
Home directory of LoxBerry, usually /opt/loxberry
PLUGIN variables and constants
$lbpplugindir LBPPLUGINDIR Sub-directory of the current plugin without path, e.g. squeezelite
$lbphtmlauthdir LBPHTMLAUTHDIR Absolute path to the HTMLAUTH directory of the active plugin, e.g. /opt/loxberry/webfrontend/htmlauth/plugins/squeezelite
$lbphtmldir LBPHTMLDIR Absolute path to the HTML directory of the active plugin, e.g. /opt/loxberry/webfrontend/html/plugins/squeezelite
$lbptemplatedir LBPTEMPLATEDIR Absolute path to the template directory of the active plugin, e.g. /opt/loxberry/templates/plugins/squeezelite
$lbpdatadir LBPDATADIR Absolute path to the data directory of the active plugin, e.g. /opt/loxberry/data/plugins/squeezelite
$lbplogdir LBPLOGDIR Absolute path to the log directory of the active plugin, e.g. /opt/loxberry/log/plugins/squeezelite
$lbpconfigdir LBPCONFIGDIR Absolute path to the config directory of the active plugin, e.g. /opt/loxberry/config/plugins/squeezelite
$lbpbindir LBPBINDIR Absolute path to the bin directory of the active plugin, e.g. /opt/loxberry/bin/plugins/squeezelite
SYSTEM variables and constants for LoxBerry-Core developers (plugin devs usually won't need)
$lbshtmlauthdir LBSHTMLAUTHDIR Absolute path to the SYSTEM HTMLAUTH directory /opt/loxberry/webfrontend/htmlauth/system
$lbshtmldir LBSHTMLDIR Absolute path to the SYSTEM HTML directory /opt/loxberry/webfrontend/html/system
$lbstemplatedir LBSTEMPLATEDIR Absolute path to the SYSTEM templates directory /opt/loxberry/templates/system
$lbsdatadir LBSDATADIR Absolute path to the SYSTEM data directory /opt/loxberry/data/system
$lbslogdir LBSLOGDIR Absolute path to the SYSTEM log directory /opt/loxberry/log/system
$lbstmpfslogdir LBSTMPFSLOGDIR Absolute path to the SYSTEM tmpfs log directory /opt/loxberry/system_tmpfs
$lbsconfigdir LBSCONFIGDIR Absolute path to the SYSTEM config directory /opt/loxberry/config/system
$lbsbindir LBSBINDIR Absolute path to the SYSTEM bin directory /opt/loxberry/bin
$lbssbindir LBSSBINDIR Absolute path to the SYSTEM bin directory /opt/loxberry/sbin/system

Functions

Most functions are in the class LBSystem, therefore they need to be called with LBSystem::function(). Some functions are in the main namespace and therefore don't require the LBSystem prefix. The title of every function in this documentation shows how to call it. 

Most function names and features are identical to the Perl sibling LoxBerry::System with PHP adjusted syntax. 

LBSystem::currtime

Returns a pre-formatted date/time string, e.g. to use in logfiles. Without parameter the format is human-readable. With parameters you can request a string that is optimized for file names, or an ISO formatted string.

LBSystem::epoch2lox

This function returns from a Unix Epoch timestamp the Loxone timestamp, or, without parameter, the current time as Loxone timestamp. 

LBSystem::get_binaries

LoxBerry's configuration saves execution paths to common binaries to stay system independend. As the required binary exists in the binary list, you should favor the variable instead of hard-coding the execution pathes in your plugin.

LBSystem::get_ftpport

Miniserver's FTP port is not included in Loxberry's configuration because it is requested on-demand by a webservice call. This function additionally supports Loxone CloudDNS and therefore always returns the correct FTP port.

LBSystem::get_localip

Returns the LoxBerry network ip address as string.

LBSystem::get_miniserver_by_ip

Searches for the given ip address in the Miniserver list and returns the list number. Use the list number in the array of get_miniservers.

LBSystem::get_miniserver_by_name

Searches for the given Miniserver name and returns the list number. Use the list number in the array of get_miniservers.

LBSystem::get_miniservers

This function returns an two dimension array of LoxBerry's configured Miniservers.

LBSystem::get_plugins

Returns an array with all installed plugins, including version information and icon uri.

LBSystem::is_disabled($text)

Used for config parameters. Returns True if the $text contains a word that fuzzy could mean False.

LBSystem::is_enabled($text)

Used for config parameters. Returns True if the $text contains a word that fuzzy could mean True.

LBSystem::lbcountry

Returns the current user country of LoxBerry (e.g. "at")

LBSystem::lbfriendlyname

Returns the user defined friendly name of this LoxBerry. This is not the hostname.

LBSystem::lbhostname

Returns the network hostname of LoxBerry.

LBSystem::lblanguage

Returns the current user langauge of LoxBerry (e.g. "de")

LBSystem::lbversion

Returns the current version of LoxBerry (e.g. "0.4.1")

LBSystem::lbwebserverport

Returns the Apache2 webserver port.

LBSystem::lox2epoch

This function returns from a Loxone timestamp the Unix Epoch timestamp . 

LBSystem::plugindata

This function returns a named array with all data of the current plugin from the plugin database. Optionally you can use the pluginname or foldername as parameter, to get the data from the named plugin.

LBSystem::pluginloglevel

This function returns the currently set plugin loglevel, that the user has set in the plugin management.

LBSystem::pluginversion

Returns the plugin version of your plugin from LoxBerry's plugin database.

LBSystem::readlanguage

Returns the appropriate user language as an array.

LBSystem::reboot_required

Sets the state of LoxBerry to require a reboot. This can be used for example in a plugin, where a change of a setting requires a reboot of LoxBerry.

CloudDNS

TESTING We had done no tests with the Cloud DNS features, therefore please give feedback if you have any issues.