r3036 - reloadDictionary(): act off target release name (or nothing)
[racktables] / inc / config.php
CommitLineData
b325120a 1<?php
e673ee24 2/*
9c0b0016
DO
3 *
4 * This file used to hold a collection of constants, variables and arrays,
5 * which drived the way misc RackTables functions performed. Now most of
201056a2 6 * them have gone into the database, and there is a user interface
9c0b0016
DO
7 * for changing them. This file now provides a couple of functions to
8 * access the new config storage.
9 *
8d07e3e0
DO
10 */
11
8d07e3e0 12
9c0b0016 13// Current code version is subject to change with each new release.
f7bd644b 14define ('CODE_VERSION', '0.17.2');
7fa7047a
DO
15define ('CHAP_OBJTYPE', 1);
16define ('CHAP_PORTTYPE', 2);
e673ee24 17
ca3d68bd
DO
18$max_dict_key = array
19(
20 '0.17.0' => 988,
21 '0.17.1' => 988,
22 '0.17.2' => 1150,
23// '0.17.3' => 1150,
24);
25
23818dde
DO
26define ('TAGNAME_REGEXP', '^[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
27define ('AUTOTAGNAME_REGEXP', '^\$[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
05771508
DO
28// The latter matches both SunOS and Linux-styled formats.
29define ('RE_L2_IFCFG', '/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i');
30define ('RE_L2_CISCO', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
31define ('RE_L2_SOLID', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
1930dc7f 32define ('RE_L2_IPCFG', '/^[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]$/i');
d516d719
DO
33define ('RE_L2_WWN_COLON', '/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]$/i');
34define ('RE_L2_WWN_HYPHEN', '/^[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]$/i');
35define ('RE_L2_WWN_SOLID', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
05771508
DO
36define ('RE_IP4_ADDR', '/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/i');
37define ('RE_IP4_NET', '/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\/[0-9][0-9]?$/i');
26131670 38
9c0b0016
DO
39function getConfigVar ($varname = '')
40{
41 global $configCache;
42 // We assume the only point of cache init, and it is init.php. If it
43 // has failed, we don't retry loading.
44 if (!isset ($configCache))
45 {
61e269b5 46 showError ("Configuration cache is unavailable", __FUNCTION__);
9c0b0016
DO
47 die;
48 }
49 if ($varname == '')
50 {
61e269b5 51 showError ("Missing argument", __FUNCTION__);
9c0b0016
DO
52 die;
53 }
54 if (isset ($configCache[$varname]))
55 {
56 // Try casting to int, if possible.
c461c579 57 if ($configCache[$varname]['vartype'] == 'uint')
9c0b0016
DO
58 return 0 + $configCache[$varname]['varvalue'];
59 else
60 return $configCache[$varname]['varvalue'];
61 }
62 return NULL;
63}
64
c461c579
DO
65// In softfail mode die only on fatal errors, letting the user check
66// and resubmit his input.
67function setConfigVar ($varname = '', $varvalue = '', $softfail = FALSE)
9c0b0016
DO
68{
69 global $configCache;
70 if (!isset ($configCache))
71 {
61e269b5 72 showError ('Configuration cache is unavailable', __FUNCTION__);
9c0b0016
DO
73 die;
74 }
59a83bd8 75 if (!strlen ($varname))
9c0b0016 76 {
61e269b5 77 showError ("Empty argument", __FUNCTION__);
9c0b0016
DO
78 die;
79 }
80 // We don't operate on unknown data.
81 if (!isset ($configCache[$varname]))
82 {
61e269b5 83 showError ("don't know how to handle '${varname}'", __FUNCTION__);
9c0b0016
DO
84 die;
85 }
dc2f1801
DO
86 if ($configCache[$varname]['is_hidden'] != 'no')
87 {
88 $errormsg = "'${varname}' is a system variable and cannot be changed by user.";
89 if ($softfail)
90 return $errormsg;
91 showError ($errormsg, __FUNCTION__);
92 die;
93 }
59a83bd8 94 if (!strlen ($varvalue) && $configCache[$varname]['emptyok'] != 'yes')
9c0b0016 95 {
c461c579
DO
96 $errormsg = "'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so.";
97 if ($softfail)
98 return $errormsg;
61e269b5 99 showError ($errormsg, __FUNCTION__);
c461c579
DO
100 die;
101 }
59a83bd8 102 if (strlen ($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric ($varvalue) or $varvalue < 0 ))
c461c579
DO
103 {
104 $errormsg = "'${varname}' can accept UINT values only";
105 if ($softfail)
106 return $errormsg;
61e269b5 107 showError ($errormsg, __FUNCTION__);
9c0b0016
DO
108 die;
109 }
110 // Update cache only if the changes went into DB.
111 if (storeConfigVar ($varname, $varvalue))
c461c579 112 {
9c0b0016 113 $configCache[$varname]['varvalue'] = $varvalue;
c461c579
DO
114 if ($softfail)
115 return '';
116 }
117 elseif ($softfail)
f1e7f725 118 return "storeConfigVar ('${varname}', '${varvalue}') failed in setConfigVar()";
9c0b0016 119}
8d07e3e0 120
e673ee24 121?>