FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-sysconfig.php File Reference

System configuration functions. More...

Go to the source code of this file.

Functions

 ConfigInit ($sysconfdir, &$SysConf, $exitOnDbFail=true)
 Initialize the fossology system after bootstrap(). More...
 
 get_pg_conn ($sysconfdir, &$SysConf, $exitOnDbFail=true)
 
 populate_from_sysconfig ($conn, &$SysConf)
 
 Populate_sysconfig ()
 Populate the sysconfig table with core variables.
 
 check_boolean ($value)
 Validation function check_boolean(). More...
 
 check_fossology_url ($url)
 Validation function check_fossology_url(). More...
 
 check_logo_url ($url)
 Validation function check_logo_url(). More...
 
 check_logo_image_url ($url)
 Validation function check_logo_image_url(). More...
 
 check_email_address ($email_address)
 Validation function check_email_address(). More...
 
 is_available ($url, $timeout=2, $tries=2)
 Check if the URL is available. More...
 
 check_url ($url)
 Check if the url is valid. More...
 
 check_IP ($ip)
 Check if the ip address is valid. More...
 
 set_python_path ()
 
 get_system_load_average ()
 Get system load average. More...
 

Variables

const CONFIG_TYPE_INT 1
 
const CONFIG_TYPE_TEXT 2
 
const CONFIG_TYPE_TEXTAREA 3
 
const CONFIG_TYPE_PASSWORD 4
 
const CONFIG_TYPE_DROP 5
 
const CONFIG_TYPE_BOOL 6
 

Detailed Description

System configuration functions.

Definition in file common-sysconfig.php.

Function Documentation

◆ check_boolean()

check_boolean (   $value)

Validation function check_boolean().

Check if the value format is valid, only true/false is valid

Parameters
string$valueThe value which will be checked
Returns
1, if the value is valid, or 0

Definition at line 617 of file common-sysconfig.php.

◆ check_email_address()

check_email_address (   $email_address)

Validation function check_email_address().

Check if the email address is valid.

Todo:
Implement this function if needed in the future.
Parameters
string$email_addressThe email address which will be checked
Returns
1: valid, 0: invalid

Definition at line 721 of file common-sysconfig.php.

◆ check_fossology_url()

check_fossology_url (   $url)

Validation function check_fossology_url().

Check if the URL is valid.

Parameters
string$urlThe URL which will be checked
Returns
1: valid, 0: invalid

Definition at line 635 of file common-sysconfig.php.

◆ check_IP()

check_IP (   $ip)

Check if the ip address is valid.

Parameters
string$ipIP address
Returns
1: yes

Definition at line 783 of file common-sysconfig.php.

◆ check_logo_image_url()

check_logo_image_url (   $url)

Validation function check_logo_image_url().

Check if the URL is available.

Parameters
string$urlThe url which will be checked
Returns
1: the url is available, 0: unavailable

Definition at line 694 of file common-sysconfig.php.

◆ check_logo_url()

check_logo_url (   $url)

Validation function check_logo_url().

Check if the URL is available.

Parameters
string$urlThe URL which will be checked
Returns
1: available, 0: unavailable

Definition at line 671 of file common-sysconfig.php.

◆ check_url()

check_url (   $url)

Check if the url is valid.

Parameters
string$urlThe url which will be checked
Returns
1: the url is valid, 0: invalid

Definition at line 767 of file common-sysconfig.php.

◆ ConfigInit()

ConfigInit (   $sysconfdir,
$SysConf,
  $exitOnDbFail = true 
)

Initialize the fossology system after bootstrap().

This function also opens a database connection (global PG_CONN).

System configuration variables are in four places:

  • SYSCONFDIR/fossology.conf (parsed by bootstrap())
  • SYSCONFDIR/VERSION
  • SYSCONFDIR/Db.conf
  • Database sysconfig table

VERSION and fossology.conf variables are organized by group. For example,

[DIRECTORIES]
REPODIR=/srv/mydir

But the sysconfig table and Db.conf are not. So all the table values will be put in a made up "SYSCONFIG" group. And all the Db.conf values will be put in a "DBCONF" group.

Parameters
string$sysconfdirPath to SYSCONFDIR
[out]array&$SysConfConfiguration variable array (updated by this function)
boolean$exitOnDbFailDo an exit() if can't connect to DB?

The first array dimension of $SysConf is the group, the second is the variable name. For example:

  • $SysConf[SYSCONFIG][LogoLink] => "http://my/logo.gif"
  • $SysConf[DIRECTORIES][MODDIR] => "/mymoduledir/ - $SysConf[VERSION][COMMIT_HASH] => "4467M"
Note
Since so many files expect directory paths that used to be in pathinclude.php to be global, this function will define the same globals (everything in the DIRECTORIES section of fossology.conf).

Definition at line 65 of file common-sysconfig.php.

◆ get_pg_conn()

get_pg_conn (   $sysconfdir,
$SysConf,
  $exitOnDbFail = true 
)

Parse the VERSION file and Db.conf and initialize respective keys in SysConf

The function also opens the connection to Postgres DB and return the object.

Parameters
string$sysconfdirPath to SYSCONFDIR
[in,out]array$SysConfConfiguration variable array
boolean$exitOnDbFailDo an exit() if can't connect to DB?
Returns
resource Postgres connection resource

Definition at line 85 of file common-sysconfig.php.

◆ get_system_load_average()

get_system_load_average ( )

Get system load average.

Get no of cores using nproc command. Get load using sys_getloadavg

Returns
button with different colors

Definition at line 808 of file common-sysconfig.php.

◆ is_available()

is_available (   $url,
  $timeout = 2,
  $tries = 2 
)

Check if the URL is available.

Parameters
string$urlURL
int$timeoutTimeout interval, default 2 seconds
int$triesIf unavailable, will try several times, default 2 times
Returns
1: available, 0: unavailable

Definition at line 735 of file common-sysconfig.php.

◆ populate_from_sysconfig()

populate_from_sysconfig (   $conn,
$SysConf 
)

Populate SysConf array with sysconfig DB table.

Parameters
resource$connConnection to Postgres
[in,out]array$SysConfConfiguration variable array

Definition at line 139 of file common-sysconfig.php.

◆ set_python_path()

set_python_path ( )

Set PYTHONPATH to appropriate location

Returns
array<string> Return the path as an associative array.

Definition at line 793 of file common-sysconfig.php.

Variable Documentation

◆ CONFIG_TYPE_BOOL

const CONFIG_TYPE_BOOL 6

Checkbox type config

Definition at line 27 of file common-sysconfig.php.

◆ CONFIG_TYPE_DROP

const CONFIG_TYPE_DROP 5

Dropdown type config

Definition at line 25 of file common-sysconfig.php.

◆ CONFIG_TYPE_INT

const CONFIG_TYPE_INT 1

Integer type config

Definition at line 17 of file common-sysconfig.php.

◆ CONFIG_TYPE_PASSWORD

const CONFIG_TYPE_PASSWORD 4

Password type config

Definition at line 23 of file common-sysconfig.php.

◆ CONFIG_TYPE_TEXT

const CONFIG_TYPE_TEXT 2

Text type config

Definition at line 19 of file common-sysconfig.php.

◆ CONFIG_TYPE_TEXTAREA

const CONFIG_TYPE_TEXTAREA 3

Textarea type config

Definition at line 21 of file common-sysconfig.php.